@metamask-previews/transaction-pay-controller 31.1.0-preview-701acab40 → 31.2.0-preview-8e636eabf
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -1
- package/dist/constants.d.ts +16 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +21 -0
- package/dist/constants.js.map +1 -1
- package/dist/helpers/TransactionPayPublishHook.js +1 -1
- package/dist/helpers/TransactionPayPublishHook.js.map +1 -1
- package/dist/strategy/across/across-submit.js +1 -1
- package/dist/strategy/across/across-submit.js.map +1 -1
- package/dist/strategy/relay/constants.d.ts +0 -1
- package/dist/strategy/relay/constants.d.ts.map +1 -1
- package/dist/strategy/relay/constants.js +0 -1
- package/dist/strategy/relay/constants.js.map +1 -1
- package/dist/strategy/relay/relay-quotes.d.ts.map +1 -1
- package/dist/strategy/relay/relay-quotes.js +40 -22
- package/dist/strategy/relay/relay-quotes.js.map +1 -1
- package/dist/strategy/relay/relay-submit.js +1 -1
- package/dist/strategy/relay/relay-submit.js.map +1 -1
- package/dist/strategy/relay/relay-validation.d.ts.map +1 -1
- package/dist/strategy/relay/relay-validation.js +13 -2
- package/dist/strategy/relay/relay-validation.js.map +1 -1
- package/dist/strategy/relay/types.d.ts +0 -1
- package/dist/strategy/relay/types.d.ts.map +1 -1
- package/dist/strategy/relay/types.js.map +1 -1
- package/dist/strategy/server/server-quotes.d.ts.map +1 -1
- package/dist/strategy/server/server-quotes.js +3 -2
- package/dist/strategy/server/server-quotes.js.map +1 -1
- package/dist/strategy/server/server-submit.js +1 -1
- package/dist/strategy/server/server-submit.js.map +1 -1
- package/dist/strategy/server/server-validation.d.ts.map +1 -1
- package/dist/strategy/server/server-validation.js +13 -2
- package/dist/strategy/server/server-validation.js.map +1 -1
- package/dist/types.d.ts +1 -6
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -9
- package/dist/types.js.map +1 -1
- package/dist/utils/account.d.ts +46 -0
- package/dist/utils/account.d.ts.map +1 -0
- package/dist/utils/account.js +65 -0
- package/dist/utils/account.js.map +1 -0
- package/dist/utils/feature-flags.d.ts +19 -0
- package/dist/utils/feature-flags.d.ts.map +1 -1
- package/dist/utils/feature-flags.js +30 -0
- package/dist/utils/feature-flags.js.map +1 -1
- package/dist/utils/gas-payment.d.ts +1 -1
- package/dist/utils/gas-payment.d.ts.map +1 -1
- package/dist/utils/gas-payment.js.map +1 -1
- package/dist/utils/max-gas-station.d.ts +53 -0
- package/dist/utils/max-gas-station.d.ts.map +1 -0
- package/dist/utils/max-gas-station.js +201 -0
- package/dist/utils/max-gas-station.js.map +1 -0
- package/dist/utils/max-quote.d.ts +86 -0
- package/dist/utils/max-quote.d.ts.map +1 -0
- package/dist/utils/max-quote.js +238 -0
- package/dist/utils/max-quote.js.map +1 -0
- package/dist/utils/quotes.d.ts.map +1 -1
- package/dist/utils/quotes.js +26 -2
- package/dist/utils/quotes.js.map +1 -1
- package/package.json +3 -3
- package/dist/strategy/relay/relay-max.d.ts +0 -33
- package/dist/strategy/relay/relay-max.d.ts.map +0 -1
- package/dist/strategy/relay/relay-max.js +0 -373
- package/dist/strategy/relay/relay-max.js.map +0 -1
- package/dist/utils/7702.d.ts +0 -15
- package/dist/utils/7702.d.ts.map +0 -1
- package/dist/utils/7702.js +0 -19
- package/dist/utils/7702.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [31.2.0]
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Add `confirmations_pay_extended.payStrategies.server.gaslessEnabled` feature flag to disable gasless quotes in `ServerStrategy`, enabled by default ([#11432](https://github.com/MetaMask/core/pull/11432))
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
|
|
18
|
+
- Skip Relay and Server quote simulation when the payer is an MPC Money account ([#11408](https://github.com/MetaMask/core/pull/11408))
|
|
19
|
+
- Perps and Predict deposits funded by a Money Account set `paymentOverride` to `moneyAccount` and put that account on `refundTo`. Simulation rebuilds the submit calls, which signs a delegation and prompts for MFA. Submit still signs once.
|
|
20
|
+
- Always request non-atomic quotes when the transaction's `from` keyring requires MFA ([#11389](https://github.com/MetaMask/core/pull/11389))
|
|
21
|
+
- An atomic quote embeds the target calls, which needs a fresh delegation signature per quote. On an MFA keyring every refresh of an open amount screen would cost the user a confirmation.
|
|
22
|
+
- The keyring is read from `transaction.txParams.from`, the account that signs the delegation, rather than the quote request's payer account.
|
|
23
|
+
- Resolved when building quote requests, so it applies to every strategy and to both the max and non-max quote paths.
|
|
24
|
+
- Make the max-amount gas station in `RelayStrategy` tolerate small gas cost changes between the probe and adjusted quotes ([#11434](https://github.com/MetaMask/core/pull/11434))
|
|
25
|
+
- Reserve a buffer on top of the probe's gas cost when reducing the source amount, configurable with the `confirmations_pay_extended.gasStationCostBuffer` feature flag (defaults to `1.0`, no buffer).
|
|
26
|
+
- Remove the gas limit checks on the adjusted quote, since the affordability check already covers any gas cost change.
|
|
27
|
+
- Bump `@metamask/assets-controller` from `^20.3.1` to `^20.4.0` ([#11447](https://github.com/MetaMask/core/pull/11447))
|
|
28
|
+
- Bump `@metamask/network-controller` from `^38.0.0` to `^38.0.1` ([#11447](https://github.com/MetaMask/core/pull/11447))
|
|
29
|
+
|
|
10
30
|
## [31.1.0]
|
|
11
31
|
|
|
12
32
|
### Added
|
|
@@ -1849,7 +1869,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
1849
1869
|
|
|
1850
1870
|
- Initial release ([#6820](https://github.com/MetaMask/core/pull/6820))
|
|
1851
1871
|
|
|
1852
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/transaction-pay-controller@31.
|
|
1872
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/transaction-pay-controller@31.2.0...HEAD
|
|
1873
|
+
[31.2.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-pay-controller@31.1.0...@metamask/transaction-pay-controller@31.2.0
|
|
1853
1874
|
[31.1.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-pay-controller@31.0.0...@metamask/transaction-pay-controller@31.1.0
|
|
1854
1875
|
[31.0.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-pay-controller@30.4.3...@metamask/transaction-pay-controller@31.0.0
|
|
1855
1876
|
[30.4.3]: https://github.com/MetaMask/core/compare/@metamask/transaction-pay-controller@30.4.2...@metamask/transaction-pay-controller@30.4.3
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { KeyringTypes } from '@metamask/keyring-controller';
|
|
1
2
|
import { TransactionType } from '@metamask/transaction-controller';
|
|
2
3
|
import type { Hex } from '@metamask/utils';
|
|
3
4
|
export declare const CONTROLLER_NAME = "TransactionPayController";
|
|
@@ -6,6 +7,21 @@ export declare const CONTROLLER_NAME = "TransactionPayController";
|
|
|
6
7
|
* share the same Arbitrum-USDC → Hypercore handling in pay strategies.
|
|
7
8
|
*/
|
|
8
9
|
export declare const PERPS_DEPOSIT_TYPES: TransactionType[];
|
|
10
|
+
/**
|
|
11
|
+
* Keyring types that support EIP-7702 authorization signing.
|
|
12
|
+
* Hardware wallets, snap keyrings, and custody keyrings are excluded.
|
|
13
|
+
*/
|
|
14
|
+
export declare const KEYRING_TYPES_SUPPORTING_7702: `${KeyringTypes}`[];
|
|
15
|
+
/**
|
|
16
|
+
* Keyring types whose signing requires multi-factor authentication.
|
|
17
|
+
*
|
|
18
|
+
* The MPC keyring splits its key across factors, so every signature it
|
|
19
|
+
* produces costs the user an MFA confirmation. Quote flows that would
|
|
20
|
+
* otherwise sign once per quote must avoid doing so for these accounts.
|
|
21
|
+
*
|
|
22
|
+
* The SRP-derived `Money Keyring` signs locally and is deliberately absent.
|
|
23
|
+
*/
|
|
24
|
+
export declare const KEYRING_TYPES_REQUIRING_MFA: `${KeyringTypes}`[];
|
|
9
25
|
export declare const CHAIN_ID_ARBITRUM: Hex;
|
|
10
26
|
export declare const CHAIN_ID_MAINNET: Hex;
|
|
11
27
|
export declare const CHAIN_ID_POLYGON: Hex;
|
package/dist/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAE3C,eAAO,MAAM,eAAe,6BAA6B,CAAC;AAE1D;;;GAGG;AACH,eAAO,MAAM,mBAAmB,EAAE,eAAe,EAGhD,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAe,GAAG,CAAC;AACjD,eAAO,MAAM,gBAAgB,EAAY,GAAG,CAAC;AAC7C,eAAO,MAAM,gBAAgB,EAAa,GAAG,CAAC;AAC9C,eAAO,MAAM,kBAAkB,EAAc,GAAG,CAAC;AACjD,eAAO,MAAM,cAAc,EAAa,GAAG,CAAC;AAE5C,eAAO,MAAM,oBAAoB,EACiB,GAAG,CAAC;AAEtD,eAAO,MAAM,qBAAqB,EACgB,GAAG,CAAC;AAEtD,eAAO,MAAM,qBAAqB,EACgB,GAAG,CAAC;AAEtD,eAAO,MAAM,oBAAoB,EACiB,GAAG,CAAC;AAEtD,eAAO,MAAM,kBAAkB,EACmB,GAAG,CAAC;AAEtD,eAAO,MAAM,sBAAsB,uCAAuC,CAAC;AAE3E,eAAO,MAAM,uBAAuB,IAAI,CAAC;AACzC,eAAO,MAAM,aAAa,IAAI,CAAC;AAE/B,eAAO,MAAM,yBAAyB,EAAE,MAAM,CAAC,GAAG,EAAE,MAAM,CAEzD,CAAC;AAEF,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,CAmB1C,CAAC;A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AM,qBAAqB,EACgB,GAAG,CAAC;AAEtD,eAAO,MAAM,qBAAqB,EACgB,GAAG,CAAC;AAEtD,eAAO,MAAM,oBAAoB,EACiB,GAAG,CAAC;AAEtD,eAAO,MAAM,kBAAkB,EACmB,GAAG,CAAC;AAEtD,eAAO,MAAM,sBAAsB,uCAAuC,CAAC;AAE3E,eAAO,MAAM,uBAAuB,IAAI,CAAC;AACzC,eAAO,MAAM,aAAa,IAAI,CAAC;AAE/B,eAAO,MAAM,yBAAyB,EAAE,MAAM,CAAC,GAAG,EAAE,MAAM,CAEzD,CAAC;AAEF,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,CAmB1C,CAAC;AAEF,oBAAY,eAAe;IACzB,YAAY,iBAAiB;IAC7B,KAAK,UAAU;IACf,OAAO,YAAY;CACpB;AAED;;;;;GAKG;AACH,oBAAY,sBAAsB;IAChC,SAAS,cAAc;IACvB,MAAM,WAAW;CAClB;AAED,qEAAqE;AACrE,eAAO,MAAM,gBAAgB,gBAAgB,CAAC;AAE9C,oBAAY,sBAAsB;IAChC,MAAM,WAAW;IACjB,IAAI,SAAS;IACb;;;OAGG;IACH,IAAI,SAAS;IACb,KAAK,UAAU;IACf,MAAM,WAAW;CAClB;AAQD;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,OAAO,GAChB,QAAQ,IAAI,sBAAsB,CAEpC"}
|
package/dist/constants.js
CHANGED
|
@@ -8,6 +8,27 @@ export const PERPS_DEPOSIT_TYPES = [
|
|
|
8
8
|
TransactionType.perpsDeposit,
|
|
9
9
|
TransactionType.perpsDepositAndOrder,
|
|
10
10
|
];
|
|
11
|
+
/**
|
|
12
|
+
* Keyring types that support EIP-7702 authorization signing.
|
|
13
|
+
* Hardware wallets, snap keyrings, and custody keyrings are excluded.
|
|
14
|
+
*/
|
|
15
|
+
export const KEYRING_TYPES_SUPPORTING_7702 = [
|
|
16
|
+
'HD Key Tree',
|
|
17
|
+
'Simple Key Pair',
|
|
18
|
+
'Money Keyring',
|
|
19
|
+
];
|
|
20
|
+
/**
|
|
21
|
+
* Keyring types whose signing requires multi-factor authentication.
|
|
22
|
+
*
|
|
23
|
+
* The MPC keyring splits its key across factors, so every signature it
|
|
24
|
+
* produces costs the user an MFA confirmation. Quote flows that would
|
|
25
|
+
* otherwise sign once per quote must avoid doing so for these accounts.
|
|
26
|
+
*
|
|
27
|
+
* The SRP-derived `Money Keyring` signs locally and is deliberately absent.
|
|
28
|
+
*/
|
|
29
|
+
export const KEYRING_TYPES_REQUIRING_MFA = [
|
|
30
|
+
'MPC Money Keyring',
|
|
31
|
+
];
|
|
11
32
|
export const CHAIN_ID_ARBITRUM = '0xa4b1';
|
|
12
33
|
export const CHAIN_ID_MAINNET = '0x1';
|
|
13
34
|
export const CHAIN_ID_POLYGON = '0x89';
|
package/dist/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAGnE,MAAM,CAAC,MAAM,eAAe,GAAG,0BAA0B,CAAC;AAE1D;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAsB;IACpD,eAAe,CAAC,YAAY;IAC5B,eAAe,CAAC,oBAAoB;CACrC,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAwB;IAChE,aAAa;IACb,iBAAiB;IACjB,eAAe;CAChB,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAwB;IAC9D,mBAAmB;CACpB,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG,QAAe,CAAC;AACjD,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAY,CAAC;AAC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D,WAAY,eAAe;IACzB,gDAA6B,CAAA;IAC7B,kCAAe,CAAA;IACf,sCAAmB,CAAA;AACrB,CAAC,EAJW,eAAe,KAAf,eAAe,QAI1B;AAED;;;;;GAKG;AACH,MAAM,CAAN,IAAY,sBAGX;AAHD,WAAY,sBAAsB;IAChC,iDAAuB,CAAA;IACvB,2CAAiB,CAAA;AACnB,CAAC,EAHW,sBAAsB,KAAtB,sBAAsB,QAGjC;AAED,qEAAqE;AACrE,MAAM,CAAC,MAAM,gBAAgB,GAAG,aAAa,CAAC;AAE9C,MAAM,CAAN,IAAY,sBAUX;AAVD,WAAY,sBAAsB;IAChC,2CAAiB,CAAA;IACjB,uCAAa,CAAA;IACb;;;OAGG;IACH,uCAAa,CAAA;IACb,yCAAe,CAAA;IACf,2CAAiB,CAAA;AACnB,CAAC,EAVW,sBAAsB,KAAtB,sBAAsB,QAUjC;AAED,MAAM,gBAAgB,GAAgC,IAAI,GAAG,CAC3D,MAAM,CAAC,MAAM,CAAC,sBAAsB,CAAC,CAAC,MAAM,CAC1C,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,KAAK,sBAAsB,CAAC,IAAI,CACvD,CACF,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,UAAU,wBAAwB,CACtC,QAAiB;IAEjB,OAAO,gBAAgB,CAAC,GAAG,CAAC,QAAkC,CAAC,CAAC;AAClE,CAAC","sourcesContent":["import type { KeyringTypes } from '@metamask/keyring-controller';\nimport { TransactionType } from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\n\nexport const CONTROLLER_NAME = 'TransactionPayController';\n\n/**\n * Parent transaction types that represent a Hyperliquid perps deposit and\n * share the same Arbitrum-USDC → Hypercore handling in pay strategies.\n */\nexport const PERPS_DEPOSIT_TYPES: TransactionType[] = [\n TransactionType.perpsDeposit,\n TransactionType.perpsDepositAndOrder,\n];\n\n/**\n * Keyring types that support EIP-7702 authorization signing.\n * Hardware wallets, snap keyrings, and custody keyrings are excluded.\n */\nexport const KEYRING_TYPES_SUPPORTING_7702: `${KeyringTypes}`[] = [\n 'HD Key Tree',\n 'Simple Key Pair',\n 'Money Keyring',\n];\n\n/**\n * Keyring types whose signing requires multi-factor authentication.\n *\n * The MPC keyring splits its key across factors, so every signature it\n * produces costs the user an MFA confirmation. Quote flows that would\n * otherwise sign once per quote must avoid doing so for these accounts.\n *\n * The SRP-derived `Money Keyring` signs locally and is deliberately absent.\n */\nexport const KEYRING_TYPES_REQUIRING_MFA: `${KeyringTypes}`[] = [\n 'MPC Money Keyring',\n];\n\nexport const CHAIN_ID_ARBITRUM = '0xa4b1' as Hex;\nexport const CHAIN_ID_MAINNET = '0x1' as Hex;\nexport const CHAIN_ID_POLYGON = '0x89' as Hex;\nexport const CHAIN_ID_HYPERCORE = '0x539' as Hex;\nexport const CHAIN_ID_MONAD = '0x8f' as Hex;\n\nexport const NATIVE_TOKEN_ADDRESS =\n '0x0000000000000000000000000000000000000000' as Hex;\n\nexport const ARBITRUM_USDC_ADDRESS =\n '0xaf88d065e77c8cC2239327C5EDb3A432268e5831' as Hex;\n\nexport const POLYGON_USDCE_ADDRESS =\n '0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174' as Hex;\n\nexport const POLYGON_PUSD_ADDRESS =\n '0xC011a7E12a19f7B1f670d46F03B03f3342E82DFB' as Hex;\n\nexport const MUSD_MONAD_ADDRESS =\n '0xaca92e438df0b2401ff60da7e4337b687a2435da' as Hex;\n\nexport const HYPERCORE_USDC_ADDRESS = '0x00000000000000000000000000000000';\n\nexport const HYPERCORE_USDC_DECIMALS = 8;\nexport const USDC_DECIMALS = 6;\n\nexport const SLIP44_COIN_TYPE_BY_CHAIN: Record<Hex, number> = {\n [CHAIN_ID_POLYGON]: 966, // POL\n};\n\nexport const STABLECOINS: Record<Hex, Hex[]> = {\n // Mainnet\n '0x1': [\n '0xaca92e438df0b2401ff60da7e4337b687a2435da', // MUSD\n '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', // USDC\n '0xdac17f958d2ee523a2206206994597c13d831ec7', // USDT\n ],\n [CHAIN_ID_ARBITRUM]: [ARBITRUM_USDC_ADDRESS.toLowerCase() as Hex],\n // Linea\n '0xe708': [\n '0xaca92e438df0b2401ff60da7e4337b687a2435da', // MUSD\n '0x176211869ca2b568f2a7d4ee941e073a821ee1ff', // USDC\n '0xa219439258ca9da29e9cc4ce5596924745e12b93', // USDT\n ],\n [CHAIN_ID_POLYGON]: [\n POLYGON_USDCE_ADDRESS.toLowerCase() as Hex,\n POLYGON_PUSD_ADDRESS.toLowerCase() as Hex,\n ],\n [CHAIN_ID_HYPERCORE]: [HYPERCORE_USDC_ADDRESS], // USDC\n};\n\nexport enum PaymentOverride {\n MoneyAccount = 'moneyAccount',\n Perps = 'perps',\n Predict = 'predict',\n}\n\n/**\n * Identifies the MetaMask client making MM Pay requests.\n *\n * Sent as the `X-Client-Id` header on requests to the intents API so the\n * server can distinguish Mobile traffic from Extension traffic.\n */\nexport enum TransactionPayClientId {\n Extension = 'extension',\n Mobile = 'mobile',\n}\n\n/** Header used to identify the calling client to the intents API. */\nexport const CLIENT_ID_HEADER = 'X-Client-Id';\n\nexport enum TransactionPayStrategy {\n Across = 'across',\n Fiat = 'fiat',\n /**\n * Internal marker for no-op quotes generated when the controller determines\n * that no conversion is needed. Not a routable strategy.\n */\n None = 'none',\n Relay = 'relay',\n Server = 'server',\n}\n\nconst VALID_STRATEGIES: Set<TransactionPayStrategy> = new Set(\n Object.values(TransactionPayStrategy).filter(\n (strategy) => strategy !== TransactionPayStrategy.None,\n ),\n);\n\n/**\n * Checks if a value is a valid, routable transaction pay strategy.\n * The internal no-op marker is not routable.\n *\n * @param strategy - Candidate strategy value.\n * @returns True if the value is a valid strategy.\n */\nexport function isTransactionPayStrategy(\n strategy: unknown,\n): strategy is TransactionPayStrategy {\n return VALID_STRATEGIES.has(strategy as TransactionPayStrategy);\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createModuleLogger } from '@metamask/utils';
|
|
2
2
|
import { TransactionPayStrategy } from '../constants.js';
|
|
3
3
|
import { projectLogger } from '../logger.js';
|
|
4
|
-
import { accountSupports7702 } from '../utils/
|
|
4
|
+
import { accountSupports7702 } from '../utils/account.js';
|
|
5
5
|
import { prefixError } from '../utils/error-prefix.js';
|
|
6
6
|
import { getStrategyByName } from '../utils/strategy.js';
|
|
7
7
|
import { updateTransaction } from '../utils/transaction.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TransactionPayPublishHook.js","sourceRoot":"","sources":["../../src/helpers/TransactionPayPublishHook.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAK7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"TransactionPayPublishHook.js","sourceRoot":"","sources":["../../src/helpers/TransactionPayPublishHook.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAK7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE5D,MAAM,GAAG,GAAG,kBAAkB,CAAC,aAAa,EAAE,kBAAkB,CAAC,CAAC;AAClE,MAAM,YAAY,GAAG,gBAAgB,CAAC;AAEtC,MAAM,YAAY,GAAG;IACnB,eAAe,EAAE,SAAS;CAC3B,CAAC;AAEF,MAA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IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;YACzC,CAAC;YAED,GAAG,CAAC,wCAAwC,EAAE,EAAE,aAAa,EAAE,CAAC,CAAC;YAEjE,OAAO,YAAY,CAAC;QACtB,CAAC;QAED,iBAAiB,CACf;YACE,aAAa;YACb,SAAS,EAAE,IAAI,CAAC,UAAU;YAC1B,IAAI,EAAE,6CAA6C;SACpD,EACD,CAAC,EAAE,EAAE,EAAE;YACL,EAAE,CAAC,aAAa,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAC;QAC1C,CAAC,CACF,CAAC;QAEF,MAAM,QAAQ,GAAG,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;QACvD,MAAM,IAAI,GAAG,eAAe,CAAC,QAAQ,CAAC,IAAW,CAAC;QAElD,OAAO,MAAM,QAAQ,CAAC,OAAO,CAAC;YAC5B,mBAAmB,EAAE,mBAAmB,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC;YAC/D,kBAAkB,EAAE,IAAI,CAAC,mBAAmB;YAC5C,MAAM;YACN,SAAS,EAAE,IAAI,CAAC,UAAU;YAC1B,WAAW,EAAE,eAAe;SAC7B,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import type { PublishHook } from '@metamask/transaction-controller';\nimport type { TransactionMeta } from '@metamask/transaction-controller';\nimport type { PublishHookResult } from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\nimport { createModuleLogger } from '@metamask/utils';\n\nimport { TransactionPayStrategy } from '../constants.js';\nimport { projectLogger } from '../logger.js';\nimport type {\n TransactionPayControllerMessenger,\n TransactionPayQuote,\n} from '../types.js';\nimport { accountSupports7702 } from '../utils/account.js';\nimport { prefixError } from '../utils/error-prefix.js';\nimport { getStrategyByName } from '../utils/strategy.js';\nimport { updateTransaction } from '../utils/transaction.js';\n\nconst log = createModuleLogger(projectLogger, 'pay-publish-hook');\nconst ERROR_PREFIX = 'MetaMask Pay: ';\n\nconst EMPTY_RESULT = {\n transactionHash: undefined,\n};\n\nexport class TransactionPayPublishHook {\n readonly #isSmartTransaction: (chainId: Hex) => boolean;\n\n readonly #messenger: TransactionPayControllerMessenger;\n\n constructor({\n isSmartTransaction,\n messenger,\n }: {\n isSmartTransaction: (chainId: Hex) => boolean;\n messenger: TransactionPayControllerMessenger;\n }) {\n this.#isSmartTransaction = isSmartTransaction;\n this.#messenger = messenger;\n }\n\n getHook(): PublishHook {\n return this.#hookWrapper.bind(this);\n }\n\n async #hookWrapper(\n transactionMeta: TransactionMeta,\n _signedTx: string,\n ): Promise<PublishHookResult> {\n try {\n return await this.#publishHook(transactionMeta, _signedTx);\n } catch (error) {\n log('Error', error);\n throw prefixError(error, ERROR_PREFIX);\n }\n }\n\n async #publishHook(\n transactionMeta: TransactionMeta,\n _signedTx: string,\n ): Promise<PublishHookResult> {\n const { id: transactionId } = transactionMeta;\n\n const controllerState = this.#messenger.call(\n 'TransactionPayController:getState',\n );\n\n const transactionData = controllerState.transactionData?.[transactionId];\n\n // No-op quotes mark direct routes and cannot be executed by any strategy.\n const quotes = (\n (transactionData?.quotes as TransactionPayQuote<unknown>[]) ?? []\n ).filter((quote) => quote.strategy !== TransactionPayStrategy.None);\n\n const isFiatSelected = Boolean(\n transactionData?.fiatPayment?.selectedPaymentMethodId,\n );\n\n if (!quotes.length) {\n if (isFiatSelected) {\n throw new Error('Fiat: Missing quote');\n }\n\n log('Skipping as no executable quotes found', { transactionId });\n\n return EMPTY_RESULT;\n }\n\n updateTransaction(\n {\n transactionId,\n messenger: this.#messenger,\n note: 'Set submittedTime at pay publish hook start',\n },\n (tx) => {\n tx.submittedTime = new Date().getTime();\n },\n );\n\n const strategy = getStrategyByName(quotes[0].strategy);\n const from = transactionMeta.txParams.from as Hex;\n\n return await strategy.execute({\n accountSupports7702: accountSupports7702(this.#messenger, from),\n isSmartTransaction: this.#isSmartTransaction,\n quotes,\n messenger: this.#messenger,\n transaction: transactionMeta,\n });\n }\n}\n"]}
|
|
@@ -3,7 +3,7 @@ import { TransactionType, hasTransactionType, } from '@metamask/transaction-cont
|
|
|
3
3
|
import { createModuleLogger } from '@metamask/utils';
|
|
4
4
|
import { PERPS_DEPOSIT_TYPES } from '../../constants.js';
|
|
5
5
|
import { projectLogger } from '../../logger.js';
|
|
6
|
-
import { accountSupports7702 } from '../../utils/
|
|
6
|
+
import { accountSupports7702 } from '../../utils/account.js';
|
|
7
7
|
import { getPayStrategiesConfig } from '../../utils/feature-flags.js';
|
|
8
8
|
import { getGasBuffer } from '../../utils/feature-flags.js';
|
|
9
9
|
import { GasPaymentMode, logGasPaymentOutcome, resolveGasPayment, } from '../../utils/gas-payment.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"across-submit.js","sourceRoot":"","sources":["../../../src/strategy/across/across-submit.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,eAAe,EACf,KAAK,GACN,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,eAAe,EACf,kBAAkB,GACnB,MAAM,kCAAkC,CAAC;AAO1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAMhD,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,iBAAiB,GAClB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EACL,qBAAqB,EACrB,cAAc,EACd,iBAAiB,EACjB,2BAA2B,GAC5B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,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AAC;AACJ,CAAC","sourcesContent":["import {\n ORIGIN_METAMASK,\n successfulFetch,\n toHex,\n} from '@metamask/controller-utils';\nimport {\n TransactionType,\n hasTransactionType,\n} from '@metamask/transaction-controller';\nimport type {\n BatchTransactionParams,\n TransactionMeta,\n TransactionParams,\n} from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\nimport { createModuleLogger } from '@metamask/utils';\n\nimport { PERPS_DEPOSIT_TYPES } from '../../constants.js';\nimport { projectLogger } from '../../logger.js';\nimport type {\n PayStrategyExecuteRequest,\n TransactionPayControllerMessenger,\n TransactionPayQuote,\n} from '../../types.js';\nimport { accountSupports7702 } from '../../utils/7702.js';\nimport { getPayStrategiesConfig } from '../../utils/feature-flags.js';\nimport { getGasBuffer } from '../../utils/feature-flags.js';\nimport {\n GasPaymentMode,\n logGasPaymentOutcome,\n resolveGasPayment,\n} from '../../utils/gas-payment.js';\nimport { getNetworkClientId } from '../../utils/provider.js';\nimport {\n collectTransactionIds,\n getTransaction,\n updateTransaction,\n waitForTransactionConfirmed,\n} from '../../utils/transaction.js';\nimport {\n getAcrossOrderedTransactions,\n getOriginalTransactionGas,\n} from './transactions.js';\nimport type { AcrossQuote } from './types.js';\n\nconst log = createModuleLogger(projectLogger, 'across-strategy');\nconst ACROSS_STATUS_POLL_INTERVAL = 1000;\n\ntype PreparedAcrossTransaction = {\n params: TransactionParams;\n type: TransactionMeta['type'];\n};\n\n/**\n * Submit Across quotes.\n *\n * @param request - Request object.\n * @returns An object containing the transaction hash if available.\n */\nexport async function submitAcrossQuotes(\n request: PayStrategyExecuteRequest<AcrossQuote>,\n): Promise<{ transactionHash?: Hex }> {\n log('Executing quotes', request);\n\n const { quotes, messenger, transaction } = request;\n let transactionHash: Hex | undefined;\n\n for (const quote of quotes) {\n ({ transactionHash } = await executeSingleQuote(\n quote,\n messenger,\n transaction,\n ));\n }\n\n return { transactionHash };\n}\n\nasync function executeSingleQuote(\n quote: TransactionPayQuote<AcrossQuote>,\n messenger: TransactionPayControllerMessenger,\n transaction: TransactionMeta,\n): Promise<{ transactionHash?: Hex }> {\n log('Executing single quote', quote);\n\n updateTransaction(\n {\n transactionId: transaction.id,\n messenger,\n note: 'Remove nonce from skipped transaction',\n },\n (tx) => {\n tx.txParams.nonce = undefined;\n },\n );\n\n const acrossDepositType = getAcrossDepositType(transaction);\n const transactionHash = await submitTransactions(\n quote,\n transaction,\n acrossDepositType,\n messenger,\n );\n\n updateTransaction(\n {\n transactionId: transaction.id,\n messenger,\n note: 'Intent complete after Across submission',\n },\n (tx) => {\n tx.isIntentComplete = true;\n },\n );\n\n return { transactionHash };\n}\n\n/**\n * Submit transactions for an Across quote.\n *\n * @param quote - Across quote.\n * @param parentTransaction - Parent transaction.\n * @param acrossDepositType - Transaction type used for the swap/deposit step.\n * @param messenger - Controller messenger.\n * @returns Hash of the last submitted transaction, if available.\n */\nasync function submitTransactions(\n quote: TransactionPayQuote<AcrossQuote>,\n parentTransaction: TransactionMeta,\n acrossDepositType: TransactionType,\n messenger: TransactionPayControllerMessenger,\n): Promise<Hex | undefined> {\n const { swapTx } = quote.original.quote;\n const { gasLimits: quoteGasLimits, is7702 } = quote.original.metamask;\n const { from, sourceTokenAddress } = quote.request;\n const chainId = toHex(swapTx.chainId);\n\n // Across has no relayer-paid delegation flow and is never sponsored, so the\n // only lift available is the gas station collecting gas in the source token.\n const gasPayment = resolveGasPayment({\n isSourceGasFeeToken: quote.fees.isSourceGasFeeToken,\n sourceTokenAddress,\n });\n const isGasFeeTokenPayment = gasPayment.mode === GasPaymentMode.GasFeeToken;\n\n const orderedTransactions = getAcrossOrderedTransactions({\n quote: quote.original.quote,\n swapType: acrossDepositType,\n });\n const shouldPrependOriginalTransaction =\n quote.request.isPostQuote === true &&\n parentTransaction.txParams.to !== undefined;\n const hasPrependedOriginalGasLimit =\n shouldPrependOriginalTransaction &&\n !is7702 &&\n quoteGasLimits.length > orderedTransactions.length;\n const gasLimitOffset = hasPrependedOriginalGasLimit ? 1 : 0;\n const transactionCount =\n orderedTransactions.length + (shouldPrependOriginalTransaction ? 1 : 0);\n\n const networkClientId = getNetworkClientId(messenger, chainId);\n\n const is7702Batch = is7702 && transactionCount > 1;\n const canUseQuotedBatchGasLimit =\n is7702Batch &&\n (!shouldPrependOriginalTransaction ||\n hasOriginalTransactionGas(parentTransaction));\n const batchGasLimit = canUseQuotedBatchGasLimit\n ? quoteGasLimits[0]?.max\n : undefined;\n\n if (canUseQuotedBatchGasLimit && batchGasLimit === undefined) {\n throw new Error('Missing quote gas limit for Across 7702 batch');\n }\n\n const quotedGasLimit7702 =\n batchGasLimit === undefined ? undefined : toHex(batchGasLimit);\n const parentHasAuthorizationList = Boolean(\n parentTransaction.txParams.authorizationList?.length,\n );\n\n const shouldUseGasFeeToken7702Submit = shouldEstimate7702SubmitBatch({\n isGasFeeTokenPayment,\n parentTransaction,\n quote,\n })\n ? accountSupports7702(messenger, from)\n : false;\n const shouldUse7702Submit = [\n Boolean(quotedGasLimit7702),\n is7702Batch,\n parentHasAuthorizationList,\n shouldUseGasFeeToken7702Submit,\n ].some(Boolean);\n\n const shouldEstimateGasLimit7702 = !quotedGasLimit7702 && shouldUse7702Submit;\n\n const estimatedGasLimit7702 = shouldEstimateGasLimit7702\n ? await estimateSubmitBatchGasLimit7702({\n chainId,\n from,\n messenger,\n orderedTransactions,\n parentTransaction,\n shouldPrependOriginalTransaction,\n })\n : undefined;\n\n const gasLimit7702 = quotedGasLimit7702 ?? estimatedGasLimit7702;\n const submitAs7702 = shouldUse7702Submit || Boolean(gasLimit7702);\n\n const acrossTransactions: PreparedAcrossTransaction[] =\n orderedTransactions.map((transaction, index) => {\n const gasLimit = submitAs7702\n ? undefined\n : quoteGasLimits[index + gasLimitOffset]?.max;\n\n if (gasLimit === undefined && !submitAs7702) {\n const quoteGasIndex = index + gasLimitOffset;\n const errorMessage =\n transaction.kind === 'approval'\n ? `Missing quote gas limit for Across approval transaction at index ${quoteGasIndex}`\n : 'Missing quote gas limit for Across swap transaction';\n\n throw new Error(errorMessage);\n }\n\n return {\n params: buildTransactionParams(from, {\n chainId: transaction.chainId,\n data: transaction.data,\n gasLimit,\n maxFeePerGas: transaction.maxFeePerGas,\n maxPriorityFeePerGas: transaction.maxPriorityFeePerGas,\n to: transaction.to,\n value: transaction.value,\n }),\n type: transaction.type ?? acrossDepositType,\n };\n });\n const originalTransaction = shouldPrependOriginalTransaction\n ? [\n buildOriginalTransaction(\n parentTransaction,\n submitAs7702 || !hasPrependedOriginalGasLimit\n ? undefined\n : quoteGasLimits[0]?.max,\n ),\n ]\n : [];\n const transactions = [...originalTransaction, ...acrossTransactions];\n\n const transactionIds: string[] = [];\n\n const { end } = collectTransactionIds(\n chainId,\n from,\n messenger,\n (transactionId) => {\n transactionIds.push(transactionId);\n\n updateTransaction(\n {\n transactionId: parentTransaction.id,\n messenger,\n note: 'Add required transaction ID from Across submission',\n },\n (tx) => {\n tx.requiredTransactionIds ??= [];\n tx.requiredTransactionIds.push(transactionId);\n },\n );\n },\n );\n\n let result: { result: Promise<string> } | undefined;\n const { excludeNativeTokenForFee, gasFeeToken } = gasPayment;\n\n try {\n if (transactions.length === 1) {\n result = await messenger.call(\n 'TransactionController:addTransaction',\n transactions[0].params,\n {\n excludeNativeTokenForFee,\n gasFeeToken,\n networkClientId,\n origin: ORIGIN_METAMASK,\n isInternal: true,\n requireApproval: false,\n type: transactions[0].type,\n },\n );\n } else {\n const batchTransactions = transactions.map(({ params, type }) => ({\n params: toBatchTransactionParams(params),\n type,\n }));\n\n await messenger.call('TransactionController:addTransactionBatch', {\n disable7702: !submitAs7702,\n disableHook: submitAs7702,\n disableSequential: submitAs7702,\n excludeNativeTokenForFee,\n from,\n gasFeeToken,\n gasLimit7702,\n networkClientId,\n origin: ORIGIN_METAMASK,\n isInternal: true,\n requireApproval: false,\n transactions: batchTransactions,\n });\n }\n } finally {\n end();\n }\n\n if (result) {\n const txHash = await result.result;\n log('Submitted transaction', txHash);\n }\n\n await Promise.all(\n transactionIds.map((txId) => waitForTransactionConfirmed(txId, messenger)),\n );\n\n logGasPaymentOutcome(\n gasPayment,\n transactionIds.map((txId) => getTransaction(txId, messenger)),\n );\n\n const hash = transactionIds.length\n ? getTransaction(transactionIds.slice(-1)[0], messenger)?.hash\n : undefined;\n\n return await waitForAcrossCompletion(hash as Hex | undefined, messenger);\n}\n\ntype AcrossStatusResponse = {\n depositId?: number | string;\n depositTxnRef?: Hex;\n status?: string;\n destinationTxHash?: Hex;\n fillTxnRef?: Hex;\n fillTxHash?: Hex;\n txHash?: Hex;\n};\n\n/**\n * Poll Across until a submitted deposit reaches a terminal status.\n *\n * @param transactionHash - Source-chain deposit transaction hash.\n * @param messenger - Controller messenger.\n * @returns Destination/fill transaction hash when available, otherwise the source hash.\n */\nasync function waitForAcrossCompletion(\n transactionHash: Hex | undefined,\n messenger: TransactionPayControllerMessenger,\n): Promise<Hex | undefined> {\n if (!transactionHash) {\n return transactionHash;\n }\n\n const config = getPayStrategiesConfig(messenger);\n const params = new URLSearchParams({\n depositTxnRef: transactionHash,\n });\n const url = `${config.across.apiBase}/deposit/status?${params.toString()}`;\n\n let attempt = 0;\n\n while (true) {\n attempt += 1;\n let status: AcrossStatusResponse;\n\n try {\n const response = await successfulFetch(url, {\n method: 'GET',\n headers: {\n Accept: 'application/json',\n },\n });\n status = (await response.json()) as AcrossStatusResponse;\n } catch (error) {\n log('Across status polling request failed', {\n attempt,\n error: String(error),\n transactionHash,\n });\n\n await new Promise((resolve) =>\n setTimeout(resolve, ACROSS_STATUS_POLL_INTERVAL),\n );\n continue;\n }\n\n const normalizedStatus = status.status?.toLowerCase();\n\n log('Polled Across status', {\n attempt,\n status: normalizedStatus,\n transactionHash,\n });\n\n if (\n normalizedStatus &&\n ['completed', 'filled', 'success'].includes(normalizedStatus)\n ) {\n return (\n status.destinationTxHash ??\n status.fillTxnRef ??\n status.fillTxHash ??\n status.txHash ??\n transactionHash\n );\n }\n\n if (\n normalizedStatus &&\n ['error', 'failed', 'refund', 'refunded'].includes(normalizedStatus)\n ) {\n throw new Error(`Across request failed with status: ${normalizedStatus}`);\n }\n\n await new Promise((resolve) =>\n setTimeout(resolve, ACROSS_STATUS_POLL_INTERVAL),\n );\n }\n}\n\n/**\n * Check whether submit should estimate a 7702 batch gas limit.\n *\n * This is needed for Predict withdraw post-quote flows that pay source-chain\n * gas with the source token, because the final submit batch can differ from the\n * batch shape that Across quoted.\n *\n * @param args - Check arguments.\n * @param args.isGasFeeTokenPayment - Whether source-chain gas is paid with a gas fee token.\n * @param args.parentTransaction - Original transaction metadata.\n * @param args.quote - Across quote selected for execution.\n * @returns Whether submit should try to estimate the final 7702 batch gas.\n */\nfunction shouldEstimate7702SubmitBatch({\n isGasFeeTokenPayment,\n parentTransaction,\n quote,\n}: {\n isGasFeeTokenPayment: boolean;\n parentTransaction: TransactionMeta;\n quote: TransactionPayQuote<AcrossQuote>;\n}): boolean {\n return (\n hasTransactionType(parentTransaction, [TransactionType.predictWithdraw]) &&\n quote.request.isPostQuote === true &&\n isGasFeeTokenPayment\n );\n}\n\n/**\n * Estimate the 7702 batch gas limit for the actual submit payload.\n *\n * Quotes can contain a combined 7702 gas limit that only covered the Across\n * approval/swap legs. When submit prepends the original transaction, estimate\n * the final batch shape so the gas limit covers every submitted leg.\n *\n * @param args - Estimation arguments.\n * @param args.chainId - Source chain ID.\n * @param args.from - Sender address.\n * @param args.messenger - Controller messenger.\n * @param args.orderedTransactions - Across approval/swap legs in submission order.\n * @param args.parentTransaction - Original transaction that may be prepended.\n * @param args.shouldPrependOriginalTransaction - Whether to include the original transaction in the estimate.\n * @returns Hex gas limit, or `undefined` when estimation is unavailable.\n */\nasync function estimateSubmitBatchGasLimit7702({\n chainId,\n from,\n messenger,\n orderedTransactions,\n parentTransaction,\n shouldPrependOriginalTransaction,\n}: {\n chainId: Hex;\n from: Hex;\n messenger: TransactionPayControllerMessenger;\n orderedTransactions: ReturnType<typeof getAcrossOrderedTransactions>;\n parentTransaction: TransactionMeta;\n shouldPrependOriginalTransaction: boolean;\n}): Promise<Hex | undefined> {\n if (!accountSupports7702(messenger, from)) {\n return undefined;\n }\n\n const originalTransaction = shouldPrependOriginalTransaction\n ? [buildOriginalTransaction(parentTransaction)]\n : [];\n\n const acrossTransactions = orderedTransactions.map((transaction) => ({\n params: buildTransactionParams(from, {\n chainId: transaction.chainId,\n data: transaction.data,\n maxFeePerGas: transaction.maxFeePerGas,\n maxPriorityFeePerGas: transaction.maxPriorityFeePerGas,\n to: transaction.to,\n value: transaction.value,\n }),\n type: transaction.type,\n }));\n\n const transactions = [...originalTransaction, ...acrossTransactions];\n\n try {\n const result = await messenger.call(\n 'TransactionController:estimateGasBatch',\n {\n chainId,\n from,\n transactions: transactions.map(({ params }) =>\n toBatchTransactionParams(params),\n ),\n },\n );\n\n // Older TransactionController versions return no `mode`, so detect a\n // combined EIP-7702 gas limit from the number of gas limits instead.\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n const is7702Result =\n result.mode === undefined\n ? result.gasLimits.length === 1\n : result.mode === 'eip7702';\n\n if (!is7702Result) {\n return undefined;\n }\n\n const gasLimit = Math.ceil(\n result.gasLimits[0] * getGasBuffer(messenger, chainId),\n );\n\n return toHex(gasLimit);\n } catch {\n return undefined;\n }\n}\n\n/**\n * Build the original parent transaction as a prepared batch leg.\n *\n * @param transaction - Original transaction metadata.\n * @param gasLimit - Optional gas limit to pin on the original leg.\n * @returns Prepared transaction params and transaction type for the original leg.\n */\nfunction buildOriginalTransaction(\n transaction: TransactionMeta,\n gasLimit?: number,\n): PreparedAcrossTransaction {\n return {\n params: {\n data: transaction.txParams.data,\n from: transaction.txParams.from,\n gas: gasLimit === undefined ? undefined : toHex(gasLimit),\n to: transaction.txParams.to,\n value: transaction.txParams.value,\n },\n type: getOriginalTransactionType(transaction),\n };\n}\n\n/**\n * Get the transaction type to use for the original batch leg.\n *\n * @param transaction - Original transaction metadata.\n * @returns `predictWithdraw` for Predict withdrawals; otherwise the original type.\n */\nfunction getOriginalTransactionType(\n transaction: TransactionMeta,\n): TransactionMeta['type'] {\n if (hasTransactionType(transaction, [TransactionType.predictWithdraw])) {\n return TransactionType.predictWithdraw;\n }\n\n return transaction.type;\n}\n\n/**\n * Check whether the original transaction already has a usable gas limit.\n *\n * @param transaction - Original transaction metadata.\n * @returns Whether the original or nested transaction gas is a positive integer.\n */\nfunction hasOriginalTransactionGas(transaction: TransactionMeta): boolean {\n return getOriginalTransactionGas(transaction) !== undefined;\n}\n\n/**\n * Get the transaction type for the Across bridge/deposit leg.\n *\n * @param transaction - Original parent transaction.\n * @returns Across-specific transaction type for known flows, or the original type.\n */\nfunction getAcrossDepositType(transaction: TransactionMeta): TransactionType {\n if (hasTransactionType(transaction, [TransactionType.predictWithdraw])) {\n return TransactionType.predictAcrossWithdraw;\n }\n\n if (transaction.type && PERPS_DEPOSIT_TYPES.includes(transaction.type)) {\n return TransactionType.perpsAcrossDeposit;\n }\n\n switch (transaction.type) {\n case TransactionType.predictDeposit:\n return TransactionType.predictAcrossDeposit;\n case undefined:\n return TransactionType.perpsAcrossDeposit;\n default:\n return transaction.type;\n }\n}\n\n/**\n * Build TransactionController params for an Across approval or swap leg.\n *\n * @param from - Sender address.\n * @param params - Across transaction fields.\n * @param params.chainId - Source chain ID.\n * @param params.data - Transaction calldata.\n * @param params.gasLimit - Optional gas limit.\n * @param params.to - Recipient contract address.\n * @param params.value - Optional native value.\n * @param params.maxFeePerGas - Optional EIP-1559 max fee.\n * @param params.maxPriorityFeePerGas - Optional EIP-1559 priority fee.\n * @returns TransactionController params.\n */\nfunction buildTransactionParams(\n from: Hex,\n params: {\n chainId: number;\n data: Hex;\n gasLimit?: number;\n to: Hex;\n value?: Hex;\n maxFeePerGas?: string;\n maxPriorityFeePerGas?: string;\n },\n): TransactionParams {\n const value = toHex(params.value ?? '0x0');\n\n return {\n data: params.data,\n from,\n gas: params.gasLimit === undefined ? undefined : toHex(params.gasLimit),\n maxFeePerGas: normalizeOptionalHex(params.maxFeePerGas),\n maxPriorityFeePerGas: normalizeOptionalHex(params.maxPriorityFeePerGas),\n to: params.to,\n value,\n };\n}\n\n/**\n * Normalize an optional numeric string or hex string into a hex value.\n *\n * @param value - Optional value to normalize.\n * @returns Hex value, or `undefined` when no value is provided.\n */\nfunction normalizeOptionalHex(value?: string): Hex | undefined {\n if (value === undefined) {\n return undefined;\n }\n\n return toHex(value);\n}\n\n/**\n * Convert full TransactionController params into batch transaction params.\n *\n * @param params - Transaction params.\n * @returns Batch-compatible transaction params.\n */\nfunction toBatchTransactionParams(\n params: TransactionParams,\n): BatchTransactionParams {\n return {\n data: params.data as Hex | undefined,\n gas: params.gas as Hex | undefined,\n maxFeePerGas: params.maxFeePerGas as Hex | undefined,\n maxPriorityFeePerGas: params.maxPriorityFeePerGas as Hex | undefined,\n to: params.to as Hex | undefined,\n value: params.value as Hex | undefined,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"across-submit.js","sourceRoot":"","sources":["../../../src/strategy/across/across-submit.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,eAAe,EACf,KAAK,GACN,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,eAAe,EACf,kBAAkB,GACnB,MAAM,kCAAkC,CAAC;AAO1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAMhD,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,iBAAiB,GAClB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EACL,qBAAqB,EACrB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pE,EAAE,EAAE,MAAM,CAAC,EAAqB;QAChC,KAAK,EAAE,MAAM,CAAC,KAAwB;KACvC,CAAC;AACJ,CAAC","sourcesContent":["import {\n ORIGIN_METAMASK,\n successfulFetch,\n toHex,\n} from '@metamask/controller-utils';\nimport {\n TransactionType,\n hasTransactionType,\n} from '@metamask/transaction-controller';\nimport type {\n BatchTransactionParams,\n TransactionMeta,\n TransactionParams,\n} from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\nimport { createModuleLogger } from '@metamask/utils';\n\nimport { PERPS_DEPOSIT_TYPES } from '../../constants.js';\nimport { projectLogger } from '../../logger.js';\nimport type {\n PayStrategyExecuteRequest,\n TransactionPayControllerMessenger,\n TransactionPayQuote,\n} from '../../types.js';\nimport { accountSupports7702 } from '../../utils/account.js';\nimport { getPayStrategiesConfig } from '../../utils/feature-flags.js';\nimport { getGasBuffer } from '../../utils/feature-flags.js';\nimport {\n GasPaymentMode,\n logGasPaymentOutcome,\n resolveGasPayment,\n} from '../../utils/gas-payment.js';\nimport { getNetworkClientId } from '../../utils/provider.js';\nimport {\n collectTransactionIds,\n getTransaction,\n updateTransaction,\n waitForTransactionConfirmed,\n} from '../../utils/transaction.js';\nimport {\n getAcrossOrderedTransactions,\n getOriginalTransactionGas,\n} from './transactions.js';\nimport type { AcrossQuote } from './types.js';\n\nconst log = createModuleLogger(projectLogger, 'across-strategy');\nconst ACROSS_STATUS_POLL_INTERVAL = 1000;\n\ntype PreparedAcrossTransaction = {\n params: TransactionParams;\n type: TransactionMeta['type'];\n};\n\n/**\n * Submit Across quotes.\n *\n * @param request - Request object.\n * @returns An object containing the transaction hash if available.\n */\nexport async function submitAcrossQuotes(\n request: PayStrategyExecuteRequest<AcrossQuote>,\n): Promise<{ transactionHash?: Hex }> {\n log('Executing quotes', request);\n\n const { quotes, messenger, transaction } = request;\n let transactionHash: Hex | undefined;\n\n for (const quote of quotes) {\n ({ transactionHash } = await executeSingleQuote(\n quote,\n messenger,\n transaction,\n ));\n }\n\n return { transactionHash };\n}\n\nasync function executeSingleQuote(\n quote: TransactionPayQuote<AcrossQuote>,\n messenger: TransactionPayControllerMessenger,\n transaction: TransactionMeta,\n): Promise<{ transactionHash?: Hex }> {\n log('Executing single quote', quote);\n\n updateTransaction(\n {\n transactionId: transaction.id,\n messenger,\n note: 'Remove nonce from skipped transaction',\n },\n (tx) => {\n tx.txParams.nonce = undefined;\n },\n );\n\n const acrossDepositType = getAcrossDepositType(transaction);\n const transactionHash = await submitTransactions(\n quote,\n transaction,\n acrossDepositType,\n messenger,\n );\n\n updateTransaction(\n {\n transactionId: transaction.id,\n messenger,\n note: 'Intent complete after Across submission',\n },\n (tx) => {\n tx.isIntentComplete = true;\n },\n );\n\n return { transactionHash };\n}\n\n/**\n * Submit transactions for an Across quote.\n *\n * @param quote - Across quote.\n * @param parentTransaction - Parent transaction.\n * @param acrossDepositType - Transaction type used for the swap/deposit step.\n * @param messenger - Controller messenger.\n * @returns Hash of the last submitted transaction, if available.\n */\nasync function submitTransactions(\n quote: TransactionPayQuote<AcrossQuote>,\n parentTransaction: TransactionMeta,\n acrossDepositType: TransactionType,\n messenger: TransactionPayControllerMessenger,\n): Promise<Hex | undefined> {\n const { swapTx } = quote.original.quote;\n const { gasLimits: quoteGasLimits, is7702 } = quote.original.metamask;\n const { from, sourceTokenAddress } = quote.request;\n const chainId = toHex(swapTx.chainId);\n\n // Across has no relayer-paid delegation flow and is never sponsored, so the\n // only lift available is the gas station collecting gas in the source token.\n const gasPayment = resolveGasPayment({\n isSourceGasFeeToken: quote.fees.isSourceGasFeeToken,\n sourceTokenAddress,\n });\n const isGasFeeTokenPayment = gasPayment.mode === GasPaymentMode.GasFeeToken;\n\n const orderedTransactions = getAcrossOrderedTransactions({\n quote: quote.original.quote,\n swapType: acrossDepositType,\n });\n const shouldPrependOriginalTransaction =\n quote.request.isPostQuote === true &&\n parentTransaction.txParams.to !== undefined;\n const hasPrependedOriginalGasLimit =\n shouldPrependOriginalTransaction &&\n !is7702 &&\n quoteGasLimits.length > orderedTransactions.length;\n const gasLimitOffset = hasPrependedOriginalGasLimit ? 1 : 0;\n const transactionCount =\n orderedTransactions.length + (shouldPrependOriginalTransaction ? 1 : 0);\n\n const networkClientId = getNetworkClientId(messenger, chainId);\n\n const is7702Batch = is7702 && transactionCount > 1;\n const canUseQuotedBatchGasLimit =\n is7702Batch &&\n (!shouldPrependOriginalTransaction ||\n hasOriginalTransactionGas(parentTransaction));\n const batchGasLimit = canUseQuotedBatchGasLimit\n ? quoteGasLimits[0]?.max\n : undefined;\n\n if (canUseQuotedBatchGasLimit && batchGasLimit === undefined) {\n throw new Error('Missing quote gas limit for Across 7702 batch');\n }\n\n const quotedGasLimit7702 =\n batchGasLimit === undefined ? undefined : toHex(batchGasLimit);\n const parentHasAuthorizationList = Boolean(\n parentTransaction.txParams.authorizationList?.length,\n );\n\n const shouldUseGasFeeToken7702Submit = shouldEstimate7702SubmitBatch({\n isGasFeeTokenPayment,\n parentTransaction,\n quote,\n })\n ? accountSupports7702(messenger, from)\n : false;\n const shouldUse7702Submit = [\n Boolean(quotedGasLimit7702),\n is7702Batch,\n parentHasAuthorizationList,\n shouldUseGasFeeToken7702Submit,\n ].some(Boolean);\n\n const shouldEstimateGasLimit7702 = !quotedGasLimit7702 && shouldUse7702Submit;\n\n const estimatedGasLimit7702 = shouldEstimateGasLimit7702\n ? await estimateSubmitBatchGasLimit7702({\n chainId,\n from,\n messenger,\n orderedTransactions,\n parentTransaction,\n shouldPrependOriginalTransaction,\n })\n : undefined;\n\n const gasLimit7702 = quotedGasLimit7702 ?? estimatedGasLimit7702;\n const submitAs7702 = shouldUse7702Submit || Boolean(gasLimit7702);\n\n const acrossTransactions: PreparedAcrossTransaction[] =\n orderedTransactions.map((transaction, index) => {\n const gasLimit = submitAs7702\n ? undefined\n : quoteGasLimits[index + gasLimitOffset]?.max;\n\n if (gasLimit === undefined && !submitAs7702) {\n const quoteGasIndex = index + gasLimitOffset;\n const errorMessage =\n transaction.kind === 'approval'\n ? `Missing quote gas limit for Across approval transaction at index ${quoteGasIndex}`\n : 'Missing quote gas limit for Across swap transaction';\n\n throw new Error(errorMessage);\n }\n\n return {\n params: buildTransactionParams(from, {\n chainId: transaction.chainId,\n data: transaction.data,\n gasLimit,\n maxFeePerGas: transaction.maxFeePerGas,\n maxPriorityFeePerGas: transaction.maxPriorityFeePerGas,\n to: transaction.to,\n value: transaction.value,\n }),\n type: transaction.type ?? acrossDepositType,\n };\n });\n const originalTransaction = shouldPrependOriginalTransaction\n ? [\n buildOriginalTransaction(\n parentTransaction,\n submitAs7702 || !hasPrependedOriginalGasLimit\n ? undefined\n : quoteGasLimits[0]?.max,\n ),\n ]\n : [];\n const transactions = [...originalTransaction, ...acrossTransactions];\n\n const transactionIds: string[] = [];\n\n const { end } = collectTransactionIds(\n chainId,\n from,\n messenger,\n (transactionId) => {\n transactionIds.push(transactionId);\n\n updateTransaction(\n {\n transactionId: parentTransaction.id,\n messenger,\n note: 'Add required transaction ID from Across submission',\n },\n (tx) => {\n tx.requiredTransactionIds ??= [];\n tx.requiredTransactionIds.push(transactionId);\n },\n );\n },\n );\n\n let result: { result: Promise<string> } | undefined;\n const { excludeNativeTokenForFee, gasFeeToken } = gasPayment;\n\n try {\n if (transactions.length === 1) {\n result = await messenger.call(\n 'TransactionController:addTransaction',\n transactions[0].params,\n {\n excludeNativeTokenForFee,\n gasFeeToken,\n networkClientId,\n origin: ORIGIN_METAMASK,\n isInternal: true,\n requireApproval: false,\n type: transactions[0].type,\n },\n );\n } else {\n const batchTransactions = transactions.map(({ params, type }) => ({\n params: toBatchTransactionParams(params),\n type,\n }));\n\n await messenger.call('TransactionController:addTransactionBatch', {\n disable7702: !submitAs7702,\n disableHook: submitAs7702,\n disableSequential: submitAs7702,\n excludeNativeTokenForFee,\n from,\n gasFeeToken,\n gasLimit7702,\n networkClientId,\n origin: ORIGIN_METAMASK,\n isInternal: true,\n requireApproval: false,\n transactions: batchTransactions,\n });\n }\n } finally {\n end();\n }\n\n if (result) {\n const txHash = await result.result;\n log('Submitted transaction', txHash);\n }\n\n await Promise.all(\n transactionIds.map((txId) => waitForTransactionConfirmed(txId, messenger)),\n );\n\n logGasPaymentOutcome(\n gasPayment,\n transactionIds.map((txId) => getTransaction(txId, messenger)),\n );\n\n const hash = transactionIds.length\n ? getTransaction(transactionIds.slice(-1)[0], messenger)?.hash\n : undefined;\n\n return await waitForAcrossCompletion(hash as Hex | undefined, messenger);\n}\n\ntype AcrossStatusResponse = {\n depositId?: number | string;\n depositTxnRef?: Hex;\n status?: string;\n destinationTxHash?: Hex;\n fillTxnRef?: Hex;\n fillTxHash?: Hex;\n txHash?: Hex;\n};\n\n/**\n * Poll Across until a submitted deposit reaches a terminal status.\n *\n * @param transactionHash - Source-chain deposit transaction hash.\n * @param messenger - Controller messenger.\n * @returns Destination/fill transaction hash when available, otherwise the source hash.\n */\nasync function waitForAcrossCompletion(\n transactionHash: Hex | undefined,\n messenger: TransactionPayControllerMessenger,\n): Promise<Hex | undefined> {\n if (!transactionHash) {\n return transactionHash;\n }\n\n const config = getPayStrategiesConfig(messenger);\n const params = new URLSearchParams({\n depositTxnRef: transactionHash,\n });\n const url = `${config.across.apiBase}/deposit/status?${params.toString()}`;\n\n let attempt = 0;\n\n while (true) {\n attempt += 1;\n let status: AcrossStatusResponse;\n\n try {\n const response = await successfulFetch(url, {\n method: 'GET',\n headers: {\n Accept: 'application/json',\n },\n });\n status = (await response.json()) as AcrossStatusResponse;\n } catch (error) {\n log('Across status polling request failed', {\n attempt,\n error: String(error),\n transactionHash,\n });\n\n await new Promise((resolve) =>\n setTimeout(resolve, ACROSS_STATUS_POLL_INTERVAL),\n );\n continue;\n }\n\n const normalizedStatus = status.status?.toLowerCase();\n\n log('Polled Across status', {\n attempt,\n status: normalizedStatus,\n transactionHash,\n });\n\n if (\n normalizedStatus &&\n ['completed', 'filled', 'success'].includes(normalizedStatus)\n ) {\n return (\n status.destinationTxHash ??\n status.fillTxnRef ??\n status.fillTxHash ??\n status.txHash ??\n transactionHash\n );\n }\n\n if (\n normalizedStatus &&\n ['error', 'failed', 'refund', 'refunded'].includes(normalizedStatus)\n ) {\n throw new Error(`Across request failed with status: ${normalizedStatus}`);\n }\n\n await new Promise((resolve) =>\n setTimeout(resolve, ACROSS_STATUS_POLL_INTERVAL),\n );\n }\n}\n\n/**\n * Check whether submit should estimate a 7702 batch gas limit.\n *\n * This is needed for Predict withdraw post-quote flows that pay source-chain\n * gas with the source token, because the final submit batch can differ from the\n * batch shape that Across quoted.\n *\n * @param args - Check arguments.\n * @param args.isGasFeeTokenPayment - Whether source-chain gas is paid with a gas fee token.\n * @param args.parentTransaction - Original transaction metadata.\n * @param args.quote - Across quote selected for execution.\n * @returns Whether submit should try to estimate the final 7702 batch gas.\n */\nfunction shouldEstimate7702SubmitBatch({\n isGasFeeTokenPayment,\n parentTransaction,\n quote,\n}: {\n isGasFeeTokenPayment: boolean;\n parentTransaction: TransactionMeta;\n quote: TransactionPayQuote<AcrossQuote>;\n}): boolean {\n return (\n hasTransactionType(parentTransaction, [TransactionType.predictWithdraw]) &&\n quote.request.isPostQuote === true &&\n isGasFeeTokenPayment\n );\n}\n\n/**\n * Estimate the 7702 batch gas limit for the actual submit payload.\n *\n * Quotes can contain a combined 7702 gas limit that only covered the Across\n * approval/swap legs. When submit prepends the original transaction, estimate\n * the final batch shape so the gas limit covers every submitted leg.\n *\n * @param args - Estimation arguments.\n * @param args.chainId - Source chain ID.\n * @param args.from - Sender address.\n * @param args.messenger - Controller messenger.\n * @param args.orderedTransactions - Across approval/swap legs in submission order.\n * @param args.parentTransaction - Original transaction that may be prepended.\n * @param args.shouldPrependOriginalTransaction - Whether to include the original transaction in the estimate.\n * @returns Hex gas limit, or `undefined` when estimation is unavailable.\n */\nasync function estimateSubmitBatchGasLimit7702({\n chainId,\n from,\n messenger,\n orderedTransactions,\n parentTransaction,\n shouldPrependOriginalTransaction,\n}: {\n chainId: Hex;\n from: Hex;\n messenger: TransactionPayControllerMessenger;\n orderedTransactions: ReturnType<typeof getAcrossOrderedTransactions>;\n parentTransaction: TransactionMeta;\n shouldPrependOriginalTransaction: boolean;\n}): Promise<Hex | undefined> {\n if (!accountSupports7702(messenger, from)) {\n return undefined;\n }\n\n const originalTransaction = shouldPrependOriginalTransaction\n ? [buildOriginalTransaction(parentTransaction)]\n : [];\n\n const acrossTransactions = orderedTransactions.map((transaction) => ({\n params: buildTransactionParams(from, {\n chainId: transaction.chainId,\n data: transaction.data,\n maxFeePerGas: transaction.maxFeePerGas,\n maxPriorityFeePerGas: transaction.maxPriorityFeePerGas,\n to: transaction.to,\n value: transaction.value,\n }),\n type: transaction.type,\n }));\n\n const transactions = [...originalTransaction, ...acrossTransactions];\n\n try {\n const result = await messenger.call(\n 'TransactionController:estimateGasBatch',\n {\n chainId,\n from,\n transactions: transactions.map(({ params }) =>\n toBatchTransactionParams(params),\n ),\n },\n );\n\n // Older TransactionController versions return no `mode`, so detect a\n // combined EIP-7702 gas limit from the number of gas limits instead.\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n const is7702Result =\n result.mode === undefined\n ? result.gasLimits.length === 1\n : result.mode === 'eip7702';\n\n if (!is7702Result) {\n return undefined;\n }\n\n const gasLimit = Math.ceil(\n result.gasLimits[0] * getGasBuffer(messenger, chainId),\n );\n\n return toHex(gasLimit);\n } catch {\n return undefined;\n }\n}\n\n/**\n * Build the original parent transaction as a prepared batch leg.\n *\n * @param transaction - Original transaction metadata.\n * @param gasLimit - Optional gas limit to pin on the original leg.\n * @returns Prepared transaction params and transaction type for the original leg.\n */\nfunction buildOriginalTransaction(\n transaction: TransactionMeta,\n gasLimit?: number,\n): PreparedAcrossTransaction {\n return {\n params: {\n data: transaction.txParams.data,\n from: transaction.txParams.from,\n gas: gasLimit === undefined ? undefined : toHex(gasLimit),\n to: transaction.txParams.to,\n value: transaction.txParams.value,\n },\n type: getOriginalTransactionType(transaction),\n };\n}\n\n/**\n * Get the transaction type to use for the original batch leg.\n *\n * @param transaction - Original transaction metadata.\n * @returns `predictWithdraw` for Predict withdrawals; otherwise the original type.\n */\nfunction getOriginalTransactionType(\n transaction: TransactionMeta,\n): TransactionMeta['type'] {\n if (hasTransactionType(transaction, [TransactionType.predictWithdraw])) {\n return TransactionType.predictWithdraw;\n }\n\n return transaction.type;\n}\n\n/**\n * Check whether the original transaction already has a usable gas limit.\n *\n * @param transaction - Original transaction metadata.\n * @returns Whether the original or nested transaction gas is a positive integer.\n */\nfunction hasOriginalTransactionGas(transaction: TransactionMeta): boolean {\n return getOriginalTransactionGas(transaction) !== undefined;\n}\n\n/**\n * Get the transaction type for the Across bridge/deposit leg.\n *\n * @param transaction - Original parent transaction.\n * @returns Across-specific transaction type for known flows, or the original type.\n */\nfunction getAcrossDepositType(transaction: TransactionMeta): TransactionType {\n if (hasTransactionType(transaction, [TransactionType.predictWithdraw])) {\n return TransactionType.predictAcrossWithdraw;\n }\n\n if (transaction.type && PERPS_DEPOSIT_TYPES.includes(transaction.type)) {\n return TransactionType.perpsAcrossDeposit;\n }\n\n switch (transaction.type) {\n case TransactionType.predictDeposit:\n return TransactionType.predictAcrossDeposit;\n case undefined:\n return TransactionType.perpsAcrossDeposit;\n default:\n return transaction.type;\n }\n}\n\n/**\n * Build TransactionController params for an Across approval or swap leg.\n *\n * @param from - Sender address.\n * @param params - Across transaction fields.\n * @param params.chainId - Source chain ID.\n * @param params.data - Transaction calldata.\n * @param params.gasLimit - Optional gas limit.\n * @param params.to - Recipient contract address.\n * @param params.value - Optional native value.\n * @param params.maxFeePerGas - Optional EIP-1559 max fee.\n * @param params.maxPriorityFeePerGas - Optional EIP-1559 priority fee.\n * @returns TransactionController params.\n */\nfunction buildTransactionParams(\n from: Hex,\n params: {\n chainId: number;\n data: Hex;\n gasLimit?: number;\n to: Hex;\n value?: Hex;\n maxFeePerGas?: string;\n maxPriorityFeePerGas?: string;\n },\n): TransactionParams {\n const value = toHex(params.value ?? '0x0');\n\n return {\n data: params.data,\n from,\n gas: params.gasLimit === undefined ? undefined : toHex(params.gasLimit),\n maxFeePerGas: normalizeOptionalHex(params.maxFeePerGas),\n maxPriorityFeePerGas: normalizeOptionalHex(params.maxPriorityFeePerGas),\n to: params.to,\n value,\n };\n}\n\n/**\n * Normalize an optional numeric string or hex string into a hex value.\n *\n * @param value - Optional value to normalize.\n * @returns Hex value, or `undefined` when no value is provided.\n */\nfunction normalizeOptionalHex(value?: string): Hex | undefined {\n if (value === undefined) {\n return undefined;\n }\n\n return toHex(value);\n}\n\n/**\n * Convert full TransactionController params into batch transaction params.\n *\n * @param params - Transaction params.\n * @returns Batch-compatible transaction params.\n */\nfunction toBatchTransactionParams(\n params: TransactionParams,\n): BatchTransactionParams {\n return {\n data: params.data as Hex | undefined,\n gas: params.gas as Hex | undefined,\n maxFeePerGas: params.maxFeePerGas as Hex | undefined,\n maxPriorityFeePerGas: params.maxPriorityFeePerGas as Hex | undefined,\n to: params.to as Hex | undefined,\n value: params.value as Hex | undefined,\n };\n}\n"]}
|
|
@@ -2,7 +2,6 @@ import { TransactionType } from '@metamask/transaction-controller';
|
|
|
2
2
|
import type { Hex } from '@metamask/utils';
|
|
3
3
|
import type { RelayStatus } from './types.js';
|
|
4
4
|
export declare const FALLBACK_HASH: Hex;
|
|
5
|
-
export declare const ATOMIC_PROMOTION_FAILURE_PREFIX = "Atomic promotion failed: ";
|
|
6
5
|
export declare const RELAY_URL_BASE = "https://api.relay.link";
|
|
7
6
|
export declare const RELAY_AUTHORIZE_URL = "https://api.relay.link/authorize";
|
|
8
7
|
export declare const RELAY_EXECUTE_URL = "https://api.relay.link/execute";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/strategy/relay/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAG3C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,eAAO,MAAM,aAAa,EAAY,GAAG,CAAC;AAE1C,eAAO,MAAM
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/strategy/relay/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAG3C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,eAAO,MAAM,aAAa,EAAY,GAAG,CAAC;AAE1C,eAAO,MAAM,cAAc,2BAA2B,CAAC;AACvD,eAAO,MAAM,mBAAmB,qCAAgC,CAAC;AACjE,eAAO,MAAM,iBAAiB,mCAA8B,CAAC;AAC7D,eAAO,MAAM,eAAe,iCAA4B,CAAC;AACzD,eAAO,MAAM,gBAAgB,6CAAwC,CAAC;AACtE,eAAO,MAAM,oBAAoB,gCAAgC,CAAC;AAClE,eAAO,MAAM,oBAAoB,qCAAiC,CAAC;AACnE,eAAO,MAAM,wBAAwB,yCAAqC,CAAC;AAC3E,eAAO,MAAM,sBAAsB,OAAO,CAAC;AAC3C,eAAO,MAAM,wBAAwB,eAAe,CAAC;AAErD,eAAO,MAAM,sBAAsB,EAAE,WAAW,EAI/C,CAAC;AAEF,eAAO,MAAM,sBAAsB,EAAE,WAAW,EAM/C,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAS/D,CAAC"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { TransactionType } from '@metamask/transaction-controller';
|
|
2
2
|
import { PERPS_DEPOSIT_TYPES } from '../../constants.js';
|
|
3
3
|
export const FALLBACK_HASH = '0x0';
|
|
4
|
-
export const ATOMIC_PROMOTION_FAILURE_PREFIX = 'Atomic promotion failed: ';
|
|
5
4
|
export const RELAY_URL_BASE = 'https://api.relay.link';
|
|
6
5
|
export const RELAY_AUTHORIZE_URL = `${RELAY_URL_BASE}/authorize`;
|
|
7
6
|
export const RELAY_EXECUTE_URL = `${RELAY_URL_BASE}/execute`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/strategy/relay/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAGnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAGzD,MAAM,CAAC,MAAM,aAAa,GAAG,KAAY,CAAC;AAE1C,MAAM,CAAC,MAAM
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/strategy/relay/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAGnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAGzD,MAAM,CAAC,MAAM,aAAa,GAAG,KAAY,CAAC;AAE1C,MAAM,CAAC,MAAM,cAAc,GAAG,wBAAwB,CAAC;AACvD,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAG,cAAc,YAAY,CAAC;AACjE,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,cAAc,UAAU,CAAC;AAC7D,MAAM,CAAC,MAAM,eAAe,GAAG,GAAG,cAAc,QAAQ,CAAC;AACzD,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,cAAc,oBAAoB,CAAC;AACtE,MAAM,CAAC,MAAM,oBAAoB,GAAG,6BAA6B,CAAC;AAClE,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAG,oBAAoB,OAAO,CAAC;AACnE,MAAM,CAAC,MAAM,wBAAwB,GAAG,GAAG,oBAAoB,WAAW,CAAC;AAC3E,MAAM,CAAC,MAAM,sBAAsB,GAAG,IAAI,CAAC,CAAC,WAAW;AACvD,MAAM,CAAC,MAAM,wBAAwB,GAAG,YAAY,CAAC;AAErD,MAAM,CAAC,MAAM,sBAAsB,GAAkB;IACnD,SAAS;IACT,QAAQ;IACR,UAAU;CACX,CAAC;AAEF,MAAM,CAAC,MAAM,sBAAsB,GAAkB;IACnD,SAAS;IACT,YAAY;IACZ,SAAS;IACT,WAAW;IACX,SAAS;CACV,CAAC;AAEF,MAAM,CAAC,MAAM,mBAAmB,GAAoC;IAClE,CAAC,eAAe,CAAC,cAAc,CAAC,EAAE,eAAe,CAAC,gBAAgB;IAClE,CAAC,eAAe,CAAC,cAAc,CAAC,EAAE,eAAe,CAAC,mBAAmB;IACrE,GAAG,MAAM,CAAC,WAAW,CACnB,mBAAmB,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;QAChC,IAAI;QACJ,eAAe,CAAC,iBAAiB;KAClC,CAAC,CACH;CACF,CAAC","sourcesContent":["import { TransactionType } from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\n\nimport { PERPS_DEPOSIT_TYPES } from '../../constants.js';\nimport type { RelayStatus } from './types.js';\n\nexport const FALLBACK_HASH = '0x0' as Hex;\n\nexport const RELAY_URL_BASE = 'https://api.relay.link';\nexport const RELAY_AUTHORIZE_URL = `${RELAY_URL_BASE}/authorize`;\nexport const RELAY_EXECUTE_URL = `${RELAY_URL_BASE}/execute`;\nexport const RELAY_QUOTE_URL = `${RELAY_URL_BASE}/quote`;\nexport const RELAY_STATUS_URL = `${RELAY_URL_BASE}/intents/status/v3`;\nexport const HYPERLIQUID_URL_BASE = 'https://api.hyperliquid.xyz';\nexport const HYPERLIQUID_INFO_URL = `${HYPERLIQUID_URL_BASE}/info`;\nexport const HYPERLIQUID_EXCHANGE_URL = `${HYPERLIQUID_URL_BASE}/exchange`;\nexport const RELAY_POLLING_INTERVAL = 1000; // 1 Second\nexport const TOKEN_TRANSFER_FOUR_BYTE = '0xa9059cbb';\n\nexport const RELAY_FAILURE_STATUSES: RelayStatus[] = [\n 'failure',\n 'refund',\n 'refunded',\n];\n\nexport const RELAY_PENDING_STATUSES: RelayStatus[] = [\n 'delayed',\n 'depositing',\n 'pending',\n 'submitted',\n 'waiting',\n];\n\nexport const RELAY_DEPOSIT_TYPES: Record<string, TransactionType> = {\n [TransactionType.musdConversion]: TransactionType.musdRelayDeposit,\n [TransactionType.predictDeposit]: TransactionType.predictRelayDeposit,\n ...Object.fromEntries(\n PERPS_DEPOSIT_TYPES.map((type) => [\n type,\n TransactionType.perpsRelayDeposit,\n ]),\n ),\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"relay-quotes.d.ts","sourceRoot":"","sources":["../../../src/strategy/relay/relay-quotes.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAGV,2BAA2B,EAG3B,mBAAmB,EACpB,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"relay-quotes.d.ts","sourceRoot":"","sources":["../../../src/strategy/relay/relay-quotes.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAGV,2BAA2B,EAG3B,mBAAmB,EACpB,MAAM,gBAAgB,CAAC;AAgDxB,OAAO,KAAK,EACV,UAAU,EAIX,MAAM,YAAY,CAAC;AASpB;;;;;GAKG;AACH,wBAAsB,cAAc,CAClC,OAAO,EAAE,2BAA2B,GACnC,OAAO,CAAC,mBAAmB,CAAC,UAAU,CAAC,EAAE,CAAC,CAuD5C"}
|
|
@@ -7,9 +7,10 @@ import { ARBITRUM_USDC_ADDRESS, CHAIN_ID_ARBITRUM, CHAIN_ID_HYPERCORE, CHAIN_ID_
|
|
|
7
7
|
import { TransactionPayStrategy } from '../../index.js';
|
|
8
8
|
import { projectLogger } from '../../logger.js';
|
|
9
9
|
import { getFiatValueFromUsd } from '../../utils/amounts.js';
|
|
10
|
-
import { getRelayOriginGasOverhead, getSlippage, getStablecoins,
|
|
10
|
+
import { getRelayOriginGasOverhead, getSlippage, getStablecoins, isEIP7702Chain, isRelayExecuteEnabled, } from '../../utils/feature-flags.js';
|
|
11
11
|
import { GasPaymentMode, resolveGasPayment, resolveGasStationCost, } from '../../utils/gas-payment.js';
|
|
12
12
|
import { calculateGasCost } from '../../utils/gas.js';
|
|
13
|
+
import { getMaxQuotes, isAtomicMaxQuote, isAtomicMaxSupported, } from '../../utils/max-quote.js';
|
|
13
14
|
import { normalizePerpsDepositRequest, normalizePerpsWithdrawRequest, } from '../../utils/perps.js';
|
|
14
15
|
import { getPolymarketDepositWalletOverrides, getPredictWithdrawFeeTokenAccount, getPredictWithdrawSafeAddress, } from '../../utils/polymarket/withdraw.js';
|
|
15
16
|
import { processPostQuotePaymentOverride } from '../../utils/post-quote-payment-override.js';
|
|
@@ -22,7 +23,7 @@ import { TOKEN_TRANSFER_FOUR_BYTE } from './constants.js';
|
|
|
22
23
|
import { hasRelayDepositStep } from './deposit-step.js';
|
|
23
24
|
import { applyHyperliquidActivationFee } from './hyperliquid-activation.js';
|
|
24
25
|
import { fetchRelayQuote } from './relay-api.js';
|
|
25
|
-
import {
|
|
26
|
+
import { isSubsidizedRelayQuote } from './relay-submit-execute.js';
|
|
26
27
|
import { validateRelayQuotes } from './relay-validation.js';
|
|
27
28
|
const log = createModuleLogger(projectLogger, 'relay-strategy');
|
|
28
29
|
const ZERO_AMOUNT = { fiat: '0', human: '0', raw: '0', usd: '0' };
|
|
@@ -48,29 +49,16 @@ export async function getRelayQuotes(request) {
|
|
|
48
49
|
.map((normalizedRequest) => applyHyperliquidActivationFee(normalizedRequest, request.messenger, request.transaction, request.signal)));
|
|
49
50
|
log('Normalized requests', normalizedRequests);
|
|
50
51
|
const quotes = await Promise.all(normalizedRequests.map((singleRequest) => getQuoteWithMaxAmountHandling(singleRequest, request)));
|
|
51
|
-
|
|
52
|
-
const
|
|
53
|
-
if (
|
|
52
|
+
// Atomic max quotes are validated as part of the max flow.
|
|
53
|
+
const quotesToValidate = quotes.filter((quote) => !isAtomicMaxQuote(quote));
|
|
54
|
+
if (quotesToValidate.length > 0) {
|
|
54
55
|
await validateRelayQuotes({
|
|
55
56
|
messenger: request.messenger,
|
|
56
|
-
quotes:
|
|
57
|
+
quotes: quotesToValidate,
|
|
57
58
|
signal: request.signal,
|
|
58
59
|
transaction: request.transaction,
|
|
59
60
|
});
|
|
60
61
|
}
|
|
61
|
-
if (atomicMaxQuotes.length > 0) {
|
|
62
|
-
try {
|
|
63
|
-
await validateRelayQuotes({
|
|
64
|
-
messenger: request.messenger,
|
|
65
|
-
quotes: atomicMaxQuotes,
|
|
66
|
-
signal: request.signal,
|
|
67
|
-
transaction: request.transaction,
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
catch (error) {
|
|
71
|
-
throwAtomicPromotionFailed(error);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
62
|
return quotes;
|
|
75
63
|
}
|
|
76
64
|
catch (error) {
|
|
@@ -83,7 +71,22 @@ async function getQuoteWithMaxAmountHandling(request, fullRequest) {
|
|
|
83
71
|
if (!isMaxAmount) {
|
|
84
72
|
return getQuoteWithPostQuoteGasHandling(request, fullRequest);
|
|
85
73
|
}
|
|
86
|
-
|
|
74
|
+
const [maxQuote] = await getMaxQuotes({
|
|
75
|
+
fullRequest,
|
|
76
|
+
getQuoteDetails: getRelayMaxQuoteDetails,
|
|
77
|
+
getQuotes: async (maxRequest, transaction) => [
|
|
78
|
+
await getSingleQuote(maxRequest, { ...fullRequest, transaction }),
|
|
79
|
+
],
|
|
80
|
+
request,
|
|
81
|
+
requote: (_quote, maxRequest, transaction) => getSingleQuote(maxRequest, { ...fullRequest, transaction }),
|
|
82
|
+
validateAtomicQuote: (quote) => validateRelayQuotes({
|
|
83
|
+
messenger: fullRequest.messenger,
|
|
84
|
+
quotes: [quote],
|
|
85
|
+
signal: fullRequest.signal,
|
|
86
|
+
transaction: fullRequest.transaction,
|
|
87
|
+
}),
|
|
88
|
+
});
|
|
89
|
+
return maxQuote;
|
|
87
90
|
}
|
|
88
91
|
/**
|
|
89
92
|
* For post-quote flows, fetch an initial quote to compute gas cost in source
|
|
@@ -250,8 +253,7 @@ async function processTransactions(transaction, request, requestBody, messenger)
|
|
|
250
253
|
// Eligible atomic max requests carry a destination amount, so the calls
|
|
251
254
|
// below use EXACT_OUTPUT rather than the usual max EXACT_INPUT quote.
|
|
252
255
|
if (isMaxAmount &&
|
|
253
|
-
(request
|
|
254
|
-
!isAtomicMaxEnabled(messenger, transaction))) {
|
|
256
|
+
!isAtomicMaxSupported({ messenger, request, transaction })) {
|
|
255
257
|
throw new Error('Max amount quotes do not support included transactions');
|
|
256
258
|
}
|
|
257
259
|
const delegation = await messenger.call('TransactionPayController:getDelegationTransaction', { transaction });
|
|
@@ -613,4 +615,20 @@ function getSubsidizedFeeAmountUsd(messenger, quote) {
|
|
|
613
615
|
function isStablecoin(messenger, chainId, tokenAddress) {
|
|
614
616
|
return Boolean(getStablecoins(messenger)[chainId]?.includes(tokenAddress.toLowerCase()));
|
|
615
617
|
}
|
|
618
|
+
function getRelayMaxQuoteDetails({ original, }) {
|
|
619
|
+
const firstTransactionStep = original.steps.find((step) => step.kind === 'transaction');
|
|
620
|
+
const firstStepData = firstTransactionStep?.items[0]?.data;
|
|
621
|
+
return {
|
|
622
|
+
gasLimits: original.metamask.gasLimits,
|
|
623
|
+
gasStationTransactions: firstStepData
|
|
624
|
+
? {
|
|
625
|
+
firstStepData,
|
|
626
|
+
totalItemCount: original.steps.reduce((count, step) => count + step.items.length, 0),
|
|
627
|
+
}
|
|
628
|
+
: undefined,
|
|
629
|
+
isGasless: original.metamask.isExecute === true,
|
|
630
|
+
isSubsidized: isSubsidizedRelayQuote(original),
|
|
631
|
+
targetAmountRaw: original.details.currencyOut.amount,
|
|
632
|
+
};
|
|
633
|
+
}
|
|
616
634
|
//# sourceMappingURL=relay-quotes.js.map
|