@metamask-previews/bridge-controller 22.0.0-preview-aa280426 → 24.0.0-preview-a578ea2
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/bridge-controller.cjs +36 -25
- package/dist/bridge-controller.cjs.map +1 -1
- package/dist/bridge-controller.d.cts +3 -2
- package/dist/bridge-controller.d.cts.map +1 -1
- package/dist/bridge-controller.d.mts +3 -2
- package/dist/bridge-controller.d.mts.map +1 -1
- package/dist/bridge-controller.mjs +37 -26
- package/dist/bridge-controller.mjs.map +1 -1
- package/dist/constants/traces.cjs +9 -0
- package/dist/constants/traces.cjs.map +1 -0
- package/dist/constants/traces.d.cts +5 -0
- package/dist/constants/traces.d.cts.map +1 -0
- package/dist/constants/traces.d.mts +5 -0
- package/dist/constants/traces.d.mts.map +1 -0
- package/dist/constants/traces.mjs +6 -0
- package/dist/constants/traces.mjs.map +1 -0
- package/dist/index.cjs +3 -2
- 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 +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/utils/bridge.cjs +20 -1
- package/dist/utils/bridge.cjs.map +1 -1
- package/dist/utils/bridge.d.cts +9 -1
- package/dist/utils/bridge.d.cts.map +1 -1
- package/dist/utils/bridge.d.mts +9 -1
- package/dist/utils/bridge.d.mts.map +1 -1
- package/dist/utils/bridge.mjs +18 -0
- package/dist/utils/bridge.mjs.map +1 -1
- package/dist/utils/metrics/properties.cjs +2 -6
- package/dist/utils/metrics/properties.cjs.map +1 -1
- package/dist/utils/metrics/properties.d.cts.map +1 -1
- package/dist/utils/metrics/properties.d.mts.map +1 -1
- package/dist/utils/metrics/properties.mjs +3 -7
- package/dist/utils/metrics/properties.mjs.map +1 -1
- package/package.json +2 -2
@@ -1 +1 @@
|
|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AO,KAAK,wBAAwB,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;AAChE,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CACvC,MAAc,EACd,OAA0B,EAC1B,EAAE;IACF,IAAI,CAAC,MAAM,IAAI,CAAC,OAAO,EAAE;QACvB,OAAO,KAAK,CAAC;KACd;IAED,OAAO,MAAM,KAAK,wBAAwB,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;AAC9D,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,OAAuB,EAAE,EAAE,CACzD,OAAO,KAAK,WAAW,IAAI,4DAA4D;IACvF,OAAO,KAAK,EAAE,IAAI,qEAAqE;IACvF,CAAC,OAAO;IACR,OAAO,CAAC,QAAQ,CAAC,kCAAkC,CAAC,IAAI,iEAAiE;IACzH,CAAC,wBAAwB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CACrD,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,CACtE,CAAC,CAAC,qDAAqD;AAE1D;;;;;GAKG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,OAA4C,EAC5C,EAAE;IACF,IAAI,aAAa,CAAC,OAAO,CAAC,EAAE;QAC1B,OAAO,OAAO,KAAK,QAAQ,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;KAChD;IACD,OAAO,OAAO,CAAC,QAAQ,EAAE,KAAK,OAAO,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;AAC1D,CAAC,CAAC","sourcesContent":["import { AddressZero } from '@ethersproject/constants';\nimport { Contract } from '@ethersproject/contracts';\nimport { SolScope } from '@metamask/keyring-api';\nimport { abiERC20 } from '@metamask/metamask-eth-abis';\nimport type { CaipAssetType, CaipChainId } from '@metamask/utils';\nimport { isCaipChainId, isStrictHexString, type Hex } from '@metamask/utils';\n\nimport {\n formatChainIdToCaip,\n formatChainIdToDec,\n formatChainIdToHex,\n} from './caip-formatters';\nimport {\n DEFAULT_BRIDGE_CONTROLLER_STATE,\n ETH_USDT_ADDRESS,\n METABRIDGE_ETHEREUM_ADDRESS,\n} from '../constants/bridge';\nimport { CHAIN_IDS } from '../constants/chains';\nimport {\n SWAPS_CHAINID_DEFAULT_TOKEN_MAP,\n SYMBOL_TO_SLIP44_MAP,\n type SupportedSwapsNativeCurrencySymbols,\n} from '../constants/tokens';\nimport type { BridgeAsset, BridgeControllerState } from '../types';\nimport { ChainId } from '../types';\n\nexport const getDefaultBridgeControllerState = (): BridgeControllerState => {\n return DEFAULT_BRIDGE_CONTROLLER_STATE;\n};\n\n/**\n * Returns the native assetType for a given chainId and native currency symbol\n * Note that the return value is used as the assetId although it is a CaipAssetType\n *\n * @param chainId - The chainId to get the native assetType for\n * @param nativeCurrencySymbol - The native currency symbol for the given chainId\n * @returns The native assetType for the given chainId\n */\nconst getNativeAssetCaipAssetType = (\n chainId: CaipChainId,\n nativeCurrencySymbol: SupportedSwapsNativeCurrencySymbols,\n): CaipAssetType => {\n return `${formatChainIdToCaip(chainId)}/${SYMBOL_TO_SLIP44_MAP[nativeCurrencySymbol]}`;\n};\n\n/**\n * Returns the native swaps or bridge asset for a given chainId\n *\n * @param chainId - The chainId to get the default token for\n * @returns The native asset for the given chainId\n * @throws If no native asset is defined for the given chainId\n */\nexport const getNativeAssetForChainId = (\n chainId: string | number | Hex | CaipChainId,\n): BridgeAsset => {\n const chainIdInCaip = formatChainIdToCaip(chainId);\n const nativeToken =\n SWAPS_CHAINID_DEFAULT_TOKEN_MAP[\n formatChainIdToCaip(\n chainId,\n ) as keyof typeof SWAPS_CHAINID_DEFAULT_TOKEN_MAP\n ] ??\n SWAPS_CHAINID_DEFAULT_TOKEN_MAP[\n formatChainIdToHex(\n chainId,\n ) as keyof typeof SWAPS_CHAINID_DEFAULT_TOKEN_MAP\n ];\n\n if (!nativeToken) {\n throw new Error(\n `No XChain Swaps native asset found for chainId: ${chainId}`,\n );\n }\n\n return {\n ...nativeToken,\n chainId: formatChainIdToDec(chainId),\n assetId: getNativeAssetCaipAssetType(chainIdInCaip, nativeToken.symbol),\n };\n};\n\n/**\n * A function to return the txParam data for setting allowance to 0 for USDT on Ethereum\n *\n * @returns The txParam data that will reset allowance to 0, combine it with the approval tx params received from Bridge API\n */\nexport const getEthUsdtResetData = () => {\n const UsdtContractInterface = new Contract(ETH_USDT_ADDRESS, abiERC20)\n .interface;\n const data = UsdtContractInterface.encodeFunctionData('approve', [\n METABRIDGE_ETHEREUM_ADDRESS,\n '0',\n ]);\n\n return data;\n};\n\nexport const isEthUsdt = (chainId: Hex, address: string) =>\n chainId === CHAIN_IDS.MAINNET &&\n address.toLowerCase() === ETH_USDT_ADDRESS.toLowerCase();\n\nexport const sumHexes = (...hexStrings: string[]): Hex => {\n if (hexStrings.length === 0) {\n return '0x0';\n }\n\n const sum = hexStrings.reduce((acc, hex) => acc + BigInt(hex), BigInt(0));\n return `0x${sum.toString(16)}`;\n};\n\n/**\n * Checks whether the provided address is strictly equal to the address for\n * the default swaps token of the provided chain.\n *\n * @param address - The string to compare to the default token address\n * @param chainId - The hex encoded chain ID of the default swaps token to check\n * @returns Whether the address is the provided chain's default token address\n */\nexport const isSwapsDefaultTokenAddress = (\n address: string,\n chainId: Hex | CaipChainId,\n) => {\n if (!address || !chainId) {\n return false;\n }\n\n return address === getNativeAssetForChainId(chainId)?.address;\n};\n\n/**\n * Checks whether the provided symbol is strictly equal to the symbol for\n * the default swaps token of the provided chain.\n *\n * @param symbol - The string to compare to the default token symbol\n * @param chainId - The hex encoded chain ID of the default swaps token to check\n * @returns Whether the symbol is the provided chain's default token symbol\n */\nexport const isSwapsDefaultTokenSymbol = (\n symbol: string,\n chainId: Hex | CaipChainId,\n) => {\n if (!symbol || !chainId) {\n return false;\n }\n\n return symbol === getNativeAssetForChainId(chainId)?.symbol;\n};\n\n/**\n * Checks whether the address is a native asset in any supported xchain swaps network\n *\n * @param address - The address to check\n * @returns Whether the address is a native asset\n */\nexport const isNativeAddress = (address?: string | null) =>\n address === AddressZero || // bridge and swap apis set the native asset address to zero\n address === '' || // assets controllers set the native asset address to an empty string\n !address ||\n address.endsWith('11111111111111111111111111111111') || // token-api and bridge-api use this as the solana native assetId\n [getNativeAssetForChainId(ChainId.SOLANA).assetId].some(\n (assetId) => assetId.includes(address) && !isStrictHexString(address),\n ); // solana native assetId used in the extension client\n\n/**\n * Checks whether the chainId matches Solana in CaipChainId or number format\n *\n * @param chainId - The chainId to check\n * @returns Whether the chainId is Solana\n */\nexport const isSolanaChainId = (\n chainId: Hex | number | CaipChainId | string,\n) => {\n if (isCaipChainId(chainId)) {\n return chainId === SolScope.Mainnet.toString();\n }\n return chainId.toString() === ChainId.SOLANA.toString();\n};\n"]}
|
1
|
+
{"version":3,"file":"bridge.mjs","sourceRoot":"","sources":["../../src/utils/bridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,iCAAiC;AACvD,OAAO,EAAE,QAAQ,EAAE,iCAAiC;AACpD,OAAO,EAAE,QAAQ,EAAE,8BAA8B;AACjD,OAAO,EAAE,QAAQ,EAAE,oCAAoC;AAEvD,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAY,wBAAwB;AAE7E,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,kBAAkB,EACnB,8BAA0B;AAC3B,OAAO,EACL,+BAA+B,EAC/B,gBAAgB,EAChB,2BAA2B,EAC5B,gCAA4B;AAC7B,OAAO,EAAE,SAAS,EAAE,gCAA4B;AAChD,OAAO,EACL,+BAA+B,EAC/B,oBAAoB,EAErB,gCAA4B;AAM7B,OAAO,EAAE,OAAO,EAAE,qBAAiB;AAEnC,MAAM,CAAC,MAAM,+BAA+B,GAAG,GAA0B,EAAE;IACzE,OAAO,+BAA+B,CAAC;AACzC,CAAC,CA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AAE,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,CACtE,CAAC,CAAC,qDAAqD;AAE1D;;;;;GAKG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,OAA4C,EAC5C,EAAE;IACF,IAAI,aAAa,CAAC,OAAO,CAAC,EAAE;QAC1B,OAAO,OAAO,KAAK,QAAQ,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;KAChD;IACD,OAAO,OAAO,CAAC,QAAQ,EAAE,KAAK,OAAO,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;AAC1D,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAC1B,UAA6C,EAC7C,WAAgD,EAChD,EAAE;IACF,IAAI;QACF,IAAI,CAAC,WAAW,EAAE;YAChB,OAAO,KAAK,CAAC;SACd;QACD,OAAO,mBAAmB,CAAC,UAAU,CAAC,KAAK,mBAAmB,CAAC,WAAW,CAAC,CAAC;KAC7E;IAAC,MAAM;QACN,OAAO,KAAK,CAAC;KACd;AACH,CAAC,CAAC","sourcesContent":["import { AddressZero } from '@ethersproject/constants';\nimport { Contract } from '@ethersproject/contracts';\nimport { SolScope } from '@metamask/keyring-api';\nimport { abiERC20 } from '@metamask/metamask-eth-abis';\nimport type { CaipAssetType, CaipChainId } from '@metamask/utils';\nimport { isCaipChainId, isStrictHexString, type Hex } from '@metamask/utils';\n\nimport {\n formatChainIdToCaip,\n formatChainIdToDec,\n formatChainIdToHex,\n} from './caip-formatters';\nimport {\n DEFAULT_BRIDGE_CONTROLLER_STATE,\n ETH_USDT_ADDRESS,\n METABRIDGE_ETHEREUM_ADDRESS,\n} from '../constants/bridge';\nimport { CHAIN_IDS } from '../constants/chains';\nimport {\n SWAPS_CHAINID_DEFAULT_TOKEN_MAP,\n SYMBOL_TO_SLIP44_MAP,\n type SupportedSwapsNativeCurrencySymbols,\n} from '../constants/tokens';\nimport type {\n BridgeAsset,\n BridgeControllerState,\n GenericQuoteRequest,\n} from '../types';\nimport { ChainId } from '../types';\n\nexport const getDefaultBridgeControllerState = (): BridgeControllerState => {\n return DEFAULT_BRIDGE_CONTROLLER_STATE;\n};\n\n/**\n * Returns the native assetType for a given chainId and native currency symbol\n * Note that the return value is used as the assetId although it is a CaipAssetType\n *\n * @param chainId - The chainId to get the native assetType for\n * @param nativeCurrencySymbol - The native currency symbol for the given chainId\n * @returns The native assetType for the given chainId\n */\nconst getNativeAssetCaipAssetType = (\n chainId: CaipChainId,\n nativeCurrencySymbol: SupportedSwapsNativeCurrencySymbols,\n): CaipAssetType => {\n return `${formatChainIdToCaip(chainId)}/${SYMBOL_TO_SLIP44_MAP[nativeCurrencySymbol]}`;\n};\n\n/**\n * Returns the native swaps or bridge asset for a given chainId\n *\n * @param chainId - The chainId to get the default token for\n * @returns The native asset for the given chainId\n * @throws If no native asset is defined for the given chainId\n */\nexport const getNativeAssetForChainId = (\n chainId: string | number | Hex | CaipChainId,\n): BridgeAsset => {\n const chainIdInCaip = formatChainIdToCaip(chainId);\n const nativeToken =\n SWAPS_CHAINID_DEFAULT_TOKEN_MAP[\n formatChainIdToCaip(\n chainId,\n ) as keyof typeof SWAPS_CHAINID_DEFAULT_TOKEN_MAP\n ] ??\n SWAPS_CHAINID_DEFAULT_TOKEN_MAP[\n formatChainIdToHex(\n chainId,\n ) as keyof typeof SWAPS_CHAINID_DEFAULT_TOKEN_MAP\n ];\n\n if (!nativeToken) {\n throw new Error(\n `No XChain Swaps native asset found for chainId: ${chainId}`,\n );\n }\n\n return {\n ...nativeToken,\n chainId: formatChainIdToDec(chainId),\n assetId: getNativeAssetCaipAssetType(chainIdInCaip, nativeToken.symbol),\n };\n};\n\n/**\n * A function to return the txParam data for setting allowance to 0 for USDT on Ethereum\n *\n * @returns The txParam data that will reset allowance to 0, combine it with the approval tx params received from Bridge API\n */\nexport const getEthUsdtResetData = () => {\n const UsdtContractInterface = new Contract(ETH_USDT_ADDRESS, abiERC20)\n .interface;\n const data = UsdtContractInterface.encodeFunctionData('approve', [\n METABRIDGE_ETHEREUM_ADDRESS,\n '0',\n ]);\n\n return data;\n};\n\nexport const isEthUsdt = (chainId: Hex, address: string) =>\n chainId === CHAIN_IDS.MAINNET &&\n address.toLowerCase() === ETH_USDT_ADDRESS.toLowerCase();\n\nexport const sumHexes = (...hexStrings: string[]): Hex => {\n if (hexStrings.length === 0) {\n return '0x0';\n }\n\n const sum = hexStrings.reduce((acc, hex) => acc + BigInt(hex), BigInt(0));\n return `0x${sum.toString(16)}`;\n};\n\n/**\n * Checks whether the provided address is strictly equal to the address for\n * the default swaps token of the provided chain.\n *\n * @param address - The string to compare to the default token address\n * @param chainId - The hex encoded chain ID of the default swaps token to check\n * @returns Whether the address is the provided chain's default token address\n */\nexport const isSwapsDefaultTokenAddress = (\n address: string,\n chainId: Hex | CaipChainId,\n) => {\n if (!address || !chainId) {\n return false;\n }\n\n return address === getNativeAssetForChainId(chainId)?.address;\n};\n\n/**\n * Checks whether the provided symbol is strictly equal to the symbol for\n * the default swaps token of the provided chain.\n *\n * @param symbol - The string to compare to the default token symbol\n * @param chainId - The hex encoded chain ID of the default swaps token to check\n * @returns Whether the symbol is the provided chain's default token symbol\n */\nexport const isSwapsDefaultTokenSymbol = (\n symbol: string,\n chainId: Hex | CaipChainId,\n) => {\n if (!symbol || !chainId) {\n return false;\n }\n\n return symbol === getNativeAssetForChainId(chainId)?.symbol;\n};\n\n/**\n * Checks whether the address is a native asset in any supported xchain swaps network\n *\n * @param address - The address to check\n * @returns Whether the address is a native asset\n */\nexport const isNativeAddress = (address?: string | null) =>\n address === AddressZero || // bridge and swap apis set the native asset address to zero\n address === '' || // assets controllers set the native asset address to an empty string\n !address ||\n address.endsWith('11111111111111111111111111111111') || // token-api and bridge-api use this as the solana native assetId\n [getNativeAssetForChainId(ChainId.SOLANA).assetId].some(\n (assetId) => assetId.includes(address) && !isStrictHexString(address),\n ); // solana native assetId used in the extension client\n\n/**\n * Checks whether the chainId matches Solana in CaipChainId or number format\n *\n * @param chainId - The chainId to check\n * @returns Whether the chainId is Solana\n */\nexport const isSolanaChainId = (\n chainId: Hex | number | CaipChainId | string,\n) => {\n if (isCaipChainId(chainId)) {\n return chainId === SolScope.Mainnet.toString();\n }\n return chainId.toString() === ChainId.SOLANA.toString();\n};\n\n/**\n * Checks whether the transaction is a cross-chain transaction by comparing the source and destination chainIds\n *\n * @param srcChainId - The source chainId\n * @param destChainId - The destination chainId\n * @returns Whether the transaction is a cross-chain transaction\n */\nexport const isCrossChain = (\n srcChainId: GenericQuoteRequest['srcChainId'],\n destChainId?: GenericQuoteRequest['destChainId'],\n) => {\n try {\n if (!destChainId) {\n return false;\n }\n return formatChainIdToCaip(srcChainId) !== formatChainIdToCaip(destChainId);\n } catch {\n return false;\n }\n};\n"]}
|
@@ -24,9 +24,7 @@ exports.toInputChangedPropertyValue = {
|
|
24
24
|
slippage: ({ slippage }) => (slippage ? Number(slippage) : slippage),
|
25
25
|
};
|
26
26
|
const getActionType = (srcChainId, destChainId) => {
|
27
|
-
if (srcChainId &&
|
28
|
-
(0, caip_formatters_1.formatChainIdToCaip)(srcChainId) ===
|
29
|
-
(0, caip_formatters_1.formatChainIdToCaip)(destChainId ?? srcChainId)) {
|
27
|
+
if (srcChainId && !(0, bridge_2.isCrossChain)(srcChainId, destChainId ?? srcChainId)) {
|
30
28
|
return constants_1.MetricsActionType.SWAPBRIDGE_V1;
|
31
29
|
}
|
32
30
|
return constants_1.MetricsActionType.CROSSCHAIN_V1;
|
@@ -37,9 +35,7 @@ const getActionTypeFromQuoteRequest = (quoteRequest) => {
|
|
37
35
|
};
|
38
36
|
exports.getActionTypeFromQuoteRequest = getActionTypeFromQuoteRequest;
|
39
37
|
const getSwapType = (srcChainId, destChainId) => {
|
40
|
-
if (srcChainId &&
|
41
|
-
(0, caip_formatters_1.formatChainIdToCaip)(srcChainId) ===
|
42
|
-
(0, caip_formatters_1.formatChainIdToCaip)(destChainId ?? srcChainId)) {
|
38
|
+
if (srcChainId && !(0, bridge_2.isCrossChain)(srcChainId, destChainId ?? srcChainId)) {
|
43
39
|
return constants_1.MetricsSwapType.SINGLE;
|
44
40
|
}
|
45
41
|
return constants_1.MetricsSwapType.CROSSCHAIN;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"properties.cjs","sourceRoot":"","sources":["../../../src/utils/metrics/properties.ts"],"names":[],"mappings":";;;AAEA,+CAAiE;AAGjE,uDAAyE;AAGzE,
|
1
|
+
{"version":3,"file":"properties.cjs","sourceRoot":"","sources":["../../../src/utils/metrics/properties.ts"],"names":[],"mappings":";;;AAEA,+CAAiE;AAGjE,uDAAyE;AAGzE,0CAAmE;AACnE,4DAG4B;AAEf,QAAA,yBAAyB,GAElC;IACF,eAAe,EAAE,cAAc;IAC/B,gBAAgB,EAAE,mBAAmB;IACrC,UAAU,EAAE,cAAc;IAC1B,WAAW,EAAE,mBAAmB;IAChC,QAAQ,EAAE,UAAU;CACrB,CAAC;AAEW,QAAA,2BAA2B,GAOpC;IACF,eAAe,EAAE,CAAC,EAAE,eAAe,EAAE,UAAU,EAAE,EAAE,EAAE,CACnD,UAAU;QACR,CAAC,CAAC,IAAA,wCAAsB,EAAC,eAAe,IAAI,EAAE,EAAE,UAAU,CAAC;QAC3D,CAAC,CAAC,SAAS;IACf,gBAAgB,EAAE,CAAC,EAAE,gBAAgB,EAAE,WAAW,EAAE,EAAE,EAAE,CACtD,WAAW;QACT,CAAC,CAAC,IAAA,wCAAsB,EAAC,gBAAgB,IAAI,EAAE,EAAE,WAAW,CAAC;QAC7D,CAAC,CAAC,SAAS;IACf,UAAU,EAAE,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,CAC7B,UAAU,CAAC,CAAC,CAAC,IAAA,qCAAmB,EAAC,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS;IAC1D,WAAW,EAAE,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE,CAC/B,W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, MetricsSwapType } from './constants';\nimport type { InputKeys, InputValues } from './types';\nimport type { AccountsControllerState } from '../../../../accounts-controller/src/AccountsController';\nimport { DEFAULT_BRIDGE_CONTROLLER_STATE } from '../../constants/bridge';\nimport type { BridgeControllerState, QuoteResponse, TxData } from '../../types';\nimport { type GenericQuoteRequest, type QuoteRequest } from '../../types';\nimport { getNativeAssetForChainId, isCrossChain } from '../bridge';\nimport {\n formatAddressToAssetId,\n formatChainIdToCaip,\n} from '../caip-formatters';\n\nexport const toInputChangedPropertyKey: Partial<\n Record<keyof QuoteRequest, InputKeys>\n> = {\n srcTokenAddress: 'token_source',\n destTokenAddress: 'token_destination',\n srcChainId: 'chain_source',\n destChainId: 'chain_destination',\n slippage: 'slippage',\n};\n\nexport const toInputChangedPropertyValue: Partial<\n Record<\n keyof typeof toInputChangedPropertyKey,\n (\n value: Partial<GenericQuoteRequest>,\n ) => InputValues[keyof InputValues] | undefined\n >\n> = {\n srcTokenAddress: ({ srcTokenAddress, srcChainId }) =>\n srcChainId\n ? formatAddressToAssetId(srcTokenAddress ?? '', srcChainId)\n : undefined,\n destTokenAddress: ({ destTokenAddress, destChainId }) =>\n destChainId\n ? formatAddressToAssetId(destTokenAddress ?? '', destChainId)\n : undefined,\n srcChainId: ({ srcChainId }) =>\n srcChainId ? formatChainIdToCaip(srcChainId) : undefined,\n destChainId: ({ destChainId }) =>\n destChainId ? formatChainIdToCaip(destChainId) : undefined,\n slippage: ({ slippage }) => (slippage ? Number(slippage) : slippage),\n};\n\nexport const getActionType = (\n srcChainId?: GenericQuoteRequest['srcChainId'],\n destChainId?: GenericQuoteRequest['destChainId'],\n) => {\n if (srcChainId && !isCrossChain(srcChainId, destChainId ?? srcChainId)) {\n return MetricsActionType.SWAPBRIDGE_V1;\n }\n return MetricsActionType.CROSSCHAIN_V1;\n};\n\nexport const getActionTypeFromQuoteRequest = (\n quoteRequest: Partial<GenericQuoteRequest>,\n) => {\n return getActionType(quoteRequest.srcChainId, quoteRequest.destChainId);\n};\n\nexport const getSwapType = (\n srcChainId?: GenericQuoteRequest['srcChainId'],\n destChainId?: GenericQuoteRequest['destChainId'],\n) => {\n if (srcChainId && !isCrossChain(srcChainId, destChainId ?? srcChainId)) {\n return MetricsSwapType.SINGLE;\n }\n return MetricsSwapType.CROSSCHAIN;\n};\n\nexport const getSwapTypeFromQuote = (\n quoteRequest: Partial<GenericQuoteRequest>,\n) => {\n return getSwapType(quoteRequest.srcChainId, quoteRequest.destChainId);\n};\n\nexport const formatProviderLabel = ({\n bridgeId,\n bridges,\n}: QuoteResponse<TxData | string>['quote']): `${string}_${string}` =>\n `${bridgeId}_${bridges[0]}`;\n\nexport const getRequestParams = (\n {\n destChainId,\n srcTokenAddress,\n destTokenAddress,\n }: BridgeControllerState['quoteRequest'],\n srcChainIdCaip: CaipChainId,\n) => {\n return {\n chain_id_source: srcChainIdCaip,\n chain_id_destination: destChainId ? formatChainIdToCaip(destChainId) : null,\n token_address_source: srcTokenAddress\n ? (formatAddressToAssetId(srcTokenAddress, srcChainIdCaip) ??\n getNativeAssetForChainId(srcChainIdCaip)?.assetId ??\n null)\n : (getNativeAssetForChainId(srcChainIdCaip)?.assetId ?? null),\n token_address_destination: destTokenAddress\n ? (formatAddressToAssetId(\n destTokenAddress,\n destChainId ?? srcChainIdCaip,\n ) ?? null)\n : null,\n };\n};\n\nexport const isHardwareWallet = (\n selectedAccount?: AccountsControllerState['internalAccounts']['accounts'][string],\n) => {\n return selectedAccount?.metadata?.keyring.type?.includes('Hardware') ?? false;\n};\n\nexport const isCustomSlippage = (slippage: GenericQuoteRequest['slippage']) => {\n return slippage !== DEFAULT_BRIDGE_CONTROLLER_STATE.quoteRequest.slippage;\n};\n"]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"properties.d.cts","sourceRoot":"","sources":["../../../src/utils/metrics/properties.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,wBAAwB;AAEnD,OAAO,EAAE,iBAAiB,E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a,gBACX,mBAAmB,CAAC,YAAY,CAAC,gBAChC,mBAAmB,CAAC,aAAa,CAAC,sBAMjD,CAAC;AAEF,eAAO,MAAM,6BAA6B,iBAC1B,QAAQ,mBAAmB,CAAC,sBAG3C,CAAC;AAEF,eAAO,MAAM,WAAW,gBACT,mBAAmB,CAAC,YAAY,CAAC,gBAChC,mBAAmB,CAAC,aAAa,CAAC,oBAMjD,CAAC;AAEF,eAAO,MAAM,oBAAoB,iBACjB,QAAQ,mBAAmB,CAAC,oBAG3C,CAAC;AAEF,eAAO,MAAM,mBAAmB,2BAG7B,cAAc,MAAM,GAAG,MAAM,CAAC,CAAC,OAAO,CAAC,KAAG,GAAG,MAAM,IAAI,MAAM,EACnC,CAAC;AAE9B,eAAO,MAAM,gBAAgB,wDAKxB,qBAAqB,CAAC,cAAc,CAAC,kBACxB,WAAW;;;;;CAiB5B,CAAC;AAEF,eAAO,MAAM,gBAAgB,qBACT,uBAAuB,CAAC,kBAAkB,CAAC,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,YAGlF,CAAC;AAEF,eAAO,MAAM,gBAAgB,aAAc,mBAAmB,CAAC,UAAU,CAAC,YAEzE,CAAC"}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { MetricsActionType, MetricsSwapType } from "./constants.mjs";
|
2
2
|
import { DEFAULT_BRIDGE_CONTROLLER_STATE } from "../../constants/bridge.mjs";
|
3
|
-
import { getNativeAssetForChainId } from "../bridge.mjs";
|
3
|
+
import { getNativeAssetForChainId, isCrossChain } from "../bridge.mjs";
|
4
4
|
import { formatAddressToAssetId, formatChainIdToCaip } from "../caip-formatters.mjs";
|
5
5
|
export const toInputChangedPropertyKey = {
|
6
6
|
srcTokenAddress: 'token_source',
|
@@ -21,9 +21,7 @@ export const toInputChangedPropertyValue = {
|
|
21
21
|
slippage: ({ slippage }) => (slippage ? Number(slippage) : slippage),
|
22
22
|
};
|
23
23
|
export const getActionType = (srcChainId, destChainId) => {
|
24
|
-
if (srcChainId &&
|
25
|
-
formatChainIdToCaip(srcChainId) ===
|
26
|
-
formatChainIdToCaip(destChainId ?? srcChainId)) {
|
24
|
+
if (srcChainId && !isCrossChain(srcChainId, destChainId ?? srcChainId)) {
|
27
25
|
return MetricsActionType.SWAPBRIDGE_V1;
|
28
26
|
}
|
29
27
|
return MetricsActionType.CROSSCHAIN_V1;
|
@@ -32,9 +30,7 @@ export const getActionTypeFromQuoteRequest = (quoteRequest) => {
|
|
32
30
|
return getActionType(quoteRequest.srcChainId, quoteRequest.destChainId);
|
33
31
|
};
|
34
32
|
export const getSwapType = (srcChainId, destChainId) => {
|
35
|
-
if (srcChainId &&
|
36
|
-
formatChainIdToCaip(srcChainId) ===
|
37
|
-
formatChainIdToCaip(destChainId ?? srcChainId)) {
|
33
|
+
if (srcChainId && !isCrossChain(srcChainId, destChainId ?? srcChainId)) {
|
38
34
|
return MetricsSwapType.SINGLE;
|
39
35
|
}
|
40
36
|
return MetricsSwapType.CROSSCHAIN;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"properties.mjs","sourceRoot":"","sources":["../../../src/utils/metrics/properties.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,wBAAoB;AAGjE,OAAO,EAAE,+BAA+B,EAAE,mCAA+B;AAGzE,OAAO,EAAE,wBAAwB,EAAE,sBAAkB;
|
1
|
+
{"version":3,"file":"properties.mjs","sourceRoot":"","sources":["../../../src/utils/metrics/properties.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,wBAAoB;AAGjE,OAAO,EAAE,+BAA+B,EAAE,mCAA+B;AAGzE,OAAO,EAAE,wBAAwB,EAAE,YAAY,EAAE,sBAAkB;AACnE,OAAO,EACL,sBAAsB,EACtB,mBAAmB,EACpB,+BAA2B;AAE5B,MAAM,CAAC,MAAM,yBAAyB,GAElC;IACF,eAAe,EAAE,cAAc;IAC/B,gBAAgB,EAAE,mBAAmB;IACrC,U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cAAc,CAC9B,IAAI,IAAI,CAAC;YACZ,CAAC,CAAC,IAAI;KACT,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,eAAiF,EACjF,EAAE;IACF,OAAO,eAAe,EAAE,QAAQ,EAAE,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,UAAU,CAAC,IAAI,KAAK,CAAC;AAChF,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,QAAyC,EAAE,EAAE;IAC5E,OAAO,QAAQ,KAAK,+BAA+B,CAAC,YAAY,CAAC,QAAQ,CAAC;AAC5E,CAAC,CAAC","sourcesContent":["import type { CaipChainId } from '@metamask/utils';\n\nimport { MetricsActionType, MetricsSwapType } from './constants';\nimport type { InputKeys, InputValues } from './types';\nimport type { AccountsControllerState } from '../../../../accounts-controller/src/AccountsController';\nimport { DEFAULT_BRIDGE_CONTROLLER_STATE } from '../../constants/bridge';\nimport type { BridgeControllerState, QuoteResponse, TxData } from '../../types';\nimport { type GenericQuoteRequest, type QuoteRequest } from '../../types';\nimport { getNativeAssetForChainId, isCrossChain } from '../bridge';\nimport {\n formatAddressToAssetId,\n formatChainIdToCaip,\n} from '../caip-formatters';\n\nexport const toInputChangedPropertyKey: Partial<\n Record<keyof QuoteRequest, InputKeys>\n> = {\n srcTokenAddress: 'token_source',\n destTokenAddress: 'token_destination',\n srcChainId: 'chain_source',\n destChainId: 'chain_destination',\n slippage: 'slippage',\n};\n\nexport const toInputChangedPropertyValue: Partial<\n Record<\n keyof typeof toInputChangedPropertyKey,\n (\n value: Partial<GenericQuoteRequest>,\n ) => InputValues[keyof InputValues] | undefined\n >\n> = {\n srcTokenAddress: ({ srcTokenAddress, srcChainId }) =>\n srcChainId\n ? formatAddressToAssetId(srcTokenAddress ?? '', srcChainId)\n : undefined,\n destTokenAddress: ({ destTokenAddress, destChainId }) =>\n destChainId\n ? formatAddressToAssetId(destTokenAddress ?? '', destChainId)\n : undefined,\n srcChainId: ({ srcChainId }) =>\n srcChainId ? formatChainIdToCaip(srcChainId) : undefined,\n destChainId: ({ destChainId }) =>\n destChainId ? formatChainIdToCaip(destChainId) : undefined,\n slippage: ({ slippage }) => (slippage ? Number(slippage) : slippage),\n};\n\nexport const getActionType = (\n srcChainId?: GenericQuoteRequest['srcChainId'],\n destChainId?: GenericQuoteRequest['destChainId'],\n) => {\n if (srcChainId && !isCrossChain(srcChainId, destChainId ?? srcChainId)) {\n return MetricsActionType.SWAPBRIDGE_V1;\n }\n return MetricsActionType.CROSSCHAIN_V1;\n};\n\nexport const getActionTypeFromQuoteRequest = (\n quoteRequest: Partial<GenericQuoteRequest>,\n) => {\n return getActionType(quoteRequest.srcChainId, quoteRequest.destChainId);\n};\n\nexport const getSwapType = (\n srcChainId?: GenericQuoteRequest['srcChainId'],\n destChainId?: GenericQuoteRequest['destChainId'],\n) => {\n if (srcChainId && !isCrossChain(srcChainId, destChainId ?? srcChainId)) {\n return MetricsSwapType.SINGLE;\n }\n return MetricsSwapType.CROSSCHAIN;\n};\n\nexport const getSwapTypeFromQuote = (\n quoteRequest: Partial<GenericQuoteRequest>,\n) => {\n return getSwapType(quoteRequest.srcChainId, quoteRequest.destChainId);\n};\n\nexport const formatProviderLabel = ({\n bridgeId,\n bridges,\n}: QuoteResponse<TxData | string>['quote']): `${string}_${string}` =>\n `${bridgeId}_${bridges[0]}`;\n\nexport const getRequestParams = (\n {\n destChainId,\n srcTokenAddress,\n destTokenAddress,\n }: BridgeControllerState['quoteRequest'],\n srcChainIdCaip: CaipChainId,\n) => {\n return {\n chain_id_source: srcChainIdCaip,\n chain_id_destination: destChainId ? formatChainIdToCaip(destChainId) : null,\n token_address_source: srcTokenAddress\n ? (formatAddressToAssetId(srcTokenAddress, srcChainIdCaip) ??\n getNativeAssetForChainId(srcChainIdCaip)?.assetId ??\n null)\n : (getNativeAssetForChainId(srcChainIdCaip)?.assetId ?? null),\n token_address_destination: destTokenAddress\n ? (formatAddressToAssetId(\n destTokenAddress,\n destChainId ?? srcChainIdCaip,\n ) ?? null)\n : null,\n };\n};\n\nexport const isHardwareWallet = (\n selectedAccount?: AccountsControllerState['internalAccounts']['accounts'][string],\n) => {\n return selectedAccount?.metadata?.keyring.type?.includes('Hardware') ?? false;\n};\n\nexport const isCustomSlippage = (slippage: GenericQuoteRequest['slippage']) => {\n return slippage !== DEFAULT_BRIDGE_CONTROLLER_STATE.quoteRequest.slippage;\n};\n"]}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@metamask-previews/bridge-controller",
|
3
|
-
"version": "
|
3
|
+
"version": "24.0.0-preview-a578ea2",
|
4
4
|
"description": "Manages bridge-related quote fetching functionality for MetaMask",
|
5
5
|
"keywords": [
|
6
6
|
"MetaMask",
|
@@ -72,7 +72,7 @@
|
|
72
72
|
"@metamask/remote-feature-flag-controller": "^1.6.0",
|
73
73
|
"@metamask/snaps-controllers": "^11.2.1",
|
74
74
|
"@metamask/superstruct": "^3.1.0",
|
75
|
-
"@metamask/transaction-controller": "^55.0.
|
75
|
+
"@metamask/transaction-controller": "^55.0.2",
|
76
76
|
"@types/jest": "^27.4.1",
|
77
77
|
"deepmerge": "^4.2.2",
|
78
78
|
"jest": "^27.5.1",
|