@metamask/bridge-controller 70.0.1 → 70.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -1
- package/dist/bridge-controller-method-action-types.cjs +7 -0
- package/dist/bridge-controller-method-action-types.cjs.map +1 -0
- package/dist/bridge-controller-method-action-types.d.cts +38 -0
- package/dist/bridge-controller-method-action-types.d.cts.map +1 -0
- package/dist/bridge-controller-method-action-types.d.mts +38 -0
- package/dist/bridge-controller-method-action-types.d.mts.map +1 -0
- package/dist/bridge-controller-method-action-types.mjs +6 -0
- package/dist/bridge-controller-method-action-types.mjs.map +1 -0
- package/dist/bridge-controller.cjs +10 -7
- package/dist/bridge-controller.cjs.map +1 -1
- package/dist/bridge-controller.d.cts.map +1 -1
- package/dist/bridge-controller.d.mts.map +1 -1
- package/dist/bridge-controller.mjs +10 -7
- package/dist/bridge-controller.mjs.map +1 -1
- package/dist/constants/bridge.cjs.map +1 -1
- package/dist/constants/bridge.d.cts.map +1 -1
- package/dist/constants/bridge.d.mts.map +1 -1
- package/dist/constants/bridge.mjs.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/selectors.cjs.map +1 -1
- package/dist/selectors.mjs.map +1 -1
- package/dist/types.cjs +8 -0
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +14 -1
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +14 -1
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs +8 -0
- package/dist/types.mjs.map +1 -1
- package/dist/utils/assets.cjs.map +1 -1
- package/dist/utils/assets.d.cts.map +1 -1
- package/dist/utils/assets.d.mts.map +1 -1
- package/dist/utils/assets.mjs.map +1 -1
- package/dist/utils/bridge.cjs +1 -1
- package/dist/utils/bridge.cjs.map +1 -1
- package/dist/utils/bridge.d.cts.map +1 -1
- package/dist/utils/bridge.d.mts.map +1 -1
- package/dist/utils/bridge.mjs +1 -1
- package/dist/utils/bridge.mjs.map +1 -1
- package/dist/utils/caip-formatters.cjs +1 -1
- package/dist/utils/caip-formatters.cjs.map +1 -1
- package/dist/utils/caip-formatters.d.cts.map +1 -1
- package/dist/utils/caip-formatters.d.mts.map +1 -1
- package/dist/utils/caip-formatters.mjs +1 -1
- package/dist/utils/caip-formatters.mjs.map +1 -1
- package/dist/utils/feature-flags.cjs +1 -1
- package/dist/utils/feature-flags.cjs.map +1 -1
- package/dist/utils/feature-flags.d.cts.map +1 -1
- package/dist/utils/feature-flags.d.mts.map +1 -1
- package/dist/utils/feature-flags.mjs +1 -1
- package/dist/utils/feature-flags.mjs.map +1 -1
- package/dist/utils/fetch.cjs.map +1 -1
- package/dist/utils/fetch.d.cts +1 -1
- package/dist/utils/fetch.d.cts.map +1 -1
- package/dist/utils/fetch.d.mts +1 -1
- package/dist/utils/fetch.d.mts.map +1 -1
- package/dist/utils/fetch.mjs.map +1 -1
- package/dist/utils/metrics/properties.cjs +1 -1
- package/dist/utils/metrics/properties.cjs.map +1 -1
- package/dist/utils/metrics/properties.d.cts +1 -1
- package/dist/utils/metrics/properties.d.cts.map +1 -1
- package/dist/utils/metrics/properties.d.mts +1 -1
- package/dist/utils/metrics/properties.d.mts.map +1 -1
- package/dist/utils/metrics/properties.mjs +1 -1
- package/dist/utils/metrics/properties.mjs.map +1 -1
- package/dist/utils/metrics/types.cjs.map +1 -1
- package/dist/utils/metrics/types.d.cts +1 -1
- package/dist/utils/metrics/types.d.cts.map +1 -1
- package/dist/utils/metrics/types.d.mts +1 -1
- package/dist/utils/metrics/types.d.mts.map +1 -1
- package/dist/utils/metrics/types.mjs.map +1 -1
- package/dist/utils/quote-fees.cjs +1 -1
- package/dist/utils/quote-fees.cjs.map +1 -1
- package/dist/utils/quote-fees.d.cts.map +1 -1
- package/dist/utils/quote-fees.d.mts.map +1 -1
- package/dist/utils/quote-fees.mjs +1 -1
- package/dist/utils/quote-fees.mjs.map +1 -1
- package/dist/utils/quote.cjs.map +1 -1
- package/dist/utils/quote.d.cts +1 -1
- package/dist/utils/quote.d.cts.map +1 -1
- package/dist/utils/quote.d.mts +1 -1
- package/dist/utils/quote.d.mts.map +1 -1
- package/dist/utils/quote.mjs.map +1 -1
- package/dist/utils/slippage.cjs.map +1 -1
- package/dist/utils/slippage.d.cts.map +1 -1
- package/dist/utils/slippage.d.mts.map +1 -1
- package/dist/utils/slippage.mjs.map +1 -1
- package/dist/utils/swaps.cjs +1 -1
- package/dist/utils/swaps.cjs.map +1 -1
- package/dist/utils/swaps.d.cts.map +1 -1
- package/dist/utils/swaps.d.mts.map +1 -1
- package/dist/utils/swaps.mjs +1 -1
- package/dist/utils/swaps.mjs.map +1 -1
- package/package.json +22 -20
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slippage.d.cts","sourceRoot":"","sources":["../../src/utils/slippage.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"slippage.d.cts","sourceRoot":"","sources":["../../src/utils/slippage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,qBAAiB;AAGpD,eAAO,MAAM,uBAAuB,MAAM,CAAC;AAK3C;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,4BAA4B,oEAMpC,QACD,KACE,mBAAmB,EACnB,iBAAiB,GAAG,kBAAkB,GAAG,YAAY,GAAG,aAAa,CACtE,CACF,mBACgB,MAAM,EAAE,oBACP,MAAM,EAAE,wBAyB3B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slippage.d.mts","sourceRoot":"","sources":["../../src/utils/slippage.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"slippage.d.mts","sourceRoot":"","sources":["../../src/utils/slippage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,qBAAiB;AAGpD,eAAO,MAAM,uBAAuB,MAAM,CAAC;AAK3C;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,4BAA4B,oEAMpC,QACD,KACE,mBAAmB,EACnB,iBAAiB,GAAG,kBAAkB,GAAG,YAAY,GAAG,aAAa,CACtE,CACF,mBACgB,MAAM,EAAE,oBACP,MAAM,EAAE,wBAyB3B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slippage.mjs","sourceRoot":"","sources":["../../src/utils/slippage.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"slippage.mjs","sourceRoot":"","sources":["../../src/utils/slippage.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,qBAAiB;AAEzD,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,CAAC;AAC3C,MAAM,oBAAoB,GAAG,SAAS,CAAC;AACvC,MAAM,4BAA4B,GAAG,GAAG,CAAC;AACzC,MAAM,yBAAyB,GAAG,CAAC,CAAC;AAEpC;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAC1C,EACE,eAAe,EACf,gBAAgB,EAChB,UAAU,EACV,WAAW,GAMZ,EACD,cAAyB,EACzB,eAA0B,EAC1B,EAAE;IACF,IAAI,CAAC,UAAU,IAAI,YAAY,CAAC,UAAU,EAAE,WAAW,CAAC,EAAE,CAAC;QACzD,OAAO,uBAAuB,CAAC;IACjC,CAAC;IAED,IAAI,eAAe,CAAC,UAAU,CAAC,EAAE,CAAC;QAChC,OAAO,oBAAoB,CAAC;IAC9B,CAAC;IAED,IACE,eAAe;QACf,gBAAgB;QAChB,cAAc;YACZ,EAAE,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE,CAAC;aAC9C,QAAQ,CAAC,eAAe,CAAC,WAAW,EAAE,CAAC;QAC1C,kFAAkF;QAClF,CAAC,eAAe,IAAI,cAAc,CAAC;YACjC,EAAE,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE,CAAC;aAC9C,QAAQ,CAAC,gBAAgB,CAAC,WAAW,EAAE,CAAC,EAC3C,CAAC;QACD,OAAO,4BAA4B,CAAC;IACtC,CAAC;IAED,OAAO,yBAAyB,CAAC;AACnC,CAAC,CAAC","sourcesContent":["import type { GenericQuoteRequest } from '../types';\nimport { isCrossChain, isSolanaChainId } from './bridge';\n\nexport const BRIDGE_DEFAULT_SLIPPAGE = 0.5;\nconst SWAP_SOLANA_SLIPPAGE = undefined;\nconst SWAP_EVM_STABLECOIN_SLIPPAGE = 0.5;\nconst SWAP_EVM_DEFAULT_SLIPPAGE = 2;\n\n/**\n * Calculates the appropriate slippage based on the transaction context\n *\n * Rules:\n * - Bridge (cross-chain): Always 0.5%\n * - Swap on Solana: Always undefined (AUTO mode)\n * - Swap on EVM stablecoin pairs (same chain only): 0.5%\n * - Swap on EVM other pairs: 2%\n *\n * @param options - the options for the destination chain\n * @param options.srcTokenAddress - the source token address\n * @param options.destTokenAddress - the destination token address\n * @param options.srcChainId - the source chain id\n * @param options.destChainId - the destination chain id\n * @param srcStablecoins - the list of stablecoins on the source chain\n * @param destStablecoins - the list of stablecoins on the destination chain\n \n * @returns the default slippage percentage for the chain and token pair\n */\nexport const getDefaultSlippagePercentage = (\n {\n srcTokenAddress,\n destTokenAddress,\n srcChainId,\n destChainId,\n }: Partial<\n Pick<\n GenericQuoteRequest,\n 'srcTokenAddress' | 'destTokenAddress' | 'srcChainId' | 'destChainId'\n >\n >,\n srcStablecoins?: string[],\n destStablecoins?: string[],\n) => {\n if (!srcChainId || isCrossChain(srcChainId, destChainId)) {\n return BRIDGE_DEFAULT_SLIPPAGE;\n }\n\n if (isSolanaChainId(srcChainId)) {\n return SWAP_SOLANA_SLIPPAGE;\n }\n\n if (\n srcTokenAddress &&\n destTokenAddress &&\n srcStablecoins\n ?.map((stablecoin) => stablecoin.toLowerCase())\n .includes(srcTokenAddress.toLowerCase()) &&\n // If destChainId is undefined, treat req as a swap and fallback to srcStablecoins\n (destStablecoins ?? srcStablecoins)\n ?.map((stablecoin) => stablecoin.toLowerCase())\n .includes(destTokenAddress.toLowerCase())\n ) {\n return SWAP_EVM_STABLECOIN_SLIPPAGE;\n }\n\n return SWAP_EVM_DEFAULT_SLIPPAGE;\n};\n"]}
|
package/dist/utils/swaps.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.fetchTokens = exports.DEV_BASE_URL = exports.API_BASE_URL = exports.getSwapsContractAddress = exports.isValidSwapsContractAddress = void 0;
|
|
4
|
-
const caip_formatters_1 = require("./caip-formatters.cjs");
|
|
5
4
|
const chains_1 = require("../constants/chains.cjs");
|
|
6
5
|
const swaps_1 = require("../constants/swaps.cjs");
|
|
7
6
|
const tokens_1 = require("../constants/tokens.cjs");
|
|
7
|
+
const caip_formatters_1 = require("./caip-formatters.cjs");
|
|
8
8
|
/**
|
|
9
9
|
* Checks if the given contract address is valid for the given chain ID.
|
|
10
10
|
*
|
package/dist/utils/swaps.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"swaps.cjs","sourceRoot":"","sources":["../../src/utils/swaps.ts"],"names":[],"mappings":";;;AAEA,
|
|
1
|
+
{"version":3,"file":"swaps.cjs","sourceRoot":"","sources":["../../src/utils/swaps.ts"],"names":[],"mappings":";;;AAEA,oDAAgD;AAChD,kDAG4B;AAC5B,oDAG6B;AAE7B,2DAAuD;AAEvD;;;;;;GAMG;AACH,SAAgB,2BAA2B,CACzC,OAAY,EACZ,QAAyB;IAEzB,IAAI,CAAC,QAAQ,IAAI,CAAC,kCAA0B,CAAC,OAAO,CAAC,EAAE,CAAC;QACtD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,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EH,MAAM,gBAAgB,GACpB,wCAA+B,CAC7B,OAAuD,CACxD,CAAC;IAEJ,cAAc,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;IACtC,OAAO,cAAc,CAAC;AACxB,CAAC;AA5BD,kCA4BC","sourcesContent":["import type { Hex } from '@metamask/utils';\n\nimport { CHAIN_IDS } from '../constants/chains';\nimport {\n ALLOWED_CONTRACT_ADDRESSES,\n SWAPS_CONTRACT_ADDRESSES,\n} from '../constants/swaps';\nimport {\n DEFAULT_TOKEN_ADDRESS,\n SWAPS_CHAINID_DEFAULT_TOKEN_MAP,\n} from '../constants/tokens';\nimport type { FetchFunction } from '../types';\nimport { formatChainIdToDec } from './caip-formatters';\n\n/**\n * Checks if the given contract address is valid for the given chain ID.\n *\n * @param chainId - The chain ID.\n * @param contract - The contract address.\n * @returns True if the contract address is valid, false otherwise.\n */\nexport function isValidSwapsContractAddress(\n chainId: Hex,\n contract: Hex | undefined,\n): boolean {\n if (!contract || !ALLOWED_CONTRACT_ADDRESSES[chainId]) {\n return false;\n }\n return ALLOWED_CONTRACT_ADDRESSES[chainId].some(\n (allowedContract) =>\n contract.toLowerCase() === allowedContract.toLowerCase(),\n );\n}\n\n/**\n * Gets the swaps contract address for the given chain ID.\n *\n * @param chainId - The chain ID.\n * @returns The swaps contract address.\n */\nexport function getSwapsContractAddress(chainId: Hex): string {\n return SWAPS_CONTRACT_ADDRESSES[chainId];\n}\n\n/**\n * Gets the client ID header.\n *\n * @param clientId - The client ID.\n * @returns The client ID header.\n */\nfunction getClientIdHeader(clientId?: string) {\n if (!clientId) {\n return undefined;\n }\n return {\n 'X-Client-Id': clientId,\n };\n}\n\nexport const API_BASE_URL = 'https://swap.api.cx.metamask.io';\nexport const DEV_BASE_URL = 'https://swap.dev-api.cx.metamask.io';\n\nexport type SwapsToken = {\n address: string;\n symbol: string;\n name?: string;\n decimals: number;\n iconUrl?: string;\n occurrences?: number;\n};\n\n/**\n * Fetches token metadata from API URL.\n *\n * @param chainId - Current chainId.\n * @param fetchFn - Fetch function.\n * @param clientId - Client id.\n * @returns Promise resolving to an object containing token metadata.\n */\nexport async function fetchTokens(\n chainId: Hex,\n fetchFn: FetchFunction,\n clientId?: string,\n): Promise<SwapsToken[]> {\n const [apiChainId, apiBaseUrl] =\n chainId === CHAIN_IDS.LOCALHOST\n ? [CHAIN_IDS.MAINNET, DEV_BASE_URL]\n : [chainId, API_BASE_URL];\n\n const apiDecimalChainId = formatChainIdToDec(apiChainId);\n const tokenUrl = `${apiBaseUrl}/networks/${apiDecimalChainId}/tokens`;\n\n const tokens: SwapsToken[] = await fetchFn(tokenUrl, {\n headers: getClientIdHeader(clientId),\n });\n\n const filteredTokens = tokens.filter((token) => {\n return token.address !== DEFAULT_TOKEN_ADDRESS;\n });\n\n const nativeSwapsToken =\n SWAPS_CHAINID_DEFAULT_TOKEN_MAP[\n chainId as keyof typeof SWAPS_CHAINID_DEFAULT_TOKEN_MAP\n ];\n\n filteredTokens.push(nativeSwapsToken);\n return filteredTokens;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"swaps.d.cts","sourceRoot":"","sources":["../../src/utils/swaps.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;
|
|
1
|
+
{"version":3,"file":"swaps.d.cts","sourceRoot":"","sources":["../../src/utils/swaps.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAW3C,OAAO,KAAK,EAAE,aAAa,EAAE,qBAAiB;AAG9C;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,GAAG,EACZ,QAAQ,EAAE,GAAG,GAAG,SAAS,GACxB,OAAO,CAQT;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,GAAG,GAAG,MAAM,CAE5D;AAiBD,eAAO,MAAM,YAAY,oCAAoC,CAAC;AAC9D,eAAO,MAAM,YAAY,wCAAwC,CAAC;AAElE,MAAM,MAAM,UAAU,GAAG;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAsB,WAAW,CAC/B,OAAO,EAAE,GAAG,EACZ,OAAO,EAAE,aAAa,EACtB,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,UAAU,EAAE,CAAC,CAwBvB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"swaps.d.mts","sourceRoot":"","sources":["../../src/utils/swaps.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;
|
|
1
|
+
{"version":3,"file":"swaps.d.mts","sourceRoot":"","sources":["../../src/utils/swaps.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAW3C,OAAO,KAAK,EAAE,aAAa,EAAE,qBAAiB;AAG9C;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,GAAG,EACZ,QAAQ,EAAE,GAAG,GAAG,SAAS,GACxB,OAAO,CAQT;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,GAAG,GAAG,MAAM,CAE5D;AAiBD,eAAO,MAAM,YAAY,oCAAoC,CAAC;AAC9D,eAAO,MAAM,YAAY,wCAAwC,CAAC;AAElE,MAAM,MAAM,UAAU,GAAG;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAsB,WAAW,CAC/B,OAAO,EAAE,GAAG,EACZ,OAAO,EAAE,aAAa,EACtB,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,UAAU,EAAE,CAAC,CAwBvB"}
|
package/dist/utils/swaps.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { formatChainIdToDec } from "./caip-formatters.mjs";
|
|
2
1
|
import { CHAIN_IDS } from "../constants/chains.mjs";
|
|
3
2
|
import { ALLOWED_CONTRACT_ADDRESSES, SWAPS_CONTRACT_ADDRESSES } from "../constants/swaps.mjs";
|
|
4
3
|
import { DEFAULT_TOKEN_ADDRESS, SWAPS_CHAINID_DEFAULT_TOKEN_MAP } from "../constants/tokens.mjs";
|
|
4
|
+
import { formatChainIdToDec } from "./caip-formatters.mjs";
|
|
5
5
|
/**
|
|
6
6
|
* Checks if the given contract address is valid for the given chain ID.
|
|
7
7
|
*
|
package/dist/utils/swaps.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"swaps.mjs","sourceRoot":"","sources":["../../src/utils/swaps.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"swaps.mjs","sourceRoot":"","sources":["../../src/utils/swaps.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,gCAA4B;AAChD,OAAO,EACL,0BAA0B,EAC1B,wBAAwB,EACzB,+BAA2B;AAC5B,OAAO,EACL,qBAAqB,EACrB,+BAA+B,EAChC,gCAA4B;AAE7B,OAAO,EAAE,kBAAkB,EAAE,8BAA0B;AAEvD;;;;;;GAMG;AACH,MAAM,UAAU,2BAA2B,CACzC,OAAY,EACZ,QAAyB;IAEzB,IAAI,CAAC,QAAQ,IAAI,CAAC,0BAA0B,CAAC,OAAO,CAAC,EAAE,CAAC;QACtD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OA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AAC;IAEH,MAAM,gBAAgB,GACpB,+BAA+B,CAC7B,OAAuD,CACxD,CAAC;IAEJ,cAAc,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;IACtC,OAAO,cAAc,CAAC;AACxB,CAAC","sourcesContent":["import type { Hex } from '@metamask/utils';\n\nimport { CHAIN_IDS } from '../constants/chains';\nimport {\n ALLOWED_CONTRACT_ADDRESSES,\n SWAPS_CONTRACT_ADDRESSES,\n} from '../constants/swaps';\nimport {\n DEFAULT_TOKEN_ADDRESS,\n SWAPS_CHAINID_DEFAULT_TOKEN_MAP,\n} from '../constants/tokens';\nimport type { FetchFunction } from '../types';\nimport { formatChainIdToDec } from './caip-formatters';\n\n/**\n * Checks if the given contract address is valid for the given chain ID.\n *\n * @param chainId - The chain ID.\n * @param contract - The contract address.\n * @returns True if the contract address is valid, false otherwise.\n */\nexport function isValidSwapsContractAddress(\n chainId: Hex,\n contract: Hex | undefined,\n): boolean {\n if (!contract || !ALLOWED_CONTRACT_ADDRESSES[chainId]) {\n return false;\n }\n return ALLOWED_CONTRACT_ADDRESSES[chainId].some(\n (allowedContract) =>\n contract.toLowerCase() === allowedContract.toLowerCase(),\n );\n}\n\n/**\n * Gets the swaps contract address for the given chain ID.\n *\n * @param chainId - The chain ID.\n * @returns The swaps contract address.\n */\nexport function getSwapsContractAddress(chainId: Hex): string {\n return SWAPS_CONTRACT_ADDRESSES[chainId];\n}\n\n/**\n * Gets the client ID header.\n *\n * @param clientId - The client ID.\n * @returns The client ID header.\n */\nfunction getClientIdHeader(clientId?: string) {\n if (!clientId) {\n return undefined;\n }\n return {\n 'X-Client-Id': clientId,\n };\n}\n\nexport const API_BASE_URL = 'https://swap.api.cx.metamask.io';\nexport const DEV_BASE_URL = 'https://swap.dev-api.cx.metamask.io';\n\nexport type SwapsToken = {\n address: string;\n symbol: string;\n name?: string;\n decimals: number;\n iconUrl?: string;\n occurrences?: number;\n};\n\n/**\n * Fetches token metadata from API URL.\n *\n * @param chainId - Current chainId.\n * @param fetchFn - Fetch function.\n * @param clientId - Client id.\n * @returns Promise resolving to an object containing token metadata.\n */\nexport async function fetchTokens(\n chainId: Hex,\n fetchFn: FetchFunction,\n clientId?: string,\n): Promise<SwapsToken[]> {\n const [apiChainId, apiBaseUrl] =\n chainId === CHAIN_IDS.LOCALHOST\n ? [CHAIN_IDS.MAINNET, DEV_BASE_URL]\n : [chainId, API_BASE_URL];\n\n const apiDecimalChainId = formatChainIdToDec(apiChainId);\n const tokenUrl = `${apiBaseUrl}/networks/${apiDecimalChainId}/tokens`;\n\n const tokens: SwapsToken[] = await fetchFn(tokenUrl, {\n headers: getClientIdHeader(clientId),\n });\n\n const filteredTokens = tokens.filter((token) => {\n return token.address !== DEFAULT_TOKEN_ADDRESS;\n });\n\n const nativeSwapsToken =\n SWAPS_CHAINID_DEFAULT_TOKEN_MAP[\n chainId as keyof typeof SWAPS_CHAINID_DEFAULT_TOKEN_MAP\n ];\n\n filteredTokens.push(nativeSwapsToken);\n return filteredTokens;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,21 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/bridge-controller",
|
|
3
|
-
"version": "70.0
|
|
3
|
+
"version": "70.1.0",
|
|
4
4
|
"description": "Manages bridge-related quote fetching functionality for MetaMask",
|
|
5
5
|
"keywords": [
|
|
6
|
-
"
|
|
7
|
-
"
|
|
6
|
+
"Ethereum",
|
|
7
|
+
"MetaMask"
|
|
8
8
|
],
|
|
9
9
|
"homepage": "https://github.com/MetaMask/core/tree/main/packages/bridge-controller#readme",
|
|
10
10
|
"bugs": {
|
|
11
11
|
"url": "https://github.com/MetaMask/core/issues"
|
|
12
12
|
},
|
|
13
|
+
"license": "MIT",
|
|
13
14
|
"repository": {
|
|
14
15
|
"type": "git",
|
|
15
16
|
"url": "https://github.com/MetaMask/core.git"
|
|
16
17
|
},
|
|
17
|
-
"
|
|
18
|
+
"files": [
|
|
19
|
+
"dist/"
|
|
20
|
+
],
|
|
18
21
|
"sideEffects": false,
|
|
22
|
+
"main": "./dist/index.cjs",
|
|
23
|
+
"types": "./dist/index.d.cts",
|
|
19
24
|
"exports": {
|
|
20
25
|
".": {
|
|
21
26
|
"import": {
|
|
@@ -29,17 +34,17 @@
|
|
|
29
34
|
},
|
|
30
35
|
"./package.json": "./package.json"
|
|
31
36
|
},
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
],
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public",
|
|
39
|
+
"registry": "https://registry.npmjs.org/"
|
|
40
|
+
},
|
|
37
41
|
"scripts": {
|
|
38
42
|
"build": "ts-bridge --project tsconfig.build.json --verbose --clean --no-references",
|
|
39
43
|
"build:all": "ts-bridge --project tsconfig.build.json --verbose --clean",
|
|
40
44
|
"build:docs": "typedoc",
|
|
41
45
|
"changelog:update": "../../scripts/update-changelog.sh @metamask/bridge-controller",
|
|
42
46
|
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/bridge-controller",
|
|
47
|
+
"generate-method-action-types": "tsx ../../packages/messenger/src/generate-action-types/cli.ts",
|
|
43
48
|
"since-latest-release": "../../scripts/since-latest-release.sh",
|
|
44
49
|
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
|
|
45
50
|
"test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",
|
|
@@ -52,14 +57,14 @@
|
|
|
52
57
|
"@ethersproject/constants": "^5.7.0",
|
|
53
58
|
"@ethersproject/contracts": "^5.7.0",
|
|
54
59
|
"@ethersproject/providers": "^5.7.0",
|
|
55
|
-
"@metamask/accounts-controller": "^37.
|
|
56
|
-
"@metamask/assets-controller": "^
|
|
57
|
-
"@metamask/assets-controllers": "^
|
|
58
|
-
"@metamask/base-controller": "^9.0
|
|
60
|
+
"@metamask/accounts-controller": "^37.2.0",
|
|
61
|
+
"@metamask/assets-controller": "^5.0.1",
|
|
62
|
+
"@metamask/assets-controllers": "^104.0.0",
|
|
63
|
+
"@metamask/base-controller": "^9.1.0",
|
|
59
64
|
"@metamask/controller-utils": "^11.20.0",
|
|
60
65
|
"@metamask/gas-fee-controller": "^26.1.1",
|
|
61
66
|
"@metamask/keyring-api": "^21.6.0",
|
|
62
|
-
"@metamask/messenger": "^1.
|
|
67
|
+
"@metamask/messenger": "^1.1.1",
|
|
63
68
|
"@metamask/metamask-eth-abis": "^3.1.1",
|
|
64
69
|
"@metamask/multichain-network-controller": "^3.0.6",
|
|
65
70
|
"@metamask/network-controller": "^30.0.1",
|
|
@@ -67,14 +72,14 @@
|
|
|
67
72
|
"@metamask/profile-sync-controller": "^28.0.2",
|
|
68
73
|
"@metamask/remote-feature-flag-controller": "^4.2.0",
|
|
69
74
|
"@metamask/snaps-controllers": "^19.0.0",
|
|
70
|
-
"@metamask/transaction-controller": "^64.
|
|
75
|
+
"@metamask/transaction-controller": "^64.2.0",
|
|
71
76
|
"@metamask/utils": "^11.9.0",
|
|
72
77
|
"bignumber.js": "^9.1.2",
|
|
73
78
|
"reselect": "^5.1.1",
|
|
74
79
|
"uuid": "^8.3.2"
|
|
75
80
|
},
|
|
76
81
|
"devDependencies": {
|
|
77
|
-
"@metamask/auto-changelog": "^
|
|
82
|
+
"@metamask/auto-changelog": "^6.0.0",
|
|
78
83
|
"@metamask/eth-json-rpc-provider": "^6.0.1",
|
|
79
84
|
"@metamask/superstruct": "^3.1.0",
|
|
80
85
|
"@ts-bridge/cli": "^0.6.4",
|
|
@@ -85,15 +90,12 @@
|
|
|
85
90
|
"lodash": "^4.17.21",
|
|
86
91
|
"nock": "^13.3.1",
|
|
87
92
|
"ts-jest": "^29.2.5",
|
|
93
|
+
"tsx": "^4.20.5",
|
|
88
94
|
"typedoc": "^0.25.13",
|
|
89
95
|
"typedoc-plugin-missing-exports": "^2.0.0",
|
|
90
96
|
"typescript": "~5.3.3"
|
|
91
97
|
},
|
|
92
98
|
"engines": {
|
|
93
99
|
"node": "^18.18 || >=20"
|
|
94
|
-
},
|
|
95
|
-
"publishConfig": {
|
|
96
|
-
"access": "public",
|
|
97
|
-
"registry": "https://registry.npmjs.org/"
|
|
98
100
|
}
|
|
99
101
|
}
|