Skip to content

feat(transaction-controller): add approval-time sponsorship/signing hooks - #10109

Open
pedronfigueiredo wants to merge 6 commits into
mainfrom
pnf/canonical-transaction-approval-preparation-handoff-implementation
Open

feat(transaction-controller): add approval-time sponsorship/signing hooks#10109
pedronfigueiredo wants to merge 6 commits into
mainfrom
pnf/canonical-transaction-approval-preparation-handoff-implementation

Conversation

@pedronfigueiredo

@pedronfigueiredo pedronfigueiredo commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Related pull requests

Summary

  • add isSponsored and shouldSign hooks to TransactionControllerOptions['hooks'] so clients supply approval-time sponsorship and local-vs-external signing policy at the approval boundary
  • keep gas-fee-token preflight in the approval flow so the controller still refreshes token quotes and native-balance fallback before deciding whether to sign
  • preserve beforeSign execution even when the approved transaction ends up on the external-sign path
  • keep the Core API surface focused on controller hooks rather than a separate approval-preparation helper

Public API

hooks: {
  isSponsored?: (request: { transactionMeta: TransactionMeta }) => Promise<boolean>;
  shouldSign?: (request: {
    transactionMeta: TransactionMeta;
    isSponsored: boolean;
  }) => Promise<boolean>;
  beforePublish?: (transactionMeta: TransactionMeta) => Promise<boolean>;
  beforeSign?: BeforeSignHook;
  publish?: (transactionMeta: TransactionMeta) => Promise<{ transactionHash: string }>;
  publishBatch?: PublishBatchHook;
}

Behavior decisions

  • isSponsored answers whether the transaction should be treated as sponsored at approval time.
  • shouldSign answers whether the controller should reserve a nonce and sign locally.
  • Sponsorship no longer implies local signing.
  • beforeSign still runs before gas-fee-token publication checks, even when the final path does not locally sign.

Validation

  • corepack yarn workspace @metamask/transaction-controller run jest --no-watchman --no-coverage packages/transaction-controller/src/TransactionController.test.ts
  • corepack yarn build

Note

High Risk
Reorders the post-approval signing pipeline (nonce, sponsorship, external sign, gas-fee preflight), which affects every approved transaction and coordinated extension/mobile consumers.

Overview
Adds isSponsored and shouldSign controller hooks (exported as IsSponsoredHook / ShouldSignHook) so clients decide sponsorship and local vs external signing at approval time, with defaults tied to isGasFeeSponsored and !isExternalSign.

Approval flow is reordered: mark approved → beforeSigngas-fee-token preflight (checkGasFeeTokenBeforePublish, moved out of #signTransaction for this path) → run hooks and set isGasFeeSponsored / isExternalSignonly reserve nonce and sign when shouldSign is true; external-sign paths skip nonce lock and clear nonce. #signTransaction gains optional skips so the approval path does not duplicate those steps.

Smaller fixes: transaction batch gas estimates update from the gas-fee poller; simulation requests initialize delegation overrides when missing; getGasFeeTokens returns empty tokens when EIP-7702 pubkey or upgrade address is missing; minor getTransactions typing and removeLeadingZeroes cleanup. Tests cover hook ordering, external-sign behavior, and transactionApproved including nonce after sign.

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

jpuri
jpuri previously approved these changes Sep 4, 2026
Comment thread packages/transaction-controller/src/utils/prepare-transaction-for-approval.ts Outdated
@pedronfigueiredo pedronfigueiredo changed the title feat(transaction-controller): prepare transactions for approval feat(transaction-controller): add approval-time sponsorship/signing hooks Sep 9, 2026

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

Stale Bugbot comment from a previous run.

Comment thread packages/transaction-controller/src/TransactionController.ts
Comment thread packages/transaction-controller/src/TransactionController.ts

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

Stale Bugbot comment from a previous run.

Comment thread packages/transaction-controller/src/TransactionController.ts
@pedronfigueiredo
pedronfigueiredo force-pushed the pnf/canonical-transaction-approval-preparation-handoff-implementation branch 2 times, most recently from c78867c to bd526cb Compare September 10, 2026 09:58
@pedronfigueiredo
pedronfigueiredo requested review from a team as code owners September 10, 2026 10:52
@pedronfigueiredo
pedronfigueiredo requested review from a team as code owners September 10, 2026 10:52
@pedronfigueiredo
pedronfigueiredo force-pushed the pnf/canonical-transaction-approval-preparation-handoff-implementation branch from 57e5828 to 83c15c8 Compare September 10, 2026 10:53

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

Stale Bugbot comment from a previous run.

Comment thread packages/transaction-controller/src/TransactionController.ts Outdated
@pedronfigueiredo
pedronfigueiredo force-pushed the pnf/canonical-transaction-approval-preparation-handoff-implementation branch from 83c15c8 to ec803b7 Compare September 10, 2026 11:17

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

Stale Bugbot comment from a previous run.

Comment thread packages/transaction-controller/src/TransactionController.ts Outdated
@pedronfigueiredo
pedronfigueiredo force-pushed the pnf/canonical-transaction-approval-preparation-handoff-implementation branch from ec803b7 to 01d269f Compare September 10, 2026 17:18

@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 53cdb36. Configure here.

Comment thread packages/transaction-controller/src/TransactionController.ts
@pedronfigueiredo
pedronfigueiredo force-pushed the pnf/canonical-transaction-approval-preparation-handoff-implementation branch from 53cdb36 to 688ed6e Compare September 10, 2026 17:40
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.

3 participants