@metamask/transaction-pay-controller 24.0.3 → 25.0.0
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 +28 -1
- package/dist/constants.cjs +8 -2
- package/dist/constants.cjs.map +1 -1
- package/dist/constants.d.cts +7 -1
- package/dist/constants.d.cts.map +1 -1
- package/dist/constants.d.mts +7 -1
- package/dist/constants.d.mts.map +1 -1
- package/dist/constants.mjs +8 -2
- package/dist/constants.mjs.map +1 -1
- package/dist/helpers/QuoteRefresher.cjs +2 -1
- package/dist/helpers/QuoteRefresher.cjs.map +1 -1
- package/dist/helpers/QuoteRefresher.d.cts.map +1 -1
- package/dist/helpers/QuoteRefresher.d.mts.map +1 -1
- package/dist/helpers/QuoteRefresher.mjs +2 -1
- package/dist/helpers/QuoteRefresher.mjs.map +1 -1
- package/dist/helpers/TransactionPayPublishHook.cjs +5 -3
- package/dist/helpers/TransactionPayPublishHook.cjs.map +1 -1
- package/dist/helpers/TransactionPayPublishHook.d.cts.map +1 -1
- package/dist/helpers/TransactionPayPublishHook.d.mts.map +1 -1
- package/dist/helpers/TransactionPayPublishHook.mjs +5 -3
- package/dist/helpers/TransactionPayPublishHook.mjs.map +1 -1
- package/dist/strategy/relay/relay-quotes.cjs +6 -6
- package/dist/strategy/relay/relay-quotes.cjs.map +1 -1
- package/dist/strategy/relay/relay-quotes.d.cts.map +1 -1
- package/dist/strategy/relay/relay-quotes.d.mts.map +1 -1
- package/dist/strategy/relay/relay-quotes.mjs +8 -8
- package/dist/strategy/relay/relay-quotes.mjs.map +1 -1
- package/dist/strategy/server/perps.cjs +18 -1
- package/dist/strategy/server/perps.cjs.map +1 -1
- package/dist/strategy/server/perps.d.cts +5 -1
- package/dist/strategy/server/perps.d.cts.map +1 -1
- package/dist/strategy/server/perps.d.mts +5 -1
- package/dist/strategy/server/perps.d.mts.map +1 -1
- package/dist/strategy/server/perps.mjs +18 -1
- package/dist/strategy/server/perps.mjs.map +1 -1
- package/dist/strategy/server/server-quotes.cjs +68 -19
- package/dist/strategy/server/server-quotes.cjs.map +1 -1
- package/dist/strategy/server/server-quotes.d.cts.map +1 -1
- package/dist/strategy/server/server-quotes.d.mts.map +1 -1
- package/dist/strategy/server/server-quotes.mjs +69 -20
- package/dist/strategy/server/server-quotes.mjs.map +1 -1
- package/dist/strategy/server/server-submit.cjs +389 -61
- package/dist/strategy/server/server-submit.cjs.map +1 -1
- package/dist/strategy/server/server-submit.d.cts.map +1 -1
- package/dist/strategy/server/server-submit.d.mts.map +1 -1
- package/dist/strategy/server/server-submit.mjs +390 -62
- package/dist/strategy/server/server-submit.mjs.map +1 -1
- package/dist/strategy/server/types.cjs.map +1 -1
- package/dist/strategy/server/types.d.cts +20 -4
- package/dist/strategy/server/types.d.cts.map +1 -1
- package/dist/strategy/server/types.d.mts +20 -4
- package/dist/strategy/server/types.d.mts.map +1 -1
- package/dist/strategy/server/types.mjs.map +1 -1
- package/dist/utils/feature-flags.cjs +24 -1
- package/dist/utils/feature-flags.cjs.map +1 -1
- package/dist/utils/feature-flags.d.cts +9 -0
- package/dist/utils/feature-flags.d.cts.map +1 -1
- package/dist/utils/feature-flags.d.mts +9 -0
- package/dist/utils/feature-flags.d.mts.map +1 -1
- package/dist/utils/feature-flags.mjs +23 -1
- package/dist/utils/feature-flags.mjs.map +1 -1
- package/dist/utils/no-op-quote.cjs +55 -0
- package/dist/utils/no-op-quote.cjs.map +1 -0
- package/dist/utils/no-op-quote.d.cts +18 -0
- package/dist/utils/no-op-quote.d.cts.map +1 -0
- package/dist/utils/no-op-quote.d.mts +18 -0
- package/dist/utils/no-op-quote.d.mts.map +1 -0
- package/dist/utils/no-op-quote.mjs +51 -0
- package/dist/utils/no-op-quote.mjs.map +1 -0
- package/dist/utils/quotes.cjs +29 -6
- package/dist/utils/quotes.cjs.map +1 -1
- package/dist/utils/quotes.d.cts.map +1 -1
- package/dist/utils/quotes.d.mts.map +1 -1
- package/dist/utils/quotes.mjs +29 -6
- package/dist/utils/quotes.mjs.map +1 -1
- package/dist/utils/token.cjs +1 -1
- package/dist/utils/token.cjs.map +1 -1
- package/dist/utils/token.d.cts.map +1 -1
- package/dist/utils/token.d.mts.map +1 -1
- package/dist/utils/token.mjs +3 -3
- package/dist/utils/token.mjs.map +1 -1
- package/dist/utils/transaction.cjs +4 -1
- package/dist/utils/transaction.cjs.map +1 -1
- package/dist/utils/transaction.d.cts.map +1 -1
- package/dist/utils/transaction.d.mts.map +1 -1
- package/dist/utils/transaction.mjs +4 -1
- package/dist/utils/transaction.mjs.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,31 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [25.0.0]
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Store a no-op quote (`TransactionPayStrategy.None`) when a payment token is selected but the route needs no conversion, so clients can tell "no conversion needed" apart from "quote missing" ([#9484](https://github.com/MetaMask/core/pull/9484))
|
|
15
|
+
- Add `None` value to `TransactionPayStrategy` enum ([#9484](https://github.com/MetaMask/core/pull/9484))
|
|
16
|
+
|
|
17
|
+
### Changed
|
|
18
|
+
|
|
19
|
+
- **BREAKING:** Quotes stored in `transactionData` can now contain a single no-op quote with the `none` strategy; clients that read quotes for display, metrics, or publish validation must ignore or handle no-op quotes ([#9484](https://github.com/MetaMask/core/pull/9484))
|
|
20
|
+
|
|
21
|
+
## [24.1.0]
|
|
22
|
+
|
|
23
|
+
### Added
|
|
24
|
+
|
|
25
|
+
- Add `getStablecoins` feature flag reader that resolves the stablecoin list from the `stable-tokens` LaunchDarkly flag, falling back to the hardcoded constant when absent ([#9495](https://github.com/MetaMask/core/pull/9495))
|
|
26
|
+
- Add generic signature steps to the server pay strategy, supporting EIP-712 sign-then-POST flows ([#9051](https://github.com/MetaMask/core/pull/9051))
|
|
27
|
+
- Trigger quote refresh when `txParams.to` or `requiredAssets` changes on a transaction, in addition to the existing `txParams.data` trigger
|
|
28
|
+
|
|
29
|
+
### Changed
|
|
30
|
+
|
|
31
|
+
- Replace hardcoded `STABLECOINS` usage in `token.ts` and `relay-quotes.ts` with the remotely configurable `getStablecoins(messenger)` lookup ([#9495](https://github.com/MetaMask/core/pull/9495))
|
|
32
|
+
- Bump `@metamask/assets-controller` from `^10.2.1` to `^11.0.0` ([#9485](https://github.com/MetaMask/core/pull/9485))
|
|
33
|
+
- Bump `@metamask/ramps-controller` from `^16.0.0` to `^17.0.0` ([#9491](https://github.com/MetaMask/core/pull/9491))
|
|
34
|
+
|
|
10
35
|
## [24.0.3]
|
|
11
36
|
|
|
12
37
|
### Changed
|
|
@@ -1275,7 +1300,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
1275
1300
|
|
|
1276
1301
|
- Initial release ([#6820](https://github.com/MetaMask/core/pull/6820))
|
|
1277
1302
|
|
|
1278
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/transaction-pay-controller@
|
|
1303
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/transaction-pay-controller@25.0.0...HEAD
|
|
1304
|
+
[25.0.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-pay-controller@24.1.0...@metamask/transaction-pay-controller@25.0.0
|
|
1305
|
+
[24.1.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-pay-controller@24.0.3...@metamask/transaction-pay-controller@24.1.0
|
|
1279
1306
|
[24.0.3]: https://github.com/MetaMask/core/compare/@metamask/transaction-pay-controller@24.0.2...@metamask/transaction-pay-controller@24.0.3
|
|
1280
1307
|
[24.0.2]: https://github.com/MetaMask/core/compare/@metamask/transaction-pay-controller@24.0.1...@metamask/transaction-pay-controller@24.0.2
|
|
1281
1308
|
[24.0.1]: https://github.com/MetaMask/core/compare/@metamask/transaction-pay-controller@24.0.0...@metamask/transaction-pay-controller@24.0.1
|
package/dist/constants.cjs
CHANGED
|
@@ -57,12 +57,18 @@ var TransactionPayStrategy;
|
|
|
57
57
|
(function (TransactionPayStrategy) {
|
|
58
58
|
TransactionPayStrategy["Across"] = "across";
|
|
59
59
|
TransactionPayStrategy["Fiat"] = "fiat";
|
|
60
|
+
/**
|
|
61
|
+
* Internal marker for no-op quotes generated when the controller determines
|
|
62
|
+
* that no conversion is needed. Not a routable strategy.
|
|
63
|
+
*/
|
|
64
|
+
TransactionPayStrategy["None"] = "none";
|
|
60
65
|
TransactionPayStrategy["Relay"] = "relay";
|
|
61
66
|
TransactionPayStrategy["Server"] = "server";
|
|
62
67
|
})(TransactionPayStrategy || (exports.TransactionPayStrategy = TransactionPayStrategy = {}));
|
|
63
|
-
const VALID_STRATEGIES = new Set(Object.values(TransactionPayStrategy));
|
|
68
|
+
const VALID_STRATEGIES = new Set(Object.values(TransactionPayStrategy).filter((strategy) => strategy !== TransactionPayStrategy.None));
|
|
64
69
|
/**
|
|
65
|
-
* Checks if a value is a valid transaction pay strategy.
|
|
70
|
+
* Checks if a value is a valid, routable transaction pay strategy.
|
|
71
|
+
* The internal no-op marker is not routable.
|
|
66
72
|
*
|
|
67
73
|
* @param strategy - Candidate strategy value.
|
|
68
74
|
* @returns True if the value is a valid strategy.
|
package/dist/constants.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.cjs","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAA,6EAAmE;AAGtD,QAAA,eAAe,GAAG,0BAA0B,CAAC;AAE1D;;;GAGG;AACU,QAAA,mBAAmB,GAAsB;IACpD,wCAAe,CAAC,YAAY;IAC5B,wCAAe,CAAC,oBAAoB;CACrC,CAAC;AAEW,QAAA,iBAAiB,GAAG,QAAe,CAAC;AACpC,QAAA,gBAAgB,GAAG,KAAY,CAAC;AAChC,QAAA,gBAAgB,GAAG,MAAa,CAAC;AACjC,QAAA,kBAAkB,GAAG,OAAc,CA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AAO;CACxD,CAAC;AAEF,IAAY,eAIX;AAJD,WAAY,eAAe;IACzB,gDAA6B,CAAA;IAC7B,kCAAe,CAAA;IACf,sCAAmB,CAAA;AACrB,CAAC,EAJW,eAAe,+BAAf,eAAe,QAI1B;AAED,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,sCAAtB,sBAAsB,QAUjC;AAED,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAC9B,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,SAAgB,wBAAwB,CACtC,QAAiB;IAEjB,OAAO,gBAAgB,CAAC,GAAG,CAAC,QAAkC,CAAC,CAAC;AAClE,CAAC;AAJD,4DAIC","sourcesContent":["import { 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\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\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 = 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"]}
|
package/dist/constants.d.cts
CHANGED
|
@@ -29,11 +29,17 @@ export declare enum PaymentOverride {
|
|
|
29
29
|
export declare enum TransactionPayStrategy {
|
|
30
30
|
Across = "across",
|
|
31
31
|
Fiat = "fiat",
|
|
32
|
+
/**
|
|
33
|
+
* Internal marker for no-op quotes generated when the controller determines
|
|
34
|
+
* that no conversion is needed. Not a routable strategy.
|
|
35
|
+
*/
|
|
36
|
+
None = "none",
|
|
32
37
|
Relay = "relay",
|
|
33
38
|
Server = "server"
|
|
34
39
|
}
|
|
35
40
|
/**
|
|
36
|
-
* Checks if a value is a valid transaction pay strategy.
|
|
41
|
+
* Checks if a value is a valid, routable transaction pay strategy.
|
|
42
|
+
* The internal no-op marker is not routable.
|
|
37
43
|
*
|
|
38
44
|
* @param strategy - Candidate strategy value.
|
|
39
45
|
* @returns True if the value is a valid strategy.
|
package/dist/constants.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.cts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,yCAAyC;AACnE,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C,eAAO,MAAM,eAAe,6BAA6B,CAAC;AAE1D;;;GAGG;AACH,eAAO,MAAM,mBAAmB,EAAE,eAAe,EAGhD,CAAC;AAEF,eAAO,MAAM,iBAAiB,eAAkB,CAAC;AACjD,eAAO,MAAM,gBAAgB,eAAe,CAAC;AAC7C,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,eAAO,MAAM,oBAAoB,eACoB,CAAC;AAEtD,eAAO,MAAM,qBAAqB,eACmB,CAAC;AAEtD,eAAO,MAAM,qBAAqB,eACmB,CAAC;AAEtD,eAAO,MAAM,oBAAoB,eACoB,CAAC;AAEtD,eAAO,MAAM,kBAAkB,eACsB,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,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.d.mts
CHANGED
|
@@ -29,11 +29,17 @@ export declare enum PaymentOverride {
|
|
|
29
29
|
export declare enum TransactionPayStrategy {
|
|
30
30
|
Across = "across",
|
|
31
31
|
Fiat = "fiat",
|
|
32
|
+
/**
|
|
33
|
+
* Internal marker for no-op quotes generated when the controller determines
|
|
34
|
+
* that no conversion is needed. Not a routable strategy.
|
|
35
|
+
*/
|
|
36
|
+
None = "none",
|
|
32
37
|
Relay = "relay",
|
|
33
38
|
Server = "server"
|
|
34
39
|
}
|
|
35
40
|
/**
|
|
36
|
-
* Checks if a value is a valid transaction pay strategy.
|
|
41
|
+
* Checks if a value is a valid, routable transaction pay strategy.
|
|
42
|
+
* The internal no-op marker is not routable.
|
|
37
43
|
*
|
|
38
44
|
* @param strategy - Candidate strategy value.
|
|
39
45
|
* @returns True if the value is a valid strategy.
|
package/dist/constants.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.mts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,yCAAyC;AACnE,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C,eAAO,MAAM,eAAe,6BAA6B,CAAC;AAE1D;;;GAGG;AACH,eAAO,MAAM,mBAAmB,EAAE,eAAe,EAGhD,CAAC;AAEF,eAAO,MAAM,iBAAiB,eAAkB,CAAC;AACjD,eAAO,MAAM,gBAAgB,eAAe,CAAC;AAC7C,eAAO,MAAM,gBAAgB,eAAgB,CAAC;AAC9C,eAAO,MAAM,kBAAkB,eAAiB,CAAC;AACjD,eAAO,MAAM,cAAc,eAAgB,CAAC;AAE5C,eAAO,MAAM,oBAAoB,eACoB,CAAC;AAEtD,eAAO,MAAM,qBAAqB,eACmB,CAAC;AAEtD,eAAO,MAAM,qBAAqB,eACmB,CAAC;AAEtD,eAAO,MAAM,oBAAoB,eACoB,CAAC;AAEtD,eAAO,MAAM,kBAAkB,eACsB,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,oBAAY,sBAAsB;IAChC,MAAM,WAAW;IACjB,IAAI,SAAS;IACb,KAAK,UAAU;IACf,MAAM,WAAW;C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,sBAAsB,CAEpC"}
|
package/dist/constants.mjs
CHANGED
|
@@ -54,12 +54,18 @@ export var TransactionPayStrategy;
|
|
|
54
54
|
(function (TransactionPayStrategy) {
|
|
55
55
|
TransactionPayStrategy["Across"] = "across";
|
|
56
56
|
TransactionPayStrategy["Fiat"] = "fiat";
|
|
57
|
+
/**
|
|
58
|
+
* Internal marker for no-op quotes generated when the controller determines
|
|
59
|
+
* that no conversion is needed. Not a routable strategy.
|
|
60
|
+
*/
|
|
61
|
+
TransactionPayStrategy["None"] = "none";
|
|
57
62
|
TransactionPayStrategy["Relay"] = "relay";
|
|
58
63
|
TransactionPayStrategy["Server"] = "server";
|
|
59
64
|
})(TransactionPayStrategy || (TransactionPayStrategy = {}));
|
|
60
|
-
const VALID_STRATEGIES = new Set(Object.values(TransactionPayStrategy));
|
|
65
|
+
const VALID_STRATEGIES = new Set(Object.values(TransactionPayStrategy).filter((strategy) => strategy !== TransactionPayStrategy.None));
|
|
61
66
|
/**
|
|
62
|
-
* Checks if a value is a valid transaction pay strategy.
|
|
67
|
+
* Checks if a value is a valid, routable transaction pay strategy.
|
|
68
|
+
* The internal no-op marker is not routable.
|
|
63
69
|
*
|
|
64
70
|
* @param strategy - Candidate strategy value.
|
|
65
71
|
* @returns True if the value is a valid strategy.
|
package/dist/constants.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.mjs","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,yCAAyC;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,MAAM,CAAC,MAAM,iBAAiB,GAAG,QAAe,CAAC;AACjD,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAY,CAAC;AAC7C,M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W,GAAuB;IAC7C,UAAU;IACV,KAAK,EAAE;QACL,4CAA4C,EAAE,OAAO;QACrD,4CAA4C,EAAE,OAAO;QACrD,4CAA4C,EAAE,OAAO;KACtD;IACD,CAAC,iBAAiB,CAAC,EAAE,CAAC,qBAAqB,CAAC,WAAW,EAAS,CAAC;IACjE,QAAQ;IACR,QAAQ,EAAE;QACR,4CAA4C,EAAE,OAAO;QACrD,4CAA4C,EAAE,OAAO;QACrD,4CAA4C,EAAE,OAAO;KACtD;IACD,CAAC,gBAAgB,CAAC,EAAE;QAClB,qBAAqB,CAAC,WAAW,EAAS;QAC1C,oBAAoB,CAAC,WAAW,EAAS;KAC1C;IACD,CAAC,kBAAkB,CAAC,EAAE,CAAC,sBAAsB,CAAC,EAAE,OAAO;CACxD,CAAC;AAEF,MAAM,CAAN,IAAY,eAIX;AAJD,WAAY,eAAe;IACzB,gDAA6B,CAAA;IAC7B,kCAAe,CAAA;IACf,sCAAmB,CAAA;AACrB,CAAC,EAJW,eAAe,KAAf,eAAe,QAI1B;AAED,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,GAAG,IAAI,GAAG,CAC9B,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 { 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\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\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 = 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"]}
|
|
@@ -74,7 +74,8 @@ _QuoteRefresher_isRunning = new WeakMap(), _QuoteRefresher_isUpdating = new Weak
|
|
|
74
74
|
__classPrivateFieldGet(this, _QuoteRefresher_instances, "m", _QuoteRefresher_onInterval).call(this).catch(lodash_1.noop);
|
|
75
75
|
}, CHECK_INTERVAL), "f");
|
|
76
76
|
}, _QuoteRefresher_onStateChange = function _QuoteRefresher_onStateChange(state) {
|
|
77
|
-
|
|
77
|
+
// No-op quotes never refresh, so they don't need the refresh loop.
|
|
78
|
+
const hasQuotes = Object.values(state.transactionData).some((transaction) => transaction.quotes?.some((quote) => quote.strategy !== constants_1.TransactionPayStrategy.None));
|
|
78
79
|
if (hasQuotes && !__classPrivateFieldGet(this, _QuoteRefresher_isRunning, "f")) {
|
|
79
80
|
__classPrivateFieldGet(this, _QuoteRefresher_instances, "m", _QuoteRefresher_start).call(this);
|
|
80
81
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QuoteRefresher.cjs","sourceRoot":"","sources":["../../src/helpers/QuoteRefresher.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,2CAAqD;AACrD,mCAA8B;AAM9B,gDAAsD;AACtD,0CAA0C;AAE1C,gDAAgD;AAEhD,MAAM,cAAc,GAAG,IAAI,CAAC,CAAC,WAAW;AAExC,MAAM,GAAG,GAAG,IAAA,0BAAkB,EAAC,sBAAa,EAAE,eAAe,CAAC,CAAC;AAE/D,MAAa,cAAc;IAezB,YAAY,EACV,aAAa,EACb,SAAS,EACT,qBAAqB,GAKtB;;QAtBD,4CAAoB;QAEpB,6CAAqB;QAEZ,4CAA8C;QAEvD,4CAAuC;QAE9B,gDAEqB;QAErB,wDAAsD;QAW7D,uBAAA,IAAI,iCAAkB,aAAa,MAAA,CAAC;QACpC,uBAAA,IAAI,6BAAc,SAAS,MAAA,CAAC;QAC5B,uBAAA,IAAI,6BAAc,KAAK,MAAA,CAAC;QACxB,uBAAA,IAAI,8BAAe,KAAK,MAAA,CAAC;QACzB,uBAAA,IAAI,yCAA0B,qBAAqB,MAAA,CAAC;QAEpD,SAAS,CAAC,SAAS,CACjB,sCAAsC,EACtC,uBAAA,IAAI,gEAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAC/B,CAAC;IACJ,CAAC;
|
|
1
|
+
{"version":3,"file":"QuoteRefresher.cjs","sourceRoot":"","sources":["../../src/helpers/QuoteRefresher.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,2CAAqD;AACrD,mCAA8B;AAM9B,gDAAsD;AACtD,0CAA0C;AAE1C,gDAAgD;AAEhD,MAAM,cAAc,GAAG,IAAI,CAAC,CAAC,WAAW;AAExC,MAAM,GAAG,GAAG,IAAA,0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C;QACf,GAAG,CAAC,yBAAyB,EAAE,KAAK,CAAC,CAAC;IACxC,CAAC;YAAS,CAAC;QACT,uBAAA,IAAI,8BAAe,KAAK,MAAA,CAAC;QAEzB,uBAAA,IAAI,oEAAmB,MAAvB,IAAI,CAAqB,CAAC;IAC5B,CAAC;AACH,CAAC;IAGC,IAAI,CAAC,uBAAA,IAAI,iCAAW,EAAE,CAAC;QACrB,OAAO;IACT,CAAC;IAED,IAAI,uBAAA,IAAI,iCAAW,EAAE,CAAC;QACpB,YAAY,CAAC,uBAAA,IAAI,iCAAW,CAAC,CAAC;IAChC,CAAC;IAED,uBAAA,IAAI,6BAAc,UAAU,CAAC,GAAG,EAAE;QAChC,uBAAA,IAAI,6DAAY,MAAhB,IAAI,CAAc,CAAC,KAAK,CAAC,aAAI,CAAC,CAAC;IACjC,CAAC,EAAE,cAAc,CAAC,MAAA,CAAC;AACrB,CAAC,yEAEc,KAAoC;IACjD,mEAAmE;IACnE,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,EAAE,CAC1E,WAAW,CAAC,MAAM,EAAE,IAAI,CACtB,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,KAAK,kCAAsB,CAAC,IAAI,CAC1D,CACF,CAAC;IAEF,IAAI,SAAS,IAAI,CAAC,uBAAA,IAAI,iCAAW,EAAE,CAAC;QAClC,uBAAA,IAAI,wDAAO,MAAX,IAAI,CAAS,CAAC;IAChB,CAAC;SAAM,IAAI,CAAC,SAAS,IAAI,uBAAA,IAAI,iCAAW,EAAE,CAAC;QACzC,uBAAA,IAAI,uDAAM,MAAV,IAAI,CAAQ,CAAC;IACf,CAAC;AACH,CAAC","sourcesContent":["import type { TransactionMeta } from '@metamask/transaction-controller';\nimport { createModuleLogger } from '@metamask/utils';\nimport { noop } from 'lodash';\n\nimport type {\n TransactionPayControllerMessenger,\n TransactionPayControllerState,\n} from '..';\nimport { TransactionPayStrategy } from '../constants';\nimport { projectLogger } from '../logger';\nimport type { UpdateTransactionDataCallback } from '../types';\nimport { refreshQuotes } from '../utils/quotes';\n\nconst CHECK_INTERVAL = 1000; // 1 Second\n\nconst log = createModuleLogger(projectLogger, 'quote-refresh');\n\nexport class QuoteRefresher {\n #isRunning: boolean;\n\n #isUpdating: boolean;\n\n readonly #messenger: TransactionPayControllerMessenger;\n\n #timeoutId: NodeJS.Timeout | undefined;\n\n readonly #getStrategies: (\n transaction: TransactionMeta,\n ) => TransactionPayStrategy[];\n\n readonly #updateTransactionData: UpdateTransactionDataCallback;\n\n constructor({\n getStrategies,\n messenger,\n updateTransactionData,\n }: {\n getStrategies: (transaction: TransactionMeta) => TransactionPayStrategy[];\n messenger: TransactionPayControllerMessenger;\n updateTransactionData: UpdateTransactionDataCallback;\n }) {\n this.#getStrategies = getStrategies;\n this.#messenger = messenger;\n this.#isRunning = false;\n this.#isUpdating = false;\n this.#updateTransactionData = updateTransactionData;\n\n messenger.subscribe(\n 'TransactionPayController:stateChange',\n this.#onStateChange.bind(this),\n );\n }\n\n #start(): void {\n this.#isRunning = true;\n\n log('Started');\n\n if (this.#isUpdating) {\n return;\n }\n\n this.#queueNextInterval();\n }\n\n #stop(): void {\n if (this.#timeoutId) {\n clearTimeout(this.#timeoutId);\n }\n\n this.#isRunning = false;\n\n log('Stopped');\n }\n\n async #onInterval(): Promise<void> {\n this.#isUpdating = true;\n\n try {\n await refreshQuotes(\n this.#messenger,\n this.#updateTransactionData,\n this.#getStrategies,\n );\n } catch (error) {\n log('Error refreshing quotes', error);\n } finally {\n this.#isUpdating = false;\n\n this.#queueNextInterval();\n }\n }\n\n #queueNextInterval(): void {\n if (!this.#isRunning) {\n return;\n }\n\n if (this.#timeoutId) {\n clearTimeout(this.#timeoutId);\n }\n\n this.#timeoutId = setTimeout(() => {\n this.#onInterval().catch(noop);\n }, CHECK_INTERVAL);\n }\n\n #onStateChange(state: TransactionPayControllerState): void {\n // No-op quotes never refresh, so they don't need the refresh loop.\n const hasQuotes = Object.values(state.transactionData).some((transaction) =>\n transaction.quotes?.some(\n (quote) => quote.strategy !== TransactionPayStrategy.None,\n ),\n );\n\n if (hasQuotes && !this.#isRunning) {\n this.#start();\n } else if (!hasQuotes && this.#isRunning) {\n this.#stop();\n }\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QuoteRefresher.d.cts","sourceRoot":"","sources":["../../src/helpers/QuoteRefresher.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,yCAAyC;AAIxE,OAAO,KAAK,EACV,iCAAiC,EAElC,qBAAW;AACZ,OAAO,EAAE,sBAAsB,EAAE,yBAAqB;AAEtD,OAAO,KAAK,EAAE,6BAA6B,EAAE,qBAAiB;AAO9D,qBAAa,cAAc;;gBAeb,EACV,aAAa,EACb,SAAS,EACT,qBAAqB,GACtB,EAAE;QACD,aAAa,EAAE,CAAC,WAAW,EAAE,eAAe,KAAK,sBAAsB,EAAE,CAAC;QAC1E,SAAS,EAAE,iCAAiC,CAAC;QAC7C,qBAAqB,EAAE,6BAA6B,CAAC;KACtD;
|
|
1
|
+
{"version":3,"file":"QuoteRefresher.d.cts","sourceRoot":"","sources":["../../src/helpers/QuoteRefresher.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,yCAAyC;AAIxE,OAAO,KAAK,EACV,iCAAiC,EAElC,qBAAW;AACZ,OAAO,EAAE,sBAAsB,EAAE,yBAAqB;AAEtD,OAAO,KAAK,EAAE,6BAA6B,EAAE,qBAAiB;AAO9D,qBAAa,cAAc;;gBAeb,EACV,aAAa,EACb,SAAS,EACT,qBAAqB,GACtB,EAAE;QACD,aAAa,EAAE,CAAC,WAAW,EAAE,eAAe,KAAK,sBAAsB,EAAE,CAAC;QAC1E,SAAS,EAAE,iCAAiC,CAAC;QAC7C,qBAAqB,EAAE,6BAA6B,CAAC;KACtD;CAiFF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QuoteRefresher.d.mts","sourceRoot":"","sources":["../../src/helpers/QuoteRefresher.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,yCAAyC;AAIxE,OAAO,KAAK,EACV,iCAAiC,EAElC,qBAAW;AACZ,OAAO,EAAE,sBAAsB,EAAE,yBAAqB;AAEtD,OAAO,KAAK,EAAE,6BAA6B,EAAE,qBAAiB;AAO9D,qBAAa,cAAc;;gBAeb,EACV,aAAa,EACb,SAAS,EACT,qBAAqB,GACtB,EAAE;QACD,aAAa,EAAE,CAAC,WAAW,EAAE,eAAe,KAAK,sBAAsB,EAAE,CAAC;QAC1E,SAAS,EAAE,iCAAiC,CAAC;QAC7C,qBAAqB,EAAE,6BAA6B,CAAC;KACtD;
|
|
1
|
+
{"version":3,"file":"QuoteRefresher.d.mts","sourceRoot":"","sources":["../../src/helpers/QuoteRefresher.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,yCAAyC;AAIxE,OAAO,KAAK,EACV,iCAAiC,EAElC,qBAAW;AACZ,OAAO,EAAE,sBAAsB,EAAE,yBAAqB;AAEtD,OAAO,KAAK,EAAE,6BAA6B,EAAE,qBAAiB;AAO9D,qBAAa,cAAc;;gBAeb,EACV,aAAa,EACb,SAAS,EACT,qBAAqB,GACtB,EAAE;QACD,aAAa,EAAE,CAAC,WAAW,EAAE,eAAe,KAAK,sBAAsB,EAAE,CAAC;QAC1E,SAAS,EAAE,iCAAiC,CAAC;QAC7C,qBAAqB,EAAE,6BAA6B,CAAC;KACtD;CAiFF"}
|
|
@@ -71,7 +71,8 @@ _QuoteRefresher_isRunning = new WeakMap(), _QuoteRefresher_isUpdating = new Weak
|
|
|
71
71
|
__classPrivateFieldGet(this, _QuoteRefresher_instances, "m", _QuoteRefresher_onInterval).call(this).catch(noop);
|
|
72
72
|
}, CHECK_INTERVAL), "f");
|
|
73
73
|
}, _QuoteRefresher_onStateChange = function _QuoteRefresher_onStateChange(state) {
|
|
74
|
-
|
|
74
|
+
// No-op quotes never refresh, so they don't need the refresh loop.
|
|
75
|
+
const hasQuotes = Object.values(state.transactionData).some((transaction) => transaction.quotes?.some((quote) => quote.strategy !== TransactionPayStrategy.None));
|
|
75
76
|
if (hasQuotes && !__classPrivateFieldGet(this, _QuoteRefresher_isRunning, "f")) {
|
|
76
77
|
__classPrivateFieldGet(this, _QuoteRefresher_instances, "m", _QuoteRefresher_start).call(this);
|
|
77
78
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QuoteRefresher.mjs","sourceRoot":"","sources":["../../src/helpers/QuoteRefresher.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,OAAO,EAAE,kBAAkB,EAAE,wBAAwB;;;AAOrD,OAAO,EAAE,sBAAsB,EAAE,yBAAqB;AACtD,OAAO,EAAE,aAAa,EAAE,sBAAkB;AAE1C,OAAO,EAAE,aAAa,EAAE,4BAAwB;AAEhD,MAAM,cAAc,GAAG,IAAI,CAAC,CAAC,WAAW;AAExC,MAAM,GAAG,GAAG,kBAAkB,CAAC,aAAa,EAAE,eAAe,CAAC,CAAC;AAE/D,MAAM,OAAO,cAAc;IAezB,YAAY,EACV,aAAa,EACb,SAAS,EACT,qBAAqB,GAKtB;;QAtBD,4CAAoB;QAEpB,6CAAqB;QAEZ,4CAA8C;QAEvD,4CAAuC;QAE9B,gDAEqB;QAErB,wDAAsD;QAW7D,uBAAA,IAAI,iCAAkB,aAAa,MAAA,CAAC;QACpC,uBAAA,IAAI,6BAAc,SAAS,MAAA,CAAC;QAC5B,uBAAA,IAAI,6BAAc,KAAK,MAAA,CAAC;QACxB,uBAAA,IAAI,8BAAe,KAAK,MAAA,CAAC;QACzB,uBAAA,IAAI,yCAA0B,qBAAqB,MAAA,CAAC;QAEpD,SAAS,CAAC,SAAS,CACjB,sCAAsC,EACtC,uBAAA,IAAI,gEAAe,CAAC,IAAI,CAA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I,CAAC,uBAAA,IAAI,iCAAW,EAAE,CAAC;QAClC,uBAAA,IAAI,wDAAO,MAAX,IAAI,CAAS,CAAC;IAChB,CAAC;SAAM,IAAI,CAAC,SAAS,IAAI,uBAAA,IAAI,iCAAW,EAAE,CAAC;QACzC,uBAAA,IAAI,uDAAM,MAAV,IAAI,CAAQ,CAAC;IACf,CAAC;AACH,CAAC","sourcesContent":["import type { TransactionMeta } from '@metamask/transaction-controller';\nimport { createModuleLogger } from '@metamask/utils';\nimport { noop } from 'lodash';\n\nimport type {\n TransactionPayControllerMessenger,\n TransactionPayControllerState,\n} from '..';\nimport { TransactionPayStrategy } from '../constants';\nimport { projectLogger } from '../logger';\nimport type { UpdateTransactionDataCallback } from '../types';\nimport { refreshQuotes } from '../utils/quotes';\n\nconst CHECK_INTERVAL = 1000; // 1 Second\n\nconst log = createModuleLogger(projectLogger, 'quote-refresh');\n\nexport class QuoteRefresher {\n #isRunning: boolean;\n\n #isUpdating: boolean;\n\n readonly #messenger: TransactionPayControllerMessenger;\n\n #timeoutId: NodeJS.Timeout | undefined;\n\n readonly #getStrategies: (\n transaction: TransactionMeta,\n ) => TransactionPayStrategy[];\n\n readonly #updateTransactionData: UpdateTransactionDataCallback;\n\n constructor({\n getStrategies,\n messenger,\n updateTransactionData,\n }: {\n getStrategies: (transaction: TransactionMeta) => TransactionPayStrategy[];\n messenger: TransactionPayControllerMessenger;\n updateTransactionData: UpdateTransactionDataCallback;\n }) {\n this.#getStrategies = getStrategies;\n this.#messenger = messenger;\n this.#isRunning = false;\n this.#isUpdating = false;\n this.#updateTransactionData = updateTransactionData;\n\n messenger.subscribe(\n 'TransactionPayController:stateChange',\n this.#onStateChange.bind(this),\n );\n }\n\n #start(): void {\n this.#isRunning = true;\n\n log('Started');\n\n if (this.#isUpdating) {\n return;\n }\n\n this.#queueNextInterval();\n }\n\n #stop(): void {\n if (this.#timeoutId) {\n clearTimeout(this.#timeoutId);\n }\n\n this.#isRunning = false;\n\n log('Stopped');\n }\n\n async #onInterval(): Promise<void> {\n this.#isUpdating = true;\n\n try {\n await refreshQuotes(\n this.#messenger,\n this.#updateTransactionData,\n this.#getStrategies,\n );\n } catch (error) {\n log('Error refreshing quotes', error);\n } finally {\n this.#isUpdating = false;\n\n this.#queueNextInterval();\n }\n }\n\n #queueNextInterval(): void {\n if (!this.#isRunning) {\n return;\n }\n\n if (this.#timeoutId) {\n clearTimeout(this.#timeoutId);\n }\n\n this.#timeoutId = setTimeout(() => {\n this.#onInterval().catch(noop);\n }, CHECK_INTERVAL);\n }\n\n #onStateChange(state: TransactionPayControllerState): void {\n // No-op quotes never refresh, so they don't need the refresh loop.\n const hasQuotes = Object.values(state.transactionData).some((transaction) =>\n transaction.quotes?.some(\n (quote) => quote.strategy !== TransactionPayStrategy.None,\n ),\n );\n\n if (hasQuotes && !this.#isRunning) {\n this.#start();\n } else if (!hasQuotes && this.#isRunning) {\n this.#stop();\n }\n }\n}\n"]}
|
|
@@ -14,6 +14,7 @@ var _TransactionPayPublishHook_instances, _TransactionPayPublishHook_isSmartTran
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.TransactionPayPublishHook = void 0;
|
|
16
16
|
const utils_1 = require("@metamask/utils");
|
|
17
|
+
const constants_1 = require("../constants.cjs");
|
|
17
18
|
const logger_1 = require("../logger.cjs");
|
|
18
19
|
const _7702_1 = require("../utils/7702.cjs");
|
|
19
20
|
const error_prefix_1 = require("../utils/error-prefix.cjs");
|
|
@@ -49,13 +50,14 @@ _TransactionPayPublishHook_isSmartTransaction = new WeakMap(), _TransactionPayPu
|
|
|
49
50
|
const { id: transactionId } = transactionMeta;
|
|
50
51
|
const controllerState = __classPrivateFieldGet(this, _TransactionPayPublishHook_messenger, "f").call('TransactionPayController:getState');
|
|
51
52
|
const transactionData = controllerState.transactionData?.[transactionId];
|
|
52
|
-
|
|
53
|
+
// No-op quotes mark direct routes and cannot be executed by any strategy.
|
|
54
|
+
const quotes = (transactionData?.quotes ?? []).filter((quote) => quote.strategy !== constants_1.TransactionPayStrategy.None);
|
|
53
55
|
const isFiatSelected = Boolean(transactionData?.fiatPayment?.selectedPaymentMethodId);
|
|
54
|
-
if (!quotes
|
|
56
|
+
if (!quotes.length) {
|
|
55
57
|
if (isFiatSelected) {
|
|
56
58
|
throw new Error('Fiat: Missing quote');
|
|
57
59
|
}
|
|
58
|
-
log('Skipping as no quotes found');
|
|
60
|
+
log('Skipping as no executable quotes found', { transactionId });
|
|
59
61
|
return EMPTY_RESULT;
|
|
60
62
|
}
|
|
61
63
|
(0, transaction_1.updateTransaction)({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TransactionPayPublishHook.cjs","sourceRoot":"","sources":["../../src/helpers/TransactionPayPublishHook.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAIA,2CAAqD;AAErD,0CAA0C;AAK1C,6CAAoD;AACpD,4DAAoD;AACpD,oDAAsD;AACtD,0DAAyD;AAEzD,MAAM,GAAG,GAAG,IAAA,0BAAkB,EAAC,sBAAa,EAAE,kBAAkB,CAAC,CAAC;AAClE,MAAM,YAAY,GAAG,gBAAgB,CAAC;AAEtC,MAAM,YAAY,GAAG;IACnB,eAAe,EAAE,SAAS;CAC3B,CAAC;AAEF,MAAa,yBAAyB;IAKpC,YAAY,EACV,kBAAkB,EAClB,SAAS,GAIV;;QAVQ,gEAA+C;QAE/C,uDAA8C;QASrD,uBAAA,IAAI,iDAAuB,kBAAkB,MAAA,CAAC;QAC9C,uBAAA,IAAI,wCAAc,SAAS,MAAA,CAAC;IAC9B,CAAC;IAED,OAAO;QACL,OAAO,uBAAA,IAAI,oFAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACtC,CAAC;
|
|
1
|
+
{"version":3,"file":"TransactionPayPublishHook.cjs","sourceRoot":"","sources":["../../src/helpers/TransactionPayPublishHook.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAIA,2CAAqD;AAErD,gDAAsD;AACtD,0CA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AM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,KAAK,kCAAsB,CAAC,IAAI,CAAC,CAAC;IAEpE,MAAM,cAAc,GAAG,OAAO,CAC5B,eAAe,EAAE,WAAW,EAAE,uBAAuB,CACtD,CAAC;IAEF,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;QACnB,IAAI,cAAc,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;QACzC,CAAC;QAED,GAAG,CAAC,wCAAwC,EAAE,EAAE,aAAa,EAAE,CAAC,CAAC;QAEjE,OAAO,YAAY,CAAC;IACtB,CAAC;IAED,IAAA,+BAAiB,EACf;QACE,aAAa;QACb,SAAS,EAAE,uBAAA,IAAI,4CAAW;QAC1B,IAAI,EAAE,6CAA6C;KACpD,EACD,CAAC,EAAE,EAAE,EAAE;QACL,EAAE,CAAC,aAAa,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAC;IAC1C,CAAC,CACF,CAAC;IAEF,MAAM,QAAQ,GAAG,IAAA,4BAAiB,EAAC,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;IACvD,MAAM,IAAI,GAAG,eAAe,CAAC,QAAQ,CAAC,IAAW,CAAC;IAElD,OAAO,MAAM,QAAQ,CAAC,OAAO,CAAC;QAC5B,mBAAmB,EAAE,IAAA,2BAAmB,EAAC,uBAAA,IAAI,4CAAW,EAAE,IAAI,CAAC;QAC/D,kBAAkB,EAAE,uBAAA,IAAI,qDAAoB;QAC5C,MAAM;QACN,SAAS,EAAE,uBAAA,IAAI,4CAAW;QAC1B,WAAW,EAAE,eAAe;KAC7B,CAAC,CAAC;AACL,CAAC","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';\nimport { projectLogger } from '../logger';\nimport type {\n TransactionPayControllerMessenger,\n TransactionPayQuote,\n} from '../types';\nimport { accountSupports7702 } from '../utils/7702';\nimport { prefixError } from '../utils/error-prefix';\nimport { getStrategyByName } from '../utils/strategy';\nimport { updateTransaction } from '../utils/transaction';\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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TransactionPayPublishHook.d.cts","sourceRoot":"","sources":["../../src/helpers/TransactionPayPublishHook.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,yCAAyC;AAGpE,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;
|
|
1
|
+
{"version":3,"file":"TransactionPayPublishHook.d.cts","sourceRoot":"","sources":["../../src/helpers/TransactionPayPublishHook.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,yCAAyC;AAGpE,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAK3C,OAAO,KAAK,EACV,iCAAiC,EAElC,qBAAiB;AAalB,qBAAa,yBAAyB;;gBAKxB,EACV,kBAAkB,EAClB,SAAS,GACV,EAAE;QACD,kBAAkB,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,OAAO,CAAC;QAC9C,SAAS,EAAE,iCAAiC,CAAC;KAC9C;IAKD,OAAO,IAAI,WAAW;CAqEvB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TransactionPayPublishHook.d.mts","sourceRoot":"","sources":["../../src/helpers/TransactionPayPublishHook.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,yCAAyC;AAGpE,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;
|
|
1
|
+
{"version":3,"file":"TransactionPayPublishHook.d.mts","sourceRoot":"","sources":["../../src/helpers/TransactionPayPublishHook.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,yCAAyC;AAGpE,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAK3C,OAAO,KAAK,EACV,iCAAiC,EAElC,qBAAiB;AAalB,qBAAa,yBAAyB;;gBAKxB,EACV,kBAAkB,EAClB,SAAS,GACV,EAAE;QACD,kBAAkB,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,OAAO,CAAC;QAC9C,SAAS,EAAE,iCAAiC,CAAC;KAC9C;IAKD,OAAO,IAAI,WAAW;CAqEvB"}
|
|
@@ -11,6 +11,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
11
11
|
};
|
|
12
12
|
var _TransactionPayPublishHook_instances, _TransactionPayPublishHook_isSmartTransaction, _TransactionPayPublishHook_messenger, _TransactionPayPublishHook_hookWrapper, _TransactionPayPublishHook_publishHook;
|
|
13
13
|
import { createModuleLogger } from "@metamask/utils";
|
|
14
|
+
import { TransactionPayStrategy } from "../constants.mjs";
|
|
14
15
|
import { projectLogger } from "../logger.mjs";
|
|
15
16
|
import { accountSupports7702 } from "../utils/7702.mjs";
|
|
16
17
|
import { prefixError } from "../utils/error-prefix.mjs";
|
|
@@ -45,13 +46,14 @@ _TransactionPayPublishHook_isSmartTransaction = new WeakMap(), _TransactionPayPu
|
|
|
45
46
|
const { id: transactionId } = transactionMeta;
|
|
46
47
|
const controllerState = __classPrivateFieldGet(this, _TransactionPayPublishHook_messenger, "f").call('TransactionPayController:getState');
|
|
47
48
|
const transactionData = controllerState.transactionData?.[transactionId];
|
|
48
|
-
|
|
49
|
+
// No-op quotes mark direct routes and cannot be executed by any strategy.
|
|
50
|
+
const quotes = (transactionData?.quotes ?? []).filter((quote) => quote.strategy !== TransactionPayStrategy.None);
|
|
49
51
|
const isFiatSelected = Boolean(transactionData?.fiatPayment?.selectedPaymentMethodId);
|
|
50
|
-
if (!quotes
|
|
52
|
+
if (!quotes.length) {
|
|
51
53
|
if (isFiatSelected) {
|
|
52
54
|
throw new Error('Fiat: Missing quote');
|
|
53
55
|
}
|
|
54
|
-
log('Skipping as no quotes found');
|
|
56
|
+
log('Skipping as no executable quotes found', { transactionId });
|
|
55
57
|
return EMPTY_RESULT;
|
|
56
58
|
}
|
|
57
59
|
updateTransaction({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TransactionPayPublishHook.mjs","sourceRoot":"","sources":["../../src/helpers/TransactionPayPublishHook.ts"],"names":[],"mappings":";;;;;;;;;;;;AAIA,OAAO,EAAE,kBAAkB,EAAE,wBAAwB;AAErD,OAAO,EAAE,aAAa,EAAE,sBAAkB;AAK1C,OAAO,EAAE,mBAAmB,EAAE,0BAAsB;AACpD,OAAO,EAAE,WAAW,EAAE,kCAA8B;AACpD,OAAO,EAAE,iBAAiB,EAAE,8BAA0B;AACtD,OAAO,EAAE,iBAAiB,EAAE,iCAA6B;AAEzD,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,MAAM,OAAO,yBAAyB;IAKpC,YAAY,EACV,kBAAkB,EAClB,SAAS,GAIV;;QAVQ,gEAA+C;QAE/C,uDAA8C;QASrD,uBAAA,IAAI,iDAAuB,kBAAkB,MAAA,CAAC;QAC9C,uBAAA,IAAI,wCAAc,SAAS,MAAA,CAAC;IAC9B,CAAC;IAED,OAAO;QACL,OAAO,uBAAA,IAAI,oFAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACtC,CAAC;
|
|
1
|
+
{"version":3,"file":"TransactionPayPublishHook.mjs","sourceRoot":"","sources":["../../src/helpers/TransactionPayPublishHook.ts"],"names":[],"mappings":";;;;;;;;;;;;AAIA,OAAO,EAAE,kBAAkB,EAAE,wBAAwB;AAErD,O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@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';\nimport { projectLogger } from '../logger';\nimport type {\n TransactionPayControllerMessenger,\n TransactionPayQuote,\n} from '../types';\nimport { accountSupports7702 } from '../utils/7702';\nimport { prefixError } from '../utils/error-prefix';\nimport { getStrategyByName } from '../utils/strategy';\nimport { updateTransaction } from '../utils/transaction';\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"]}
|
|
@@ -359,7 +359,7 @@ async function normalizeQuote(quote, request, fullRequest) {
|
|
|
359
359
|
const { currencyIn, currencyOut } = details;
|
|
360
360
|
const { usdToFiatRate } = getFiatRates(messenger, request);
|
|
361
361
|
const dust = (0, amounts_1.getFiatValueFromUsd)(calculateDustUsd(quote, request), usdToFiatRate);
|
|
362
|
-
const subsidizedFeeUsd = getSubsidizedFeeAmountUsd(quote);
|
|
362
|
+
const subsidizedFeeUsd = getSubsidizedFeeAmountUsd(messenger, quote);
|
|
363
363
|
const appFeeUsd = new bignumber_js_1.BigNumber(quote.fees?.app?.amountUsd ?? '0');
|
|
364
364
|
const metaMaskFee = (0, amounts_1.getFiatValueFromUsd)(appFeeUsd, usdToFiatRate);
|
|
365
365
|
// Subtract app fee from provider fee since totalImpact.usd already includes
|
|
@@ -381,7 +381,7 @@ async function normalizeQuote(quote, request, fullRequest) {
|
|
|
381
381
|
raw: currencyIn.amount,
|
|
382
382
|
...(0, amounts_1.getFiatValueFromUsd)(new bignumber_js_1.BigNumber(currencyIn.amountUsd), usdToFiatRate),
|
|
383
383
|
};
|
|
384
|
-
const isTargetStablecoin = isStablecoin(request.targetChainId, request.targetTokenAddress);
|
|
384
|
+
const isTargetStablecoin = isStablecoin(messenger, request.targetChainId, request.targetTokenAddress);
|
|
385
385
|
const targetAmountUsd = isTargetStablecoin
|
|
386
386
|
? new bignumber_js_1.BigNumber(currencyOut.amountFormatted)
|
|
387
387
|
: new bignumber_js_1.BigNumber(currencyOut.amountUsd);
|
|
@@ -812,17 +812,17 @@ function getTransferRecipient(data) {
|
|
|
812
812
|
.decodeFunctionData('transfer', data)
|
|
813
813
|
.to.toLowerCase();
|
|
814
814
|
}
|
|
815
|
-
function getSubsidizedFeeAmountUsd(quote) {
|
|
815
|
+
function getSubsidizedFeeAmountUsd(messenger, quote) {
|
|
816
816
|
const subsidizedFee = quote.fees?.subsidized;
|
|
817
817
|
const amountUsd = new bignumber_js_1.BigNumber(subsidizedFee?.amountUsd ?? '0');
|
|
818
818
|
const amountFormatted = new bignumber_js_1.BigNumber(subsidizedFee?.amountFormatted ?? '0');
|
|
819
819
|
if (!subsidizedFee || amountUsd.isZero()) {
|
|
820
820
|
return new bignumber_js_1.BigNumber(0);
|
|
821
821
|
}
|
|
822
|
-
const isSubsidizedStablecoin = isStablecoin((0, controller_utils_1.toHex)(subsidizedFee.currency.chainId), subsidizedFee.currency.address);
|
|
822
|
+
const isSubsidizedStablecoin = isStablecoin(messenger, (0, controller_utils_1.toHex)(subsidizedFee.currency.chainId), subsidizedFee.currency.address);
|
|
823
823
|
return isSubsidizedStablecoin ? amountFormatted : amountUsd;
|
|
824
824
|
}
|
|
825
|
-
function isStablecoin(chainId, tokenAddress) {
|
|
826
|
-
return Boolean(
|
|
825
|
+
function isStablecoin(messenger, chainId, tokenAddress) {
|
|
826
|
+
return Boolean((0, feature_flags_1.getStablecoins)(messenger)[chainId]?.includes(tokenAddress.toLowerCase()));
|
|
827
827
|
}
|
|
828
828
|
//# sourceMappingURL=relay-quotes.cjs.map
|