LocalDefii contract
Last updated
Last updated
LocalDefii - a DEFII smart contract operating on the same network as Vault. LocalDefii combines the logic of interacting with external protocols with interactions with Vault and minting DEFII LP.
LocalDefii is an ERC20 token, allowing it to manage user liquidity. Standard ERC20 functions are not described in this document; for information on them, please refer to the .
Similar to Vault, LocalDefii also has notion.
LocalDefii can use Instructions, which are specific actions set by the user during entry, exit, or reinvestment. The following instructions are available for LocalDefii: SWAP, MIN_LIQUIDITY_DELTA, MIN_TOKENS_DELTA. A description of all possible instructions can be found on the .
Interaction with external protocols is described on the page.
Returns the tokens supported by DEFII. The list of tokens is determined during the deployment of the LocalDefii smart contract.
Returns DEFII notion token address.
Returns type of DEFII. For LocalDefii is 0.
Returns current amount of DEFII LP tokens.
Returns current amount of liquidity locked in external protocol.
It implements the logic of entering DEFII. Entry consists of:
Receiving notion tokens from the user.
Swapping into supported third-party protocol tokens, if the input tokens are different from notion. The 1inch router is used for swapping.
Entering the third-party protocol. To do this, DEFII makes a delegatecall to the logic library. At the same time, the amount of LP tokens that should be minted to the depositor is calculated. The depositor can use the MIN_LIQUIDITY_DELTA instruction for slippage protection.
Minting DEFII LP for the depositor. A portion of DEFII LP is allocated to the TREASURY as a fee.
Returning the remaining tokens from the swap to the depositor.
Calling the enterCallback.
During entry, it is possible to use instructions. To enter DEFII, users can use the following types of instructions:
SWAP - swaps 2 tokens.
MIN_LIQUIDITY_DELTA - slippage protection. It checks that after entering DEFII, the user has minted a satisfactory amount of DEFII LP.
amount
uint256
The amount of notion tokens that the user wants to deposit into DEFII.
positionId
uint256
Position ID in Vault
instructions
Instruction[]
List of entry instructions
It performs an exit from DEFII. When exiting, the following sequence of actions is executed:
Exiting the external protocol. Similar to the enter function, exit performs a delegatecall to the Logic contract. During this process, the user can specify the minimum amount of tokens they want in exchange for their DEFII LP.
Burning DEFII LP.
Optional token swapping.
Returning the remaining tokens from the swap to the user.
Calling the exitCallback in the Vault.
When exiting, it's possible to use instructions. For the exit, the user can use the following types of instructions:
SWAP - swaps 2 tokens.
MIN_TOKENS_DELTA - slippage protection. Checks the amount of tokens the user will receive in exchange for their DEFII LP.
shares
uint256
The amount of liquidity to be withdrawn from the protocol.
positionId
uint256
Position ID in Vault
instructions
Instruction[]
List of exit instructions
Claim rewards on the incentive vault. The incentive vault is set during the deployment of DEFII.
Reinvestment of claimed rewards. After rewards have been received in the incentive vault, they are swapped into notion on a chain where there is liquidity available for this purpose, and the acquired notion tokens are reinvested back into DEFII by trader. When the reinvest function is called, the following sequence of actions is performed:
DEFII accepts notion tokens.
Swaps are executed into tokens supported by external protocols.
Shares are minted. User can specify the minimum amount of LP tokens to be minted after reinvestment.
Remaining tokens from the swaps are returned to the user.
instructions
Instruction[]
Set of instructions for reinvest.
Withdrawal of liquidity from DEFII to the recipient's address. This function burns DEFII LP tokens belonging to the msg.sender and triggers the liquidity withdrawal logic from the third-party protocol.
recipient
address
Recipient address
shares
uint256
The amount of DEFII LP tokens to be burned.
instructions
Instruction[]
Set of instructions. Here is should be empty.
Instruction for withdrawing liquidity after an emergency exit. It burns all shares held by msg.sender and initiates the logic for an emergency exit from the external protocol.
recipient
address
Recipient address
Initiates the emergency exit logic. This function can be called if an emergency exit has not been executed previously. It is only available for the owner. The owner is the address that deployed the contract.
These functions simulate user actions with DEFII. Such functions are called using staticcall and do not result in liquidity withdrawal.
Simulation of claiming rewards. Returns the amount of reward tokens that would have been allocated to the incentive vault if a real claim had been made.
rewardTokens
address[]
Set of reward tokens
Simulation of exiting from a third-party protocol. Returns the amount of tokens that would have been earned after exiting DEFII if a real exit had occurred.
shares
uint256
The amount of liquidity to simulate the withdrawal of.
tokens
address[]
Set of tokens.