shift
  • Introduction
  • Underlying factors for developing shift
  • Get started
    • How to choose the Vault
    • How to deposit
    • How to withdraw
    • How to shuffle between Vault versions
    • How to track the balance
    • How to review transactions history
    • Emergency situation
  • SHIFT Products
    • Vault
    • DeFi strategy
    • Vault for Financial Institutes
  • Risk Management
    • Overview
    • Risk Assessment and Management Policy
    • Risk Mitigation
  • Developer Resources
    • Ecosystem overview
    • Vault contract
      • Position status logic
    • DEFII
      • Logic contract
      • LocalDefii contract
      • RemoteDefiiPrincipal contract
      • RemoteDefiiAgent contract
      • Instructions
    • OperatorRegistry contract
    • Emergency situations
    • Deployment addresses
  • Vaults
    • USD - Risk Level 3
  • FAQ
    • General
    • Fee terms
    • Platform design
    • Emergency
    • Utility
    • Security
    • Communication
  • Resources
    • Discord
    • Medium
    • Twitter
    • Telegram
    • Github
Powered by GitBook
On this page
  • Read functions
  • Write functions
  • Simulation Functions
  1. Developer Resources
  2. DEFII

LocalDefii contract

Last updated 1 year ago

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.

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:

  1. Receiving notion tokens from the user.

  2. Swapping into supported third-party protocol tokens, if the input tokens are different from notion. The 1inch router is used for swapping.

  3. 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.

  4. Minting DEFII LP for the depositor. A portion of DEFII LP is allocated to the TREASURY as a fee.

  5. Returning the remaining tokens from the swap to the depositor.

  6. 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:

  1. SWAP - swaps 2 tokens.

  2. MIN_LIQUIDITY_DELTA - slippage protection. It checks that after entering DEFII, the user has minted a satisfactory amount of DEFII LP.

Parameter
Type
Definition

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:

  1. 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.

  2. Burning DEFII LP.

  3. Optional token swapping.

  4. Returning the remaining tokens from the swap to the user.

  5. 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:

  1. SWAP - swaps 2 tokens.

  2. MIN_TOKENS_DELTA - slippage protection. Checks the amount of tokens the user will receive in exchange for their DEFII LP.

Parameter
Type
Definition

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:

  1. DEFII accepts notion tokens.

  2. Swaps are executed into tokens supported by external protocols.

  3. Shares are minted. User can specify the minimum amount of LP tokens to be minted after reinvestment.

  4. Remaining tokens from the swaps are returned to the user.

function reinvest(Instruction[] calldata instructions) external;
Parameter
Type
Definition

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;
Parameter
Type
Definition

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;
Parameter
Type
Definition

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);
Parameter
Type
Definition

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);
Parameter
Type
Definition

shares

uint256

The amount of liquidity to simulate the withdrawal of.

tokens

address[]

Set of tokens.

OpenZeppelin ERC20 documentation
Instructions page
Logic smart contract