This contract implements the market cap square root index management strategy.
Categories are periodically sorted, ranking their tokens in descending order by market cap.
Index pools have a defined size which is used to select the top tokens from the pool's category. Every 2 weeks, pools are either re-weighed or re-indexed. They are re-indexed once for every three re-weighs.
Re-indexing involves selecting the top tokens from the pool's category and weighing them by the square root of their market caps. Re-weighing involves weighing the tokens which are already indexed by the pool by the square root of their market caps. When a pool is re-weighed, only the tokens with a desired weight above 0 are included.
constructor(UniSwapV2PriceOracle oracle,address ndx,PoolFactory factory,DelegateCallProxyManager proxyManager)
Deploy the controller and configure the addresses of the related contracts.
function setOwner(address owner)
Set the address of the ndx contract. After deployment this will likely never change, but it is useful to have some small window during which things can be initialized before governance is fully in place.
function setDefaultSellerPremium(uint8 _defaultSellerPremium)
Sets the default premium rate for token seller contracts.
function emergencyExecuteSwapTokensForExactTokens(address sellerAddress,address tokenIn,address tokenOut,uint256 maxAmountIn,uint256 amountOut,address path)
Emergency function that allows the dao to force a token sale through UniSwap. This exists in case of an emergency which demands immediate removal of a token.
function prepareIndexPool(uint256 categoryID,uint256 indexSize,uint256 initialWethValue,string name,string symbol)
Deploys an index pool and a pool initializer. The initializer contract is a pool with specific token balance targets which gives pool tokens in the finished pool to users who provide the underlying tokens needed to initialize it.
function finishPreparedIndexPool(address poolAddress,address tokens,uint256 balances)
Initializes a pool which has been deployed but not initialized and transfers the underlying tokens from the initialization pool to the actual pool.
function updateSellerPremiumToDefault(address sellerAddress)
Update the premium rate on
sellerAddress with the current default rate.
function updateSellerPremiumToDefault(address sellerAddresses)
Update the premium rate on each unbound token seller in
sellerAddresses with the current default rate.
function setSwapFee(address poolAddress, uint256 swapFee)
Sets the swap fee on an index pool.
function pausePublicTrading(address poolAddress)
Freezes public trading and liquidity providing on an index pool.
function resumePublicTrading(address poolAddress)
Resumes public trading and liquidity providing on an index pool.
function removeTokenFromPool(address poolAddress,address tokenAddress)
Forcibly removes a token from a pool. This should only be used as a last resort if a token is experiencing a sudden crash or major vulnerability. Otherwise, tokens should only be removed gradually through re-indexing events.
function createCategory(bytes32 metadataHash)
Create a new token category.
function addToken(address token, uint256 categoryID)
Adds a new token to a category. Note: A token can only be assigned to one category at a time.
function addTokens(uint256 categoryID, address tokens)
Add tokens to a category.
function orderCategoryTokensByMarketCap(uint256 categoryID, address orderedTokens)
Sorts a category's tokens in descending order by market cap. Verifies the order of the provided array by querying the market caps.
function reindexPool(address poolAddress)
Re-indexes a pool by setting the underlying assets to the top tokens in its category by market cap.
function reweighPool(address poolAddress)
Reweighs the assets in a pool by market cap and sets the desired new weights, which will be adjusted over time.
function setMinimumBalance(IPool pool,address tokenAddress)
Updates the minimum balance of an uninitialized token, which is useful when the token's price on the pool is too low relative to external prices for people to trade it in.
function defaultSellerPremium() returns (uint256 defaultSellerPremium)
Default premium percent for index pool's unbound token sellers.
function computeInitializerAddress(address poolAddress) returns (address initializerAddress)
Compute the create2 address for a pool initializer.
function computePoolAddress(uint256 categoryID, uint256 indexSize) returns (address poolAddress)
Compute the create2 address for a pool.
function getInitialTokenWeightsAndBalances(uint256 categoryID,uint256 indexSize,uint256 wethValue) returns (address tokens, uint96 denormalizedWeights, uint256 balances)
Queries the top
indexSize tokens in a category from the market _oracle, computes their relative weights by market cap square root and determines the weighted balance of each token to meet a specified total value in weth.
function getInitialTokensAndBalances(uint256 categoryID,uint256 indexSize,uint256 wethValue) returns (address tokens, uint256 balances)
Queries the top
indexSize tokens in a category from the market _oracle, computes their relative weights by market cap square root and determines the weighted balance of each token to meet a specified total value.
function computeAverageMarketCap(address token) returns (uint144 marketCap)
Compute the average market cap of a token in WETH. Queries the average amount of ether that the total supply is worth using the recent moving average.
function computeAverageMarketCaps(address tokens) returns (uint144 marketCaps)
Returns the average market cap for each token.
function categoryIndex() returns (uint256 categoryID)
Number of categories in the oracle.
function hasCategory(uint256 categoryID) returns (bool)
Returns a boolean stating whether a category exists.
function getCategoryTokens(uint256 categoryID) returns (address tokens)
Returns the array of tokens in a category.
function getCategoryMarketCaps(uint256 categoryID) returns (uint144 marketCaps)
Returns the market capitalization rates for the tokens in a category.
function getTopCategoryTokens(uint256 categoryID,uint256 num) returns (address tokens)
Get the top
num tokens in a category. Note: The category must have been sorted by market cap in the last