Skip to content

fix(sim): track swap output token in wallet-balance snapshots#65

Open
dglowinski wants to merge 1 commit into
mainfrom
fix/sim-swap-output-wallet-balance
Open

fix(sim): track swap output token in wallet-balance snapshots#65
dglowinski wants to merge 1 commit into
mainfrom
fix/sim-swap-output-wallet-balance

Conversation

@dglowinski

Copy link
Copy Markdown
Collaborator

Problem

Wallet-receiving swaps (withdraw / redeem / wallet swaps) transfer the swapped-in token to the wallet via verifyAmountMinAndTransfer(asset, …). The wallet-balance snapshot discovery in buildSimulationBatch only covered touched-vault underlyings, required-approval (debited) tokens, and claim/unlock tokens — so the swap output token was never snapshotted in simulatedWalletBalances. As a result the output stayed invisible to consumers (e.g. a withdraw → swap-to-PT-AUSD feeding a multiply showed a 0 available balance), and to later wallet-sourced batch operations. extractBalanceRequirements only covers debited tokens, so it doesn't help here.

Fix

Add collectSwapWalletBalanceTokens(batch) — mirroring collectClaimWalletBalanceTokens — that decodes the verifyAmountMinAndTransfer verifier item and adds its asset to the snapshotted wallet tokens, wired into buildSimulationBatch next to the claim-token loop.

Scope: the transferMin (wallet-receive) verifier only. The deposit/skim verifier variants land output into a vault (a different balance) and are out of scope.

Test

Adds simulateTransactionPlan tracks swap-verifier wallet output tokens. Full suite green (322 tests).

🤖 Generated with Claude Code

@LeonardEulerXYZ LeonardEulerXYZ left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Reviewed head: 504e268

Verdict: Approved

Scope reviewed:

  • packages/euler-v2-sdk/src/services/executionService/simulate.ts
  • packages/euler-v2-sdk/test/simulate.test.ts

What changed:

  • Simulation wallet-balance discovery now decodes SwapVerifier verifyAmountMinAndTransfer(address,address,uint256,uint256) calls and includes the transfer asset in per-layer wallet balanceOf(owner) snapshots.
  • Added a regression test proving a transferMin swap verifier call causes the output token to be included in wallet-balance reads.

Evidence and validation:

  • Full PR diff inspected against origin/development at base 82feb80.
  • Active issue comments, formal reviews, and inline review comments inspected; there were no existing Leonard or bot comments to update or clean up.
  • Security/supply-chain sweep over the diff: no dependency, lockfile, workflow, package-export, network, secret, env, install-script, or generated-client changes; only simulation code and tests changed.
  • ABI fixture check after build: verifyAmountMinAndTransfer(address,address,uint256,uint256) selector resolves to 0xcbe0a971, the encoded calldata decodes back to verifyAmountMinAndTransfer, and arg0 is the transfer asset being added to the wallet-balance token set.
  • pnpm --filter @eulerxyz/euler-v2-sdk test -- simulate.test.ts passed. Vitest executed the package suite: 26 files / 322 tests passed.
  • pnpm --filter @eulerxyz/euler-v2-sdk typecheck passed.
  • pnpm --filter @eulerxyz/euler-v2-sdk build passed.
  • pnpm --filter @eulerxyz/euler-v2-sdk lint exited 0; it reported pre-existing warnings in unrelated src/utils/* files, not in this PR's changed files.
  • gh pr checks reported no checks on the branch.

Scalability / maintainability hygiene pass:

  • Started from the intended consumer behavior: Euler Lite stitches simulatedWalletBalances and surfaces insufficientWalletAssets; missing the swap output token means a wallet-receiving swap can be invisible to later wallet-sourced operations and wallet delta display.
  • Sibling wallet-balance discovery paths in this module were checked: touched vault assets, required wallet-balance tokens, operation-provided walletBalanceTokens, claim reward tokens, and rEUL unlock tokens. This patch fits the existing reusable discovery pattern rather than duplicating display logic downstream.
  • Sibling swap verifier flows were checked: TransferMin is the wallet-output verifier; SkimMin deposits/skims into vaults and remains covered by touched-vault assets; DebtMax repays debt and remains outside wallet-output tracking. I did not find a missed parallel transfer-output flow.
  • Cross-repo consumer pass: current Euler Lite development consumes simulateTransactionPlan, simulatedWalletBalances, and insufficientWalletAssets in composables/useTxBatch.ts; this SDK-side fix is the narrow producer-side abstraction needed by that consumer. No Lite code change is required, aside from normal SDK version uptake/release sequencing.

Bot/reviewer feedback:

  • No active CodeRabbit/other bot comments or prior Leonard comments were present on the PR at review time.

Screenshots:

  • Not applicable; this is SDK simulation logic with no direct UI surface changed in the PR.

Comment lifecycle: none found; no Leonard comments or inline review comments needed cleanup.

Wallet-receiving swaps (withdraw/redeem/wallet swaps) transfer the
swapped-in token to the wallet via verifyAmountMinAndTransfer(asset, ...),
but the balance-snapshot discovery in buildSimulationBatch only covered
touched-vault underlyings, required-approval (debited) tokens, and
claim/unlock tokens. The swap output token was never snapshotted, so it
stayed invisible to the wallet-balance display and to later wallet-sourced
batch operations.

Decode the verifyAmountMinAndTransfer verifier item and add its asset to
the snapshotted wallet tokens (collectSwapWalletBalanceTokens), mirroring
collectClaimWalletBalanceTokens. Adds a unit test.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@dglowinski dglowinski force-pushed the fix/sim-swap-output-wallet-balance branch from 504e268 to 3796c15 Compare June 25, 2026 15:31
@dglowinski dglowinski changed the base branch from development to main June 25, 2026 15:31

@LeonardEulerXYZ LeonardEulerXYZ left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Reviewed head: 3796c15

Verdict: Approved

Scope reviewed:

  • packages/euler-v2-sdk/src/services/executionService/simulate.ts
  • packages/euler-v2-sdk/test/simulate.test.ts

What changed:

  • Simulation wallet-balance discovery now decodes SwapVerifier verifyAmountMinAndTransfer(address,address,uint256,uint256) verifier calls and includes the transfer asset in the wallet balanceOf(owner) snapshot token set.
  • Added a regression test covering the transferMin wallet-output case.

Validation performed:

  • pnpm install --frozen-lockfile from a fresh clone
  • pnpm test -- simulate.test.ts -t "simulateTransactionPlan tracks swap-verifier wallet output tokens" — passed; Vitest executed the package test set, 26 files / 347 tests passed
  • pnpm typecheck — passed
  • pnpm build — passed
  • pnpm lint — exit 0; reported pre-existing warnings outside this PR’s touched files (src/utils/*)
  • git diff --check origin/main...HEAD — clean
  • malicious/supply-chain sweep over the diff — no package, lockfile, workflow, dependency, secret, network, env, or script-surface changes found

Scalability / maintainability hygiene pass:

  • Searched sibling simulation and transaction paths for walletBalanceTokens, simulatedWalletBalances, verifyAmountMinAndTransfer, and swapVerifierAbi usage.
  • The change is correctly centralized in simulation wallet-balance discovery rather than patching a downstream consumer display path.
  • Existing explicit walletBalanceTokens producers for rewards/rEUL remain compatible; this PR covers the missing implicit verifier-derived transfer token.
  • Deposit/skim verifier variants intentionally remain out of scope because they land output into a vault, not directly into the wallet snapshot being fixed here.

Bot / reviewer feedback:

  • No active CodeRabbit or other bot comments were present to verify/refute.
  • Previous Leonard approval was attached to stale head 504e2682...; this review supersedes it for the current head.

Screenshots:

  • Not applicable: SDK simulation logic/test-only change, no user-visible UI was exercised.

No blocking correctness, API-compatibility, generated-package, dependency, build, type-safety, protocol-integration, or downstream consumer risks found.

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