Skip to content

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

Open
pedronfigueiredo wants to merge 7 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 7 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

Medium Risk
Changes the core post-approval pipeline (nonce, signing, events) for every transaction, though default hooks mirror prior isGasFeeSponsored / isExternalSign behavior.

Overview
Adds optional isSponsored and shouldSign hooks so clients can decide sponsorship and local vs external signing at approval time, without treating sponsorship as “must sign locally.”

Approval flow is reordered: mark approved → beforeSign → gas-fee-token preflight → run hooks and set isGasFeeSponsored / isExternalSign → only if shouldSign is true, reserve nonce and sign (signing skips duplicate beforeSign / token checks). transactionApproved is emitted after this path so listeners can see a nonce when local signing ran.

Smaller fixes: batch gas poller updates transactionBatches, simulation API creates delegation overrides when missing, getGasFeeTokens returns empty tokens when EIP-7702 key/upgrade address is missing, and removeLeadingZeroes is simplified.

Reviewed by Cursor Bugbot for commit 58ac505. 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 3 times, most recently from 347f207 to 46fe285 Compare September 11, 2026 09:16
@pedronfigueiredo
pedronfigueiredo force-pushed the pnf/canonical-transaction-approval-preparation-handoff-implementation branch from 46fe285 to e9262f4 Compare September 11, 2026 09:54
@pedronfigueiredo

Copy link
Copy Markdown
Contributor Author

Fixed the lint:misc:check failure (Prettier formatting in TransactionController.test.ts) and pushed 58ac505. GitHub checks are green again; @matthewwalsh0, could you re-review when you have a moment?

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