Skip to content

Replenish the OUSD Vault idle buffer through Talos - #3069

Closed
naddison36 wants to merge 5 commits into
masterfrom
codex/ousd-withdrawal-vault-buffer
Closed

naddison36 wants to merge 5 commits into
masterfrom
codex/ousd-withdrawal-vault-buffer

Conversation

@naddison36

Copy link
Copy Markdown
Collaborator

With a nonzero OUSD Vault buffer and no withdrawal queue shortfall, the current auto-withdrawal module does nothing and leaves the idle buffer depleted. The replacement funds all queued, unclaimed withdrawals plus the configured idle buffer, subtracting existing Vault USDC and capping the withdrawal at the strategy's reported balance. It uses the same supply percentage and decimal rounding as Vault allocation.

  • Replace pendingShortfall() with targetBuffer() and liquidityShortfall().
  • Update otokenOusdAutoWithdrawal logging and load the module through a curated ABI.
  • Add unit/fuzz coverage for six- and eighteen-decimal assets, queue reservations, partial liquidity, and repeated calls; add action tests and live-strategy smoke coverage.

Deployment 016_AutoWithdrawalBuffer deploys only a replacement AutoWithdrawalModule, retaining the existing Safe and strategy and granting the Talos relayer the operator role. No core Vault/token upgrade or role reassignment is required. The Safe must enable the replacement, disable the old module, and call Vault.setVaultBuffer(1e16) for 1%. These Safe transactions are simulated in _fork(), not broadcast by the deploy script.

Talos impact: make deploy-mainnet refreshes deployments/mainnet/AutoWithdrawalModule.json; ship that address descriptor and the new abi/AutoWithdrawalModule.json in the runner image after Safe activation, and update any explicit --module override. The pinned old-module address in the deploy script is intentionally retained for retirement; no action-local or utils/addresses.js address update is needed. The existing twice-daily schedule remains unchanged, so withdrawals can consume the buffer between runs. Strategy withdrawals retain the existing soft-failure handling when immediately available liquidity is insufficient.

Validation:

  • 27 Foundry unit tests passed, including two fuzz tests with 1,024 runs each.
  • 4 action tests passed.
  • 8 Ethereum fork smoke tests passed, including real strategy replenishment and Safe module replacement.
  • Contract/deployment builds, targeted formatting/lint checks, and the repository pre-commit checks passed.

@shahthepro

Copy link
Copy Markdown
Collaborator

The module sends the queue shortfall and the buffer top-up as one withdrawal, capped only by checkBalance(). On MorphoV2Strategy, checkBalance() counts funds the Morpho vault can't release yet, and withdraw reverts when the amount is more than the available liquidity. Say the queue shortfall is 50k, the buffer deficit is 560k, and the Morpho liquidity is 300k. The module asks for 610k, the Safe exec fails, and WithdrawalFailed fires. The queue gets nothing, though 50k was available. This repeats on every run until liquidity covers queue plus buffer. The old module would have withdrawn the 50k, and this also breaks the "withdrawals take priority" rule in ACTIONS.md.

I'd fund the queue shortfall first, then try the buffer top-up as a separate best-effort withdrawal. Capping at the strategy's maxWithdraw() where it has one would also work. Please add a unit test where the mock strategy has liquidity between the queue amount and queue plus buffer. The current test_fundWithdrawals_partialLiquidityFundsQueueBeforeBuffer only covers the checkBalance cap.

// Step 2: Reserve all outstanding withdrawals, then target the idle buffer.
uint256 shortfall = liquidityShortfall();

if (shortfall == 0) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After a run, idle USDC sits exactly at targetBuffer(), so every rebase that grows totalSupply leaves a tiny shortfall. With a 1% buffer, about 1e14 wei of OUSD growth already creates a 1-wei USDC gap. Almost every run then calls withdrawFromStrategy for a few USDC, which costs extra strategy gas for no real benefit. Add a minimum buffer deficit, for example a percentage of the target, and only top up the buffer once the gap passes it. Keep funding the withdrawal queue shortfall in full, whatever its size.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in d77faf5e3. The threshold is enforced in Talos through bufferThreshold, defaulting to 100 bps (1% of the target buffer), rounded up to the asset's smallest unit. Buffer-only runs skip both simulation and submission when the deficit, or the withdrawal after the strategy-balance cap, is below that minimum. Queue funding is exempt regardless of size and can include buffer replenishment in the same transaction. Fully funded targets also skip. Added coverage for threshold boundaries, rounding, configurable percentages, strategy caps, and tiny queue deficits.

}

return await getContract("AutoWithdrawalModule");
// Descriptors supply addresses; the curated ABI also includes buffer views.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The action calls liquidityShortfall() and targetBuffer() every run. The module in deployments/mainnet/AutoWithdrawalModule.json (0x90d588fc…2ae5) only has pendingShortfall(). So before deploy 016, the read reverts and no withdrawals get funded. After make deploy-mainnet updates the descriptor but before the Safe runs enableModule, fundWithdrawals() reverts with GS104 inside the Safe. That is a hard revert, so the soft-failure path is skipped, and the old module that is still enabled is never called. We should pause the Talos action and do the deployment, enable the module on the Safe and then unpause the action for a smoother transition

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in c72332fbf. Added an explicit rollout checklist to deploy 016 and ACTIONS.md: pause the action and drain any in-flight run before releasing the new code, deploy, enable the replacement/disable the old module and set the buffer on the Safe, ship the updated runner descriptor/ABI, verify simulation, then resume and run manually.

The action now checks isModuleEnabled(module) on module.safeContract() before reading the new buffer views, and throws an explicit activation error without simulating or sending if disabled. Tests cover disabled modules and activation-check failures. There is no legacy-module fallback; the coordinated rollout is still required because an enabled old module lacks the new API.

function test_targetBuffer_matchesVaultAllocation() public view {
IVault vault = IVault(autoWithdrawalModule.vault());
uint256 supply = IOToken(vault.oToken()).totalSupply();
assertEq(vault.vaultBuffer(), 1e16);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assertEq(vault.vaultBuffer(), 1e16) only passes because _fork() pranks setVaultBuffer(1e16). After 016 is marked done, _fork() stops running, so any Strategist change to the buffer will fail mainnet smoke CI, even though the formula check right after it would still pass. Before execution, this assert also passes even if the Safe never enabled the module, so it proves nothing about the deployment. I'd drop the pin and keep the formula equality, or assert vaultBuffer() > 0 and check that the module is enabled on the Safe.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 7921314b3. Removed the fixed 1% assertion and retained the formula equality against the Vault's configured buffer, including zero. Added a separate test_moduleEnabled() check on the module's Safe. The exact 1% assertion remains in deploy 016's _fork() to verify the intended initial setup.

The smoke checks observe simulated activation while deploy 016 is pending, and live fork state once the deployment is marked complete. All 9 focused Ethereum fork smoke tests passed.

@naddison36

Copy link
Copy Markdown
Collaborator Author

@shahthepro, addressed the queue-versus-buffer liquidity issue from this comment in e00ee5ae3.

Talos now simulates fundWithdrawals(true) first, then fundWithdrawals(false) if combined funding fails and the queue needs funding. It submits only the successful mode as one transaction, or sends none if both simulations fail. The module returns a boolean so a failed Safe execution is detected even when the module call itself does not revert. There is no second on-chain withdrawal attempt.

Added the 50k queue / 560k buffer / 300k available-liquidity regression, plus action tests for reverted and soft-failed simulations, queue-only fallback, and no submission when both modes fail.

@naddison36

Copy link
Copy Markdown
Collaborator Author

This change has got way bigger than the original intention. Closing for now

@naddison36 naddison36 closed this Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants