@metamask-previews/bridge-controller 79.3.1-preview-e68ab1498 → 80.0.0-preview-4b37525
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 +21 -1
- package/dist/coercers/quote-response-v1-to-v2.cjs +4 -4
- package/dist/coercers/quote-response-v1-to-v2.cjs.map +1 -1
- package/dist/coercers/quote-response-v1-to-v2.mjs +4 -4
- package/dist/coercers/quote-response-v1-to-v2.mjs.map +1 -1
- package/dist/index.cjs +12 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2 -1
- package/dist/index.mjs.map +1 -1
- package/dist/selectors.cjs +48 -4
- package/dist/selectors.cjs.map +1 -1
- package/dist/selectors.d.cts +1200 -105
- package/dist/selectors.d.cts.map +1 -1
- package/dist/selectors.d.mts +1200 -105
- package/dist/selectors.d.mts.map +1 -1
- package/dist/selectors.mjs +48 -4
- package/dist/selectors.mjs.map +1 -1
- package/dist/utils/quote-metadata/calculators.cjs +7 -12
- package/dist/utils/quote-metadata/calculators.cjs.map +1 -1
- package/dist/utils/quote-metadata/calculators.d.cts.map +1 -1
- package/dist/utils/quote-metadata/calculators.d.mts.map +1 -1
- package/dist/utils/quote-metadata/calculators.mjs +8 -13
- package/dist/utils/quote-metadata/calculators.mjs.map +1 -1
- package/dist/utils/quote-metadata/include-if-truthy.cjs +21 -0
- package/dist/utils/quote-metadata/include-if-truthy.cjs.map +1 -0
- package/dist/utils/quote-metadata/include-if-truthy.d.cts +9 -0
- package/dist/utils/quote-metadata/include-if-truthy.d.cts.map +1 -0
- package/dist/utils/quote-metadata/include-if-truthy.d.mts +9 -0
- package/dist/utils/quote-metadata/include-if-truthy.d.mts.map +1 -0
- package/dist/utils/quote-metadata/include-if-truthy.mjs +17 -0
- package/dist/utils/quote-metadata/include-if-truthy.mjs.map +1 -0
- package/dist/utils/quote-metadata/merge.cjs +43 -10
- package/dist/utils/quote-metadata/merge.cjs.map +1 -1
- package/dist/utils/quote-metadata/merge.d.cts +6 -3
- package/dist/utils/quote-metadata/merge.d.cts.map +1 -1
- package/dist/utils/quote-metadata/merge.d.mts +6 -3
- package/dist/utils/quote-metadata/merge.d.mts.map +1 -1
- package/dist/utils/quote-metadata/merge.mjs +43 -10
- package/dist/utils/quote-metadata/merge.mjs.map +1 -1
- package/dist/utils/quote-metadata/to-currency-values.cjs +62 -0
- package/dist/utils/quote-metadata/to-currency-values.cjs.map +1 -0
- package/dist/utils/quote-metadata/to-currency-values.d.cts +12 -0
- package/dist/utils/quote-metadata/to-currency-values.d.cts.map +1 -0
- package/dist/utils/quote-metadata/to-currency-values.d.mts +12 -0
- package/dist/utils/quote-metadata/to-currency-values.d.mts.map +1 -0
- package/dist/utils/quote-metadata/to-currency-values.mjs +58 -0
- package/dist/utils/quote-metadata/to-currency-values.mjs.map +1 -0
- package/dist/utils/quote-metadata/to-quote-metadata-v1.cjs +67 -16
- package/dist/utils/quote-metadata/to-quote-metadata-v1.cjs.map +1 -1
- package/dist/utils/quote-metadata/to-quote-metadata-v1.d.cts +3 -1
- package/dist/utils/quote-metadata/to-quote-metadata-v1.d.cts.map +1 -1
- package/dist/utils/quote-metadata/to-quote-metadata-v1.d.mts +3 -1
- package/dist/utils/quote-metadata/to-quote-metadata-v1.d.mts.map +1 -1
- package/dist/utils/quote-metadata/to-quote-metadata-v1.mjs +67 -16
- package/dist/utils/quote-metadata/to-quote-metadata-v1.mjs.map +1 -1
- package/dist/utils/quote-metadata/to-quote-metadata-v2.cjs +26 -45
- package/dist/utils/quote-metadata/to-quote-metadata-v2.cjs.map +1 -1
- package/dist/utils/quote-metadata/to-quote-metadata-v2.d.cts.map +1 -1
- package/dist/utils/quote-metadata/to-quote-metadata-v2.d.mts.map +1 -1
- package/dist/utils/quote-metadata/to-quote-metadata-v2.mjs +26 -45
- package/dist/utils/quote-metadata/to-quote-metadata-v2.mjs.map +1 -1
- package/dist/utils/quote-metadata/types.cjs +16 -0
- package/dist/utils/quote-metadata/types.cjs.map +1 -1
- package/dist/utils/quote-metadata/types.d.cts +21 -0
- package/dist/utils/quote-metadata/types.d.cts.map +1 -1
- package/dist/utils/quote-metadata/types.d.mts +21 -0
- package/dist/utils/quote-metadata/types.d.mts.map +1 -1
- package/dist/utils/quote-metadata/types.mjs +15 -1
- package/dist/utils/quote-metadata/types.mjs.map +1 -1
- package/dist/validators/quote-response.cjs +14 -1
- package/dist/validators/quote-response.cjs.map +1 -1
- package/dist/validators/quote-response.d.cts +9 -0
- package/dist/validators/quote-response.d.cts.map +1 -1
- package/dist/validators/quote-response.d.mts +9 -0
- package/dist/validators/quote-response.d.mts.map +1 -1
- package/dist/validators/quote-response.mjs +12 -0
- package/dist/validators/quote-response.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -2,6 +2,16 @@ import { parseCaipAssetType } from "@metamask/utils";
|
|
|
2
2
|
import { toBridgeAssetV2 } from "../../coercers/quote-response-v1-to-v2.mjs";
|
|
3
3
|
import { getNativeAssetForChainId } from "../bridge.mjs";
|
|
4
4
|
import { calcAtomicTokenAmount } from "../number-formatters.mjs";
|
|
5
|
+
import { includeIfTruthy } from "./include-if-truthy.mjs";
|
|
6
|
+
const toAmountAndAsset = (asset, metadata, extraFields) => {
|
|
7
|
+
return {
|
|
8
|
+
amount: calcAtomicTokenAmount(metadata?.amount, asset?.decimals),
|
|
9
|
+
normalizedAmount: metadata?.amount,
|
|
10
|
+
valueInCurrency: metadata?.valueInCurrency,
|
|
11
|
+
usd: metadata?.usd,
|
|
12
|
+
...extraFields,
|
|
13
|
+
};
|
|
14
|
+
};
|
|
5
15
|
/**
|
|
6
16
|
* Converts a {@link QuoteMetadata} to a partial {@link QuoteResponse} containing only metadata
|
|
7
17
|
*
|
|
@@ -28,68 +38,39 @@ export const toQuoteMetadataV2 = (quoteMetadata, quoteResponseV2) => {
|
|
|
28
38
|
return {
|
|
29
39
|
...rest,
|
|
30
40
|
quote: {
|
|
31
|
-
src:
|
|
32
|
-
amount: calcAtomicTokenAmount(sentAmount?.amount, srcAsset?.decimals),
|
|
33
|
-
normalizedAmount: sentAmount?.amount,
|
|
34
|
-
valueInCurrency: sentAmount?.valueInCurrency,
|
|
35
|
-
usd: sentAmount?.usd,
|
|
36
|
-
},
|
|
41
|
+
src: toAmountAndAsset(srcAsset, sentAmount),
|
|
37
42
|
dest: {
|
|
38
|
-
|
|
39
|
-
normalizedAmount: toTokenAmount?.amount,
|
|
40
|
-
valueInCurrency: toTokenAmount?.valueInCurrency,
|
|
41
|
-
usd: toTokenAmount?.usd,
|
|
43
|
+
...toAmountAndAsset(destAsset, toTokenAmount),
|
|
42
44
|
minAmount: calcAtomicTokenAmount(minToTokenAmount?.amount, destAsset?.decimals),
|
|
43
45
|
minAmountNormalized: minToTokenAmount?.amount,
|
|
44
46
|
minAmountUsd: minToTokenAmount?.usd,
|
|
45
47
|
minAmountValueInCurrency: minToTokenAmount?.valueInCurrency,
|
|
46
48
|
},
|
|
47
49
|
feeData: {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
normalizedAmount: networkFeeToUse?.amount,
|
|
52
|
-
valueInCurrency: networkFeeToUse?.valueInCurrency,
|
|
53
|
-
usd: networkFeeToUse?.usd,
|
|
54
|
-
asset: nativeAsset,
|
|
55
|
-
},
|
|
56
|
-
],
|
|
57
|
-
...(relayerFee &&
|
|
58
|
-
Object.values(relayerFee).some(Boolean) && {
|
|
59
|
-
relayer: [
|
|
60
|
-
{
|
|
61
|
-
amount: calcAtomicTokenAmount(relayerFee?.amount, nativeAsset?.decimals),
|
|
62
|
-
normalizedAmount: relayerFee.amount,
|
|
63
|
-
valueInCurrency: relayerFee.valueInCurrency,
|
|
64
|
-
usd: relayerFee.usd,
|
|
50
|
+
...includeIfTruthy(networkFeeToUse, {
|
|
51
|
+
network: [
|
|
52
|
+
toAmountAndAsset(nativeAsset, networkFeeToUse, {
|
|
65
53
|
asset: nativeAsset,
|
|
66
|
-
},
|
|
54
|
+
}),
|
|
55
|
+
],
|
|
56
|
+
}),
|
|
57
|
+
...includeIfTruthy(relayerFee, {
|
|
58
|
+
relayer: [
|
|
59
|
+
toAmountAndAsset(nativeAsset, relayerFee, { asset: nativeAsset }),
|
|
67
60
|
],
|
|
68
61
|
}),
|
|
69
|
-
...(includedTxFees
|
|
70
|
-
Object.values(includedTxFees).some(Boolean) && {
|
|
62
|
+
...includeIfTruthy(includedTxFees, {
|
|
71
63
|
txFee: [
|
|
72
|
-
{
|
|
73
|
-
amount: calcAtomicTokenAmount(includedTxFees?.amount, txFeeAsset?.decimals),
|
|
74
|
-
normalizedAmount: includedTxFees?.amount,
|
|
75
|
-
valueInCurrency: includedTxFees?.valueInCurrency,
|
|
76
|
-
usd: includedTxFees?.usd,
|
|
77
|
-
asset: txFeeAsset,
|
|
78
|
-
},
|
|
64
|
+
toAmountAndAsset(txFeeAsset, includedTxFees, { asset: txFeeAsset }),
|
|
79
65
|
],
|
|
80
66
|
}),
|
|
81
67
|
},
|
|
82
68
|
priceData: {
|
|
83
|
-
...(priceImpactToUse
|
|
84
|
-
Object.values(priceImpactToUse).some(Boolean) && {
|
|
69
|
+
...includeIfTruthy(priceImpactToUse, {
|
|
85
70
|
priceImpact: priceImpactToUse,
|
|
86
71
|
}),
|
|
87
|
-
...(adjustedReturn
|
|
88
|
-
|
|
89
|
-
adjustedReturn: {
|
|
90
|
-
valueInCurrency: adjustedReturn?.valueInCurrency,
|
|
91
|
-
usd: adjustedReturn?.usd,
|
|
92
|
-
},
|
|
72
|
+
...includeIfTruthy(adjustedReturn, {
|
|
73
|
+
adjustedReturn,
|
|
93
74
|
}),
|
|
94
75
|
swapRate,
|
|
95
76
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"to-quote-metadata-v2.mjs","sourceRoot":"","sources":["../../../src/utils/quote-metadata/to-quote-metadata-v2.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,wBAAwB;AAErD,OAAO,EAAE,eAAe,EAAE,mDAAkD;
|
|
1
|
+
{"version":3,"file":"to-quote-metadata-v2.mjs","sourceRoot":"","sources":["../../../src/utils/quote-metadata/to-quote-metadata-v2.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,wBAAwB;AAErD,OAAO,EAAE,eAAe,EAAE,mDAAkD;AAK5E,OAAO,EAAE,wBAAwB,EAAE,sBAAqB;AACxD,OAAO,EAAE,qBAAqB,EAAE,iCAAgC;AAChE,OAAO,EAAE,eAAe,EAAE,gCAA+B;AAGzD,MAAM,gBAAgB,GAAG,CACvB,KAAkC,EAClC,QAAqC,EACrC,WAA0C,EACZ,EAAE;IAChC,OAAO;QACL,MAAM,EAAE,qBAAqB,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,CAAC;QAChE,gBAAgB,EAAE,QAAQ,EAAE,MAAM;QAClC,eAAe,EAAE,QAAQ,EAAE,eAAe;QAC1C,GAAG,EAAE,QAAQ,EAAE,GAAG;QAClB,GAAG,WAAW;KACf,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,aAA4B,EAC5B,eAA4C,EAChB,EAAE;IAC9B,MAAM,EACJ,UAAU,EACV,aAAa,EACb,gBAAgB,EAChB,QAAQ,EACR,eAAe,EACf,MAAM,EACN,cAAc,EACd,IAAI,EACJ,cAAc,EACd,UAAU,EACV,WAAW,EACX,GAAG,IAAI,EACR,GAAG,aAAa,CAAC;IAElB,MAAM,QAAQ,GAAG,eAAe,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,CAAC;IACpD,MAAM,SAAS,GAAG,eAAe,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC;IAEtD,MAAM,OAAO,GAAG,QAAQ,EAAE,OAAO;QAC/B,CAAC,CAAC,kBA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qBAClE;iBACF,CAAC;gBACF,GAAG,eAAe,CAAC,cAAc,EAAE;oBACjC,KAAK,EAAE;wBACL,gBAAgB,CAAC,UAAU,EAAE,cAAc,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC;qBACpE;iBACF,CAAC;aACH;YACD,SAAS,EAAE;gBACT,GAAG,eAAe,CAAC,gBAAgB,EAAE;oBACnC,WAAW,EAAE,gBAAgB;iBAC9B,CAAC;gBACF,GAAG,eAAe,CAAC,cAAc,EAAE;oBACjC,cAAc;iBACf,CAAC;gBACF,QAAQ;aACT;SACF;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { parseCaipAssetType } from '@metamask/utils';\n\nimport { toBridgeAssetV2 } from '../../coercers/quote-response-v1-to-v2.js';\nimport type { DeepPartial } from '../../types.js';\nimport type { AmountsAndAsset } from '../../validators/amount-and-asset.js';\nimport type { BridgeAssetV2 } from '../../validators/bridge-asset.js';\nimport type { QuoteResponse } from '../../validators/quote-response.js';\nimport { getNativeAssetForChainId } from '../bridge.js';\nimport { calcAtomicTokenAmount } from '../number-formatters.js';\nimport { includeIfTruthy } from './include-if-truthy.js';\nimport type { QuoteMetadata, TokenAmountValues } from './types.js';\n\nconst toAmountAndAsset = (\n asset?: DeepPartial<BridgeAssetV2>,\n metadata?: Partial<TokenAmountValues>,\n extraFields?: DeepPartial<AmountsAndAsset>,\n): DeepPartial<AmountsAndAsset> => {\n return {\n amount: calcAtomicTokenAmount(metadata?.amount, asset?.decimals),\n normalizedAmount: metadata?.amount,\n valueInCurrency: metadata?.valueInCurrency,\n usd: metadata?.usd,\n ...extraFields,\n };\n};\n\n/**\n * Converts a {@link QuoteMetadata} to a partial {@link QuoteResponse} containing only metadata\n *\n * @param quoteMetadata - The {@link QuoteMetadata} to convert\n * @param quoteResponseV2 - The {@link QuoteResponse} to use for token data\n * @returns The {@link DeepPartial<QuoteResponse>}\n */\nexport const toQuoteMetadataV2 = (\n quoteMetadata: QuoteMetadata,\n quoteResponseV2?: DeepPartial<QuoteResponse>,\n): DeepPartial<QuoteResponse> => {\n const {\n sentAmount,\n toTokenAmount,\n minToTokenAmount,\n swapRate,\n totalNetworkFee,\n gasFee,\n adjustedReturn,\n cost,\n includedTxFees,\n relayerFee,\n priceImpact,\n ...rest\n } = quoteMetadata;\n\n const srcAsset = quoteResponseV2?.quote?.src?.asset;\n const destAsset = quoteResponseV2?.quote?.dest?.asset;\n\n const chainId = srcAsset?.assetId\n ? parseCaipAssetType(srcAsset.assetId)?.chainId\n : undefined;\n const nativeAsset = chainId\n ? toBridgeAssetV2(getNativeAssetForChainId(chainId))\n : undefined;\n const txFeeAsset = quoteResponseV2?.quote?.feeData?.txFee?.[0]?.asset;\n\n const priceImpactToUse = {\n usd: priceImpact?.usd ?? cost?.usd,\n valueInCurrency: priceImpact?.valueInCurrency ?? cost?.valueInCurrency,\n };\n const networkFeeToUse = gasFee?.total ?? totalNetworkFee;\n\n return {\n ...rest,\n quote: {\n src: toAmountAndAsset(srcAsset, sentAmount),\n dest: {\n ...toAmountAndAsset(destAsset, toTokenAmount),\n minAmount: calcAtomicTokenAmount(\n minToTokenAmount?.amount,\n destAsset?.decimals,\n ),\n minAmountNormalized: minToTokenAmount?.amount,\n minAmountUsd: minToTokenAmount?.usd,\n minAmountValueInCurrency: minToTokenAmount?.valueInCurrency,\n },\n feeData: {\n ...includeIfTruthy(networkFeeToUse, {\n network: [\n toAmountAndAsset(nativeAsset, networkFeeToUse, {\n asset: nativeAsset,\n }),\n ],\n }),\n ...includeIfTruthy(relayerFee, {\n relayer: [\n toAmountAndAsset(nativeAsset, relayerFee, { asset: nativeAsset }),\n ],\n }),\n ...includeIfTruthy(includedTxFees, {\n txFee: [\n toAmountAndAsset(txFeeAsset, includedTxFees, { asset: txFeeAsset }),\n ],\n }),\n },\n priceData: {\n ...includeIfTruthy(priceImpactToUse, {\n priceImpact: priceImpactToUse,\n }),\n ...includeIfTruthy(adjustedReturn, {\n adjustedReturn,\n }),\n swapRate,\n },\n },\n };\n};\n"]}
|
|
@@ -1,3 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.QuoteMetadataMigrationPhase = void 0;
|
|
4
|
+
exports.QuoteMetadataMigrationPhase = {
|
|
5
|
+
/**
|
|
6
|
+
* Phase 1: omit API V2 currency metadata; serve legacy calcQuoteMetadata
|
|
7
|
+
* into V2 nested shape
|
|
8
|
+
*/
|
|
9
|
+
V1Data: '1',
|
|
10
|
+
/**
|
|
11
|
+
* Phase 1.5: prefer API V2 metadata (+ fiat from usd); fall back to legacy.
|
|
12
|
+
*/
|
|
13
|
+
V2WithV1Fallback: '1.5',
|
|
14
|
+
/**
|
|
15
|
+
* Phase 2: API V2 metadata only; legacy metadata utils can be removed.
|
|
16
|
+
*/
|
|
17
|
+
V2Only: '2',
|
|
18
|
+
};
|
|
3
19
|
//# sourceMappingURL=types.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../../../src/utils/quote-metadata/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { DeepPartial } from '../../types.js';\n\n/**\n * The types of values for the token amount and its values when converted to the user's selected currency and USD\n */\nexport type TokenAmountValues = {\n /**\n * The amount of the token\n *\n * @example \"1.005\"\n */\n amount: string;\n /**\n * The amount of the token in the user's selected currency\n *\n * @example \"4.55\"\n */\n valueInCurrency: string;\n /**\n * The amount of the token in USD\n *\n * @example \"1.234\"\n */\n usd: string;\n};\n\n/**\n * Values derived from the quote response\n *\n * @deprecated Avoid introducing new usages and use the QuoteResponse V2 type instead\n */\ntype QuoteMetadataV1 = {\n /**\n * If gas is included, this is the value of the src or dest token that was used to pay for the gas.\n * Show this value to indicate transaction fees for gasless quotes.\n */\n includedTxFees?: Partial<TokenAmountValues>;\n /**\n * The gas fee for the bridge transaction.\n * effective is the gas fee that is shown to the user. If this value is not\n * included in the trade, the calculation falls back to the gasLimit (total)\n * total is the gas fee that is spent by the user, including refunds.\n * max is the max gas fee that will be used by the transaction.\n */\n gasFee: Record<'total', TokenAmountValues>;\n relayerFee?: Partial<TokenAmountValues>; // relayer/provider fee in native units\n /**\n * The total network fee required to submit the trade and any approvals. This includes\n * the relayer fee or other native fees. Should be used for balance checks and tx submission.\n * Note: This is only accurate for non-gasless transactions. Use {@link QuoteMetadata.includedTxFees} to\n * get the total network fee for gasless transactions.\n */\n totalNetworkFee: TokenAmountValues; // gasFee.total + relayerFee\n /**\n * The amount that the user will receive (destTokenAmount)\n */\n toTokenAmount: TokenAmountValues;\n /**\n * The minimum amount that the user will receive (minDestTokenAmount)\n */\n minToTokenAmount: TokenAmountValues;\n /**\n * If gas is included: {@link QuoteMetadata.toTokenAmount} - {@link QuoteMetadata.includedTxFees}.\n * Otherwise: {@link QuoteMetadata.toTokenAmount} - {@link QuoteMetadata.totalNetworkFee}.\n */\n adjustedReturn: Omit<TokenAmountValues, 'amount'>;\n /**\n * The amount that the user will send, including fees that are paid in the src token\n * {@link Quote.srcTokenAmount} + {@link Quote.feeData[FeeType.METABRIDGE].amount} + {@link Quote.feeData[FeeType.TX_FEE].amount}\n */\n sentAmount: TokenAmountValues;\n /**\n * The swap rate is the amount that the user will receive per amount sent. Accounts for fees paid in the src or dest token.\n * This is calculated as {@link QuoteMetadata.toTokenAmount} / {@link QuoteMetadata.sentAmount}.\n */\n swapRate: string;\n /**\n * The cost of the trade, which is the difference between the amount sent and the adjusted return.\n * This is calculated as {@link QuoteMetadata.sentAmount} - {@link QuoteMetadata.adjustedReturn}.\n */\n cost: Omit<TokenAmountValues, 'amount'>; // sentAmount - adjustedReturn\n\n /**\n * The price impact for the quote.\n */\n priceImpact: Omit<TokenAmountValues, 'amount'>; // abs(sentAmount - toTokenAmount);\n};\n\nexport type QuoteMetadata = DeepPartial<QuoteMetadataV1>;\n"]}
|
|
1
|
+
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../../../src/utils/quote-metadata/types.ts"],"names":[],"mappings":";;;AA+Fa,QAAA,2BAA2B,GAAG;IACzC;;;OAGG;IACH,MAAM,EAAE,GAAG;IACX;;OAEG;IACH,gBAAgB,EAAE,KAAK;IACvB;;OAEG;IACH,MAAM,EAAE,GAAG;CACH,CAAC","sourcesContent":["import type { DeepPartial } from '../../types.js';\n\n/**\n * The types of values for the token amount and its values when converted to the user's selected currency and USD\n */\nexport type TokenAmountValues = {\n /**\n * The amount of the token\n *\n * @example \"1.005\"\n */\n amount: string;\n /**\n * The amount of the token in the user's selected currency\n *\n * @example \"4.55\"\n */\n valueInCurrency: string;\n /**\n * The amount of the token in USD\n *\n * @example \"1.234\"\n */\n usd: string;\n};\n\n/**\n * Values derived from the quote response\n *\n * @deprecated Avoid introducing new usages and use the QuoteResponse V2 type instead\n */\ntype QuoteMetadataV1 = {\n /**\n * If gas is included, this is the value of the src or dest token that was used to pay for the gas.\n * Show this value to indicate transaction fees for gasless quotes.\n */\n includedTxFees?: Partial<TokenAmountValues>;\n /**\n * The gas fee for the bridge transaction.\n * effective is the gas fee that is shown to the user. If this value is not\n * included in the trade, the calculation falls back to the gasLimit (total)\n * total is the gas fee that is spent by the user, including refunds.\n * max is the max gas fee that will be used by the transaction.\n */\n gasFee: Record<'total', TokenAmountValues>;\n relayerFee?: Partial<TokenAmountValues>; // relayer/provider fee in native units\n /**\n * The total network fee required to submit the trade and any approvals. This includes\n * the relayer fee or other native fees. Should be used for balance checks and tx submission.\n * Note: This is only accurate for non-gasless transactions. Use {@link QuoteMetadata.includedTxFees} to\n * get the total network fee for gasless transactions.\n */\n totalNetworkFee: TokenAmountValues; // gasFee.total + relayerFee\n /**\n * The amount that the user will receive (destTokenAmount)\n */\n toTokenAmount: TokenAmountValues;\n /**\n * The minimum amount that the user will receive (minDestTokenAmount)\n */\n minToTokenAmount: TokenAmountValues;\n /**\n * If gas is included: {@link QuoteMetadata.toTokenAmount} - {@link QuoteMetadata.includedTxFees}.\n * Otherwise: {@link QuoteMetadata.toTokenAmount} - {@link QuoteMetadata.totalNetworkFee}.\n */\n adjustedReturn: Omit<TokenAmountValues, 'amount'>;\n /**\n * The amount that the user will send, including fees that are paid in the src token\n * {@link Quote.srcTokenAmount} + {@link Quote.feeData[FeeType.METABRIDGE].amount} + {@link Quote.feeData[FeeType.TX_FEE].amount}\n */\n sentAmount: TokenAmountValues;\n /**\n * The swap rate is the amount that the user will receive per amount sent. Accounts for fees paid in the src or dest token.\n * This is calculated as {@link QuoteMetadata.toTokenAmount} / {@link QuoteMetadata.sentAmount}.\n */\n swapRate: string;\n /**\n * The cost of the trade, which is the difference between the amount sent and the adjusted return.\n * This is calculated as {@link QuoteMetadata.sentAmount} - {@link QuoteMetadata.adjustedReturn}.\n */\n cost: Omit<TokenAmountValues, 'amount'>; // sentAmount - adjustedReturn\n\n /**\n * The price impact for the quote.\n */\n priceImpact: Omit<TokenAmountValues, 'amount'>; // abs(sentAmount - toTokenAmount);\n};\n\n/**\n * The partial legacy quote metadata\n *\n * @deprecated Avoid introducing new usages and use the nested QuoteResponse metadata instead\n */\nexport type QuoteMetadata = DeepPartial<QuoteMetadataV1>;\n\nexport const QuoteMetadataMigrationPhase = {\n /**\n * Phase 1: omit API V2 currency metadata; serve legacy calcQuoteMetadata\n * into V2 nested shape\n */\n V1Data: '1',\n /**\n * Phase 1.5: prefer API V2 metadata (+ fiat from usd); fall back to legacy.\n */\n V2WithV1Fallback: '1.5',\n /**\n * Phase 2: API V2 metadata only; legacy metadata utils can be removed.\n */\n V2Only: '2',\n} as const;\n\nexport type QuoteMetadataMigrationPhase =\n (typeof QuoteMetadataMigrationPhase)[keyof typeof QuoteMetadataMigrationPhase];\n"]}
|
|
@@ -82,6 +82,27 @@ type QuoteMetadataV1 = {
|
|
|
82
82
|
*/
|
|
83
83
|
priceImpact: Omit<TokenAmountValues, 'amount'>;
|
|
84
84
|
};
|
|
85
|
+
/**
|
|
86
|
+
* The partial legacy quote metadata
|
|
87
|
+
*
|
|
88
|
+
* @deprecated Avoid introducing new usages and use the nested QuoteResponse metadata instead
|
|
89
|
+
*/
|
|
85
90
|
export type QuoteMetadata = DeepPartial<QuoteMetadataV1>;
|
|
91
|
+
export declare const QuoteMetadataMigrationPhase: {
|
|
92
|
+
/**
|
|
93
|
+
* Phase 1: omit API V2 currency metadata; serve legacy calcQuoteMetadata
|
|
94
|
+
* into V2 nested shape
|
|
95
|
+
*/
|
|
96
|
+
readonly V1Data: "1";
|
|
97
|
+
/**
|
|
98
|
+
* Phase 1.5: prefer API V2 metadata (+ fiat from usd); fall back to legacy.
|
|
99
|
+
*/
|
|
100
|
+
readonly V2WithV1Fallback: "1.5";
|
|
101
|
+
/**
|
|
102
|
+
* Phase 2: API V2 metadata only; legacy metadata utils can be removed.
|
|
103
|
+
*/
|
|
104
|
+
readonly V2Only: "2";
|
|
105
|
+
};
|
|
106
|
+
export type QuoteMetadataMigrationPhase = (typeof QuoteMetadataMigrationPhase)[keyof typeof QuoteMetadataMigrationPhase];
|
|
86
107
|
export {};
|
|
87
108
|
//# sourceMappingURL=types.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../../../src/utils/quote-metadata/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,wBAAuB;AAElD;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B;;;;OAIG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;;;OAIG;IACH,eAAe,EAAE,MAAM,CAAC;IACxB;;;;OAIG;IACH,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF;;;;GAIG;AACH,KAAK,eAAe,GAAG;IACrB;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAC5C;;;;;;OAMG;IACH,MAAM,EAAE,MAAM,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAC;IAC3C,UAAU,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC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AiB,CAAC;IACpC;;;OAGG;IACH,cAAc,EAAE,IAAI,CAAC,iBAAiB,EAAE,QAAQ,CAAC,CAAC;IAClD;;;OAGG;IACH,UAAU,EAAE,iBAAiB,CAAC;IAC9B;;;OAGG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,IAAI,EAAE,IAAI,CAAC,iBAAiB,EAAE,QAAQ,CAAC,CAAC;IAExC;;OAEG;IACH,WAAW,EAAE,IAAI,CAAC,iBAAiB,EAAE,QAAQ,CAAC,CAAC;CAChD,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,aAAa,GAAG,WAAW,CAAC,eAAe,CAAC,CAAC;AAEzD,eAAO,MAAM,2BAA2B;IACtC;;;OAGG;;IAEH;;OAEG;;IAEH;;OAEG;;CAEK,CAAC;AAEX,MAAM,MAAM,2BAA2B,GACrC,CAAC,OAAO,2BAA2B,CAAC,CAAC,MAAM,OAAO,2BAA2B,CAAC,CAAC"}
|
|
@@ -82,6 +82,27 @@ type QuoteMetadataV1 = {
|
|
|
82
82
|
*/
|
|
83
83
|
priceImpact: Omit<TokenAmountValues, 'amount'>;
|
|
84
84
|
};
|
|
85
|
+
/**
|
|
86
|
+
* The partial legacy quote metadata
|
|
87
|
+
*
|
|
88
|
+
* @deprecated Avoid introducing new usages and use the nested QuoteResponse metadata instead
|
|
89
|
+
*/
|
|
85
90
|
export type QuoteMetadata = DeepPartial<QuoteMetadataV1>;
|
|
91
|
+
export declare const QuoteMetadataMigrationPhase: {
|
|
92
|
+
/**
|
|
93
|
+
* Phase 1: omit API V2 currency metadata; serve legacy calcQuoteMetadata
|
|
94
|
+
* into V2 nested shape
|
|
95
|
+
*/
|
|
96
|
+
readonly V1Data: "1";
|
|
97
|
+
/**
|
|
98
|
+
* Phase 1.5: prefer API V2 metadata (+ fiat from usd); fall back to legacy.
|
|
99
|
+
*/
|
|
100
|
+
readonly V2WithV1Fallback: "1.5";
|
|
101
|
+
/**
|
|
102
|
+
* Phase 2: API V2 metadata only; legacy metadata utils can be removed.
|
|
103
|
+
*/
|
|
104
|
+
readonly V2Only: "2";
|
|
105
|
+
};
|
|
106
|
+
export type QuoteMetadataMigrationPhase = (typeof QuoteMetadataMigrationPhase)[keyof typeof QuoteMetadataMigrationPhase];
|
|
86
107
|
export {};
|
|
87
108
|
//# sourceMappingURL=types.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../../../src/utils/quote-metadata/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,wBAAuB;AAElD;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B;;;;OAIG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;;;OAIG;IACH,eAAe,EAAE,MAAM,CAAC;IACxB;;;;OAIG;IACH,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF;;;;GAIG;AACH,KAAK,eAAe,GAAG;IACrB;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAC5C;;;;;;OAMG;IACH,MAAM,EAAE,MAAM,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAC;IAC3C,UAAU,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC;IACxC;;;;;OAKG;IACH,eAAe,EAAE,iBAAiB,CAAC;IACnC;;OAEG;IACH,aAAa,EAAE,iBAAiB,CAAC;IACjC;;OAEG;IACH,gBAAgB,EAAE,iBAAiB,CAAC;IACpC;;;OAGG;IACH,cAAc,EAAE,IAAI,CAAC,iBAAiB,EAAE,QAAQ,CAAC,CAAC;IAClD;;;OAGG;IACH,UAAU,EAAE,iBAAiB,CAAC;IAC9B;;;OAGG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,IAAI,EAAE,IAAI,CAAC,iBAAiB,EAAE,QAAQ,CAAC,CAAC;IAExC;;OAEG;IACH,WAAW,EAAE,IAA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AEzD,eAAO,MAAM,2BAA2B;IACtC;;;OAGG;;IAEH;;OAEG;;IAEH;;OAEG;;CAEK,CAAC;AAEX,MAAM,MAAM,2BAA2B,GACrC,CAAC,OAAO,2BAA2B,CAAC,CAAC,MAAM,OAAO,2BAA2B,CAAC,CAAC"}
|
|
@@ -1,2 +1,16 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export const QuoteMetadataMigrationPhase = {
|
|
2
|
+
/**
|
|
3
|
+
* Phase 1: omit API V2 currency metadata; serve legacy calcQuoteMetadata
|
|
4
|
+
* into V2 nested shape
|
|
5
|
+
*/
|
|
6
|
+
V1Data: '1',
|
|
7
|
+
/**
|
|
8
|
+
* Phase 1.5: prefer API V2 metadata (+ fiat from usd); fall back to legacy.
|
|
9
|
+
*/
|
|
10
|
+
V2WithV1Fallback: '1.5',
|
|
11
|
+
/**
|
|
12
|
+
* Phase 2: API V2 metadata only; legacy metadata utils can be removed.
|
|
13
|
+
*/
|
|
14
|
+
V2Only: '2',
|
|
15
|
+
};
|
|
2
16
|
//# sourceMappingURL=types.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../../../src/utils/quote-metadata/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { DeepPartial } from '../../types.js';\n\n/**\n * The types of values for the token amount and its values when converted to the user's selected currency and USD\n */\nexport type TokenAmountValues = {\n /**\n * The amount of the token\n *\n * @example \"1.005\"\n */\n amount: string;\n /**\n * The amount of the token in the user's selected currency\n *\n * @example \"4.55\"\n */\n valueInCurrency: string;\n /**\n * The amount of the token in USD\n *\n * @example \"1.234\"\n */\n usd: string;\n};\n\n/**\n * Values derived from the quote response\n *\n * @deprecated Avoid introducing new usages and use the QuoteResponse V2 type instead\n */\ntype QuoteMetadataV1 = {\n /**\n * If gas is included, this is the value of the src or dest token that was used to pay for the gas.\n * Show this value to indicate transaction fees for gasless quotes.\n */\n includedTxFees?: Partial<TokenAmountValues>;\n /**\n * The gas fee for the bridge transaction.\n * effective is the gas fee that is shown to the user. If this value is not\n * included in the trade, the calculation falls back to the gasLimit (total)\n * total is the gas fee that is spent by the user, including refunds.\n * max is the max gas fee that will be used by the transaction.\n */\n gasFee: Record<'total', TokenAmountValues>;\n relayerFee?: Partial<TokenAmountValues>; // relayer/provider fee in native units\n /**\n * The total network fee required to submit the trade and any approvals. This includes\n * the relayer fee or other native fees. Should be used for balance checks and tx submission.\n * Note: This is only accurate for non-gasless transactions. Use {@link QuoteMetadata.includedTxFees} to\n * get the total network fee for gasless transactions.\n */\n totalNetworkFee: TokenAmountValues; // gasFee.total + relayerFee\n /**\n * The amount that the user will receive (destTokenAmount)\n */\n toTokenAmount: TokenAmountValues;\n /**\n * The minimum amount that the user will receive (minDestTokenAmount)\n */\n minToTokenAmount: TokenAmountValues;\n /**\n * If gas is included: {@link QuoteMetadata.toTokenAmount} - {@link QuoteMetadata.includedTxFees}.\n * Otherwise: {@link QuoteMetadata.toTokenAmount} - {@link QuoteMetadata.totalNetworkFee}.\n */\n adjustedReturn: Omit<TokenAmountValues, 'amount'>;\n /**\n * The amount that the user will send, including fees that are paid in the src token\n * {@link Quote.srcTokenAmount} + {@link Quote.feeData[FeeType.METABRIDGE].amount} + {@link Quote.feeData[FeeType.TX_FEE].amount}\n */\n sentAmount: TokenAmountValues;\n /**\n * The swap rate is the amount that the user will receive per amount sent. Accounts for fees paid in the src or dest token.\n * This is calculated as {@link QuoteMetadata.toTokenAmount} / {@link QuoteMetadata.sentAmount}.\n */\n swapRate: string;\n /**\n * The cost of the trade, which is the difference between the amount sent and the adjusted return.\n * This is calculated as {@link QuoteMetadata.sentAmount} - {@link QuoteMetadata.adjustedReturn}.\n */\n cost: Omit<TokenAmountValues, 'amount'>; // sentAmount - adjustedReturn\n\n /**\n * The price impact for the quote.\n */\n priceImpact: Omit<TokenAmountValues, 'amount'>; // abs(sentAmount - toTokenAmount);\n};\n\nexport type QuoteMetadata = DeepPartial<QuoteMetadataV1>;\n"]}
|
|
1
|
+
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../../../src/utils/quote-metadata/types.ts"],"names":[],"mappings":"AA+FA,MAAM,CAAC,MAAM,2BAA2B,GAAG;IACzC;;;OAGG;IACH,MAAM,EAAE,GAAG;IACX;;OAEG;IACH,gBAAgB,EAAE,KAAK;IACvB;;OAEG;IACH,MAAM,EAAE,GAAG;CACH,CAAC","sourcesContent":["import type { DeepPartial } from '../../types.js';\n\n/**\n * The types of values for the token amount and its values when converted to the user's selected currency and USD\n */\nexport type TokenAmountValues = {\n /**\n * The amount of the token\n *\n * @example \"1.005\"\n */\n amount: string;\n /**\n * The amount of the token in the user's selected currency\n *\n * @example \"4.55\"\n */\n valueInCurrency: string;\n /**\n * The amount of the token in USD\n *\n * @example \"1.234\"\n */\n usd: string;\n};\n\n/**\n * Values derived from the quote response\n *\n * @deprecated Avoid introducing new usages and use the QuoteResponse V2 type instead\n */\ntype QuoteMetadataV1 = {\n /**\n * If gas is included, this is the value of the src or dest token that was used to pay for the gas.\n * Show this value to indicate transaction fees for gasless quotes.\n */\n includedTxFees?: Partial<TokenAmountValues>;\n /**\n * The gas fee for the bridge transaction.\n * effective is the gas fee that is shown to the user. If this value is not\n * included in the trade, the calculation falls back to the gasLimit (total)\n * total is the gas fee that is spent by the user, including refunds.\n * max is the max gas fee that will be used by the transaction.\n */\n gasFee: Record<'total', TokenAmountValues>;\n relayerFee?: Partial<TokenAmountValues>; // relayer/provider fee in native units\n /**\n * The total network fee required to submit the trade and any approvals. This includes\n * the relayer fee or other native fees. Should be used for balance checks and tx submission.\n * Note: This is only accurate for non-gasless transactions. Use {@link QuoteMetadata.includedTxFees} to\n * get the total network fee for gasless transactions.\n */\n totalNetworkFee: TokenAmountValues; // gasFee.total + relayerFee\n /**\n * The amount that the user will receive (destTokenAmount)\n */\n toTokenAmount: TokenAmountValues;\n /**\n * The minimum amount that the user will receive (minDestTokenAmount)\n */\n minToTokenAmount: TokenAmountValues;\n /**\n * If gas is included: {@link QuoteMetadata.toTokenAmount} - {@link QuoteMetadata.includedTxFees}.\n * Otherwise: {@link QuoteMetadata.toTokenAmount} - {@link QuoteMetadata.totalNetworkFee}.\n */\n adjustedReturn: Omit<TokenAmountValues, 'amount'>;\n /**\n * The amount that the user will send, including fees that are paid in the src token\n * {@link Quote.srcTokenAmount} + {@link Quote.feeData[FeeType.METABRIDGE].amount} + {@link Quote.feeData[FeeType.TX_FEE].amount}\n */\n sentAmount: TokenAmountValues;\n /**\n * The swap rate is the amount that the user will receive per amount sent. Accounts for fees paid in the src or dest token.\n * This is calculated as {@link QuoteMetadata.toTokenAmount} / {@link QuoteMetadata.sentAmount}.\n */\n swapRate: string;\n /**\n * The cost of the trade, which is the difference between the amount sent and the adjusted return.\n * This is calculated as {@link QuoteMetadata.sentAmount} - {@link QuoteMetadata.adjustedReturn}.\n */\n cost: Omit<TokenAmountValues, 'amount'>; // sentAmount - adjustedReturn\n\n /**\n * The price impact for the quote.\n */\n priceImpact: Omit<TokenAmountValues, 'amount'>; // abs(sentAmount - toTokenAmount);\n};\n\n/**\n * The partial legacy quote metadata\n *\n * @deprecated Avoid introducing new usages and use the nested QuoteResponse metadata instead\n */\nexport type QuoteMetadata = DeepPartial<QuoteMetadataV1>;\n\nexport const QuoteMetadataMigrationPhase = {\n /**\n * Phase 1: omit API V2 currency metadata; serve legacy calcQuoteMetadata\n * into V2 nested shape\n */\n V1Data: '1',\n /**\n * Phase 1.5: prefer API V2 metadata (+ fiat from usd); fall back to legacy.\n */\n V2WithV1Fallback: '1.5',\n /**\n * Phase 2: API V2 metadata only; legacy metadata utils can be removed.\n */\n V2Only: '2',\n} as const;\n\nexport type QuoteMetadataMigrationPhase =\n (typeof QuoteMetadataMigrationPhase)[keyof typeof QuoteMetadataMigrationPhase];\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateQuoteResponse = exports.QuoteResponseSchemaV2 = void 0;
|
|
3
|
+
exports.isQuoteResponseV2 = exports.validateQuoteResponse = exports.QuoteResponseSchemaV2 = void 0;
|
|
4
4
|
const superstruct_1 = require("@metamask/superstruct");
|
|
5
5
|
const utils_1 = require("@metamask/utils");
|
|
6
6
|
const feature_flags_js_1 = require("./feature-flags.cjs");
|
|
@@ -113,4 +113,17 @@ const validateQuoteResponse = (quoteResponse) => {
|
|
|
113
113
|
return true;
|
|
114
114
|
};
|
|
115
115
|
exports.validateQuoteResponse = validateQuoteResponse;
|
|
116
|
+
/**
|
|
117
|
+
* Shallow check for the presence of the `src` property
|
|
118
|
+
*
|
|
119
|
+
* @param quote - The quote to check
|
|
120
|
+
* @returns True if the quote is a V2 quote, false otherwise
|
|
121
|
+
*/
|
|
122
|
+
const isQuoteResponseV2 = (quote) => {
|
|
123
|
+
if (!quote?.quote) {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
return Object.prototype.hasOwnProperty.call(quote.quote, 'src');
|
|
127
|
+
};
|
|
128
|
+
exports.isQuoteResponseV2 = isQuoteResponseV2;
|
|
116
129
|
//# sourceMappingURL=quote-response.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quote-response.cjs","sourceRoot":"","sources":["../../src/validators/quote-response.ts"],"names":[],"mappings":";;;AAAA,uDAc+B;AAC/B,2CAMyB;AAEzB,0DAA+C;AAC/C,4CAAgD;AAChD,0CAA2C;AAC3C,0CASoB;AAEpB,MAAM,yBAAyB,GAAG,IAAA,kBAAI,EAAC;IACrC,OAAO,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;IAC3B,KAAK,EAAE,wBAAa;IACpB,gCAAgC,EAAE,IAAA,oBAAM,GAAE;IAC1C;;;OAGG;IACH,iBAAiB,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;IACrC;;OAEG;IACH,SAAS,EAAE,IAAA,sBAAQ,EAAC,IAAA,mBA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AA,0BAAkB,EAAC,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC9D,MAAM,SAAS,GAAG,eAA6C,CAAC;IAEhE,IAAI,CAAC,yBAAyB,CAAC,SAAS,CAAC,EAAE,CAAC;QAC1C,OAAO,KAAK,CAAC;IACf,CAAC;IAED,4EAA4E;IAC5E,IAAA,oBAAM,EACJ;QACE,GAAG,aAAa;QAChB,SAAS;QACT,OAAO;KACR,EACD,yBAAyB,CAAC,SAAS,CAAC,CACrC,CAAC;IACF,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AA3BW,QAAA,qBAAqB,yBA2BhC","sourcesContent":["import {\n assert,\n Infer,\n number,\n optional,\n string,\n type,\n union,\n intersection,\n Describe,\n nullable,\n enums,\n literal,\n AnyStruct,\n} from '@metamask/superstruct';\nimport {\n CaipChainId,\n CaipChainIdStruct,\n KnownCaipNamespace,\n parseCaipAssetType,\n StrictHexStruct,\n} from '@metamask/utils';\n\nimport { FeatureId } from './feature-flags.js';\nimport { FloatStringSchema } from './number.js';\nimport { QuoteSchemaV2 } from './quote.js';\nimport {\n BitcoinTradeData,\n BitcoinTradeDataSchema,\n StellarTradeData,\n StellarTradeDataSchema,\n TronTradeData,\n TronTradeDataSchema,\n TxData,\n TxDataSchema,\n} from './trade.js';\n\nconst CommonQuoteResponseSchema = type({\n quoteId: optional(string()),\n quote: QuoteSchemaV2,\n estimatedProcessingTimeInSeconds: number(),\n /**\n * Appended to the quote if there are multiple quote requests in a batch. This\n * indicates which quoteRequest the quote is for\n */\n quoteRequestIndex: optional(number()),\n /**\n * Appended to the quote response based on the quote requested featureId\n */\n featureId: optional(enums(Object.values(FeatureId))),\n /**\n * Appended to the quote response based on the quote request nonEvmFeesInNative flag\n *\n * @deprecated Use network feeData\n */\n nonEvmFeesInNative: optional(FloatStringSchema),\n /**\n * Appended to the quote response based on the quote request l1GasFeesInHexWei flag\n *\n * @deprecated Use network feeData\n */\n l1GasFeesInHexWei: optional(StrictHexStruct),\n});\n\nconst EvmQuoteResponseSchema = intersection([\n CommonQuoteResponseSchema,\n type({\n namespace: literal(KnownCaipNamespace.Eip155),\n chainId: CaipChainIdStruct,\n trade: TxDataSchema,\n approval: optional(TxDataSchema),\n resetApproval: optional(TxDataSchema),\n }),\n]);\n\nconst TronQuoteResponseSchema = intersection([\n CommonQuoteResponseSchema,\n type({\n namespace: literal(KnownCaipNamespace.Tron),\n chainId: CaipChainIdStruct,\n trade: TronTradeDataSchema,\n approval: optional(TronTradeDataSchema),\n }),\n]);\n\nconst SolanaQuoteResponseSchema = intersection([\n CommonQuoteResponseSchema,\n type({\n namespace: literal(KnownCaipNamespace.Solana),\n chainId: CaipChainIdStruct,\n trade: string(),\n approval: optional(TxDataSchema),\n }),\n]);\n\nconst BitcoinQuoteResponseSchema = intersection([\n CommonQuoteResponseSchema,\n type({\n namespace: literal(KnownCaipNamespace.Bip122),\n chainId: CaipChainIdStruct,\n trade: BitcoinTradeDataSchema,\n approval: optional(TxDataSchema),\n }),\n]);\n\nconst StellarQuoteResponseSchema = intersection([\n CommonQuoteResponseSchema,\n type({\n namespace: literal(KnownCaipNamespace.Stellar),\n chainId: CaipChainIdStruct,\n trade: StellarTradeDataSchema,\n approval: optional(TxDataSchema),\n }),\n]);\n\nexport const QuoteResponseSchemaV2 = nullable(\n union([\n EvmQuoteResponseSchema,\n SolanaQuoteResponseSchema,\n TronQuoteResponseSchema,\n BitcoinQuoteResponseSchema,\n StellarQuoteResponseSchema,\n ]),\n);\n\n/**\n * This is the V2 QuoteResponse type, including metadata calculated after quote fetch\n */\nexport type QuoteResponse = Omit<\n NonNullable<Infer<typeof QuoteResponseSchemaV2>>,\n 'trade' | 'approval' | 'resetApproval'\n> &\n (\n | {\n namespace: KnownCaipNamespace.Eip155;\n chainId: CaipChainId;\n trade: TxData & {\n data: string;\n };\n approval?: TxData;\n /**\n * Appended to the quote response based on the quote request resetApproval flag\n * If defined, the quote's total network fee will include the reset approval's gas limit.\n */\n resetApproval?: TxData;\n }\n | {\n namespace: KnownCaipNamespace.Solana;\n chainId: CaipChainId;\n trade: string;\n approval?: TxData;\n }\n | {\n namespace: KnownCaipNamespace.Tron;\n chainId: CaipChainId;\n trade: TronTradeData & {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n raw_data_hex: string;\n };\n approval?: TronTradeData;\n }\n | {\n namespace: KnownCaipNamespace.Bip122;\n chainId: CaipChainId;\n trade: BitcoinTradeData;\n approval?: TxData;\n }\n | {\n namespace: KnownCaipNamespace.Stellar;\n chainId: CaipChainId;\n trade: StellarTradeData;\n approval?: TxData;\n }\n );\n// This ensures the QuoteResponse type is in sync with the QuoteResponseSchemaV2\nconst QuoteResponse: Describe<QuoteResponse | null> = QuoteResponseSchemaV2;\n\nconst NAMESPACE_TO_TRADE_SCHEMA: Record<QuoteResponse['namespace'], AnyStruct> =\n {\n [KnownCaipNamespace.Eip155]: EvmQuoteResponseSchema,\n [KnownCaipNamespace.Tron]: TronQuoteResponseSchema,\n [KnownCaipNamespace.Solana]: SolanaQuoteResponseSchema,\n [KnownCaipNamespace.Bip122]: BitcoinQuoteResponseSchema,\n [KnownCaipNamespace.Stellar]: StellarQuoteResponseSchema,\n };\n\nexport const validateQuoteResponse = (\n quoteResponse: unknown,\n): quoteResponse is QuoteResponse => {\n // Validate common fields first\n assert(quoteResponse, CommonQuoteResponseSchema);\n\n // Extract the namespace and chainId from the src asset\n const {\n chain: { namespace: namespaceString },\n chainId,\n } = parseCaipAssetType(quoteResponse.quote.src.asset.assetId);\n const namespace = namespaceString as QuoteResponse['namespace'];\n\n if (!NAMESPACE_TO_TRADE_SCHEMA[namespace]) {\n return false;\n }\n\n // Validate the trade and approval fields based on the src chain's namespace\n assert(\n {\n ...quoteResponse,\n namespace,\n chainId,\n },\n NAMESPACE_TO_TRADE_SCHEMA[namespace],\n );\n return true;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"quote-response.cjs","sourceRoot":"","sources":["../../src/validators/quote-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B,CAAC,IAAI,CAAC,EAAE,uBAAuB;IAClD,CAAC,0BAAkB,CAAC,MAAM,CAAC,EAAE,yBAAyB;IACtD,CAAC,0BAAkB,CAAC,MAAM,CAAC,EAAE,0BAA0B;IACvD,CAAC,0BAAkB,CAAC,OAAO,CAAC,EAAE,0BAA0B;CACzD,CAAC;AAEG,MAAM,qBAAqB,GAAG,CACnC,aAAsB,EACU,EAAE;IAClC,+BAA+B;IAC/B,IAAA,oBAAM,EAAC,aAAa,EAAE,yBAAyB,CAAC,CAAC;IAEjD,uDAAuD;IACvD,MAAM,EACJ,KAAK,EAAE,EAAE,SAAS,EAAE,eAAe,EAAE,EACrC,OAAO,GACR,GAAG,IAAA,0BAAkB,EAAC,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC9D,MAAM,SAAS,GAAG,eAA6C,CAAC;IAEhE,IAAI,CAAC,yBAAyB,CAAC,SAAS,CAAC,EAAE,CAAC;QAC1C,OAAO,KAAK,CAAC;IACf,CAAC;IAED,4EAA4E;IAC5E,IAAA,oBAAM,EACJ;QACE,GAAG,aAAa;QAChB,SAAS;QACT,OAAO;KACR,EACD,yBAAyB,CAAC,SAAS,CAAC,CACrC,CAAC;IACF,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AA3BW,QAAA,qBAAqB,yBA2BhC;AAEF;;;;;GAKG;AACI,MAAM,iBAAiB,GAAG,CAC/B,KAA4C,EACpB,EAAE;IAC1B,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,CAAC;QAClB,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AAClE,CAAC,CAAC;AAPW,QAAA,iBAAiB,qBAO5B","sourcesContent":["import {\n assert,\n Infer,\n number,\n optional,\n string,\n type,\n union,\n intersection,\n Describe,\n nullable,\n enums,\n literal,\n AnyStruct,\n} from '@metamask/superstruct';\nimport {\n CaipChainId,\n CaipChainIdStruct,\n KnownCaipNamespace,\n parseCaipAssetType,\n StrictHexStruct,\n} from '@metamask/utils';\n\nimport { FeatureId } from './feature-flags.js';\nimport { FloatStringSchema } from './number.js';\nimport { QuoteSchemaV2 } from './quote.js';\nimport {\n BitcoinTradeData,\n BitcoinTradeDataSchema,\n StellarTradeData,\n StellarTradeDataSchema,\n TronTradeData,\n TronTradeDataSchema,\n TxData,\n TxDataSchema,\n} from './trade.js';\n\nconst CommonQuoteResponseSchema = type({\n quoteId: optional(string()),\n quote: QuoteSchemaV2,\n estimatedProcessingTimeInSeconds: number(),\n /**\n * Appended to the quote if there are multiple quote requests in a batch. This\n * indicates which quoteRequest the quote is for\n */\n quoteRequestIndex: optional(number()),\n /**\n * Appended to the quote response based on the quote requested featureId\n */\n featureId: optional(enums(Object.values(FeatureId))),\n /**\n * Appended to the quote response based on the quote request nonEvmFeesInNative flag\n *\n * @deprecated Use network feeData\n */\n nonEvmFeesInNative: optional(FloatStringSchema),\n /**\n * Appended to the quote response based on the quote request l1GasFeesInHexWei flag\n *\n * @deprecated Use network feeData\n */\n l1GasFeesInHexWei: optional(StrictHexStruct),\n});\n\nconst EvmQuoteResponseSchema = intersection([\n CommonQuoteResponseSchema,\n type({\n namespace: literal(KnownCaipNamespace.Eip155),\n chainId: CaipChainIdStruct,\n trade: TxDataSchema,\n approval: optional(TxDataSchema),\n resetApproval: optional(TxDataSchema),\n }),\n]);\n\nconst TronQuoteResponseSchema = intersection([\n CommonQuoteResponseSchema,\n type({\n namespace: literal(KnownCaipNamespace.Tron),\n chainId: CaipChainIdStruct,\n trade: TronTradeDataSchema,\n approval: optional(TronTradeDataSchema),\n }),\n]);\n\nconst SolanaQuoteResponseSchema = intersection([\n CommonQuoteResponseSchema,\n type({\n namespace: literal(KnownCaipNamespace.Solana),\n chainId: CaipChainIdStruct,\n trade: string(),\n approval: optional(TxDataSchema),\n }),\n]);\n\nconst BitcoinQuoteResponseSchema = intersection([\n CommonQuoteResponseSchema,\n type({\n namespace: literal(KnownCaipNamespace.Bip122),\n chainId: CaipChainIdStruct,\n trade: BitcoinTradeDataSchema,\n approval: optional(TxDataSchema),\n }),\n]);\n\nconst StellarQuoteResponseSchema = intersection([\n CommonQuoteResponseSchema,\n type({\n namespace: literal(KnownCaipNamespace.Stellar),\n chainId: CaipChainIdStruct,\n trade: StellarTradeDataSchema,\n approval: optional(TxDataSchema),\n }),\n]);\n\nexport const QuoteResponseSchemaV2 = nullable(\n union([\n EvmQuoteResponseSchema,\n SolanaQuoteResponseSchema,\n TronQuoteResponseSchema,\n BitcoinQuoteResponseSchema,\n StellarQuoteResponseSchema,\n ]),\n);\n\n/**\n * This is the V2 QuoteResponse type, including metadata calculated after quote fetch\n */\nexport type QuoteResponse = Omit<\n NonNullable<Infer<typeof QuoteResponseSchemaV2>>,\n 'trade' | 'approval' | 'resetApproval'\n> &\n (\n | {\n namespace: KnownCaipNamespace.Eip155;\n chainId: CaipChainId;\n trade: TxData & {\n data: string;\n };\n approval?: TxData;\n /**\n * Appended to the quote response based on the quote request resetApproval flag\n * If defined, the quote's total network fee will include the reset approval's gas limit.\n */\n resetApproval?: TxData;\n }\n | {\n namespace: KnownCaipNamespace.Solana;\n chainId: CaipChainId;\n trade: string;\n approval?: TxData;\n }\n | {\n namespace: KnownCaipNamespace.Tron;\n chainId: CaipChainId;\n trade: TronTradeData & {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n raw_data_hex: string;\n };\n approval?: TronTradeData;\n }\n | {\n namespace: KnownCaipNamespace.Bip122;\n chainId: CaipChainId;\n trade: BitcoinTradeData;\n approval?: TxData;\n }\n | {\n namespace: KnownCaipNamespace.Stellar;\n chainId: CaipChainId;\n trade: StellarTradeData;\n approval?: TxData;\n }\n );\n// This ensures the QuoteResponse type is in sync with the QuoteResponseSchemaV2\nconst QuoteResponse: Describe<QuoteResponse | null> = QuoteResponseSchemaV2;\n\nconst NAMESPACE_TO_TRADE_SCHEMA: Record<QuoteResponse['namespace'], AnyStruct> =\n {\n [KnownCaipNamespace.Eip155]: EvmQuoteResponseSchema,\n [KnownCaipNamespace.Tron]: TronQuoteResponseSchema,\n [KnownCaipNamespace.Solana]: SolanaQuoteResponseSchema,\n [KnownCaipNamespace.Bip122]: BitcoinQuoteResponseSchema,\n [KnownCaipNamespace.Stellar]: StellarQuoteResponseSchema,\n };\n\nexport const validateQuoteResponse = (\n quoteResponse: unknown,\n): quoteResponse is QuoteResponse => {\n // Validate common fields first\n assert(quoteResponse, CommonQuoteResponseSchema);\n\n // Extract the namespace and chainId from the src asset\n const {\n chain: { namespace: namespaceString },\n chainId,\n } = parseCaipAssetType(quoteResponse.quote.src.asset.assetId);\n const namespace = namespaceString as QuoteResponse['namespace'];\n\n if (!NAMESPACE_TO_TRADE_SCHEMA[namespace]) {\n return false;\n }\n\n // Validate the trade and approval fields based on the src chain's namespace\n assert(\n {\n ...quoteResponse,\n namespace,\n chainId,\n },\n NAMESPACE_TO_TRADE_SCHEMA[namespace],\n );\n return true;\n};\n\n/**\n * Shallow check for the presence of the `src` property\n *\n * @param quote - The quote to check\n * @returns True if the quote is a V2 quote, false otherwise\n */\nexport const isQuoteResponseV2 = (\n quote: { quote?: object } | null | undefined,\n): quote is QuoteResponse => {\n if (!quote?.quote) {\n return false;\n }\n return Object.prototype.hasOwnProperty.call(quote.quote, 'src');\n};\n"]}
|
|
@@ -1961,4 +1961,13 @@ export type QuoteResponse = Omit<NonNullable<Infer<typeof QuoteResponseSchemaV2>
|
|
|
1961
1961
|
approval?: TxData;
|
|
1962
1962
|
});
|
|
1963
1963
|
export declare const validateQuoteResponse: (quoteResponse: unknown) => quoteResponse is QuoteResponse;
|
|
1964
|
+
/**
|
|
1965
|
+
* Shallow check for the presence of the `src` property
|
|
1966
|
+
*
|
|
1967
|
+
* @param quote - The quote to check
|
|
1968
|
+
* @returns True if the quote is a V2 quote, false otherwise
|
|
1969
|
+
*/
|
|
1970
|
+
export declare const isQuoteResponseV2: (quote: {
|
|
1971
|
+
quote?: object | undefined;
|
|
1972
|
+
} | null | undefined) => quote is QuoteResponse;
|
|
1964
1973
|
//# sourceMappingURL=quote-response.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quote-response.d.cts","sourceRoot":"","sources":["../../src/validators/quote-response.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,EAYN,8BAA8B;AAC/B,OAAO,EACL,WAAW,EAEX,kBAAkB,EAGnB,wBAAwB;AAEzB,OAAO,EAAE,SAAS,EAAE,4BAA2B;AAG/C,OAAO,EACL,gBAAgB,EAEhB,gBAAgB,EAEhB,aAAa,EAEb,MAAM,EAEP,oBAAmB;AAgFpB,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,EAAE,gBAAgB,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,GACD;IACE,SAAS,EAAE,kBAAkB,CAAC,OAAO,CAAC;IACtC,OAAO,EAAE,WAAW,CAAC;IACrB,KAAK,EAAE,gBAAgB,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CACJ,CAAC;AAaJ,eAAO,MAAM,qBAAqB,kBACjB,OAAO,mCA0BvB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB;;+CAO7B,CAAC"}
|
|
@@ -1961,4 +1961,13 @@ export type QuoteResponse = Omit<NonNullable<Infer<typeof QuoteResponseSchemaV2>
|
|
|
1961
1961
|
approval?: TxData;
|
|
1962
1962
|
});
|
|
1963
1963
|
export declare const validateQuoteResponse: (quoteResponse: unknown) => quoteResponse is QuoteResponse;
|
|
1964
|
+
/**
|
|
1965
|
+
* Shallow check for the presence of the `src` property
|
|
1966
|
+
*
|
|
1967
|
+
* @param quote - The quote to check
|
|
1968
|
+
* @returns True if the quote is a V2 quote, false otherwise
|
|
1969
|
+
*/
|
|
1970
|
+
export declare const isQuoteResponseV2: (quote: {
|
|
1971
|
+
quote?: object | undefined;
|
|
1972
|
+
} | null | undefined) => quote is QuoteResponse;
|
|
1964
1973
|
//# sourceMappingURL=quote-response.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quote-response.d.mts","sourceRoot":"","sources":["../../src/validators/quote-response.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,EAYN,8BAA8B;AAC/B,OAAO,EACL,WAAW,EAEX,kBAAkB,EAGnB,wBAAwB;AAEzB,OAAO,EAAE,SAAS,EAAE,4BAA2B;AAG/C,OAAO,EACL,gBAAgB,EAEhB,gBAAgB,EAEhB,aAAa,EAEb,MAAM,EAEP,oBAAmB;AAgFpB,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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M,CAAC;IACrC,OAAO,EAAE,WAAW,CAAC;IACrB,KAAK,EAAE,MAAM,GAAG;QACd,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;IACF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,GACD;IACE,SAAS,EAAE,kBAAkB,CAAC,MAAM,CAAC;IACrC,OAAO,EAAE,WAAW,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,GACD;IACE,SAAS,EAAE,kBAAkB,CAAC,IAAI,CAAC;IACnC,OAAO,EAAE,WAAW,CAAC;IACrB,KAAK,EAAE,aAAa,GAAG;QAErB,YAAY,EAAE,MAAM,CAAC;KACtB,CAAC;IACF,QAAQ,CAAC,EAAE,aAAa,CAAC;CAC1B,GACD;IACE,SAAS,EAAE,kBAAkB,CAAC,MAAM,CAAC;IACrC,OAAO,EAAE,WAAW,CAAC;IACrB,KAAK,EAAE,gBAAgB,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,GACD;IACE,SAAS,EAAE,kBAAkB,CAAC,OAAO,CAAC;IACtC,OAAO,EAAE,WAAW,CAAC;IACrB,KAAK,EAAE,gBAAgB,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CACJ,CAAC;AAaJ,eAAO,MAAM,qBAAqB,kBACjB,OAAO,mCA0BvB,CAAC"}
|
|
1
|
+
{"version":3,"file":"quote-response.d.mts","sourceRoot":"","sources":["../../src/validators/quote-response.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,EAYN,8BAA8B;AAC/B,OAAO,EACL,WAAW,EAEX,kBAAkB,EAGnB,wBAAwB;AAEzB,OAAO,EAAE,SAAS,EAAE,4BAA2B;AAG/C,OAAO,EACL,gBAAgB,EAEhB,gBAAgB,EAEhB,aAAa,EAEb,MAAM,EAEP,oBAAmB;AAgFpB,eA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UAAU,GAAG,eAAe,CACvC,GACC,CACI;IACE,SAAS,EAAE,kBAAkB,CAAC,MAAM,CAAC;IACrC,OAAO,EAAE,WAAW,CAAC;IACrB,KAAK,EAAE,MAAM,GAAG;QACd,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;IACF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,GACD;IACE,SAAS,EAAE,kBAAkB,CAAC,MAAM,CAAC;IACrC,OAAO,EAAE,WAAW,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,GACD;IACE,SAAS,EAAE,kBAAkB,CAAC,IAAI,CAAC;IACnC,OAAO,EAAE,WAAW,CAAC;IACrB,KAAK,EAAE,aAAa,GAAG;QAErB,YAAY,EAAE,MAAM,CAAC;KACtB,CAAC;IACF,QAAQ,CAAC,EAAE,aAAa,CAAC;CAC1B,GACD;IACE,SAAS,EAAE,kBAAkB,CAAC,MAAM,CAAC;IACrC,OAAO,EAAE,WAAW,CAAC;IACrB,KAAK,EAAE,gBAAgB,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,GACD;IACE,SAAS,EAAE,kBAAkB,CAAC,OAAO,CAAC;IACtC,OAAO,EAAE,WAAW,CAAC;IACrB,KAAK,EAAE,gBAAgB,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CACJ,CAAC;AAaJ,eAAO,MAAM,qBAAqB,kBACjB,OAAO,mCA0BvB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB;;+CAO7B,CAAC"}
|
|
@@ -109,4 +109,16 @@ export const validateQuoteResponse = (quoteResponse) => {
|
|
|
109
109
|
}, NAMESPACE_TO_TRADE_SCHEMA[namespace]);
|
|
110
110
|
return true;
|
|
111
111
|
};
|
|
112
|
+
/**
|
|
113
|
+
* Shallow check for the presence of the `src` property
|
|
114
|
+
*
|
|
115
|
+
* @param quote - The quote to check
|
|
116
|
+
* @returns True if the quote is a V2 quote, false otherwise
|
|
117
|
+
*/
|
|
118
|
+
export const isQuoteResponseV2 = (quote) => {
|
|
119
|
+
if (!quote?.quote) {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
return Object.prototype.hasOwnProperty.call(quote.quote, 'src');
|
|
123
|
+
};
|
|
112
124
|
//# sourceMappingURL=quote-response.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quote-response.mjs","sourceRoot":"","sources":["../../src/validators/quote-response.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EAEN,MAAM,EACN,QAAQ,EACR,MAAM,EACN,IAAI,EACJ,KAAK,EACL,YAAY,EAEZ,QAAQ,EACR,KAAK,EACL,OAAO,EAER,8BAA8B;AAC/B,OAAO,EAEL,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,eAAe,EAChB,wBAAwB;AAEzB,OAAO,EAAE,SAAS,EAAE,4BAA2B;AAC/C,OAAO,EAAE,iBAAiB,EAAE,qBAAoB;AAChD,OAAO,EAAE,aAAa,EAAE,oBAAmB;AAC3C,OAAO,EAEL,sBAAsB,EAEtB,sBAAsB,EAEtB,mBAAmB,EAEnB,YAAY,EACb,oBAAmB;AAEpB,MAAM,yBAAyB,GAAG,IAAI,CAAC;IACrC,OAAO,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC;IAC3B,KAAK,EAAE,aAAa;IACpB,gCAAgC,EAAE,MAAM,EAAE;IAC1C;;;OAGG;IACH,iBAAiB,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC;IACrC;;OAEG;IACH,SAAS,EAAE,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC;IACpD;;;;OAIG;IACH,kBAAkB,EAAE,QAAQ,CAAC,iBAAiB,CAAC;IAC/C;;;;OAIG;IACH,iBAA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AAC;IACF,OAAO,IAAI,CAAC;AACd,CAAC,CAAC","sourcesContent":["import {\n assert,\n Infer,\n number,\n optional,\n string,\n type,\n union,\n intersection,\n Describe,\n nullable,\n enums,\n literal,\n AnyStruct,\n} from '@metamask/superstruct';\nimport {\n CaipChainId,\n CaipChainIdStruct,\n KnownCaipNamespace,\n parseCaipAssetType,\n StrictHexStruct,\n} from '@metamask/utils';\n\nimport { FeatureId } from './feature-flags.js';\nimport { FloatStringSchema } from './number.js';\nimport { QuoteSchemaV2 } from './quote.js';\nimport {\n BitcoinTradeData,\n BitcoinTradeDataSchema,\n StellarTradeData,\n StellarTradeDataSchema,\n TronTradeData,\n TronTradeDataSchema,\n TxData,\n TxDataSchema,\n} from './trade.js';\n\nconst CommonQuoteResponseSchema = type({\n quoteId: optional(string()),\n quote: QuoteSchemaV2,\n estimatedProcessingTimeInSeconds: number(),\n /**\n * Appended to the quote if there are multiple quote requests in a batch. This\n * indicates which quoteRequest the quote is for\n */\n quoteRequestIndex: optional(number()),\n /**\n * Appended to the quote response based on the quote requested featureId\n */\n featureId: optional(enums(Object.values(FeatureId))),\n /**\n * Appended to the quote response based on the quote request nonEvmFeesInNative flag\n *\n * @deprecated Use network feeData\n */\n nonEvmFeesInNative: optional(FloatStringSchema),\n /**\n * Appended to the quote response based on the quote request l1GasFeesInHexWei flag\n *\n * @deprecated Use network feeData\n */\n l1GasFeesInHexWei: optional(StrictHexStruct),\n});\n\nconst EvmQuoteResponseSchema = intersection([\n CommonQuoteResponseSchema,\n type({\n namespace: literal(KnownCaipNamespace.Eip155),\n chainId: CaipChainIdStruct,\n trade: TxDataSchema,\n approval: optional(TxDataSchema),\n resetApproval: optional(TxDataSchema),\n }),\n]);\n\nconst TronQuoteResponseSchema = intersection([\n CommonQuoteResponseSchema,\n type({\n namespace: literal(KnownCaipNamespace.Tron),\n chainId: CaipChainIdStruct,\n trade: TronTradeDataSchema,\n approval: optional(TronTradeDataSchema),\n }),\n]);\n\nconst SolanaQuoteResponseSchema = intersection([\n CommonQuoteResponseSchema,\n type({\n namespace: literal(KnownCaipNamespace.Solana),\n chainId: CaipChainIdStruct,\n trade: string(),\n approval: optional(TxDataSchema),\n }),\n]);\n\nconst BitcoinQuoteResponseSchema = intersection([\n CommonQuoteResponseSchema,\n type({\n namespace: literal(KnownCaipNamespace.Bip122),\n chainId: CaipChainIdStruct,\n trade: BitcoinTradeDataSchema,\n approval: optional(TxDataSchema),\n }),\n]);\n\nconst StellarQuoteResponseSchema = intersection([\n CommonQuoteResponseSchema,\n type({\n namespace: literal(KnownCaipNamespace.Stellar),\n chainId: CaipChainIdStruct,\n trade: StellarTradeDataSchema,\n approval: optional(TxDataSchema),\n }),\n]);\n\nexport const QuoteResponseSchemaV2 = nullable(\n union([\n EvmQuoteResponseSchema,\n SolanaQuoteResponseSchema,\n TronQuoteResponseSchema,\n BitcoinQuoteResponseSchema,\n StellarQuoteResponseSchema,\n ]),\n);\n\n/**\n * This is the V2 QuoteResponse type, including metadata calculated after quote fetch\n */\nexport type QuoteResponse = Omit<\n NonNullable<Infer<typeof QuoteResponseSchemaV2>>,\n 'trade' | 'approval' | 'resetApproval'\n> &\n (\n | {\n namespace: KnownCaipNamespace.Eip155;\n chainId: CaipChainId;\n trade: TxData & {\n data: string;\n };\n approval?: TxData;\n /**\n * Appended to the quote response based on the quote request resetApproval flag\n * If defined, the quote's total network fee will include the reset approval's gas limit.\n */\n resetApproval?: TxData;\n }\n | {\n namespace: KnownCaipNamespace.Solana;\n chainId: CaipChainId;\n trade: string;\n approval?: TxData;\n }\n | {\n namespace: KnownCaipNamespace.Tron;\n chainId: CaipChainId;\n trade: TronTradeData & {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n raw_data_hex: string;\n };\n approval?: TronTradeData;\n }\n | {\n namespace: KnownCaipNamespace.Bip122;\n chainId: CaipChainId;\n trade: BitcoinTradeData;\n approval?: TxData;\n }\n | {\n namespace: KnownCaipNamespace.Stellar;\n chainId: CaipChainId;\n trade: StellarTradeData;\n approval?: TxData;\n }\n );\n// This ensures the QuoteResponse type is in sync with the QuoteResponseSchemaV2\nconst QuoteResponse: Describe<QuoteResponse | null> = QuoteResponseSchemaV2;\n\nconst NAMESPACE_TO_TRADE_SCHEMA: Record<QuoteResponse['namespace'], AnyStruct> =\n {\n [KnownCaipNamespace.Eip155]: EvmQuoteResponseSchema,\n [KnownCaipNamespace.Tron]: TronQuoteResponseSchema,\n [KnownCaipNamespace.Solana]: SolanaQuoteResponseSchema,\n [KnownCaipNamespace.Bip122]: BitcoinQuoteResponseSchema,\n [KnownCaipNamespace.Stellar]: StellarQuoteResponseSchema,\n };\n\nexport const validateQuoteResponse = (\n quoteResponse: unknown,\n): quoteResponse is QuoteResponse => {\n // Validate common fields first\n assert(quoteResponse, CommonQuoteResponseSchema);\n\n // Extract the namespace and chainId from the src asset\n const {\n chain: { namespace: namespaceString },\n chainId,\n } = parseCaipAssetType(quoteResponse.quote.src.asset.assetId);\n const namespace = namespaceString as QuoteResponse['namespace'];\n\n if (!NAMESPACE_TO_TRADE_SCHEMA[namespace]) {\n return false;\n }\n\n // Validate the trade and approval fields based on the src chain's namespace\n assert(\n {\n ...quoteResponse,\n namespace,\n chainId,\n },\n NAMESPACE_TO_TRADE_SCHEMA[namespace],\n );\n return true;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"quote-response.mjs","sourceRoot":"","sources":["../../src/validators/quote-response.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EAEN,MAAM,EACN,QAAQ,EACR,MAAM,EACN,IAAI,EACJ,KAAK,EACL,YAAY,EAEZ,QAAQ,EACR,KAAK,EACL,OAAO,EAER,8BAA8B;AAC/B,OAAO,EAEL,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,eAAe,EAChB,wBAAwB;AAEzB,OAAO,EAAE,SAAS,EAAE,4BAA2B;AAC/C,OAAO,EAAE,iBAAiB,EAAE,qBAAoB;AAChD,OAAO,EAAE,aAAa,EAAE,oBAAmB;AAC3C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AA+B;IAC/B,MAAM,CAAC,aAAa,EAAE,yBAAyB,CAAC,CAAC;IAEjD,uDAAuD;IACvD,MAAM,EACJ,KAAK,EAAE,EAAE,SAAS,EAAE,eAAe,EAAE,EACrC,OAAO,GACR,GAAG,kBAAkB,CAAC,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC9D,MAAM,SAAS,GAAG,eAA6C,CAAC;IAEhE,IAAI,CAAC,yBAAyB,CAAC,SAAS,CAAC,EAAE,CAAC;QAC1C,OAAO,KAAK,CAAC;IACf,CAAC;IAED,4EAA4E;IAC5E,MAAM,CACJ;QACE,GAAG,aAAa;QAChB,SAAS;QACT,OAAO;KACR,EACD,yBAAyB,CAAC,SAAS,CAAC,CACrC,CAAC;IACF,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,KAA4C,EACpB,EAAE;IAC1B,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,CAAC;QAClB,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AAClE,CAAC,CAAC","sourcesContent":["import {\n assert,\n Infer,\n number,\n optional,\n string,\n type,\n union,\n intersection,\n Describe,\n nullable,\n enums,\n literal,\n AnyStruct,\n} from '@metamask/superstruct';\nimport {\n CaipChainId,\n CaipChainIdStruct,\n KnownCaipNamespace,\n parseCaipAssetType,\n StrictHexStruct,\n} from '@metamask/utils';\n\nimport { FeatureId } from './feature-flags.js';\nimport { FloatStringSchema } from './number.js';\nimport { QuoteSchemaV2 } from './quote.js';\nimport {\n BitcoinTradeData,\n BitcoinTradeDataSchema,\n StellarTradeData,\n StellarTradeDataSchema,\n TronTradeData,\n TronTradeDataSchema,\n TxData,\n TxDataSchema,\n} from './trade.js';\n\nconst CommonQuoteResponseSchema = type({\n quoteId: optional(string()),\n quote: QuoteSchemaV2,\n estimatedProcessingTimeInSeconds: number(),\n /**\n * Appended to the quote if there are multiple quote requests in a batch. This\n * indicates which quoteRequest the quote is for\n */\n quoteRequestIndex: optional(number()),\n /**\n * Appended to the quote response based on the quote requested featureId\n */\n featureId: optional(enums(Object.values(FeatureId))),\n /**\n * Appended to the quote response based on the quote request nonEvmFeesInNative flag\n *\n * @deprecated Use network feeData\n */\n nonEvmFeesInNative: optional(FloatStringSchema),\n /**\n * Appended to the quote response based on the quote request l1GasFeesInHexWei flag\n *\n * @deprecated Use network feeData\n */\n l1GasFeesInHexWei: optional(StrictHexStruct),\n});\n\nconst EvmQuoteResponseSchema = intersection([\n CommonQuoteResponseSchema,\n type({\n namespace: literal(KnownCaipNamespace.Eip155),\n chainId: CaipChainIdStruct,\n trade: TxDataSchema,\n approval: optional(TxDataSchema),\n resetApproval: optional(TxDataSchema),\n }),\n]);\n\nconst TronQuoteResponseSchema = intersection([\n CommonQuoteResponseSchema,\n type({\n namespace: literal(KnownCaipNamespace.Tron),\n chainId: CaipChainIdStruct,\n trade: TronTradeDataSchema,\n approval: optional(TronTradeDataSchema),\n }),\n]);\n\nconst SolanaQuoteResponseSchema = intersection([\n CommonQuoteResponseSchema,\n type({\n namespace: literal(KnownCaipNamespace.Solana),\n chainId: CaipChainIdStruct,\n trade: string(),\n approval: optional(TxDataSchema),\n }),\n]);\n\nconst BitcoinQuoteResponseSchema = intersection([\n CommonQuoteResponseSchema,\n type({\n namespace: literal(KnownCaipNamespace.Bip122),\n chainId: CaipChainIdStruct,\n trade: BitcoinTradeDataSchema,\n approval: optional(TxDataSchema),\n }),\n]);\n\nconst StellarQuoteResponseSchema = intersection([\n CommonQuoteResponseSchema,\n type({\n namespace: literal(KnownCaipNamespace.Stellar),\n chainId: CaipChainIdStruct,\n trade: StellarTradeDataSchema,\n approval: optional(TxDataSchema),\n }),\n]);\n\nexport const QuoteResponseSchemaV2 = nullable(\n union([\n EvmQuoteResponseSchema,\n SolanaQuoteResponseSchema,\n TronQuoteResponseSchema,\n BitcoinQuoteResponseSchema,\n StellarQuoteResponseSchema,\n ]),\n);\n\n/**\n * This is the V2 QuoteResponse type, including metadata calculated after quote fetch\n */\nexport type QuoteResponse = Omit<\n NonNullable<Infer<typeof QuoteResponseSchemaV2>>,\n 'trade' | 'approval' | 'resetApproval'\n> &\n (\n | {\n namespace: KnownCaipNamespace.Eip155;\n chainId: CaipChainId;\n trade: TxData & {\n data: string;\n };\n approval?: TxData;\n /**\n * Appended to the quote response based on the quote request resetApproval flag\n * If defined, the quote's total network fee will include the reset approval's gas limit.\n */\n resetApproval?: TxData;\n }\n | {\n namespace: KnownCaipNamespace.Solana;\n chainId: CaipChainId;\n trade: string;\n approval?: TxData;\n }\n | {\n namespace: KnownCaipNamespace.Tron;\n chainId: CaipChainId;\n trade: TronTradeData & {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n raw_data_hex: string;\n };\n approval?: TronTradeData;\n }\n | {\n namespace: KnownCaipNamespace.Bip122;\n chainId: CaipChainId;\n trade: BitcoinTradeData;\n approval?: TxData;\n }\n | {\n namespace: KnownCaipNamespace.Stellar;\n chainId: CaipChainId;\n trade: StellarTradeData;\n approval?: TxData;\n }\n );\n// This ensures the QuoteResponse type is in sync with the QuoteResponseSchemaV2\nconst QuoteResponse: Describe<QuoteResponse | null> = QuoteResponseSchemaV2;\n\nconst NAMESPACE_TO_TRADE_SCHEMA: Record<QuoteResponse['namespace'], AnyStruct> =\n {\n [KnownCaipNamespace.Eip155]: EvmQuoteResponseSchema,\n [KnownCaipNamespace.Tron]: TronQuoteResponseSchema,\n [KnownCaipNamespace.Solana]: SolanaQuoteResponseSchema,\n [KnownCaipNamespace.Bip122]: BitcoinQuoteResponseSchema,\n [KnownCaipNamespace.Stellar]: StellarQuoteResponseSchema,\n };\n\nexport const validateQuoteResponse = (\n quoteResponse: unknown,\n): quoteResponse is QuoteResponse => {\n // Validate common fields first\n assert(quoteResponse, CommonQuoteResponseSchema);\n\n // Extract the namespace and chainId from the src asset\n const {\n chain: { namespace: namespaceString },\n chainId,\n } = parseCaipAssetType(quoteResponse.quote.src.asset.assetId);\n const namespace = namespaceString as QuoteResponse['namespace'];\n\n if (!NAMESPACE_TO_TRADE_SCHEMA[namespace]) {\n return false;\n }\n\n // Validate the trade and approval fields based on the src chain's namespace\n assert(\n {\n ...quoteResponse,\n namespace,\n chainId,\n },\n NAMESPACE_TO_TRADE_SCHEMA[namespace],\n );\n return true;\n};\n\n/**\n * Shallow check for the presence of the `src` property\n *\n * @param quote - The quote to check\n * @returns True if the quote is a V2 quote, false otherwise\n */\nexport const isQuoteResponseV2 = (\n quote: { quote?: object } | null | undefined,\n): quote is QuoteResponse => {\n if (!quote?.quote) {\n return false;\n }\n return Object.prototype.hasOwnProperty.call(quote.quote, 'src');\n};\n"]}
|
package/package.json
CHANGED