fix(llm): model Yearn V3 update_debt as a capped target through the batch - #397
Merged
Merged
Conversation
…atch The Yearn V3 context printed update_debt as "deposits target − current_debt; idle now <pre-batch idle>". For the Cap multisig batch (nonce 252) that exits 26.9M USDC from two Morpho strategies and sets Aave's target to 50M, the prompt said "deposits 50,000,000 USDC; idle now 0 USDC" after each step, and the model reported a funding gap and a HIGH risk that cannot exist — the vault deposits only the 26.93M it holds. It also misread use_default_queue =False as "automatic use of the default queue is disabled". - utils/llm/yearn_v3_batch.py: mirrors the vault's _update_debt over a running state (idle, minimum_total_idle, shutdown, per-strategy debt/max debt/maxDeposit/redeemable), so each call is described against what the earlier calls leave. - yearn_v3_context: reads maxDeposit(vault) and convertToAssets(maxRedeem (vault)) for named strategies; update_debt lines show the amount moved, what limited it, and idle before → after; cap and revoke lines use the running state; the semantics line explains targets and use_default_queue. - A ceiling above the vault's size is flagged as a ceiling, not a deposit. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The Yearn V3 context line for
update_debttreated the target as an amount. It printeddeposits (target − current_debt)and always showed the pre-batch idle.Real case: the Cap multisig
0xb8FC49402dF3ee4f8587268FB89fda4d621a8793, nonce 252, calling the capUSDC vault0x3Ed6aa32c930253fc990dE58fF882B9186cd0072. The batch withdraws 26.9M USDC from two Morpho strategies and sets Aave's target to 50M. The prompt said "deposits 50,000,000 USDC; idle now 0 USDC", even right after the withdrawals. The model then reported "Aave's 50,000,000 USDC target exceeds the vault's reported 26,930,230.66 USDC in assets; reconcile the simulated funding" and rated it HIGH.That gap cannot exist. The vault's
_update_debtcaps a deposit bymax_debt, the strategy'smaxDeposit, and idle aboveminimum_total_idle. Its docstring says to pass a large target to allocate as much idle as possible. Aave receives the 26.93M the vault holds.The model also said the queue reorder was inert because
use_default_queue=False. That's wrong:_redeemuses the default queue unless the withdrawer passes a custom one, and the flag only decides whether custom queues are allowed.Change
utils/llm/yearn_v3_batch.py(new): mirrors the vault's_update_debt(3.0.x/3.1.x) over a running copy of the vault state. Each call is described against what the earlier calls in the batch leave.minimum_total_idleand are capped by what the strategy can redeem.max_debt; the amount is capped bymaxDepositand by idle aboveminimum_total_idle.utils/llm/yearn_v3_context.py:maxDeposit(vault)andconvertToAssets(maxRedeem(vault))for the strategies the calls name.update_debtlines give the amount moved, what limited it, and vault idle before → after.use_default_queuereally means.utils/llm/README.md: documents the model.Rendered live against the real batch:
Verification
uv run pytest tests/: 1611 passed, 6 skipped.tests/test_yearn_v3_batch.pycovers the model: idle and minimum-idle caps,maxDeposit, withdrawals feeding later deposits, raising a withdrawal to restore minimum idle, shutdown, revoked strategies, case-insensitive addresses.TestBatchDebtAccountingcovers the Cap batch end to end, redeem-limited withdrawals,max_debt-limited deposits, the equal-target revert, an unregistered strategy, force-revoke after a withdrawal, and the prompt semantics.test_update_debt_moves_funds_nowasserted the bug itself: a 79 WETH deposit into a vault with 0 idle. It is replaced by a no-idle case and a funded case.ruff formatandruff checkare clean; mypy shows no errors in the two modules.Not in scope: the report also missed what OndoHolder does. It converts USDC to Ondo rUSDY (a KYC-gated tokenized-treasury RWA), and both subscribe and redeem pass a minimum output of 0. Explaining new strategies from their source is a separate improvement.
🤖 Generated with Claude Code