@metamask-previews/bridge-controller 71.1.1-preview-9e2a7fac5 → 71.1.1-preview-8f8f607
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 +0 -10
- package/dist/bridge-controller.cjs +102 -150
- package/dist/bridge-controller.cjs.map +1 -1
- package/dist/bridge-controller.d.cts +4 -14
- package/dist/bridge-controller.d.cts.map +1 -1
- package/dist/bridge-controller.d.mts +4 -14
- package/dist/bridge-controller.d.mts.map +1 -1
- package/dist/bridge-controller.mjs +103 -151
- package/dist/bridge-controller.mjs.map +1 -1
- package/dist/constants/bridge.cjs +3 -5
- package/dist/constants/bridge.cjs.map +1 -1
- package/dist/constants/bridge.d.cts.map +1 -1
- package/dist/constants/bridge.d.mts.map +1 -1
- package/dist/constants/bridge.mjs +3 -5
- package/dist/constants/bridge.mjs.map +1 -1
- package/dist/constants/traces.cjs +0 -1
- package/dist/constants/traces.cjs.map +1 -1
- package/dist/constants/traces.d.cts +0 -1
- package/dist/constants/traces.d.cts.map +1 -1
- package/dist/constants/traces.d.mts +0 -1
- package/dist/constants/traces.d.mts.map +1 -1
- package/dist/constants/traces.mjs +0 -1
- package/dist/constants/traces.mjs.map +1 -1
- package/dist/index.cjs +2 -4
- 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 +2 -2
- package/dist/index.mjs.map +1 -1
- package/dist/selectors.cjs +33 -89
- package/dist/selectors.cjs.map +1 -1
- package/dist/selectors.d.cts +76 -7163
- package/dist/selectors.d.cts.map +1 -1
- package/dist/selectors.d.mts +76 -7163
- package/dist/selectors.d.mts.map +1 -1
- package/dist/selectors.mjs +32 -88
- package/dist/selectors.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +1 -6
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +1 -6
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/dist/utils/fetch.cjs +17 -61
- package/dist/utils/fetch.cjs.map +1 -1
- package/dist/utils/fetch.d.cts +4 -3
- package/dist/utils/fetch.d.cts.map +1 -1
- package/dist/utils/fetch.d.mts +4 -3
- package/dist/utils/fetch.d.mts.map +1 -1
- package/dist/utils/fetch.mjs +18 -62
- package/dist/utils/fetch.mjs.map +1 -1
- package/dist/utils/metrics/properties.cjs +1 -1
- package/dist/utils/metrics/properties.cjs.map +1 -1
- package/dist/utils/metrics/properties.mjs +1 -1
- package/dist/utils/metrics/properties.mjs.map +1 -1
- package/dist/utils/quote.cjs +1 -3
- package/dist/utils/quote.cjs.map +1 -1
- package/dist/utils/quote.d.cts +0 -1
- package/dist/utils/quote.d.cts.map +1 -1
- package/dist/utils/quote.d.mts +0 -1
- package/dist/utils/quote.d.mts.map +1 -1
- package/dist/utils/quote.mjs +0 -1
- package/dist/utils/quote.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -9,7 +9,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var _BridgeController_instances, _BridgeController_abortController, _BridgeController_quotesFirstFetched, _BridgeController_location, _BridgeController_clientId, _BridgeController_clientVersion, _BridgeController_getLayer1GasFee, _BridgeController_fetchFn, _BridgeController_trackMetaMetricsFn, _BridgeController_trace, _BridgeController_config, _BridgeController_getUseAssetsControllerForRates, _BridgeController_trackQuoteValidationFailures, _BridgeController_getExchangeRateSources, _BridgeController_fetchAssetExchangeRates, _BridgeController_hasInsufficientBalance,
|
|
12
|
+
var _BridgeController_instances, _BridgeController_abortController, _BridgeController_quotesFirstFetched, _BridgeController_location, _BridgeController_clientId, _BridgeController_clientVersion, _BridgeController_getLayer1GasFee, _BridgeController_fetchFn, _BridgeController_trackMetaMetricsFn, _BridgeController_trace, _BridgeController_config, _BridgeController_getUseAssetsControllerForRates, _BridgeController_trackQuoteValidationFailures, _BridgeController_getExchangeRateSources, _BridgeController_fetchAssetExchangeRates, _BridgeController_hasInsufficientBalance, _BridgeController_shouldResetApproval, _BridgeController_fetchBridgeQuotes, _BridgeController_handleQuoteStreaming, _BridgeController_setMinimumBalanceForRentExemptionInLamports, _BridgeController_getMultichainSelectedAccount, _BridgeController_getNetworkClientByChainId, _BridgeController_getJwt, _BridgeController_getRequestMetadata, _BridgeController_getQuoteFetchData, _BridgeController_getEventProperties, _BridgeController_trackInputChangedEvents, _BridgeController_getUSDTMainnetAllowance;
|
|
13
13
|
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
14
14
|
import { BigNumber } from "@ethersproject/bignumber";
|
|
15
15
|
import { Contract } from "@ethersproject/contracts";
|
|
@@ -30,7 +30,7 @@ import { getBridgeFeatureFlags, hasMinimumRequiredVersion } from "./utils/featur
|
|
|
30
30
|
import { fetchAssetPrices, fetchBridgeQuotes, fetchBridgeQuoteStream } from "./utils/fetch.mjs";
|
|
31
31
|
import { AbortReason, MetaMetricsSwapsEventSource, MetricsActionType, UnifiedSwapBridgeEventName } from "./utils/metrics/constants.mjs";
|
|
32
32
|
import { formatProviderLabel, getAccountHardwareType, getRequestParams, getSwapTypeFromQuote, isCustomSlippage, toInputChangedPropertyKey, toInputChangedPropertyValue } from "./utils/metrics/properties.mjs";
|
|
33
|
-
import { isValidQuoteRequest,
|
|
33
|
+
import { isValidQuoteRequest, sortQuotes } from "./utils/quote.mjs";
|
|
34
34
|
import { appendFeesToQuotes } from "./utils/quote-fees.mjs";
|
|
35
35
|
import { getMinimumBalanceForRentExemptionInLamports } from "./utils/snaps.mjs";
|
|
36
36
|
const metadata = {
|
|
@@ -153,48 +153,54 @@ export class BridgeController extends StaticIntervalPollingController() {
|
|
|
153
153
|
this._executePoll = async (pollingInput) => {
|
|
154
154
|
await __classPrivateFieldGet(this, _BridgeController_fetchBridgeQuotes, "f").call(this, pollingInput);
|
|
155
155
|
};
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
* @param quoteRequestCount - The number of quote requests in the UI
|
|
164
|
-
*/
|
|
165
|
-
this.updateBridgeQuoteRequestParams = async (paramsToUpdate, context, quoteRequestIndex = 0, quoteRequestCount = 1) => {
|
|
166
|
-
// Guard against updating a quote request that doesn't exist
|
|
167
|
-
if (quoteRequestIndex >= quoteRequestCount) {
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
__classPrivateFieldGet(this, _BridgeController_trackInputChangedEvents, "f").call(this, paramsToUpdate, quoteRequestIndex);
|
|
171
|
-
this.resetState(AbortReason.QuoteRequestUpdated, quoteRequestIndex);
|
|
156
|
+
this.updateBridgeQuoteRequestParams = async (paramsToUpdate, context) => {
|
|
157
|
+
__classPrivateFieldGet(this, _BridgeController_trackInputChangedEvents, "f").call(this, paramsToUpdate);
|
|
158
|
+
this.resetState(AbortReason.QuoteRequestUpdated);
|
|
159
|
+
const updatedQuoteRequest = {
|
|
160
|
+
...DEFAULT_BRIDGE_CONTROLLER_STATE.quoteRequest,
|
|
161
|
+
...paramsToUpdate,
|
|
162
|
+
};
|
|
172
163
|
this.update((state) => {
|
|
173
|
-
|
|
174
|
-
state.quoteRequest = state.quoteRequest
|
|
175
|
-
.slice(0, quoteRequestIndex)
|
|
176
|
-
.concat({
|
|
177
|
-
...DEFAULT_BRIDGE_CONTROLLER_STATE.quoteRequest[0],
|
|
178
|
-
...paramsToUpdate,
|
|
179
|
-
})
|
|
180
|
-
.concat(state.quoteRequest.slice(quoteRequestIndex + 1, quoteRequestCount));
|
|
164
|
+
state.quoteRequest = updatedQuoteRequest;
|
|
181
165
|
state.tokenSecurityTypeDestination =
|
|
182
166
|
context.token_security_type_destination ?? null;
|
|
183
167
|
});
|
|
184
|
-
|
|
185
|
-
if (isValidQuoteRequest(paramsToUpdate) &&
|
|
186
|
-
isValidBatchSellQuoteRequest(this.state.quoteRequest)) {
|
|
168
|
+
if (isValidQuoteRequest(updatedQuoteRequest)) {
|
|
187
169
|
__classPrivateFieldSet(this, _BridgeController_quotesFirstFetched, Date.now(), "f");
|
|
188
|
-
|
|
189
|
-
const
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
170
|
+
const isSrcChainNonEVM = isNonEvmChainId(updatedQuoteRequest.srcChainId);
|
|
171
|
+
const providerConfig = isSrcChainNonEVM
|
|
172
|
+
? undefined
|
|
173
|
+
: __classPrivateFieldGet(this, _BridgeController_instances, "m", _BridgeController_getNetworkClientByChainId).call(this, formatChainIdToHex(updatedQuoteRequest.srcChainId))?.configuration;
|
|
174
|
+
let insufficientBal;
|
|
175
|
+
let resetApproval = Boolean(paramsToUpdate.resetApproval);
|
|
176
|
+
if (isSrcChainNonEVM) {
|
|
177
|
+
// If the source chain is not an EVM network, use value from params
|
|
178
|
+
insufficientBal = paramsToUpdate.insufficientBal;
|
|
179
|
+
}
|
|
180
|
+
else if (providerConfig?.rpcUrl?.includes('tenderly')) {
|
|
181
|
+
// If the rpcUrl is a tenderly fork (e2e tests), set insufficientBal=true
|
|
182
|
+
// The bridge-api filters out quotes if the balance on mainnet is insufficient so this override allows quotes to always be returned
|
|
183
|
+
insufficientBal = true;
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
// Set loading status if RPC calls are made before the quotes are fetched
|
|
187
|
+
this.update((state) => {
|
|
188
|
+
state.quotesLoadingStatus = RequestStatus.LOADING;
|
|
189
|
+
});
|
|
190
|
+
resetApproval = await __classPrivateFieldGet(this, _BridgeController_shouldResetApproval, "f").call(this, updatedQuoteRequest);
|
|
191
|
+
// Otherwise query the src token balance from the RPC provider
|
|
192
|
+
insufficientBal =
|
|
193
|
+
paramsToUpdate.insufficientBal ??
|
|
194
|
+
(await __classPrivateFieldGet(this, _BridgeController_hasInsufficientBalance, "f").call(this, updatedQuoteRequest));
|
|
195
|
+
}
|
|
194
196
|
// Set refresh rate based on the source chain before starting polling
|
|
195
197
|
this.setChainIntervalLength();
|
|
196
198
|
this.startPolling({
|
|
197
|
-
|
|
199
|
+
updatedQuoteRequest: {
|
|
200
|
+
...updatedQuoteRequest,
|
|
201
|
+
insufficientBal,
|
|
202
|
+
resetApproval,
|
|
203
|
+
},
|
|
198
204
|
context,
|
|
199
205
|
});
|
|
200
206
|
}
|
|
@@ -252,21 +258,25 @@ export class BridgeController extends StaticIntervalPollingController() {
|
|
|
252
258
|
* Fetches the exchange rates for the assets in the quote request if they are not already in the state
|
|
253
259
|
* In addition to the selected tokens, this also fetches the native asset for the source and destination chains
|
|
254
260
|
*
|
|
255
|
-
* @param
|
|
261
|
+
* @param quoteRequest - The quote request
|
|
262
|
+
* @param quoteRequest.srcChainId - The source chain ID
|
|
263
|
+
* @param quoteRequest.srcTokenAddress - The source token address
|
|
264
|
+
* @param quoteRequest.destChainId - The destination chain ID
|
|
265
|
+
* @param quoteRequest.destTokenAddress - The destination token address
|
|
256
266
|
*/
|
|
257
|
-
_BridgeController_fetchAssetExchangeRates.set(this, async (
|
|
267
|
+
_BridgeController_fetchAssetExchangeRates.set(this, async ({ srcChainId, srcTokenAddress, destChainId, destTokenAddress, }) => {
|
|
268
|
+
const assetIds = new Set([]);
|
|
258
269
|
const exchangeRateSources = __classPrivateFieldGet(this, _BridgeController_getExchangeRateSources, "f").call(this);
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
.filter((assetId) => !selectIsAssetExchangeRateInState(exchangeRateSources, assetId)));
|
|
270
|
+
if (srcTokenAddress &&
|
|
271
|
+
srcChainId &&
|
|
272
|
+
!selectIsAssetExchangeRateInState(exchangeRateSources, srcChainId, srcTokenAddress)) {
|
|
273
|
+
getAssetIdsForToken(srcTokenAddress, srcChainId).forEach((assetId) => assetIds.add(assetId));
|
|
274
|
+
}
|
|
275
|
+
if (destTokenAddress &&
|
|
276
|
+
destChainId &&
|
|
277
|
+
!selectIsAssetExchangeRateInState(exchangeRateSources, destChainId, destTokenAddress)) {
|
|
278
|
+
getAssetIdsForToken(destTokenAddress, destChainId).forEach((assetId) => assetIds.add(assetId));
|
|
279
|
+
}
|
|
270
280
|
const currency = __classPrivateFieldGet(this, _BridgeController_getUseAssetsControllerForRates, "f").call(this)
|
|
271
281
|
? this.messenger.call('AssetsController:getExchangeRatesForBridge')
|
|
272
282
|
.currentCurrency
|
|
@@ -307,39 +317,6 @@ export class BridgeController extends StaticIntervalPollingController() {
|
|
|
307
317
|
return true;
|
|
308
318
|
}
|
|
309
319
|
});
|
|
310
|
-
_BridgeController_appendInsufficientBalAndResetApproval.set(this, async (quoteRequest) => {
|
|
311
|
-
const isSrcChainNonEVM = isNonEvmChainId(quoteRequest.srcChainId);
|
|
312
|
-
const providerConfig = isSrcChainNonEVM
|
|
313
|
-
? undefined
|
|
314
|
-
: __classPrivateFieldGet(this, _BridgeController_instances, "m", _BridgeController_getNetworkClientByChainId).call(this, formatChainIdToHex(quoteRequest.srcChainId))?.configuration;
|
|
315
|
-
let insufficientBal;
|
|
316
|
-
let resetApproval = Boolean(quoteRequest.resetApproval);
|
|
317
|
-
if (isSrcChainNonEVM) {
|
|
318
|
-
// If the source chain is not an EVM network, use value from params
|
|
319
|
-
insufficientBal = quoteRequest.insufficientBal;
|
|
320
|
-
}
|
|
321
|
-
else if (providerConfig?.rpcUrl?.includes('tenderly')) {
|
|
322
|
-
// If the rpcUrl is a tenderly fork (e2e tests), set insufficientBal=true
|
|
323
|
-
// The bridge-api filters out quotes if the balance on mainnet is insufficient so this override allows quotes to always be returned
|
|
324
|
-
insufficientBal = true;
|
|
325
|
-
}
|
|
326
|
-
else {
|
|
327
|
-
// Set loading status if RPC calls are made before the quotes are fetched
|
|
328
|
-
this.update((state) => {
|
|
329
|
-
state.quotesLoadingStatus = RequestStatus.LOADING;
|
|
330
|
-
});
|
|
331
|
-
resetApproval = await __classPrivateFieldGet(this, _BridgeController_shouldResetApproval, "f").call(this, quoteRequest);
|
|
332
|
-
// Otherwise query the src token balance from the RPC provider
|
|
333
|
-
insufficientBal =
|
|
334
|
-
quoteRequest.insufficientBal ??
|
|
335
|
-
(await __classPrivateFieldGet(this, _BridgeController_hasInsufficientBalance, "f").call(this, quoteRequest));
|
|
336
|
-
}
|
|
337
|
-
return {
|
|
338
|
-
...quoteRequest,
|
|
339
|
-
insufficientBal,
|
|
340
|
-
resetApproval,
|
|
341
|
-
};
|
|
342
|
-
});
|
|
343
320
|
_BridgeController_shouldResetApproval.set(this, async (quoteRequest) => {
|
|
344
321
|
if (isNonEvmChainId(quoteRequest.srcChainId)) {
|
|
345
322
|
return false;
|
|
@@ -377,21 +354,11 @@ export class BridgeController extends StaticIntervalPollingController() {
|
|
|
377
354
|
this.setLocation = (location) => {
|
|
378
355
|
__classPrivateFieldSet(this, _BridgeController_location, location, "f");
|
|
379
356
|
};
|
|
380
|
-
this.resetState = (reason = AbortReason.ResetState
|
|
357
|
+
this.resetState = (reason = AbortReason.ResetState) => {
|
|
381
358
|
this.stopPollingForQuotes(reason);
|
|
382
359
|
this.update((state) => {
|
|
383
360
|
// Cannot do direct assignment to state, i.e. state = {... }, need to manually assign each field
|
|
384
|
-
|
|
385
|
-
// Clear all requests if index is null
|
|
386
|
-
state.quoteRequest = DEFAULT_BRIDGE_CONTROLLER_STATE.quoteRequest;
|
|
387
|
-
}
|
|
388
|
-
else {
|
|
389
|
-
// Otherwise only clear the specified request
|
|
390
|
-
state.quoteRequest = state.quoteRequest
|
|
391
|
-
.slice(0, quoteRequestIndex)
|
|
392
|
-
.concat(DEFAULT_BRIDGE_CONTROLLER_STATE.quoteRequest[0])
|
|
393
|
-
.concat(state.quoteRequest.slice(quoteRequestIndex + 1));
|
|
394
|
-
}
|
|
361
|
+
state.quoteRequest = DEFAULT_BRIDGE_CONTROLLER_STATE.quoteRequest;
|
|
395
362
|
state.quotesInitialLoadTime =
|
|
396
363
|
DEFAULT_BRIDGE_CONTROLLER_STATE.quotesInitialLoadTime;
|
|
397
364
|
state.quotes = DEFAULT_BRIDGE_CONTROLLER_STATE.quotes;
|
|
@@ -418,9 +385,7 @@ export class BridgeController extends StaticIntervalPollingController() {
|
|
|
418
385
|
*/
|
|
419
386
|
this.setChainIntervalLength = () => {
|
|
420
387
|
const { state } = this;
|
|
421
|
-
|
|
422
|
-
// Use the first one to determine refresh rate
|
|
423
|
-
const { srcChainId } = state.quoteRequest[0];
|
|
388
|
+
const { srcChainId } = state.quoteRequest;
|
|
424
389
|
const bridgeFeatureFlags = getBridgeFeatureFlags(this.messenger);
|
|
425
390
|
const refreshRateOverride = srcChainId
|
|
426
391
|
? bridgeFeatureFlags.chains[formatChainIdToCaip(srcChainId)]?.refreshRate
|
|
@@ -428,16 +393,16 @@ export class BridgeController extends StaticIntervalPollingController() {
|
|
|
428
393
|
const defaultRefreshRate = bridgeFeatureFlags.refreshRate;
|
|
429
394
|
this.setIntervalLength(refreshRateOverride ?? defaultRefreshRate);
|
|
430
395
|
};
|
|
431
|
-
_BridgeController_fetchBridgeQuotes.set(this, async ({
|
|
396
|
+
_BridgeController_fetchBridgeQuotes.set(this, async ({ updatedQuoteRequest, context, }) => {
|
|
432
397
|
__classPrivateFieldGet(this, _BridgeController_abortController, "f")?.abort(AbortReason.NewQuoteRequest);
|
|
433
398
|
__classPrivateFieldSet(this, _BridgeController_abortController, new AbortController(), "f");
|
|
434
|
-
__classPrivateFieldGet(this, _BridgeController_fetchAssetExchangeRates, "f").call(this,
|
|
399
|
+
__classPrivateFieldGet(this, _BridgeController_fetchAssetExchangeRates, "f").call(this, updatedQuoteRequest).catch((error) => console.warn('Failed to fetch asset exchange rates', error));
|
|
435
400
|
this.trackUnifiedSwapBridgeEvent(UnifiedSwapBridgeEventName.QuotesRequested, context);
|
|
436
401
|
const { sse, maxRefreshCount } = getBridgeFeatureFlags(this.messenger);
|
|
437
402
|
const shouldStream = sse?.enabled &&
|
|
438
403
|
hasMinimumRequiredVersion(__classPrivateFieldGet(this, _BridgeController_clientVersion, "f"), sse.minimumVersion);
|
|
439
|
-
const isBatchSellRequest = quoteRequests.length > 1;
|
|
440
404
|
this.update((state) => {
|
|
405
|
+
state.quoteRequest = updatedQuoteRequest;
|
|
441
406
|
state.quoteFetchError = DEFAULT_BRIDGE_CONTROLLER_STATE.quoteFetchError;
|
|
442
407
|
state.tokenWarnings = DEFAULT_BRIDGE_CONTROLLER_STATE.tokenWarnings;
|
|
443
408
|
state.quoteStreamComplete =
|
|
@@ -447,30 +412,26 @@ export class BridgeController extends StaticIntervalPollingController() {
|
|
|
447
412
|
});
|
|
448
413
|
const jwt = await __classPrivateFieldGet(this, _BridgeController_getJwt, "f").call(this);
|
|
449
414
|
try {
|
|
450
|
-
const [firstQuoteRequest] = quoteRequests;
|
|
451
|
-
const unifiedSwapTraceName = isCrossChain(firstQuoteRequest.srcChainId, firstQuoteRequest.destChainId)
|
|
452
|
-
? TraceName.BridgeQuotesFetched
|
|
453
|
-
: TraceName.SwapQuotesFetched;
|
|
454
415
|
await __classPrivateFieldGet(this, _BridgeController_trace, "f").call(this, {
|
|
455
|
-
name:
|
|
456
|
-
? TraceName.
|
|
457
|
-
:
|
|
416
|
+
name: isCrossChain(updatedQuoteRequest.srcChainId, updatedQuoteRequest.destChainId)
|
|
417
|
+
? TraceName.BridgeQuotesFetched
|
|
418
|
+
: TraceName.SwapQuotesFetched,
|
|
458
419
|
data: {
|
|
459
|
-
srcChainId: formatChainIdToCaip(
|
|
460
|
-
destChainId: formatChainIdToCaip(
|
|
420
|
+
srcChainId: formatChainIdToCaip(updatedQuoteRequest.srcChainId),
|
|
421
|
+
destChainId: formatChainIdToCaip(updatedQuoteRequest.destChainId),
|
|
461
422
|
},
|
|
462
423
|
}, async () => {
|
|
463
|
-
const selectedAccount = __classPrivateFieldGet(this, _BridgeController_instances, "m", _BridgeController_getMultichainSelectedAccount).call(this,
|
|
424
|
+
const selectedAccount = __classPrivateFieldGet(this, _BridgeController_instances, "m", _BridgeController_getMultichainSelectedAccount).call(this, updatedQuoteRequest.walletAddress);
|
|
464
425
|
// This call is not awaited to prevent blocking quote fetching if the snap takes too long to respond
|
|
465
426
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
466
|
-
__classPrivateFieldGet(this, _BridgeController_setMinimumBalanceForRentExemptionInLamports, "f").call(this,
|
|
427
|
+
__classPrivateFieldGet(this, _BridgeController_setMinimumBalanceForRentExemptionInLamports, "f").call(this, updatedQuoteRequest.srcChainId, selectedAccount?.metadata?.snap?.id);
|
|
467
428
|
// Use SSE if enabled and return early
|
|
468
|
-
if (shouldStream
|
|
469
|
-
await __classPrivateFieldGet(this, _BridgeController_handleQuoteStreaming, "f").call(this,
|
|
429
|
+
if (shouldStream) {
|
|
430
|
+
await __classPrivateFieldGet(this, _BridgeController_handleQuoteStreaming, "f").call(this, updatedQuoteRequest, jwt, selectedAccount);
|
|
470
431
|
return;
|
|
471
432
|
}
|
|
472
433
|
// Otherwise use regular fetch
|
|
473
|
-
const quotes = await this.fetchQuotes(
|
|
434
|
+
const quotes = await this.fetchQuotes(updatedQuoteRequest, __classPrivateFieldGet(this, _BridgeController_abortController, "f")?.signal);
|
|
474
435
|
this.update((state) => {
|
|
475
436
|
// Set the initial load time if this is the first fetch
|
|
476
437
|
if (state.quotesRefreshCount ===
|
|
@@ -526,17 +487,14 @@ export class BridgeController extends StaticIntervalPollingController() {
|
|
|
526
487
|
this.update((state) => {
|
|
527
488
|
state.quotesRefreshCount += 1;
|
|
528
489
|
});
|
|
529
|
-
|
|
530
|
-
if (
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
true
|
|
534
|
-
: // Otherwise continue polling until the maximum number of refreshes has been reached
|
|
535
|
-
this.state.quotesRefreshCount >= maxRefreshCount) {
|
|
490
|
+
// Stop polling if the maximum number of refreshes has been reached
|
|
491
|
+
if (updatedQuoteRequest.insufficientBal ||
|
|
492
|
+
(!updatedQuoteRequest.insufficientBal &&
|
|
493
|
+
this.state.quotesRefreshCount >= maxRefreshCount)) {
|
|
536
494
|
this.stopAllPolling();
|
|
537
495
|
}
|
|
538
496
|
});
|
|
539
|
-
_BridgeController_handleQuoteStreaming.set(this, async (
|
|
497
|
+
_BridgeController_handleQuoteStreaming.set(this, async (updatedQuoteRequest, jwt, selectedAccount) => {
|
|
540
498
|
/**
|
|
541
499
|
* Tracks the number of valid quotes received from the current stream, which is used
|
|
542
500
|
* to determine when to clear the quotes list and set the initial load time
|
|
@@ -547,7 +505,7 @@ export class BridgeController extends StaticIntervalPollingController() {
|
|
|
547
505
|
* before setting quotesLoadingStatus to FETCHED
|
|
548
506
|
*/
|
|
549
507
|
const pendingFeeAppendPromises = new Set();
|
|
550
|
-
await fetchBridgeQuoteStream(__classPrivateFieldGet(this, _BridgeController_fetchFn, "f"),
|
|
508
|
+
await fetchBridgeQuoteStream(__classPrivateFieldGet(this, _BridgeController_fetchFn, "f"), updatedQuoteRequest, __classPrivateFieldGet(this, _BridgeController_abortController, "f")?.signal, __classPrivateFieldGet(this, _BridgeController_clientId, "f"), jwt, __classPrivateFieldGet(this, _BridgeController_config, "f").customBridgeApiBaseUrl ?? BRIDGE_PROD_API_BASE_URL, {
|
|
551
509
|
onQuoteValidationFailure: __classPrivateFieldGet(this, _BridgeController_trackQuoteValidationFailures, "f"),
|
|
552
510
|
onValidQuoteReceived: async (quote) => {
|
|
553
511
|
const feeAppendPromise = (async () => {
|
|
@@ -634,16 +592,15 @@ export class BridgeController extends StaticIntervalPollingController() {
|
|
|
634
592
|
return undefined;
|
|
635
593
|
}
|
|
636
594
|
});
|
|
637
|
-
_BridgeController_getRequestMetadata.set(this, (
|
|
638
|
-
const
|
|
639
|
-
const { walletAddress } = quoteRequest;
|
|
595
|
+
_BridgeController_getRequestMetadata.set(this, () => {
|
|
596
|
+
const { walletAddress } = this.state.quoteRequest;
|
|
640
597
|
const accountHardwareType = getAccountHardwareType(walletAddress
|
|
641
598
|
? __classPrivateFieldGet(this, _BridgeController_instances, "m", _BridgeController_getMultichainSelectedAccount).call(this, walletAddress)
|
|
642
599
|
: undefined);
|
|
643
600
|
return {
|
|
644
|
-
slippage_limit: quoteRequest.slippage,
|
|
645
|
-
swap_type: getSwapTypeFromQuote(quoteRequest),
|
|
646
|
-
custom_slippage: isCustomSlippage(quoteRequest.slippage),
|
|
601
|
+
slippage_limit: this.state.quoteRequest.slippage,
|
|
602
|
+
swap_type: getSwapTypeFromQuote(this.state.quoteRequest),
|
|
603
|
+
custom_slippage: isCustomSlippage(this.state.quoteRequest.slippage),
|
|
647
604
|
account_hardware_type: accountHardwareType,
|
|
648
605
|
is_hardware_wallet: accountHardwareType !== null,
|
|
649
606
|
};
|
|
@@ -656,35 +613,34 @@ export class BridgeController extends StaticIntervalPollingController() {
|
|
|
656
613
|
has_gas_included_quote: this.state.quotes.some(({ quote }) => quote.gasIncluded),
|
|
657
614
|
};
|
|
658
615
|
});
|
|
659
|
-
_BridgeController_getEventProperties.set(this, (eventName, propertiesFromClient
|
|
616
|
+
_BridgeController_getEventProperties.set(this, (eventName, propertiesFromClient) => {
|
|
660
617
|
const clientProps = propertiesFromClient;
|
|
661
618
|
const baseProperties = {
|
|
662
619
|
...propertiesFromClient,
|
|
663
620
|
location: clientProps?.location ?? __classPrivateFieldGet(this, _BridgeController_location, "f"),
|
|
664
621
|
action_type: MetricsActionType.SWAPBRIDGE_V1,
|
|
665
622
|
};
|
|
666
|
-
const quoteRequest = this.state.quoteRequest[quoteRequestIndex];
|
|
667
623
|
switch (eventName) {
|
|
668
624
|
case UnifiedSwapBridgeEventName.ButtonClicked:
|
|
669
625
|
return {
|
|
670
|
-
...getRequestParams(quoteRequest, this.state.tokenSecurityTypeDestination),
|
|
626
|
+
...getRequestParams(this.state.quoteRequest, this.state.tokenSecurityTypeDestination),
|
|
671
627
|
...baseProperties,
|
|
672
628
|
};
|
|
673
629
|
case UnifiedSwapBridgeEventName.PageViewed:
|
|
674
630
|
return {
|
|
675
|
-
...getRequestParams(quoteRequest, this.state.tokenSecurityTypeDestination),
|
|
631
|
+
...getRequestParams(this.state.quoteRequest, this.state.tokenSecurityTypeDestination),
|
|
676
632
|
...__classPrivateFieldGet(this, _BridgeController_getRequestMetadata, "f").call(this),
|
|
677
633
|
...baseProperties,
|
|
678
634
|
};
|
|
679
635
|
case UnifiedSwapBridgeEventName.QuotesValidationFailed:
|
|
680
636
|
return {
|
|
681
|
-
...getRequestParams(quoteRequest, this.state.tokenSecurityTypeDestination),
|
|
637
|
+
...getRequestParams(this.state.quoteRequest, this.state.tokenSecurityTypeDestination),
|
|
682
638
|
refresh_count: this.state.quotesRefreshCount,
|
|
683
639
|
...baseProperties,
|
|
684
640
|
};
|
|
685
641
|
case UnifiedSwapBridgeEventName.QuotesReceived:
|
|
686
642
|
return {
|
|
687
|
-
...getRequestParams(quoteRequest, this.state.tokenSecurityTypeDestination),
|
|
643
|
+
...getRequestParams(this.state.quoteRequest, this.state.tokenSecurityTypeDestination),
|
|
688
644
|
...__classPrivateFieldGet(this, _BridgeController_getRequestMetadata, "f").call(this),
|
|
689
645
|
...__classPrivateFieldGet(this, _BridgeController_getQuoteFetchData, "f").call(this),
|
|
690
646
|
refresh_count: this.state.quotesRefreshCount,
|
|
@@ -692,24 +648,24 @@ export class BridgeController extends StaticIntervalPollingController() {
|
|
|
692
648
|
};
|
|
693
649
|
case UnifiedSwapBridgeEventName.QuotesRequested:
|
|
694
650
|
return {
|
|
695
|
-
...getRequestParams(quoteRequest, this.state.tokenSecurityTypeDestination),
|
|
651
|
+
...getRequestParams(this.state.quoteRequest, this.state.tokenSecurityTypeDestination),
|
|
696
652
|
...__classPrivateFieldGet(this, _BridgeController_getRequestMetadata, "f").call(this),
|
|
697
|
-
has_sufficient_funds: !quoteRequest.insufficientBal,
|
|
653
|
+
has_sufficient_funds: !this.state.quoteRequest.insufficientBal,
|
|
698
654
|
...baseProperties,
|
|
699
655
|
};
|
|
700
656
|
case UnifiedSwapBridgeEventName.QuotesError:
|
|
701
657
|
return {
|
|
702
|
-
...getRequestParams(quoteRequest, this.state.tokenSecurityTypeDestination),
|
|
658
|
+
...getRequestParams(this.state.quoteRequest, this.state.tokenSecurityTypeDestination),
|
|
703
659
|
...__classPrivateFieldGet(this, _BridgeController_getRequestMetadata, "f").call(this),
|
|
704
660
|
error_message: this.state.quoteFetchError,
|
|
705
|
-
has_sufficient_funds: !quoteRequest.insufficientBal,
|
|
661
|
+
has_sufficient_funds: !this.state.quoteRequest.insufficientBal,
|
|
706
662
|
...baseProperties,
|
|
707
663
|
};
|
|
708
664
|
case UnifiedSwapBridgeEventName.AllQuotesOpened:
|
|
709
665
|
case UnifiedSwapBridgeEventName.AllQuotesSorted:
|
|
710
666
|
case UnifiedSwapBridgeEventName.QuoteSelected:
|
|
711
667
|
return {
|
|
712
|
-
...getRequestParams(quoteRequest, this.state.tokenSecurityTypeDestination),
|
|
668
|
+
...getRequestParams(this.state.quoteRequest, this.state.tokenSecurityTypeDestination),
|
|
713
669
|
...__classPrivateFieldGet(this, _BridgeController_getRequestMetadata, "f").call(this),
|
|
714
670
|
...__classPrivateFieldGet(this, _BridgeController_getQuoteFetchData, "f").call(this),
|
|
715
671
|
...baseProperties,
|
|
@@ -718,7 +674,7 @@ export class BridgeController extends StaticIntervalPollingController() {
|
|
|
718
674
|
// Populate the properties that the error occurred before the tx was submitted
|
|
719
675
|
return {
|
|
720
676
|
...baseProperties,
|
|
721
|
-
...getRequestParams(quoteRequest, this.state.tokenSecurityTypeDestination),
|
|
677
|
+
...getRequestParams(this.state.quoteRequest, this.state.tokenSecurityTypeDestination),
|
|
722
678
|
...__classPrivateFieldGet(this, _BridgeController_getRequestMetadata, "f").call(this),
|
|
723
679
|
...__classPrivateFieldGet(this, _BridgeController_getQuoteFetchData, "f").call(this),
|
|
724
680
|
...propertiesFromClient,
|
|
@@ -745,15 +701,13 @@ export class BridgeController extends StaticIntervalPollingController() {
|
|
|
745
701
|
return baseProperties;
|
|
746
702
|
}
|
|
747
703
|
});
|
|
748
|
-
_BridgeController_trackInputChangedEvents.set(this, (paramsToUpdate
|
|
704
|
+
_BridgeController_trackInputChangedEvents.set(this, (paramsToUpdate) => {
|
|
749
705
|
Object.entries(paramsToUpdate).forEach(([key, value]) => {
|
|
750
706
|
const inputKey = toInputChangedPropertyKey[key];
|
|
751
707
|
const inputValue = toInputChangedPropertyValue[key]?.(paramsToUpdate);
|
|
752
708
|
if (inputKey &&
|
|
753
709
|
inputValue !== undefined &&
|
|
754
|
-
this.state.quoteRequest[
|
|
755
|
-
value !==
|
|
756
|
-
this.state.quoteRequest[quoteRequestIndex][key]) {
|
|
710
|
+
value !== this.state.quoteRequest[key]) {
|
|
757
711
|
this.trackUnifiedSwapBridgeEvent(UnifiedSwapBridgeEventName.InputChanged, {
|
|
758
712
|
input: inputKey,
|
|
759
713
|
input_value: inputValue,
|
|
@@ -767,15 +721,14 @@ export class BridgeController extends StaticIntervalPollingController() {
|
|
|
767
721
|
*
|
|
768
722
|
* @param eventName - The name of the event to track
|
|
769
723
|
* @param propertiesFromClient - Properties that can't be calculated from the event name and need to be provided by the client
|
|
770
|
-
* @param quoteRequestIndex - The index of the quote request to track the event for
|
|
771
724
|
* @example
|
|
772
725
|
* this.trackUnifiedSwapBridgeEvent(UnifiedSwapBridgeEventName.ActionOpened, {
|
|
773
726
|
* location: MetaMetricsSwapsEventSource.MainView,
|
|
774
727
|
* });
|
|
775
728
|
*/
|
|
776
|
-
this.trackUnifiedSwapBridgeEvent = (eventName, propertiesFromClient
|
|
729
|
+
this.trackUnifiedSwapBridgeEvent = (eventName, propertiesFromClient) => {
|
|
777
730
|
try {
|
|
778
|
-
const combinedPropertiesForEvent = __classPrivateFieldGet(this, _BridgeController_getEventProperties, "f").call(this, eventName, propertiesFromClient
|
|
731
|
+
const combinedPropertiesForEvent = __classPrivateFieldGet(this, _BridgeController_getEventProperties, "f").call(this, eventName, propertiesFromClient);
|
|
779
732
|
__classPrivateFieldGet(this, _BridgeController_trackMetaMetricsFn, "f").call(this, eventName, combinedPropertiesForEvent);
|
|
780
733
|
}
|
|
781
734
|
catch (error) {
|
|
@@ -816,9 +769,8 @@ export class BridgeController extends StaticIntervalPollingController() {
|
|
|
816
769
|
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
817
770
|
}
|
|
818
771
|
}
|
|
819
|
-
_BridgeController_abortController = new WeakMap(), _BridgeController_quotesFirstFetched = new WeakMap(), _BridgeController_location = new WeakMap(), _BridgeController_clientId = new WeakMap(), _BridgeController_clientVersion = new WeakMap(), _BridgeController_getLayer1GasFee = new WeakMap(), _BridgeController_fetchFn = new WeakMap(), _BridgeController_trackMetaMetricsFn = new WeakMap(), _BridgeController_trace = new WeakMap(), _BridgeController_config = new WeakMap(), _BridgeController_getUseAssetsControllerForRates = new WeakMap(), _BridgeController_trackQuoteValidationFailures = new WeakMap(), _BridgeController_getExchangeRateSources = new WeakMap(), _BridgeController_fetchAssetExchangeRates = new WeakMap(), _BridgeController_hasInsufficientBalance = new WeakMap(),
|
|
820
|
-
|
|
821
|
-
const addressToUse = walletAddress ?? this.state.quoteRequest[0].walletAddress;
|
|
772
|
+
_BridgeController_abortController = new WeakMap(), _BridgeController_quotesFirstFetched = new WeakMap(), _BridgeController_location = new WeakMap(), _BridgeController_clientId = new WeakMap(), _BridgeController_clientVersion = new WeakMap(), _BridgeController_getLayer1GasFee = new WeakMap(), _BridgeController_fetchFn = new WeakMap(), _BridgeController_trackMetaMetricsFn = new WeakMap(), _BridgeController_trace = new WeakMap(), _BridgeController_config = new WeakMap(), _BridgeController_getUseAssetsControllerForRates = new WeakMap(), _BridgeController_trackQuoteValidationFailures = new WeakMap(), _BridgeController_getExchangeRateSources = new WeakMap(), _BridgeController_fetchAssetExchangeRates = new WeakMap(), _BridgeController_hasInsufficientBalance = new WeakMap(), _BridgeController_shouldResetApproval = new WeakMap(), _BridgeController_fetchBridgeQuotes = new WeakMap(), _BridgeController_handleQuoteStreaming = new WeakMap(), _BridgeController_setMinimumBalanceForRentExemptionInLamports = new WeakMap(), _BridgeController_getJwt = new WeakMap(), _BridgeController_getRequestMetadata = new WeakMap(), _BridgeController_getQuoteFetchData = new WeakMap(), _BridgeController_getEventProperties = new WeakMap(), _BridgeController_trackInputChangedEvents = new WeakMap(), _BridgeController_getUSDTMainnetAllowance = new WeakMap(), _BridgeController_instances = new WeakSet(), _BridgeController_getMultichainSelectedAccount = function _BridgeController_getMultichainSelectedAccount(walletAddress) {
|
|
773
|
+
const addressToUse = walletAddress ?? this.state.quoteRequest.walletAddress;
|
|
822
774
|
if (!addressToUse) {
|
|
823
775
|
throw new Error('Account address is required');
|
|
824
776
|
}
|