RemoteDefiiAgent contract
Description in progres...
RemoteDefiiAgent - an implementation of DEFII on a network different from the Vault's network. The contract interacts with an external protocol using the Logic library. Each DEFII references Logic with a set of functions for entering, exiting, claiming rewards, withdrawing liquidity, and performing an emergency exit from the external protocol. For more details about Logic, please refer to the Logic smart contract section.
RemoteDefiiAgent interacts with RemoteDefiiPrincipal using a message broker. Currently, the protocol only supports LayerZero.
Read functions
FIXED_FEE
A fixed fee charged once when entering DEFII.
PERFORMANCE_FEE
The fee charged with each reinvestment in DEFII.
TREASURY
The ERC-20 address to which fees for entry and reinvestment in DEFII are credited.
INCENTIVE_VAULT
ERC-20 address where rewards from an external protocol are accrued. The incentive vault is managed by a trader who converts rewards into Notion tokens and reinvests them in DEFII.
LOGIC
The address of the library responsible for the logic of interaction between DEFII and an external protocol. When DEFII interacts with an external protocol, it triggers a delegatecall
to a specific function within the library.
OPERATOR_REGISTRY
Address of the smart contract that verifies the operator's access to the position.
FUNDS_HOLDER
The address of the Funds holder smart contract. This contract is utilized in remoteDefii for bridges, as the DEFII smart contract cannot hold any user liquidity.
REMOTE_CHAIN_ID
Chain identifier for the vault. Vault and remoteDefiiPrincipal are deployed on this chain.
killed
Returns true when an emergency situation has occurred, and the owner has called emergencyExit().
positionBalance
Returns the balance of the position in the vault.
vault
address
Vault address
positionId
uint256
Position identifier in the vault.
owner
address
Position owner
token
address
Token address
quoteLayerZeroFee
Returns the LayerZero fees for relaying a message to another chain.
calldata_
bytes
Message that needs to be relayed through LayerZero
payInZRO
bool
Use false
lzAdapterParams
bytes
LayerZero adapter parameters
remoteCallType
Type of cross-chain message broker. Currently, only LayerZero is supported.
supportedTokens
Tokens supported by DEFII. The list of tokens is immutable and defined during the smart contract deployment.
totalLiquidity
The amount of liquidity involved in an external protocol, calculated as the quantity of collateral tokens or LP tokens.
totalShares
The amount of DEFII LP tokens. DEFII LP tokens are stored in the Vault and represents its share in DEFII.
Write functions
remoteEnter
This function is called upon receiving a command from remoteDefiiPrincipal and performs a deposit into the external protocol. The function expects that the user's tokens have been successfully bridged to the chain of remoteDefiAgent and credited to the FundsHolder contract. When depositing into the external protocol, the following actions are taken:
remoteDefiiAgent retrieves tokens from FundsHolder.
If necessary, swaps into the input tokens.
Initiates entry into the external protocol.
Sends a command to remoteDefiiAgent to mint DEFII LP tokens.
Returns the remaining swap balance to FundsHolder.
vault
address
Vault address
positionId
uint256
Position ID in Vault
owner
address
Position owner
instructions
Instruction[]
Set of instructions
startRemoteExit
Start the exit from DEFII. Performs the following actions:
Exits the external protocol. When exiting, the minTokensDelta instruction can be used as slippage protection.
Executes the BRIDGE or SWAP_BRIDGE instruction. In this process, the user's tokens are sent to the Vault's chain on remoteDefiiAgent contract. remoteDefiiAgent burns DEFII LP and returns the funds to the Vault, from where the user can withdraw them.
Returns the remaining swap balance to FundsHolder.
reinvest
Reinvesting claimed rewards. After rewards have been received in the incentive vault, they are swapped into other tokens on a chain where there is liquidity exists, and the received tokens are deposited back into DEFII. When the reinvest function is called, the following sequence of actions is executed:
DEFII receives tokens from msg.sender.
Swaps are performed into tokens supported by third-party protocols.
PERFORMANCE_FEE is accrued to TREASURY.
Residuals from the swap are returned to the user.
instructions
Instruction[]
Set of instructions
remoteWithdrawLiquidity
Initiates the withdrawLiquidity logic, withdrawing all liquidity to the recipient's wallet.
withdrawFunds
Returns tokens from FundsHolder to msg.sender.
vault
address
Vault address
positionId
uint256
Position ID in Vault
token
address
Token address
amount
uint256
Amount of tokens
withdrawFundsAfterEmergencyExit
Returns all user liquidity to the recipient after an emergency exit.
vault
address
Vault address
positionId
uint256
Position ID in Vault
owner
address
Position owner's address
claimRewards
Sends rewards to the incentive vault's address.
emergencyExit
Exits the third-party protocol during an emergency situation.
increaseShareBalance
Increases the balance of DEFII LP tokens within remoteDefiiAgent. Can only be called via self-call from this contract. The call is initiated by remoteDefiiPrincipal.
vault
address
Vault address
positionId
uint256
Position ID in Vault
owner
address
Position owner's address
shares
uint256
Amount of shares for increase
receiveTokenWithMessage
Receives tokens from the bridge adapter and credits them to FundsHolder. Increases position balances.
token
address
Token address
amount
uint256
Amount of tokens
message
bytes
Message where the vault, position id, and owner are encoded
lzReceive
Function to support message exchange using LayerZero. For additional information, refer to the LayerZero documentation.
_srcChainId
uint16
Source chain ID
_srcAddress
address
Address of the contract from which the message was sent
uint64
nonce
Message nonce
_payload
bytes
Message payload
Last updated