Skip to content

feat: experimental MetaSwap order delegation manager - #207

Open
hanzel98 wants to merge 14 commits into
mainfrom
feat/metaswap-order-delegation-manager
Open

feat: experimental MetaSwap order delegation manager#207
hanzel98 wants to merge 14 commits into
mainfrom
feat/metaswap-order-delegation-manager

Conversation

@hanzel98

@hanzel98 hanzel98 commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Experimental purpose-specific MetaSwapOrderDelegationManager for two MetaSwap flows (not a drop-in for the generic DelegationManager).
  • Also includes experimental flexible-only prototypes (Hookless, ExecutionBuilder) under src/experiments/ for comparison.
Intent Product User signs Redeemer may change
ExactCalldata Gasless exact swap Full batch hash Nothing
FlexibleSettlement Limit order Economics + approval shape Route / aggregatorId only

Redemption gas (EIP-7702)

Measured with gasleft() immediately around redeemDelegations. Each old/new pair executes the same swap shape from a one-element root delegation with an ECDSA signature and zero starting output-token balance. Numbers include the manager call and exclude top-level transaction intrinsic calldata gas.

Purpose Swap shape Existing DelegationManager path Existing gas Order gas Saving
Gasless exact swap Native swap ExactExecutionBatch + LimitedCalls(1) 167,475 96,618 42.3%
Gasless exact swap approve + swap ExactExecutionBatch + LimitedCalls(1) 230,987 152,242 34.1%
Gasless exact swap reset + approve + swap ExactExecutionBatch + LimitedCalls(1) 244,355 157,710 35.5%
Flexible limit order Native swap MetaSwapFlexibleSettlementEnforcer 143,414 101,730 29.1%
Flexible limit order approve + swap MetaSwapFlexibleSettlementEnforcer 200,783 158,990 20.8%
Flexible limit order reset + approve + swap MetaSwapFlexibleSettlementEnforcer 207,974 166,072 20.1%

Exact orders save 34–42% by removing generic delegation loops, external hook calls, full execution terms, and LimitedCallsEnforcer state/event costs. Flexible orders save 20–29% while retaining approval-shape, swap-calldata, and output-delta validation. The compact redemption event is part of the measured saving; the generic manager emits the full delegation.

Included

  • Contracts: order manager + shared base + two flexible prototypes
  • Docs: documents/MetaSwapSpecializedDelegationManagers.md
  • Tests: order + specialized suites, including native, approve, and reset-approve gas comparisons
  • Deploy: script/DeployMetaSwapOrderDelegationManager.s.sol
  • Verify: script/verification/verify-metaswap-order-delegation-manager.sh

Limits

  • One root delegation, one self-caveat, batch/default only
  • No chains / try-mode / pause / enableDelegation
  • Gasless expiry remains off-chain
  • ECDSA first; accounts with code fall back to ERC-1271

Supersedes naming in #206 (feat/metaswap-intent-delegation-manager).

Test plan

  • 32 focused MetaSwapOrderDelegationManagerTest tests pass
  • Equivalent native, approve, and reset-approve redemption benchmarks cover both intents
  • Dry-run script/DeployMetaSwapOrderDelegationManager.s.sol
  • Confirm verify script reads META_SWAP_ORDER_DELEGATION_MANAGER_ADDRESS

Note

High Risk
New on-chain paths authorize MetaSwap batches, ERC-20 approvals, and min-output checks via balance deltas, with documented trust in delegates, MetaSwap, and unrelated balance increases; mistakes could affect user funds despite extensive tests.

Overview
Adds an experimental MetaSwap stack: purpose-built redemption managers, several MetaSwap caveat enforcers, deploy/verify wiring, docs, and broad Forge coverage (including gas benchmarks vs the generic DelegationManager).

MetaSwapOrderDelegationManager (with MetaSwapDelegationManagerBase) is the main product path for EIP-7702 accounts. It keeps the familiar redeemDelegations shape but only allows one root delegation, one self-referential caveat, and batch/default execution. ExactCalldata commits to keccak256(execution batch) for gasless exact swaps; FlexibleSettlement binds swap economics (tokens, amounts, approval shape, recipient, min output) while leaving MetaSwap route/aggregatorId to the redeemer. Enforcement is internal—no external caveat hooks—aimed at ~20–42% lower redemption gas than ExactExecutionBatch + LimitedCalls(1) or MetaSwapFlexibleSettlementEnforcer.

Also ships flexible settlement enforcers for the generic manager path: MetaSwapFlexibleSettlementEnforcer (one-shot consumption + min output on recipient balance), plus calldata-shape helpers (MetaSwapBatchCalldataEnforcer, MetaSwap7702CalldataEnforcer, MetaSwapApproveSwapEnforcer). MetaSwapFlexibleSettlementEnforcer is added to DeployCaveatEnforcers.s.sol and documented in CaveatEnforcers.md.

Under src/experiments/, prototype managers (Hookless, ExecutionBuilder, GaslessSwapDelegationManager, MetaSwapMinimalDelegationManager) compare hook-based vs inlined validation. documents/MetaSwapSpecializedDelegationManagers.md, DeployMetaSwapOrderDelegationManager.s.sol, verify-metaswap-order-delegation-manager.sh, and META_SWAP_ORDER_DELEGATION_MANAGER_ADDRESS in .env.example support deployment and verification.

Reviewed by Cursor Bugbot for commit 47373df. Bugbot is set up for automated code reviews on this repo. Configure here.

Authorize one open-route MetaSwap settlement with exact input constraints, signed approval flexibility, minimum output, and atomic one-shot consumption.
Support exact-calldata gasless swaps and flexible limit-order
settlements in one hookless manager, with gas benchmarks against
the generic ExactBatch+LimitedCalls and FlexibleSettlement paths.
Introduce a purpose-specific manager for ExactCalldata gasless swaps and
FlexibleSettlement limit orders, with prototype managers, docs, deploy
and verify scripts, and ~100% line coverage on the new contracts.
@hanzel98
hanzel98 requested a review from a team as a code owner September 11, 2026 01:50

@cursor cursor Bot 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.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 8e74755. Configure here.

Comment thread src/enforcers/MetaSwapPrefundEnforcer.sol Outdated
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.

1 participant