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
  • View functions
  • Write functions
  1. Developer Resources

Vault contract

The Vault is an fundamental smart contract within the shift ecosystem, primarily designed to enable users to deposit funds and allocate them to various investment strategies, called as DEFIIs. It designed in accordance with the ERC721 non-fungible token standard, granting users an NFT as a record of their deposited funds. This NFT acts as an account ledger, where stored the user’s ERC20 tokens balances.

The Vault offers the capability to automate the process of entering DEFIIs by allowing users to delegate access rights to an operator. This necessitates users granting the operator permission to manage their position within the OperatorRegistry contract, along with covering the transaction fees for entering DEFIIs.

Deposits into DEFIIs must be made with a notion token to ensure correct functionality. Users need to deposit this specific token into the Vault. To support user convenience, a Router smart contract is included as part of the broader ecosystem. This Router allows users to enter the Vault with any ERC20 token supported by a swap router.

View functions

NOTION

Returns the notion of the vault

function NOTION() external returns (address);

Returns the address of the OperatorRegistry contract.

IOperatorRegistry public immutable OPERATOR_REGISTRY;

calculateDefiiEnterAmount

Returns the amount of tokens for depositing into a specific DEFII from a specific position. During the deposit into the Vault, the number of notion tokens available for deposit from a specific position is specified. Each DEFII in the Vault has a predefined weight, which determines the share of the position that will be deposited into a specific DEFII.

function calculateEnterDefiiAmount(
        uint256 positionId,
        address defii
    ) public view returns (uint256);

calculateDefiiExitShares

Returns the amount of DEFII LP tokens to be withdrawn from a specific DEFII for a given position. Before the withdrawal, the user or operator specifies the percentage of shares they intend to withdraw. The weight of DEFII is set during the deployment of the Vault and remains unchanged thereafter.

function calculateExitDefiiShares(
        uint256 positionId,
        address defii
    ) public view returns (uint256);

getDefiis

Returns a list of all DEFIIs in the Vault.

function getDefiis() external view returns (address[] memory);

getPositionStatus

function getPositionStatus(uint256 positionId)
        external
        view
        returns (Status positionStatus, Status[] memory defiiStatuses);

Write functions

deposit

function deposit(
        address token,
        uint256 amount,
        uint256 operatorFeeAmount
    ) external returns (uint256 positionId);
Parameter
Type
Definition

token

address

Token address

amount

uint256

Amount of deposited tokens

operatorFeeAmount

uint256

Operator fee. User pays fee for transaction processing

depositToPosition

Deposits tokens into existing position in Vault.

function depositToPosition(
        uint256 positionId,
        address token,
        uint256 amount,
        uint256 operatorFeeAmount
    ) external;
Parameter
Type
Definition

positionId

uint256

Position Id for deposit.

token

address

Deposited token

amount

uint256

Amount of deposited tokens

operatorFeeAmount

uint256

Operator fee. User pays fee for transaction processing.

depositWithPermit

function depositWithPermit(
        address token,
        uint256 amount,
        uint256 operatorFeeAmount,
        uint256 deadline,
        uint8 permitV,
        bytes32 permitR,
        bytes32 permitS
    ) external returns (uint256 positionId);
Parameter
Type
Definition

token

address

Deposited token

amount

uint256

Amount of deposited tokens

operatorFeeAmount

uint256

Operator fee. User pays fee for transaction processing.

deadline

uint256

Permit deadline

permitV

uint8

Permit V parameter

permitR

bytes32

Permit R paramter

permitS

bytes32

Permit S parameter

enterCallback

The function increases the DEFII LP balance for a position and changes the DEFII's status in the position to PROCESSING after entry into an external protocol. It is called by the DEFII after entering the external protocol. The DEFII's status in the position affects the position's status.

function enterCallback(
        uint256 positionId,
        uint256 shares
    ) external validateDefii(msg.sender) {
        _changeBalance(positionId, msg.sender, shares, true);
        _changeDefiiStatus(positionId, msg.sender, Status.PROCESSED);
    };
Parameter
Type
Definition

positionId

uint256

Position Id for which enter in DEFII was made.

shares

uint256

Amount for shares were deposited into DEFII

exitCallback

The function changes the DEFII's status to PROCESSED. It is called after exiting from the DEFIl. The DEFII's status in the position affects the position's status.

function exitCallback(
        uint256 positionId
    ) external validateDefii(msg.sender);
Parameter
Type
Definition

positionId

uint256

Position Id for which exit in DEFII was made.

enterDefii

Entering a specific DEFII. It can be called by the position owner or an operator with access granted by the owner. The function calculates the amount of notion tokens for entry, changes the DEFII's status within the position, and triggers the entry logic into DEFII.

function enterDefii(
        address defii,
        uint256 positionId,
        IDefii.Instruction[] calldata instructions
    )
        external
        payable
        validateDefii(defii)
        operatorCheckApproval(ownerOf(positionId));
Parameter
Type
Definition

defii

address

DEFII address

positonId

uint256

Position Id

instructions

Instruction[]

Array of entering instructions. It is can be swap, bridge, slippage protection instructions for enter in DEFII.

exitDefii

Exiting from a specific DEFII. It can be initiated by the position owner or an operator granted access by the position owner. It calculates the amount of DEFII LP tokens for withdrawal, updates the DEFII's status within the position, decreases the user's DEFII LP balance, and triggers the exit logic.

function exitDefii(
        address defii,
        uint256 positionId,
        IDefii.Instruction[] calldata instructions
    )
        external
        payable
        validateDefii(defii)
        operatorCheckApproval(ownerOf(positionId));
Parameter
Type
Definition

defii

address

Address of DEFII

positonId

uint256

Position Id

instructions

Instruction[]

Array of exit instructions. It is can be swap, bridge, slippage protection instructions for exit from DEFII.

startExit

Sets the percentage of DEFII LP tokens to be withdrawn from DEFII.

function startExit(uint256 percentage) external;
Parameter
Type
Definition

percentage

uint256

Percent of user’s funds for exit from vault.

withdraw

Returns the owner of the position an amount of tokens from the position. It can be called by the owner of the position or an operator with access to the position.

function withdraw(
        address token,
        uint256 amount,
        uint256 positionId
    ) external;
Parameter
Type
Definition

token

address

Token for withdraw

amount

uint256

Amount of token for withdraw

positionId

uint256

Position Id from which user want to withdraw. If msg.sender ≠ positionOwner, msg.sender should have approve from positionOwner.

withdrawLiquidity

Burns the user's DEFII LP tokens and directly withdraws liquidity to the owner of the position.

function withdrawLiquidityFromDefii(
        uint256 positionId,
        address defii,
        IDefii.Instruction[] calldata instructions
    ) external payable validateDefii(defii);
Parameter
Type
Definition

positionId

uint256

Position Id from which user want to withdraw. If msg.sender ≠ positionOwner, msg.sender should have approve from positionOwner.

defii

address

Address of defii to withdraw

instructions

Instruction[]

Set of instructions to withdraw liquidity.

Last updated 1 year ago

Returns the status of the position. The position's status is determined by the statuses of the Vault's DEFIIs. For more details on statuses, refer to the .

Deposits tokens into the Vault. During the deposit, a position is opened for the user if it has not been created previously. The position is represented as an NFT. A user can have only one position in which all the user's tokens are accounted for. This function solely deposits tokens into the Vault but does not enter DEFII. The function is used for entering DEFII. The user can automate entry into DEFII by providing approval to the operator and paying the operatorFeeAmount, which is the transaction processing fee.

Deposit with permit. The permit standard, explained in , makes it easier and safer for users to deposit tokens. It allows users to delegate access to their tokens for specific actions, like deposits, without having to manually sign each transaction. This simplifies the process and gives users more control.

status logic page
enterDefii
EIP-2612