feat(adapters): add type discriminant field to VaultV2 adapter interfaces#535
feat(adapters): add type discriminant field to VaultV2 adapter interfaces#535Foulks-Plb wants to merge 2 commits intomainfrom
Conversation
…e reset before approval
…aces Add a `type` string literal field to each adapter interface to enable easy type narrowing via type assertion instead of instanceof checks. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1cf149a8b5
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (erc20Allowances.permit2 < amount) { | ||
| if ( | ||
| APPROVE_ONLY_ONCE_TOKENS[data.chainId]?.includes(address) && | ||
| erc20Allowances.permit2 > 0n | ||
| ) | ||
| operations.push({ | ||
| type: "Erc20_Approve", | ||
| sender: from, | ||
| address, | ||
| args: { | ||
| amount: 0n, | ||
| spender: permit2, | ||
| }, | ||
| }); | ||
| operations.push({ | ||
| type: "Erc20_Approve", | ||
| sender: from, |
There was a problem hiding this comment.
Restore zero-reset before approve-only token Permit2 approvals
populateInputTransfer now emits a single positive Erc20_Approve whenever erc20Allowances.permit2 < amount, but for APPROVE_ONLY_ONCE_TOKENS (USDT/CRV) any non-zero existing allowance must be reset to zero first. finalizeBundle/encodeOperation simulate this operation via handleErc20ApproveOperation, which throws NonZeroAllowanceError when allowance is already > 0, so bundle construction fails before encodeErc20Approval can inject the extra zero-approval transaction requirement. This breaks users with partial existing Permit2 allowances (e.g., approved 60, now need 80), and the same pattern also affects the simple-transfer approval branch.
Useful? React with 👍 / 👎.
Summary
typestring literal field to each VaultV2 adapter interface (VaultV2MorphoMarketV1Adapter,VaultV2MorphoMarketV1AdapterV2,VaultV2MorphoVaultV1Adapter)adapter.type === "VaultV2MorphoMarketV1Adapter"instead of relying oninstanceofchecks, which don't work reliably with plain objects or across serialization boundariesTest plan
blue-sdk,blue-sdk-viem, andsimulation-sdk