feat: experimental MetaSwap order delegation manager - #207
Open
hanzel98 wants to merge 14 commits into
Open
Conversation
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.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ 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.
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.

Summary
MetaSwapOrderDelegationManagerfor two MetaSwap flows (not a drop-in for the genericDelegationManager).Hookless,ExecutionBuilder) undersrc/experiments/for comparison.aggregatorIdonlyRedemption gas (EIP-7702)
Measured with
gasleft()immediately aroundredeemDelegations. 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.DelegationManagerpathExactExecutionBatch+LimitedCalls(1)167,47596,618approve + swapExactExecutionBatch+LimitedCalls(1)230,987152,242reset + approve + swapExactExecutionBatch+LimitedCalls(1)244,355157,710MetaSwapFlexibleSettlementEnforcer143,414101,730approve + swapMetaSwapFlexibleSettlementEnforcer200,783158,990reset + approve + swapMetaSwapFlexibleSettlementEnforcer207,974166,072Exact orders save 34–42% by removing generic delegation loops, external hook calls, full execution terms, and
LimitedCallsEnforcerstate/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
documents/MetaSwapSpecializedDelegationManagers.mdscript/DeployMetaSwapOrderDelegationManager.s.solscript/verification/verify-metaswap-order-delegation-manager.shLimits
enableDelegationSupersedes naming in #206 (
feat/metaswap-intent-delegation-manager).Test plan
MetaSwapOrderDelegationManagerTesttests passscript/DeployMetaSwapOrderDelegationManager.s.solMETA_SWAP_ORDER_DELEGATION_MANAGER_ADDRESSNote
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(withMetaSwapDelegationManagerBase) is the main product path for EIP-7702 accounts. It keeps the familiarredeemDelegationsshape but only allows one root delegation, one self-referential caveat, and batch/default execution. ExactCalldata commits tokeccak256(execution batch)for gasless exact swaps; FlexibleSettlement binds swap economics (tokens, amounts, approval shape, recipient, min output) while leaving MetaSwap route/aggregatorIdto the redeemer. Enforcement is internal—no external caveat hooks—aimed at ~20–42% lower redemption gas thanExactExecutionBatch+LimitedCalls(1)orMetaSwapFlexibleSettlementEnforcer.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).MetaSwapFlexibleSettlementEnforceris added toDeployCaveatEnforcers.s.soland documented inCaveatEnforcers.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, andMETA_SWAP_ORDER_DELEGATION_MANAGER_ADDRESSin.env.examplesupport deployment and verification.Reviewed by Cursor Bugbot for commit 47373df. Bugbot is set up for automated code reviews on this repo. Configure here.