Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
3dcfcf2
Initial commit
matthewwalsh0 Sep 24, 2025
666d742
Add publish hook
matthewwalsh0 Sep 24, 2025
24ab0c9
Parse token transfer as required token
matthewwalsh0 Sep 24, 2025
90a8fdd
Update tokens on transaction change
matthewwalsh0 Sep 25, 2025
48d5ab1
Fetch quotes
matthewwalsh0 Sep 26, 2025
83016ca
Add update payment token unit tests
matthewwalsh0 Sep 26, 2025
a3e3256
Add source amount unit tests
matthewwalsh0 Sep 26, 2025
b55bf2b
Add dust and fee calculation
matthewwalsh0 Sep 26, 2025
42ff38d
Add required assets to transaction controller
matthewwalsh0 Sep 28, 2025
7b14513
Pass required assets from middleware
matthewwalsh0 Sep 28, 2025
cfa6ad2
Parse required tokens from required assets
matthewwalsh0 Sep 28, 2025
c448437
Add quote metadata
matthewwalsh0 Sep 28, 2025
c655128
Update bridge status controller
matthewwalsh0 Sep 28, 2025
b1e2c1d
Add totals to state
matthewwalsh0 Sep 29, 2025
5a79473
Support abstract pay strategy
matthewwalsh0 Oct 12, 2025
b181dc6
Add strategy constructor callback
matthewwalsh0 Oct 12, 2025
870e156
Add bridge strategy
matthewwalsh0 Oct 12, 2025
db4bce3
Add bridge unit tests
matthewwalsh0 Oct 12, 2025
960b380
Add bridge quotes unit tests
matthewwalsh0 Oct 12, 2025
b9aeb89
Incude amount in totals
matthewwalsh0 Oct 12, 2025
68e79e1
Handle no source amounts
matthewwalsh0 Oct 12, 2025
ff291b5
Fix linting
matthewwalsh0 Oct 13, 2025
1e1fbbd
Fix linting
matthewwalsh0 Oct 13, 2025
9a59357
Remove unnecessary changes
matthewwalsh0 Oct 13, 2025
c5519f7
Add type
matthewwalsh0 Oct 13, 2025
957697a
Update changelog
matthewwalsh0 Oct 13, 2025
cc4c03a
Add unit test coverage
matthewwalsh0 Oct 13, 2025
a40bd4c
Add Relay strategy
matthewwalsh0 Oct 13, 2025
0e50e56
Add relay quotes unit tests
matthewwalsh0 Oct 13, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
/packages/name-controller @MetaMask/confirmations
/packages/signature-controller @MetaMask/confirmations
/packages/transaction-controller @MetaMask/confirmations
/packages/transaction-pay-controller @MetaMask/confirmations
/packages/user-operation-controller @MetaMask/confirmations

## Delegation Team
Expand Down Expand Up @@ -147,6 +148,8 @@
/packages/signature-controller/CHANGELOG.md @MetaMask/confirmations @MetaMask/core-platform
/packages/transaction-controller/package.json @MetaMask/confirmations @MetaMask/core-platform
/packages/transaction-controller/CHANGELOG.md @MetaMask/confirmations @MetaMask/core-platform
/packages/transaction-pay-controller/package.json @MetaMask/confirmations @MetaMask/core-platform
/packages/transaction-pay-controller/CHANGELOG.md @MetaMask/confirmations @MetaMask/core-platform
/packages/user-operation-controller/package.json @MetaMask/confirmations @MetaMask/core-platform
/packages/user-operation-controller/CHANGELOG.md @MetaMask/confirmations @MetaMask/core-platform
/packages/multichain-transactions-controller/package.json @MetaMask/accounts-engineers @MetaMask/core-platform
Expand Down
1 change: 1 addition & 0 deletions packages/transaction-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"@metamask/gas-fee-controller": "^24.1.0",
"@metamask/network-controller": "^24.2.1",
"@metamask/remote-feature-flag-controller": "^1.8.0",
"@ts-bridge/cli": "^0.6.1",
"@types/bn.js": "^5.1.5",
"@types/jest": "^27.4.1",
"@types/node": "^16.18.54",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,12 @@ export class PendingTransactionTracker {
}

async #checkTransaction(txMeta: TransactionMeta) {
const { hash, id } = txMeta;
const { hash, id, isIntentComplete } = txMeta;

if (isIntentComplete) {
await this.#onTransactionConfirmed(txMeta);
return;
}

if (!hash && (await this.#beforeCheckPendingTransaction(txMeta))) {
const error = new Error(
Expand Down Expand Up @@ -450,10 +455,10 @@ export class PendingTransactionTracker {

async #onTransactionConfirmed(
txMeta: TransactionMeta,
receipt: SuccessfulTransactionReceipt,
receipt?: SuccessfulTransactionReceipt,
) {
const { id } = txMeta;
const { blockHash } = receipt;
const { blockHash } = receipt ?? {};

this.#log('Transaction confirmed', id);

Expand All @@ -463,19 +468,23 @@ export class PendingTransactionTracker {
return;
}

const { baseFeePerGas, timestamp: blockTimestamp } =
await this.#getBlockByHash(blockHash, false);

const updatedTxMeta = cloneDeep(txMeta);
updatedTxMeta.baseFeePerGas = baseFeePerGas;
updatedTxMeta.blockTimestamp = blockTimestamp;

if (receipt && blockHash) {
const { baseFeePerGas, timestamp: blockTimestamp } =
await this.#getBlockByHash(blockHash, false);

updatedTxMeta.baseFeePerGas = baseFeePerGas;
updatedTxMeta.blockTimestamp = blockTimestamp;
updatedTxMeta.txParams = {
...updatedTxMeta.txParams,
gasUsed: receipt.gasUsed,
};
updatedTxMeta.txReceipt = receipt;
updatedTxMeta.verifiedOnBlockchain = true;
}

updatedTxMeta.status = TransactionStatus.confirmed;
updatedTxMeta.txParams = {
...updatedTxMeta.txParams,
gasUsed: receipt.gasUsed,
};
updatedTxMeta.txReceipt = receipt;
updatedTxMeta.verifiedOnBlockchain = true;

this.#updateTransaction(
updatedTxMeta,
Expand Down
3 changes: 3 additions & 0 deletions packages/transaction-controller/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,9 @@ export type TransactionMeta = {
/** Whether MetaMask will be compensated for the gas fee by the transaction. */
isGasFeeIncluded?: boolean;

/** Whether the intent of the transaction was achieved via an alternate route or chain. */
isIntentComplete?: boolean;

/**
* Whether the transaction is an incoming token transfer.
*/
Expand Down
14 changes: 14 additions & 0 deletions packages/transaction-pay-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- Initial release ([#6820](https://github.com/MetaMask/core/pull/6820))

[Unreleased]: https://github.com/MetaMask/core/
20 changes: 20 additions & 0 deletions packages/transaction-pay-controller/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
MIT License

Copyright (c) 2025 MetaMask

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 changes: 19 additions & 0 deletions packages/transaction-pay-controller/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# `@metamask/transaction-pay-controller`

Manages alternate payment strategies to provide required funds for transactions in MetaMask.

## Installation

`yarn add @metamask/transaction-pay-controller`

or

`npm install @metamask/transaction-pay-controller`

## Compatibility

This package relies implicitly upon the `EventEmitter` module. This module is available natively in Node.js, but when using this package for the browser, make sure to use a polyfill such as `events`.

## Contributing

This package is part of a monorepo. Instructions for contributing can be found in the [monorepo README](https://github.com/MetaMask/core#readme).
26 changes: 26 additions & 0 deletions packages/transaction-pay-controller/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* For a detailed explanation regarding each configuration property and type check, visit:
* https://jestjs.io/docs/configuration
*/

const merge = require('deepmerge');
const path = require('path');

const baseConfig = require('../../jest.config.packages');

const displayName = path.basename(__dirname);

module.exports = merge(baseConfig, {
// The display name when running multiple projects
displayName,

// An object that configures minimum threshold enforcement for coverage results
coverageThreshold: {
global: {
branches: 100,
functions: 100,
lines: 100,
statements: 100,
},
},
});
94 changes: 94 additions & 0 deletions packages/transaction-pay-controller/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{
"name": "@metamask/transaction-pay-controller",
"version": "0.0.0",
"description": "Manages alternate payment strategies to provide required funds for transactions in MetaMask",
"keywords": [
"MetaMask",
"Ethereum"
],
"homepage": "https://github.com/MetaMask/core/tree/main/packages/transaction-pay-controller#readme",
"bugs": {
"url": "https://github.com/MetaMask/core/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/MetaMask/core.git"
},
"license": "MIT",
"sideEffects": false,
"exports": {
".": {
"import": {
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
},
"require": {
"types": "./dist/index.d.cts",
"default": "./dist/index.cjs"
}
},
"./package.json": "./package.json"
},
"main": "./dist/index.cjs",
"types": "./dist/index.d.cts",
"files": [
"dist/"
],
"scripts": {
"build": "ts-bridge --project tsconfig.build.json --verbose --clean --no-references",
"build:docs": "typedoc",
"changelog:update": "../../scripts/update-changelog.sh @metamask/transaction-pay-controller",
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/transaction-pay-controller",
"prepare-manifest:preview": "../../scripts/prepare-preview-manifest.sh",
"publish:preview": "yarn npm publish --tag preview",
"since-latest-release": "../../scripts/since-latest-release.sh",
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
"test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",
"test:verbose": "NODE_OPTIONS=--experimental-vm-modules jest --verbose",
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
},
"dependencies": {
"@ethersproject/abi": "^5.7.0",
"@ethersproject/contracts": "^5.7.0",
"@metamask/base-controller": "^8.4.1",
"@metamask/controller-utils": "^11.14.1",
"@metamask/metamask-eth-abis": "^3.1.1",
"@metamask/utils": "^11.8.1",
"bignumber.js": "^9.1.2",
"bn.js": "^5.2.1",
"immer": "^9.0.6",
"lodash": "^4.17.21"
},
"devDependencies": {
"@metamask/assets-controllers": "^79.0.1",
"@metamask/auto-changelog": "^3.4.4",
"@metamask/bridge-controller": "^49.0.1",
"@metamask/bridge-status-controller": "^49.0.1",
"@metamask/network-controller": "^24.2.1",
"@metamask/remote-feature-flag-controller": "^1.8.0",
"@metamask/transaction-controller": "^60.6.1",
"@ts-bridge/cli": "^0.6.1",
"@types/jest": "^27.4.1",
"deepmerge": "^4.2.2",
"jest": "^27.5.1",
"ts-jest": "^27.1.4",
"typedoc": "^0.24.8",
"typedoc-plugin-missing-exports": "^2.0.0",
"typescript": "~5.2.2"
},
"peerDependencies": {
"@metamask/assets-controllers": "^79.0.0",
"@metamask/bridge-controller": "^49.0.0",
"@metamask/bridge-status-controller": "^49.0.0",
"@metamask/network-controller": "^24.0.0",
"@metamask/remote-feature-flag-controller": "^1.5.0",
"@metamask/transaction-controller": "^60.0.0"
},
"engines": {
"node": "^18.18 || >=20"
},
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org/"
}
}
Loading
Loading