LocalDefii contract
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 OpenZeppelin ERC20 documentation.
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 Instructions page.
Interaction with external protocols is described on the Logic smart contract page.
Read functions
supportedTokens
Returns the tokens supported by DEFII. The list of tokens is determined during the deployment of the LocalDefii smart contract.
function supportedTokens() public view virtual returns (address[] memory t);
notion
Returns DEFII notion token address.
address immutable NOTION;
defiiType
Returns type of DEFII. For LocalDefii is 0.
function defiiType() external pure returns (Type);
totalShares
Returns current amount of DEFII LP tokens.
function totalShares() public view virtual returns (uint256);
totalLiqudity
Returns current amount of liquidity locked in external protocol.
function totalLiquidity() public view virtual returns (uint256);
Write functions
enter
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.
function enter(
uint256 amount,
uint256 positionId,
Instruction[] calldata instructions
) external payable;
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
exit
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.
function exit(
uint256 shares,
uint256 positionId,
Instruction[] calldata instructions
) external payable
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
claimRewards
Claim rewards on the incentive vault. The incentive vault is set during the deployment of DEFII.
function claimRewards() external;
reinvest
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.
function reinvest(Instruction[] calldata instructions) external;
instructions
Instruction[]
Set of instructions for reinvest.
withdrawLiquidity
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.
function withdrawLiquidity(
address recipient,
uint256 shares,
Instruction[] calldata
) external payable;
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.
withdrawFundsAfterEmergencyWithdraw
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.
function withdrawFundsAfterEmergencyExit(address recipient) external;
recipient
address
Recipient address
emergencyExit
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.
function withdrawFundsAfterEmergencyExit(address recipient) external;
Simulation Functions
These functions simulate user actions with DEFII. Such functions are called using staticcall and do not result in liquidity withdrawal.
simulateClaimRewards
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.
function simulateClaimRewards(
address[] calldata rewardTokens
) external returns (int256[] memory balanceChanges);
rewardTokens
address[]
Set of reward tokens
simulateExit
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.
function simulateExit(
uint256 shares,
address[] calldata tokens
) external returns (int256[] memory balanceChanges);
shares
uint256
The amount of liquidity to simulate the withdrawal of.
tokens
address[]
Set of tokens.
Last updated