|
| 1 | +# iCKB Deposit Pool Rebalancing Algorithm |
| 2 | + |
| 3 | +For simplicity, let's model: |
| 4 | + |
| 5 | +- NervosDAO 180 epoch cycle as a circular clock. |
| 6 | +- Current Tip Header Epoch as the the clock needle. |
| 7 | +- iCKB Deposits as coins scattered continuously along the clock perimeter. |
| 8 | +- iCKB Deposit Pool size as the total coins. |
| 9 | +- Making an iCKB Deposit into the Pool as depositing a coin. |
| 10 | +- Withdrawing an iCKB Deposit from the Pool as picking up a coin. |
| 11 | + |
| 12 | +## Environment |
| 13 | + |
| 14 | +- **Setting Idea:** A circular clock with coins scattered continuously along the perimeter. The environment deterministically over time sets the direction in which the agent is looking at, the one pointed by the needle. |
| 15 | +- **Dynamics:** Our agent can only interact with coins pointed by the needle. External parties can add or remove coins arbitrarily, so the total coins `N` may change over time. |
| 16 | + |
| 17 | +## Agent Details |
| 18 | + |
| 19 | +- **Position:** Center of the circle, facing a specific segment of the perimeter. |
| 20 | +- **Action:** Operates in discrete snapshots, snapshots occur at regular intervals. |
| 21 | +- **Container:** Holds `m` coins up to a capacity `M`. |
| 22 | +- **Memory:** None (each snapshot is processed independently). |
| 23 | + |
| 24 | +## Overall Objectives |
| 25 | + |
| 26 | +- **Uniformity:** Aim for a reasonably uniform coin distribution across the perimeter. |
| 27 | + |
| 28 | +- **Minimize Re-shuffling:** Minimize coin re-shuffling when external parties add or remove coins by using a robust representation. |
| 29 | + |
| 30 | +- **Maximize Holdings:** Maximize the coins held by the agent (up to `M`). |
| 31 | + |
| 32 | +## Perimeter Segmentation |
| 33 | + |
| 34 | +- **Free Coins:** `O = N + m - M`, which accounts for the total coins available minus the agent's capacity. This way `O` is independent from the coins held by agent. |
| 35 | + |
| 36 | +- **Segmentation Function:** Total segments = `2^(ceil(log2(O)))`. Each segment have the same length and it can be indexed (0,1,2...) starting from an absolute origin that remains unchanged across snapshots. Segmentation is recalculated at every snapshot, so coins placed previously may change immediately the segment they belong to. Segment evaluation cycles modulo `O`: 0, 1, 2, … `O` - 1 and then repeats. |
| 37 | + |
| 38 | +- **Segment Priority:** |
| 39 | + - **High-Priority Segments:** Odd-numbered segments (indices 1,3...) are High-Priority and at equilibrium each must have exactly one coin. |
| 40 | + - **Low-Priority Segments:** Even-numbered segments (indices 0,2...) are Low-Priority and at equilibrium each must have either one or zero coins. |
| 41 | + - **Visual Idea:** We can visualize this segmentation prioritization as the alternating colors of the outer rim of a circular Dart Board. |
| 42 | + |
| 43 | +## Strategy and Dynamics |
| 44 | + |
| 45 | +Given a snapshot, segmentation recalculation always occurs prior to action decisions. Agent actions are greedy (taken as soon as available) to minimize disruptions from other agents, which modify the system state outside of our agent control. |
| 46 | + |
| 47 | +### General Pick-up Rules |
| 48 | + |
| 49 | +- Never pick up the last coin of an High-Priority Segment. |
| 50 | +- Pick up coins from each segment sequentially, starting with the coin nearest the segment’s beginning and proceeding toward its end. Within any stack of coins at the same position, pick them from the top down. Leave the last segment coin in place if applicable. |
| 51 | + |
| 52 | +### General Deposit Rules |
| 53 | + |
| 54 | +- When depositing a coin, deposit it as close as possible to the end of the chosen segment, while still staying in the right segment by a reasonably small margin. This margin size is snapshot-based, extremely small relative to segment size. This ensures that if resolution increases and the interval is subdivided, the coin remains in the high-priority portion. |
| 55 | + |
| 56 | +### Initial State: Non-Equilibrium |
| 57 | + |
| 58 | +**State:** |
| 59 | + |
| 60 | +- At least one High-Priority Segment has zero coins. |
| 61 | +- Some segments have multiple coins. |
| 62 | + |
| 63 | +**Pick-up Strategy:** Follow general rules for multiple coins in one segment. If no segments with multiple coins exist, pick up coins from Low-Priority Segments. |
| 64 | + |
| 65 | +**Deposit Strategy:** Deposit a coin when an High-Priority Segment is empty and the agent has coins. |
| 66 | + |
| 67 | +### Intermediate Target: Near Equilibrium |
| 68 | + |
| 69 | +**State:** |
| 70 | + |
| 71 | +- All High-Priority Segments have at least one coin. |
| 72 | +- Some segments have multiple coins. |
| 73 | + |
| 74 | +**Pick-up Strategy:** Follow general rules for multiple coins in one segment. |
| 75 | + |
| 76 | +**Deposit Strategy:** Deposit a coin when a Low-Priority Segment is empty and the agent has coins. |
| 77 | + |
| 78 | +### Final Target: Equilibrium |
| 79 | + |
| 80 | +**State:** |
| 81 | + |
| 82 | +- All High-Priority Segments have exactly one coin. |
| 83 | +- All Low-Priority Segments have exactly one or zero coins. |
| 84 | + |
| 85 | +**Pick-up Strategy:** Pick up coins from Low-Priority Segments until the agent has `M` coins. |
| 86 | + |
| 87 | +**Deposit Strategy:** None. |
| 88 | + |
| 89 | +### Dynamics |
| 90 | + |
| 91 | +- If Segmentation resolution increases (due to increased `O`), deposited coins in previous snapshots (placed at the end of segments) automatically fall into the High-Priority portions of their new subdivided segments. |
| 92 | +- If Segmentation resolution decreases (due to decreased `O`), previous high and low priority segments naturally merge into the lower resolution segments. |
| 93 | +- The system adapts at each snapshot to reach uniformity and priority requirements, gaining stability. Oscillatory behaviors (frequent pick-ups and deposits) are prevented as much as possible by a smart segmentation. |
0 commit comments