@@ -617,6 +617,51 @@ contract GeneralIndexModule is ModuleBase, ReentrancyGuard {
617
617
618
618
/* ============ Internal Functions ============ */
619
619
620
+ /**
621
+ * A rebalance is a multi-step process in which current Set components are sold for a
622
+ * bridge asset (WETH) before buying target components in the correct amount to achieve
623
+ * the desired balance between elements in the set.
624
+ *
625
+ * Step 1 | Step 2
626
+ * -------------------------------------------
627
+ * Component --> WETH | WETH --> Component
628
+ * -------------------------------------------
629
+ *
630
+ * The syntax we use frames this as trading from a "fixed" amount of one component to a
631
+ * "fixed" amount of another via a "floating limit" which is *either* the maximum size of
632
+ * the trade we want to make (trades may be tranched to avoid moving markets) OR the minimum
633
+ * amount of tokens we expect to receive. The different meanings of the floating limit map to
634
+ * the trade sequence as below:
635
+ *
636
+ * Step 1: Component --> WETH
637
+ * ----------------------------------------------------------
638
+ * | Fixed | Floating limit |
639
+ * ----------------------------------------------------------
640
+ * send (Component) | Yes | |
641
+ * recieve (WETH) | | Maximum trade size |
642
+ * ----------------------------------------------------------
643
+ *
644
+ * Step 2: WETH --> Component
645
+ * ----------------------------------------------------------
646
+ * | Fixed | Floating limit |
647
+ * ----------------------------------------------------------
648
+ * send (WETH) | NO | |
649
+ * recieve (Component) | | Min amount to receive |
650
+ * ----------------------------------------------------------
651
+ *
652
+ * Additionally, there is an edge case where price volatility during a rebalance
653
+ * results in remaindered WETH which needs to be allocated proportionately. In this case
654
+ * the values are as below:
655
+ *
656
+ * Edge case: Remaing WETH --> Component
657
+ * ----------------------------------------------------------
658
+ * | Fixed | Floating limit |
659
+ * ----------------------------------------------------------
660
+ * send (WETH) | YES | |
661
+ * recieve (Component) | | Min amount to receive |
662
+ * ----------------------------------------------------------
663
+ */
664
+
620
665
/**
621
666
* Create and return TradeInfo struct. This function reverts if the target has already been met.
622
667
* If this is a trade from component into WETH, sell the total fixed component quantity
0 commit comments