IndexStrategyUpgradeable.sol

Introduction

The Index contract is an abstract contract called IndexStrategyUpgradeable, which is a type of smart contract that represents a basket of digital assets. It has a list of components (tokens) and each component has a weight. The contract maintains mappings from each component to its weight, from each token to its list of routers, from each router to its type of DEX, and from each router, tokenIn, and tokenOut to PairData. The contract also has a whitelistedTokens array and an equityValuationLimit variable.

The contract provides functionalities to mint and withdraw Index tokens, add new components, add new swap routes, and rebalance the weights of the components. The contract ensures that the equity valuation limit is not exceeded and only allows operations on whitelisted tokens.

Main Features of the Smart Contract:

The smart contract implements the following main features:

  • Minting and withdrawing Index tokens

  • Adding new components (tokens) to the index

  • Removing components (tokens) to the index

  • Adding new swap routes for each token

  • Removing swap routes for each token

  • Rebalancing the weights of the components in the index

  • Pausing all operations on the contract

  • Checking if a token is whitelisted

  • Checking if the equity valuation limit has been reached

User Stories for Minting and Withdrawing Index Tokens

Minting Index Tokens: A user can mint Index Tokens by calling the mintIndexFromToken function. This function takes in the token address, the maximum amount of the token that the user is willing to spend, the minimum amount of Index tokens that the user wants to receive, and the recipient address. The function checks if the recipient address is valid, the token is whitelisted, and the equity valuation limit has not been reached. It then calculates the amount of Index tokens that can be minted, performs the necessary token transfers and mints the Index tokens.

One important note regarding the implementation for minting new Index token is the fact that the UI calls the getAmountIndexFromToken function before calling mintIndexFromToken. This function returns the amount which is used as parameter for the minimum amount of Index tokens in mintIndexFromToken.

Withdrawing Index Tokens: A user can withdraw Index Tokens by calling the burnExactIndexForToken function. This function takes in the token address, the minimum amount of the token that the user wants to receive, the exact amount of Index tokens that the user wants to burn, and the recipient address. The function checks if the recipient address is valid and the token is whitelisted. It then calculates the amount of the token that will be received, performs the necessary token transfers and burns the Index tokens.

Similar to the implementation for minting new Index tokens, the UI shall call getAmountTokenFromExactIndex before calling burnExactIndexForToken. This function returns the amount which is used as parameter for the minimum amount of tokens in burnExactIndexForToken.

User Stories for owner operations

The owner of the contract has special permissions to perform certain actions:

Adding Components: The owner can add a new component (token) to the index by calling the addComponent function with the address of the new component as a parameter.

Removing Components: The owner can remove a component (token) to the index by calling the removeComponent function with the address of the component as a parameter.

Adding Swap Routes: The owner can add a new swap route by calling the addSwapRoute function with the token address, router address, type of DEX, and pair data as parameters.

Removing Swap Routes: The owner can remove a swap route by calling the removeSwapRoute function with the token address, and router address as parameters.

Rebalancing: The owner can rebalance the weights of the components in the index by calling the rebalance function with the new target weights as parameters.

Pausing: The owner can pause all operations on the contract by calling the pause function. This function does not take any parameters.

Last updated

About Brokkr

WebsiteXDiscord