Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2835 +/- ##
==========================================
+ Coverage 49.21% 51.66% +2.45%
==========================================
Files 112 113 +1
Lines 4844 4916 +72
Branches 1343 1362 +19
==========================================
+ Hits 2384 2540 +156
+ Misses 2456 2372 -84
Partials 4 4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
sparrowDom
left a comment
There was a problem hiding this comment.
Not done yet left comments inline
naddison36
left a comment
There was a problem hiding this comment.
I think we need to whitelist what strategies the RebalancerModule can automatically deposit/withdraw to/from. I'm mostly worried about AMO strategies being accidentally being called without a vault value checker.
sparrowDom
left a comment
There was a problem hiding this comment.
Left some comments inline: This code is much easier to follow now. Thanks it is a great improvement
| ]; | ||
|
|
||
| // Return the action amount, capping cross-chain moves at the bridge limit | ||
| const actionAmount = (a) => { |
There was a problem hiding this comment.
nit: maybe cappedAmount would be a better name
| // All withdrawals are same-chain: freed USDC lands in the vault immediately, | ||
| // so withdrawals and deposits can be batched into a single transaction. | ||
| await executeTx(() => | ||
| rebalancerModule.processWithdrawalsAndDeposits( |
There was a problem hiding this comment.
nit: the on-chain contract could have just the processWithdrawalsAndDeposits function exposed. And have empty arrays passed when there would be no deposits or no withdrawals.
There was a problem hiding this comment.
That's a good point, the safe module already behaves that way when you call that processWithdrawalsAndDeposits method. Will drop the other two methods
There was a problem hiding this comment.
It simplified the code even further, thank you: 4a0a253
| shortfall, | ||
| constraints | ||
| ) { | ||
| const totalRebalancable = strategies.reduce( |
There was a problem hiding this comment.
Should minDefaultStrategyBps be excluded from totalRebalancable?
There was a problem hiding this comment.
I believe that'll complicate the script further. If we are subtracting that here, we should also subtract it from the defaultStrategy's balance when we query it. Otherewise, if the default strategy has less than the amount we subtract here, it might end with us having a few more conditional statements (like subtracting it from other strategies). I'm not sure if that's gonna work
| /** | ||
| * Compute total capital minus reserved amounts (shortfall + minVaultBalance). | ||
| */ | ||
| function _computeDeployableCapital( |
There was a problem hiding this comment.
This code is much better readable from the last time. Great improvement 👍
|
|
||
| const sorted = [...strategies] | ||
| .filter((s) => s.address !== defaultStrategy.address) | ||
| .sort((a, b) => (targets[b.address].gt(targets[a.address]) ? 1 : -1)); |
There was a problem hiding this comment.
So the sort mechanics here is to sort by the amount to be deposited. Would it make sense to sort by the APY strategy is earning instead?
Otherwise we might always deduct from the strategy having the largest amount deposited which might also be the one earning the highest APY.
There was a problem hiding this comment.
I thought of doing it by APY at first. But then if we are allocating it by APY, the lower APY strategies will have less liquidity. So, it means that they may not have enough liquidity to fund from a single strategy. So, it'll involve multiple withdraws from lower APY strategy, which would only make it gas expensive
| .filter((a) => a.action === ACTION_DEPOSIT) | ||
| .sort((a, b) => b.apy - a.apy); | ||
|
|
||
| for (const c of deposits) { |
There was a problem hiding this comment.
nit: instead of c this could be named deposit
| } | ||
|
|
||
| const amt = c.delta.gt(budget) ? budget : c.delta; | ||
| budget = budget.sub(amt); |
There was a problem hiding this comment.
Shouldn't this budget subtraction happen after the additional if statement checks below that result in a continue? Budget is reduced even when the action can be invalidated by setting it to ACTION_NONE
| const hasApprovedWithdrawals = result.some( | ||
| (a) => a.action === ACTION_WITHDRAW | ||
| ); | ||
| if (!hasApprovedWithdrawals && shortfall.gt(0)) { |
There was a problem hiding this comment.
could it be that there are approved withdrawals that don't withdraw enough to cover the shortfall?
There was a problem hiding this comment.
Right now, the rebalancer cannot directly move between strategies. So, if it has to move between strategies, it has to withdraw to Vault first and then to the other strategy (either in a single run or across multiple runs). So, if there's a withdraw action, it'll always cover the withdrawal shortfall
* Consider APY impact for deposits * Fix config issues * Bug fixes * Bug fix * bug fix * few more tweaks * Switch to using subsquid server * APY Impact solver * Fix available liquidity * Address CR comments
Code Changes
RebalancerModulewith methods to process deposits, withdrawals or both (in withdrawals -> deposits order). It will be replacing the existingAutoWithdrawalModuleplanRebalancethat prints the optimal allocations and recommended actionsExecuting Hardhat task
Pending Things
Monitoring: Discord NotificationsDone in d50c610