Function findOptimalWithdrawalsVolatile

  • The strategy is to examine the position after we have withdrawn the units.

    Let N be the number of non-zero elements of units. IF either of the new differences are negative, rebalance with exactly N swaps. This is done by sorting the imbalance and doing the following: Filter deficit by selecting only non-zero elements of units. Largest excess goes into largest deficit. Subtract used difference from largest excess. New Largest excess goes into largest deficit. (excluding used index of deficit). Subtract used. repeat.

    Parameters

    Returns {
        from: number;
        to: number;
        units: bigint;
    }[]