Repository navigation
Commit fba8d42
authored
fix: Retargetter rebalance path and flash-loan callback hardening (#209)
* fix: harden Retargetter rebalance path and flash-loan callback
- rebalance: totalAssets must not grow while the operation's Request is
unrepaid and short of its deadline (value-conservation gate, all callers)
- rebalance: a module above target only reverts when it worsened, so an
untouched module no longer blocks the other legs
- onFlashLoan: bound to the payload committed at the window open (transient
digest) and to full delivery of the principal (pre-loan balance snapshot)
* fix: measure bridge value on the whole book and scope window authority to the payload
The value-conservation gate read the position manager's totalAssets, which
drops any module whose debt exceeds its collateral, so it read flat while
bridge capital was poured into an underwater module. It now measures quoted
collateral minus debt summed over every module (PositionValueIncreased).
Window step authority moved from the whole flash-loan call into the callback
around the committed payload, so a module holds no authority in its own frame
and cannot source the delivery check's balance growth from the position
manager itself.
* refactor: read the Request through syncRepaidStatus and store the payload digest as a uint
The value gate derived the effective repaid state from the mirrored deadline
plus the stale repaid flag; syncRepaidStatus returns exactly that disjunction
and folds a past-deadline Request into the flag, the same idiom resolve uses.
The payload digest now goes through the existing tStoreUint/tLoadUint, so
LibTransientSlot is untouched by this PR.
* perf: read the position aggregates once per rebalance snapshot
_positionSnapshot returns the aggregate LTV and the net value from a single
read of collateralAmountQuoted/debtAmount, replacing the two helpers that each
re-read the pair. The post-call check hands the LTV back to the direction
checks so they do not read it again, which also keeps valueAfter off the
rebalance stack (it would otherwise re-trigger stack-too-deep).
Halves the module iterations on the rebalancer path (8 to 4) and drops the
runtime size by 169 bytes.
* docs: point the rebalance NatSpec at the renamed value-gate helpers1 parent deb7130 commit fba8d42
9 files changed
Lines changed: 604 additions & 60 deletions
File tree
- src
- interfaces/manager/rebalancer
- libs/manager/rebalancer
- manager/rebalancer
- test
- manager/rebalancer
- mock/manager/rebalancer
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
251 | 251 | | |
252 | 252 | | |
253 | 253 | | |
254 | | - | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
255 | 259 | | |
256 | 260 | | |
257 | 261 | | |
| |||
276 | 280 | | |
277 | 281 | | |
278 | 282 | | |
279 | | - | |
280 | | - | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
281 | 287 | | |
282 | 288 | | |
283 | 289 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
116 | 116 | | |
117 | 117 | | |
118 | 118 | | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
124 | 126 | | |
125 | 127 | | |
126 | 128 | | |
| |||
132 | 134 | | |
133 | 135 | | |
134 | 136 | | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
135 | 151 | | |
136 | 152 | | |
137 | 153 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
71 | | - | |
| 71 | + | |
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
75 | 84 | | |
76 | 85 | | |
77 | 86 | | |
| |||
99 | 108 | | |
100 | 109 | | |
101 | 110 | | |
102 | | - | |
| 111 | + | |
| 112 | + | |
103 | 113 | | |
104 | 114 | | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
105 | 119 | | |
106 | 120 | | |
107 | 121 | | |
| |||
0 commit comments