Function: proposeTokenSwap(BasketManagerStorage self, InternalTrade[] internalTrades, ExternalTrade[] externalTrades, address[] baskets, uint64[][] basketTargetWeights)
This function allows the proposal of token swaps to rebalance the given baskets. If the proposed token swap results are not close to the target balances, this function will revert.
Inputs
self
Control: Fully controlled by the calling function.
Constraints: None.
Impact: The storage reference.
internalTrades
Control: Fully controlled by the calling function.
Constraints: None at this level — some checks are performed in
_processInternalTrades
.Impact: The list of internal trades to be processed. Assumed to be correct and valid as well as most optimally ordered.
externalTrades
Control: Fully controlled by the calling function.
Constraints: None at this level — some checks are performed in
_validateExternalTrades
.Impact: The list of external trades to be processed. Assumed to be correct and valid as well as most optimally ordered.
baskets
Control: Fully controlled by the calling function.
Constraints: The baskets' hash and target weights are validated against the stored
basketHash
.Impact: The lists of baskets for which the token swap is proposed. Assumed to be correct and valid.
basketTargetWeights
Control: Fully controlled by the calling function.
Constraints: The target weights are validated against the baskets that are to be rebalanced.
Impact: The target weights for each basket. Assumed to be correct and valid.
Branches and code coverage
Intended branches
Validate the basket hash against the storage one so that no arbitrary trades are processed.
Initialize the basket data.
Update the storage with the new rebalance status as well as the external trades hash.
Process the internal trades and validate the external ones.
Estimate whether the target weights would theoretically be met.
Negative behavior
Should not allow empty internal and external trades.
Should not allow proposing a token swap if the status is not
REBALANCE_PROPOSED
.Should revert if the target weights are not met.