feat(transaction-pay-controller): send v2 metamask envelope and alternate caveats for subsidized executes#9298
Draft
matthewwalsh0 wants to merge 12 commits into
Draft
feat(transaction-pay-controller): send v2 metamask envelope and alternate caveats for subsidized executes#9298matthewwalsh0 wants to merge 12 commits into
matthewwalsh0 wants to merge 12 commits into
Conversation
ea5c3ac to
7867e7c
Compare
…lay/subsidize Subsidized Relay quotes (non-zero fees.subsidized.amountUsd) now bypass /execute and submit through the intents-API POST /relay/subsidize endpoint instead. The client signs two ERC20BalanceChange + LimitedCalls delegations server-side; the server JIT-fetches a fresh Relay quote, pairs each delegation with a step, builds redeemDelegations calldata, and submits to Relay — returning a new request ID for status polling. Key changes: - utils/delegation.ts: buildAndSignSubsidizedDelegation with ERC20BalanceChange and LimitedCalls caveats, ANY_BENEFICIARY delegate, 20% amount buffer - relay-api.ts: submitRelaySubsidize() calling POST /relay/subsidize - relay-submit.ts: submitViaRelaySubsidize signs 2 delegations in parallel and sends delegations:[ctx0,ctx1] matching server schema; isSubsidizedRelayQuote detects subsidized quotes from fees.subsidized.amountUsd - types.ts: RelaySubsidizeRequest / RelaySubsidizeResponse - feature-flags.ts: relaySubsidizeUrl flag with DEFAULT_RELAY_SUBSIDIZE_URL default; fix localhost hardcoded URLs for relayQuoteUrl and relaySubsidizeUrl Fix crash when subsidized preview quotes have steps: undefined — server toSafeSubsidizedQuote() strips steps entirely; submitTransactions now uses quote.original.steps ?? [] and submitViaRelaySubsidize initialises quote.original.steps ??= [] before element access.
…ginal before subsidized submit quote.original is read from Immer-frozen controller state. The subsidized path injects a server-returned requestId into original.steps (absent on preview quotes), which throws 'Cannot add new property' on a frozen object. Shallow-clone quote.original into mutableOriginal before the submit/poll cycle so submitTransactions and waitForRelayCompletion operate on a mutable copy while the frozen state tree is left untouched.
…ional preStep in subsidized submit
…etDelegationTransactionCallback - Export Caveat type, buildLimitedCallsCaveat, buildAllowedTargetsCaveat, buildAllowedCalldataCaveat, packSingleExecution, packBatchExecution, encodeRedeemDelegations, and extractRedeemDelegationsParams from delegation.ts - Add optional caveats param to GetDelegationTransactionCallback so callers can supply pre-built caveats (e.g. subsidy enforcer set) instead of the default ones built inside the callback - Re-export Caveat from types.ts for downstream consumers
…step mutation in subsidized submit - normalizeParams guards maxFeePerGas and maxPriorityFeePerGas with undefined checks before calling toHex — sanitizeSteps strips these fields from quote steps so they arrive as undefined, causing a toString crash on Hermes - Replace direct mutation of quote.original.steps[0].requestId with a full steps array reassignment; the step objects are Immer-frozen so property addition throws 'Cannot add new property' in strict mode - submitViaRelaySubsidize builds three subsidy caveats (LimitedCalls, AllowedTargets, AllowedCalldata) from the sanitized ERC20 step and passes them to getDelegationTransaction; sends new RelaySubsidizeRequest shape - Tests: add gas-fee-params-missing case and update subsidize body assertions
…velope The intents-api no longer accepts or expects orderId in the /relay/execute metamask envelope; the order ID is derived server-side. Remove it from the execute request, the type definitions, and the associated guard.
7aa8583 to
f2d9f00
Compare
…ts from delegation.ts
Member
Author
|
@metamaskbot publish-preview |
Contributor
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
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.
Explanation
Relay execute quotes are now requested as v2, and execute requests forward a
metamaskenvelope.metamask.executeVersion: 2.metamaskenvelope on execute. The execute body includes{ isSubsidized, quoteRequest, signature }, wheresignatureis the token the server returned on the quote (quote.metamask.signature) — forwarded, not generated. Execute is rejected if the token is absent.caveatsargument ongetDelegationTransaction. Non-subsidized executes are unchanged.relay-submit-execute.ts; newutils/delegation.tscaveat builders + redeemDelegations helpers; shallow-clone of Immer-frozenquote.original; guard undefined gas params.References
Checklist