@metamask/bridge-controller 55.0.0 → 56.0.1
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 +34 -1
- package/dist/bridge-controller.cjs +29 -29
- 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 +29 -29
- package/dist/bridge-controller.mjs.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/selectors.d.cts +3805 -3805
- package/dist/selectors.d.mts +3805 -3805
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +7 -4
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +7 -4
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/dist/utils/bridge.d.cts +3 -3
- package/dist/utils/bridge.d.mts +3 -3
- package/dist/utils/feature-flags.d.cts +3 -3
- package/dist/utils/feature-flags.d.mts +3 -3
- package/dist/utils/fetch-server-events.cjs +10 -1
- package/dist/utils/fetch-server-events.cjs.map +1 -1
- package/dist/utils/fetch-server-events.d.cts.map +1 -1
- package/dist/utils/fetch-server-events.d.mts.map +1 -1
- package/dist/utils/fetch-server-events.mjs +10 -1
- package/dist/utils/fetch-server-events.mjs.map +1 -1
- package/dist/utils/quote-fees.cjs +26 -6
- 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 +26 -6
- package/dist/utils/quote-fees.mjs.map +1 -1
- package/dist/utils/slippage.d.cts +1 -1
- package/dist/utils/slippage.d.mts +1 -1
- package/dist/utils/validators.d.cts +347 -347
- package/dist/utils/validators.d.mts +347 -347
- package/package.json +16 -15
package/dist/types.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAgDA;;GAEG;AACH,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,yBAAT,SAAS,QAYpB;AAiFD;;GAEG;AACH,IAAY,SAGX;AAHD,WAAY,SAAS;IACnB,wCAA2B,CAAA;IAC3B,wCAA2B,CAAA;AAC7B,CAAC,EAHW,SAAS,yBAAT,SAAS,QAGpB;AAsED,IAAY,WAKX;AALD,WAAY,WAAW;IACrB,kCAAmB,CAAA;IACnB,gCAAiB,CAAA;IACjB,kCAAmB,CAAA;IACnB,oCAAqB,CAAA;AACvB,CAAC,EALW,WAAW,2BAAX,WAAW,QAKtB;AAqCD,IAAY,OAYX;AAZD,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;AACtB,CAAC,EAZW,OAAO,uBAAP,OAAO,QAYlB;AAID,IAAY,aAIX;AAJD,WAAY,aAAa;IACvB,uDAAO,CAAA;IACP,uDAAO,CAAA;IACP,mDAAK,CAAA;AACP,CAAC,EAJW,aAAa,6BAAb,aAAa,QAIxB;AACD,IAAY,gBAGX;AAHD,WAAY,gBAAgB;IAC1B,6DAAyC,CAAA;IACzC,0EAAsD,CAAA;AACxD,CAAC,EAHW,gBAAgB,gCAAhB,gBAAgB,QAG3B;AACD,IAAY,sBAOX;AAPD,WAAY,sBAAsB;IAChC,8EAAoD,CAAA;IACpD,oDAA0B,CAAA;IAC1B,gFAAsD,CAAA;IACtD,iFAAuD,CAAA;IACvD,0EAAgD,CAAA;IAChD,sDAA4B,CAAA;AAC9B,CAAC,EAPW,sBAAsB,sCAAtB,sBAAsB,QAOjC","sourcesContent":["import type { AccountsControllerGetAccountByAddressAction } from '@metamask/accounts-controller';\nimport type {\n GetCurrencyRateState,\n MultichainAssetsRatesControllerGetStateAction,\n TokenRatesControllerGetStateAction,\n} from '@metamask/assets-controllers';\nimport type {\n ControllerStateChangeEvent,\n RestrictedMessenger,\n} from '@metamask/base-controller';\nimport type {\n NetworkControllerFindNetworkClientIdByChainIdAction,\n NetworkControllerGetStateAction,\n NetworkControllerGetNetworkClientByIdAction,\n} from '@metamask/network-controller';\nimport type { RemoteFeatureFlagControllerGetStateAction } from '@metamask/remote-feature-flag-controller';\nimport type { HandleSnapRequest } 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 FeatureId,\n FeeDataSchema,\n PlatformConfigSchema,\n ProtocolSchema,\n QuoteResponseSchema,\n QuoteSchema,\n StepSchema,\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 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 */\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 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: toTokenAmount\n * Otherwise: toTokenAmount - totalNetworkFee\n */\n adjustedReturn: Omit<TokenAmountValues, 'amount'>;\n /**\n * The amount that the user will send, including fees\n * srcTokenAmount + metabridgeFee + txFee\n */\n sentAmount: TokenAmountValues;\n swapRate: string; // destTokenAmount / sentAmount\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 noFee?: boolean;\n};\n\nexport enum StatusTypes {\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 // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-arguments\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 BitcoinTradeData = Infer<typeof BitcoinTradeDataSchema>;\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 */\nexport type QuoteResponse<TxDataType = TxData | string | BitcoinTradeData> =\n Infer<typeof QuoteResponseSchema> & {\n trade: TxDataType;\n approval?: TxData;\n featureId?: FeatureId;\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}\n\nexport type FeatureFlagsPlatformConfig = Infer<typeof PlatformConfigSchema>;\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 GET_BRIDGE_ERC20_ALLOWANCE = 'getBridgeERC20Allowance',\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\nexport type BridgeControllerAction<\n FunctionName extends keyof BridgeController,\n> = {\n type: `${typeof BRIDGE_CONTROLLER_NAME}:${FunctionName}`;\n handler: BridgeController[FunctionName];\n};\n\n// Maps to BridgeController function names\nexport type BridgeControllerActions =\n | BridgeControllerAction<BridgeBackgroundAction.SET_CHAIN_INTERVAL_LENGTH>\n | BridgeControllerAction<BridgeBackgroundAction.RESET_STATE>\n | BridgeControllerAction<BridgeBackgroundAction.GET_BRIDGE_ERC20_ALLOWANCE>\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 = ControllerStateChangeEvent<\n typeof BRIDGE_CONTROLLER_NAME,\n BridgeControllerState\n>;\n\nexport type AllowedActions =\n | AccountsControllerGetAccountByAddressAction\n | GetCurrencyRateState\n | TokenRatesControllerGetStateAction\n | MultichainAssetsRatesControllerGetStateAction\n | HandleSnapRequest\n | NetworkControllerFindNetworkClientIdByChainIdAction\n | NetworkControllerGetStateAction\n | NetworkControllerGetNetworkClientByIdAction\n | RemoteFeatureFlagControllerGetStateAction;\nexport type AllowedEvents = never;\n\n/**\n * The messenger for the BridgeController.\n */\nexport type BridgeControllerMessenger = RestrictedMessenger<\n typeof BRIDGE_CONTROLLER_NAME,\n BridgeControllerActions | AllowedActions,\n BridgeControllerEvents | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n"]}
|
|
1
|
+
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAiDA;;GAEG;AACH,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,yBAAT,SAAS,QAYpB;AAiFD;;GAEG;AACH,IAAY,SAGX;AAHD,WAAY,SAAS;IACnB,wCAA2B,CAAA;IAC3B,wCAA2B,CAAA;AAC7B,CAAC,EAHW,SAAS,yBAAT,SAAS,QAGpB;AAsED,IAAY,WAKX;AALD,WAAY,WAAW;IACrB,kCAAmB,CAAA;IACnB,gCAAiB,CAAA;IACjB,kCAAmB,CAAA;IACnB,oCAAqB,CAAA;AACvB,CAAC,EALW,WAAW,2BAAX,WAAW,QAKtB;AAqCD,IAAY,OAYX;AAZD,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;AACtB,CAAC,EAZW,OAAO,uBAAP,OAAO,QAYlB;AAID,IAAY,aAIX;AAJD,WAAY,aAAa;IACvB,uDAAO,CAAA;IACP,uDAAO,CAAA;IACP,mDAAK,CAAA;AACP,CAAC,EAJW,aAAa,6BAAb,aAAa,QAIxB;AACD,IAAY,gBAGX;AAHD,WAAY,gBAAgB;IAC1B,6DAAyC,CAAA;IACzC,0EAAsD,CAAA;AACxD,CAAC,EAHW,gBAAgB,gCAAhB,gBAAgB,QAG3B;AACD,IAAY,sBAOX;AAPD,WAAY,sBAAsB;IAChC,8EAAoD,CAAA;IACpD,oDAA0B,CAAA;IAC1B,gFAAsD,CAAA;IACtD,iFAAuD,CAAA;IACvD,0EAAgD,CAAA;IAChD,sDAA4B,CAAA;AAC9B,CAAC,EAPW,sBAAsB,sCAAtB,sBAAsB,QAOjC","sourcesContent":["import type { AccountsControllerGetAccountByAddressAction } from '@metamask/accounts-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 NetworkControllerGetStateAction,\n NetworkControllerGetNetworkClientByIdAction,\n} from '@metamask/network-controller';\nimport type { RemoteFeatureFlagControllerGetStateAction } from '@metamask/remote-feature-flag-controller';\nimport type { HandleSnapRequest } 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 FeatureId,\n FeeDataSchema,\n PlatformConfigSchema,\n ProtocolSchema,\n QuoteResponseSchema,\n QuoteSchema,\n StepSchema,\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 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 */\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 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: toTokenAmount\n * Otherwise: toTokenAmount - totalNetworkFee\n */\n adjustedReturn: Omit<TokenAmountValues, 'amount'>;\n /**\n * The amount that the user will send, including fees\n * srcTokenAmount + metabridgeFee + txFee\n */\n sentAmount: TokenAmountValues;\n swapRate: string; // destTokenAmount / sentAmount\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 noFee?: boolean;\n};\n\nexport enum StatusTypes {\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 // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-arguments\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 BitcoinTradeData = Infer<typeof BitcoinTradeDataSchema>;\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 */\nexport type QuoteResponse<TxDataType = TxData | string | BitcoinTradeData> =\n Infer<typeof QuoteResponseSchema> & {\n trade: TxDataType;\n approval?: TxData;\n featureId?: FeatureId;\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}\n\nexport type FeatureFlagsPlatformConfig = Infer<typeof PlatformConfigSchema>;\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 GET_BRIDGE_ERC20_ALLOWANCE = 'getBridgeERC20Allowance',\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\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.GET_BRIDGE_ERC20_ALLOWANCE>\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 | GetCurrencyRateState\n | TokenRatesControllerGetStateAction\n | MultichainAssetsRatesControllerGetStateAction\n | HandleSnapRequest\n | NetworkControllerFindNetworkClientIdByChainIdAction\n | NetworkControllerGetStateAction\n | NetworkControllerGetNetworkClientByIdAction\n | RemoteFeatureFlagControllerGetStateAction;\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"]}
|
package/dist/types.d.cts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { AccountsControllerGetAccountByAddressAction } from "@metamask/accounts-controller";
|
|
2
2
|
import type { GetCurrencyRateState, MultichainAssetsRatesControllerGetStateAction, TokenRatesControllerGetStateAction } from "@metamask/assets-controllers";
|
|
3
|
-
import type {
|
|
3
|
+
import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
|
|
4
|
+
import type { Messenger } from "@metamask/messenger";
|
|
4
5
|
import type { NetworkControllerFindNetworkClientIdByChainIdAction, NetworkControllerGetStateAction, NetworkControllerGetNetworkClientByIdAction } from "@metamask/network-controller";
|
|
5
6
|
import type { RemoteFeatureFlagControllerGetStateAction } from "@metamask/remote-feature-flag-controller";
|
|
6
7
|
import type { HandleSnapRequest } from "@metamask/snaps-controllers";
|
|
@@ -270,13 +271,15 @@ export type BridgeControllerAction<FunctionName extends keyof BridgeController>
|
|
|
270
271
|
type: `${typeof BRIDGE_CONTROLLER_NAME}:${FunctionName}`;
|
|
271
272
|
handler: BridgeController[FunctionName];
|
|
272
273
|
};
|
|
273
|
-
export type
|
|
274
|
-
export type
|
|
274
|
+
export type BridgeControllerGetStateAction = ControllerGetStateAction<typeof BRIDGE_CONTROLLER_NAME, BridgeControllerState>;
|
|
275
|
+
export type BridgeControllerStateChangeEvent = ControllerStateChangeEvent<typeof BRIDGE_CONTROLLER_NAME, BridgeControllerState>;
|
|
276
|
+
export type BridgeControllerActions = BridgeControllerGetStateAction | BridgeControllerAction<BridgeBackgroundAction.SET_CHAIN_INTERVAL_LENGTH> | BridgeControllerAction<BridgeBackgroundAction.RESET_STATE> | BridgeControllerAction<BridgeBackgroundAction.GET_BRIDGE_ERC20_ALLOWANCE> | BridgeControllerAction<BridgeBackgroundAction.TRACK_METAMETRICS_EVENT> | BridgeControllerAction<BridgeBackgroundAction.STOP_POLLING_FOR_QUOTES> | BridgeControllerAction<BridgeBackgroundAction.FETCH_QUOTES> | BridgeControllerAction<BridgeUserAction.UPDATE_QUOTE_PARAMS>;
|
|
277
|
+
export type BridgeControllerEvents = BridgeControllerStateChangeEvent;
|
|
275
278
|
export type AllowedActions = AccountsControllerGetAccountByAddressAction | GetCurrencyRateState | TokenRatesControllerGetStateAction | MultichainAssetsRatesControllerGetStateAction | HandleSnapRequest | NetworkControllerFindNetworkClientIdByChainIdAction | NetworkControllerGetStateAction | NetworkControllerGetNetworkClientByIdAction | RemoteFeatureFlagControllerGetStateAction;
|
|
276
279
|
export type AllowedEvents = never;
|
|
277
280
|
/**
|
|
278
281
|
* The messenger for the BridgeController.
|
|
279
282
|
*/
|
|
280
|
-
export type BridgeControllerMessenger =
|
|
283
|
+
export type BridgeControllerMessenger = Messenger<typeof BRIDGE_CONTROLLER_NAME, BridgeControllerActions | AllowedActions, BridgeControllerEvents | AllowedEvents>;
|
|
281
284
|
export {};
|
|
282
285
|
//# sourceMappingURL=types.d.cts.map
|
package/dist/types.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2CAA2C,EAAE,sCAAsC;AACjG,OAAO,KAAK,EACV,oBAAoB,EACpB,6CAA6C,EAC7C,kCAAkC,EACnC,qCAAqC;AACtC,OAAO,KAAK,EACV,
|
|
1
|
+
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2CAA2C,EAAE,sCAAsC;AACjG,OAAO,KAAK,EACV,oBAAoB,EACpB,6CAA6C,EAC7C,kCAAkC,EACnC,qCAAqC;AACtC,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC3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O,sBAAsB,EAC7B,qBAAqB,CACtB,CAAC;AAGF,MAAM,MAAM,uBAAuB,GAC/B,8BAA8B,GAC9B,sBAAsB,CAAC,sBAAsB,CAAC,yBAAyB,CAAC,GACxE,sBAAsB,CAAC,sBAAsB,CAAC,WAAW,CAAC,GAC1D,sBAAsB,CAAC,sBAAsB,CAAC,0BAA0B,CAAC,GACzE,sBAAsB,CAAC,sBAAsB,CAAC,uBAAuB,CAAC,GACtE,sBAAsB,CAAC,sBAAsB,CAAC,uBAAuB,CAAC,GACtE,sBAAsB,CAAC,sBAAsB,CAAC,YAAY,CAAC,GAC3D,sBAAsB,CAAC,gBAAgB,CAAC,mBAAmB,CAAC,CAAC;AAEjE,MAAM,MAAM,sBAAsB,GAAG,gCAAgC,CAAC;AAEtE,MAAM,MAAM,cAAc,GACtB,2CAA2C,GAC3C,oBAAoB,GACpB,kCAAkC,GAClC,6CAA6C,GAC7C,iBAAiB,GACjB,mDAAmD,GACnD,+BAA+B,GAC/B,2CAA2C,GAC3C,yCAAyC,CAAC;AAC9C,MAAM,MAAM,aAAa,GAAG,KAAK,CAAC;AAElC;;GAEG;AACH,MAAM,MAAM,yBAAyB,GAAG,SAAS,CAC/C,OAAO,sBAAsB,EAC7B,uBAAuB,GAAG,cAAc,EACxC,sBAAsB,GAAG,aAAa,CACvC,CAAC"}
|
package/dist/types.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { AccountsControllerGetAccountByAddressAction } from "@metamask/accounts-controller";
|
|
2
2
|
import type { GetCurrencyRateState, MultichainAssetsRatesControllerGetStateAction, TokenRatesControllerGetStateAction } from "@metamask/assets-controllers";
|
|
3
|
-
import type {
|
|
3
|
+
import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
|
|
4
|
+
import type { Messenger } from "@metamask/messenger";
|
|
4
5
|
import type { NetworkControllerFindNetworkClientIdByChainIdAction, NetworkControllerGetStateAction, NetworkControllerGetNetworkClientByIdAction } from "@metamask/network-controller";
|
|
5
6
|
import type { RemoteFeatureFlagControllerGetStateAction } from "@metamask/remote-feature-flag-controller";
|
|
6
7
|
import type { HandleSnapRequest } from "@metamask/snaps-controllers";
|
|
@@ -270,13 +271,15 @@ export type BridgeControllerAction<FunctionName extends keyof BridgeController>
|
|
|
270
271
|
type: `${typeof BRIDGE_CONTROLLER_NAME}:${FunctionName}`;
|
|
271
272
|
handler: BridgeController[FunctionName];
|
|
272
273
|
};
|
|
273
|
-
export type
|
|
274
|
-
export type
|
|
274
|
+
export type BridgeControllerGetStateAction = ControllerGetStateAction<typeof BRIDGE_CONTROLLER_NAME, BridgeControllerState>;
|
|
275
|
+
export type BridgeControllerStateChangeEvent = ControllerStateChangeEvent<typeof BRIDGE_CONTROLLER_NAME, BridgeControllerState>;
|
|
276
|
+
export type BridgeControllerActions = BridgeControllerGetStateAction | BridgeControllerAction<BridgeBackgroundAction.SET_CHAIN_INTERVAL_LENGTH> | BridgeControllerAction<BridgeBackgroundAction.RESET_STATE> | BridgeControllerAction<BridgeBackgroundAction.GET_BRIDGE_ERC20_ALLOWANCE> | BridgeControllerAction<BridgeBackgroundAction.TRACK_METAMETRICS_EVENT> | BridgeControllerAction<BridgeBackgroundAction.STOP_POLLING_FOR_QUOTES> | BridgeControllerAction<BridgeBackgroundAction.FETCH_QUOTES> | BridgeControllerAction<BridgeUserAction.UPDATE_QUOTE_PARAMS>;
|
|
277
|
+
export type BridgeControllerEvents = BridgeControllerStateChangeEvent;
|
|
275
278
|
export type AllowedActions = AccountsControllerGetAccountByAddressAction | GetCurrencyRateState | TokenRatesControllerGetStateAction | MultichainAssetsRatesControllerGetStateAction | HandleSnapRequest | NetworkControllerFindNetworkClientIdByChainIdAction | NetworkControllerGetStateAction | NetworkControllerGetNetworkClientByIdAction | RemoteFeatureFlagControllerGetStateAction;
|
|
276
279
|
export type AllowedEvents = never;
|
|
277
280
|
/**
|
|
278
281
|
* The messenger for the BridgeController.
|
|
279
282
|
*/
|
|
280
|
-
export type BridgeControllerMessenger =
|
|
283
|
+
export type BridgeControllerMessenger = Messenger<typeof BRIDGE_CONTROLLER_NAME, BridgeControllerActions | AllowedActions, BridgeControllerEvents | AllowedEvents>;
|
|
281
284
|
export {};
|
|
282
285
|
//# sourceMappingURL=types.d.mts.map
|
package/dist/types.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2CAA2C,EAAE,sCAAsC;AACjG,OAAO,KAAK,EACV,oBAAoB,EACpB,6CAA6C,EAC7C,kCAAkC,EACnC,qCAAqC;AACtC,OAAO,KAAK,EACV,
|
|
1
|
+
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2CAA2C,EAAE,sCAAsC;AACjG,OAAO,KAAK,EACV,oBAAoB,EACpB,6CAA6C,EAC7C,kCAAkC,EACnC,qCAAqC;AACtC,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC3B,kCAAkC;AACnC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EACV,mDAAmD,EACnD,+BAA+B,EAC/B,2CAA2C,EAC5C,qCAAqC;AACtC,OAAO,KAAK,EAAE,yCAAyC,EAAE,iDAAiD;AAC1G,OAAO,KAAK,EAAE,iBAAiB,EAAE,oCAAoC;AACrE,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AACnD,OAAO,KAAK,EACV,aAAa,EACb,WAAW,EACX,aAAa,EACb,WAAW,EACX,GAAG,EACJ,wBAAwB;AAEzB,OAAO,KAAK,EAAE,gBAAgB,EAAE,gCAA4B;AAC5D,OAAO,KAAK,EAAE,sBAAsB,EAAE,+BAA2B;AACjE,OAAO,KAAK,EACV,sBAAsB,EACtB,iBAAiB,EACjB,wBAAwB,EACxB,SAAS,EACT,aAAa,EACb,oB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kC,GAClC,6CAA6C,GAC7C,iBAAiB,GACjB,mDAAmD,GACnD,+BAA+B,GAC/B,2CAA2C,GAC3C,yCAAyC,CAAC;AAC9C,MAAM,MAAM,aAAa,GAAG,KAAK,CAAC;AAElC;;GAEG;AACH,MAAM,MAAM,yBAAyB,GAAG,SAAS,CAC/C,OAAO,sBAAsB,EAC7B,uBAAuB,GAAG,cAAc,EACxC,sBAAsB,GAAG,aAAa,CACvC,CAAC"}
|
package/dist/types.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAgDA;;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;AAiFD;;GAEG;AACH,MAAM,CAAN,IAAY,SAGX;AAHD,WAAY,SAAS;IACnB,wCAA2B,CAAA;IAC3B,wCAA2B,CAAA;AAC7B,CAAC,EAHW,SAAS,KAAT,SAAS,QAGpB;AAsED,MAAM,CAAN,IAAY,WAKX;AALD,WAAY,WAAW;IACrB,kCAAmB,CAAA;IACnB,gCAAiB,CAAA;IACjB,kCAAmB,CAAA;IACnB,oCAAqB,CAAA;AACvB,CAAC,EALW,WAAW,KAAX,WAAW,QAKtB;AAqCD,MAAM,CAAN,IAAY,OAYX;AAZD,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;AACtB,CAAC,EAZW,OAAO,KAAP,OAAO,QAYlB;AAID,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,sBAOX;AAPD,WAAY,sBAAsB;IAChC,8EAAoD,CAAA;IACpD,oDAA0B,CAAA;IAC1B,gFAAsD,CAAA;IACtD,iFAAuD,CAAA;IACvD,0EAAgD,CAAA;IAChD,sDAA4B,CAAA;AAC9B,CAAC,EAPW,sBAAsB,KAAtB,sBAAsB,QAOjC","sourcesContent":["import type { AccountsControllerGetAccountByAddressAction } from '@metamask/accounts-controller';\nimport type {\n GetCurrencyRateState,\n MultichainAssetsRatesControllerGetStateAction,\n TokenRatesControllerGetStateAction,\n} from '@metamask/assets-controllers';\nimport type {\n ControllerStateChangeEvent,\n RestrictedMessenger,\n} from '@metamask/base-controller';\nimport type {\n NetworkControllerFindNetworkClientIdByChainIdAction,\n NetworkControllerGetStateAction,\n NetworkControllerGetNetworkClientByIdAction,\n} from '@metamask/network-controller';\nimport type { RemoteFeatureFlagControllerGetStateAction } from '@metamask/remote-feature-flag-controller';\nimport type { HandleSnapRequest } 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 FeatureId,\n FeeDataSchema,\n PlatformConfigSchema,\n ProtocolSchema,\n QuoteResponseSchema,\n QuoteSchema,\n StepSchema,\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 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 */\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 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: toTokenAmount\n * Otherwise: toTokenAmount - totalNetworkFee\n */\n adjustedReturn: Omit<TokenAmountValues, 'amount'>;\n /**\n * The amount that the user will send, including fees\n * srcTokenAmount + metabridgeFee + txFee\n */\n sentAmount: TokenAmountValues;\n swapRate: string; // destTokenAmount / sentAmount\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 noFee?: boolean;\n};\n\nexport enum StatusTypes {\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 // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-arguments\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 BitcoinTradeData = Infer<typeof BitcoinTradeDataSchema>;\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 */\nexport type QuoteResponse<TxDataType = TxData | string | BitcoinTradeData> =\n Infer<typeof QuoteResponseSchema> & {\n trade: TxDataType;\n approval?: TxData;\n featureId?: FeatureId;\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}\n\nexport type FeatureFlagsPlatformConfig = Infer<typeof PlatformConfigSchema>;\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 GET_BRIDGE_ERC20_ALLOWANCE = 'getBridgeERC20Allowance',\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\nexport type BridgeControllerAction<\n FunctionName extends keyof BridgeController,\n> = {\n type: `${typeof BRIDGE_CONTROLLER_NAME}:${FunctionName}`;\n handler: BridgeController[FunctionName];\n};\n\n// Maps to BridgeController function names\nexport type BridgeControllerActions =\n | BridgeControllerAction<BridgeBackgroundAction.SET_CHAIN_INTERVAL_LENGTH>\n | BridgeControllerAction<BridgeBackgroundAction.RESET_STATE>\n | BridgeControllerAction<BridgeBackgroundAction.GET_BRIDGE_ERC20_ALLOWANCE>\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 = ControllerStateChangeEvent<\n typeof BRIDGE_CONTROLLER_NAME,\n BridgeControllerState\n>;\n\nexport type AllowedActions =\n | AccountsControllerGetAccountByAddressAction\n | GetCurrencyRateState\n | TokenRatesControllerGetStateAction\n | MultichainAssetsRatesControllerGetStateAction\n | HandleSnapRequest\n | NetworkControllerFindNetworkClientIdByChainIdAction\n | NetworkControllerGetStateAction\n | NetworkControllerGetNetworkClientByIdAction\n | RemoteFeatureFlagControllerGetStateAction;\nexport type AllowedEvents = never;\n\n/**\n * The messenger for the BridgeController.\n */\nexport type BridgeControllerMessenger = RestrictedMessenger<\n typeof BRIDGE_CONTROLLER_NAME,\n BridgeControllerActions | AllowedActions,\n BridgeControllerEvents | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n"]}
|
|
1
|
+
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAiDA;;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;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from '@metamask/accounts-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 NetworkControllerGetStateAction,\n NetworkControllerGetNetworkClientByIdAction,\n} from '@metamask/network-controller';\nimport type { RemoteFeatureFlagControllerGetStateAction } from '@metamask/remote-feature-flag-controller';\nimport type { HandleSnapRequest } 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 FeatureId,\n FeeDataSchema,\n PlatformConfigSchema,\n ProtocolSchema,\n QuoteResponseSchema,\n QuoteSchema,\n StepSchema,\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 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 */\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 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: toTokenAmount\n * Otherwise: toTokenAmount - totalNetworkFee\n */\n adjustedReturn: Omit<TokenAmountValues, 'amount'>;\n /**\n * The amount that the user will send, including fees\n * srcTokenAmount + metabridgeFee + txFee\n */\n sentAmount: TokenAmountValues;\n swapRate: string; // destTokenAmount / sentAmount\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 noFee?: boolean;\n};\n\nexport enum StatusTypes {\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 // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-arguments\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 BitcoinTradeData = Infer<typeof BitcoinTradeDataSchema>;\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 */\nexport type QuoteResponse<TxDataType = TxData | string | BitcoinTradeData> =\n Infer<typeof QuoteResponseSchema> & {\n trade: TxDataType;\n approval?: TxData;\n featureId?: FeatureId;\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}\n\nexport type FeatureFlagsPlatformConfig = Infer<typeof PlatformConfigSchema>;\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 GET_BRIDGE_ERC20_ALLOWANCE = 'getBridgeERC20Allowance',\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\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.GET_BRIDGE_ERC20_ALLOWANCE>\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 | GetCurrencyRateState\n | TokenRatesControllerGetStateAction\n | MultichainAssetsRatesControllerGetStateAction\n | HandleSnapRequest\n | NetworkControllerFindNetworkClientIdByChainIdAction\n | NetworkControllerGetStateAction\n | NetworkControllerGetNetworkClientByIdAction\n | RemoteFeatureFlagControllerGetStateAction;\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"]}
|
package/dist/utils/bridge.d.cts
CHANGED
|
@@ -60,12 +60,12 @@ export declare const isBitcoinChainId: (chainId: Hex | number | CaipChainId | st
|
|
|
60
60
|
*/
|
|
61
61
|
export declare const isNonEvmChainId: (chainId: GenericQuoteRequest['srcChainId']) => boolean;
|
|
62
62
|
export declare const isEvmQuoteResponse: (quoteResponse: QuoteResponse) => quoteResponse is QuoteResponse<{
|
|
63
|
-
|
|
64
|
-
value: string;
|
|
63
|
+
chainId: number;
|
|
65
64
|
to: string;
|
|
66
65
|
from: string;
|
|
66
|
+
value: string;
|
|
67
|
+
data: string;
|
|
67
68
|
gasLimit: number | null;
|
|
68
|
-
chainId: number;
|
|
69
69
|
effectiveGas?: number | undefined;
|
|
70
70
|
}>;
|
|
71
71
|
/**
|
package/dist/utils/bridge.d.mts
CHANGED
|
@@ -60,12 +60,12 @@ export declare const isBitcoinChainId: (chainId: Hex | number | CaipChainId | st
|
|
|
60
60
|
*/
|
|
61
61
|
export declare const isNonEvmChainId: (chainId: GenericQuoteRequest['srcChainId']) => boolean;
|
|
62
62
|
export declare const isEvmQuoteResponse: (quoteResponse: QuoteResponse) => quoteResponse is QuoteResponse<{
|
|
63
|
-
|
|
64
|
-
value: string;
|
|
63
|
+
chainId: number;
|
|
65
64
|
to: string;
|
|
66
65
|
from: string;
|
|
66
|
+
value: string;
|
|
67
|
+
data: string;
|
|
67
68
|
gasLimit: number | null;
|
|
68
|
-
chainId: number;
|
|
69
69
|
effectiveGas?: number | undefined;
|
|
70
70
|
}>;
|
|
71
71
|
/**
|
|
@@ -2,13 +2,13 @@ import type { RemoteFeatureFlagControllerState } from "@metamask/remote-feature-
|
|
|
2
2
|
import type { FeatureFlagsPlatformConfig } from "../types.cjs";
|
|
3
3
|
export declare const formatFeatureFlags: (bridgeFeatureFlags: FeatureFlagsPlatformConfig) => {
|
|
4
4
|
chains: {};
|
|
5
|
-
support: boolean;
|
|
6
5
|
refreshRate: number;
|
|
7
6
|
minimumVersion: string;
|
|
8
7
|
maxRefreshCount: number;
|
|
8
|
+
support: boolean;
|
|
9
9
|
priceImpactThreshold?: {
|
|
10
|
-
normal: number;
|
|
11
10
|
gasless: number;
|
|
11
|
+
normal: number;
|
|
12
12
|
} | undefined;
|
|
13
13
|
quoteRequestOverrides?: Record<import("./validators.cjs").FeatureId, {
|
|
14
14
|
aggIds?: string[] | undefined;
|
|
@@ -20,8 +20,8 @@ export declare const formatFeatureFlags: (bridgeFeatureFlags: FeatureFlagsPlatfo
|
|
|
20
20
|
other: Record<string, string>;
|
|
21
21
|
} | undefined> | undefined;
|
|
22
22
|
sse?: {
|
|
23
|
-
enabled: boolean;
|
|
24
23
|
minimumVersion: string;
|
|
24
|
+
enabled: boolean;
|
|
25
25
|
} | undefined;
|
|
26
26
|
};
|
|
27
27
|
export declare const processFeatureFlags: (bridgeFeatureFlags: unknown) => FeatureFlagsPlatformConfig;
|
|
@@ -2,13 +2,13 @@ import type { RemoteFeatureFlagControllerState } from "@metamask/remote-feature-
|
|
|
2
2
|
import type { FeatureFlagsPlatformConfig } from "../types.mjs";
|
|
3
3
|
export declare const formatFeatureFlags: (bridgeFeatureFlags: FeatureFlagsPlatformConfig) => {
|
|
4
4
|
chains: {};
|
|
5
|
-
support: boolean;
|
|
6
5
|
refreshRate: number;
|
|
7
6
|
minimumVersion: string;
|
|
8
7
|
maxRefreshCount: number;
|
|
8
|
+
support: boolean;
|
|
9
9
|
priceImpactThreshold?: {
|
|
10
|
-
normal: number;
|
|
11
10
|
gasless: number;
|
|
11
|
+
normal: number;
|
|
12
12
|
} | undefined;
|
|
13
13
|
quoteRequestOverrides?: Record<import("./validators.mjs").FeatureId, {
|
|
14
14
|
aggIds?: string[] | undefined;
|
|
@@ -20,8 +20,8 @@ export declare const formatFeatureFlags: (bridgeFeatureFlags: FeatureFlagsPlatfo
|
|
|
20
20
|
other: Record<string, string>;
|
|
21
21
|
} | undefined> | undefined;
|
|
22
22
|
sse?: {
|
|
23
|
-
enabled: boolean;
|
|
24
23
|
minimumVersion: string;
|
|
24
|
+
enabled: boolean;
|
|
25
25
|
} | undefined;
|
|
26
26
|
};
|
|
27
27
|
export declare const processFeatureFlags: (bridgeFeatureFlags: unknown) => FeatureFlagsPlatformConfig;
|
|
@@ -12,12 +12,13 @@ exports.fetchServerEvents = void 0;
|
|
|
12
12
|
* @param options.fetchFn - The function to use to fetch the events. Consumers need to provide a fetch function that supports server-sent events.
|
|
13
13
|
*/
|
|
14
14
|
const fetchServerEvents = async (url, { onMessage, onError, onClose, fetchFn, ...requestOptions }) => {
|
|
15
|
+
let reader;
|
|
15
16
|
try {
|
|
16
17
|
const response = await fetchFn(url, requestOptions);
|
|
17
18
|
if (!response.ok || !response.body) {
|
|
18
19
|
throw new Error(`${response.status}`);
|
|
19
20
|
}
|
|
20
|
-
|
|
21
|
+
reader = response.body.getReader();
|
|
21
22
|
const decoder = new TextDecoder('utf-8');
|
|
22
23
|
let buffer = '';
|
|
23
24
|
while (true) {
|
|
@@ -56,6 +57,14 @@ const fetchServerEvents = async (url, { onMessage, onError, onClose, fetchFn, ..
|
|
|
56
57
|
catch (error) {
|
|
57
58
|
onError?.(error);
|
|
58
59
|
}
|
|
60
|
+
finally {
|
|
61
|
+
try {
|
|
62
|
+
await reader?.cancel();
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
console.error('Error cleaning up stream reader', error);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
59
68
|
};
|
|
60
69
|
exports.fetchServerEvents = fetchServerEvents;
|
|
61
70
|
//# sourceMappingURL=fetch-server-events.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch-server-events.cjs","sourceRoot":"","sources":["../../src/utils/fetch-server-events.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;GASG;AACI,MAAM,iBAAiB,GAAG,KAAK,EACpC,GAAW,EACX,EACE,SAAS,EACT,OAAO,EACP,OAAO,EACP,OAAO,EACP,GAAG,cAAc,EAMlB,EACD,EAAE;IACF,IAAI;QACF,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;QACpD,IAAI,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE;YAClC,MAAM,IAAI,KAAK,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;SACvC;QAED,MAAM,
|
|
1
|
+
{"version":3,"file":"fetch-server-events.cjs","sourceRoot":"","sources":["../../src/utils/fetch-server-events.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;GASG;AACI,MAAM,iBAAiB,GAAG,KAAK,EACpC,GAAW,EACX,EACE,SAAS,EACT,OAAO,EACP,OAAO,EACP,OAAO,EACP,GAAG,cAAc,EAMlB,EACD,EAAE;IACF,IAAI,MAA2D,CAAC;IAChE,IAAI;QACF,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;QACpD,IAAI,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE;YAClC,MAAM,I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AS,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;iBAC9D;gBACD,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE;oBACxB,MAAM,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;oBACxD,SAAS,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC;iBACtC;aACF;SACF;QACD,OAAO,EAAE,EAAE,CAAC;KACb;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC;KAClB;YAAS;QACR,IAAI;YACF,MAAM,MAAM,EAAE,MAAM,EAAE,CAAC;SACxB;QAAC,OAAO,KAAK,EAAE;YACd,OAAO,CAAC,KAAK,CAAC,iCAAiC,EAAE,KAAK,CAAC,CAAC;SACzD;KACF;AACH,CAAC,CAAC;AAxEW,QAAA,iBAAiB,qBAwE5B","sourcesContent":["/**\n * Streams server-sent events from the given URL\n *\n * @param url - The URL to stream events from\n * @param options - The options for the SSE stream\n * @param options.onMessage - The function to call when a message is received\n * @param options.onError - The function to call when an error occurs\n * @param options.onClose - The function to call when the stream finishes successfully\n * @param options.fetchFn - The function to use to fetch the events. Consumers need to provide a fetch function that supports server-sent events.\n */\nexport const fetchServerEvents = async (\n url: string,\n {\n onMessage,\n onError,\n onClose,\n fetchFn,\n ...requestOptions\n }: RequestInit & {\n onMessage: (data: Record<string, unknown>, eventName?: string) => void;\n onError?: (err: unknown) => void;\n onClose?: () => void;\n fetchFn: typeof fetch;\n },\n) => {\n let reader: ReadableStreamDefaultReader<Uint8Array> | undefined;\n try {\n const response = await fetchFn(url, requestOptions);\n if (!response.ok || !response.body) {\n throw new Error(`${response.status}`);\n }\n\n reader = response.body.getReader();\n const decoder = new TextDecoder('utf-8');\n let buffer = '';\n\n while (true) {\n const { done, value } = await reader.read();\n\n if (done) {\n break;\n }\n\n buffer += decoder.decode(value, { stream: true });\n\n // Split SSE messages at double newlines\n const parts = buffer.split('\\n\\n');\n buffer = parts.pop() || '';\n\n // Split chunks into lines and parse the data\n for (const chunk of parts) {\n const lines = chunk.split('\\n');\n let eventName: string | undefined;\n const dataLines: string[] = [];\n\n for (const line of lines) {\n if (line.startsWith('event:')) {\n eventName = line.slice(6).trim();\n } else if (line.startsWith('data:')) {\n dataLines.push(line.slice(5).trim());\n }\n }\n\n if (eventName === 'error') {\n throw new Error(`Bridge-api error: ${dataLines.join('\\n')}`);\n }\n if (dataLines.length > 0) {\n const parsedJSONData = JSON.parse(dataLines.join('\\n'));\n onMessage(parsedJSONData, eventName);\n }\n }\n }\n onClose?.();\n } catch (error) {\n onError?.(error);\n } finally {\n try {\n await reader?.cancel();\n } catch (error) {\n console.error('Error cleaning up stream reader', error);\n }\n }\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch-server-events.d.cts","sourceRoot":"","sources":["../../src/utils/fetch-server-events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB,QACvB,MAAM;sBAQS,OAAO,MAAM,EAAE,OAAO,CAAC,cAAc,MAAM,KAAK,IAAI;qBACtD,OAAO,KAAK,IAAI;qBAChB,IAAI;aACX,YAAY;
|
|
1
|
+
{"version":3,"file":"fetch-server-events.d.cts","sourceRoot":"","sources":["../../src/utils/fetch-server-events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB,QACvB,MAAM;sBAQS,OAAO,MAAM,EAAE,OAAO,CAAC,cAAc,MAAM,KAAK,IAAI;qBACtD,OAAO,KAAK,IAAI;qBAChB,IAAI;aACX,YAAY;mBA4DxB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch-server-events.d.mts","sourceRoot":"","sources":["../../src/utils/fetch-server-events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB,QACvB,MAAM;sBAQS,OAAO,MAAM,EAAE,OAAO,CAAC,cAAc,MAAM,KAAK,IAAI;qBACtD,OAAO,KAAK,IAAI;qBAChB,IAAI;aACX,YAAY;
|
|
1
|
+
{"version":3,"file":"fetch-server-events.d.mts","sourceRoot":"","sources":["../../src/utils/fetch-server-events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB,QACvB,MAAM;sBAQS,OAAO,MAAM,EAAE,OAAO,CAAC,cAAc,MAAM,KAAK,IAAI;qBACtD,OAAO,KAAK,IAAI;qBAChB,IAAI;aACX,YAAY;mBA4DxB,CAAC"}
|
|
@@ -9,12 +9,13 @@
|
|
|
9
9
|
* @param options.fetchFn - The function to use to fetch the events. Consumers need to provide a fetch function that supports server-sent events.
|
|
10
10
|
*/
|
|
11
11
|
export const fetchServerEvents = async (url, { onMessage, onError, onClose, fetchFn, ...requestOptions }) => {
|
|
12
|
+
let reader;
|
|
12
13
|
try {
|
|
13
14
|
const response = await fetchFn(url, requestOptions);
|
|
14
15
|
if (!response.ok || !response.body) {
|
|
15
16
|
throw new Error(`${response.status}`);
|
|
16
17
|
}
|
|
17
|
-
|
|
18
|
+
reader = response.body.getReader();
|
|
18
19
|
const decoder = new TextDecoder('utf-8');
|
|
19
20
|
let buffer = '';
|
|
20
21
|
while (true) {
|
|
@@ -53,5 +54,13 @@ export const fetchServerEvents = async (url, { onMessage, onError, onClose, fetc
|
|
|
53
54
|
catch (error) {
|
|
54
55
|
onError?.(error);
|
|
55
56
|
}
|
|
57
|
+
finally {
|
|
58
|
+
try {
|
|
59
|
+
await reader?.cancel();
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
console.error('Error cleaning up stream reader', error);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
56
65
|
};
|
|
57
66
|
//# sourceMappingURL=fetch-server-events.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch-server-events.mjs","sourceRoot":"","sources":["../../src/utils/fetch-server-events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,EACpC,GAAW,EACX,EACE,SAAS,EACT,OAAO,EACP,OAAO,EACP,OAAO,EACP,GAAG,cAAc,EAMlB,EACD,EAAE;IACF,IAAI;QACF,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;QACpD,IAAI,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE;YAClC,MAAM,IAAI,KAAK,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;SACvC;QAED,MAAM,
|
|
1
|
+
{"version":3,"file":"fetch-server-events.mjs","sourceRoot":"","sources":["../../src/utils/fetch-server-events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,EACpC,GAAW,EACX,EACE,SAAS,EACT,OAAO,EACP,OAAO,EACP,OAAO,EACP,GAAG,cAAc,EAMlB,EACD,EAAE;IACF,IAAI,MAA2D,CAAC;IAChE,IAAI;QACF,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;QACpD,IAAI,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE;YAClC,MAAM,IAAI,KAAK,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;SACvC;QAED,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;QACnC,MAAM,OAAO,GAAG,IAAI,WAAW,CAAC,OAAO,CAAC,CAAC;QACzC,IAAI,MAAM,GAAG,EAAE,CAAC;QAEhB,OAAO,IAAI,EAAE;YACX,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;YAE5C,IAAI,I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,CAAC,KAAK,CAAC,CAAC;KAClB;YAAS;QACR,IAAI;YACF,MAAM,MAAM,EAAE,MAAM,EAAE,CAAC;SACxB;QAAC,OAAO,KAAK,EAAE;YACd,OAAO,CAAC,KAAK,CAAC,iCAAiC,EAAE,KAAK,CAAC,CAAC;SACzD;KACF;AACH,CAAC,CAAC","sourcesContent":["/**\n * Streams server-sent events from the given URL\n *\n * @param url - The URL to stream events from\n * @param options - The options for the SSE stream\n * @param options.onMessage - The function to call when a message is received\n * @param options.onError - The function to call when an error occurs\n * @param options.onClose - The function to call when the stream finishes successfully\n * @param options.fetchFn - The function to use to fetch the events. Consumers need to provide a fetch function that supports server-sent events.\n */\nexport const fetchServerEvents = async (\n url: string,\n {\n onMessage,\n onError,\n onClose,\n fetchFn,\n ...requestOptions\n }: RequestInit & {\n onMessage: (data: Record<string, unknown>, eventName?: string) => void;\n onError?: (err: unknown) => void;\n onClose?: () => void;\n fetchFn: typeof fetch;\n },\n) => {\n let reader: ReadableStreamDefaultReader<Uint8Array> | undefined;\n try {\n const response = await fetchFn(url, requestOptions);\n if (!response.ok || !response.body) {\n throw new Error(`${response.status}`);\n }\n\n reader = response.body.getReader();\n const decoder = new TextDecoder('utf-8');\n let buffer = '';\n\n while (true) {\n const { done, value } = await reader.read();\n\n if (done) {\n break;\n }\n\n buffer += decoder.decode(value, { stream: true });\n\n // Split SSE messages at double newlines\n const parts = buffer.split('\\n\\n');\n buffer = parts.pop() || '';\n\n // Split chunks into lines and parse the data\n for (const chunk of parts) {\n const lines = chunk.split('\\n');\n let eventName: string | undefined;\n const dataLines: string[] = [];\n\n for (const line of lines) {\n if (line.startsWith('event:')) {\n eventName = line.slice(6).trim();\n } else if (line.startsWith('data:')) {\n dataLines.push(line.slice(5).trim());\n }\n }\n\n if (eventName === 'error') {\n throw new Error(`Bridge-api error: ${dataLines.join('\\n')}`);\n }\n if (dataLines.length > 0) {\n const parsedJSONData = JSON.parse(dataLines.join('\\n'));\n onMessage(parsedJSONData, eventName);\n }\n }\n }\n onClose?.();\n } catch (error) {\n onError?.(error);\n } finally {\n try {\n await reader?.cancel();\n } catch (error) {\n console.error('Error cleaning up stream reader', error);\n }\n }\n};\n"]}
|
|
@@ -78,18 +78,38 @@ const appendNonEvmFees = async (quotes, messenger, selectedAccount) => {
|
|
|
78
78
|
}
|
|
79
79
|
const nonEvmFeePromises = Promise.allSettled(quotes.map(async (quoteResponse) => {
|
|
80
80
|
const { trade, quote } = quoteResponse;
|
|
81
|
-
if
|
|
81
|
+
// Skip fee computation if no snap account or trade data
|
|
82
|
+
if (!selectedAccount?.metadata?.snap?.id || !trade) {
|
|
83
|
+
return quoteResponse;
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
82
86
|
const scope = (0, caip_formatters_1.formatChainIdToCaip)(quote.srcChainId);
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
//
|
|
86
|
-
const
|
|
87
|
+
// Normalize trade data to string format expected by snap
|
|
88
|
+
// Solana: trade is already a base64 transaction string
|
|
89
|
+
// Bitcoin: extract unsignedPsbtBase64 from trade object
|
|
90
|
+
const transaction = typeof trade === 'string'
|
|
91
|
+
? trade
|
|
92
|
+
: trade.unsignedPsbtBase64;
|
|
93
|
+
const response = (await messenger.call('SnapController:handleRequest', (0, snaps_1.computeFeeRequest)(selectedAccount.metadata.snap?.id, transaction, selectedAccount.id, scope)));
|
|
94
|
+
// Bitcoin snap returns 'priority' fee, Solana returns 'base' fee
|
|
95
|
+
const fee = response?.find((f) => f.type === 'base') ||
|
|
96
|
+
response?.find((f) => f.type === 'priority') ||
|
|
97
|
+
response?.[0];
|
|
98
|
+
const feeInNative = fee?.asset?.amount || '0';
|
|
87
99
|
return {
|
|
88
100
|
...quoteResponse,
|
|
89
101
|
nonEvmFeesInNative: feeInNative,
|
|
90
102
|
};
|
|
91
103
|
}
|
|
92
|
-
|
|
104
|
+
catch (error) {
|
|
105
|
+
// Return quote with undefined fee if snap fails (e.g., insufficient UTXO funds)
|
|
106
|
+
// Client can render special UI or skip the quote card row for quotes with missing fee data
|
|
107
|
+
console.error(`Failed to compute non-EVM fees for quote ${quote.requestId}:`, error);
|
|
108
|
+
return {
|
|
109
|
+
...quoteResponse,
|
|
110
|
+
nonEvmFeesInNative: undefined,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
93
113
|
}));
|
|
94
114
|
const quotesWithNonEvmFees = (await nonEvmFeePromises).reduce((acc, result) => {
|
|
95
115
|
if (result.status === 'fulfilled' && result.value) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quote-fees.cjs","sourceRoot":"","sources":["../../src/utils/quote-fees.ts"],"names":[],"mappings":";;;AAEA,2CAA8C;AAE9C,yCAAqD;AACrD,2DAAwD;AACxD,uCAA4C;AAC5C,oDAAgD;AAShD;;;;;;GAMG;AACH,MAAM,eAAe,GAAG,KAAK,EAC3B,MAAuB,EACvB,eAAuE,EACnB,EAAE;IACtD,oEAAoE;IACpE,MAAM,gBAAgB,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE;QACjD,MAAM,OAAO,GAAG,IAAA,qCAAmB,EAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QACtD,OAAO,CAAC,CAAC,kBAAS,CAAC,QAAQ,EAAE,kBAAS,CAAC,IAAI,CAAC;aACzC,GAAG,CAAC,qCAAmB,CAAC;aACxB,QAAQ,CAAC,OAAO,CAAC,CAAC;IACvB,CAAC,CAAC,CAAC;IAEH,wEAAwE;IACxE,IAAI,gBAAgB,EAAE;QACpB,OAAO,SAAS,CAAC;KAClB;IAED,MAAM,gBAAgB,GAAG,OAAO,CAAC,UAAU,CACzC,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,aAAa,EAAE,EAAE;QACjC,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,aAAa,CAAC;QACjD,MAAM,OAAO,GAAG,IAAA,mBAAW,EAAC,KAAK,CAAC,UAAU,CAAC,CAAC;Q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AAC,MAAM,iBAAiB,CAAC,CAAC,MAAM,CAE3D,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE;QAChB,IAAI,MAAM,CAAC,MAAM,KAAK,WAAW,IAAI,MAAM,CAAC,KAAK,EAAE;YACjD,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;SACxB;aAAM,IAAI,MAAM,CAAC,MAAM,KAAK,UAAU,EAAE;YACvC,OAAO,CAAC,KAAK,CAAC,0CAA0C,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;SAC1E;QACD,OAAO,GAAG,CAAC;IACb,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,oBAAoB,CAAC;AAC9B,CAAC,CAAC;AAEF;;;;;;;;GAQG;AACI,MAAM,kBAAkB,GAAG,KAAK,EACrC,MAAuB,EACvB,SAAoC,EACpC,eAAuE,EACvE,eAAgC,EACqB,EAAE;IACvD,MAAM,mBAAmB,GAAG,MAAM,eAAe,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IAC3E,MAAM,oBAAoB,GAAG,MAAM,gBAAgB,CACjD,MAAM,EACN,SAAS,EACT,eAAe,CAChB,CAAC;IAEF,OAAO,mBAAmB,IAAI,oBAAoB,IAAI,MAAM,CAAC;AAC/D,CAAC,CAAC;AAdW,QAAA,kBAAkB,sBAc7B","sourcesContent":["import type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type { TransactionController } from '@metamask/transaction-controller';\nimport { numberToHex } from '@metamask/utils';\n\nimport { isNonEvmChainId, sumHexes } from './bridge';\nimport { formatChainIdToCaip } from './caip-formatters';\nimport { computeFeeRequest } from './snaps';\nimport { CHAIN_IDS } from '../constants/chains';\nimport type {\n QuoteResponse,\n L1GasFees,\n NonEvmFees,\n TxData,\n BridgeControllerMessenger,\n} from '../types';\n\n/**\n * Appends transaction fees for EVM chains to quotes\n *\n * @param quotes - Array of quote responses to append fees to\n * @param getLayer1GasFee - The function to use to get the layer 1 gas fee\n * @returns Array of quotes with fees appended, or undefined if quotes are for non-EVM chains\n */\nconst appendL1GasFees = async (\n quotes: QuoteResponse[],\n getLayer1GasFee: typeof TransactionController.prototype.getLayer1GasFee,\n): Promise<(QuoteResponse & L1GasFees)[] | undefined> => {\n // Indicates whether some of the quotes are not for optimism or base\n const hasInvalidQuotes = quotes.some(({ quote }) => {\n const chainId = formatChainIdToCaip(quote.srcChainId);\n return ![CHAIN_IDS.OPTIMISM, CHAIN_IDS.BASE]\n .map(formatChainIdToCaip)\n .includes(chainId);\n });\n\n // Only append L1 gas fees if all quotes are for either optimism or base\n if (hasInvalidQuotes) {\n return undefined;\n }\n\n const l1GasFeePromises = Promise.allSettled(\n quotes.map(async (quoteResponse) => {\n const { quote, trade, approval } = quoteResponse;\n const chainId = numberToHex(quote.srcChainId);\n\n const getTxParams = (txData: TxData) => ({\n from: txData.from,\n to: txData.to,\n value: txData.value,\n data: txData.data,\n gasLimit: txData.gasLimit?.toString(),\n });\n const approvalL1GasFees = approval\n ? await getLayer1GasFee({\n transactionParams: getTxParams(approval),\n chainId,\n })\n : '0x0';\n const tradeL1GasFees = await getLayer1GasFee({\n transactionParams: getTxParams(trade as TxData),\n chainId,\n });\n\n if (approvalL1GasFees === undefined || tradeL1GasFees === undefined) {\n return undefined;\n }\n\n return {\n ...quoteResponse,\n l1GasFeesInHexWei: sumHexes(approvalL1GasFees, tradeL1GasFees),\n };\n }),\n );\n\n const quotesWithL1GasFees = (await l1GasFeePromises).reduce<\n (QuoteResponse & L1GasFees)[]\n >((acc, result) => {\n if (result.status === 'fulfilled' && result.value) {\n acc.push(result.value);\n } else if (result.status === 'rejected') {\n console.error('Error calculating L1 gas fees for quote', result.reason);\n }\n return acc;\n }, []);\n\n return quotesWithL1GasFees;\n};\n\n/**\n * Appends transaction fees for non-EVM chains to quotes\n *\n * @param quotes - Array of quote responses to append fees to\n * @param messenger - The messaging system to use to call the snap controller\n * @param selectedAccount - The selected account for which the quotes were requested\n * @returns Array of quotes with fees appended, or undefined if quotes are for EVM chains\n */\nconst appendNonEvmFees = async (\n quotes: QuoteResponse[],\n messenger: BridgeControllerMessenger,\n selectedAccount: InternalAccount,\n): Promise<(QuoteResponse & NonEvmFees)[] | undefined> => {\n if (\n quotes.some(({ quote: { srcChainId } }) => !isNonEvmChainId(srcChainId))\n ) {\n return undefined;\n }\n\n const nonEvmFeePromises = Promise.allSettled(\n quotes.map(async (quoteResponse) => {\n const { trade, quote } = quoteResponse;\n\n if (selectedAccount?.metadata?.snap?.id && typeof trade === 'string') {\n const scope = formatChainIdToCaip(quote.srcChainId);\n\n const response = (await messenger.call(\n 'SnapController:handleRequest',\n computeFeeRequest(\n selectedAccount.metadata.snap?.id,\n trade,\n selectedAccount.id,\n scope,\n ),\n )) as {\n type: 'base' | 'priority';\n asset: {\n unit: string;\n type: string;\n amount: string;\n fungible: true;\n };\n }[];\n\n const baseFee = response?.find((fee) => fee.type === 'base');\n // Store fees in native units as returned by the snap (e.g., SOL, BTC)\n const feeInNative = baseFee?.asset?.amount || '0';\n\n return {\n ...quoteResponse,\n nonEvmFeesInNative: feeInNative,\n };\n }\n return quoteResponse;\n }),\n );\n\n const quotesWithNonEvmFees = (await nonEvmFeePromises).reduce<\n (QuoteResponse & NonEvmFees)[]\n >((acc, result) => {\n if (result.status === 'fulfilled' && result.value) {\n acc.push(result.value);\n } else if (result.status === 'rejected') {\n console.error('Error calculating non-EVM fees for quote', result.reason);\n }\n return acc;\n }, []);\n\n return quotesWithNonEvmFees;\n};\n\n/**\n * Appends transaction fees to quotes\n *\n * @param quotes - Array of quote responses to append fees to\n * @param messenger - The bridge controller to use to call the snap controller\n * @param getLayer1GasFee - The function to use to get the layer 1 gas fee\n * @param selectedAccount - The selected account for which the quotes were requested\n * @returns Array of quotes with fees appended, or undefined if quotes are for EVM chains\n */\nexport const appendFeesToQuotes = async (\n quotes: QuoteResponse[],\n messenger: BridgeControllerMessenger,\n getLayer1GasFee: typeof TransactionController.prototype.getLayer1GasFee,\n selectedAccount: InternalAccount,\n): Promise<(QuoteResponse & L1GasFees & NonEvmFees)[]> => {\n const quotesWithL1GasFees = await appendL1GasFees(quotes, getLayer1GasFee);\n const quotesWithNonEvmFees = await appendNonEvmFees(\n quotes,\n messenger,\n selectedAccount,\n );\n\n return quotesWithL1GasFees ?? quotesWithNonEvmFees ?? quotes;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"quote-fees.cjs","sourceRoot":"","sources":["../../src/utils/quote-fees.ts"],"names":[],"mappings":";;;AAEA,2CAA8C;AAE9C,yCAAqD;AACrD,2DAAwD;AACxD,uCAA4C;AAC5C,oDAAgD;AAUhD;;;;;;GAMG;AACH,MAAM,eAAe,GAAG,KAAK,EAC3B,MAAuB,EACvB,eAAuE,EACnB,EAAE;IACtD,oEAAoE;IACpE,MAAM,gBAAgB,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE;QACjD,MAAM,OAAO,GAAG,IAAA,qCAAmB,EAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QACtD,OAAO,CAAC,CAAC,kBAAS,CAAC,QAAQ,EAAE,kBAAS,CAAC,IAAI,CAAC;aACzC,GAAG,CAAC,qCAAmB,CAAC;aACxB,QAAQ,CAAC,OAAO,CAAC,CAAC;IACvB,CAAC,CAAC,CAAC;IAEH,wEAAwE;IACxE,IAAI,gBAAgB,EAAE;QACpB,OAAO,SAAS,CAAC;KAClB;IAED,MAAM,gBAAgB,GAAG,OAAO,CAAC,UAAU,CACzC,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,aAAa,EAAE,EAAE;QACjC,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,aAAa,CAAC;QACjD,MAAM,OAAO,GAAG,IAAA,mBAAW,EAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QAE9C,MAAM,WAAW,GAAG,CAAC,MAAc,EAAE,EAAE,CAAC,CAAC;YACvC,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB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CAAC;AAdW,QAAA,kBAAkB,sBAc7B","sourcesContent":["import type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type { TransactionController } from '@metamask/transaction-controller';\nimport { numberToHex } from '@metamask/utils';\n\nimport { isNonEvmChainId, sumHexes } from './bridge';\nimport { formatChainIdToCaip } from './caip-formatters';\nimport { computeFeeRequest } from './snaps';\nimport { CHAIN_IDS } from '../constants/chains';\nimport type {\n QuoteResponse,\n L1GasFees,\n NonEvmFees,\n TxData,\n BridgeControllerMessenger,\n BitcoinTradeData,\n} from '../types';\n\n/**\n * Appends transaction fees for EVM chains to quotes\n *\n * @param quotes - Array of quote responses to append fees to\n * @param getLayer1GasFee - The function to use to get the layer 1 gas fee\n * @returns Array of quotes with fees appended, or undefined if quotes are for non-EVM chains\n */\nconst appendL1GasFees = async (\n quotes: QuoteResponse[],\n getLayer1GasFee: typeof TransactionController.prototype.getLayer1GasFee,\n): Promise<(QuoteResponse & L1GasFees)[] | undefined> => {\n // Indicates whether some of the quotes are not for optimism or base\n const hasInvalidQuotes = quotes.some(({ quote }) => {\n const chainId = formatChainIdToCaip(quote.srcChainId);\n return ![CHAIN_IDS.OPTIMISM, CHAIN_IDS.BASE]\n .map(formatChainIdToCaip)\n .includes(chainId);\n });\n\n // Only append L1 gas fees if all quotes are for either optimism or base\n if (hasInvalidQuotes) {\n return undefined;\n }\n\n const l1GasFeePromises = Promise.allSettled(\n quotes.map(async (quoteResponse) => {\n const { quote, trade, approval } = quoteResponse;\n const chainId = numberToHex(quote.srcChainId);\n\n const getTxParams = (txData: TxData) => ({\n from: txData.from,\n to: txData.to,\n value: txData.value,\n data: txData.data,\n gasLimit: txData.gasLimit?.toString(),\n });\n const approvalL1GasFees = approval\n ? await getLayer1GasFee({\n transactionParams: getTxParams(approval),\n chainId,\n })\n : '0x0';\n const tradeL1GasFees = await getLayer1GasFee({\n transactionParams: getTxParams(trade as TxData),\n chainId,\n });\n\n if (approvalL1GasFees === undefined || tradeL1GasFees === undefined) {\n return undefined;\n }\n\n return {\n ...quoteResponse,\n l1GasFeesInHexWei: sumHexes(approvalL1GasFees, tradeL1GasFees),\n };\n }),\n );\n\n const quotesWithL1GasFees = (await l1GasFeePromises).reduce<\n (QuoteResponse & L1GasFees)[]\n >((acc, result) => {\n if (result.status === 'fulfilled' && result.value) {\n acc.push(result.value);\n } else if (result.status === 'rejected') {\n console.error('Error calculating L1 gas fees for quote', result.reason);\n }\n return acc;\n }, []);\n\n return quotesWithL1GasFees;\n};\n\n/**\n * Appends transaction fees for non-EVM chains to quotes\n *\n * @param quotes - Array of quote responses to append fees to\n * @param messenger - The messaging system to use to call the snap controller\n * @param selectedAccount - The selected account for which the quotes were requested\n * @returns Array of quotes with fees appended, or undefined if quotes are for EVM chains\n */\nconst appendNonEvmFees = async (\n quotes: QuoteResponse[],\n messenger: BridgeControllerMessenger,\n selectedAccount: InternalAccount,\n): Promise<(QuoteResponse & NonEvmFees)[] | undefined> => {\n if (\n quotes.some(({ quote: { srcChainId } }) => !isNonEvmChainId(srcChainId))\n ) {\n return undefined;\n }\n\n const nonEvmFeePromises = Promise.allSettled(\n quotes.map(async (quoteResponse) => {\n const { trade, quote } = quoteResponse;\n\n // Skip fee computation if no snap account or trade data\n if (!selectedAccount?.metadata?.snap?.id || !trade) {\n return quoteResponse;\n }\n\n try {\n const scope = formatChainIdToCaip(quote.srcChainId);\n\n // Normalize trade data to string format expected by snap\n // Solana: trade is already a base64 transaction string\n // Bitcoin: extract unsignedPsbtBase64 from trade object\n const transaction =\n typeof trade === 'string'\n ? trade\n : (trade as BitcoinTradeData).unsignedPsbtBase64;\n\n const response = (await messenger.call(\n 'SnapController:handleRequest',\n computeFeeRequest(\n selectedAccount.metadata.snap?.id,\n transaction,\n selectedAccount.id,\n scope,\n ),\n )) as {\n type: 'base' | 'priority';\n asset: {\n unit: string;\n type: string;\n amount: string;\n fungible: true;\n };\n }[];\n\n // Bitcoin snap returns 'priority' fee, Solana returns 'base' fee\n const fee =\n response?.find((f) => f.type === 'base') ||\n response?.find((f) => f.type === 'priority') ||\n response?.[0];\n const feeInNative = fee?.asset?.amount || '0';\n\n return {\n ...quoteResponse,\n nonEvmFeesInNative: feeInNative,\n };\n } catch (error) {\n // Return quote with undefined fee if snap fails (e.g., insufficient UTXO funds)\n // Client can render special UI or skip the quote card row for quotes with missing fee data\n console.error(\n `Failed to compute non-EVM fees for quote ${quote.requestId}:`,\n error,\n );\n return {\n ...quoteResponse,\n nonEvmFeesInNative: undefined,\n };\n }\n }),\n );\n\n const quotesWithNonEvmFees = (await nonEvmFeePromises).reduce<\n (QuoteResponse & NonEvmFees)[]\n >((acc, result) => {\n if (result.status === 'fulfilled' && result.value) {\n acc.push(result.value);\n } else if (result.status === 'rejected') {\n console.error('Error calculating non-EVM fees for quote', result.reason);\n }\n return acc;\n }, []);\n\n return quotesWithNonEvmFees;\n};\n\n/**\n * Appends transaction fees to quotes\n *\n * @param quotes - Array of quote responses to append fees to\n * @param messenger - The bridge controller to use to call the snap controller\n * @param getLayer1GasFee - The function to use to get the layer 1 gas fee\n * @param selectedAccount - The selected account for which the quotes were requested\n * @returns Array of quotes with fees appended, or undefined if quotes are for EVM chains\n */\nexport const appendFeesToQuotes = async (\n quotes: QuoteResponse[],\n messenger: BridgeControllerMessenger,\n getLayer1GasFee: typeof TransactionController.prototype.getLayer1GasFee,\n selectedAccount: InternalAccount,\n): Promise<(QuoteResponse & L1GasFees & NonEvmFees)[]> => {\n const quotesWithL1GasFees = await appendL1GasFees(quotes, getLayer1GasFee);\n const quotesWithNonEvmFees = await appendNonEvmFees(\n quotes,\n messenger,\n selectedAccount,\n );\n\n return quotesWithL1GasFees ?? quotesWithNonEvmFees ?? quotes;\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quote-fees.d.cts","sourceRoot":"","sources":["../../src/utils/quote-fees.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AACtE,OAAO,KAAK,EAAE,qBAAqB,EAAE,yCAAyC;AAO9E,OAAO,KAAK,EACV,aAAa,EACb,SAAS,EACT,UAAU,EAEV,yBAAyB,
|
|
1
|
+
{"version":3,"file":"quote-fees.d.cts","sourceRoot":"","sources":["../../src/utils/quote-fees.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AACtE,OAAO,KAAK,EAAE,qBAAqB,EAAE,yCAAyC;AAO9E,OAAO,KAAK,EACV,aAAa,EACb,SAAS,EACT,UAAU,EAEV,yBAAyB,EAE1B,qBAAiB;AA2KlB;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,WACrB,aAAa,EAAE;;;;2DAGN,eAAe,KAC/B,QAAQ,CAAC,aAAa,GAAG,SAAS,GAAG,UAAU,CAAC,EAAE,CASpD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quote-fees.d.mts","sourceRoot":"","sources":["../../src/utils/quote-fees.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AACtE,OAAO,KAAK,EAAE,qBAAqB,EAAE,yCAAyC;AAO9E,OAAO,KAAK,EACV,aAAa,EACb,SAAS,EACT,UAAU,EAEV,yBAAyB,
|
|
1
|
+
{"version":3,"file":"quote-fees.d.mts","sourceRoot":"","sources":["../../src/utils/quote-fees.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AACtE,OAAO,KAAK,EAAE,qBAAqB,EAAE,yCAAyC;AAO9E,OAAO,KAAK,EACV,aAAa,EACb,SAAS,EACT,UAAU,EAEV,yBAAyB,EAE1B,qBAAiB;AA2KlB;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,WACrB,aAAa,EAAE;;;;2DAGN,eAAe,KAC/B,QAAQ,CAAC,aAAa,GAAG,SAAS,GAAG,UAAU,CAAC,EAAE,CASpD,CAAC"}
|