@metamask-previews/bridge-controller 13.0.0-preview-13a1c613 → 14.0.0-preview-f919f9b0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/CHANGELOG.md +21 -3
  2. package/dist/bridge-controller.cjs +59 -4
  3. package/dist/bridge-controller.cjs.map +1 -1
  4. package/dist/bridge-controller.d.cts +2 -3
  5. package/dist/bridge-controller.d.cts.map +1 -1
  6. package/dist/bridge-controller.d.mts +2 -3
  7. package/dist/bridge-controller.d.mts.map +1 -1
  8. package/dist/bridge-controller.mjs +60 -5
  9. package/dist/bridge-controller.mjs.map +1 -1
  10. package/dist/constants/bridge.cjs +1 -0
  11. package/dist/constants/bridge.cjs.map +1 -1
  12. package/dist/constants/bridge.d.cts.map +1 -1
  13. package/dist/constants/bridge.d.mts.map +1 -1
  14. package/dist/constants/bridge.mjs +1 -0
  15. package/dist/constants/bridge.mjs.map +1 -1
  16. package/dist/index.cjs +13 -1
  17. package/dist/index.cjs.map +1 -1
  18. package/dist/index.d.cts +10 -1
  19. package/dist/index.d.cts.map +1 -1
  20. package/dist/index.d.mts +10 -1
  21. package/dist/index.d.mts.map +1 -1
  22. package/dist/index.mjs +10 -1
  23. package/dist/index.mjs.map +1 -1
  24. package/dist/selectors.cjs +224 -0
  25. package/dist/selectors.cjs.map +1 -0
  26. package/dist/selectors.d.cts +1506 -0
  27. package/dist/selectors.d.cts.map +1 -0
  28. package/dist/selectors.d.mts +1506 -0
  29. package/dist/selectors.d.mts.map +1 -0
  30. package/dist/selectors.mjs +220 -0
  31. package/dist/selectors.mjs.map +1 -0
  32. package/dist/types.cjs.map +1 -1
  33. package/dist/types.d.cts +44 -14
  34. package/dist/types.d.cts.map +1 -1
  35. package/dist/types.d.mts +44 -14
  36. package/dist/types.d.mts.map +1 -1
  37. package/dist/types.mjs.map +1 -1
  38. package/dist/utils/assets.cjs +30 -0
  39. package/dist/utils/assets.cjs.map +1 -0
  40. package/dist/utils/assets.d.cts +9 -0
  41. package/dist/utils/assets.d.cts.map +1 -0
  42. package/dist/utils/assets.d.mts +9 -0
  43. package/dist/utils/assets.d.mts.map +1 -0
  44. package/dist/utils/assets.mjs +25 -0
  45. package/dist/utils/assets.mjs.map +1 -0
  46. package/dist/utils/caip-formatters.cjs +25 -1
  47. package/dist/utils/caip-formatters.cjs.map +1 -1
  48. package/dist/utils/caip-formatters.d.cts +10 -0
  49. package/dist/utils/caip-formatters.d.cts.map +1 -1
  50. package/dist/utils/caip-formatters.d.mts +10 -0
  51. package/dist/utils/caip-formatters.d.mts.map +1 -1
  52. package/dist/utils/caip-formatters.mjs +25 -2
  53. package/dist/utils/caip-formatters.mjs.map +1 -1
  54. package/dist/utils/fetch.cjs +61 -1
  55. package/dist/utils/fetch.cjs.map +1 -1
  56. package/dist/utils/fetch.d.cts +21 -1
  57. package/dist/utils/fetch.d.cts.map +1 -1
  58. package/dist/utils/fetch.d.mts +21 -1
  59. package/dist/utils/fetch.d.mts.map +1 -1
  60. package/dist/utils/fetch.mjs +59 -0
  61. package/dist/utils/fetch.mjs.map +1 -1
  62. package/dist/utils/quote.cjs +177 -1
  63. package/dist/utils/quote.cjs.map +1 -1
  64. package/dist/utils/quote.d.cts +62 -1
  65. package/dist/utils/quote.d.cts.map +1 -1
  66. package/dist/utils/quote.d.mts +62 -1
  67. package/dist/utils/quote.d.mts.map +1 -1
  68. package/dist/utils/quote.mjs +164 -0
  69. package/dist/utils/quote.mjs.map +1 -1
  70. package/package.json +9 -5
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selectors.d.mts","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,iBAAiB,EACjB,oCAAoC,EACpC,yBAAyB,EAC1B,qCAAqC;AACtC,OAAO,KAAK,EAAE,eAAe,EAAE,qCAAqC;AAUpE,OAAO,KAAK,EACV,qBAAqB,EACrB,qBAAqB,EACrB,YAAY,EACZ,mBAAmB,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OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;8CAqNd,wBAAwB;;;;;;;;;yBAvN5B,eAAe;;kCAEJ,OAAO;;;;;;;;;;;;;;6BAFlB,eAAe;;sCAEJ,OAAO;;;;;;;;;;;;;;iCAFlB,eAAe;;0CAEJ,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qCAFlB,eAAe;;8CAEJ,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;yCAFlB,eAAe;;kDAEJ,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;yCAFlB,eAAe;;kDAEJ,OAAO;;;;;;;;;;;;;;;;;;;;;;yCAFlB,eAAe;;kDAEJ,OAAO;;;;;;;;;;;;;;;;;;;;;;yCAFlB,eAAe;;kDAEJ,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;sDAqNd,wBAAwB;;;;;;;;;;;;;;;;kDA6BpB,wBAAwB;;;;;;;;uIAM1C,cAAc,uBACA,wBAAwB;;;;;;;;CAiE7C,CAAC"}
@@ -0,0 +1,220 @@
1
+ import { AddressZero } from "@ethersproject/constants";
2
+ import { isStrictHexString } from "@metamask/utils";
3
+ import $lodash from "lodash";
4
+ const { orderBy } = $lodash;
5
+ import { createSelector as createSelector_, createStructuredSelector as createStructuredSelector_ } from "reselect";
6
+ import { BRIDGE_PREFERRED_GAS_ESTIMATE } from "./constants/bridge.mjs";
7
+ import { RequestStatus, SortOrder } from "./types.mjs";
8
+ import { getNativeAssetForChainId, isNativeAddress, isSolanaChainId } from "./utils/bridge.mjs";
9
+ import { formatAddressToAssetId, formatChainIdToCaip, formatChainIdToHex } from "./utils/caip-formatters.mjs";
10
+ import { calcAdjustedReturn, calcCost, calcEstimatedAndMaxTotalGasFee, calcRelayerFee, calcSentAmount, calcSolanaTotalNetworkFee, calcSwapRate, calcToAmount, calcTotalEstimatedNetworkFee, calcTotalMaxNetworkFee } from "./utils/quote.mjs";
11
+ /**
12
+ * Creates a structured selector for the bridge controller
13
+ */
14
+ const createStructuredBridgeSelector = createStructuredSelector_.withTypes();
15
+ /**
16
+ * Creates a typed selector for the bridge controller
17
+ */
18
+ const createBridgeSelector = createSelector_.withTypes();
19
+ const getExchangeRateByChainIdAndAddress = (exchangeRateSources, chainId, address) => {
20
+ if (!chainId || !address) {
21
+ return {};
22
+ }
23
+ // TODO return usd exchange rate if user has opted into metrics
24
+ const assetId = formatAddressToAssetId(address, chainId);
25
+ if (!assetId) {
26
+ return {};
27
+ }
28
+ const { assetExchangeRates, currencyRates, marketData, conversionRates } = exchangeRateSources;
29
+ // If the asset exchange rate is available in the bridge controller, use it
30
+ // This is defined if the token's rate is not available from the assets controllers
31
+ const bridgeControllerRate = assetExchangeRates?.[assetId] ??
32
+ assetExchangeRates?.[assetId.toLowerCase()];
33
+ if (bridgeControllerRate?.exchangeRate) {
34
+ return bridgeControllerRate;
35
+ }
36
+ // If the chain is a Solana chain, use the conversion rate from the multichain assets controller
37
+ if (isSolanaChainId(chainId)) {
38
+ const multichainAssetExchangeRate = conversionRates?.[assetId];
39
+ if (multichainAssetExchangeRate) {
40
+ return {
41
+ exchangeRate: multichainAssetExchangeRate.rate,
42
+ usdExchangeRate: undefined,
43
+ };
44
+ }
45
+ return {};
46
+ }
47
+ // If the chain is an EVM chain, use the conversion rate from the currency rates controller
48
+ if (isNativeAddress(address)) {
49
+ const { symbol } = getNativeAssetForChainId(chainId);
50
+ const evmNativeExchangeRate = currencyRates?.[symbol.toLowerCase()];
51
+ if (evmNativeExchangeRate) {
52
+ return {
53
+ exchangeRate: evmNativeExchangeRate?.conversionRate?.toString(),
54
+ usdExchangeRate: evmNativeExchangeRate?.usdConversionRate?.toString(),
55
+ };
56
+ }
57
+ return {};
58
+ }
59
+ // If the chain is an EVM chain and the asset is not the native asset, use the conversion rate from the token rates controller
60
+ const evmTokenExchangeRates = marketData?.[formatChainIdToHex(chainId)];
61
+ const evmTokenExchangeRateForAddress = isStrictHexString(address)
62
+ ? evmTokenExchangeRates?.[address]
63
+ : null;
64
+ if (evmTokenExchangeRateForAddress) {
65
+ return {
66
+ exchangeRate: evmTokenExchangeRateForAddress?.price.toString(),
67
+ usdExchangeRate: undefined,
68
+ };
69
+ }
70
+ return {};
71
+ };
72
+ /**
73
+ * Selects the asset exchange rate for a given chain and address
74
+ *
75
+ * @param state The state of the bridge controller and its dependency controllers
76
+ * @param chainId The chain ID of the asset
77
+ * @param address The address of the asset
78
+ * @returns The asset exchange rate for the given chain and address
79
+ */
80
+ export const selectExchangeRateByChainIdAndAddress = (state, chainId, address) => {
81
+ return getExchangeRateByChainIdAndAddress(state, chainId, address);
82
+ };
83
+ /**
84
+ * Checks whether an exchange rate is available for a given chain and address
85
+ *
86
+ * @param params The parameters to pass to {@link getExchangeRateByChainIdAndAddress}
87
+ * @returns Whether an exchange rate is available for the given chain and address
88
+ */
89
+ export const selectIsAssetExchangeRateInState = (...params) => Boolean(getExchangeRateByChainIdAndAddress(...params)?.exchangeRate);
90
+ /**
91
+ * Selects the gas fee estimates from the gas fee controller. All potential networks
92
+ * support EIP1559 gas fees so assume that gasFeeEstimates is of type GasFeeEstimates
93
+ *
94
+ * @returns The gas fee estimates in decGWEI
95
+ */
96
+ const selectBridgeFeesPerGas = createStructuredBridgeSelector({
97
+ estimatedBaseFeeInDecGwei: ({ gasFeeEstimates }) => gasFeeEstimates?.estimatedBaseFee,
98
+ maxPriorityFeePerGasInDecGwei: ({ gasFeeEstimates }) => gasFeeEstimates?.[BRIDGE_PREFERRED_GAS_ESTIMATE]
99
+ ?.suggestedMaxPriorityFeePerGas,
100
+ maxFeePerGasInDecGwei: ({ gasFeeEstimates }) => gasFeeEstimates?.high?.suggestedMaxFeePerGas,
101
+ });
102
+ // Selects cross-chain swap quotes including their metadata
103
+ const selectBridgeQuotesWithMetadata = createBridgeSelector([
104
+ ({ quotes }) => quotes,
105
+ selectBridgeFeesPerGas,
106
+ createBridgeSelector([
107
+ (state) => state,
108
+ ({ quoteRequest: { srcChainId } }) => srcChainId,
109
+ ({ quoteRequest: { srcTokenAddress } }) => srcTokenAddress,
110
+ ], selectExchangeRateByChainIdAndAddress),
111
+ createBridgeSelector([
112
+ (state) => state,
113
+ ({ quoteRequest: { destChainId } }) => destChainId,
114
+ ({ quoteRequest: { destTokenAddress } }) => destTokenAddress,
115
+ ], selectExchangeRateByChainIdAndAddress),
116
+ createBridgeSelector([(state) => state, ({ quoteRequest: { srcChainId } }) => srcChainId], (state, chainId) => selectExchangeRateByChainIdAndAddress(state, chainId, AddressZero)),
117
+ ], (quotes, bridgeFeesPerGas, srcTokenExchangeRate, destTokenExchangeRate, nativeExchangeRate) => {
118
+ const newQuotes = quotes.map((quote) => {
119
+ const sentAmount = calcSentAmount(quote.quote, srcTokenExchangeRate);
120
+ const toTokenAmount = calcToAmount(quote.quote, destTokenExchangeRate);
121
+ let totalEstimatedNetworkFee, gasFee, totalMaxNetworkFee, relayerFee;
122
+ if (isSolanaChainId(quote.quote.srcChainId)) {
123
+ totalEstimatedNetworkFee = calcSolanaTotalNetworkFee(quote, nativeExchangeRate);
124
+ gasFee = totalEstimatedNetworkFee;
125
+ totalMaxNetworkFee = totalEstimatedNetworkFee;
126
+ }
127
+ else {
128
+ relayerFee = calcRelayerFee(quote, nativeExchangeRate);
129
+ gasFee = calcEstimatedAndMaxTotalGasFee({
130
+ bridgeQuote: quote,
131
+ ...bridgeFeesPerGas,
132
+ ...nativeExchangeRate,
133
+ });
134
+ totalEstimatedNetworkFee = calcTotalEstimatedNetworkFee(gasFee, relayerFee);
135
+ totalMaxNetworkFee = calcTotalMaxNetworkFee(gasFee, relayerFee);
136
+ }
137
+ const adjustedReturn = calcAdjustedReturn(toTokenAmount, totalEstimatedNetworkFee);
138
+ const cost = calcCost(adjustedReturn, sentAmount);
139
+ return {
140
+ ...quote,
141
+ // QuoteMetadata fields
142
+ sentAmount,
143
+ toTokenAmount,
144
+ swapRate: calcSwapRate(sentAmount.amount, toTokenAmount.amount),
145
+ totalNetworkFee: totalEstimatedNetworkFee,
146
+ totalMaxNetworkFee,
147
+ gasFee,
148
+ adjustedReturn,
149
+ cost,
150
+ };
151
+ });
152
+ return newQuotes;
153
+ });
154
+ const selectSortedBridgeQuotes = createBridgeSelector([
155
+ selectBridgeQuotesWithMetadata,
156
+ (_, { sortOrder }) => sortOrder,
157
+ ], (quotesWithMetadata, sortOrder) => {
158
+ switch (sortOrder) {
159
+ case SortOrder.ETA_ASC:
160
+ return orderBy(quotesWithMetadata, (quote) => quote.estimatedProcessingTimeInSeconds, 'asc');
161
+ default:
162
+ return orderBy(quotesWithMetadata, ({ cost }) => cost.valueInCurrency ? Number(cost.valueInCurrency) : 0, 'asc');
163
+ }
164
+ });
165
+ const selectRecommendedQuote = createBridgeSelector([selectSortedBridgeQuotes], ([recommendedQuote]) => recommendedQuote);
166
+ const selectActiveQuote = createBridgeSelector([
167
+ selectRecommendedQuote,
168
+ (_, { selectedQuote }) => selectedQuote,
169
+ ], (recommendedQuote, selectedQuote) => selectedQuote ?? recommendedQuote);
170
+ const selectIsQuoteGoingToRefresh = (state, { featureFlagsKey }) => state.quoteRequest.insufficientBal
171
+ ? false
172
+ : state.quotesRefreshCount <
173
+ state.bridgeFeatureFlags[featureFlagsKey].maxRefreshCount;
174
+ const selectQuoteRefreshRate = createBridgeSelector([
175
+ ({ bridgeFeatureFlags }, { featureFlagsKey }) => bridgeFeatureFlags[featureFlagsKey],
176
+ (state) => state.quoteRequest.srcChainId,
177
+ ], (featureFlags, srcChainId) => (srcChainId
178
+ ? featureFlags.chains[formatChainIdToCaip(srcChainId)]?.refreshRate
179
+ : featureFlags.refreshRate) ?? featureFlags.refreshRate);
180
+ export const selectIsQuoteExpired = createBridgeSelector([
181
+ selectIsQuoteGoingToRefresh,
182
+ ({ quotesLastFetched }) => quotesLastFetched,
183
+ selectQuoteRefreshRate,
184
+ (_, __, currentTimeInMs) => currentTimeInMs,
185
+ ], (isQuoteGoingToRefresh, quotesLastFetched, refreshRate, currentTimeInMs) => Boolean(!isQuoteGoingToRefresh &&
186
+ quotesLastFetched &&
187
+ currentTimeInMs - quotesLastFetched > refreshRate));
188
+ /**
189
+ * Selects sorted cross-chain swap quotes. By default, the quotes are sorted by cost in ascending order.
190
+ *
191
+ * @param state - The state of the bridge controller and its dependency controllers
192
+ * @param sortOrder - The sort order of the quotes
193
+ * @param selectedQuote - The quote that is currently selected by the user, should be cleared by clients when the req params change
194
+ * @param featureFlagsKey - The feature flags key for the client (e.g. `BridgeFeatureFlagsKey.EXTENSION_CONFIG`
195
+ * @returns The activeQuote, recommendedQuote, sortedQuotes, and other quote fetching metadata
196
+ *
197
+ * @example
198
+ * ```ts
199
+ * const quotes = useSelector(state => selectBridgeQuotes(
200
+ * state.metamask,
201
+ * {
202
+ * sortOrder: state.bridge.sortOrder,
203
+ * selectedQuote: state.bridge.selectedQuote,
204
+ * featureFlagsKey: BridgeFeatureFlagsKey.EXTENSION_CONFIG,
205
+ * }
206
+ * ));
207
+ * ```
208
+ */
209
+ export const selectBridgeQuotes = createStructuredBridgeSelector({
210
+ sortedQuotes: selectSortedBridgeQuotes,
211
+ recommendedQuote: selectRecommendedQuote,
212
+ activeQuote: selectActiveQuote,
213
+ quotesLastFetchedMs: (state) => state.quotesLastFetched,
214
+ isLoading: (state) => state.quotesLoadingStatus === RequestStatus.LOADING,
215
+ quoteFetchError: (state) => state.quoteFetchError,
216
+ quotesRefreshCount: (state) => state.quotesRefreshCount,
217
+ quotesInitialLoadTimeMs: (state) => state.quotesInitialLoadTime,
218
+ isQuoteGoingToRefresh: selectIsQuoteGoingToRefresh,
219
+ });
220
+ //# sourceMappingURL=selectors.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selectors.mjs","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,iCAAiC;AAQvD,OAAO,EAAE,iBAAiB,EAAE,wBAAwB;;;AAEpD,OAAO,EACL,cAAc,IAAI,eAAe,EACjC,wBAAwB,IAAI,yBAAyB,EACtD,iBAAiB;AAElB,OAAO,EAAE,6BAA6B,EAAE,+BAA2B;AASnE,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,oBAAgB;AACnD,OAAO,EACL,wBAAwB,EACxB,eAAe,EACf,eAAe,EAChB,2BAAuB;AACxB,OAAO,EACL,sBAAsB,EACtB,mBAAmB,EACnB,kBAAkB,EACnB,oCAAgC;AACjC,OAAO,EACL,kBAAkB,EAClB,QAAQ,EACR,8BAA8B,EAC9B,cAAc,EACd,cAAc,EACd,yBAAyB,EACzB,YAAY,EACZ,YAAY,EACZ,4BAA4B,EAC5B,sBAAsB,EACvB,0BAAsB;AAiBvB;;GAEG;AACH,MAAM,8BAA8B,GAClC,yBAAyB,CAAC,SAAS,EAAkB,CAAC;AACxD;;GAEG;AACH,MAAM,oBAAoB,GAAG,eAAe,CAAC,SAAS,EAAkB,CAAC;AAUzE,MAAM,kCAAkC,GAAG,CACzC,mBAAgD,EAChD,OAA2C,EAC3C,OAAgD,EAClC,EAAE;IAChB,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,EAAE;QACxB,OAAO,EAAE,CAAC;KACX;IACD,+DAA+D;IAC/D,MAAM,OAAO,GAAG,sBAAsB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACzD,IAAI,CAAC,OAAO,EAAE;QACZ,OAAO,EAAE,CAAC;KACX;IAED,MAAM,EAAE,kBAAkB,EAAE,aAAa,EAAE,UAAU,EAAE,eAAe,EAAE,GACtE,mBAAmB,CAAC;IAEtB,2EAA2E;IAC3E,mFAA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IACjB,eAAe,GAAG,iBAAiB,GAAG,WAAW,CACpD,CACJ,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,8BAA8B,CAAC;IAC/D,YAAY,EAAE,wBAAwB;IACtC,gBAAgB,EAAE,sBAAsB;IACxC,WAAW,EAAE,iBAAiB;IAC9B,mBAAmB,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,iBAAiB;IACvD,SAAS,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,mBAAmB,KAAK,aAAa,CAAC,OAAO;IACzE,eAAe,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,eAAe;IACjD,kBAAkB,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,kBAAkB;IACvD,uBAAuB,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,qBAAqB;IAC/D,qBAAqB,EAAE,2BAA2B;CACnD,CAAC,CAAC","sourcesContent":["import { AddressZero } from '@ethersproject/constants';\nimport type {\n CurrencyRateState,\n MultichainAssetsRatesControllerState,\n TokenRatesControllerState,\n} from '@metamask/assets-controllers';\nimport type { GasFeeEstimates } from '@metamask/gas-fee-controller';\nimport type { CaipAssetType } from '@metamask/utils';\nimport { isStrictHexString } from '@metamask/utils';\nimport { orderBy } from 'lodash';\nimport {\n createSelector as createSelector_,\n createStructuredSelector as createStructuredSelector_,\n} from 'reselect';\n\nimport { BRIDGE_PREFERRED_GAS_ESTIMATE } from './constants/bridge';\nimport type {\n BridgeControllerState,\n BridgeFeatureFlagsKey,\n ExchangeRate,\n GenericQuoteRequest,\n QuoteMetadata,\n QuoteResponse,\n} from './types';\nimport { RequestStatus, SortOrder } from './types';\nimport {\n getNativeAssetForChainId,\n isNativeAddress,\n isSolanaChainId,\n} from './utils/bridge';\nimport {\n formatAddressToAssetId,\n formatChainIdToCaip,\n formatChainIdToHex,\n} from './utils/caip-formatters';\nimport {\n calcAdjustedReturn,\n calcCost,\n calcEstimatedAndMaxTotalGasFee,\n calcRelayerFee,\n calcSentAmount,\n calcSolanaTotalNetworkFee,\n calcSwapRate,\n calcToAmount,\n calcTotalEstimatedNetworkFee,\n calcTotalMaxNetworkFee,\n} from './utils/quote';\n\n/**\n * The controller states that provide exchange rates\n */\ntype ExchangeRateControllerState = MultichainAssetsRatesControllerState &\n TokenRatesControllerState &\n CurrencyRateState &\n Pick<BridgeControllerState, 'assetExchangeRates'>;\n/**\n * The state of the bridge controller and all its dependency controllers\n */\nexport type BridgeAppState = BridgeControllerState & {\n gasFeeEstimates: GasFeeEstimates;\n} & ExchangeRateControllerState & {\n participateInMetaMetrics: boolean;\n };\n/**\n * Creates a structured selector for the bridge controller\n */\nconst createStructuredBridgeSelector =\n createStructuredSelector_.withTypes<BridgeAppState>();\n/**\n * Creates a typed selector for the bridge controller\n */\nconst createBridgeSelector = createSelector_.withTypes<BridgeAppState>();\n/**\n * Required parameters that clients must provide for the bridge quotes selector\n */\ntype BridgeQuotesClientParams = {\n sortOrder: SortOrder;\n selectedQuote: (QuoteResponse & QuoteMetadata) | null;\n featureFlagsKey: BridgeFeatureFlagsKey;\n};\n\nconst getExchangeRateByChainIdAndAddress = (\n exchangeRateSources: ExchangeRateControllerState,\n chainId?: GenericQuoteRequest['srcChainId'],\n address?: GenericQuoteRequest['srcTokenAddress'],\n): ExchangeRate => {\n if (!chainId || !address) {\n return {};\n }\n // TODO return usd exchange rate if user has opted into metrics\n const assetId = formatAddressToAssetId(address, chainId);\n if (!assetId) {\n return {};\n }\n\n const { assetExchangeRates, currencyRates, marketData, conversionRates } =\n exchangeRateSources;\n\n // If the asset exchange rate is available in the bridge controller, use it\n // This is defined if the token's rate is not available from the assets controllers\n const bridgeControllerRate =\n assetExchangeRates?.[assetId] ??\n assetExchangeRates?.[assetId.toLowerCase() as CaipAssetType];\n if (bridgeControllerRate?.exchangeRate) {\n return bridgeControllerRate;\n }\n // If the chain is a Solana chain, use the conversion rate from the multichain assets controller\n if (isSolanaChainId(chainId)) {\n const multichainAssetExchangeRate = conversionRates?.[assetId];\n if (multichainAssetExchangeRate) {\n return {\n exchangeRate: multichainAssetExchangeRate.rate,\n usdExchangeRate: undefined,\n };\n }\n return {};\n }\n // If the chain is an EVM chain, use the conversion rate from the currency rates controller\n if (isNativeAddress(address)) {\n const { symbol } = getNativeAssetForChainId(chainId);\n const evmNativeExchangeRate = currencyRates?.[symbol.toLowerCase()];\n if (evmNativeExchangeRate) {\n return {\n exchangeRate: evmNativeExchangeRate?.conversionRate?.toString(),\n usdExchangeRate: evmNativeExchangeRate?.usdConversionRate?.toString(),\n };\n }\n return {};\n }\n // If the chain is an EVM chain and the asset is not the native asset, use the conversion rate from the token rates controller\n const evmTokenExchangeRates = marketData?.[formatChainIdToHex(chainId)];\n const evmTokenExchangeRateForAddress = isStrictHexString(address)\n ? evmTokenExchangeRates?.[address]\n : null;\n if (evmTokenExchangeRateForAddress) {\n return {\n exchangeRate: evmTokenExchangeRateForAddress?.price.toString(),\n usdExchangeRate: undefined,\n };\n }\n\n return {};\n};\n\n/**\n * Selects the asset exchange rate for a given chain and address\n *\n * @param state The state of the bridge controller and its dependency controllers\n * @param chainId The chain ID of the asset\n * @param address The address of the asset\n * @returns The asset exchange rate for the given chain and address\n */\nexport const selectExchangeRateByChainIdAndAddress = (\n state: BridgeAppState,\n chainId?: GenericQuoteRequest['srcChainId'],\n address?: GenericQuoteRequest['srcTokenAddress'],\n) => {\n return getExchangeRateByChainIdAndAddress(state, chainId, address);\n};\n\n/**\n * Checks whether an exchange rate is available for a given chain and address\n *\n * @param params The parameters to pass to {@link getExchangeRateByChainIdAndAddress}\n * @returns Whether an exchange rate is available for the given chain and address\n */\nexport const selectIsAssetExchangeRateInState = (\n ...params: Parameters<typeof getExchangeRateByChainIdAndAddress>\n) => Boolean(getExchangeRateByChainIdAndAddress(...params)?.exchangeRate);\n\n/**\n * Selects the gas fee estimates from the gas fee controller. All potential networks\n * support EIP1559 gas fees so assume that gasFeeEstimates is of type GasFeeEstimates\n *\n * @returns The gas fee estimates in decGWEI\n */\nconst selectBridgeFeesPerGas = createStructuredBridgeSelector({\n estimatedBaseFeeInDecGwei: ({ gasFeeEstimates }) =>\n gasFeeEstimates?.estimatedBaseFee,\n maxPriorityFeePerGasInDecGwei: ({ gasFeeEstimates }) =>\n gasFeeEstimates?.[BRIDGE_PREFERRED_GAS_ESTIMATE]\n ?.suggestedMaxPriorityFeePerGas,\n maxFeePerGasInDecGwei: ({ gasFeeEstimates }) =>\n gasFeeEstimates?.high?.suggestedMaxFeePerGas,\n});\n\n// Selects cross-chain swap quotes including their metadata\nconst selectBridgeQuotesWithMetadata = createBridgeSelector(\n [\n ({ quotes }) => quotes,\n selectBridgeFeesPerGas,\n createBridgeSelector(\n [\n (state) => state,\n ({ quoteRequest: { srcChainId } }) => srcChainId,\n ({ quoteRequest: { srcTokenAddress } }) => srcTokenAddress,\n ],\n selectExchangeRateByChainIdAndAddress,\n ),\n createBridgeSelector(\n [\n (state) => state,\n ({ quoteRequest: { destChainId } }) => destChainId,\n ({ quoteRequest: { destTokenAddress } }) => destTokenAddress,\n ],\n selectExchangeRateByChainIdAndAddress,\n ),\n createBridgeSelector(\n [(state) => state, ({ quoteRequest: { srcChainId } }) => srcChainId],\n (state, chainId) =>\n selectExchangeRateByChainIdAndAddress(state, chainId, AddressZero),\n ),\n ],\n (\n quotes,\n bridgeFeesPerGas,\n srcTokenExchangeRate,\n destTokenExchangeRate,\n nativeExchangeRate,\n ) => {\n const newQuotes = quotes.map((quote) => {\n const sentAmount = calcSentAmount(quote.quote, srcTokenExchangeRate);\n const toTokenAmount = calcToAmount(quote.quote, destTokenExchangeRate);\n\n let totalEstimatedNetworkFee, gasFee, totalMaxNetworkFee, relayerFee;\n\n if (isSolanaChainId(quote.quote.srcChainId)) {\n totalEstimatedNetworkFee = calcSolanaTotalNetworkFee(\n quote,\n nativeExchangeRate,\n );\n gasFee = totalEstimatedNetworkFee;\n totalMaxNetworkFee = totalEstimatedNetworkFee;\n } else {\n relayerFee = calcRelayerFee(quote, nativeExchangeRate);\n gasFee = calcEstimatedAndMaxTotalGasFee({\n bridgeQuote: quote,\n ...bridgeFeesPerGas,\n ...nativeExchangeRate,\n });\n totalEstimatedNetworkFee = calcTotalEstimatedNetworkFee(\n gasFee,\n relayerFee,\n );\n totalMaxNetworkFee = calcTotalMaxNetworkFee(gasFee, relayerFee);\n }\n\n const adjustedReturn = calcAdjustedReturn(\n toTokenAmount,\n totalEstimatedNetworkFee,\n );\n const cost = calcCost(adjustedReturn, sentAmount);\n\n return {\n ...quote,\n // QuoteMetadata fields\n sentAmount,\n toTokenAmount,\n swapRate: calcSwapRate(sentAmount.amount, toTokenAmount.amount),\n totalNetworkFee: totalEstimatedNetworkFee,\n totalMaxNetworkFee,\n gasFee,\n adjustedReturn,\n cost,\n };\n });\n\n return newQuotes;\n },\n);\n\nconst selectSortedBridgeQuotes = createBridgeSelector(\n [\n selectBridgeQuotesWithMetadata,\n (_, { sortOrder }: BridgeQuotesClientParams) => sortOrder,\n ],\n (quotesWithMetadata, sortOrder): (QuoteResponse & QuoteMetadata)[] => {\n switch (sortOrder) {\n case SortOrder.ETA_ASC:\n return orderBy(\n quotesWithMetadata,\n (quote) => quote.estimatedProcessingTimeInSeconds,\n 'asc',\n );\n default:\n return orderBy(\n quotesWithMetadata,\n ({ cost }) =>\n cost.valueInCurrency ? Number(cost.valueInCurrency) : 0,\n 'asc',\n );\n }\n },\n);\n\nconst selectRecommendedQuote = createBridgeSelector(\n [selectSortedBridgeQuotes],\n ([recommendedQuote]) => recommendedQuote,\n);\n\nconst selectActiveQuote = createBridgeSelector(\n [\n selectRecommendedQuote,\n (_, { selectedQuote }: BridgeQuotesClientParams) => selectedQuote,\n ],\n (recommendedQuote, selectedQuote) => selectedQuote ?? recommendedQuote,\n);\n\nconst selectIsQuoteGoingToRefresh = (\n state: BridgeAppState,\n { featureFlagsKey }: BridgeQuotesClientParams,\n) =>\n state.quoteRequest.insufficientBal\n ? false\n : state.quotesRefreshCount <\n state.bridgeFeatureFlags[featureFlagsKey].maxRefreshCount;\n\nconst selectQuoteRefreshRate = createBridgeSelector(\n [\n ({ bridgeFeatureFlags }, { featureFlagsKey }: BridgeQuotesClientParams) =>\n bridgeFeatureFlags[featureFlagsKey],\n (state) => state.quoteRequest.srcChainId,\n ],\n (featureFlags, srcChainId) =>\n (srcChainId\n ? featureFlags.chains[formatChainIdToCaip(srcChainId)]?.refreshRate\n : featureFlags.refreshRate) ?? featureFlags.refreshRate,\n);\n\nexport const selectIsQuoteExpired = createBridgeSelector(\n [\n selectIsQuoteGoingToRefresh,\n ({ quotesLastFetched }) => quotesLastFetched,\n selectQuoteRefreshRate,\n (_, __, currentTimeInMs: number) => currentTimeInMs,\n ],\n (isQuoteGoingToRefresh, quotesLastFetched, refreshRate, currentTimeInMs) =>\n Boolean(\n !isQuoteGoingToRefresh &&\n quotesLastFetched &&\n currentTimeInMs - quotesLastFetched > refreshRate,\n ),\n);\n\n/**\n * Selects sorted cross-chain swap quotes. By default, the quotes are sorted by cost in ascending order.\n *\n * @param state - The state of the bridge controller and its dependency controllers\n * @param sortOrder - The sort order of the quotes\n * @param selectedQuote - The quote that is currently selected by the user, should be cleared by clients when the req params change\n * @param featureFlagsKey - The feature flags key for the client (e.g. `BridgeFeatureFlagsKey.EXTENSION_CONFIG`\n * @returns The activeQuote, recommendedQuote, sortedQuotes, and other quote fetching metadata\n *\n * @example\n * ```ts\n * const quotes = useSelector(state => selectBridgeQuotes(\n * state.metamask,\n * {\n * sortOrder: state.bridge.sortOrder,\n * selectedQuote: state.bridge.selectedQuote,\n * featureFlagsKey: BridgeFeatureFlagsKey.EXTENSION_CONFIG,\n * }\n * ));\n * ```\n */\nexport const selectBridgeQuotes = createStructuredBridgeSelector({\n sortedQuotes: selectSortedBridgeQuotes,\n recommendedQuote: selectRecommendedQuote,\n activeQuote: selectActiveQuote,\n quotesLastFetchedMs: (state) => state.quotesLastFetched,\n isLoading: (state) => state.quotesLoadingStatus === RequestStatus.LOADING,\n quoteFetchError: (state) => state.quoteFetchError,\n quotesRefreshCount: (state) => state.quotesRefreshCount,\n quotesInitialLoadTimeMs: (state) => state.quotesInitialLoadTime,\n isQuoteGoingToRefresh: selectIsQuoteGoingToRefresh,\n});\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAsCA;;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;AAwCD;;GAEG;AACH,IAAY,SAGX;AAHD,WAAY,SAAS;IACnB,wCAA2B,CAAA;IAC3B,wCAA2B,CAAA;AAC7B,CAAC,EAHW,SAAS,yBAAT,SAAS,QAGpB;AAuDD,IAAY,UAGX;AAHD,WAAY,UAAU;IACpB,mDAAqC,CAAA;IACrC,6CAA+B,CAAA;AACjC,CAAC,EAHW,UAAU,0BAAV,UAAU,QAGrB;AA6DD,IAAY,WAIX;AAJD,WAAY,WAAW;IACrB,gCAAiB,CAAA;IACjB,4BAAa,CAAA;IACb,gCAAiB,CAAA;AACnB,CAAC,EAJW,WAAW,2BAAX,WAAW,QAItB;AAuCD,IAAY,OAWX;AAXD,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;AAC3B,CAAC,EAXW,OAAO,uBAAP,OAAO,QAWlB;AAED,IAAY,OAGX;AAHD,WAAY,OAAO;IACjB,oCAAyB,CAAA;IACzB,4BAAiB,CAAA;AACnB,CAAC,EAHW,OAAO,uBAAP,OAAO,QAGlB;AAaD,IAAY,qBAGX;AAHD,WAAY,qBAAqB;IAC/B,6DAAoC,CAAA;IACpC,uDAA8B,CAAA;AAChC,CAAC,EAHW,qBAAqB,qCAArB,qBAAqB,QAGhC;AAaD,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,sBAIX;AAJD,WAAY,sBAAsB;IAChC,qEAA2C,CAAA;IAC3C,oDAA0B,CAAA;IAC1B,gFAAsD,CAAA;AACxD,CAAC,EAJW,sBAAsB,sCAAtB,sBAAsB,QAIjC","sourcesContent":["import type { AccountsControllerGetSelectedMultichainAccountAction } from '@metamask/accounts-controller';\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 { HandleSnapRequest } from '@metamask/snaps-controllers';\nimport type {\n CaipAccountId,\n CaipAssetId,\n CaipChainId,\n Hex,\n} from '@metamask/utils';\nimport type { BigNumber } from 'bignumber.js';\n\nimport type { BridgeController } from './bridge-controller';\nimport type { BRIDGE_CONTROLLER_NAME } from './constants/bridge';\n\n/**\n * Additional options accepted by the extension's fetchWithCache function\n */\ntype FetchWithCacheOptions = {\n cacheOptions?: {\n cacheRefreshTime: number;\n };\n functionName?: string;\n};\n\nexport type FetchFunction = (\n input: RequestInfo | URL,\n init?: RequestInit & FetchWithCacheOptions,\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 = {\n isActiveSrc: boolean;\n isActiveDest: boolean;\n refreshRate?: number;\n topAssets?: string[];\n};\n\nexport type L1GasFees = {\n l1GasFeesInHexWei?: string; // l1 fees for approval and trade in hex wei, appended by BridgeController.#appendL1GasFees\n};\n\nexport type SolanaFees = {\n solanaFeesInLamports?: string; // solana fees in lamports, appended by BridgeController.#appendSolanaFees\n};\n\n/**\n * valueInCurrency values are calculated based on the user's selected currency\n */\nexport type TokenAmountValues = {\n amount: BigNumber;\n valueInCurrency: BigNumber | null;\n usd: BigNumber | null;\n};\n\n/**\n * Values derived from the quote response\n */\nexport type QuoteMetadata = {\n gasFee: TokenAmountValues;\n totalNetworkFee: TokenAmountValues; // estimatedGasFees + relayerFees\n totalMaxNetworkFee: TokenAmountValues; // maxGasFees + relayerFees\n toTokenAmount: TokenAmountValues;\n adjustedReturn: Omit<TokenAmountValues, 'amount'>; // destTokenAmount - totalNetworkFee\n sentAmount: TokenAmountValues; // srcTokenAmount + metabridgeFee\n swapRate: BigNumber; // 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 = {\n /**\n * The chainId of the token\n */\n chainId: ChainId;\n /**\n * An address that the metaswap-api recognizes as the default token\n */\n address: string;\n /**\n * The symbol of token object\n */\n symbol: string;\n /**\n * The name for the network\n */\n name: string;\n /**\n * Number of digits after decimal point\n */\n decimals: number;\n icon?: string;\n /**\n * URL for token icon\n */\n iconUrl?: string;\n /**\n * The assetId of the token\n */\n assetId: string;\n};\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\nexport enum BridgeFlag {\n EXTENSION_CONFIG = 'extension-config',\n MOBILE_CONFIG = 'mobile-config',\n}\ntype DecimalChainId = string;\nexport type GasMultiplierByChainId = Record<DecimalChainId, number>;\n\ntype FeatureFlagResponsePlatformConfig = {\n refreshRate: number;\n maxRefreshCount: number;\n support: boolean;\n chains: Record<string, ChainConfiguration>;\n};\n\nexport type FeatureFlagResponse = {\n [BridgeFlag.EXTENSION_CONFIG]: FeatureFlagResponsePlatformConfig;\n [BridgeFlag.MOBILE_CONFIG]: FeatureFlagResponsePlatformConfig;\n};\n\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\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 = {\n name: string;\n displayName?: string;\n icon?: string;\n};\n\nexport enum ActionTypes {\n BRIDGE = 'bridge',\n SWAP = 'swap',\n REFUEL = 'refuel',\n}\n\nexport type Step = {\n action: ActionTypes;\n srcChainId: ChainId;\n destChainId?: ChainId;\n srcAsset: BridgeAsset;\n destAsset: BridgeAsset;\n srcAmount: string;\n destAmount: string;\n protocol: Protocol;\n};\n\nexport type RefuelData = Step;\n\nexport type Quote = {\n requestId: string;\n srcChainId: ChainId;\n srcAsset: BridgeAsset;\n // Some tokens have a fee of 0, so sometimes it's equal to amount sent\n srcTokenAmount: string; // Atomic amount, the amount sent - fees\n destChainId: ChainId;\n destAsset: BridgeAsset;\n destTokenAmount: string; // Atomic amount, the amount received\n feeData: Record<FeeType.METABRIDGE, FeeData> &\n Partial<Record<FeeType, FeeData>>;\n bridgeId: string;\n bridges: string[];\n steps: Step[];\n refuel?: RefuelData;\n};\n\nexport type QuoteResponse = {\n quote: Quote;\n approval?: TxData | null;\n trade: TxData;\n estimatedProcessingTimeInSeconds: number;\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}\n\nexport enum FeeType {\n METABRIDGE = 'metabridge',\n REFUEL = 'refuel',\n}\nexport type FeeData = {\n amount: string;\n asset: BridgeAsset;\n};\nexport type TxData = {\n chainId: ChainId;\n to: string;\n from: string;\n value: string;\n data: string;\n gasLimit: number | null;\n};\nexport enum BridgeFeatureFlagsKey {\n EXTENSION_CONFIG = 'extensionConfig',\n MOBILE_CONFIG = 'mobileConfig',\n}\n\ntype FeatureFlagsPlatformConfig = {\n refreshRate: number;\n maxRefreshCount: number;\n support: boolean;\n chains: Record<CaipChainId, ChainConfiguration>;\n};\n\nexport type BridgeFeatureFlags = {\n [BridgeFeatureFlagsKey.EXTENSION_CONFIG]: FeatureFlagsPlatformConfig;\n [BridgeFeatureFlagsKey.MOBILE_CONFIG]: FeatureFlagsPlatformConfig;\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_FEATURE_FLAGS = 'setBridgeFeatureFlags',\n RESET_STATE = 'resetState',\n GET_BRIDGE_ERC20_ALLOWANCE = 'getBridgeERC20Allowance',\n}\n\nexport type BridgeControllerState = {\n bridgeFeatureFlags: BridgeFeatureFlags;\n quoteRequest: Partial<GenericQuoteRequest>;\n quotes: (QuoteResponse & L1GasFees & SolanaFees)[];\n quotesInitialLoadTime: number | null;\n quotesLastFetched: number | null;\n quotesLoadingStatus: RequestStatus | null;\n quoteFetchError: string | null;\n quotesRefreshCount: number;\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_FEATURE_FLAGS>\n | BridgeControllerAction<BridgeBackgroundAction.RESET_STATE>\n | BridgeControllerAction<BridgeBackgroundAction.GET_BRIDGE_ERC20_ALLOWANCE>\n | BridgeControllerAction<BridgeUserAction.UPDATE_QUOTE_PARAMS>;\n\nexport type BridgeControllerEvents = ControllerStateChangeEvent<\n typeof BRIDGE_CONTROLLER_NAME,\n BridgeControllerState\n>;\n\nexport type AllowedActions =\n | AccountsControllerGetSelectedMultichainAccountAction\n | HandleSnapRequest\n | NetworkControllerFindNetworkClientIdByChainIdAction\n | NetworkControllerGetStateAction\n | NetworkControllerGetNetworkClientByIdAction;\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":";;;AA2CA;;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;AA4DD;;GAEG;AACH,IAAY,SAGX;AAHD,WAAY,SAAS;IACnB,wCAA2B,CAAA;IAC3B,wCAA2B,CAAA;AAC7B,CAAC,EAHW,SAAS,yBAAT,SAAS,QAGpB;AAuDD,IAAY,UAGX;AAHD,WAAY,UAAU;IACpB,mDAAqC,CAAA;IACrC,6CAA+B,CAAA;AACjC,CAAC,EAHW,UAAU,0BAAV,UAAU,QAGrB;AA6DD,IAAY,WAIX;AAJD,WAAY,WAAW;IACrB,gCAAiB,CAAA;IACjB,4BAAa,CAAA;IACb,gCAAiB,CAAA;AACnB,CAAC,EAJW,WAAW,2BAAX,WAAW,QAItB;AA2CD,IAAY,OAWX;AAXD,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;AAC3B,CAAC,EAXW,OAAO,uBAAP,OAAO,QAWlB;AAED,IAAY,OAGX;AAHD,WAAY,OAAO;IACjB,oCAAyB,CAAA;IACzB,4BAAiB,CAAA;AACnB,CAAC,EAHW,OAAO,uBAAP,OAAO,QAGlB;AAaD,IAAY,qBAGX;AAHD,WAAY,qBAAqB;IAC/B,6DAAoC,CAAA;IACpC,uDAA8B,CAAA;AAChC,CAAC,EAHW,qBAAqB,qCAArB,qBAAqB,QAGhC;AAaD,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,sBAIX;AAJD,WAAY,sBAAsB;IAChC,qEAA2C,CAAA;IAC3C,oDAA0B,CAAA;IAC1B,gFAAsD,CAAA;AACxD,CAAC,EAJW,sBAAsB,sCAAtB,sBAAsB,QAIjC","sourcesContent":["import type { AccountsControllerGetSelectedMultichainAccountAction } 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 { HandleSnapRequest } from '@metamask/snaps-controllers';\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';\n\n/**\n * Additional options accepted by the extension's fetchWithCache function\n */\ntype FetchWithCacheOptions = {\n cacheOptions?: {\n cacheRefreshTime: number;\n };\n functionName?: string;\n};\n\nexport type FetchFunction = (\n input: RequestInfo | URL,\n init?: RequestInit & FetchWithCacheOptions,\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 = {\n isActiveSrc: boolean;\n isActiveDest: boolean;\n refreshRate?: number;\n topAssets?: string[];\n};\n\nexport type L1GasFees = {\n l1GasFeesInHexWei?: string; // l1 fees for approval and trade in hex wei, appended by BridgeController.#appendL1GasFees\n};\n\nexport type SolanaFees = {\n solanaFeesInLamports?: string; // solana fees in lamports, appended by BridgeController.#appendSolanaFees\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 gasFee: TokenAmountValues;\n totalNetworkFee: TokenAmountValues; // estimatedGasFees + relayerFees\n totalMaxNetworkFee: TokenAmountValues; // maxGasFees + relayerFees\n toTokenAmount: TokenAmountValues;\n adjustedReturn: Omit<TokenAmountValues, 'amount'>; // destTokenAmount - totalNetworkFee\n sentAmount: TokenAmountValues; // srcTokenAmount + metabridgeFee\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 = {\n /**\n * The chainId of the token\n */\n chainId: ChainId;\n /**\n * An address that the metaswap-api recognizes as the default token\n */\n address: string;\n /**\n * The symbol of token object\n */\n symbol: string;\n /**\n * The name for the network\n */\n name: string;\n /**\n * Number of digits after decimal point\n */\n decimals: number;\n icon?: string;\n /**\n * URL for token icon\n */\n iconUrl?: string;\n /**\n * The assetId of the token\n */\n assetId: CaipAssetType;\n};\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\nexport enum BridgeFlag {\n EXTENSION_CONFIG = 'extension-config',\n MOBILE_CONFIG = 'mobile-config',\n}\ntype DecimalChainId = string;\nexport type GasMultiplierByChainId = Record<DecimalChainId, number>;\n\ntype FeatureFlagResponsePlatformConfig = {\n refreshRate: number;\n maxRefreshCount: number;\n support: boolean;\n chains: Record<string, ChainConfiguration>;\n};\n\nexport type FeatureFlagResponse = {\n [BridgeFlag.EXTENSION_CONFIG]: FeatureFlagResponsePlatformConfig;\n [BridgeFlag.MOBILE_CONFIG]: FeatureFlagResponsePlatformConfig;\n};\n\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\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 = {\n name: string;\n displayName?: string;\n icon?: string;\n};\n\nexport enum ActionTypes {\n BRIDGE = 'bridge',\n SWAP = 'swap',\n REFUEL = 'refuel',\n}\n\nexport type Step = {\n action: ActionTypes;\n srcChainId: ChainId;\n destChainId?: ChainId;\n srcAsset?: BridgeAsset;\n destAsset?: BridgeAsset;\n srcAmount: string;\n destAmount: string;\n protocol: Protocol;\n};\n\nexport type RefuelData = Step;\n\nexport type Quote = {\n requestId: string;\n srcChainId: ChainId;\n srcAsset: BridgeAsset;\n // Some tokens have a fee of 0, so sometimes it's equal to amount sent\n srcTokenAmount: string; // Atomic amount, the amount sent - fees\n destChainId: ChainId;\n destAsset: BridgeAsset;\n destTokenAmount: string; // Atomic amount, the amount received\n feeData: Record<FeeType.METABRIDGE, FeeData> &\n Partial<Record<FeeType, FeeData>>;\n bridgeId: string;\n bridges: string[];\n steps: Step[];\n refuel?: RefuelData;\n};\n\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<TradeType = TxData, ApprovalType = TxData | null> = {\n quote: Quote;\n approval?: ApprovalType;\n trade: TradeType;\n estimatedProcessingTimeInSeconds: number;\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}\n\nexport enum FeeType {\n METABRIDGE = 'metabridge',\n REFUEL = 'refuel',\n}\nexport type FeeData = {\n amount: string;\n asset: BridgeAsset;\n};\nexport type TxData = {\n chainId: ChainId;\n to: string;\n from: string;\n value: string;\n data: string;\n gasLimit: number | null;\n};\nexport enum BridgeFeatureFlagsKey {\n EXTENSION_CONFIG = 'extensionConfig',\n MOBILE_CONFIG = 'mobileConfig',\n}\n\ntype FeatureFlagsPlatformConfig = {\n refreshRate: number;\n maxRefreshCount: number;\n support: boolean;\n chains: Record<CaipChainId, ChainConfiguration>;\n};\n\nexport type BridgeFeatureFlags = {\n [BridgeFeatureFlagsKey.EXTENSION_CONFIG]: FeatureFlagsPlatformConfig;\n [BridgeFeatureFlagsKey.MOBILE_CONFIG]: FeatureFlagsPlatformConfig;\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_FEATURE_FLAGS = 'setBridgeFeatureFlags',\n RESET_STATE = 'resetState',\n GET_BRIDGE_ERC20_ALLOWANCE = 'getBridgeERC20Allowance',\n}\n\nexport type BridgeControllerState = {\n bridgeFeatureFlags: BridgeFeatureFlags;\n quoteRequest: Partial<GenericQuoteRequest>;\n quotes: (QuoteResponse & L1GasFees & SolanaFees)[];\n quotesInitialLoadTime: number | null;\n quotesLastFetched: number | null;\n quotesLoadingStatus: RequestStatus | null;\n quoteFetchError: string | null;\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\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_FEATURE_FLAGS>\n | BridgeControllerAction<BridgeBackgroundAction.RESET_STATE>\n | BridgeControllerAction<BridgeBackgroundAction.GET_BRIDGE_ERC20_ALLOWANCE>\n | BridgeControllerAction<BridgeUserAction.UPDATE_QUOTE_PARAMS>;\n\nexport type BridgeControllerEvents = ControllerStateChangeEvent<\n typeof BRIDGE_CONTROLLER_NAME,\n BridgeControllerState\n>;\n\nexport type AllowedActions =\n | AccountsControllerGetSelectedMultichainAccountAction\n | GetCurrencyRateState\n | TokenRatesControllerGetStateAction\n | MultichainAssetsRatesControllerGetStateAction\n | HandleSnapRequest\n | NetworkControllerFindNetworkClientIdByChainIdAction\n | NetworkControllerGetStateAction\n | NetworkControllerGetNetworkClientByIdAction;\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"]}
package/dist/types.d.cts CHANGED
@@ -1,9 +1,9 @@
1
1
  import type { AccountsControllerGetSelectedMultichainAccountAction } from "@metamask/accounts-controller";
2
+ import type { GetCurrencyRateState, MultichainAssetsRatesControllerGetStateAction, TokenRatesControllerGetStateAction } from "@metamask/assets-controllers";
2
3
  import type { ControllerStateChangeEvent, RestrictedMessenger } from "@metamask/base-controller";
3
4
  import type { NetworkControllerFindNetworkClientIdByChainIdAction, NetworkControllerGetStateAction, NetworkControllerGetNetworkClientByIdAction } from "@metamask/network-controller";
4
5
  import type { HandleSnapRequest } from "@metamask/snaps-controllers";
5
- import type { CaipAccountId, CaipAssetId, CaipChainId, Hex } from "@metamask/utils";
6
- import type { BigNumber } from "bignumber.js";
6
+ import type { CaipAccountId, CaipAssetId, CaipAssetType, CaipChainId, Hex } from "@metamask/utils";
7
7
  import type { BridgeController } from "./bridge-controller.cjs";
8
8
  import type { BRIDGE_CONTROLLER_NAME } from "./constants/bridge.cjs";
9
9
  /**
@@ -45,12 +45,34 @@ export type SolanaFees = {
45
45
  solanaFeesInLamports?: string;
46
46
  };
47
47
  /**
48
- * valueInCurrency values are calculated based on the user's selected currency
48
+ * The types of values for the token amount and its values when converted to the user's selected currency and USD
49
49
  */
50
50
  export type TokenAmountValues = {
51
- amount: BigNumber;
52
- valueInCurrency: BigNumber | null;
53
- usd: BigNumber | null;
51
+ /**
52
+ * The amount of the token
53
+ *
54
+ * @example "1000000000000000000"
55
+ */
56
+ amount: string;
57
+ /**
58
+ * The amount of the token in the user's selected currency
59
+ *
60
+ * @example "4.55"
61
+ */
62
+ valueInCurrency: string | null;
63
+ /**
64
+ * The amount of the token in USD
65
+ *
66
+ * @example "1.234"
67
+ */
68
+ usd: string | null;
69
+ };
70
+ /**
71
+ * Asset exchange rate values for a given chain and address
72
+ */
73
+ export type ExchangeRate = {
74
+ exchangeRate?: string;
75
+ usdExchangeRate?: string;
54
76
  };
55
77
  /**
56
78
  * Values derived from the quote response
@@ -62,7 +84,7 @@ export type QuoteMetadata = {
62
84
  toTokenAmount: TokenAmountValues;
63
85
  adjustedReturn: Omit<TokenAmountValues, 'amount'>;
64
86
  sentAmount: TokenAmountValues;
65
- swapRate: BigNumber;
87
+ swapRate: string;
66
88
  cost: Omit<TokenAmountValues, 'amount'>;
67
89
  };
68
90
  /**
@@ -105,7 +127,7 @@ export type BridgeAsset = {
105
127
  /**
106
128
  * The assetId of the token
107
129
  */
108
- assetId: string;
130
+ assetId: CaipAssetType;
109
131
  };
110
132
  /**
111
133
  * This is the interface for the token object used in the extension client
@@ -184,8 +206,8 @@ export type Step = {
184
206
  action: ActionTypes;
185
207
  srcChainId: ChainId;
186
208
  destChainId?: ChainId;
187
- srcAsset: BridgeAsset;
188
- destAsset: BridgeAsset;
209
+ srcAsset?: BridgeAsset;
210
+ destAsset?: BridgeAsset;
189
211
  srcAmount: string;
190
212
  destAmount: string;
191
213
  protocol: Protocol;
@@ -205,10 +227,14 @@ export type Quote = {
205
227
  steps: Step[];
206
228
  refuel?: RefuelData;
207
229
  };
208
- export type QuoteResponse = {
230
+ /**
231
+ * This is the type for the quote response from the bridge-api
232
+ * TxDataType can be overriden to be a string when the quote is non-evm
233
+ */
234
+ export type QuoteResponse<TradeType = TxData, ApprovalType = TxData | null> = {
209
235
  quote: Quote;
210
- approval?: TxData | null;
211
- trade: TxData;
236
+ approval?: ApprovalType;
237
+ trade: TradeType;
212
238
  estimatedProcessingTimeInSeconds: number;
213
239
  };
214
240
  export declare enum ChainId {
@@ -276,6 +302,10 @@ export type BridgeControllerState = {
276
302
  quotesLoadingStatus: RequestStatus | null;
277
303
  quoteFetchError: string | null;
278
304
  quotesRefreshCount: number;
305
+ /**
306
+ * Asset exchange rates for EVM and multichain assets that are not indexed by the assets controllers
307
+ */
308
+ assetExchangeRates: Record<CaipAssetType, ExchangeRate>;
279
309
  };
280
310
  export type BridgeControllerAction<FunctionName extends keyof BridgeController> = {
281
311
  type: `${typeof BRIDGE_CONTROLLER_NAME}:${FunctionName}`;
@@ -283,7 +313,7 @@ export type BridgeControllerAction<FunctionName extends keyof BridgeController>
283
313
  };
284
314
  export type BridgeControllerActions = BridgeControllerAction<BridgeBackgroundAction.SET_FEATURE_FLAGS> | BridgeControllerAction<BridgeBackgroundAction.RESET_STATE> | BridgeControllerAction<BridgeBackgroundAction.GET_BRIDGE_ERC20_ALLOWANCE> | BridgeControllerAction<BridgeUserAction.UPDATE_QUOTE_PARAMS>;
285
315
  export type BridgeControllerEvents = ControllerStateChangeEvent<typeof BRIDGE_CONTROLLER_NAME, BridgeControllerState>;
286
- export type AllowedActions = AccountsControllerGetSelectedMultichainAccountAction | HandleSnapRequest | NetworkControllerFindNetworkClientIdByChainIdAction | NetworkControllerGetStateAction | NetworkControllerGetNetworkClientByIdAction;
316
+ export type AllowedActions = AccountsControllerGetSelectedMultichainAccountAction | GetCurrencyRateState | TokenRatesControllerGetStateAction | MultichainAssetsRatesControllerGetStateAction | HandleSnapRequest | NetworkControllerFindNetworkClientIdByChainIdAction | NetworkControllerGetStateAction | NetworkControllerGetNetworkClientByIdAction;
287
317
  export type AllowedEvents = never;
288
318
  /**
289
319
  * The messenger for the BridgeController.
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oDAAoD,EAAE,sCAAsC;AAC1G,OAAO,KAAK,EACV,0BAA0B,EAC1B,mBAAmB,EACpB,kCAAkC;AACnC,OAAO,KAAK,EACV,mDAAmD,EACnD,+BAA+B,EAC/B,2CAA2C,EAC5C,qCAAqC;AACtC,OAAO,KAAK,EAAE,iBAAiB,EAAE,oCAAoC;AACrE,OAAO,KAAK,EACV,aAAa,EACb,WAAW,EACX,WAAW,EACX,GAAG,EACJ,wBAAwB;AACzB,OAAO,KAAK,EAAE,SAAS,EAAE,qBAAqB;AAE9C,OAAO,KAAK,EAAE,gBAAgB,EAAE,gCAA4B;AAC5D,OAAO,KAAK,EAAE,sBAAsB,EAAE,+BAA2B;AAEjE;;GAEG;AACH,KAAK,qBAAqB,GAAG;IAC3B,YAAY,CAAC,EAAE;QACb,gBAAgB,EAAE,MAAM,CAAC;KAC1B,CAAC;IACF,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,CAC1B,KAAK,EAAE,WAAW,GAAG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F,IAAI,EAAE,GAAG,OAAO,sBAAsB,IAAI,YAAY,EAAE,CAAC;IACzD,OAAO,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAC;CACzC,CAAC;AAGF,MAAM,MAAM,uBAAuB,GAC/B,sBAAsB,CAAC,sBAAsB,CAAC,iBAAiB,CAAC,GAChE,sBAAsB,CAAC,sBAAsB,CAAC,WAAW,CAAC,GAC1D,sBAAsB,CAAC,sBAAsB,CAAC,0BAA0B,CAAC,GACzE,sBAAsB,CAAC,gBAAgB,CAAC,mBAAmB,CAAC,CAAC;AAEjE,MAAM,MAAM,sBAAsB,GAAG,0BAA0B,CAC7D,OAAO,sBAAsB,EAC7B,qBAAqB,CACtB,CAAC;AAEF,MAAM,MAAM,cAAc,GACtB,oDAAoD,GACpD,oBAAoB,GACpB,kCAAkC,GAClC,6CAA6C,GAC7C,iBAAiB,GACjB,mDAAmD,GACnD,+BAA+B,GAC/B,2CAA2C,CAAC;AAChD,MAAM,MAAM,aAAa,GAAG,KAAK,CAAC;AAElC;;GAEG;AACH,MAAM,MAAM,yBAAyB,GAAG,mBAAmB,CACzD,OAAO,sBAAsB,EAC7B,uBAAuB,GAAG,cAAc,EACxC,sBAAsB,GAAG,aAAa,EACtC,cAAc,CAAC,MAAM,CAAC,EACtB,aAAa,CAAC,MAAM,CAAC,CACtB,CAAC"}
package/dist/types.d.mts CHANGED
@@ -1,9 +1,9 @@
1
1
  import type { AccountsControllerGetSelectedMultichainAccountAction } from "@metamask/accounts-controller";
2
+ import type { GetCurrencyRateState, MultichainAssetsRatesControllerGetStateAction, TokenRatesControllerGetStateAction } from "@metamask/assets-controllers";
2
3
  import type { ControllerStateChangeEvent, RestrictedMessenger } from "@metamask/base-controller";
3
4
  import type { NetworkControllerFindNetworkClientIdByChainIdAction, NetworkControllerGetStateAction, NetworkControllerGetNetworkClientByIdAction } from "@metamask/network-controller";
4
5
  import type { HandleSnapRequest } from "@metamask/snaps-controllers";
5
- import type { CaipAccountId, CaipAssetId, CaipChainId, Hex } from "@metamask/utils";
6
- import type { BigNumber } from "bignumber.js";
6
+ import type { CaipAccountId, CaipAssetId, CaipAssetType, CaipChainId, Hex } from "@metamask/utils";
7
7
  import type { BridgeController } from "./bridge-controller.mjs";
8
8
  import type { BRIDGE_CONTROLLER_NAME } from "./constants/bridge.mjs";
9
9
  /**
@@ -45,12 +45,34 @@ export type SolanaFees = {
45
45
  solanaFeesInLamports?: string;
46
46
  };
47
47
  /**
48
- * valueInCurrency values are calculated based on the user's selected currency
48
+ * The types of values for the token amount and its values when converted to the user's selected currency and USD
49
49
  */
50
50
  export type TokenAmountValues = {
51
- amount: BigNumber;
52
- valueInCurrency: BigNumber | null;
53
- usd: BigNumber | null;
51
+ /**
52
+ * The amount of the token
53
+ *
54
+ * @example "1000000000000000000"
55
+ */
56
+ amount: string;
57
+ /**
58
+ * The amount of the token in the user's selected currency
59
+ *
60
+ * @example "4.55"
61
+ */
62
+ valueInCurrency: string | null;
63
+ /**
64
+ * The amount of the token in USD
65
+ *
66
+ * @example "1.234"
67
+ */
68
+ usd: string | null;
69
+ };
70
+ /**
71
+ * Asset exchange rate values for a given chain and address
72
+ */
73
+ export type ExchangeRate = {
74
+ exchangeRate?: string;
75
+ usdExchangeRate?: string;
54
76
  };
55
77
  /**
56
78
  * Values derived from the quote response
@@ -62,7 +84,7 @@ export type QuoteMetadata = {
62
84
  toTokenAmount: TokenAmountValues;
63
85
  adjustedReturn: Omit<TokenAmountValues, 'amount'>;
64
86
  sentAmount: TokenAmountValues;
65
- swapRate: BigNumber;
87
+ swapRate: string;
66
88
  cost: Omit<TokenAmountValues, 'amount'>;
67
89
  };
68
90
  /**
@@ -105,7 +127,7 @@ export type BridgeAsset = {
105
127
  /**
106
128
  * The assetId of the token
107
129
  */
108
- assetId: string;
130
+ assetId: CaipAssetType;
109
131
  };
110
132
  /**
111
133
  * This is the interface for the token object used in the extension client
@@ -184,8 +206,8 @@ export type Step = {
184
206
  action: ActionTypes;
185
207
  srcChainId: ChainId;
186
208
  destChainId?: ChainId;
187
- srcAsset: BridgeAsset;
188
- destAsset: BridgeAsset;
209
+ srcAsset?: BridgeAsset;
210
+ destAsset?: BridgeAsset;
189
211
  srcAmount: string;
190
212
  destAmount: string;
191
213
  protocol: Protocol;
@@ -205,10 +227,14 @@ export type Quote = {
205
227
  steps: Step[];
206
228
  refuel?: RefuelData;
207
229
  };
208
- export type QuoteResponse = {
230
+ /**
231
+ * This is the type for the quote response from the bridge-api
232
+ * TxDataType can be overriden to be a string when the quote is non-evm
233
+ */
234
+ export type QuoteResponse<TradeType = TxData, ApprovalType = TxData | null> = {
209
235
  quote: Quote;
210
- approval?: TxData | null;
211
- trade: TxData;
236
+ approval?: ApprovalType;
237
+ trade: TradeType;
212
238
  estimatedProcessingTimeInSeconds: number;
213
239
  };
214
240
  export declare enum ChainId {
@@ -276,6 +302,10 @@ export type BridgeControllerState = {
276
302
  quotesLoadingStatus: RequestStatus | null;
277
303
  quoteFetchError: string | null;
278
304
  quotesRefreshCount: number;
305
+ /**
306
+ * Asset exchange rates for EVM and multichain assets that are not indexed by the assets controllers
307
+ */
308
+ assetExchangeRates: Record<CaipAssetType, ExchangeRate>;
279
309
  };
280
310
  export type BridgeControllerAction<FunctionName extends keyof BridgeController> = {
281
311
  type: `${typeof BRIDGE_CONTROLLER_NAME}:${FunctionName}`;
@@ -283,7 +313,7 @@ export type BridgeControllerAction<FunctionName extends keyof BridgeController>
283
313
  };
284
314
  export type BridgeControllerActions = BridgeControllerAction<BridgeBackgroundAction.SET_FEATURE_FLAGS> | BridgeControllerAction<BridgeBackgroundAction.RESET_STATE> | BridgeControllerAction<BridgeBackgroundAction.GET_BRIDGE_ERC20_ALLOWANCE> | BridgeControllerAction<BridgeUserAction.UPDATE_QUOTE_PARAMS>;
285
315
  export type BridgeControllerEvents = ControllerStateChangeEvent<typeof BRIDGE_CONTROLLER_NAME, BridgeControllerState>;
286
- export type AllowedActions = AccountsControllerGetSelectedMultichainAccountAction | HandleSnapRequest | NetworkControllerFindNetworkClientIdByChainIdAction | NetworkControllerGetStateAction | NetworkControllerGetNetworkClientByIdAction;
316
+ export type AllowedActions = AccountsControllerGetSelectedMultichainAccountAction | GetCurrencyRateState | TokenRatesControllerGetStateAction | MultichainAssetsRatesControllerGetStateAction | HandleSnapRequest | NetworkControllerFindNetworkClientIdByChainIdAction | NetworkControllerGetStateAction | NetworkControllerGetNetworkClientByIdAction;
287
317
  export type AllowedEvents = never;
288
318
  /**
289
319
  * The messenger for the BridgeController.