Rebalance
SingleIndexModule.sol
Module that facilitates rebalances for indices. Manager can set target unit amounts, max trade sizes, the exchange to trade on, and the cool down period between trades (on a per asset basis) for the sake of rebalancing the assets. As currently constructed the module only works for one Set at a time.
initialize
Initializes this module to the SetToken. Only callable by the SetToken's manager.
_index Address of index being used for this Set
startRebalance
Set new target units, zeroing out any units for components being removed from index. Log position multiplier to adjust target units in case fees are accrued. Validate that weth is not a part of the new allocation and that all components in current allocation are in _components
array. Considered administrative function, hence to be called my Manager only
_newComponents Array of new components to add to allocation
_newComponentsTargetUnits Array of target units at end of rebalance for new components, maps to same index of component
_oldComponentsTargetUnits Array of target units at end of rebalance for old component, maps to same index of component. Set to 0 if component being removed.
_positionMultiplier Position multiplier when target units were calculated, needed in order to adjust target units
trade
Only approved addresses can call if anyoneTrade
is false. Determines trade size and direction and swaps into or out of WETH on exchange specified by manager.
_component Component to trade
tradeRemainingWETH
Only approved addresses can call if anyoneTrade is false. Only callable when
There are no more components to be sold (i.e. being on the buying phase of the rebalance).
Entire remaining WETH amount can be traded such that resulting inflows won't exceed components maxTradeSize nor overshoot the target unit. To be used near the end of rebalances when a component's calculated trade size is greater in value than remaining WETH.
_component Component to trade
raiseAssetTargets
Only allowed trader can call this function. For situation where all target units met and SetToken still holds some remaining WETH, uniformly raise targets by same percentage in order to allow further trading. Can be called multiple times if necessary, increase should be small in order to reduce tracking error.
setTradeMaximums
Set trade maximums for passed components. Only called by Manager.
_components Array of components
_tradeMaximums Array of trade maximums mapping to correct component
setExchanges
Set a uniswap-like decentralized exchanges for passed components. Only called by Manager.
_components Array of components
_exchanges Array of exchanges mapping to correct component, uint256 used to signify exchange
setCoolOffPeriods
Set the coolOfffPeriod for components. It is needed in order to make sure enough time has elapsed since component's last trade. Only callable by Manager.
_components Array of components
_coolOffPeriods Array of cool off periods to correct component
updatetraderstatus
Toggle ability for passed addresses to trade from current state. Only called by Manager.
_traders Array trader addresses to toggle status
_statuses Booleans indicating if matching trader can trade
updateAnyoneTrade
Toggle whether anyone can trade, bypassing the traderAllowList. Only called by Manager.
_status Boolean indicating if anyone can trade
getTargetUnits
Get target units for passed components, normalized to current positionMultiplier.
_components Array of components to get target units for
return Array of targetUnits mapping to passed components
getRebalanceComponents
Get the target components aimed to be rebalanced (i.e. result of a prior call of startRebalance
)
Last updated