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
  1. Developer Resources
  2. DEFII

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.

uint256 public immutable FIXED_FEE;

PERFORMANCE_FEE

The fee charged with each reinvestment in DEFII.

uint256 public immutable PERFORMANCE_FEE;

TREASURY

The ERC-20 address to which fees for entry and reinvestment in DEFII are credited.

address public immutable TREASURY;

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.

address public immutable INCENTIVE_VAULT;

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.

address public immutable LOGIC;

OPERATOR_REGISTRY

Address of the smart contract that verifies the operator's access to the position.

IOperatorRegistry public immutable OPERATOR_REGISTRY;

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.

FundsHolder public immutable FUNDS_HOLDER;

REMOTE_CHAIN_ID

Chain identifier for the vault. Vault and remoteDefiiPrincipal are deployed on this chain.

uint256 public immutable REMOTE_CHAIN_ID;

killed

Returns true when an emergency situation has occurred, and the owner has called emergencyExit().

bool public killed;

positionBalance

Returns the balance of the position in the vault.

mapping(address vault => mapping(uint256 positionId => mapping(address owner => mapping(address token => uint256 balance))))
        public positionBalance;
Parameter
Type
Definition

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.

 function quoteLayerZeroFee(
        bytes calldata calldata_,
        bool payInZRO,
        bytes calldata lzAdapterParams
    ) external view returns (uint256 nativeFee, uint256 zroFee);
Parameter
Type
Definition

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.

function remoteCallType() external pure override returns (RemoteCallsType);

supportedTokens

Tokens supported by DEFII. The list of tokens is immutable and defined during the smart contract deployment.

function supportedTokens() public view virtual returns (address[] memory t);

totalLiquidity

The amount of liquidity involved in an external protocol, calculated as the quantity of collateral tokens or LP tokens.

// Some code

totalShares

The amount of DEFII LP tokens. DEFII LP tokens are stored in the Vault and represents its share in DEFII.

function totalLiquidity() public view override returns (uint256);

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:

  1. remoteDefiiAgent retrieves tokens from FundsHolder.

  2. If necessary, swaps into the input tokens.

  3. Initiates entry into the external protocol.

  4. Sends a command to remoteDefiiAgent to mint DEFII LP tokens.

  5. Returns the remaining swap balance to FundsHolder.

function remoteEnter(
        address vault,
        uint256 positionId,
        address owner,
        IDefii.Instruction[] calldata instructions
    ) external payable operatorCheckApproval(owner)
Parameter
Type
Definition

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:

  1. Exits the external protocol. When exiting, the minTokensDelta instruction can be used as slippage protection.

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

  3. Returns the remaining swap balance to FundsHolder.

function startRemoteExit(
    address vault,
    uint256 positionId,
    address owner,
    IDefii.Instruction[] calldata instructions
) external payable operatorCheckApproval(owner)

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:

  1. DEFII receives tokens from msg.sender.

  2. Swaps are performed into tokens supported by third-party protocols.

  3. PERFORMANCE_FEE is accrued to TREASURY.

  4. Residuals from the swap are returned to the user.

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

instructions

Instruction[]

Set of instructions

remoteWithdrawLiquidity

Initiates the withdrawLiquidity logic, withdrawing all liquidity to the recipient's wallet.

solidityCopy codefunction remoteWithdrawLiquidity() external

withdrawFunds

Returns tokens from FundsHolder to msg.sender.

solidityCopy codefunction withdrawFunds(
        address vault,
        uint256 positionId,
        address token,
        uint256 amount
    ) external
Parameter
Type
Definition

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.

solidityCopy codefunction withdrawFundsAfterEmergencyExit(
        address vault,
        uint256 positionId,
        address owner
    ) external
Parameter
Type
Definition

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.

solidityCopy codefunction claimRewards() external;

emergencyExit

Exits the third-party protocol during an emergency situation.

solidityCopy codefunction emergencyExit() external alive onlyOwner

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.

solidityCopy codefunction increaseShareBalance(
        address vault,
        uint256 positionId,
        address owner,
        uint256 shares
    ) external remoteFn
Parameter
Type
Definition

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.

solidityCopy codefunction receiveTokenWithMessage(
        address token,
        uint256 amount,
        bytes calldata message
    ) external
Parameter
Type
Definition

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.

solidityCopy codefunction lzReceive(
        uint16 _srcChainId,
        bytes calldata _srcAddress,
        uint64,
        bytes calldata _payload
    ) external
Parameter
Type
Definition

_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 1 year ago