Consider APY impact for deposits#2857
Conversation
clement-ux
left a comment
There was a problem hiding this comment.
A few questions on the new APY-impact path. Not blocking — mostly want to confirm intent.
contracts/utils/rebalancer.js
Outdated
| let best = { maxDeposit: BigNumber.from(0), impactBps: 0, postDepositApy: 0 }; | ||
|
|
||
| while (hi.sub(lo).gt(step)) { | ||
| const mid = lo.add(hi).div(2).div(step).mul(step); // round to step |
There was a problem hiding this comment.
I think the binary search collapses to zero on small ranges. With step = $100K and lo = $5K, say maxAmt = $150K and the fast path failed:
iter 1: mid = (5K + 150K) / 2 = 77.5K → /100K * 100K = 0 → mid.lt(lo) → break
returns { maxDeposit: 0 }
So any strategy with maxPossible below ~2 * step ($200K) whose full amount fails the impact check always returns zero, even when $50K or $100K would have been fine. The fast path gets one shot; if it fails the search can't make forward progress.
Also best starts at zero and only updates inside the impactBps <= max branch, so if the first probe is over the threshold and the loop exits, we return zero without ever probing lo itself. The implicit "minMoveAmount is always acceptable" assumption never gets verified.
Probably matters most for the smaller cross-chain strategies (Base/HyperEVM) where target allocations could routinely sit in that <$200K range.
A few ways out: skip the search entirely below 2 * step, shrink the step when the range is narrow, or just probe lo as a final fallback before giving up.
There was a problem hiding this comment.
I think this is something we will run with almost any step amount. Right now, I set it to 100k because we barely have 4mil in TVL. Reducing that to 50k or even 10k would cover the case all the time but it'll go through more iterations on the binary search. I'll check if any of the options you listed would work
There was a problem hiding this comment.
Oh wait, I misunderstood this one. Will fix this
There was a problem hiding this comment.
I changed the logic to use a different step if the range is too narrow: 644d180
Code Changes