Indexed Finance
Search…
MarketCapSqrtController.sol

MarketCapSqrtController

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

1
constructor(
2
UniSwapV2PriceOracle oracle,
3
address ndx,
4
PoolFactory factory,
5
DelegateCallProxyManager proxyManager
6
)
Copied!
Deploy the controller and configure the addresses of the related contracts.

Controls

setOwner

1
function setOwner(address owner)
Copied!
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.

setDefaultSellerPremium

1
function setDefaultSellerPremium(uint8 _defaultSellerPremium)
Copied!
Sets the default premium rate for token seller contracts.

emergencyExecuteSwapTokensForExactTokens

1
function emergencyExecuteSwapTokensForExactTokens(
2
address sellerAddress,
3
address tokenIn,
4
address tokenOut,
5
uint256 maxAmountIn,
6
uint256 amountOut,
7
address[] path
8
)
Copied!
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.

Pool Deployment

prepareIndexPool

1
function prepareIndexPool(
2
uint256 categoryID,
3
uint256 indexSize,
4
uint256 initialWethValue,
5
string name,
6
string symbol
7
)
Copied!
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.

finishPreparedIndexPool

1
function finishPreparedIndexPool(
2
address poolAddress,
3
address[] tokens,
4
uint256[] balances
5
)
Copied!
Initializes a pool which has been deployed but not initialized and transfers the underlying tokens from the initialization pool to the actual pool.

Pool Management

updateSellerPremiumToDefault

1
function updateSellerPremiumToDefault(
2
address sellerAddress
3
)
Copied!
Update the premium rate on sellerAddress with the current default rate.

updateSellerPremiumToDefault

1
function updateSellerPremiumToDefault(
2
address[] sellerAddresses
3
)
Copied!
Update the premium rate on each unbound token seller in sellerAddresses with the current default rate.

setSwapFee

1
function setSwapFee(address poolAddress, uint256 swapFee)
Copied!
Sets the swap fee on an index pool.

pausePublicTrading

1
function pausePublicTrading(address poolAddress)
Copied!
Freezes public trading and liquidity providing on an index pool.

resumePublicTrading

1
function resumePublicTrading(address poolAddress)
Copied!
Resumes public trading and liquidity providing on an index pool.

removeTokenFromPool

1
function removeTokenFromPool(
2
address poolAddress,
3
address tokenAddress
4
)
Copied!
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.

Category Management

createCategory

1
function createCategory(bytes32 metadataHash)
Copied!
Create a new token category.

addToken

1
function addToken(address token, uint256 categoryID)
Copied!
Adds a new token to a category. Note: A token can only be assigned to one category at a time.

addTokens

1
function addTokens(uint256 categoryID, address[] tokens)
Copied!
Add tokens to a category.

orderCategoryTokensByMarketCap

1
function orderCategoryTokensByMarketCap(uint256 categoryID, address[] orderedTokens)
Copied!
Sorts a category's tokens in descending order by market cap. Verifies the order of the provided array by querying the market caps.

Pool Rebalancing

reindexPool

1
function reindexPool(address poolAddress)
Copied!
Re-indexes a pool by setting the underlying assets to the top tokens in its category by market cap.

reweighPool

1
function reweighPool(address poolAddress)
Copied!
Reweighs the assets in a pool by market cap and sets the desired new weights, which will be adjusted over time.

setMinimumBalance

1
function setMinimumBalance(
2
IPool pool,
3
address tokenAddress
4
)
Copied!
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.

Pool Queries

defaultSellerPremium

1
function defaultSellerPremium() returns (uint256 defaultSellerPremium)
Copied!
Default premium percent for index pool's unbound token sellers.

computeInitializerAddress

1
function computeInitializerAddress(address poolAddress) returns (address initializerAddress)
Copied!
Compute the create2 address for a pool initializer.

computePoolAddress

1
function computePoolAddress(uint256 categoryID, uint256 indexSize) returns (address poolAddress)
Copied!
Compute the create2 address for a pool.

getInitialTokenWeightsAndBalances

1
function getInitialTokenWeightsAndBalances(
2
uint256 categoryID,
3
uint256 indexSize,
4
uint256 wethValue
5
) returns (address[] tokens, uint96[] denormalizedWeights, uint256[] balances)
Copied!
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.

getInitialTokensAndBalances

1
function getInitialTokensAndBalances(
2
uint256 categoryID,
3
uint256 indexSize,
4
uint256 wethValue
5
) returns (address[] tokens, uint256[] balances)
Copied!
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.

Market Cap Queries

computeAverageMarketCap

1
function computeAverageMarketCap(
2
address token
3
) returns (uint144 marketCap)
Copied!
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.

computeAverageMarketCaps

1
function computeAverageMarketCaps(
2
address[] tokens
3
) returns (uint144[] marketCaps)
Copied!
Returns the average market cap for each token.

Category Queries

categoryIndex

1
function categoryIndex() returns (uint256 categoryID)
Copied!
Number of categories in the oracle.

hasCategory

1
function hasCategory(uint256 categoryID) returns (bool)
Copied!
Returns a boolean stating whether a category exists.

getCategoryTokens

1
function getCategoryTokens(
2
uint256 categoryID
3
) returns (address[] tokens)
Copied!
Returns the array of tokens in a category.

getCategoryMarketCaps

1
function getCategoryMarketCaps(
2
uint256 categoryID
3
) returns (uint144[] marketCaps)
Copied!
Returns the market capitalization rates for the tokens in a category.

getTopCategoryTokens

1
function getTopCategoryTokens(
2
uint256 categoryID,
3
uint256 num
4
) returns (address[] tokens)
Copied!
Get the top num tokens in a category. Note: The category must have been sorted by market cap in the last MAX_SORT_DELAY seconds.
Last modified 10mo ago