Function: _processInternalTrades(BasketManagerStorage self, InternalTrade[] internalTrades, address[] baskets, uint256[][] basketBalances)
This function handles the processing of internal trades.
Inputs
selfControl: Controlled by the
proposeTokenSwapfunction.Constraints: None.
Impact: The storage reference.
internalTradesControl: Controlled by the
proposeTokenSwapfunction.Constraints: None at this level.
Impact: The internal trades to be processed.
basketsControl: Controlled by the
proposeTokenSwapfunction.Constraints: None at this level.
Impact: The baskets that are being rebalanced.
basketBalancesControl: Controlled by the
proposeTokenSwapfunction.Constraints: None at this level.
Impact: The basket's balances.
Branches and code coverage
Intended branches
Assume that the trades are most efficiently ordered. This is not enforced in code, and responsibility for this comes from the proposer.
Calculate the fee on the
sellAmount(if any).Calculate the fee on the
buyAmount(if any).Calculate the initial
buyAmountbased onnetSellAmountthrough the EulerRouter.Update the basket balances based on the trade.
Negative behavior
Should not allow the
initialBuyAmountto be greater than the balance of the token in the basket.Should not allow having a
netBuyAmountless than theminAmountor greater than themaxAmount.Should not allow the
sellAmountto be greater than the balance of the token in the basket.