@metamask/transaction-pay-controller 3.0.0 → 3.1.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 +14 -1
- package/dist/strategy/bridge/bridge-quotes.cjs +13 -5
- package/dist/strategy/bridge/bridge-quotes.cjs.map +1 -1
- package/dist/strategy/bridge/bridge-quotes.mjs +13 -5
- package/dist/strategy/bridge/bridge-quotes.mjs.map +1 -1
- package/dist/strategy/bridge/bridge-submit.cjs +9 -3
- package/dist/strategy/bridge/bridge-submit.cjs.map +1 -1
- package/dist/strategy/bridge/bridge-submit.d.cts.map +1 -1
- package/dist/strategy/bridge/bridge-submit.d.mts.map +1 -1
- package/dist/strategy/bridge/bridge-submit.mjs +9 -3
- package/dist/strategy/bridge/bridge-submit.mjs.map +1 -1
- package/dist/utils/quotes.cjs +97 -49
- package/dist/utils/quotes.cjs.map +1 -1
- package/dist/utils/quotes.d.cts +2 -1
- package/dist/utils/quotes.d.cts.map +1 -1
- package/dist/utils/quotes.d.mts +2 -1
- package/dist/utils/quotes.d.mts.map +1 -1
- package/dist/utils/quotes.mjs +97 -49
- package/dist/utils/quotes.mjs.map +1 -1
- package/dist/utils/totals.cjs +14 -6
- package/dist/utils/totals.cjs.map +1 -1
- package/dist/utils/totals.d.cts +12 -4
- package/dist/utils/totals.d.cts.map +1 -1
- package/dist/utils/totals.d.mts +12 -4
- package/dist/utils/totals.d.mts.map +1 -1
- package/dist/utils/totals.mjs +14 -6
- package/dist/utils/totals.mjs.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"totals.d.cts","sourceRoot":"","sources":["../../src/utils/totals.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"totals.d.cts","sourceRoot":"","sources":["../../src/utils/totals.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,yCAAyC;AAIxE,OAAO,KAAK,EACV,iCAAiC,EACjC,mBAAmB,EACnB,2BAA2B,EAC3B,oBAAoB,EACrB,qBAAiB;AAElB;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,EAC9B,MAAM,EACN,SAAS,EACT,MAAM,EACN,WAAW,GACZ,EAAE;IACD,MAAM,EAAE,mBAAmB,CAAC,OAAO,CAAC,EAAE,CAAC;IACvC,SAAS,EAAE,iCAAiC,CAAC;IAC7C,MAAM,EAAE,2BAA2B,EAAE,CAAC;IACtC,WAAW,EAAE,eAAe,CAAC;CAC9B,GAAG,oBAAoB,CA+EvB"}
|
package/dist/utils/totals.d.mts
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
|
+
import type { TransactionMeta } from "@metamask/transaction-controller";
|
|
1
2
|
import type { TransactionPayControllerMessenger, TransactionPayQuote, TransactionPayRequiredToken, TransactionPayTotals } from "../types.mjs";
|
|
2
3
|
/**
|
|
3
4
|
* Calculate totals for a list of quotes and tokens.
|
|
4
5
|
*
|
|
5
|
-
* @param
|
|
6
|
-
* @param
|
|
7
|
-
* @param
|
|
6
|
+
* @param request - Request parameters.
|
|
7
|
+
* @param request.quotes - List of bridge quotes.
|
|
8
|
+
* @param request.messenger - Controller messenger.
|
|
9
|
+
* @param request.tokens - List of required tokens.
|
|
10
|
+
* @param request.transaction - Transaction metadata.
|
|
8
11
|
* @returns The calculated totals in USD and fiat currency.
|
|
9
12
|
*/
|
|
10
|
-
export declare function calculateTotals(quotes
|
|
13
|
+
export declare function calculateTotals({ quotes, messenger, tokens, transaction, }: {
|
|
14
|
+
quotes: TransactionPayQuote<unknown>[];
|
|
15
|
+
messenger: TransactionPayControllerMessenger;
|
|
16
|
+
tokens: TransactionPayRequiredToken[];
|
|
17
|
+
transaction: TransactionMeta;
|
|
18
|
+
}): TransactionPayTotals;
|
|
11
19
|
//# sourceMappingURL=totals.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"totals.d.mts","sourceRoot":"","sources":["../../src/utils/totals.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"totals.d.mts","sourceRoot":"","sources":["../../src/utils/totals.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,yCAAyC;AAIxE,OAAO,KAAK,EACV,iCAAiC,EACjC,mBAAmB,EACnB,2BAA2B,EAC3B,oBAAoB,EACrB,qBAAiB;AAElB;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,EAC9B,MAAM,EACN,SAAS,EACT,MAAM,EACN,WAAW,GACZ,EAAE;IACD,MAAM,EAAE,mBAAmB,CAAC,OAAO,CAAC,EAAE,CAAC;IACvC,SAAS,EAAE,iCAAiC,CAAC;IAC7C,MAAM,EAAE,2BAA2B,EAAE,CAAC;IACtC,WAAW,EAAE,eAAe,CAAC;CAC9B,GAAG,oBAAoB,CA+EvB"}
|
package/dist/utils/totals.mjs
CHANGED
|
@@ -1,19 +1,27 @@
|
|
|
1
1
|
import { BigNumber } from "bignumber.js";
|
|
2
|
+
import { calculateTransactionGasCost } from "./gas.mjs";
|
|
2
3
|
/**
|
|
3
4
|
* Calculate totals for a list of quotes and tokens.
|
|
4
5
|
*
|
|
5
|
-
* @param
|
|
6
|
-
* @param
|
|
7
|
-
* @param
|
|
6
|
+
* @param request - Request parameters.
|
|
7
|
+
* @param request.quotes - List of bridge quotes.
|
|
8
|
+
* @param request.messenger - Controller messenger.
|
|
9
|
+
* @param request.tokens - List of required tokens.
|
|
10
|
+
* @param request.transaction - Transaction metadata.
|
|
8
11
|
* @returns The calculated totals in USD and fiat currency.
|
|
9
12
|
*/
|
|
10
|
-
export function calculateTotals(quotes, tokens,
|
|
13
|
+
export function calculateTotals({ quotes, messenger, tokens, transaction, }) {
|
|
11
14
|
const providerFeeFiat = sumProperty(quotes, (quote) => quote.fees.provider.fiat);
|
|
12
15
|
const providerFeeUsd = sumProperty(quotes, (quote) => quote.fees.provider.usd);
|
|
13
16
|
const sourceNetworkFeeFiat = sumProperty(quotes, (quote) => quote.fees.sourceNetwork.fiat);
|
|
14
17
|
const sourceNetworkFeeUsd = sumProperty(quotes, (quote) => quote.fees.sourceNetwork.usd);
|
|
15
|
-
const
|
|
16
|
-
const
|
|
18
|
+
const transactionNetworkFee = calculateTransactionGasCost(transaction, messenger);
|
|
19
|
+
const targetNetworkFeeFiat = quotes?.length
|
|
20
|
+
? sumProperty(quotes, (quote) => quote.fees.targetNetwork.fiat)
|
|
21
|
+
: transactionNetworkFee.fiat;
|
|
22
|
+
const targetNetworkFeeUsd = quotes.length
|
|
23
|
+
? sumProperty(quotes, (quote) => quote.fees.targetNetwork.usd)
|
|
24
|
+
: transactionNetworkFee.usd;
|
|
17
25
|
const quoteTokens = tokens.filter((t) => !t.skipIfBalance || new BigNumber(t.balanceRaw).isLessThan(t.amountRaw));
|
|
18
26
|
const amountFiat = sumProperty(quoteTokens, (token) => token.amountFiat);
|
|
19
27
|
const amountUsd = sumProperty(quoteTokens, (token) => token.amountUsd);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"totals.mjs","sourceRoot":"","sources":["../../src/utils/totals.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"totals.mjs","sourceRoot":"","sources":["../../src/utils/totals.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,qBAAqB;AAEzC,OAAO,EAAE,2BAA2B,EAAE,kBAAc;AAQpD;;;;;;;;;GASG;AACH,MAAM,UAAU,eAAe,CAAC,EAC9B,MAAM,EACN,SAAS,EACT,MAAM,EACN,WAAW,GAMZ;IACC,MAAM,eAAe,GAAG,WAAW,CACjC,MAAM,EACN,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CACpC,CAAC;IAEF,MAAM,cAAc,GAAG,WAAW,CAChC,MAAM,EACN,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CACnC,CAAC;IAEF,MAAM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C,IAAI,CAAC,oBAAoB,CAAC;SAC1B,IAAI,CAAC,oBAAoB,CAAC;SAC1B,IAAI,CAAC,UAAU,CAAC;SAChB,QAAQ,CAAC,EAAE,CAAC,CAAC;IAEhB,MAAM,QAAQ,GAAG,IAAI,SAAS,CAAC,cAAc,CAAC;SAC3C,IAAI,CAAC,mBAAmB,CAAC;SACzB,IAAI,CAAC,mBAAmB,CAAC;SACzB,IAAI,CAAC,SAAS,CAAC;SACf,QAAQ,CAAC,EAAE,CAAC,CAAC;IAEhB,MAAM,iBAAiB,GAAG,MAAM,CAC9B,WAAW,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,iBAAiB,CAAC,CACxD,CAAC;IAEF,OAAO;QACL,iBAAiB;QACjB,IAAI,EAAE;YACJ,QAAQ,EAAE;gBACR,IAAI,EAAE,eAAe;gBACrB,GAAG,EAAE,cAAc;aACpB;YACD,aAAa,EAAE;gBACb,IAAI,EAAE,oBAAoB;gBAC1B,GAAG,EAAE,mBAAmB;aACzB;YACD,aAAa,EAAE;gBACb,IAAI,EAAE,oBAAoB;gBAC1B,GAAG,EAAE,mBAAmB;aACzB;SACF;QACD,KAAK,EAAE;YACL,IAAI,EAAE,SAAS;YACf,GAAG,EAAE,QAAQ;SACd;KACF,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,SAAS,WAAW,CAClB,IAAS,EACT,WAAyC;IAEzC,OAAO,IAAI;SACR,GAAG,CAAC,WAAW,CAAC;SAChB,MAAM,CAAY,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,IAAI,SAAS,CAAC,CAAC,CAAC,CAAC;SACxE,QAAQ,CAAC,EAAE,CAAC,CAAC;AAClB,CAAC","sourcesContent":["import type { TransactionMeta } from '@metamask/transaction-controller';\nimport { BigNumber } from 'bignumber.js';\n\nimport { calculateTransactionGasCost } from './gas';\nimport type {\n TransactionPayControllerMessenger,\n TransactionPayQuote,\n TransactionPayRequiredToken,\n TransactionPayTotals,\n} from '../types';\n\n/**\n * Calculate totals for a list of quotes and tokens.\n *\n * @param request - Request parameters.\n * @param request.quotes - List of bridge quotes.\n * @param request.messenger - Controller messenger.\n * @param request.tokens - List of required tokens.\n * @param request.transaction - Transaction metadata.\n * @returns The calculated totals in USD and fiat currency.\n */\nexport function calculateTotals({\n quotes,\n messenger,\n tokens,\n transaction,\n}: {\n quotes: TransactionPayQuote<unknown>[];\n messenger: TransactionPayControllerMessenger;\n tokens: TransactionPayRequiredToken[];\n transaction: TransactionMeta;\n}): TransactionPayTotals {\n const providerFeeFiat = sumProperty(\n quotes,\n (quote) => quote.fees.provider.fiat,\n );\n\n const providerFeeUsd = sumProperty(\n quotes,\n (quote) => quote.fees.provider.usd,\n );\n\n const sourceNetworkFeeFiat = sumProperty(\n quotes,\n (quote) => quote.fees.sourceNetwork.fiat,\n );\n\n const sourceNetworkFeeUsd = sumProperty(\n quotes,\n (quote) => quote.fees.sourceNetwork.usd,\n );\n\n const transactionNetworkFee = calculateTransactionGasCost(\n transaction,\n messenger,\n );\n\n const targetNetworkFeeFiat = quotes?.length\n ? sumProperty(quotes, (quote) => quote.fees.targetNetwork.fiat)\n : transactionNetworkFee.fiat;\n\n const targetNetworkFeeUsd = quotes.length\n ? sumProperty(quotes, (quote) => quote.fees.targetNetwork.usd)\n : transactionNetworkFee.usd;\n\n const quoteTokens = tokens.filter(\n (t) =>\n !t.skipIfBalance || new BigNumber(t.balanceRaw).isLessThan(t.amountRaw),\n );\n\n const amountFiat = sumProperty(quoteTokens, (token) => token.amountFiat);\n const amountUsd = sumProperty(quoteTokens, (token) => token.amountUsd);\n\n const totalFiat = new BigNumber(providerFeeFiat)\n .plus(sourceNetworkFeeFiat)\n .plus(targetNetworkFeeFiat)\n .plus(amountFiat)\n .toString(10);\n\n const totalUsd = new BigNumber(providerFeeUsd)\n .plus(sourceNetworkFeeUsd)\n .plus(targetNetworkFeeUsd)\n .plus(amountUsd)\n .toString(10);\n\n const estimatedDuration = Number(\n sumProperty(quotes, (quote) => quote.estimatedDuration),\n );\n\n return {\n estimatedDuration,\n fees: {\n provider: {\n fiat: providerFeeFiat,\n usd: providerFeeUsd,\n },\n sourceNetwork: {\n fiat: sourceNetworkFeeFiat,\n usd: sourceNetworkFeeUsd,\n },\n targetNetwork: {\n fiat: targetNetworkFeeFiat,\n usd: targetNetworkFeeUsd,\n },\n },\n total: {\n fiat: totalFiat,\n usd: totalUsd,\n },\n };\n}\n\n/**\n * Sum a specific property from a list of items.\n *\n * @param data - List of items.\n * @param getProperty - Function to extract the property to sum from each item.\n * @returns The summed value as a string.\n */\nfunction sumProperty<T>(\n data: T[],\n getProperty: (item: T) => BigNumber.Value,\n): string {\n return data\n .map(getProperty)\n .reduce<BigNumber>((total, value) => total.plus(value), new BigNumber(0))\n .toString(10);\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/transaction-pay-controller",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "Manages alternate payment strategies to provide required funds for transactions in MetaMask",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"lodash": "^4.17.21"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
|
-
"@metamask/assets-controllers": "^87.
|
|
65
|
+
"@metamask/assets-controllers": "^87.1.0",
|
|
66
66
|
"@metamask/auto-changelog": "^3.4.4",
|
|
67
67
|
"@metamask/bridge-controller": "^59.0.0",
|
|
68
68
|
"@metamask/bridge-status-controller": "^59.0.0",
|