Deposit / Withdrawal

Overview

The IndexSwap contract facilitates the process of investing and withdrawing funds in a portfolio of tokens. It allows users to invest in a portfolio and receive index tokens representing their share in the portfolio. Moreover, users can withdraw their investments by burning index tokens and receiving the corresponding portfolio tokens.

Deposit Process

  • Initiation:

    • The user calls the investInFund function.

    • The user can send BNB (or another permitted token) as the investment amount.

  • Validation:

    • Various checks are made before the investment, such as verifying the number of tokens and their respective slippage limits.

    • The function checks if the sent value is BNB. If it's not, it verifies the token and its balance.

  • Charge Fees:

    • If the entry fee is set, the contract charges it from the investment amount. Also it charges management and performance fee from the vault based on the current status before minting tokens for the new user to make sure the amount is fair.

  • Swap and Calculate USD value:

    • The BNB (or another token) is then swapped into portfolio tokens.

    • The output of the swap is converted into USD to determine the amount after slippage. This is used to calculate the amount of index tokens to mint.

  • Mint Index Tokens:

    • Based on the investment amount and the current total supply of index tokens, new index tokens are minted for the user.

  • Update Cooldown Period:

    • After minting, the cooldown period for the user's next withdrawal is updated.

  • Completion:

    • The function emits an InvestInFund event, marking the completion of the deposit process.

Withdrawal Process

  • Initiation:

    • The user calls the withdrawFund function.

    • The user specifies the amount of index tokens they want to burn (withdraw).

  • Validation:

    • Various checks are made before the withdrawal, such as verifying the number of tokens and their respective slippage limits.

    • The function also verifies that the cooldown period for the user has passed.

    • Vault min amount requirements have to be met after the withdrawal or the user has to withdraw 100%

  • Charge Fees:

    • If the exit fee is set, the contract charges it. Also it charges management and performance fee based on the current status of the vault.

  • Burn Index Tokens:

    • The specified amount of index tokens is burned from the user's balance.

  • Swap Portfolio Tokens:

    • The portfolio tokens represented by the burned index tokens are then swapped back to BNB (or another specified token) for the user.

    • If the user chooses a multi-asset withdrawal, they receive multiple tokens (i.e., their share of the underlying tokens from the vault). If they choose a single asset, they receive only one specified token.

  • Completion:

    • The function emits a WithdrawFund event, marking the completion of the withdrawal process.

    • Any leftover balance that doesn't meet the minimum investment threshold is validated and reverted if needed

Additional Notes

  • The IndexSwap contract uses the OpenZeppelin library for various features, including the ERC20 standard, upgradeability, and ownership.

  • The contract also uses a series of other custom contracts and interfaces, like IExchange, IPriceOracle, IAccessController, etc., to facilitate its functionalities.

  • Throughout the contract, various events (like InvestInFund, WithdrawFund, etc.) are emitted to log important actions and changes.

  • There are also administrative functionalities (like updating token lists, setting cooldown periods, pausing the contract, etc.) that are restricted to specific roles, ensuring security and proper management.