@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
package/dist/types.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAwDA;;GAEG;AACH,MAAM,CAAN,IAAY,SAYX;AAZD,WAAY,SAAS;IACnB,4DAA4D;IAC5D,8BAAiB,CAAA;IACjB,qBAAqB;IACrB,4BAAe,CAAA;IACf,kCAAkC;IAClC,wBAAW,CAAA;IACX;;;OAGG;IACH,gCAAmB,CAAA;AACrB,CAAC,EAZW,SAAS,KAAT,SAAS,QAYpB;AAkGD;;GAEG;AACH,MAAM,CAAN,IAAY,SAGX;AAHD,WAAY,SAAS;IACnB,wCAA2B,CAAA;IAC3B,wCAA2B,CAAA;AAC7B,CAAC,EAHW,SAAS,KAAT,SAAS,QAGpB;AAyED,MAAM,CAAN,IAAY,WAMX;AAND,WAAY,WAAW;IACrB,sCAAuB,CAAA;IACvB,kCAAmB,CAAA;IACnB,gCAAiB,CAAA;IACjB,kCAAmB,CAAA;IACnB,oCAAqB,CAAA;AACvB,CAAC,EANW,WAAW,KAAX,WAAW,QAMtB;AAoDD,MAAM,CAAN,IAAY,OAiBX;AAjBD,WAAY,OAAO;IACjB,mCAAO,CAAA;IACP,8CAAa,CAAA;IACb,oCAAQ,CAAA;IACR,6CAAa,CAAA;IACb,2CAAY,CAAA;IACZ,wCAAW,CAAA;IACX,iDAAgB,CAAA;IAChB,mDAAiB,CAAA;IACjB,2CAAa,CAAA;IACb,wDAAyB,CAAA;IACzB,gDAAoB,CAAA;IACpB,6CAAgB,CAAA;IAChB,sCAAU,CAAA;IACV,yCAAW,CAAA;IACX,+CAAc,CAAA;IACd,8CAAc,CAAA;AAChB,CAAC,EAjBW,OAAO,KAAP,OAAO,QAiBlB;AAQD,MAAM,CAAN,IAAY,aAIX;AAJD,WAAY,aAAa;IACvB,uDAAO,CAAA;IACP,uDAAO,CAAA;IACP,mDAAK,CAAA;AACP,CAAC,EAJW,aAAa,KAAb,aAAa,QAIxB;AACD,MAAM,CAAN,IAAY,gBAGX;AAHD,WAAY,gBAAgB;IAC1B,6DAAyC,CAAA;IACzC,0EAAsD,CAAA;AACxD,CAAC,EAHW,gBAAgB,KAAhB,gBAAgB,QAG3B;AACD,MAAM,CAAN,IAAY,sBAMX;AAND,WAAY,sBAAsB;IAChC,8EAAoD,CAAA;IACpD,oDAA0B,CAAA;IAC1B,iFAAuD,CAAA;IACvD,0EAAgD,CAAA;IAChD,sDAA4B,CAAA;AAC9B,CAAC,EANW,sBAAsB,KAAtB,sBAAsB,QAMjC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\nimport type { AccountsControllerGetAccountByAddressAction } from '@metamask/accounts-controller';\nimport type { AssetsControllerGetExchangeRatesForBridgeAction } from '@metamask/assets-controller';\nimport type {\n GetCurrencyRateState,\n MultichainAssetsRatesControllerGetStateAction,\n TokenRatesControllerGetStateAction,\n} from '@metamask/assets-controllers';\nimport type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type {\n NetworkControllerFindNetworkClientIdByChainIdAction,\n NetworkControllerGetNetworkClientByIdAction,\n} from '@metamask/network-controller';\nimport type { AuthenticationControllerGetBearerTokenAction } from '@metamask/profile-sync-controller/auth';\nimport type { RemoteFeatureFlagControllerGetStateAction } from '@metamask/remote-feature-flag-controller';\nimport type { SnapControllerHandleRequestAction } from '@metamask/snaps-controllers';\nimport type { Infer } from '@metamask/superstruct';\nimport type {\n CaipAccountId,\n CaipAssetId,\n CaipAssetType,\n CaipChainId,\n Hex,\n} from '@metamask/utils';\n\nimport type { BridgeController } from './bridge-controller';\nimport type { BRIDGE_CONTROLLER_NAME } from './constants/bridge';\nimport type {\n BitcoinTradeDataSchema,\n BridgeAssetSchema,\n ChainConfigurationSchema,\n ChainRankingSchema,\n FeatureId,\n FeeDataSchema,\n IntentSchema,\n PlatformConfigSchema,\n ProtocolSchema,\n QuoteResponseSchema,\n QuoteSchema,\n StepSchema,\n TokenFeatureSchema,\n QuoteStreamCompleteSchema,\n TronTradeDataSchema,\n TxDataSchema,\n} from './utils/validators';\n\nexport type FetchFunction = (\n input: RequestInfo | URL | string,\n init?: RequestInit,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n) => Promise<any>;\n\n/**\n * The types of assets that a user can send\n */\nexport enum AssetType {\n /** The native asset for the current network, such as ETH */\n native = 'NATIVE',\n /** An ERC20 token */\n token = 'TOKEN',\n /** An ERC721 or ERC1155 token. */\n NFT = 'NFT',\n /**\n * A transaction interacting with a contract that isn't a token method\n * interaction will be marked as dealing with an unknown asset type.\n */\n unknown = 'UNKNOWN',\n}\n\nexport type ChainConfiguration = Infer<typeof ChainConfigurationSchema>;\n\nexport type ChainRanking = Infer<typeof ChainRankingSchema>;\n\nexport type L1GasFees = {\n l1GasFeesInHexWei?: string; // l1 fees for approval and trade in hex wei, appended by BridgeController.#appendL1GasFees\n};\n\nexport type NonEvmFees = {\n nonEvmFeesInNative?: string; // Non-EVM chain fees in native units (SOL for Solana, BTC for Bitcoin)\n};\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 \"1000000000000000000\"\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 | null;\n /**\n * The amount of the token in USD\n *\n * @example \"1.234\"\n */\n usd: string | null;\n};\n\n/**\n * Asset exchange rate values for a given chain and address\n */\nexport type ExchangeRate = { exchangeRate?: string; usdExchangeRate?: string };\n\n/**\n * Values derived from the quote response\n */\nexport type QuoteMetadata = {\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?: TokenAmountValues | null;\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<'effective' | 'total' | 'max', TokenAmountValues>;\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; // estimatedGasFees + relayerFees\n totalMaxNetworkFee: TokenAmountValues; // maxGasFees + relayerFees\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/**\n * Sort order set by the user\n */\nexport enum SortOrder {\n COST_ASC = 'cost_ascending',\n ETA_ASC = 'time_descending',\n}\n\n/**\n * This is the interface for the asset object returned by the bridge-api\n * This type is used in the QuoteResponse and in the fetchBridgeTokens response\n */\nexport type BridgeAsset = Infer<typeof BridgeAssetSchema>;\n\n/**\n * This is the interface for the token object used in the extension client\n * In addition to the {@link BridgeAsset} fields, it includes balance information\n */\nexport type BridgeToken = {\n address: string;\n symbol: string;\n image: string;\n decimals: number;\n chainId: number | Hex | ChainId | CaipChainId;\n balance: string; // raw balance\n // TODO deprecate this field and use balance instead\n string: string | undefined; // normalized balance as a stringified number\n tokenFiatAmount?: number | null;\n occurrences?: number;\n};\n\ntype DecimalChainId = string;\nexport type GasMultiplierByChainId = Record<DecimalChainId, number>;\n\nexport type FeatureFlagResponse = Infer<typeof PlatformConfigSchema>;\n\n// TODO move definition to validators.ts\n/**\n * This is the interface for the quote request sent to the bridge-api\n * and should only be used by the fetchBridgeQuotes utility function\n * Components and redux stores should use the {@link GenericQuoteRequest} type\n */\nexport type QuoteRequest<\n ChainIdType = ChainId | number,\n TokenAddressType = string,\n WalletAddressType = string,\n> = {\n walletAddress: WalletAddressType;\n destWalletAddress?: WalletAddressType;\n srcChainId: ChainIdType;\n destChainId: ChainIdType;\n srcTokenAddress: TokenAddressType;\n destTokenAddress: TokenAddressType;\n /**\n * This is the amount sent, in atomic amount\n */\n srcTokenAmount: string;\n slippage?: number;\n aggIds?: string[];\n bridgeIds?: string[];\n insufficientBal?: boolean;\n resetApproval?: boolean;\n refuel?: boolean;\n /**\n * Whether the response should include gasless swap quotes\n * This should be true if the user has opted in to STX on the client\n * and the current network has STX support\n */\n gasIncluded: boolean;\n /**\n * Whether to request quotes that use EIP-7702 delegated gasless execution\n */\n gasIncluded7702: boolean;\n /**\n * The fee that will be charged by MetaMask\n */\n fee?: number;\n};\n\nexport enum StatusTypes {\n SUBMITTED = 'SUBMITTED',\n UNKNOWN = 'UNKNOWN',\n FAILED = 'FAILED',\n PENDING = 'PENDING',\n COMPLETE = 'COMPLETE',\n}\n\n/**\n * These are types that components pass in. Since data is a mix of types when coming from the redux store, we need to use a generic type that can cover all the types.\n * Payloads with this type are transformed into QuoteRequest by fetchBridgeQuotes right before fetching quotes\n */\nexport type GenericQuoteRequest = QuoteRequest<\n Hex | CaipChainId | string | number, // chainIds\n Hex | CaipAssetId | string, // assetIds/addresses\n Hex | CaipAccountId | string // accountIds/addresses\n>;\n\nexport type Protocol = Infer<typeof ProtocolSchema>;\n\nexport type Step = Infer<typeof StepSchema>;\n\nexport type RefuelData = Step;\n\nexport type FeeData = Infer<typeof FeeDataSchema>;\n\nexport type Quote = Infer<typeof QuoteSchema>;\n\nexport type TxData = Infer<typeof TxDataSchema>;\n\nexport type Intent = Infer<typeof IntentSchema>;\nexport type IntentOrderLike = Intent['order'];\n\nexport type BitcoinTradeData = Infer<typeof BitcoinTradeDataSchema>;\n\nexport type TronTradeData = Infer<typeof TronTradeDataSchema>;\n/**\n * This is the type for the quote response from the bridge-api\n * TxDataType can be overriden to be a string when the quote is non-evm\n * ApprovalType can be overriden when you know the specific approval type (e.g., TxData for EVM-only contexts)\n */\nexport type QuoteResponse<\n TxDataType = TxData | string | BitcoinTradeData | TronTradeData,\n ApprovalType = TxData | TronTradeData,\n> = Infer<typeof QuoteResponseSchema> & {\n trade: TxDataType;\n approval?: ApprovalType;\n /**\n * Appended to the quote response based on the quote request\n */\n featureId?: FeatureId;\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\nexport enum ChainId {\n ETH = 1,\n OPTIMISM = 10,\n BSC = 56,\n POLYGON = 137,\n ZKSYNC = 324,\n BASE = 8453,\n ARBITRUM = 42161,\n AVALANCHE = 43114,\n LINEA = 59144,\n SOLANA = 1151111081099710,\n BTC = 20000000000001,\n TRON = 728126428,\n SEI = 1329,\n MONAD = 143,\n HYPEREVM = 999,\n MEGAETH = 4326,\n}\n\nexport type FeatureFlagsPlatformConfig = Infer<typeof PlatformConfigSchema>;\n\nexport type TokenFeature = Infer<typeof TokenFeatureSchema>;\n\nexport type QuoteStreamCompleteData = Infer<typeof QuoteStreamCompleteSchema>;\n\nexport enum RequestStatus {\n LOADING,\n FETCHED,\n ERROR,\n}\nexport enum BridgeUserAction {\n SELECT_DEST_NETWORK = 'selectDestNetwork',\n UPDATE_QUOTE_PARAMS = 'updateBridgeQuoteRequestParams',\n}\nexport enum BridgeBackgroundAction {\n SET_CHAIN_INTERVAL_LENGTH = 'setChainIntervalLength',\n RESET_STATE = 'resetState',\n TRACK_METAMETRICS_EVENT = 'trackUnifiedSwapBridgeEvent',\n STOP_POLLING_FOR_QUOTES = 'stopPollingForQuotes',\n FETCH_QUOTES = 'fetchQuotes',\n}\n\nexport type BridgeControllerState = {\n quoteRequest: Partial<GenericQuoteRequest>;\n quotes: (QuoteResponse & L1GasFees & NonEvmFees)[];\n /**\n * The time elapsed between the initial quote fetch and when the first valid quote was received\n */\n quotesInitialLoadTime: number | null;\n /**\n * The timestamp of when the latest quote fetch started\n */\n quotesLastFetched: number | null;\n /**\n * The status of the quote fetch, including fee calculations and validations\n * This is set to\n * - LOADING when the quote fetch starts\n * - FETCHED when the process completes successfully, including when quotes are empty\n * - ERROR when any errors occur\n *\n * When SSE is enabled, this is set to LOADING even when a quote is available. It is only\n * set to FETCHED when the stream is closed and all quotes have been received\n */\n quotesLoadingStatus: RequestStatus | null;\n quoteFetchError: string | null;\n /**\n * The number of times the quotes have been refreshed, starts at 0 and is\n * incremented at the end of each quote fetch\n */\n quotesRefreshCount: number;\n /**\n * Asset exchange rates for EVM and multichain assets that are not indexed by the assets controllers\n */\n assetExchangeRates: Record<CaipAssetType, ExchangeRate>;\n /**\n * When the src token is SOL, this needs to be subtracted from their balance to determine\n * the max amount that can be sent.\n */\n minimumBalanceForRentExemptionInLamports: string | null;\n /**\n * Security alerts for the destination token in the current quote request,\n * populated from `token_warning` SSE events.\n */\n tokenWarnings: TokenFeature[];\n /**\n * Metadata about the completed quote stream, populated from the `complete` SSE event.\n * Set to null at the start of each fetch and updated when the complete event is received.\n */\n quoteStreamComplete: QuoteStreamCompleteData | null;\n};\n\nexport type BridgeControllerAction<\n FunctionName extends keyof BridgeController,\n> = {\n type: `${typeof BRIDGE_CONTROLLER_NAME}:${FunctionName}`;\n handler: BridgeController[FunctionName];\n};\n\nexport type BridgeControllerGetStateAction = ControllerGetStateAction<\n typeof BRIDGE_CONTROLLER_NAME,\n BridgeControllerState\n>;\n\nexport type BridgeControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof BRIDGE_CONTROLLER_NAME,\n BridgeControllerState\n>;\n\n// Maps to BridgeController function names\nexport type BridgeControllerActions =\n | BridgeControllerGetStateAction\n | BridgeControllerAction<BridgeBackgroundAction.SET_CHAIN_INTERVAL_LENGTH>\n | BridgeControllerAction<BridgeBackgroundAction.RESET_STATE>\n | BridgeControllerAction<BridgeBackgroundAction.TRACK_METAMETRICS_EVENT>\n | BridgeControllerAction<BridgeBackgroundAction.STOP_POLLING_FOR_QUOTES>\n | BridgeControllerAction<BridgeBackgroundAction.FETCH_QUOTES>\n | BridgeControllerAction<BridgeUserAction.UPDATE_QUOTE_PARAMS>;\n\nexport type BridgeControllerEvents = BridgeControllerStateChangeEvent;\n\nexport type AllowedActions =\n | AccountsControllerGetAccountByAddressAction\n | AuthenticationControllerGetBearerTokenAction\n | GetCurrencyRateState\n | TokenRatesControllerGetStateAction\n | MultichainAssetsRatesControllerGetStateAction\n | SnapControllerHandleRequestAction\n | NetworkControllerFindNetworkClientIdByChainIdAction\n | NetworkControllerGetNetworkClientByIdAction\n | RemoteFeatureFlagControllerGetStateAction\n | AssetsControllerGetExchangeRatesForBridgeAction;\nexport type AllowedEvents = never;\n\n/**\n * The messenger for the BridgeController.\n */\nexport type BridgeControllerMessenger = Messenger<\n typeof BRIDGE_CONTROLLER_NAME,\n BridgeControllerActions | AllowedActions,\n BridgeControllerEvents | AllowedEvents\n>;\n"]}
|
|
1
|
+
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAyDA;;GAEG;AACH,MAAM,CAAN,IAAY,SAYX;AAZD,WAAY,SAAS;IACnB,4DAA4D;IAC5D,8BAAiB,CAAA;IACjB,qBAAqB;IACrB,4BAAe,CAAA;IACf,kCAAkC;IAClC,wBAAW,CAAA;IACX;;;OAGG;IACH,gCAAmB,CAAA;AACrB,CAAC,EAZW,SAAS,KAAT,SAAS,QAYpB;AAkGD;;GAEG;AACH,MAAM,CAAN,IAAY,SAGX;AAHD,WAAY,SAAS;IACnB,wCAA2B,CAAA;IAC3B,wCAA2B,CAAA;AAC7B,CAAC,EAHW,SAAS,KAAT,SAAS,QAGpB;AAyED,MAAM,CAAN,IAAY,WAMX;AAND,WAAY,WAAW;IACrB,sCAAuB,CAAA;IACvB,kCAAmB,CAAA;IACnB,gCAAiB,CAAA;IACjB,kCAAmB,CAAA;IACnB,oCAAqB,CAAA;AACvB,CAAC,EANW,WAAW,KAAX,WAAW,QAMtB;AAoDD,MAAM,CAAN,IAAY,OAiBX;AAjBD,WAAY,OAAO;IACjB,mCAAO,CAAA;IACP,8CAAa,CAAA;IACb,oCAAQ,CAAA;IACR,6CAAa,CAAA;IACb,2CAAY,CAAA;IACZ,wCAAW,CAAA;IACX,iDAAgB,CAAA;IAChB,mDAAiB,CAAA;IACjB,2CAAa,CAAA;IACb,wDAAyB,CAAA;IACzB,gDAAoB,CAAA;IACpB,6CAAgB,CAAA;IAChB,sCAAU,CAAA;IACV,yCAAW,CAAA;IACX,+CAAc,CAAA;IACd,8CAAc,CAAA;AAChB,CAAC,EAjBW,OAAO,KAAP,OAAO,QAiBlB;AAQD,MAAM,CAAN,IAAY,aAIX;AAJD,WAAY,aAAa;IACvB,uDAAO,CAAA;IACP,uDAAO,CAAA;IACP,mDAAK,CAAA;AACP,CAAC,EAJW,aAAa,KAAb,aAAa,QAIxB;AAED;;;GAGG;AACH,MAAM,CAAN,IAAY,gBAGX;AAHD,WAAY,gBAAgB;IAC1B,6DAAyC,CAAA;IACzC,0EAAsD,CAAA;AACxD,CAAC,EAHW,gBAAgB,KAAhB,gBAAgB,QAG3B;AAED;;;GAGG;AACH,MAAM,CAAN,IAAY,sBAMX;AAND,WAAY,sBAAsB;IAChC,8EAAoD,CAAA;IACpD,oDAA0B,CAAA;IAC1B,iFAAuD,CAAA;IACvD,0EAAgD,CAAA;IAChD,sDAA4B,CAAA;AAC9B,CAAC,EANW,sBAAsB,KAAtB,sBAAsB,QAMjC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\nimport type { AccountsControllerGetAccountByAddressAction } from '@metamask/accounts-controller';\nimport type { AssetsControllerGetExchangeRatesForBridgeAction } from '@metamask/assets-controller';\nimport type {\n GetCurrencyRateState,\n MultichainAssetsRatesControllerGetStateAction,\n TokenRatesControllerGetStateAction,\n} from '@metamask/assets-controllers';\nimport type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type {\n NetworkControllerFindNetworkClientIdByChainIdAction,\n NetworkControllerGetNetworkClientByIdAction,\n} from '@metamask/network-controller';\nimport type { AuthenticationControllerGetBearerTokenAction } from '@metamask/profile-sync-controller/auth';\nimport type { RemoteFeatureFlagControllerGetStateAction } from '@metamask/remote-feature-flag-controller';\nimport type { SnapControllerHandleRequestAction } from '@metamask/snaps-controllers';\nimport type { Infer } from '@metamask/superstruct';\nimport type {\n CaipAccountId,\n CaipAssetId,\n CaipAssetType,\n CaipChainId,\n Hex,\n} from '@metamask/utils';\n\nimport type { BridgeController } from './bridge-controller';\nimport type { BridgeControllerMethodActions } from './bridge-controller-method-action-types';\nimport type { BRIDGE_CONTROLLER_NAME } from './constants/bridge';\nimport type {\n BitcoinTradeDataSchema,\n BridgeAssetSchema,\n ChainConfigurationSchema,\n ChainRankingSchema,\n FeatureId,\n FeeDataSchema,\n IntentSchema,\n PlatformConfigSchema,\n ProtocolSchema,\n QuoteResponseSchema,\n QuoteSchema,\n StepSchema,\n TokenFeatureSchema,\n QuoteStreamCompleteSchema,\n TronTradeDataSchema,\n TxDataSchema,\n} from './utils/validators';\n\nexport type FetchFunction = (\n input: RequestInfo | URL | string,\n init?: RequestInit,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n) => Promise<any>;\n\n/**\n * The types of assets that a user can send\n */\nexport enum AssetType {\n /** The native asset for the current network, such as ETH */\n native = 'NATIVE',\n /** An ERC20 token */\n token = 'TOKEN',\n /** An ERC721 or ERC1155 token. */\n NFT = 'NFT',\n /**\n * A transaction interacting with a contract that isn't a token method\n * interaction will be marked as dealing with an unknown asset type.\n */\n unknown = 'UNKNOWN',\n}\n\nexport type ChainConfiguration = Infer<typeof ChainConfigurationSchema>;\n\nexport type ChainRanking = Infer<typeof ChainRankingSchema>;\n\nexport type L1GasFees = {\n l1GasFeesInHexWei?: string; // l1 fees for approval and trade in hex wei, appended by BridgeController.#appendL1GasFees\n};\n\nexport type NonEvmFees = {\n nonEvmFeesInNative?: string; // Non-EVM chain fees in native units (SOL for Solana, BTC for Bitcoin)\n};\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 \"1000000000000000000\"\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 | null;\n /**\n * The amount of the token in USD\n *\n * @example \"1.234\"\n */\n usd: string | null;\n};\n\n/**\n * Asset exchange rate values for a given chain and address\n */\nexport type ExchangeRate = { exchangeRate?: string; usdExchangeRate?: string };\n\n/**\n * Values derived from the quote response\n */\nexport type QuoteMetadata = {\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?: TokenAmountValues | null;\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<'effective' | 'total' | 'max', TokenAmountValues>;\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; // estimatedGasFees + relayerFees\n totalMaxNetworkFee: TokenAmountValues; // maxGasFees + relayerFees\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/**\n * Sort order set by the user\n */\nexport enum SortOrder {\n COST_ASC = 'cost_ascending',\n ETA_ASC = 'time_descending',\n}\n\n/**\n * This is the interface for the asset object returned by the bridge-api\n * This type is used in the QuoteResponse and in the fetchBridgeTokens response\n */\nexport type BridgeAsset = Infer<typeof BridgeAssetSchema>;\n\n/**\n * This is the interface for the token object used in the extension client\n * In addition to the {@link BridgeAsset} fields, it includes balance information\n */\nexport type BridgeToken = {\n address: string;\n symbol: string;\n image: string;\n decimals: number;\n chainId: number | Hex | ChainId | CaipChainId;\n balance: string; // raw balance\n // TODO deprecate this field and use balance instead\n string: string | undefined; // normalized balance as a stringified number\n tokenFiatAmount?: number | null;\n occurrences?: number;\n};\n\ntype DecimalChainId = string;\nexport type GasMultiplierByChainId = Record<DecimalChainId, number>;\n\nexport type FeatureFlagResponse = Infer<typeof PlatformConfigSchema>;\n\n// TODO move definition to validators.ts\n/**\n * This is the interface for the quote request sent to the bridge-api\n * and should only be used by the fetchBridgeQuotes utility function\n * Components and redux stores should use the {@link GenericQuoteRequest} type\n */\nexport type QuoteRequest<\n ChainIdType = ChainId | number,\n TokenAddressType = string,\n WalletAddressType = string,\n> = {\n walletAddress: WalletAddressType;\n destWalletAddress?: WalletAddressType;\n srcChainId: ChainIdType;\n destChainId: ChainIdType;\n srcTokenAddress: TokenAddressType;\n destTokenAddress: TokenAddressType;\n /**\n * This is the amount sent, in atomic amount\n */\n srcTokenAmount: string;\n slippage?: number;\n aggIds?: string[];\n bridgeIds?: string[];\n insufficientBal?: boolean;\n resetApproval?: boolean;\n refuel?: boolean;\n /**\n * Whether the response should include gasless swap quotes\n * This should be true if the user has opted in to STX on the client\n * and the current network has STX support\n */\n gasIncluded: boolean;\n /**\n * Whether to request quotes that use EIP-7702 delegated gasless execution\n */\n gasIncluded7702: boolean;\n /**\n * The fee that will be charged by MetaMask\n */\n fee?: number;\n};\n\nexport enum StatusTypes {\n SUBMITTED = 'SUBMITTED',\n UNKNOWN = 'UNKNOWN',\n FAILED = 'FAILED',\n PENDING = 'PENDING',\n COMPLETE = 'COMPLETE',\n}\n\n/**\n * These are types that components pass in. Since data is a mix of types when coming from the redux store, we need to use a generic type that can cover all the types.\n * Payloads with this type are transformed into QuoteRequest by fetchBridgeQuotes right before fetching quotes\n */\nexport type GenericQuoteRequest = QuoteRequest<\n Hex | CaipChainId | string | number, // chainIds\n Hex | CaipAssetId | string, // assetIds/addresses\n Hex | CaipAccountId | string // accountIds/addresses\n>;\n\nexport type Protocol = Infer<typeof ProtocolSchema>;\n\nexport type Step = Infer<typeof StepSchema>;\n\nexport type RefuelData = Step;\n\nexport type FeeData = Infer<typeof FeeDataSchema>;\n\nexport type Quote = Infer<typeof QuoteSchema>;\n\nexport type TxData = Infer<typeof TxDataSchema>;\n\nexport type Intent = Infer<typeof IntentSchema>;\nexport type IntentOrderLike = Intent['order'];\n\nexport type BitcoinTradeData = Infer<typeof BitcoinTradeDataSchema>;\n\nexport type TronTradeData = Infer<typeof TronTradeDataSchema>;\n/**\n * This is the type for the quote response from the bridge-api\n * TxDataType can be overriden to be a string when the quote is non-evm\n * ApprovalType can be overriden when you know the specific approval type (e.g., TxData for EVM-only contexts)\n */\nexport type QuoteResponse<\n TxDataType = TxData | string | BitcoinTradeData | TronTradeData,\n ApprovalType = TxData | TronTradeData,\n> = Infer<typeof QuoteResponseSchema> & {\n trade: TxDataType;\n approval?: ApprovalType;\n /**\n * Appended to the quote response based on the quote request\n */\n featureId?: FeatureId;\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\nexport enum ChainId {\n ETH = 1,\n OPTIMISM = 10,\n BSC = 56,\n POLYGON = 137,\n ZKSYNC = 324,\n BASE = 8453,\n ARBITRUM = 42161,\n AVALANCHE = 43114,\n LINEA = 59144,\n SOLANA = 1151111081099710,\n BTC = 20000000000001,\n TRON = 728126428,\n SEI = 1329,\n MONAD = 143,\n HYPEREVM = 999,\n MEGAETH = 4326,\n}\n\nexport type FeatureFlagsPlatformConfig = Infer<typeof PlatformConfigSchema>;\n\nexport type TokenFeature = Infer<typeof TokenFeatureSchema>;\n\nexport type QuoteStreamCompleteData = Infer<typeof QuoteStreamCompleteSchema>;\n\nexport enum RequestStatus {\n LOADING,\n FETCHED,\n ERROR,\n}\n\n/**\n * @deprecated Use the separate method action types (e.g.,\n * `BridgeControllerFetchQuotesAction`) instead.\n */\nexport enum BridgeUserAction {\n SELECT_DEST_NETWORK = 'selectDestNetwork',\n UPDATE_QUOTE_PARAMS = 'updateBridgeQuoteRequestParams',\n}\n\n/**\n * @deprecated Use the separate method action types (e.g.,\n * `BridgeControllerFetchQuotesAction`) instead.\n */\nexport enum BridgeBackgroundAction {\n SET_CHAIN_INTERVAL_LENGTH = 'setChainIntervalLength',\n RESET_STATE = 'resetState',\n TRACK_METAMETRICS_EVENT = 'trackUnifiedSwapBridgeEvent',\n STOP_POLLING_FOR_QUOTES = 'stopPollingForQuotes',\n FETCH_QUOTES = 'fetchQuotes',\n}\n\nexport type BridgeControllerState = {\n quoteRequest: Partial<GenericQuoteRequest>;\n quotes: (QuoteResponse & L1GasFees & NonEvmFees)[];\n /**\n * The time elapsed between the initial quote fetch and when the first valid quote was received\n */\n quotesInitialLoadTime: number | null;\n /**\n * The timestamp of when the latest quote fetch started\n */\n quotesLastFetched: number | null;\n /**\n * The status of the quote fetch, including fee calculations and validations\n * This is set to\n * - LOADING when the quote fetch starts\n * - FETCHED when the process completes successfully, including when quotes are empty\n * - ERROR when any errors occur\n *\n * When SSE is enabled, this is set to LOADING even when a quote is available. It is only\n * set to FETCHED when the stream is closed and all quotes have been received\n */\n quotesLoadingStatus: RequestStatus | null;\n quoteFetchError: string | null;\n /**\n * The number of times the quotes have been refreshed, starts at 0 and is\n * incremented at the end of each quote fetch\n */\n quotesRefreshCount: number;\n /**\n * Asset exchange rates for EVM and multichain assets that are not indexed by the assets controllers\n */\n assetExchangeRates: Record<CaipAssetType, ExchangeRate>;\n /**\n * When the src token is SOL, this needs to be subtracted from their balance to determine\n * the max amount that can be sent.\n */\n minimumBalanceForRentExemptionInLamports: string | null;\n /**\n * Security alerts for the destination token in the current quote request,\n * populated from `token_warning` SSE events.\n */\n tokenWarnings: TokenFeature[];\n /**\n * Metadata about the completed quote stream, populated from the `complete` SSE event.\n * Set to null at the start of each fetch and updated when the complete event is received.\n */\n quoteStreamComplete: QuoteStreamCompleteData | null;\n};\n\n/**\n * @deprecated Use the separate method action types (e.g.,\n * `BridgeControllerFetchQuotesAction`) instead.\n */\nexport type BridgeControllerAction<\n FunctionName extends keyof BridgeController,\n> = {\n type: `${typeof BRIDGE_CONTROLLER_NAME}:${FunctionName}`;\n handler: BridgeController[FunctionName];\n};\n\nexport type BridgeControllerGetStateAction = ControllerGetStateAction<\n typeof BRIDGE_CONTROLLER_NAME,\n BridgeControllerState\n>;\n\nexport type BridgeControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof BRIDGE_CONTROLLER_NAME,\n BridgeControllerState\n>;\n\nexport type BridgeControllerActions =\n | BridgeControllerGetStateAction\n | BridgeControllerMethodActions;\n\nexport type BridgeControllerEvents = BridgeControllerStateChangeEvent;\n\nexport type AllowedActions =\n | AccountsControllerGetAccountByAddressAction\n | AuthenticationControllerGetBearerTokenAction\n | GetCurrencyRateState\n | TokenRatesControllerGetStateAction\n | MultichainAssetsRatesControllerGetStateAction\n | SnapControllerHandleRequestAction\n | NetworkControllerFindNetworkClientIdByChainIdAction\n | NetworkControllerGetNetworkClientByIdAction\n | RemoteFeatureFlagControllerGetStateAction\n | AssetsControllerGetExchangeRatesForBridgeAction;\nexport type AllowedEvents = never;\n\n/**\n * The messenger for the BridgeController.\n */\nexport type BridgeControllerMessenger = Messenger<\n typeof BRIDGE_CONTROLLER_NAME,\n BridgeControllerActions | AllowedActions,\n BridgeControllerEvents | AllowedEvents\n>;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assets.cjs","sourceRoot":"","sources":["../../src/utils/assets.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"assets.cjs","sourceRoot":"","sources":["../../src/utils/assets.ts"],"names":[],"mappings":";;;AAGA,yCAAoD;AACpD,2DAA2D;AAEpD,MAAM,mBAAmB,GAAG,CACjC,YAAoD,EACpD,OAA0C,EAC1C,EAAE;IACF,MAAM,eAAe,GAAoB,EAAE,CAAC;IAE5C,MAAM,OAAO,GAAG,IAAA,wCAAsB,EAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IAC9D,IAAI,OAAO,EAAE,CAAC;QACZ,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC9B,IAAA,iCAAwB,EAAC,OAAO,CAAC,EAAE,OAAO;YACxC,eAAe,CAAC,IAAI,CAAC,IAAA,iCAAwB,EAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC;IACpE,CAAC;IAED,OAAO,eAAe,CAAC;AACzB,CAAC,CAAC;AAdW,QAAA,mBAAmB,uBAc9B;AAEK,MAAM,eAAe,GAAG,CAC7B,QAAgB,EAChB,eAEC,EACD,EAAE;IACF,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC,MAAM,CAE1D,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE,EAAE;QAC3B,IAAI,MAAM,EAAE,CAAC;YACX,GAAG,CAAC,OAAwB,CAAC,GAAG;gBAC9B,YAAY,EAAE,MAAM,CAAC,QAAQ,CAAC;gBAC9B,eAAe,EAAE,MAAM,CAAC,GAAG;aAC5B,CAAC;QACJ,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC,EAAE,EAAE,CAAC,CAAC;IACP,OAAO,aAAa,CAAC;AACvB,CAAC,CAAC;AAlBW,QAAA,eAAe,mBAkB1B","sourcesContent":["import type { CaipAssetType } from '@metamask/utils';\n\nimport type { ExchangeRate, GenericQuoteRequest } from '../types';\nimport { getNativeAssetForChainId } from './bridge';\nimport { formatAddressToAssetId } from './caip-formatters';\n\nexport const getAssetIdsForToken = (\n tokenAddress: GenericQuoteRequest['srcTokenAddress'],\n chainId: GenericQuoteRequest['srcChainId'],\n) => {\n const assetIdsToFetch: CaipAssetType[] = [];\n\n const assetId = formatAddressToAssetId(tokenAddress, chainId);\n if (assetId) {\n assetIdsToFetch.push(assetId);\n getNativeAssetForChainId(chainId)?.assetId &&\n assetIdsToFetch.push(getNativeAssetForChainId(chainId).assetId);\n }\n\n return assetIdsToFetch;\n};\n\nexport const toExchangeRates = (\n currency: string,\n pricesByAssetId: {\n [assetId: CaipAssetType]: { [currency: string]: string } | undefined;\n },\n) => {\n const exchangeRates = Object.entries(pricesByAssetId).reduce<\n Record<CaipAssetType, ExchangeRate>\n >((acc, [assetId, prices]) => {\n if (prices) {\n acc[assetId as CaipAssetType] = {\n exchangeRate: prices[currency],\n usdExchangeRate: prices.usd,\n };\n }\n return acc;\n }, {});\n return exchangeRates;\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assets.d.cts","sourceRoot":"","sources":["../../src/utils/assets.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,wBAAwB;
|
|
1
|
+
{"version":3,"file":"assets.d.cts","sourceRoot":"","sources":["../../src/utils/assets.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,wBAAwB;AAErD,OAAO,KAAK,EAAE,YAAY,EAAE,mBAAmB,EAAE,qBAAiB;AAIlE,eAAO,MAAM,mBAAmB,iBAChB,mBAAmB,CAAC,iBAAiB,CAAC,WAC3C,mBAAmB,CAAC,YAAY,CAAC,gDAY3C,CAAC;AAEF,eAAO,MAAM,eAAe,aAChB,MAAM;;;;qEAiBjB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assets.d.mts","sourceRoot":"","sources":["../../src/utils/assets.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,wBAAwB;
|
|
1
|
+
{"version":3,"file":"assets.d.mts","sourceRoot":"","sources":["../../src/utils/assets.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,wBAAwB;AAErD,OAAO,KAAK,EAAE,YAAY,EAAE,mBAAmB,EAAE,qBAAiB;AAIlE,eAAO,MAAM,mBAAmB,iBAChB,mBAAmB,CAAC,iBAAiB,CAAC,WAC3C,mBAAmB,CAAC,YAAY,CAAC,gDAY3C,CAAC;AAEF,eAAO,MAAM,eAAe,aAChB,MAAM;;;;qEAiBjB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assets.mjs","sourceRoot":"","sources":["../../src/utils/assets.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"assets.mjs","sourceRoot":"","sources":["../../src/utils/assets.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,wBAAwB,EAAE,qBAAiB;AACpD,OAAO,EAAE,sBAAsB,EAAE,8BAA0B;AAE3D,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,YAAoD,EACpD,OAA0C,EAC1C,EAAE;IACF,MAAM,eAAe,GAAoB,EAAE,CAAC;IAE5C,MAAM,OAAO,GAAG,sBAAsB,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IAC9D,IAAI,OAAO,EAAE,CAAC;QACZ,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC9B,wBAAwB,CAAC,OAAO,CAAC,EAAE,OAAO;YACxC,eAAe,CAAC,IAAI,CAAC,wBAAwB,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC;IACpE,CAAC;IAED,OAAO,eAAe,CAAC;AACzB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,QAAgB,EAChB,eAEC,EACD,EAAE;IACF,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC,MAAM,CAE1D,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE,EAAE;QAC3B,IAAI,MAAM,EAAE,CAAC;YACX,GAAG,CAAC,OAAwB,CAAC,GAAG;gBAC9B,YAAY,EAAE,MAAM,CAAC,QAAQ,CAAC;gBAC9B,eAAe,EAAE,MAAM,CAAC,GAAG;aAC5B,CAAC;QACJ,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC,EAAE,EAAE,CAAC,CAAC;IACP,OAAO,aAAa,CAAC;AACvB,CAAC,CAAC","sourcesContent":["import type { CaipAssetType } from '@metamask/utils';\n\nimport type { ExchangeRate, GenericQuoteRequest } from '../types';\nimport { getNativeAssetForChainId } from './bridge';\nimport { formatAddressToAssetId } from './caip-formatters';\n\nexport const getAssetIdsForToken = (\n tokenAddress: GenericQuoteRequest['srcTokenAddress'],\n chainId: GenericQuoteRequest['srcChainId'],\n) => {\n const assetIdsToFetch: CaipAssetType[] = [];\n\n const assetId = formatAddressToAssetId(tokenAddress, chainId);\n if (assetId) {\n assetIdsToFetch.push(assetId);\n getNativeAssetForChainId(chainId)?.assetId &&\n assetIdsToFetch.push(getNativeAssetForChainId(chainId).assetId);\n }\n\n return assetIdsToFetch;\n};\n\nexport const toExchangeRates = (\n currency: string,\n pricesByAssetId: {\n [assetId: CaipAssetType]: { [currency: string]: string } | undefined;\n },\n) => {\n const exchangeRates = Object.entries(pricesByAssetId).reduce<\n Record<CaipAssetType, ExchangeRate>\n >((acc, [assetId, prices]) => {\n if (prices) {\n acc[assetId as CaipAssetType] = {\n exchangeRate: prices[currency],\n usdExchangeRate: prices.usd,\n };\n }\n return acc;\n }, {});\n return exchangeRates;\n};\n"]}
|
package/dist/utils/bridge.cjs
CHANGED
|
@@ -6,12 +6,12 @@ const contracts_1 = require("@ethersproject/contracts");
|
|
|
6
6
|
const keyring_api_1 = require("@metamask/keyring-api");
|
|
7
7
|
const metamask_eth_abis_1 = require("@metamask/metamask-eth-abis");
|
|
8
8
|
const utils_1 = require("@metamask/utils");
|
|
9
|
-
const caip_formatters_1 = require("./caip-formatters.cjs");
|
|
10
9
|
const bridge_1 = require("../constants/bridge.cjs");
|
|
11
10
|
const chains_1 = require("../constants/chains.cjs");
|
|
12
11
|
const swaps_1 = require("../constants/swaps.cjs");
|
|
13
12
|
const tokens_1 = require("../constants/tokens.cjs");
|
|
14
13
|
const types_1 = require("../types.cjs");
|
|
14
|
+
const caip_formatters_1 = require("./caip-formatters.cjs");
|
|
15
15
|
/**
|
|
16
16
|
* Checks whether the transaction is a cross-chain transaction by comparing the source and destination chainIds
|
|
17
17
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bridge.cjs","sourceRoot":"","sources":["../../src/utils/bridge.ts"],"names":[],"mappings":";;;AAAA,wDAAuD;AACvD,wDAAoD;AACpD,uDAAqE;AACrE,mEAAuD;AACvD,2CAAmE;AAGnE,2DAI2B;AAC3B,oDAI6B;AAC7B,oDAAgD;AAChD,kDAA8D;AAC9D,oDAG6B;AAS7B,wCAAmC;AAEnC;;;;;;GAMG;AACI,MAAM,YAAY,GAAG,CAC1B,UAA6C,EAC7C,WAAgD,EAChD,EAAE;IACF,IAAI,CAAC;QACH,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,OAAO,KAAK,CAAC;QACf,CAAC;QACD,OAAO,IAAA,qCAAmB,EAAC,UAAU,CAAC,KAAK,IAAA,qCAAmB,EAAC,WAAW,CAAC,CAAC;IAC9E,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC,CAAC;AAZW,QAAA,YAAY,gBAYvB;AAEK,MAAM,+BAA+B,GAAG,GAA0B,EAAE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BAO3B;AAEK,MAAM,aAAa,GAAG,CAAC,OAA4C,EAAE,EAAE;IAC5E,IAAI,IAAA,qBAAa,EAAC,OAAO,CAAC,EAAE,CAAC;QAC3B,OAAO,OAAO,KAAK,sBAAQ,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;IACjD,CAAC;IACD,OAAO,OAAO,CAAC,QAAQ,EAAE,KAAK,eAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;AACxD,CAAC,CAAC;AALW,QAAA,aAAa,iBAKxB;AAEF;;;;;;GAMG;AACI,MAAM,eAAe,GAAG,CAC7B,OAA0C,EACjC,EAAE;IACX,OAAO,CACL,IAAA,uBAAe,EAAC,OAAO,CAAC;QACxB,IAAA,wBAAgB,EAAC,OAAO,CAAC;QACzB,IAAA,qBAAa,EAAC,OAAO,CAAC,CACvB,CAAC;AACJ,CAAC,CAAC;AARW,QAAA,eAAe,mBAQ1B;AAEK,MAAM,kBAAkB,GAAG,CAChC,aAA4B,EACoB,EAAE;IAClD,OAAO,CAAC,IAAA,uBAAe,EAAC,aAAa,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;AAC1D,CAAC,CAAC;AAJW,QAAA,kBAAkB,sBAI7B","sourcesContent":["import { AddressZero } from '@ethersproject/constants';\nimport { Contract } from '@ethersproject/contracts';\nimport { BtcScope, SolScope, TrxScope } from '@metamask/keyring-api';\nimport { abiERC20 } from '@metamask/metamask-eth-abis';\nimport { isCaipChainId, isStrictHexString } from '@metamask/utils';\nimport type { CaipAssetType, CaipChainId, 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 { SWAPS_CONTRACT_ADDRESSES } from '../constants/swaps';\nimport {\n SWAPS_CHAINID_DEFAULT_TOKEN_MAP,\n SYMBOL_TO_SLIP44_MAP,\n} from '../constants/tokens';\nimport type { SupportedSwapsNativeCurrencySymbols } from '../constants/tokens';\nimport type {\n BridgeAsset,\n BridgeControllerState,\n GenericQuoteRequest,\n QuoteResponse,\n TxData,\n} from '../types';\nimport { ChainId } from '../types';\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\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 * @param destChainId - The destination chain ID\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 destChainId: GenericQuoteRequest['destChainId'],\n) => {\n const spenderAddress = isCrossChain(CHAIN_IDS.MAINNET, destChainId)\n ? METABRIDGE_ETHEREUM_ADDRESS\n : SWAPS_CONTRACT_ADDRESSES[CHAIN_IDS.MAINNET];\n const UsdtContractInterface = new Contract(ETH_USDT_ADDRESS, abiERC20)\n .interface;\n const data = UsdtContractInterface.encodeFunctionData('approve', [\n spenderAddress,\n '0',\n ]);\n\n return data;\n};\n\nexport const isEthUsdt = (\n chainId: GenericQuoteRequest['srcChainId'],\n address: string,\n) =>\n formatChainIdToDec(chainId) === ChainId.ETH &&\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 (!isStrictHexString(address) &&\n Object.values(SYMBOL_TO_SLIP44_MAP).some(\n // check if it matches any supported SLIP44 references\n (reference) => address.includes(reference) || reference.endsWith(address),\n ));\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\nexport const isBitcoinChainId = (\n chainId: Hex | number | CaipChainId | string,\n) => {\n if (isCaipChainId(chainId)) {\n return chainId === BtcScope.Mainnet.toString();\n }\n return chainId.toString() === ChainId.BTC.toString();\n};\n\nexport const isTronChainId = (chainId: Hex | number | CaipChainId | string) => {\n if (isCaipChainId(chainId)) {\n return chainId === TrxScope.Mainnet.toString();\n }\n return chainId.toString() === ChainId.TRON.toString();\n};\n\n/**\n * Checks if a chain ID represents a non-EVM blockchain supported by swaps\n * Currently supports Solana, Bitcoin and Tron\n *\n * @param chainId - The chain ID to check\n * @returns True if the chain is a supported non-EVM chain, false otherwise\n */\nexport const isNonEvmChainId = (\n chainId: GenericQuoteRequest['srcChainId'],\n): boolean => {\n return (\n isSolanaChainId(chainId) ||\n isBitcoinChainId(chainId) ||\n isTronChainId(chainId)\n );\n};\n\nexport const isEvmQuoteResponse = (\n quoteResponse: QuoteResponse,\n): quoteResponse is QuoteResponse<TxData, TxData> => {\n return !isNonEvmChainId(quoteResponse.quote.srcChainId);\n};\n"]}
|
|
1
|
+
{"version":3,"file":"bridge.cjs","sourceRoot":"","sources":["../../src/utils/bridge.ts"],"names":[],"mappings":";;;AAAA,wDAAuD;AACvD,wDAAoD;AACpD,uDAAqE;AACrE,mEAAuD;AACvD,2CAAmE;AAGnE,oDAI6B;AAC7B,oDAAgD;AAChD,kDAA8D;AAC9D,oDAG6B;AAS7B,wCAAmC;AACnC,2DAI2B;AAE3B;;;;;;GAMG;AACI,MAAM,YAAY,GAAG,CAC1B,UAA6C,EAC7C,WAAgD,EAChD,EAAE;IACF,IAAI,CAAC;QACH,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,OAAO,KAAK,CAAC;QACf,CAAC;QACD,OAAO,IAAA,qCAAmB,EAAC,UAAU,CAAC,KAAK,IAAA,qCAAmB,EAAC,WAAW,CAAC,CAAC;IAC9E,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC,CAAC;AAZW,QAAA,YAAY,gBAYvB;AAEK,MAAM,+BAA+B,GAAG,GAA0B,EAAE;IACzE,OAAO,wCAA+B,CAAC;AACzC,CAAC,CAAC;AAFW,QAAA,+BAA+B,mCAE1C;AAEF;;;;;;;GAOG;AACH,MAAM,2BAA2B,GAAG,CAClC,OAAoB,EACpB,oBAAyD,EAC1C,EAAE;IACjB,OAAO,GAAG,IAAA,qCAAmB,EAAC,OAAO,CAAC,IAAI,6BAAoB,CAAC,oBAAoB,CAAC,EAAE,CAAC;AACzF,CAAC,CAAC;AAEF;;;;;;GAMG;AACI,MAAM,wBAAwB,GAAG,CACtC,OAA4C,EAC/B,EAAE;IACf,MAAM,aAAa,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AG,CAC7B,OAA0C,EACjC,EAAE;IACX,OAAO,CACL,IAAA,uBAAe,EAAC,OAAO,CAAC;QACxB,IAAA,wBAAgB,EAAC,OAAO,CAAC;QACzB,IAAA,qBAAa,EAAC,OAAO,CAAC,CACvB,CAAC;AACJ,CAAC,CAAC;AARW,QAAA,eAAe,mBAQ1B;AAEK,MAAM,kBAAkB,GAAG,CAChC,aAA4B,EACoB,EAAE;IAClD,OAAO,CAAC,IAAA,uBAAe,EAAC,aAAa,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;AAC1D,CAAC,CAAC;AAJW,QAAA,kBAAkB,sBAI7B","sourcesContent":["import { AddressZero } from '@ethersproject/constants';\nimport { Contract } from '@ethersproject/contracts';\nimport { BtcScope, SolScope, TrxScope } from '@metamask/keyring-api';\nimport { abiERC20 } from '@metamask/metamask-eth-abis';\nimport { isCaipChainId, isStrictHexString } from '@metamask/utils';\nimport type { CaipAssetType, CaipChainId, Hex } from '@metamask/utils';\n\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 { SWAPS_CONTRACT_ADDRESSES } from '../constants/swaps';\nimport {\n SWAPS_CHAINID_DEFAULT_TOKEN_MAP,\n SYMBOL_TO_SLIP44_MAP,\n} from '../constants/tokens';\nimport type { SupportedSwapsNativeCurrencySymbols } from '../constants/tokens';\nimport type {\n BridgeAsset,\n BridgeControllerState,\n GenericQuoteRequest,\n QuoteResponse,\n TxData,\n} from '../types';\nimport { ChainId } from '../types';\nimport {\n formatChainIdToCaip,\n formatChainIdToDec,\n formatChainIdToHex,\n} from './caip-formatters';\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\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 * @param destChainId - The destination chain ID\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 destChainId: GenericQuoteRequest['destChainId'],\n) => {\n const spenderAddress = isCrossChain(CHAIN_IDS.MAINNET, destChainId)\n ? METABRIDGE_ETHEREUM_ADDRESS\n : SWAPS_CONTRACT_ADDRESSES[CHAIN_IDS.MAINNET];\n const UsdtContractInterface = new Contract(ETH_USDT_ADDRESS, abiERC20)\n .interface;\n const data = UsdtContractInterface.encodeFunctionData('approve', [\n spenderAddress,\n '0',\n ]);\n\n return data;\n};\n\nexport const isEthUsdt = (\n chainId: GenericQuoteRequest['srcChainId'],\n address: string,\n) =>\n formatChainIdToDec(chainId) === ChainId.ETH &&\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 (!isStrictHexString(address) &&\n Object.values(SYMBOL_TO_SLIP44_MAP).some(\n // check if it matches any supported SLIP44 references\n (reference) => address.includes(reference) || reference.endsWith(address),\n ));\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\nexport const isBitcoinChainId = (\n chainId: Hex | number | CaipChainId | string,\n) => {\n if (isCaipChainId(chainId)) {\n return chainId === BtcScope.Mainnet.toString();\n }\n return chainId.toString() === ChainId.BTC.toString();\n};\n\nexport const isTronChainId = (chainId: Hex | number | CaipChainId | string) => {\n if (isCaipChainId(chainId)) {\n return chainId === TrxScope.Mainnet.toString();\n }\n return chainId.toString() === ChainId.TRON.toString();\n};\n\n/**\n * Checks if a chain ID represents a non-EVM blockchain supported by swaps\n * Currently supports Solana, Bitcoin and Tron\n *\n * @param chainId - The chain ID to check\n * @returns True if the chain is a supported non-EVM chain, false otherwise\n */\nexport const isNonEvmChainId = (\n chainId: GenericQuoteRequest['srcChainId'],\n): boolean => {\n return (\n isSolanaChainId(chainId) ||\n isBitcoinChainId(chainId) ||\n isTronChainId(chainId)\n );\n};\n\nexport const isEvmQuoteResponse = (\n quoteResponse: QuoteResponse,\n): quoteResponse is QuoteResponse<TxData, TxData> => {\n return !isNonEvmChainId(quoteResponse.quote.srcChainId);\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bridge.d.cts","sourceRoot":"","sources":["../../src/utils/bridge.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAiB,WAAW,EAAE,GA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AAa,YAAa,GAAG,GAAG,MAAM,GAAG,WAAW,GAAG,MAAM,YAKzE,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,YACjB,mBAAmB,CAAC,YAAY,CAAC,KACzC,OAMF,CAAC;AAEF,eAAO,MAAM,kBAAkB,kBACd,aAAa;;;;;;;;;;;;;;;;EAG7B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bridge.d.mts","sourceRoot":"","sources":["../../src/utils/bridge.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAiB,WAAW,EAAE,GAAG,EAAE,wBAAwB;
|
|
1
|
+
{"version":3,"file":"bridge.d.mts","sourceRoot":"","sources":["../../src/utils/bridge.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAiB,WAAW,EAAE,GAAG,EAAE,wBAAwB;AAcvE,OAAO,KAAK,EACV,WAAW,EACX,qBAAqB,EACrB,mBAAmB,EACnB,aAAa,EAEd,qBAAiB;AAQlB;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,eACX,mBAAmB,CAAC,YAAY,CAAC,gBAC/B,mBAAmB,CAAC,aAAa,CAAC,YAUjD,CAAC;AAEF,eAAO,MAAM,+BAA+B,QAAO,qBAElD,CAAC;AAiBF;;;;;;GAMG;AACH,eAAO,MAAM,wBAAwB,YAC1B,MAAM,GAAG,MAAM,GAAG,GAAG,GAAG,WAAW,KAC3C,WAyBF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,gBACjB,mBAAmB,CAAC,aAAa,CAAC,WAahD,CAAC;AAEF,eAAO,MAAM,SAAS,YACX,mBAAmB,CAAC,YAAY,CAAC,WACjC,MAAM,YAGyC,CAAC;AAE3D,eAAO,MAAM,QAAQ,kBAAmB,MAAM,EAAE,KAAG,GAOlD,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,0BAA0B,YAC5B,MAAM,WACN,GAAG,GAAG,WAAW,YAO3B,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,yBAAyB,WAC5B,MAAM,WACL,GAAG,GAAG,WAAW,YAO3B,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,aAAc,MAAM,GAAG,IAAI,YAQjD,CAAC;AAEP;;;;;GAKG;AACH,eAAO,MAAM,eAAe,YACjB,GAAG,GAAG,MAAM,GAAG,WAAW,GAAG,MAAM,YAM7C,CAAC;AAEF,eAAO,MAAM,gBAAgB,YAClB,GAAG,GAAG,MAAM,GAAG,WAAW,GAAG,MAAM,YAM7C,CAAC;AAEF,eAAO,MAAM,aAAa,YAAa,GAAG,GAAG,MAAM,GAAG,WAAW,GAAG,MAAM,YAKzE,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,YACjB,mBAAmB,CAAC,YAAY,CAAC,KACzC,OAMF,CAAC;AAEF,eAAO,MAAM,kBAAkB,kBACd,aAAa;;;;;;;;;;;;;;;;EAG7B,CAAC"}
|
package/dist/utils/bridge.mjs
CHANGED
|
@@ -3,12 +3,12 @@ import { Contract } from "@ethersproject/contracts";
|
|
|
3
3
|
import { BtcScope, SolScope, TrxScope } from "@metamask/keyring-api";
|
|
4
4
|
import { abiERC20 } from "@metamask/metamask-eth-abis";
|
|
5
5
|
import { isCaipChainId, isStrictHexString } from "@metamask/utils";
|
|
6
|
-
import { formatChainIdToCaip, formatChainIdToDec, formatChainIdToHex } from "./caip-formatters.mjs";
|
|
7
6
|
import { DEFAULT_BRIDGE_CONTROLLER_STATE, ETH_USDT_ADDRESS, METABRIDGE_ETHEREUM_ADDRESS } from "../constants/bridge.mjs";
|
|
8
7
|
import { CHAIN_IDS } from "../constants/chains.mjs";
|
|
9
8
|
import { SWAPS_CONTRACT_ADDRESSES } from "../constants/swaps.mjs";
|
|
10
9
|
import { SWAPS_CHAINID_DEFAULT_TOKEN_MAP, SYMBOL_TO_SLIP44_MAP } from "../constants/tokens.mjs";
|
|
11
10
|
import { ChainId } from "../types.mjs";
|
|
11
|
+
import { formatChainIdToCaip, formatChainIdToDec, formatChainIdToHex } from "./caip-formatters.mjs";
|
|
12
12
|
/**
|
|
13
13
|
* Checks whether the transaction is a cross-chain transaction by comparing the source and destination chainIds
|
|
14
14
|
*
|
|
@@ -1 +1 @@
|
|
|
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,QAAQ,EAAE,QAAQ,EAAE,8BAA8B;AACrE,OAAO,EAAE,QAAQ,EAAE,oCAAoC;AACvD,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,wBAAwB;AAGnE,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,EAAE,wBAAwB,EAAE,+BAA2B;AAC9D,OAAO,EACL,+BAA+B,EAC/B,oBAAoB,EACrB,gCAA4B;AAS7B,OAAO,EAAE,OAAO,EAAE,qBAAiB;AAEnC;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAC1B,UAA6C,EAC7C,WAAgD,EAChD,EAAE;IACF,IAAI,CAAC;QACH,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,OAAO,KAAK,CAAC;QACf,CAAC;QACD,OAAO,mBAAmB,CAAC,UAAU,CAAC,KAAK,mBAAmB,CAAC,WAAW,CAAC,CAAC;IAC9E,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,+BAA+B,GAAG,GAA0B,EAAE;IACzE,OAAO,+BAA+B,CAAC;AACzC,CA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xD,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,OAA0C,EACjC,EAAE;IACX,OAAO,CACL,eAAe,CAAC,OAAO,CAAC;QACxB,gBAAgB,CAAC,OAAO,CAAC;QACzB,aAAa,CAAC,OAAO,CAAC,CACvB,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,aAA4B,EACoB,EAAE;IAClD,OAAO,CAAC,eAAe,CAAC,aAAa,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;AAC1D,CAAC,CAAC","sourcesContent":["import { AddressZero } from '@ethersproject/constants';\nimport { Contract } from '@ethersproject/contracts';\nimport { BtcScope, SolScope, TrxScope } from '@metamask/keyring-api';\nimport { abiERC20 } from '@metamask/metamask-eth-abis';\nimport { isCaipChainId, isStrictHexString } from '@metamask/utils';\nimport type { CaipAssetType, CaipChainId, 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 { SWAPS_CONTRACT_ADDRESSES } from '../constants/swaps';\nimport {\n SWAPS_CHAINID_DEFAULT_TOKEN_MAP,\n SYMBOL_TO_SLIP44_MAP,\n} from '../constants/tokens';\nimport type { SupportedSwapsNativeCurrencySymbols } from '../constants/tokens';\nimport type {\n BridgeAsset,\n BridgeControllerState,\n GenericQuoteRequest,\n QuoteResponse,\n TxData,\n} from '../types';\nimport { ChainId } from '../types';\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\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 * @param destChainId - The destination chain ID\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 destChainId: GenericQuoteRequest['destChainId'],\n) => {\n const spenderAddress = isCrossChain(CHAIN_IDS.MAINNET, destChainId)\n ? METABRIDGE_ETHEREUM_ADDRESS\n : SWAPS_CONTRACT_ADDRESSES[CHAIN_IDS.MAINNET];\n const UsdtContractInterface = new Contract(ETH_USDT_ADDRESS, abiERC20)\n .interface;\n const data = UsdtContractInterface.encodeFunctionData('approve', [\n spenderAddress,\n '0',\n ]);\n\n return data;\n};\n\nexport const isEthUsdt = (\n chainId: GenericQuoteRequest['srcChainId'],\n address: string,\n) =>\n formatChainIdToDec(chainId) === ChainId.ETH &&\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 (!isStrictHexString(address) &&\n Object.values(SYMBOL_TO_SLIP44_MAP).some(\n // check if it matches any supported SLIP44 references\n (reference) => address.includes(reference) || reference.endsWith(address),\n ));\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\nexport const isBitcoinChainId = (\n chainId: Hex | number | CaipChainId | string,\n) => {\n if (isCaipChainId(chainId)) {\n return chainId === BtcScope.Mainnet.toString();\n }\n return chainId.toString() === ChainId.BTC.toString();\n};\n\nexport const isTronChainId = (chainId: Hex | number | CaipChainId | string) => {\n if (isCaipChainId(chainId)) {\n return chainId === TrxScope.Mainnet.toString();\n }\n return chainId.toString() === ChainId.TRON.toString();\n};\n\n/**\n * Checks if a chain ID represents a non-EVM blockchain supported by swaps\n * Currently supports Solana, Bitcoin and Tron\n *\n * @param chainId - The chain ID to check\n * @returns True if the chain is a supported non-EVM chain, false otherwise\n */\nexport const isNonEvmChainId = (\n chainId: GenericQuoteRequest['srcChainId'],\n): boolean => {\n return (\n isSolanaChainId(chainId) ||\n isBitcoinChainId(chainId) ||\n isTronChainId(chainId)\n );\n};\n\nexport const isEvmQuoteResponse = (\n quoteResponse: QuoteResponse,\n): quoteResponse is QuoteResponse<TxData, TxData> => {\n return !isNonEvmChainId(quoteResponse.quote.srcChainId);\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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,aAAa,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;AAC1D,CAAC,CAAC","sourcesContent":["import { AddressZero } from '@ethersproject/constants';\nimport { Contract } from '@ethersproject/contracts';\nimport { BtcScope, SolScope, TrxScope } from '@metamask/keyring-api';\nimport { abiERC20 } from '@metamask/metamask-eth-abis';\nimport { isCaipChainId, isStrictHexString } from '@metamask/utils';\nimport type { CaipAssetType, CaipChainId, Hex } from '@metamask/utils';\n\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 { SWAPS_CONTRACT_ADDRESSES } from '../constants/swaps';\nimport {\n SWAPS_CHAINID_DEFAULT_TOKEN_MAP,\n SYMBOL_TO_SLIP44_MAP,\n} from '../constants/tokens';\nimport type { SupportedSwapsNativeCurrencySymbols } from '../constants/tokens';\nimport type {\n BridgeAsset,\n BridgeControllerState,\n GenericQuoteRequest,\n QuoteResponse,\n TxData,\n} from '../types';\nimport { ChainId } from '../types';\nimport {\n formatChainIdToCaip,\n formatChainIdToDec,\n formatChainIdToHex,\n} from './caip-formatters';\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\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 * @param destChainId - The destination chain ID\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 destChainId: GenericQuoteRequest['destChainId'],\n) => {\n const spenderAddress = isCrossChain(CHAIN_IDS.MAINNET, destChainId)\n ? METABRIDGE_ETHEREUM_ADDRESS\n : SWAPS_CONTRACT_ADDRESSES[CHAIN_IDS.MAINNET];\n const UsdtContractInterface = new Contract(ETH_USDT_ADDRESS, abiERC20)\n .interface;\n const data = UsdtContractInterface.encodeFunctionData('approve', [\n spenderAddress,\n '0',\n ]);\n\n return data;\n};\n\nexport const isEthUsdt = (\n chainId: GenericQuoteRequest['srcChainId'],\n address: string,\n) =>\n formatChainIdToDec(chainId) === ChainId.ETH &&\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 (!isStrictHexString(address) &&\n Object.values(SYMBOL_TO_SLIP44_MAP).some(\n // check if it matches any supported SLIP44 references\n (reference) => address.includes(reference) || reference.endsWith(address),\n ));\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\nexport const isBitcoinChainId = (\n chainId: Hex | number | CaipChainId | string,\n) => {\n if (isCaipChainId(chainId)) {\n return chainId === BtcScope.Mainnet.toString();\n }\n return chainId.toString() === ChainId.BTC.toString();\n};\n\nexport const isTronChainId = (chainId: Hex | number | CaipChainId | string) => {\n if (isCaipChainId(chainId)) {\n return chainId === TrxScope.Mainnet.toString();\n }\n return chainId.toString() === ChainId.TRON.toString();\n};\n\n/**\n * Checks if a chain ID represents a non-EVM blockchain supported by swaps\n * Currently supports Solana, Bitcoin and Tron\n *\n * @param chainId - The chain ID to check\n * @returns True if the chain is a supported non-EVM chain, false otherwise\n */\nexport const isNonEvmChainId = (\n chainId: GenericQuoteRequest['srcChainId'],\n): boolean => {\n return (\n isSolanaChainId(chainId) ||\n isBitcoinChainId(chainId) ||\n isTronChainId(chainId)\n );\n};\n\nexport const isEvmQuoteResponse = (\n quoteResponse: QuoteResponse,\n): quoteResponse is QuoteResponse<TxData, TxData> => {\n return !isNonEvmChainId(quoteResponse.quote.srcChainId);\n};\n"]}
|
|
@@ -8,8 +8,8 @@ const controller_utils_1 = require("@metamask/controller-utils");
|
|
|
8
8
|
const keyring_api_1 = require("@metamask/keyring-api");
|
|
9
9
|
const multichain_network_controller_1 = require("@metamask/multichain-network-controller");
|
|
10
10
|
const utils_1 = require("@metamask/utils");
|
|
11
|
-
const bridge_1 = require("./bridge.cjs");
|
|
12
11
|
const types_1 = require("../types.cjs");
|
|
12
|
+
const bridge_1 = require("./bridge.cjs");
|
|
13
13
|
/**
|
|
14
14
|
* Converts a chainId to a CaipChainId
|
|
15
15
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"caip-formatters.cjs","sourceRoot":"","sources":["../../src/utils/caip-formatters.ts"],"names":[],"mappings":";;;AAAA,qEAAqE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,CAAC,EAAE,CAAC;QACtC,OAAO,IAAA,iCAAwB,EAAC,WAAW,CAAC,CAAC,OAAO,CAAC;IACvD,CAAC;IACD,IAAI,WAAW,KAAK,sBAAQ,CAAC,OAAO,EAAE,CAAC;QACrC,OAAO,2BAAmB,CAAC,MAAM,CAC/B,GAAG,WAAW,UAAU,gBAAgB,EAAE,CAC3C,CAAC;IACJ,CAAC;IAED,IAAI,WAAW,KAAK,sBAAQ,CAAC,OAAO,EAAE,CAAC;QACrC,OAAO,2BAAmB,CAAC,MAAM,CAC/B,GAAG,WAAW,UAAU,gBAAgB,EAAE,CAC3C,CAAC;IACJ,CAAC;IAED,aAAa;IACb,IAAI,CAAC,IAAA,yBAAiB,EAAC,gBAAgB,CAAC,EAAE,CAAC;QACzC,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,aAAa;IACb,MAAM,kBAAkB,GAAG,IAAA,uCAAoB,EAAC,gBAAgB,CAAC,CAAC;IAClE,OAAO,2BAAmB,CAAC,MAAM,CAC/B,GAAG,WAAW,UAAU,kBAAkB,EAAE,CAC7C,CAAC;AACJ,CAAC,CAAC;AArCW,QAAA,sBAAsB,0BAqCjC","sourcesContent":["/* eslint-disable @typescript-eslint/explicit-function-return-type */\nimport { getAddress } from '@ethersproject/address';\nimport { AddressZero } from '@ethersproject/constants';\nimport {\n convertHexToDecimal,\n toChecksumHexAddress,\n} from '@metamask/controller-utils';\nimport { BtcScope, SolScope, TrxScope } from '@metamask/keyring-api';\nimport { toEvmCaipChainId } from '@metamask/multichain-network-controller';\nimport {\n isCaipChainId,\n isStrictHexString,\n parseCaipChainId,\n isCaipReference,\n isCaipAssetType,\n CaipAssetTypeStruct,\n numberToHex,\n} from '@metamask/utils';\nimport type { CaipAssetType, CaipChainId, Hex } from '@metamask/utils';\n\nimport type { GenericQuoteRequest } from '../types';\nimport { ChainId } from '../types';\nimport {\n getNativeAssetForChainId,\n isBitcoinChainId,\n isNativeAddress,\n isSolanaChainId,\n isTronChainId,\n} from './bridge';\n\n/**\n * Converts a chainId to a CaipChainId\n *\n * @param chainId - The chainId to convert\n * @returns The CaipChainId\n */\nexport const formatChainIdToCaip = (\n chainId: Hex | number | CaipChainId | string,\n): CaipChainId => {\n if (isCaipChainId(chainId)) {\n return chainId;\n }\n if (isStrictHexString(chainId)) {\n return toEvmCaipChainId(chainId);\n }\n if (isSolanaChainId(chainId)) {\n return SolScope.Mainnet;\n }\n if (isBitcoinChainId(chainId)) {\n return BtcScope.Mainnet;\n }\n if (isTronChainId(chainId)) {\n return TrxScope.Mainnet;\n }\n return toEvmCaipChainId(numberToHex(Number(chainId)));\n};\n\n/**\n * Converts a chainId to a decimal number that can be used for bridge-api requests\n *\n * @param chainId - The chainId to convert\n * @returns The decimal number\n */\nexport const formatChainIdToDec = (\n chainId: number | Hex | CaipChainId | string,\n) => {\n if (isStrictHexString(chainId)) {\n return convertHexToDecimal(chainId);\n }\n if (chainId === SolScope.Mainnet) {\n return ChainId.SOLANA;\n }\n if (chainId === BtcScope.Mainnet) {\n return ChainId.BTC;\n }\n if (chainId === TrxScope.Mainnet) {\n return ChainId.TRON;\n }\n if (isCaipChainId(chainId)) {\n return Number(chainId.split(':').at(-1));\n }\n if (typeof chainId === 'string') {\n return parseInt(chainId, 10);\n }\n return chainId;\n};\n\n/**\n * Converts a chainId to a hex string used to read controller data within the app\n * Hex chainIds are also used for fetching exchange rates\n *\n * @param chainId - The chainId to convert\n * @returns The hex string\n */\nexport const formatChainIdToHex = (\n chainId: Hex | CaipChainId | string | number,\n): Hex => {\n if (isStrictHexString(chainId)) {\n return chainId;\n }\n if (typeof chainId === 'number' || parseInt(chainId, 10)) {\n return numberToHex(Number(chainId));\n }\n if (isCaipChainId(chainId)) {\n const { reference } = parseCaipChainId(chainId);\n if (isCaipReference(reference) && !isNaN(Number(reference))) {\n return numberToHex(Number(reference));\n }\n }\n // Throw an error if a non-evm chainId is passed to this function\n // This should never happen, but it's a sanity check\n throw new Error(`Invalid cross-chain swaps chainId: ${chainId}`);\n};\n\n/**\n * Converts an asset or account address to a string that can be used for bridge-api requests\n *\n * @param address - The address to convert\n * @returns The converted address\n */\nexport const formatAddressToCaipReference = (address: string) => {\n if (isStrictHexString(address)) {\n return getAddress(address);\n }\n // If the address looks like a native token, return the zero address because it's\n // what bridge-api uses to represent a native asset\n if (isNativeAddress(address)) {\n return AddressZero;\n }\n const addressWithoutPrefix = address.split(':').at(-1);\n // If the address is not a valid hex string or CAIP address, throw an error\n // This should never happen, but it's a sanity check\n if (!addressWithoutPrefix) {\n throw new Error('Invalid address');\n }\n return addressWithoutPrefix;\n};\n\n/**\n * Converts an address or assetId to a checksummed CaipAssetType\n *\n * @param addressOrAssetId - The address or assetId to convert\n * @param chainId - The chainId of the asset\n * @returns The CaipAssetType\n */\nexport const formatAddressToAssetId = (\n addressOrAssetId: Hex | CaipAssetType | string,\n chainId?: GenericQuoteRequest['srcChainId'],\n): CaipAssetType | undefined => {\n if (isCaipAssetType(addressOrAssetId)) {\n return addressOrAssetId;\n }\n if (!chainId) {\n return undefined;\n }\n\n const chainIdCaip = formatChainIdToCaip(chainId);\n if (isNativeAddress(addressOrAssetId)) {\n return getNativeAssetForChainId(chainIdCaip).assetId;\n }\n if (chainIdCaip === SolScope.Mainnet) {\n return CaipAssetTypeStruct.create(\n `${chainIdCaip}/token:${addressOrAssetId}`,\n );\n }\n\n if (chainIdCaip === TrxScope.Mainnet) {\n return CaipAssetTypeStruct.create(\n `${chainIdCaip}/trc20:${addressOrAssetId}`,\n );\n }\n\n // EVM assets\n if (!isStrictHexString(addressOrAssetId)) {\n return undefined;\n }\n\n // EVM assets\n const checksummedAddress = toChecksumHexAddress(addressOrAssetId);\n return CaipAssetTypeStruct.create(\n `${chainIdCaip}/erc20:${checksummedAddress}`,\n );\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"caip-formatters.d.cts","sourceRoot":"","sources":["../../src/utils/caip-formatters.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,GAAG,EAAE,wBAAwB;
|
|
1
|
+
{"version":3,"file":"caip-formatters.d.cts","sourceRoot":"","sources":["../../src/utils/caip-formatters.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,GAAG,EAAE,wBAAwB;AAEvE,OAAO,KAAK,EAAE,mBAAmB,EAAE,qBAAiB;AAUpD;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,YACrB,GAAG,GAAG,MAAM,GAAG,WAAW,GAAG,MAAM,KAC3C,WAiBF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,YACpB,MAAM,GAAG,GAAG,GAAG,WAAW,GAAG,MAAM,WAqB7C,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,YACpB,GAAG,GAAG,WAAW,GAAG,MAAM,GAAG,MAAM,KAC3C,GAgBF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,4BAA4B,YAAa,MAAM,WAgB3D,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,qBACf,GAAG,GAAG,aAAa,GAAG,MAAM,YACpC,mBAAmB,CAAC,YAAY,CAAC,KAC1C,aAAa,GAAG,SAkClB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"caip-formatters.d.mts","sourceRoot":"","sources":["../../src/utils/caip-formatters.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,GAAG,EAAE,wBAAwB;
|
|
1
|
+
{"version":3,"file":"caip-formatters.d.mts","sourceRoot":"","sources":["../../src/utils/caip-formatters.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,GAAG,EAAE,wBAAwB;AAEvE,OAAO,KAAK,EAAE,mBAAmB,EAAE,qBAAiB;AAUpD;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,YACrB,GAAG,GAAG,MAAM,GAAG,WAAW,GAAG,MAAM,KAC3C,WAiBF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,YACpB,MAAM,GAAG,GAAG,GAAG,WAAW,GAAG,MAAM,WAqB7C,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,YACpB,GAAG,GAAG,WAAW,GAAG,MAAM,GAAG,MAAM,KAC3C,GAgBF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,4BAA4B,YAAa,MAAM,WAgB3D,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,qBACf,GAAG,GAAG,aAAa,GAAG,MAAM,YACpC,mBAAmB,CAAC,YAAY,CAAC,KAC1C,aAAa,GAAG,SAkClB,CAAC"}
|
|
@@ -5,8 +5,8 @@ import { convertHexToDecimal, toChecksumHexAddress } from "@metamask/controller-
|
|
|
5
5
|
import { BtcScope, SolScope, TrxScope } from "@metamask/keyring-api";
|
|
6
6
|
import { toEvmCaipChainId } from "@metamask/multichain-network-controller";
|
|
7
7
|
import { isCaipChainId, isStrictHexString, parseCaipChainId, isCaipReference, isCaipAssetType, CaipAssetTypeStruct, numberToHex } from "@metamask/utils";
|
|
8
|
-
import { getNativeAssetForChainId, isBitcoinChainId, isNativeAddress, isSolanaChainId, isTronChainId } from "./bridge.mjs";
|
|
9
8
|
import { ChainId } from "../types.mjs";
|
|
9
|
+
import { getNativeAssetForChainId, isBitcoinChainId, isNativeAddress, isSolanaChainId, isTronChainId } from "./bridge.mjs";
|
|
10
10
|
/**
|
|
11
11
|
* Converts a chainId to a CaipChainId
|
|
12
12
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"caip-formatters.mjs","sourceRoot":"","sources":["../../src/utils/caip-formatters.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,OAAO,EAAE,UAAU,EAAE,+BAA+B;AACpD,OAAO,EAAE,WAAW,EAAE,iCAAiC;AACvD,OAAO,EACL,mBAAmB,EACnB,oBAAoB,EACrB,mCAAmC;AACpC,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,8BAA8B;AACrE,OAAO,EAAE,gBAAgB,EAAE,gDAAgD;AAC3E,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,mBAAmB,EACnB,WAAW,EACZ,wBAAwB;
|
|
1
|
+
{"version":3,"file":"caip-formatters.mjs","sourceRoot":"","sources":["../../src/utils/caip-formatters.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,OAAO,EAAE,UAAU,EAAE,+BAA+B;AACpD,OAAO,EAAE,WAAW,EAAE,iCAAiC;AACvD,OAAO,EACL,mBAAmB,EACnB,oBAAoB,EACrB,mCAAmC;AACpC,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,8BAA8B;AACrE,OAAO,EAAE,gBAAgB,EAAE,gDAAgD;AAC3E,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,mBAAmB,EACnB,WAAW,EACZ,wBAAwB;AAIzB,OAAO,EAAE,OAAO,EAAE,qBAAiB;AACnC,OAAO,EACL,wBAAwB,EACxB,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,aAAa,EACd,qBAAiB;AAElB;;;;;GAKG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,OAA4C,EAC/B,EAAE;IACf,IAAI,aAAa,CAAC,OAAO,CAAC,EAAE,CAAC;QAC3B,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,IAAI,iBAAiB,CAAC,OAAO,CAAC,EAAE,CAAC;QAC/B,OAAO,gBAAgB,CAAC,OAAO,CAAC,CAAC;IACnC,CAAC;IACD,IAAI,eAAe,CAAC,OAAO,CAAC,EAAE,CAAC;QAC7B,OAAO,QAAQ,CAAC,OAAO,CAAC;IAC1B,CAAC;I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AAM,CAAC,MAAM,sBAAsB,GAAG,CACpC,gBAA8C,EAC9C,OAA2C,EAChB,EAAE;IAC7B,IAAI,eAAe,CAAC,gBAAgB,CAAC,EAAE,CAAC;QACtC,OAAO,gBAAgB,CAAC;IAC1B,CAAC;IACD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,WAAW,GAAG,mBAAmB,CAAC,OAAO,CAAC,CAAC;IACjD,IAAI,eAAe,CAAC,gBAAgB,CAAC,EAAE,CAAC;QACtC,OAAO,wBAAwB,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC;IACvD,CAAC;IACD,IAAI,WAAW,KAAK,QAAQ,CAAC,OAAO,EAAE,CAAC;QACrC,OAAO,mBAAmB,CAAC,MAAM,CAC/B,GAAG,WAAW,UAAU,gBAAgB,EAAE,CAC3C,CAAC;IACJ,CAAC;IAED,IAAI,WAAW,KAAK,QAAQ,CAAC,OAAO,EAAE,CAAC;QACrC,OAAO,mBAAmB,CAAC,MAAM,CAC/B,GAAG,WAAW,UAAU,gBAAgB,EAAE,CAC3C,CAAC;IACJ,CAAC;IAED,aAAa;IACb,IAAI,CAAC,iBAAiB,CAAC,gBAAgB,CAAC,EAAE,CAAC;QACzC,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,aAAa;IACb,MAAM,kBAAkB,GAAG,oBAAoB,CAAC,gBAAgB,CAAC,CAAC;IAClE,OAAO,mBAAmB,CAAC,MAAM,CAC/B,GAAG,WAAW,UAAU,kBAAkB,EAAE,CAC7C,CAAC;AACJ,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/explicit-function-return-type */\nimport { getAddress } from '@ethersproject/address';\nimport { AddressZero } from '@ethersproject/constants';\nimport {\n convertHexToDecimal,\n toChecksumHexAddress,\n} from '@metamask/controller-utils';\nimport { BtcScope, SolScope, TrxScope } from '@metamask/keyring-api';\nimport { toEvmCaipChainId } from '@metamask/multichain-network-controller';\nimport {\n isCaipChainId,\n isStrictHexString,\n parseCaipChainId,\n isCaipReference,\n isCaipAssetType,\n CaipAssetTypeStruct,\n numberToHex,\n} from '@metamask/utils';\nimport type { CaipAssetType, CaipChainId, Hex } from '@metamask/utils';\n\nimport type { GenericQuoteRequest } from '../types';\nimport { ChainId } from '../types';\nimport {\n getNativeAssetForChainId,\n isBitcoinChainId,\n isNativeAddress,\n isSolanaChainId,\n isTronChainId,\n} from './bridge';\n\n/**\n * Converts a chainId to a CaipChainId\n *\n * @param chainId - The chainId to convert\n * @returns The CaipChainId\n */\nexport const formatChainIdToCaip = (\n chainId: Hex | number | CaipChainId | string,\n): CaipChainId => {\n if (isCaipChainId(chainId)) {\n return chainId;\n }\n if (isStrictHexString(chainId)) {\n return toEvmCaipChainId(chainId);\n }\n if (isSolanaChainId(chainId)) {\n return SolScope.Mainnet;\n }\n if (isBitcoinChainId(chainId)) {\n return BtcScope.Mainnet;\n }\n if (isTronChainId(chainId)) {\n return TrxScope.Mainnet;\n }\n return toEvmCaipChainId(numberToHex(Number(chainId)));\n};\n\n/**\n * Converts a chainId to a decimal number that can be used for bridge-api requests\n *\n * @param chainId - The chainId to convert\n * @returns The decimal number\n */\nexport const formatChainIdToDec = (\n chainId: number | Hex | CaipChainId | string,\n) => {\n if (isStrictHexString(chainId)) {\n return convertHexToDecimal(chainId);\n }\n if (chainId === SolScope.Mainnet) {\n return ChainId.SOLANA;\n }\n if (chainId === BtcScope.Mainnet) {\n return ChainId.BTC;\n }\n if (chainId === TrxScope.Mainnet) {\n return ChainId.TRON;\n }\n if (isCaipChainId(chainId)) {\n return Number(chainId.split(':').at(-1));\n }\n if (typeof chainId === 'string') {\n return parseInt(chainId, 10);\n }\n return chainId;\n};\n\n/**\n * Converts a chainId to a hex string used to read controller data within the app\n * Hex chainIds are also used for fetching exchange rates\n *\n * @param chainId - The chainId to convert\n * @returns The hex string\n */\nexport const formatChainIdToHex = (\n chainId: Hex | CaipChainId | string | number,\n): Hex => {\n if (isStrictHexString(chainId)) {\n return chainId;\n }\n if (typeof chainId === 'number' || parseInt(chainId, 10)) {\n return numberToHex(Number(chainId));\n }\n if (isCaipChainId(chainId)) {\n const { reference } = parseCaipChainId(chainId);\n if (isCaipReference(reference) && !isNaN(Number(reference))) {\n return numberToHex(Number(reference));\n }\n }\n // Throw an error if a non-evm chainId is passed to this function\n // This should never happen, but it's a sanity check\n throw new Error(`Invalid cross-chain swaps chainId: ${chainId}`);\n};\n\n/**\n * Converts an asset or account address to a string that can be used for bridge-api requests\n *\n * @param address - The address to convert\n * @returns The converted address\n */\nexport const formatAddressToCaipReference = (address: string) => {\n if (isStrictHexString(address)) {\n return getAddress(address);\n }\n // If the address looks like a native token, return the zero address because it's\n // what bridge-api uses to represent a native asset\n if (isNativeAddress(address)) {\n return AddressZero;\n }\n const addressWithoutPrefix = address.split(':').at(-1);\n // If the address is not a valid hex string or CAIP address, throw an error\n // This should never happen, but it's a sanity check\n if (!addressWithoutPrefix) {\n throw new Error('Invalid address');\n }\n return addressWithoutPrefix;\n};\n\n/**\n * Converts an address or assetId to a checksummed CaipAssetType\n *\n * @param addressOrAssetId - The address or assetId to convert\n * @param chainId - The chainId of the asset\n * @returns The CaipAssetType\n */\nexport const formatAddressToAssetId = (\n addressOrAssetId: Hex | CaipAssetType | string,\n chainId?: GenericQuoteRequest['srcChainId'],\n): CaipAssetType | undefined => {\n if (isCaipAssetType(addressOrAssetId)) {\n return addressOrAssetId;\n }\n if (!chainId) {\n return undefined;\n }\n\n const chainIdCaip = formatChainIdToCaip(chainId);\n if (isNativeAddress(addressOrAssetId)) {\n return getNativeAssetForChainId(chainIdCaip).assetId;\n }\n if (chainIdCaip === SolScope.Mainnet) {\n return CaipAssetTypeStruct.create(\n `${chainIdCaip}/token:${addressOrAssetId}`,\n );\n }\n\n if (chainIdCaip === TrxScope.Mainnet) {\n return CaipAssetTypeStruct.create(\n `${chainIdCaip}/trc20:${addressOrAssetId}`,\n );\n }\n\n // EVM assets\n if (!isStrictHexString(addressOrAssetId)) {\n return undefined;\n }\n\n // EVM assets\n const checksummedAddress = toChecksumHexAddress(addressOrAssetId);\n return CaipAssetTypeStruct.create(\n `${chainIdCaip}/erc20:${checksummedAddress}`,\n );\n};\n"]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.hasMinimumRequiredVersion = exports.getBridgeFeatureFlags = exports.processFeatureFlags = exports.formatFeatureFlags = void 0;
|
|
4
|
+
const bridge_1 = require("../constants/bridge.cjs");
|
|
4
5
|
const caip_formatters_1 = require("./caip-formatters.cjs");
|
|
5
6
|
const validators_1 = require("./validators.cjs");
|
|
6
|
-
const bridge_1 = require("../constants/bridge.cjs");
|
|
7
7
|
const formatFeatureFlags = (bridgeFeatureFlags) => {
|
|
8
8
|
const getChainsObj = (chains) => Object.entries(chains).reduce((acc, [chainId, value]) => ({
|
|
9
9
|
...acc,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"feature-flags.cjs","sourceRoot":"","sources":["../../src/utils/feature-flags.ts"],"names":[],"mappings":";;;AAEA,2DAAwD;AACxD,iDAA4D;
|
|
1
|
+
{"version":3,"file":"feature-flags.cjs","sourceRoot":"","sources":["../../src/utils/feature-flags.ts"],"names":[],"mappings":";;;AAEA,oDAG6B;AAE7B,2DAAwD;AACxD,iDAA4D;AAErD,MAAM,kBAAkB,GAAG,CAChC,kBAA8C,EAC9C,EAAE;IACF,MAAM,YAAY,GAAG,CAAC,MAA0C,EAAE,EAAE,CAClE,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,CAC3B,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;QAC1B,GAAG,GAAG;QACN,CAAC,IAAA,qCAAmB,EAAC,OAAO,CAAC,CAAC,EAAE,KAAK;KACtC,CAAC,EACF,EAAE,CACH,CAAC;IAEJ,OAAO;QAC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D,KAAK,CAAC,GAAG,CAAC;SACV,GAAG,CAAC,MAAM,CAAC,CAAC;IACf,MAAM,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,gBAAgB,CAAC,GAC1D,kBAAkB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAE5C,IAAI,WAAW,GAAG,gBAAgB,EAAE,CAAC;QACnC,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,WAAW,KAAK,gBAAgB,IAAI,WAAW,GAAG,gBAAgB,EAAE,CAAC;QACvE,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,CACL,WAAW,KAAK,gBAAgB;QAChC,WAAW,KAAK,gBAAgB;QAChC,WAAW,IAAI,gBAAgB,CAChC,CAAC;AACJ,CAAC,CAAC;AArBW,QAAA,yBAAyB,6BAqBpC","sourcesContent":["import type { RemoteFeatureFlagControllerState } from '@metamask/remote-feature-flag-controller';\n\nimport {\n DEFAULT_CHAIN_RANKING,\n DEFAULT_FEATURE_FLAG_CONFIG,\n} from '../constants/bridge';\nimport type { FeatureFlagsPlatformConfig, ChainConfiguration } from '../types';\nimport { formatChainIdToCaip } from './caip-formatters';\nimport { validateFeatureFlagsResponse } from './validators';\n\nexport const formatFeatureFlags = (\n bridgeFeatureFlags: FeatureFlagsPlatformConfig,\n) => {\n const getChainsObj = (chains: Record<string, ChainConfiguration>) =>\n Object.entries(chains).reduce(\n (acc, [chainId, value]) => ({\n ...acc,\n [formatChainIdToCaip(chainId)]: value,\n }),\n {},\n );\n\n return {\n ...bridgeFeatureFlags,\n chains: getChainsObj(bridgeFeatureFlags.chains),\n };\n};\n\nexport const processFeatureFlags = (\n bridgeFeatureFlags: unknown,\n): FeatureFlagsPlatformConfig => {\n if (validateFeatureFlagsResponse(bridgeFeatureFlags)) {\n const formattedFlags = formatFeatureFlags(bridgeFeatureFlags);\n // If chainRanking is undefined or empty, use the default chainRanking\n if (\n !formattedFlags.chainRanking ||\n formattedFlags.chainRanking.length === 0\n ) {\n return {\n ...formattedFlags,\n chainRanking: [...DEFAULT_CHAIN_RANKING],\n };\n }\n return formattedFlags;\n }\n return DEFAULT_FEATURE_FLAG_CONFIG;\n};\n\n/**\n * Gets the bridge feature flags from the remote feature flag controller\n *\n * @param messenger - Any messenger with access to RemoteFeatureFlagController:getState\n * @returns The bridge feature flags\n */\nexport function getBridgeFeatureFlags<\n T extends {\n call(\n action: 'RemoteFeatureFlagController:getState',\n ): RemoteFeatureFlagControllerState;\n },\n>(messenger: T): FeatureFlagsPlatformConfig {\n // This will return the bridgeConfig for the current platform even without specifying the platform\n const remoteFeatureFlagControllerState = messenger.call(\n 'RemoteFeatureFlagController:getState',\n );\n\n // bridgeConfigV2 is the feature flag for the mobile app\n // bridgeConfig for Mobile has been deprecated since release of bridge and Solana in 7.46.0 was pushed back\n // and there's no way to turn on bridgeConfig for 7.47.0 without affecting 7.46.0 as well.\n // You will still get bridgeConfig returned from remoteFeatureFlagControllerState but you should use bridgeConfigV2 instead\n // Mobile's bridgeConfig will be permanently serving the disabled variation, so falling back to it in Mobile will be ok\n const rawMobileFlags =\n remoteFeatureFlagControllerState?.remoteFeatureFlags?.bridgeConfigV2;\n\n // Extension LaunchDarkly will not have the bridgeConfigV2 field, so we'll continue to use bridgeConfig\n const rawBridgeConfig =\n remoteFeatureFlagControllerState?.remoteFeatureFlags?.bridgeConfig;\n\n return processFeatureFlags(rawMobileFlags || rawBridgeConfig);\n}\n\n/**\n * Checks if the client version is greater than or equal to the minimum required version\n *\n * @param clientVersion - The client version\n * @param minRequiredVersion - The minimum required version\n * @returns True if the client version is greater than or equal to the minimum required version, false otherwise\n */\nexport const hasMinimumRequiredVersion = (\n clientVersion: string,\n minRequiredVersion: string,\n) => {\n const [clientMajor, clientMinor, clientPatch] = clientVersion\n .split('.')\n .map(Number);\n const [minRequiredMajor, minRequiredMinor, minRequiredPatch] =\n minRequiredVersion.split('.').map(Number);\n\n if (clientMajor > minRequiredMajor) {\n return true;\n }\n if (clientMajor === minRequiredMajor && clientMinor > minRequiredMinor) {\n return true;\n }\n return (\n clientMajor === minRequiredMajor &&\n clientMinor === minRequiredMinor &&\n clientPatch >= minRequiredPatch\n );\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"feature-flags.d.cts","sourceRoot":"","sources":["../../src/utils/feature-flags.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gCAAgC,EAAE,iDAAiD;
|
|
1
|
+
{"version":3,"file":"feature-flags.d.cts","sourceRoot":"","sources":["../../src/utils/feature-flags.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gCAAgC,EAAE,iDAAiD;AAMjG,OAAO,KAAK,EAAE,0BAA0B,EAAsB,qBAAiB;AAI/E,eAAO,MAAM,kBAAkB,uBACT,0BAA0B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAe/C,CAAC;AAEF,eAAO,MAAM,mBAAmB,uBACV,OAAO,KAC1B,0BAgBF,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,CAAC,SAAS;IACR,IAAI,CACF,MAAM,EAAE,sCAAsC,GAC7C,gCAAgC,CAAC;CACrC,EACD,SAAS,EAAE,CAAC,GAAG,0BAA0B,CAmB1C;AAED;;;;;;GAMG;AACH,eAAO,MAAM,yBAAyB,kBACrB,MAAM,sBACD,MAAM,YAmB3B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"feature-flags.d.mts","sourceRoot":"","sources":["../../src/utils/feature-flags.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gCAAgC,EAAE,iDAAiD;
|
|
1
|
+
{"version":3,"file":"feature-flags.d.mts","sourceRoot":"","sources":["../../src/utils/feature-flags.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gCAAgC,EAAE,iDAAiD;AAMjG,OAAO,KAAK,EAAE,0BAA0B,EAAsB,qBAAiB;AAI/E,eAAO,MAAM,kBAAkB,uBACT,0BAA0B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAe/C,CAAC;AAEF,eAAO,MAAM,mBAAmB,uBACV,OAAO,KAC1B,0BAgBF,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,CAAC,SAAS;IACR,IAAI,CACF,MAAM,EAAE,sCAAsC,GAC7C,gCAAgC,CAAC;CACrC,EACD,SAAS,EAAE,CAAC,GAAG,0BAA0B,CAmB1C;AAED;;;;;;GAMG;AACH,eAAO,MAAM,yBAAyB,kBACrB,MAAM,sBACD,MAAM,YAmB3B,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { DEFAULT_CHAIN_RANKING, DEFAULT_FEATURE_FLAG_CONFIG } from "../constants/bridge.mjs";
|
|
1
2
|
import { formatChainIdToCaip } from "./caip-formatters.mjs";
|
|
2
3
|
import { validateFeatureFlagsResponse } from "./validators.mjs";
|
|
3
|
-
import { DEFAULT_CHAIN_RANKING, DEFAULT_FEATURE_FLAG_CONFIG } from "../constants/bridge.mjs";
|
|
4
4
|
export const formatFeatureFlags = (bridgeFeatureFlags) => {
|
|
5
5
|
const getChainsObj = (chains) => Object.entries(chains).reduce((acc, [chainId, value]) => ({
|
|
6
6
|
...acc,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"feature-flags.mjs","sourceRoot":"","sources":["../../src/utils/feature-flags.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,8BAA0B;AACxD,OAAO,EAAE,4BAA4B,EAAE,yBAAqB;
|
|
1
|
+
{"version":3,"file":"feature-flags.mjs","sourceRoot":"","sources":["../../src/utils/feature-flags.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,qBAAqB,EACrB,2BAA2B,EAC5B,gCAA4B;AAE7B,OAAO,EAAE,mBAAmB,EAAE,8BAA0B;AACxD,OAAO,EAAE,4BAA4B,EAAE,yBAAqB;AAE5D,MAAM,CAAC,MAA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e,GACnB,gCAAgC,EAAE,kBAAkB,EAAE,YAAY,CAAC;IAErE,OAAO,mBAAmB,CAAC,cAAc,IAAI,eAAe,CAAC,CAAC;AAChE,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CACvC,aAAqB,EACrB,kBAA0B,EAC1B,EAAE;IACF,MAAM,CAAC,WAAW,EAAE,WAAW,EAAE,WAAW,CAAC,GAAG,aAAa;SAC1D,KAAK,CAAC,GAAG,CAAC;SACV,GAAG,CAAC,MAAM,CAAC,CAAC;IACf,MAAM,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,gBAAgB,CAAC,GAC1D,kBAAkB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAE5C,IAAI,WAAW,GAAG,gBAAgB,EAAE,CAAC;QACnC,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,WAAW,KAAK,gBAAgB,IAAI,WAAW,GAAG,gBAAgB,EAAE,CAAC;QACvE,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,CACL,WAAW,KAAK,gBAAgB;QAChC,WAAW,KAAK,gBAAgB;QAChC,WAAW,IAAI,gBAAgB,CAChC,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import type { RemoteFeatureFlagControllerState } from '@metamask/remote-feature-flag-controller';\n\nimport {\n DEFAULT_CHAIN_RANKING,\n DEFAULT_FEATURE_FLAG_CONFIG,\n} from '../constants/bridge';\nimport type { FeatureFlagsPlatformConfig, ChainConfiguration } from '../types';\nimport { formatChainIdToCaip } from './caip-formatters';\nimport { validateFeatureFlagsResponse } from './validators';\n\nexport const formatFeatureFlags = (\n bridgeFeatureFlags: FeatureFlagsPlatformConfig,\n) => {\n const getChainsObj = (chains: Record<string, ChainConfiguration>) =>\n Object.entries(chains).reduce(\n (acc, [chainId, value]) => ({\n ...acc,\n [formatChainIdToCaip(chainId)]: value,\n }),\n {},\n );\n\n return {\n ...bridgeFeatureFlags,\n chains: getChainsObj(bridgeFeatureFlags.chains),\n };\n};\n\nexport const processFeatureFlags = (\n bridgeFeatureFlags: unknown,\n): FeatureFlagsPlatformConfig => {\n if (validateFeatureFlagsResponse(bridgeFeatureFlags)) {\n const formattedFlags = formatFeatureFlags(bridgeFeatureFlags);\n // If chainRanking is undefined or empty, use the default chainRanking\n if (\n !formattedFlags.chainRanking ||\n formattedFlags.chainRanking.length === 0\n ) {\n return {\n ...formattedFlags,\n chainRanking: [...DEFAULT_CHAIN_RANKING],\n };\n }\n return formattedFlags;\n }\n return DEFAULT_FEATURE_FLAG_CONFIG;\n};\n\n/**\n * Gets the bridge feature flags from the remote feature flag controller\n *\n * @param messenger - Any messenger with access to RemoteFeatureFlagController:getState\n * @returns The bridge feature flags\n */\nexport function getBridgeFeatureFlags<\n T extends {\n call(\n action: 'RemoteFeatureFlagController:getState',\n ): RemoteFeatureFlagControllerState;\n },\n>(messenger: T): FeatureFlagsPlatformConfig {\n // This will return the bridgeConfig for the current platform even without specifying the platform\n const remoteFeatureFlagControllerState = messenger.call(\n 'RemoteFeatureFlagController:getState',\n );\n\n // bridgeConfigV2 is the feature flag for the mobile app\n // bridgeConfig for Mobile has been deprecated since release of bridge and Solana in 7.46.0 was pushed back\n // and there's no way to turn on bridgeConfig for 7.47.0 without affecting 7.46.0 as well.\n // You will still get bridgeConfig returned from remoteFeatureFlagControllerState but you should use bridgeConfigV2 instead\n // Mobile's bridgeConfig will be permanently serving the disabled variation, so falling back to it in Mobile will be ok\n const rawMobileFlags =\n remoteFeatureFlagControllerState?.remoteFeatureFlags?.bridgeConfigV2;\n\n // Extension LaunchDarkly will not have the bridgeConfigV2 field, so we'll continue to use bridgeConfig\n const rawBridgeConfig =\n remoteFeatureFlagControllerState?.remoteFeatureFlags?.bridgeConfig;\n\n return processFeatureFlags(rawMobileFlags || rawBridgeConfig);\n}\n\n/**\n * Checks if the client version is greater than or equal to the minimum required version\n *\n * @param clientVersion - The client version\n * @param minRequiredVersion - The minimum required version\n * @returns True if the client version is greater than or equal to the minimum required version, false otherwise\n */\nexport const hasMinimumRequiredVersion = (\n clientVersion: string,\n minRequiredVersion: string,\n) => {\n const [clientMajor, clientMinor, clientPatch] = clientVersion\n .split('.')\n .map(Number);\n const [minRequiredMajor, minRequiredMinor, minRequiredPatch] =\n minRequiredVersion.split('.').map(Number);\n\n if (clientMajor > minRequiredMajor) {\n return true;\n }\n if (clientMajor === minRequiredMajor && clientMinor > minRequiredMinor) {\n return true;\n }\n return (\n clientMajor === minRequiredMajor &&\n clientMinor === minRequiredMinor &&\n clientPatch >= minRequiredPatch\n );\n};\n"]}
|