IndexAvalanche.sol
The IndexAvalanche
contract is an extension of the IndexStrategyUpgradeable
contract and includes two additional functions: equityValuation
and addSwapRoute
.
Here are the key points of the smart contract:
Inheritance: This contract inherits from the
IndexStrategyUpgradeable
contract, meaning that it has access to all public and internal functions and state variables declared in theIndexStrategyUpgradeable
contract.equityValuation Function: The
equityValuation
function is used to calculate the equity valuation of the index. The function takes two boolean parameters,maximize
andincludeAmmPrice
, and returns the equity valuation as an unsigned integer. Here are the steps involved:It first retrieves the total supply of the index token.
If the total supply is zero, it returns zero.
It then calculates the unit amount of WNATIVE for the exact index precision.
It retrieves the price of WNATIVE based on the
maximize
andincludeAmmPrice
parameters.Finally, it calculates the equity valuation by multiplying the unit amount of WNATIVE, the price of WNATIVE, and the total supply of the index token, and then divides the result by the product of the decimals and precision constants. This result is returned as the equity valuation.
addSwapRoute Function: The
addSwapRoute
function is an external function that can only be called by the contract owner. It is used to add a new swap route for a token. The function takes four parameters,token
(the address of the token),router
(the address of the router),dex
(the DEX type), andpair
(the address of the pair). It creates aPairData
struct with thepair
address and zero for thebinStep
value and then calls theaddSwapRoute
function in theIndexStrategyUpgradeable
contract with these parameters.It's important to note that this function allows the owner of the contract to add new swap routes, which can impact how tokens are swapped within the contract.
Last updated