@metamask-previews/bridge-status-controller 38.0.1-preview-332b557 → 38.1.0-preview-a89812f5

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.
Files changed (46) hide show
  1. package/CHANGELOG.md +13 -1
  2. package/dist/bridge-status-controller.cjs +5 -1
  3. package/dist/bridge-status-controller.cjs.map +1 -1
  4. package/dist/bridge-status-controller.d.cts.map +1 -1
  5. package/dist/bridge-status-controller.d.mts.map +1 -1
  6. package/dist/bridge-status-controller.mjs +5 -1
  7. package/dist/bridge-status-controller.mjs.map +1 -1
  8. package/dist/types.cjs.map +1 -1
  9. package/dist/types.d.cts +2 -1
  10. package/dist/types.d.cts.map +1 -1
  11. package/dist/types.d.mts +2 -1
  12. package/dist/types.d.mts.map +1 -1
  13. package/dist/types.mjs.map +1 -1
  14. package/dist/utils/gas.cjs +31 -1
  15. package/dist/utils/gas.cjs.map +1 -1
  16. package/dist/utils/gas.d.cts +13 -3
  17. package/dist/utils/gas.d.cts.map +1 -1
  18. package/dist/utils/gas.d.mts +13 -3
  19. package/dist/utils/gas.d.mts.map +1 -1
  20. package/dist/utils/gas.mjs +29 -0
  21. package/dist/utils/gas.mjs.map +1 -1
  22. package/dist/utils/metrics.cjs +37 -8
  23. package/dist/utils/metrics.cjs.map +1 -1
  24. package/dist/utils/metrics.d.cts +13 -5
  25. package/dist/utils/metrics.d.cts.map +1 -1
  26. package/dist/utils/metrics.d.mts +13 -5
  27. package/dist/utils/metrics.d.mts.map +1 -1
  28. package/dist/utils/metrics.mjs +37 -8
  29. package/dist/utils/metrics.mjs.map +1 -1
  30. package/dist/utils/swap-received-amount.cjs +96 -0
  31. package/dist/utils/swap-received-amount.cjs.map +1 -0
  32. package/dist/utils/swap-received-amount.d.cts +25 -0
  33. package/dist/utils/swap-received-amount.d.cts.map +1 -0
  34. package/dist/utils/swap-received-amount.d.mts +25 -0
  35. package/dist/utils/swap-received-amount.d.mts.map +1 -0
  36. package/dist/utils/swap-received-amount.mjs +91 -0
  37. package/dist/utils/swap-received-amount.mjs.map +1 -0
  38. package/dist/utils/validators.cjs +1 -1
  39. package/dist/utils/validators.cjs.map +1 -1
  40. package/dist/utils/validators.d.cts +18 -6
  41. package/dist/utils/validators.d.cts.map +1 -1
  42. package/dist/utils/validators.d.mts +18 -6
  43. package/dist/utils/validators.d.mts.map +1 -1
  44. package/dist/utils/validators.mjs +2 -2
  45. package/dist/utils/validators.mjs.map +1 -1
  46. package/package.json +2 -2
@@ -0,0 +1,25 @@
1
+ import type { TokenAmountValues } from "@metamask/bridge-controller";
2
+ import { type TransactionMeta } from "@metamask/transaction-controller";
3
+ import { BigNumber } from "bignumber.js";
4
+ import type { BridgeHistoryItem } from "../types.mjs";
5
+ /**
6
+ * Calculate the amount received after a swap transaction based on the txMeta
7
+ *
8
+ * @param historyItem - The bridge history item
9
+ * @param actualGas - The actual gas used for the transaction
10
+ * @param txMeta - The transaction meta from the TransactionController
11
+ * @returns The actual amount received for the swap transaction
12
+ */
13
+ export declare const getActualSwapReceivedAmount: (historyItem: BridgeHistoryItem, actualGas: Omit<TokenAmountValues, 'valueInCurrency'> | null, txMeta?: TransactionMeta) => {
14
+ amount: string | BigNumber | null;
15
+ usd: BigNumber | null;
16
+ } | null;
17
+ /**
18
+ * Calculate the amount received after a bridge transaction based on the getTxStatus's
19
+ * amount field
20
+ *
21
+ * @param historyItem - The bridge history item
22
+ * @returns The actual amount received for the bridge transaction
23
+ */
24
+ export declare const getActualBridgeReceivedAmount: (historyItem: BridgeHistoryItem) => Omit<TokenAmountValues, 'valueInCurrency'> | null;
25
+ //# sourceMappingURL=swap-received-amount.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"swap-received-amount.d.mts","sourceRoot":"","sources":["../../src/utils/swap-received-amount.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,oCAAoC;AAErE,OAAO,EAAE,KAAK,eAAe,EAAE,yCAAyC;AACxE,OAAO,EAAE,SAAS,EAAE,qBAAqB;AAEzC,OAAO,KAAK,EAAE,iBAAiB,EAAE,qBAAiB;AAiElD;;;;;;;GAOG;AACH,eAAO,MAAM,2BAA2B,gBACzB,iBAAiB,aACnB,KAAK,iBAAiB,EAAE,iBAAiB,CAAC,GAAG,IAAI,WACnD,eAAe;;;QA6BzB,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,6BAA6B,gBAC3B,iBAAiB,KAC7B,KAAK,iBAAiB,EAAE,iBAAiB,CAAC,GAAG,IAc/C,CAAC"}
@@ -0,0 +1,91 @@
1
+ import { isNativeAddress } from "@metamask/bridge-controller";
2
+ import { BigNumber } from "bignumber.js";
3
+ const getReceivedNativeAmount = (historyItem, actualGas, txMeta) => {
4
+ const { preTxBalance, postTxBalance } = txMeta;
5
+ if (!preTxBalance || !postTxBalance || preTxBalance === postTxBalance) {
6
+ // If preTxBalance and postTxBalance are equal, postTxBalance hasn't been updated on time
7
+ // because of the RPC provider delay, so we return an estimated receiving amount instead.
8
+ return new BigNumber(historyItem.quote.destTokenAmount)
9
+ .div(new BigNumber(10).pow(historyItem.quote.destAsset.decimals))
10
+ .toString(10);
11
+ }
12
+ return actualGas && postTxBalance && preTxBalance
13
+ ? new BigNumber(postTxBalance, 16)
14
+ .minus(preTxBalance, 16)
15
+ .minus(actualGas.amount)
16
+ .div(10 ** historyItem.quote.destAsset.decimals)
17
+ : null;
18
+ };
19
+ const getReceivedERC20Amount = (historyItem, txMeta) => {
20
+ const { txReceipt } = txMeta;
21
+ if (!txReceipt || !txReceipt.logs || txReceipt.status === '0x0') {
22
+ return null;
23
+ }
24
+ const { account: accountAddress, quote } = historyItem;
25
+ const TOKEN_TRANSFER_LOG_TOPIC_HASH = '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef';
26
+ const tokenTransferLog = txReceipt.logs.find((txReceiptLog) => {
27
+ const isTokenTransfer = txReceiptLog.topics &&
28
+ txReceiptLog.topics[0].startsWith(TOKEN_TRANSFER_LOG_TOPIC_HASH);
29
+ const isTransferFromGivenToken = txReceiptLog.address?.toLowerCase() ===
30
+ quote.destAsset.address?.toLowerCase();
31
+ const isTransferFromGivenAddress = txReceiptLog.topics &&
32
+ txReceiptLog.topics[2] &&
33
+ (txReceiptLog.topics[2] === accountAddress ||
34
+ txReceiptLog.topics[2].match(accountAddress?.slice(2)));
35
+ return (isTokenTransfer && isTransferFromGivenToken && isTransferFromGivenAddress);
36
+ });
37
+ if (tokenTransferLog?.data) {
38
+ return new BigNumber(tokenTransferLog.data, 16).div(new BigNumber(10).pow(quote.destAsset.decimals));
39
+ }
40
+ return null;
41
+ };
42
+ /**
43
+ * Calculate the amount received after a swap transaction based on the txMeta
44
+ *
45
+ * @param historyItem - The bridge history item
46
+ * @param actualGas - The actual gas used for the transaction
47
+ * @param txMeta - The transaction meta from the TransactionController
48
+ * @returns The actual amount received for the swap transaction
49
+ */
50
+ export const getActualSwapReceivedAmount = (historyItem, actualGas, txMeta) => {
51
+ const { pricingData } = historyItem;
52
+ const quotedReturnAmount = historyItem.quote.destTokenAmount;
53
+ if (!txMeta?.txReceipt) {
54
+ return null;
55
+ }
56
+ const actualReturnAmount = isNativeAddress(historyItem.quote.destAsset.address)
57
+ ? getReceivedNativeAmount(historyItem, actualGas, txMeta)
58
+ : getReceivedERC20Amount(historyItem, txMeta);
59
+ const returnUsdExchangeRate = pricingData?.quotedReturnInUsd && quotedReturnAmount
60
+ ? new BigNumber(pricingData.quotedReturnInUsd)
61
+ .div(quotedReturnAmount)
62
+ .multipliedBy(10 ** historyItem.quote.destAsset.decimals)
63
+ : null;
64
+ return {
65
+ amount: actualReturnAmount,
66
+ usd: actualReturnAmount && returnUsdExchangeRate
67
+ ? returnUsdExchangeRate.multipliedBy(actualReturnAmount)
68
+ : null,
69
+ };
70
+ };
71
+ /**
72
+ * Calculate the amount received after a bridge transaction based on the getTxStatus's
73
+ * amount field
74
+ *
75
+ * @param historyItem - The bridge history item
76
+ * @returns The actual amount received for the bridge transaction
77
+ */
78
+ export const getActualBridgeReceivedAmount = (historyItem) => {
79
+ const { quote, pricingData, status } = historyItem;
80
+ const usdExchangeRate = pricingData?.quotedReturnInUsd
81
+ ? new BigNumber(pricingData.quotedReturnInUsd).div(quote.destTokenAmount)
82
+ : null;
83
+ const actualAmount = status.destChain?.amount;
84
+ return actualAmount && usdExchangeRate
85
+ ? {
86
+ amount: actualAmount,
87
+ usd: usdExchangeRate.multipliedBy(actualAmount).toString(10),
88
+ }
89
+ : null;
90
+ };
91
+ //# sourceMappingURL=swap-received-amount.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"swap-received-amount.mjs","sourceRoot":"","sources":["../../src/utils/swap-received-amount.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,oCAAoC;AAE9D,OAAO,EAAE,SAAS,EAAE,qBAAqB;AAIzC,MAAM,uBAAuB,GAAG,CAC9B,WAA8B,EAC9B,SAA4D,EAC5D,MAAuB,EACvB,EAAE;IACF,MAAM,EAAE,YAAY,EAAE,aAAa,EAAE,GAAG,MAAM,CAAC;IAE/C,IAAI,CAAC,YAAY,IAAI,CAAC,aAAa,IAAI,YAAY,KAAK,aAAa,EAAE;QACrE,yFAAyF;QACzF,yFAAyF;QACzF,OAAO,IAAI,SAAS,CAAC,WAAW,CAAC,KAAK,CAAC,eAAe,CAAC;aACpD,GAAG,CAAC,IAAI,SAAS,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC,KAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;aAChE,QAAQ,CAAC,EAAE,CAAC,CAAC;KACjB;IAED,OAAO,SAAS,IAAI,aAAa,IAAI,YAAY;QAC/C,CAAC,CAAC,IAAI,SAAS,CAAC,aAAa,EAAE,EAAE,CAAC;aAC7B,KAAK,CAAC,YAAY,EAAE,EAAE,CAAC;aACvB,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC;aACvB,GAAG,CAAC,EAAE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IACrD,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,WAAW,CAAC;IAEnD,MAAM,eAAe,GAAG,WAAW,EAAE,iBAAiB;QACpD,CAAC,CAAC,IAAI,SAAS,CAAC,WAAW,CAAC,iBAAiB,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,eAAe,CAAC;QACzE,CAAC,CAAC,IAAI,CAAC;IAET,MAAM,YAAY,GAAG,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC;IAC9C,OAAO,YAAY,IAAI,eAAe;QACpC,CAAC,CAAC;YACE,MAAM,EAAE,YAAY;YACpB,GAAG,EAAE,eAAe,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC;SAC7D;QACH,CAAC,CAAC,IAAI,CAAC;AACX,CAAC,CAAC","sourcesContent":["import type { TokenAmountValues } from '@metamask/bridge-controller';\nimport { isNativeAddress } from '@metamask/bridge-controller';\nimport { type TransactionMeta } from '@metamask/transaction-controller';\nimport { BigNumber } from 'bignumber.js';\n\nimport type { BridgeHistoryItem } from '../types';\n\nconst getReceivedNativeAmount = (\n historyItem: BridgeHistoryItem,\n actualGas: Omit<TokenAmountValues, 'valueInCurrency'> | null,\n txMeta: TransactionMeta,\n) => {\n const { preTxBalance, postTxBalance } = txMeta;\n\n if (!preTxBalance || !postTxBalance || preTxBalance === postTxBalance) {\n // If preTxBalance and postTxBalance are equal, postTxBalance hasn't been updated on time\n // because of the RPC provider delay, so we return an estimated receiving amount instead.\n return new BigNumber(historyItem.quote.destTokenAmount)\n .div(new BigNumber(10).pow(historyItem.quote.destAsset.decimals))\n .toString(10);\n }\n\n return actualGas && postTxBalance && preTxBalance\n ? new BigNumber(postTxBalance, 16)\n .minus(preTxBalance, 16)\n .minus(actualGas.amount)\n .div(10 ** historyItem.quote.destAsset.decimals)\n : null;\n};\n\nconst getReceivedERC20Amount = (\n historyItem: BridgeHistoryItem,\n txMeta: TransactionMeta,\n) => {\n const { txReceipt } = txMeta;\n if (!txReceipt || !txReceipt.logs || txReceipt.status === '0x0') {\n return null;\n }\n const { account: accountAddress, quote } = historyItem;\n\n const TOKEN_TRANSFER_LOG_TOPIC_HASH =\n '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef';\n\n const tokenTransferLog = txReceipt.logs.find((txReceiptLog) => {\n const isTokenTransfer =\n txReceiptLog.topics &&\n txReceiptLog.topics[0].startsWith(TOKEN_TRANSFER_LOG_TOPIC_HASH);\n const isTransferFromGivenToken =\n txReceiptLog.address?.toLowerCase() ===\n quote.destAsset.address?.toLowerCase();\n const isTransferFromGivenAddress =\n txReceiptLog.topics &&\n txReceiptLog.topics[2] &&\n (txReceiptLog.topics[2] === accountAddress ||\n txReceiptLog.topics[2].match(accountAddress?.slice(2)));\n\n return (\n isTokenTransfer && isTransferFromGivenToken && isTransferFromGivenAddress\n );\n });\n\n if (tokenTransferLog?.data) {\n return new BigNumber(tokenTransferLog.data, 16).div(\n new BigNumber(10).pow(quote.destAsset.decimals),\n );\n }\n\n return null;\n};\n\n/**\n * Calculate the amount received after a swap transaction based on the txMeta\n *\n * @param historyItem - The bridge history item\n * @param actualGas - The actual gas used for the transaction\n * @param txMeta - The transaction meta from the TransactionController\n * @returns The actual amount received for the swap transaction\n */\nexport const getActualSwapReceivedAmount = (\n historyItem: BridgeHistoryItem,\n actualGas: Omit<TokenAmountValues, 'valueInCurrency'> | null,\n txMeta?: TransactionMeta,\n) => {\n const { pricingData } = historyItem;\n const quotedReturnAmount = historyItem.quote.destTokenAmount;\n\n if (!txMeta?.txReceipt) {\n return null;\n }\n\n const actualReturnAmount = isNativeAddress(\n historyItem.quote.destAsset.address,\n )\n ? getReceivedNativeAmount(historyItem, actualGas, txMeta)\n : getReceivedERC20Amount(historyItem, txMeta);\n\n const returnUsdExchangeRate =\n pricingData?.quotedReturnInUsd && quotedReturnAmount\n ? new BigNumber(pricingData.quotedReturnInUsd)\n .div(quotedReturnAmount)\n .multipliedBy(10 ** historyItem.quote.destAsset.decimals)\n : null;\n\n return {\n amount: actualReturnAmount,\n usd:\n actualReturnAmount && returnUsdExchangeRate\n ? returnUsdExchangeRate.multipliedBy(actualReturnAmount)\n : null,\n };\n};\n\n/**\n * Calculate the amount received after a bridge transaction based on the getTxStatus's\n * amount field\n *\n * @param historyItem - The bridge history item\n * @returns The actual amount received for the bridge transaction\n */\nexport const getActualBridgeReceivedAmount = (\n historyItem: BridgeHistoryItem,\n): Omit<TokenAmountValues, 'valueInCurrency'> | null => {\n const { quote, pricingData, status } = historyItem;\n\n const usdExchangeRate = pricingData?.quotedReturnInUsd\n ? new BigNumber(pricingData.quotedReturnInUsd).div(quote.destTokenAmount)\n : null;\n\n const actualAmount = status.destChain?.amount;\n return actualAmount && usdExchangeRate\n ? {\n amount: actualAmount,\n usd: usdExchangeRate.multipliedBy(actualAmount).toString(10),\n }\n : null;\n};\n"]}
@@ -4,7 +4,7 @@ exports.validateBridgeStatusResponse = exports.StatusResponseSchema = void 0;
4
4
  const bridge_controller_1 = require("@metamask/bridge-controller");
5
5
  const superstruct_1 = require("@metamask/superstruct");
6
6
  const ChainIdSchema = (0, superstruct_1.number)();
7
- const EmptyObjectSchema = (0, superstruct_1.object)({});
7
+ const EmptyObjectSchema = (0, superstruct_1.type)({});
8
8
  const SrcChainStatusSchema = (0, superstruct_1.type)({
9
9
  chainId: ChainIdSchema,
10
10
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"validators.cjs","sourceRoot":"","sources":["../../src/utils/validators.ts"],"names":[],"mappings":";;;AAAA,mEAA6E;AAC7E,uDAW+B;AAE/B,MAAM,aAAa,GAAG,IAAA,oBAAM,GAAE,CAAC;AAE/B,MAAM,iBAAiB,GAAG,IAAA,oBAAM,EAAC,EAAE,CAAC,CAAC;AAErC,MAAM,oBAAoB,GAAG,IAAA,kBAAI,EAAC;IAChC,OAAO,EAAE,aAAa;IACtB;;;OAGG;IACH,MAAM,EAAE,IAAA,sBAAQ,EA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AAC,IAAI,EAAE,4BAAoB,CAAC,CAAC;KACpC;IAAC,OAAO,KAAK,EAAE;QACd,IAAI,KAAK,YAAY,yBAAW,EAAE;YAChC,KAAK,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE;gBACrD,MAAM,UAAU,GAAG,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,SAAS,CAAC;gBAChD,kBAAkB,CAAC,UAAU,CAAC;oBAC5B,IAAI,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,IAAI,SAAS,KAAK,OAAO,EAAE,CAAC;YACvD,CAAC,CAAC,CAAC;SACJ;QACD,MAAM,KAAK,CAAC;KACb;YAAS;QACR,IAAI,MAAM,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;YAC9C,OAAO,CAAC,KAAK,CAAC,iCAAiC,EAAE,kBAAkB,CAAC,CAAC;SACtE;KACF;AACH,CAAC,CAAC;AAlBW,QAAA,4BAA4B,gCAkBvC","sourcesContent":["import { StatusTypes, BridgeAssetSchema } from '@metamask/bridge-controller';\nimport {\n object,\n string,\n boolean,\n number,\n optional,\n enums,\n union,\n type,\n assert,\n StructError,\n} from '@metamask/superstruct';\n\nconst ChainIdSchema = number();\n\nconst EmptyObjectSchema = object({});\n\nconst SrcChainStatusSchema = type({\n chainId: ChainIdSchema,\n /**\n * The txHash of the transaction on the source chain.\n * This might be undefined for smart transactions (STX)\n */\n txHash: optional(string()),\n /**\n * The atomic amount of the token sent minus fees on the source chain\n */\n amount: optional(string()),\n token: optional(union([EmptyObjectSchema, BridgeAssetSchema])),\n});\n\nconst DestChainStatusSchema = type({\n chainId: ChainIdSchema,\n txHash: optional(string()),\n /**\n * The atomic amount of the token received on the destination chain\n */\n amount: optional(string()),\n token: optional(union([EmptyObjectSchema, BridgeAssetSchema])),\n});\n\nconst RefuelStatusResponseSchema = type({});\n\nexport const StatusResponseSchema = type({\n status: enums(Object.values(StatusTypes)),\n srcChain: SrcChainStatusSchema,\n destChain: optional(DestChainStatusSchema),\n bridge: optional(string()),\n isExpectedToken: optional(boolean()),\n isUnrecognizedRouterAddress: optional(boolean()),\n refuel: optional(RefuelStatusResponseSchema),\n});\n\nexport const validateBridgeStatusResponse = (data: unknown) => {\n const validationFailures: { [path: string]: string } = {};\n try {\n assert(data, StatusResponseSchema);\n } catch (error) {\n if (error instanceof StructError) {\n error.failures().forEach(({ branch, path, message }) => {\n const pathString = path?.join('.') || 'unknown';\n validationFailures[pathString] =\n `[${branch?.[0]?.bridge || 'unknown'}] ${message}`;\n });\n }\n throw error;\n } finally {\n if (Object.keys(validationFailures).length > 0) {\n console.error(`Bridge status validation failed`, validationFailures);\n }\n }\n};\n"]}
1
+ {"version":3,"file":"validators.cjs","sourceRoot":"","sources":["../../src/utils/validators.ts"],"names":[],"mappings":";;;AAAA,mEAA6E;AAC7E,uDAU+B;AAE/B,MAAM,aAAa,GAAG,IAAA,oBAAM,GAAE,CAAC;AAE/B,MAAM,iBAAiB,GAAG,IAAA,kBAAI,EAAC,EAAE,CAAC,CAAC;AAEnC,MAAM,oBAAoB,GAAG,IAAA,kBAAI,EAAC;IAChC,OAAO,EAAE,aAAa;IACtB;;;OAGG;IACH,MAAM,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;IAC1B;;OAEG;IACH,MAAM,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;IAC1B,KAAK,EAAE,IAAA,sBAAQ,EAAC,IAAA,mBAAK,EAAC,CAAC,iBAAiB,EAAE,qCAAiB,CAAC,CAAC,CAAC;CAC/D,CAAC,CAAC;AAEH,MAAM,qBAAqB,GAAG,IAAA,kBAAI,EAAC;IACjC,OAAO,EAAE,aAAa;IACtB,MAAM,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;IAC1B;;OAEG;IACH,MA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I,SAAS,KAAK,OAAO,EAAE,CAAC;YACvD,CAAC,CAAC,CAAC;SACJ;QACD,MAAM,KAAK,CAAC;KACb;YAAS;QACR,IAAI,MAAM,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;YAC9C,OAAO,CAAC,KAAK,CAAC,iCAAiC,EAAE,kBAAkB,CAAC,CAAC;SACtE;KACF;AACH,CAAC,CAAC;AAlBW,QAAA,4BAA4B,gCAkBvC","sourcesContent":["import { StatusTypes, BridgeAssetSchema } from '@metamask/bridge-controller';\nimport {\n string,\n boolean,\n number,\n optional,\n enums,\n union,\n type,\n assert,\n StructError,\n} from '@metamask/superstruct';\n\nconst ChainIdSchema = number();\n\nconst EmptyObjectSchema = type({});\n\nconst SrcChainStatusSchema = type({\n chainId: ChainIdSchema,\n /**\n * The txHash of the transaction on the source chain.\n * This might be undefined for smart transactions (STX)\n */\n txHash: optional(string()),\n /**\n * The atomic amount of the token sent minus fees on the source chain\n */\n amount: optional(string()),\n token: optional(union([EmptyObjectSchema, BridgeAssetSchema])),\n});\n\nconst DestChainStatusSchema = type({\n chainId: ChainIdSchema,\n txHash: optional(string()),\n /**\n * The atomic amount of the token received on the destination chain\n */\n amount: optional(string()),\n token: optional(union([EmptyObjectSchema, BridgeAssetSchema])),\n});\n\nconst RefuelStatusResponseSchema = type({});\n\nexport const StatusResponseSchema = type({\n status: enums(Object.values(StatusTypes)),\n srcChain: SrcChainStatusSchema,\n destChain: optional(DestChainStatusSchema),\n bridge: optional(string()),\n isExpectedToken: optional(boolean()),\n isUnrecognizedRouterAddress: optional(boolean()),\n refuel: optional(RefuelStatusResponseSchema),\n});\n\nexport const validateBridgeStatusResponse = (data: unknown) => {\n const validationFailures: { [path: string]: string } = {};\n try {\n assert(data, StatusResponseSchema);\n } catch (error) {\n if (error instanceof StructError) {\n error.failures().forEach(({ branch, path, message }) => {\n const pathString = path?.join('.') || 'unknown';\n validationFailures[pathString] =\n `[${branch?.[0]?.bridge || 'unknown'}] ${message}`;\n });\n }\n throw error;\n } finally {\n if (Object.keys(validationFailures).length > 0) {\n console.error(`Bridge status validation failed`, validationFailures);\n }\n }\n};\n"]}
@@ -9,7 +9,9 @@ export declare const StatusResponseSchema: import("@metamask/superstruct").Struc
9
9
  address: string;
10
10
  name: string;
11
11
  chainId: number;
12
- decimals: number;
12
+ decimals: number; /**
13
+ * The atomic amount of the token sent minus fees on the source chain
14
+ */
13
15
  assetId: `${string}:${string}/${string}:${string}`;
14
16
  iconUrl?: string | null | undefined;
15
17
  icon?: string | null | undefined;
@@ -26,7 +28,9 @@ export declare const StatusResponseSchema: import("@metamask/superstruct").Struc
26
28
  address: string;
27
29
  name: string;
28
30
  chainId: number;
29
- decimals: number;
31
+ decimals: number; /**
32
+ * The atomic amount of the token sent minus fees on the source chain
33
+ */
30
34
  assetId: `${string}:${string}/${string}:${string}`;
31
35
  iconUrl?: string | null | undefined;
32
36
  icon?: string | null | undefined;
@@ -50,7 +54,9 @@ export declare const StatusResponseSchema: import("@metamask/superstruct").Struc
50
54
  address: string;
51
55
  name: string;
52
56
  chainId: number;
53
- decimals: number;
57
+ decimals: number; /**
58
+ * The atomic amount of the token sent minus fees on the source chain
59
+ */
54
60
  assetId: `${string}:${string}/${string}:${string}`;
55
61
  iconUrl?: string | null | undefined;
56
62
  icon?: string | null | undefined;
@@ -72,7 +78,9 @@ export declare const StatusResponseSchema: import("@metamask/superstruct").Struc
72
78
  address: string;
73
79
  name: string;
74
80
  chainId: number;
75
- decimals: number;
81
+ decimals: number; /**
82
+ * The atomic amount of the token sent minus fees on the source chain
83
+ */
76
84
  assetId: `${string}:${string}/${string}:${string}`;
77
85
  iconUrl?: string | null | undefined;
78
86
  icon?: string | null | undefined;
@@ -86,7 +94,9 @@ export declare const StatusResponseSchema: import("@metamask/superstruct").Struc
86
94
  address: string;
87
95
  name: string;
88
96
  chainId: number;
89
- decimals: number;
97
+ decimals: number; /**
98
+ * The atomic amount of the token sent minus fees on the source chain
99
+ */
90
100
  assetId: `${string}:${string}/${string}:${string}`;
91
101
  iconUrl?: string | null | undefined;
92
102
  icon?: string | null | undefined;
@@ -104,7 +114,9 @@ export declare const StatusResponseSchema: import("@metamask/superstruct").Struc
104
114
  address: string;
105
115
  name: string;
106
116
  chainId: number;
107
- decimals: number;
117
+ decimals: number; /**
118
+ * The atomic amount of the token sent minus fees on the source chain
119
+ */
108
120
  assetId: `${string}:${string}/${string}:${string}`;
109
121
  iconUrl?: string | null | undefined;
110
122
  icon?: string | null | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"validators.d.cts","sourceRoot":"","sources":["../../src/utils/validators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAqB,oCAAoC;AA4C7E,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAxB/B;;;WAGG;;QAEH;;WAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAQH;;WAEG;;;;;;;;;;;;;;;;;EAeH,CAAC;AAEH,eAAO,MAAM,4BAA4B,SAAU,OAAO,SAkBzD,CAAC"}
1
+ {"version":3,"file":"validators.d.cts","sourceRoot":"","sources":["../../src/utils/validators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAqB,oCAAoC;AA2C7E,eAAO,MAAM,oBAAoB;;;;;;;;;;8BAnB/B;;eAEG;;;;;;;;;;;;;;;;;8BAFH;;eAEG;;;;;;;;;;;;;;;;;;;;;;;;8BAFH;;eAEG;;;;;;;;QAPH;;;WAGG;;QAEH;;WAEG;;;;;;;8BAFH;;eAEG;;;;;;;;;;;;;;8BAFH;;eAEG;;;;;;;;;QAQH;;WAEG;;;;;;;8BAZH;;eAEG;;;;;;;;;;EAyBH,CAAC;AAEH,eAAO,MAAM,4BAA4B,SAAU,OAAO,SAkBzD,CAAC"}
@@ -9,7 +9,9 @@ export declare const StatusResponseSchema: import("@metamask/superstruct").Struc
9
9
  address: string;
10
10
  name: string;
11
11
  chainId: number;
12
- decimals: number;
12
+ decimals: number; /**
13
+ * The atomic amount of the token sent minus fees on the source chain
14
+ */
13
15
  assetId: `${string}:${string}/${string}:${string}`;
14
16
  iconUrl?: string | null | undefined;
15
17
  icon?: string | null | undefined;
@@ -26,7 +28,9 @@ export declare const StatusResponseSchema: import("@metamask/superstruct").Struc
26
28
  address: string;
27
29
  name: string;
28
30
  chainId: number;
29
- decimals: number;
31
+ decimals: number; /**
32
+ * The atomic amount of the token sent minus fees on the source chain
33
+ */
30
34
  assetId: `${string}:${string}/${string}:${string}`;
31
35
  iconUrl?: string | null | undefined;
32
36
  icon?: string | null | undefined;
@@ -50,7 +54,9 @@ export declare const StatusResponseSchema: import("@metamask/superstruct").Struc
50
54
  address: string;
51
55
  name: string;
52
56
  chainId: number;
53
- decimals: number;
57
+ decimals: number; /**
58
+ * The atomic amount of the token sent minus fees on the source chain
59
+ */
54
60
  assetId: `${string}:${string}/${string}:${string}`;
55
61
  iconUrl?: string | null | undefined;
56
62
  icon?: string | null | undefined;
@@ -72,7 +78,9 @@ export declare const StatusResponseSchema: import("@metamask/superstruct").Struc
72
78
  address: string;
73
79
  name: string;
74
80
  chainId: number;
75
- decimals: number;
81
+ decimals: number; /**
82
+ * The atomic amount of the token sent minus fees on the source chain
83
+ */
76
84
  assetId: `${string}:${string}/${string}:${string}`;
77
85
  iconUrl?: string | null | undefined;
78
86
  icon?: string | null | undefined;
@@ -86,7 +94,9 @@ export declare const StatusResponseSchema: import("@metamask/superstruct").Struc
86
94
  address: string;
87
95
  name: string;
88
96
  chainId: number;
89
- decimals: number;
97
+ decimals: number; /**
98
+ * The atomic amount of the token sent minus fees on the source chain
99
+ */
90
100
  assetId: `${string}:${string}/${string}:${string}`;
91
101
  iconUrl?: string | null | undefined;
92
102
  icon?: string | null | undefined;
@@ -104,7 +114,9 @@ export declare const StatusResponseSchema: import("@metamask/superstruct").Struc
104
114
  address: string;
105
115
  name: string;
106
116
  chainId: number;
107
- decimals: number;
117
+ decimals: number; /**
118
+ * The atomic amount of the token sent minus fees on the source chain
119
+ */
108
120
  assetId: `${string}:${string}/${string}:${string}`;
109
121
  iconUrl?: string | null | undefined;
110
122
  icon?: string | null | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"validators.d.mts","sourceRoot":"","sources":["../../src/utils/validators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAqB,oCAAoC;AA4C7E,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAxB/B;;;WAGG;;QAEH;;WAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAQH;;WAEG;;;;;;;;;;;;;;;;;EAeH,CAAC;AAEH,eAAO,MAAM,4BAA4B,SAAU,OAAO,SAkBzD,CAAC"}
1
+ {"version":3,"file":"validators.d.mts","sourceRoot":"","sources":["../../src/utils/validators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAqB,oCAAoC;AA2C7E,eAAO,MAAM,oBAAoB;;;;;;;;;;8BAnB/B;;eAEG;;;;;;;;;;;;;;;;;8BAFH;;eAEG;;;;;;;;;;;;;;;;;;;;;;;;8BAFH;;eAEG;;;;;;;;QAPH;;;WAGG;;QAEH;;WAEG;;;;;;;8BAFH;;eAEG;;;;;;;;;;;;;;8BAFH;;eAEG;;;;;;;;;QAQH;;WAEG;;;;;;;8BAZH;;eAEG;;;;;;;;;;EAyBH,CAAC;AAEH,eAAO,MAAM,4BAA4B,SAAU,OAAO,SAkBzD,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import { StatusTypes, BridgeAssetSchema } from "@metamask/bridge-controller";
2
- import { object, string, boolean, number, optional, enums, union, type, assert, StructError } from "@metamask/superstruct";
2
+ import { string, boolean, number, optional, enums, union, type, assert, StructError } from "@metamask/superstruct";
3
3
  const ChainIdSchema = number();
4
- const EmptyObjectSchema = object({});
4
+ const EmptyObjectSchema = type({});
5
5
  const SrcChainStatusSchema = type({
6
6
  chainId: ChainIdSchema,
7
7
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"validators.mjs","sourceRoot":"","sources":["../../src/utils/validators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,oCAAoC;AAC7E,OAAO,EACL,MAAM,EACN,MAAM,EACN,OAAO,EACP,MAAM,EACN,QAAQ,EACR,KAAK,EACL,KAAK,EACL,IAAI,EACJ,MAAM,EACN,WAAW,EACZ,8BAA8B;AAE/B,MAAM,aAAa,GAAG,MAAM,EAAE,CAAC;AAE/B,MAAM,iBAAiB,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC;AAErC,MAAM,oBAAoB,GAAG,IAAI,CAAC;IAChC,OAAO,EAAE,aAAa;IACtB;;;OAGG;IACH,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC;IAC1B;;OAEG;IACH,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC;IAC1B,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,iBAAiB,EAAE,iBAAiB,CAAC,CAAC,CAAC;CAC/D,CAAC,CAAC;AAEH,MAAM,qBAAqB,GAAG,IAAI,CAAC;IACjC,OAAO,EAAE,aAAa;IACtB,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC;IAC1B;;OAEG;IACH,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC;IAC1B,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,iBAAiB,EAAE,iBAAiB,CAAC,CAAC,CAAC;CAC/D,CAAC,CAAC;AAEH,MAAM,0BAA0B,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC;AAE5C,MAAM,CAAC,MAAM,oBAAoB,GAAG,IAAI,CAAC;IACvC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IACzC,QAAQ,EAAE,oBAAoB;IAC9B,SAAS,EAAE,QAAQ,CAAC,qBAAqB,CAAC;IAC1C,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC;IAC1B,eAAe,EAAE,QAAQ,CAAC,OAAO,EAAE,CAAC;IACpC,2BAA2B,EAAE,QAAQ,CAAC,OAAO,EAAE,CAAC;IAChD,MAAM,EAAE,QAAQ,CAAC,0BAA0B,CAAC;CAC7C,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAAC,IAAa,EAAE,EAAE;IAC5D,MAAM,kBAAkB,GAA+B,EAAE,CAAC;IAC1D,IAAI;QACF,MAAM,CAAC,IAAI,EAAE,oBAAoB,CAAC,CAAC;KACpC;IAAC,OAAO,KAAK,EAAE;QACd,IAAI,KAAK,YAAY,WAAW,EAAE;YAChC,KAAK,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE;gBACrD,MAAM,UAAU,GAAG,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,SAAS,CAAC;gBAChD,kBAAkB,CAAC,UAAU,CAAC;oBAC5B,IAAI,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,IAAI,SAAS,KAAK,OAAO,EAAE,CAAC;YACvD,CAAC,CAAC,CAAC;SACJ;QACD,MAAM,KAAK,CAAC;KACb;YAAS;QACR,IAAI,MAAM,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;YAC9C,OAAO,CAAC,KAAK,CAAC,iCAAiC,EAAE,kBAAkB,CAAC,CAAC;SACtE;KACF;AACH,CAAC,CAAC","sourcesContent":["import { StatusTypes, BridgeAssetSchema } from '@metamask/bridge-controller';\nimport {\n object,\n string,\n boolean,\n number,\n optional,\n enums,\n union,\n type,\n assert,\n StructError,\n} from '@metamask/superstruct';\n\nconst ChainIdSchema = number();\n\nconst EmptyObjectSchema = object({});\n\nconst SrcChainStatusSchema = type({\n chainId: ChainIdSchema,\n /**\n * The txHash of the transaction on the source chain.\n * This might be undefined for smart transactions (STX)\n */\n txHash: optional(string()),\n /**\n * The atomic amount of the token sent minus fees on the source chain\n */\n amount: optional(string()),\n token: optional(union([EmptyObjectSchema, BridgeAssetSchema])),\n});\n\nconst DestChainStatusSchema = type({\n chainId: ChainIdSchema,\n txHash: optional(string()),\n /**\n * The atomic amount of the token received on the destination chain\n */\n amount: optional(string()),\n token: optional(union([EmptyObjectSchema, BridgeAssetSchema])),\n});\n\nconst RefuelStatusResponseSchema = type({});\n\nexport const StatusResponseSchema = type({\n status: enums(Object.values(StatusTypes)),\n srcChain: SrcChainStatusSchema,\n destChain: optional(DestChainStatusSchema),\n bridge: optional(string()),\n isExpectedToken: optional(boolean()),\n isUnrecognizedRouterAddress: optional(boolean()),\n refuel: optional(RefuelStatusResponseSchema),\n});\n\nexport const validateBridgeStatusResponse = (data: unknown) => {\n const validationFailures: { [path: string]: string } = {};\n try {\n assert(data, StatusResponseSchema);\n } catch (error) {\n if (error instanceof StructError) {\n error.failures().forEach(({ branch, path, message }) => {\n const pathString = path?.join('.') || 'unknown';\n validationFailures[pathString] =\n `[${branch?.[0]?.bridge || 'unknown'}] ${message}`;\n });\n }\n throw error;\n } finally {\n if (Object.keys(validationFailures).length > 0) {\n console.error(`Bridge status validation failed`, validationFailures);\n }\n }\n};\n"]}
1
+ {"version":3,"file":"validators.mjs","sourceRoot":"","sources":["../../src/utils/validators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,oCAAoC;AAC7E,OAAO,EACL,MAAM,EACN,OAAO,EACP,MAAM,EACN,QAAQ,EACR,KAAK,EACL,KAAK,EACL,IAAI,EACJ,MAAM,EACN,WAAW,EACZ,8BAA8B;AAE/B,MAAM,aAAa,GAAG,MAAM,EAAE,CAAC;AAE/B,MAAM,iBAAiB,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC;AAE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OAAO,KAAK,EAAE;QACd,IAAI,KAAK,YAAY,WAAW,EAAE;YAChC,KAAK,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE;gBACrD,MAAM,UAAU,GAAG,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,SAAS,CAAC;gBAChD,kBAAkB,CAAC,UAAU,CAAC;oBAC5B,IAAI,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,IAAI,SAAS,KAAK,OAAO,EAAE,CAAC;YACvD,CAAC,CAAC,CAAC;SACJ;QACD,MAAM,KAAK,CAAC;KACb;YAAS;QACR,IAAI,MAAM,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;YAC9C,OAAO,CAAC,KAAK,CAAC,iCAAiC,EAAE,kBAAkB,CAAC,CAAC;SACtE;KACF;AACH,CAAC,CAAC","sourcesContent":["import { StatusTypes, BridgeAssetSchema } from '@metamask/bridge-controller';\nimport {\n string,\n boolean,\n number,\n optional,\n enums,\n union,\n type,\n assert,\n StructError,\n} from '@metamask/superstruct';\n\nconst ChainIdSchema = number();\n\nconst EmptyObjectSchema = type({});\n\nconst SrcChainStatusSchema = type({\n chainId: ChainIdSchema,\n /**\n * The txHash of the transaction on the source chain.\n * This might be undefined for smart transactions (STX)\n */\n txHash: optional(string()),\n /**\n * The atomic amount of the token sent minus fees on the source chain\n */\n amount: optional(string()),\n token: optional(union([EmptyObjectSchema, BridgeAssetSchema])),\n});\n\nconst DestChainStatusSchema = type({\n chainId: ChainIdSchema,\n txHash: optional(string()),\n /**\n * The atomic amount of the token received on the destination chain\n */\n amount: optional(string()),\n token: optional(union([EmptyObjectSchema, BridgeAssetSchema])),\n});\n\nconst RefuelStatusResponseSchema = type({});\n\nexport const StatusResponseSchema = type({\n status: enums(Object.values(StatusTypes)),\n srcChain: SrcChainStatusSchema,\n destChain: optional(DestChainStatusSchema),\n bridge: optional(string()),\n isExpectedToken: optional(boolean()),\n isUnrecognizedRouterAddress: optional(boolean()),\n refuel: optional(RefuelStatusResponseSchema),\n});\n\nexport const validateBridgeStatusResponse = (data: unknown) => {\n const validationFailures: { [path: string]: string } = {};\n try {\n assert(data, StatusResponseSchema);\n } catch (error) {\n if (error instanceof StructError) {\n error.failures().forEach(({ branch, path, message }) => {\n const pathString = path?.join('.') || 'unknown';\n validationFailures[pathString] =\n `[${branch?.[0]?.bridge || 'unknown'}] ${message}`;\n });\n }\n throw error;\n } finally {\n if (Object.keys(validationFailures).length > 0) {\n console.error(`Bridge status validation failed`, validationFailures);\n }\n }\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/bridge-status-controller",
3
- "version": "38.0.1-preview-332b557",
3
+ "version": "38.1.0-preview-a89812f5",
4
4
  "description": "Manages bridge-related status fetching functionality for MetaMask",
5
5
  "keywords": [
6
6
  "MetaMask",
@@ -59,7 +59,7 @@
59
59
  "devDependencies": {
60
60
  "@metamask/accounts-controller": "^32.0.2",
61
61
  "@metamask/auto-changelog": "^3.4.4",
62
- "@metamask/bridge-controller": "^39.0.1",
62
+ "@metamask/bridge-controller": "^39.1.0",
63
63
  "@metamask/gas-fee-controller": "^24.0.0",
64
64
  "@metamask/network-controller": "^24.1.0",
65
65
  "@metamask/snaps-controllers": "^14.0.1",