@imtbl/sdk 0.22.0 → 0.22.2
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/dist/blockchain_data.js +1 -1
- package/dist/browser/checkout.js +2 -2
- package/dist/checkout_sdk.js +584 -231
- package/dist/checkout_widgets.d.ts +51 -4
- package/dist/checkout_widgets.js +17 -2
- package/dist/immutablex_client.js +1 -1
- package/dist/index.browser.js +7 -7
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +639 -247
- package/dist/index.d.ts +80 -10
- package/dist/index.js +639 -247
- package/dist/orderbook.d.ts +21 -7
- package/dist/orderbook.js +7 -4
- package/dist/passport.js +38 -15
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -22,7 +22,6 @@ import assert from 'assert';
|
|
|
22
22
|
import { FeeAmount, Route, SwapQuoter, Pool, Trade, toHex as toHex$1, encodeRouteToPath } from '@uniswap/v3-sdk';
|
|
23
23
|
import { keccak256 as keccak256$1 } from '@ethersproject/solidity';
|
|
24
24
|
import { SwapRouter } from '@uniswap/router-sdk';
|
|
25
|
-
import { parseUnits as parseUnits$1 } from 'ethers/lib/utils';
|
|
26
25
|
import { jsx } from 'react/jsx-runtime';
|
|
27
26
|
import { useEffect } from 'react';
|
|
28
27
|
|
|
@@ -2988,7 +2987,7 @@ class MultiRollupApiClients {
|
|
|
2988
2987
|
}
|
|
2989
2988
|
|
|
2990
2989
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
2991
|
-
const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.22.
|
|
2990
|
+
const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.22.2' };
|
|
2992
2991
|
const createConfig = ({ basePath, headers, }) => {
|
|
2993
2992
|
if (!basePath.trim()) {
|
|
2994
2993
|
throw Error('basePath can not be empty');
|
|
@@ -3048,7 +3047,7 @@ class APIError extends Error {
|
|
|
3048
3047
|
|
|
3049
3048
|
/* eslint-disable implicit-arrow-linebreak */
|
|
3050
3049
|
const defaultHeaders = {
|
|
3051
|
-
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.22.
|
|
3050
|
+
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.22.2',
|
|
3052
3051
|
};
|
|
3053
3052
|
/**
|
|
3054
3053
|
* createAPIConfiguration to create a custom Configuration
|
|
@@ -3334,7 +3333,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
|
|
|
3334
3333
|
chainID,
|
|
3335
3334
|
coreContractAddress,
|
|
3336
3335
|
registrationContractAddress,
|
|
3337
|
-
sdkVersion: 'ts-immutable-sdk-0.22.
|
|
3336
|
+
sdkVersion: 'ts-immutable-sdk-0.22.2',
|
|
3338
3337
|
});
|
|
3339
3338
|
/**
|
|
3340
3339
|
* Sets `sdkVersion` at the time of build
|
|
@@ -7904,6 +7903,22 @@ class DeviceCredentialsManager {
|
|
|
7904
7903
|
}
|
|
7905
7904
|
}
|
|
7906
7905
|
|
|
7906
|
+
function isIdTokenExpired(idToken) {
|
|
7907
|
+
if (!idToken) {
|
|
7908
|
+
return false;
|
|
7909
|
+
}
|
|
7910
|
+
const decodedToken = jwt_decode(idToken);
|
|
7911
|
+
const now = Math.floor(Date.now() / 1000);
|
|
7912
|
+
return decodedToken.exp < now;
|
|
7913
|
+
}
|
|
7914
|
+
function isTokenExpired(oidcUser) {
|
|
7915
|
+
const { id_token: idToken, expired } = oidcUser;
|
|
7916
|
+
if (expired) {
|
|
7917
|
+
return true;
|
|
7918
|
+
}
|
|
7919
|
+
return isIdTokenExpired(idToken);
|
|
7920
|
+
}
|
|
7921
|
+
|
|
7907
7922
|
const formUrlEncodedHeader = {
|
|
7908
7923
|
headers: {
|
|
7909
7924
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
@@ -8181,23 +8196,30 @@ class AuthManager {
|
|
|
8181
8196
|
}, PassportErrorType.LOGOUT_ERROR);
|
|
8182
8197
|
}
|
|
8183
8198
|
async loginSilent() {
|
|
8184
|
-
return withPassportError(async () =>
|
|
8185
|
-
|
|
8186
|
-
|
|
8187
|
-
|
|
8188
|
-
|
|
8189
|
-
|
|
8190
|
-
|
|
8191
|
-
|
|
8192
|
-
|
|
8199
|
+
return withPassportError(async () => this.getUser(), PassportErrorType.SILENT_LOGIN_ERROR);
|
|
8200
|
+
}
|
|
8201
|
+
async getWebUser() {
|
|
8202
|
+
const oidcUser = await this.userManager.getUser();
|
|
8203
|
+
if (!oidcUser) {
|
|
8204
|
+
return null;
|
|
8205
|
+
}
|
|
8206
|
+
const tokenExpired = isTokenExpired(oidcUser);
|
|
8207
|
+
if (!tokenExpired) {
|
|
8193
8208
|
return AuthManager.mapOidcUserToDomainModel(oidcUser);
|
|
8194
|
-
}
|
|
8209
|
+
}
|
|
8210
|
+
if (oidcUser.refresh_token) {
|
|
8211
|
+
const newOidcUser = await this.userManager.signinSilent();
|
|
8212
|
+
if (newOidcUser) {
|
|
8213
|
+
return AuthManager.mapOidcUserToDomainModel(newOidcUser);
|
|
8214
|
+
}
|
|
8215
|
+
}
|
|
8216
|
+
return null;
|
|
8195
8217
|
}
|
|
8196
8218
|
async getUser() {
|
|
8197
8219
|
return withPassportError(async () => {
|
|
8198
|
-
const
|
|
8199
|
-
if (
|
|
8200
|
-
return
|
|
8220
|
+
const user = await this.getWebUser();
|
|
8221
|
+
if (user) {
|
|
8222
|
+
return user;
|
|
8201
8223
|
}
|
|
8202
8224
|
const deviceToken = this.deviceCredentialsManager.getCredentials();
|
|
8203
8225
|
if (deviceToken) {
|
|
@@ -11303,11 +11325,14 @@ class Orderbook {
|
|
|
11303
11325
|
})),
|
|
11304
11326
|
},
|
|
11305
11327
|
]);
|
|
11306
|
-
if (fulfillmentDataRes.result.length
|
|
11307
|
-
throw new Error(
|
|
11328
|
+
if (fulfillmentDataRes.result.unfulfillable_orders?.length > 0) {
|
|
11329
|
+
throw new Error(`Unable to prepare fulfillment date: ${fulfillmentDataRes.result.unfulfillable_orders[0].reason}`);
|
|
11330
|
+
}
|
|
11331
|
+
else if (fulfillmentDataRes.result.fulfillable_orders?.length !== 1) {
|
|
11332
|
+
throw new Error('unexpected fulfillable order result length');
|
|
11308
11333
|
}
|
|
11309
|
-
const extraData = fulfillmentDataRes.result[0].extra_data;
|
|
11310
|
-
const orderResult = fulfillmentDataRes.result[0].order;
|
|
11334
|
+
const extraData = fulfillmentDataRes.result.fulfillable_orders[0].extra_data;
|
|
11335
|
+
const orderResult = fulfillmentDataRes.result.fulfillable_orders[0].order;
|
|
11311
11336
|
if (orderResult.status !== OrderStatus.ACTIVE) {
|
|
11312
11337
|
throw new Error(`Cannot fulfil order that is not active. Current status: ${orderResult.status}`);
|
|
11313
11338
|
}
|
|
@@ -30159,6 +30184,7 @@ const $7f2e17f026d4fc8d$export$f1ca3744c025ab81 = async (config, provider)=>{
|
|
|
30159
30184
|
|
|
30160
30185
|
|
|
30161
30186
|
|
|
30187
|
+
|
|
30162
30188
|
var $b23305044c0e096a$export$3057de18ac0c076;
|
|
30163
30189
|
(function(RouteCalculatorType) {
|
|
30164
30190
|
RouteCalculatorType["ROUTES_FOUND"] = "ROUTES_FOUND";
|
|
@@ -30220,214 +30246,6 @@ const $33acec7b4a26c053$export$23ddeb2642d2f9d = async (config, readOnlyProvider
|
|
|
30220
30246
|
};
|
|
30221
30247
|
|
|
30222
30248
|
|
|
30223
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
30224
|
-
|
|
30225
|
-
|
|
30226
|
-
|
|
30227
|
-
const $f730af3b727f04ac$export$22fea095b15361de = (balances)=>{
|
|
30228
|
-
for (const balance of balances.balances){
|
|
30229
|
-
if (!balance.token.address || balance.token.address === "") return balance.balance;
|
|
30230
|
-
}
|
|
30231
|
-
return (BigNumber$1).from(0);
|
|
30232
|
-
};
|
|
30233
|
-
|
|
30234
|
-
|
|
30235
|
-
|
|
30236
|
-
|
|
30237
|
-
|
|
30238
|
-
|
|
30239
|
-
const $8a49d1a3783a2640$export$3aff971444a4f244 = async (config, readOnlyProviders)=>{
|
|
30240
|
-
try {
|
|
30241
|
-
const estimate = await (0, $2e7bf45a7c9a9570$export$942c8de7174809fc)({
|
|
30242
|
-
gasEstimateType: (0, $de275b98d2b651c3$export$788b1fd17f3dad84).BRIDGE_TO_L2,
|
|
30243
|
-
isSpendingCapApprovalRequired: false
|
|
30244
|
-
}, readOnlyProviders, config);
|
|
30245
|
-
const gasEstimate = estimate.gasFee.estimatedAmount;
|
|
30246
|
-
const bridgeFee = estimate.bridgeFee.estimatedAmount;
|
|
30247
|
-
let totalFees = (0, BigNumber$1).from(0);
|
|
30248
|
-
if (gasEstimate) totalFees = totalFees.add(gasEstimate);
|
|
30249
|
-
if (bridgeFee) totalFees = totalFees.add(bridgeFee);
|
|
30250
|
-
return totalFees;
|
|
30251
|
-
} catch (err) {
|
|
30252
|
-
throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Error estimating gas for bridge", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).BRIDGE_GAS_ESTIMATE_ERROR, {
|
|
30253
|
-
message: err.message
|
|
30254
|
-
});
|
|
30255
|
-
}
|
|
30256
|
-
};
|
|
30257
|
-
|
|
30258
|
-
|
|
30259
|
-
|
|
30260
|
-
const $823db9fb0ca4bc15$export$c37d8687c27b9660 = "0x0000000000000000000000000000000000000001";
|
|
30261
|
-
const $823db9fb0ca4bc15$export$1430626eec86fce9 = (chainId)=>{
|
|
30262
|
-
if (chainId === ($0472f23319457bfb$export$c06e1e7429de6283).IMTBL_ZKEVM_TESTNET) return "imtbl-zkevm-testnet";
|
|
30263
|
-
return "";
|
|
30264
|
-
};
|
|
30265
|
-
const $823db9fb0ca4bc15$export$53e663abd9b77fc1 = async (chainId, config)=>{
|
|
30266
|
-
const imxMappingConfig = await config.remote.getConfig("imxAddressMapping");
|
|
30267
|
-
return imxMappingConfig[chainId] ?? "";
|
|
30268
|
-
};
|
|
30269
|
-
|
|
30270
|
-
|
|
30271
|
-
|
|
30272
|
-
|
|
30273
|
-
|
|
30274
|
-
|
|
30275
|
-
|
|
30276
|
-
const $07ac9c0576988336$export$7847f5f5cce25dfa = async (config, readOnlyProviders, l1provider, depositorAddress, fromChainId, toChainId, token, depositAmount)=>{
|
|
30277
|
-
try {
|
|
30278
|
-
const tokenBridge = await $67fc622a2b913d5f$export$989eefe1274a439c(fromChainId, toChainId, readOnlyProviders, config);
|
|
30279
|
-
const { unsignedTx: unsignedTx } = await tokenBridge.getUnsignedApproveDepositBridgeTx({
|
|
30280
|
-
depositorAddress: depositorAddress,
|
|
30281
|
-
token: token,
|
|
30282
|
-
depositAmount: depositAmount
|
|
30283
|
-
});
|
|
30284
|
-
if (unsignedTx === null) return (0, BigNumber$1).from(0);
|
|
30285
|
-
return await l1provider.estimateGas(unsignedTx);
|
|
30286
|
-
} catch (err) {
|
|
30287
|
-
throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Error occurred while attempting ot estimate gas for approval transaction", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).BRIDGE_GAS_ESTIMATE_ERROR, {
|
|
30288
|
-
message: err.message
|
|
30289
|
-
});
|
|
30290
|
-
}
|
|
30291
|
-
};
|
|
30292
|
-
const $07ac9c0576988336$export$a3dd181de896b7c7 = async (config, readOnlyProviders, l1provider, depositorAddress, l1Address, delta)=>{
|
|
30293
|
-
if (l1Address === ($823db9fb0ca4bc15$export$c37d8687c27b9660)) return (BigNumber$1).from(0); // Native ETH does not require approval
|
|
30294
|
-
const fromChainId = ($4013c5c91bb535f6$export$9b794d067cdd1af6)(config);
|
|
30295
|
-
const toChainId = ($4013c5c91bb535f6$export$c9af4e4b001c6476)(config);
|
|
30296
|
-
return await $07ac9c0576988336$export$7847f5f5cce25dfa(config, readOnlyProviders, l1provider, depositorAddress, fromChainId, toChainId, l1Address, delta);
|
|
30297
|
-
};
|
|
30298
|
-
|
|
30299
|
-
|
|
30300
|
-
|
|
30301
|
-
|
|
30302
|
-
const $5a5ccedc98d53d25$var$filterTokens = (allowedTokens, balances)=>{
|
|
30303
|
-
if (balances && balances.success) return allowedTokens.filter((token)=>{
|
|
30304
|
-
if ("address" in token) return balances.balances.find((balance)=>balance.token.address === token.address && balance.balance.gt(0));
|
|
30305
|
-
return balances.balances.find((balance)=>!("address" in balance.token) && balance.balance.gt(0));
|
|
30306
|
-
});
|
|
30307
|
-
return [];
|
|
30308
|
-
};
|
|
30309
|
-
const $5a5ccedc98d53d25$export$9ec9fc71f3ce62c4 = async (config, availableRoutingOptions)=>{
|
|
30310
|
-
if (availableRoutingOptions.onRamp) {
|
|
30311
|
-
const onRampOptions = await config.remote.getConfig("onramp");
|
|
30312
|
-
const onRampAllowList = {};
|
|
30313
|
-
Object.entries(onRampOptions).forEach(([onRampProvider, onRampProviderConfig])=>{
|
|
30314
|
-
// Allowed list per onRamp provider
|
|
30315
|
-
onRampAllowList[onRampProvider] = onRampProviderConfig.tokens ?? [];
|
|
30316
|
-
});
|
|
30317
|
-
return onRampAllowList;
|
|
30318
|
-
}
|
|
30319
|
-
return {};
|
|
30320
|
-
};
|
|
30321
|
-
const $5a5ccedc98d53d25$export$d744af9f1c0712bc = async (config, tokenBalances, availableRoutingOptions)=>{
|
|
30322
|
-
if (availableRoutingOptions.bridge) {
|
|
30323
|
-
const allowedTokens = (await config.remote.getConfig("bridge"))?.tokens ?? [];
|
|
30324
|
-
const balances = tokenBalances.get(($4013c5c91bb535f6$export$9b794d067cdd1af6)(config));
|
|
30325
|
-
return $5a5ccedc98d53d25$var$filterTokens(allowedTokens, balances);
|
|
30326
|
-
}
|
|
30327
|
-
return [];
|
|
30328
|
-
};
|
|
30329
|
-
const $5a5ccedc98d53d25$export$87ed7f956d73690 = async (config, tokenBalances, availableRoutingOptions)=>{
|
|
30330
|
-
if (availableRoutingOptions.swap) {
|
|
30331
|
-
const allowedTokens = (await config.remote.getConfig("dex"))?.tokens ?? [];
|
|
30332
|
-
const balances = tokenBalances.get(($4013c5c91bb535f6$export$c9af4e4b001c6476)(config));
|
|
30333
|
-
return $5a5ccedc98d53d25$var$filterTokens(allowedTokens, balances);
|
|
30334
|
-
}
|
|
30335
|
-
return [];
|
|
30336
|
-
};
|
|
30337
|
-
const $5a5ccedc98d53d25$export$1ad29657d49c5440 = async (config, tokenBalances, availableRoutingOptions)=>{
|
|
30338
|
-
const tokenAllowList = {};
|
|
30339
|
-
tokenAllowList.swap = await $5a5ccedc98d53d25$export$87ed7f956d73690(config, tokenBalances, availableRoutingOptions);
|
|
30340
|
-
tokenAllowList.bridge = await $5a5ccedc98d53d25$export$d744af9f1c0712bc(config, tokenBalances, availableRoutingOptions);
|
|
30341
|
-
tokenAllowList.onRamp = await $5a5ccedc98d53d25$export$9ec9fc71f3ce62c4(config, availableRoutingOptions);
|
|
30342
|
-
return tokenAllowList;
|
|
30343
|
-
};
|
|
30344
|
-
|
|
30345
|
-
|
|
30346
|
-
const $fa9ac5bfdbbf9dfa$export$9994ad18c2f0e665 = (balances, totalFees)=>{
|
|
30347
|
-
const balance = ($f730af3b727f04ac$export$22fea095b15361de)(balances);
|
|
30348
|
-
return balance.gte(totalFees);
|
|
30349
|
-
};
|
|
30350
|
-
const $fa9ac5bfdbbf9dfa$export$97330fab5f794e7f = (balanceRequirement)=>{
|
|
30351
|
-
if (balanceRequirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE) return $d85ad1457a3f1a83$export$b80040cb173ba6e9;
|
|
30352
|
-
if (balanceRequirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) return balanceRequirement.required.token.address ?? "";
|
|
30353
|
-
return "";
|
|
30354
|
-
};
|
|
30355
|
-
const $fa9ac5bfdbbf9dfa$export$952cdf461a00a8c6 = async (config, balanceRequirement)=>{
|
|
30356
|
-
const l2address = $fa9ac5bfdbbf9dfa$export$97330fab5f794e7f(balanceRequirement);
|
|
30357
|
-
if (l2address === "") return "";
|
|
30358
|
-
if (l2address === ($d85ad1457a3f1a83$export$b80040cb173ba6e9)) return await ($823db9fb0ca4bc15$export$53e663abd9b77fc1)(($4013c5c91bb535f6$export$9b794d067cdd1af6)(config), config);
|
|
30359
|
-
const chainName = ($823db9fb0ca4bc15$export$1430626eec86fce9)(($4013c5c91bb535f6$export$c9af4e4b001c6476)(config));
|
|
30360
|
-
if (chainName === "") return ""; // Chain name not a valid indexer chain name
|
|
30361
|
-
const blockchainData = ($67fc622a2b913d5f$export$436dd76f23f463ff)(config);
|
|
30362
|
-
const tokenData = await blockchainData.getToken({
|
|
30363
|
-
chainName: chainName,
|
|
30364
|
-
contractAddress: l2address
|
|
30365
|
-
});
|
|
30366
|
-
const l1address = tokenData.result.root_contract_address;
|
|
30367
|
-
if (l1address === null) return ""; // No L1 representation of this token
|
|
30368
|
-
return l1address;
|
|
30369
|
-
};
|
|
30370
|
-
const $fa9ac5bfdbbf9dfa$export$da05aed50d75046 = async (config, readOnlyProviders, feeEstimates)=>{
|
|
30371
|
-
let bridgeFeeEstimate = feeEstimates.get(($4b58188d47aafe8d$export$3af78bb3e8650ee6).BRIDGE);
|
|
30372
|
-
if (bridgeFeeEstimate) return bridgeFeeEstimate;
|
|
30373
|
-
bridgeFeeEstimate = await ($8a49d1a3783a2640$export$3aff971444a4f244)(config, readOnlyProviders);
|
|
30374
|
-
feeEstimates.set(($4b58188d47aafe8d$export$3af78bb3e8650ee6).BRIDGE, bridgeFeeEstimate);
|
|
30375
|
-
return bridgeFeeEstimate;
|
|
30376
|
-
};
|
|
30377
|
-
const $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute = (chainId, balance)=>({
|
|
30378
|
-
type: ($4b58188d47aafe8d$export$3af78bb3e8650ee6).BRIDGE,
|
|
30379
|
-
chainId: chainId,
|
|
30380
|
-
asset: {
|
|
30381
|
-
balance: balance.balance,
|
|
30382
|
-
formattedBalance: balance.formattedBalance,
|
|
30383
|
-
token: {
|
|
30384
|
-
name: balance.token.name,
|
|
30385
|
-
symbol: balance.token.symbol,
|
|
30386
|
-
address: balance.token.address,
|
|
30387
|
-
decimals: balance.token.decimals
|
|
30388
|
-
}
|
|
30389
|
-
}
|
|
30390
|
-
});
|
|
30391
|
-
const $fa9ac5bfdbbf9dfa$export$3139474685e4dedd = (address)=>{
|
|
30392
|
-
if (!address || address === "") return true;
|
|
30393
|
-
return false;
|
|
30394
|
-
};
|
|
30395
|
-
const $fa9ac5bfdbbf9dfa$export$ddc7ba2b57d7c5fa = async (config, readOnlyProviders, depositorAddress, availableRoutingOptions, balanceRequirement, balances, feeEstimates)=>{
|
|
30396
|
-
if (!availableRoutingOptions.bridge) return undefined;
|
|
30397
|
-
const chainId = ($4013c5c91bb535f6$export$9b794d067cdd1af6)(config);
|
|
30398
|
-
const tokenBalanceResult = balances.get(chainId);
|
|
30399
|
-
const l1provider = readOnlyProviders.get(chainId);
|
|
30400
|
-
if (!l1provider) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("No L1 provider available", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).PROVIDER_ERROR, {
|
|
30401
|
-
chainId: chainId.toString()
|
|
30402
|
-
});
|
|
30403
|
-
// If no balances on layer 1 then Bridge cannot be an option
|
|
30404
|
-
if (tokenBalanceResult === undefined || tokenBalanceResult.success === false) return undefined;
|
|
30405
|
-
const allowedTokenList = await ($5a5ccedc98d53d25$export$d744af9f1c0712bc)(config, balances, availableRoutingOptions);
|
|
30406
|
-
if (allowedTokenList.length === 0) return undefined;
|
|
30407
|
-
const bridgeFeeEstimate = await $fa9ac5bfdbbf9dfa$export$da05aed50d75046(config, readOnlyProviders, feeEstimates);
|
|
30408
|
-
// If the user has no ETH to cover the bridge fees or approval fees then bridge cannot be an option
|
|
30409
|
-
if (!$fa9ac5bfdbbf9dfa$export$9994ad18c2f0e665(tokenBalanceResult, bridgeFeeEstimate)) return undefined;
|
|
30410
|
-
const l1address = await $fa9ac5bfdbbf9dfa$export$952cdf461a00a8c6(config, balanceRequirement);
|
|
30411
|
-
if (l1address === "") return undefined;
|
|
30412
|
-
// Ensure l1address is in the allowed token list
|
|
30413
|
-
if (l1address === ($823db9fb0ca4bc15$export$c37d8687c27b9660)) {
|
|
30414
|
-
if (!allowedTokenList.find((token)=>!("address" in token))) return undefined;
|
|
30415
|
-
} else if (!allowedTokenList.find((token)=>token.address === l1address)) return undefined;
|
|
30416
|
-
const gasForApproval = await ($07ac9c0576988336$export$a3dd181de896b7c7)(config, readOnlyProviders, l1provider, depositorAddress, l1address, balanceRequirement.delta.balance);
|
|
30417
|
-
if (!$fa9ac5bfdbbf9dfa$export$9994ad18c2f0e665(tokenBalanceResult, gasForApproval.add(bridgeFeeEstimate))) return undefined;
|
|
30418
|
-
// If the L1 representation of the requirement is ETH then find the ETH balance and check if the balance covers the delta
|
|
30419
|
-
if (l1address === ($823db9fb0ca4bc15$export$c37d8687c27b9660)) {
|
|
30420
|
-
const nativeETHBalance = tokenBalanceResult.balances.find((balance)=>$fa9ac5bfdbbf9dfa$export$3139474685e4dedd(balance.token.address));
|
|
30421
|
-
if (nativeETHBalance && nativeETHBalance.balance.gte(balanceRequirement.delta.balance.add(bridgeFeeEstimate))) return $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute(chainId, nativeETHBalance);
|
|
30422
|
-
return undefined;
|
|
30423
|
-
}
|
|
30424
|
-
// Find the balance of the L1 representation of the token and check if the balance covers the delta
|
|
30425
|
-
const erc20balance = tokenBalanceResult.balances.find((balance)=>balance.token.address === l1address);
|
|
30426
|
-
if (erc20balance && erc20balance.balance.gte(balanceRequirement.delta.balance)) return $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute(chainId, erc20balance);
|
|
30427
|
-
return undefined;
|
|
30428
|
-
};
|
|
30429
|
-
|
|
30430
|
-
|
|
30431
30249
|
|
|
30432
30250
|
|
|
30433
30251
|
|
|
@@ -30456,11 +30274,13 @@ async function $0e0060cb42e136d2$export$339cb2be73677b30(config, existingReadOnl
|
|
|
30456
30274
|
|
|
30457
30275
|
const $049bba630af05555$export$6946a1f17c2bbf26 = async (config, chainId, walletAddress, requiredToken, swappableTokens)=>{
|
|
30458
30276
|
const dexQuotes = new Map();
|
|
30277
|
+
// Apply a small slippage percent as a buffer to cover price fluctuations between token pairs
|
|
30278
|
+
const slippagePercent = 1;
|
|
30459
30279
|
try {
|
|
30460
30280
|
const exchange = await $67fc622a2b913d5f$export$7cf6178417769841(chainId, config);
|
|
30461
30281
|
const dexTransactionResponsePromises = [];
|
|
30462
30282
|
// Create a quote for each swappable token
|
|
30463
|
-
for (const swappableToken of swappableTokens)dexTransactionResponsePromises.push(exchange.getUnsignedSwapTxFromAmountOut(walletAddress, swappableToken, requiredToken.address, requiredToken.amount));
|
|
30283
|
+
for (const swappableToken of swappableTokens)dexTransactionResponsePromises.push(exchange.getUnsignedSwapTxFromAmountOut(walletAddress, swappableToken, requiredToken.address, requiredToken.amount, slippagePercent));
|
|
30464
30284
|
// Resolve all the quotes and link them back to the swappable token
|
|
30465
30285
|
// The swappable token array is in the same position in the array as the quote in the promise array
|
|
30466
30286
|
const dexTransactionResponse = await Promise.all(dexTransactionResponsePromises);
|
|
@@ -30481,7 +30301,7 @@ const $049bba630af05555$export$6946a1f17c2bbf26 = async (config, chainId, wallet
|
|
|
30481
30301
|
|
|
30482
30302
|
const $3ee85f12225c19f3$export$fb80fe94a81a3132 = async (config, dexQuoteCache, walletAddress, requiredToken, swappableTokens)=>{
|
|
30483
30303
|
const dexQuotes = dexQuoteCache.get(requiredToken.address);
|
|
30484
|
-
if (dexQuotes) return dexQuotes;
|
|
30304
|
+
if (dexQuotes && dexQuotes.size > 0) return dexQuotes;
|
|
30485
30305
|
const quotes = await ($049bba630af05555$export$6946a1f17c2bbf26)(config, ($4013c5c91bb535f6$export$c9af4e4b001c6476)(config), walletAddress, requiredToken, swappableTokens);
|
|
30486
30306
|
dexQuoteCache.set(requiredToken.address, quotes);
|
|
30487
30307
|
return quotes;
|
|
@@ -30618,6 +30438,506 @@ const $91807edfd7057288$export$8e03ea04d59f2402 = async (config, availableRoutin
|
|
|
30618
30438
|
|
|
30619
30439
|
|
|
30620
30440
|
|
|
30441
|
+
const $5a5ccedc98d53d25$var$filterTokens = (allowedTokens, balances)=>{
|
|
30442
|
+
if (balances && balances.success) return allowedTokens.filter((token)=>{
|
|
30443
|
+
if ("address" in token) return balances.balances.find((balance)=>balance.token.address === token.address && balance.balance.gt(0));
|
|
30444
|
+
return balances.balances.find((balance)=>!("address" in balance.token) && balance.balance.gt(0));
|
|
30445
|
+
});
|
|
30446
|
+
return [];
|
|
30447
|
+
};
|
|
30448
|
+
const $5a5ccedc98d53d25$export$9ec9fc71f3ce62c4 = async (config, availableRoutingOptions)=>{
|
|
30449
|
+
if (availableRoutingOptions.onRamp) {
|
|
30450
|
+
const onRampOptions = await config.remote.getConfig("onramp");
|
|
30451
|
+
const onRampAllowList = {};
|
|
30452
|
+
Object.entries(onRampOptions).forEach(([onRampProvider, onRampProviderConfig])=>{
|
|
30453
|
+
// Allowed list per onRamp provider
|
|
30454
|
+
onRampAllowList[onRampProvider] = onRampProviderConfig.tokens ?? [];
|
|
30455
|
+
});
|
|
30456
|
+
return onRampAllowList;
|
|
30457
|
+
}
|
|
30458
|
+
return {};
|
|
30459
|
+
};
|
|
30460
|
+
const $5a5ccedc98d53d25$export$d744af9f1c0712bc = async (config, tokenBalances, availableRoutingOptions)=>{
|
|
30461
|
+
if (availableRoutingOptions.bridge) {
|
|
30462
|
+
const allowedTokens = (await config.remote.getConfig("bridge"))?.tokens ?? [];
|
|
30463
|
+
const balances = tokenBalances.get(($4013c5c91bb535f6$export$9b794d067cdd1af6)(config));
|
|
30464
|
+
return $5a5ccedc98d53d25$var$filterTokens(allowedTokens, balances);
|
|
30465
|
+
}
|
|
30466
|
+
return [];
|
|
30467
|
+
};
|
|
30468
|
+
const $5a5ccedc98d53d25$export$87ed7f956d73690 = async (config, tokenBalances, availableRoutingOptions)=>{
|
|
30469
|
+
if (availableRoutingOptions.swap) {
|
|
30470
|
+
const allowedTokens = (await config.remote.getConfig("dex"))?.tokens ?? [];
|
|
30471
|
+
const balances = tokenBalances.get(($4013c5c91bb535f6$export$c9af4e4b001c6476)(config));
|
|
30472
|
+
return $5a5ccedc98d53d25$var$filterTokens(allowedTokens, balances);
|
|
30473
|
+
}
|
|
30474
|
+
return [];
|
|
30475
|
+
};
|
|
30476
|
+
const $5a5ccedc98d53d25$export$1ad29657d49c5440 = async (config, tokenBalances, availableRoutingOptions)=>{
|
|
30477
|
+
const tokenAllowList = {};
|
|
30478
|
+
tokenAllowList.swap = await $5a5ccedc98d53d25$export$87ed7f956d73690(config, tokenBalances, availableRoutingOptions);
|
|
30479
|
+
tokenAllowList.bridge = await $5a5ccedc98d53d25$export$d744af9f1c0712bc(config, tokenBalances, availableRoutingOptions);
|
|
30480
|
+
tokenAllowList.onRamp = await $5a5ccedc98d53d25$export$9ec9fc71f3ce62c4(config, availableRoutingOptions);
|
|
30481
|
+
return tokenAllowList;
|
|
30482
|
+
};
|
|
30483
|
+
|
|
30484
|
+
|
|
30485
|
+
|
|
30486
|
+
|
|
30487
|
+
|
|
30488
|
+
|
|
30489
|
+
|
|
30490
|
+
|
|
30491
|
+
|
|
30492
|
+
const $f730af3b727f04ac$export$22fea095b15361de = (balances)=>{
|
|
30493
|
+
for (const balance of balances.balances){
|
|
30494
|
+
if (!balance.token.address || balance.token.address === "") return balance.balance;
|
|
30495
|
+
}
|
|
30496
|
+
return (BigNumber$1).from(0);
|
|
30497
|
+
};
|
|
30498
|
+
|
|
30499
|
+
|
|
30500
|
+
|
|
30501
|
+
|
|
30502
|
+
|
|
30503
|
+
|
|
30504
|
+
const $8a49d1a3783a2640$export$3aff971444a4f244 = async (config, readOnlyProviders)=>{
|
|
30505
|
+
try {
|
|
30506
|
+
const estimate = await (0, $2e7bf45a7c9a9570$export$942c8de7174809fc)({
|
|
30507
|
+
gasEstimateType: (0, $de275b98d2b651c3$export$788b1fd17f3dad84).BRIDGE_TO_L2,
|
|
30508
|
+
isSpendingCapApprovalRequired: false
|
|
30509
|
+
}, readOnlyProviders, config);
|
|
30510
|
+
const gasEstimate = estimate.gasFee.estimatedAmount;
|
|
30511
|
+
const bridgeFee = estimate.bridgeFee.estimatedAmount;
|
|
30512
|
+
let totalFees = (0, BigNumber$1).from(0);
|
|
30513
|
+
if (gasEstimate) totalFees = totalFees.add(gasEstimate);
|
|
30514
|
+
if (bridgeFee) totalFees = totalFees.add(bridgeFee);
|
|
30515
|
+
return totalFees;
|
|
30516
|
+
} catch (err) {
|
|
30517
|
+
throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Error estimating gas for bridge", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).BRIDGE_GAS_ESTIMATE_ERROR, {
|
|
30518
|
+
message: err.message
|
|
30519
|
+
});
|
|
30520
|
+
}
|
|
30521
|
+
};
|
|
30522
|
+
|
|
30523
|
+
|
|
30524
|
+
|
|
30525
|
+
|
|
30526
|
+
|
|
30527
|
+
|
|
30528
|
+
|
|
30529
|
+
|
|
30530
|
+
|
|
30531
|
+
const $887d24b47765b1c0$export$c37d8687c27b9660 = "0x0000000000000000000000000000000000000001";
|
|
30532
|
+
const $887d24b47765b1c0$export$1430626eec86fce9 = (chainId)=>{
|
|
30533
|
+
if (chainId === ($0472f23319457bfb$export$c06e1e7429de6283).IMTBL_ZKEVM_TESTNET) return "imtbl-zkevm-testnet";
|
|
30534
|
+
return "";
|
|
30535
|
+
};
|
|
30536
|
+
const $887d24b47765b1c0$export$53e663abd9b77fc1 = async (chainId, config)=>{
|
|
30537
|
+
const imxMappingConfig = await config.remote.getConfig("imxAddressMapping");
|
|
30538
|
+
return imxMappingConfig[chainId] ?? "";
|
|
30539
|
+
};
|
|
30540
|
+
const $887d24b47765b1c0$export$952cdf461a00a8c6 = async (config, l2address)=>{
|
|
30541
|
+
if (l2address === "") return {
|
|
30542
|
+
l1address: "",
|
|
30543
|
+
l2address: l2address
|
|
30544
|
+
};
|
|
30545
|
+
if (l2address === ($d85ad1457a3f1a83$export$b80040cb173ba6e9)) return {
|
|
30546
|
+
l1address: await $887d24b47765b1c0$export$53e663abd9b77fc1(($4013c5c91bb535f6$export$9b794d067cdd1af6)(config), config),
|
|
30547
|
+
l2address: ($d85ad1457a3f1a83$export$b80040cb173ba6e9)
|
|
30548
|
+
};
|
|
30549
|
+
const chainName = $887d24b47765b1c0$export$1430626eec86fce9(($4013c5c91bb535f6$export$c9af4e4b001c6476)(config));
|
|
30550
|
+
if (chainName === "") return {
|
|
30551
|
+
l1address: "",
|
|
30552
|
+
l2address: l2address
|
|
30553
|
+
}; // Chain name not a valid indexer chain name
|
|
30554
|
+
const blockchainData = ($67fc622a2b913d5f$export$436dd76f23f463ff)(config);
|
|
30555
|
+
const tokenData = await blockchainData.getToken({
|
|
30556
|
+
chainName: chainName,
|
|
30557
|
+
contractAddress: l2address
|
|
30558
|
+
});
|
|
30559
|
+
const l1address = tokenData.result.root_contract_address;
|
|
30560
|
+
if (l1address === null) return {
|
|
30561
|
+
l1address: "",
|
|
30562
|
+
l2address: l2address
|
|
30563
|
+
}; // No L1 representation of this token
|
|
30564
|
+
return {
|
|
30565
|
+
l1address: l1address,
|
|
30566
|
+
l2address: l2address
|
|
30567
|
+
};
|
|
30568
|
+
};
|
|
30569
|
+
|
|
30570
|
+
|
|
30571
|
+
const $07ac9c0576988336$export$7847f5f5cce25dfa = async (config, readOnlyProviders, l1provider, depositorAddress, fromChainId, toChainId, token, depositAmount)=>{
|
|
30572
|
+
try {
|
|
30573
|
+
const tokenBridge = await $67fc622a2b913d5f$export$989eefe1274a439c(fromChainId, toChainId, readOnlyProviders, config);
|
|
30574
|
+
const { unsignedTx: unsignedTx } = await tokenBridge.getUnsignedApproveDepositBridgeTx({
|
|
30575
|
+
depositorAddress: depositorAddress,
|
|
30576
|
+
token: token,
|
|
30577
|
+
depositAmount: depositAmount
|
|
30578
|
+
});
|
|
30579
|
+
if (unsignedTx === null) return (0, BigNumber$1).from(0);
|
|
30580
|
+
return await l1provider.estimateGas(unsignedTx);
|
|
30581
|
+
} catch (err) {
|
|
30582
|
+
throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Error occurred while attempting ot estimate gas for approval transaction", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).BRIDGE_GAS_ESTIMATE_ERROR, {
|
|
30583
|
+
message: err.message
|
|
30584
|
+
});
|
|
30585
|
+
}
|
|
30586
|
+
};
|
|
30587
|
+
const $07ac9c0576988336$export$a3dd181de896b7c7 = async (config, readOnlyProviders, l1provider, depositorAddress, l1Address, delta)=>{
|
|
30588
|
+
if (l1Address === ($887d24b47765b1c0$export$c37d8687c27b9660)) return (BigNumber$1).from(0); // Native ETH does not require approval
|
|
30589
|
+
const fromChainId = ($4013c5c91bb535f6$export$9b794d067cdd1af6)(config);
|
|
30590
|
+
const toChainId = ($4013c5c91bb535f6$export$c9af4e4b001c6476)(config);
|
|
30591
|
+
return await $07ac9c0576988336$export$7847f5f5cce25dfa(config, readOnlyProviders, l1provider, depositorAddress, fromChainId, toChainId, l1Address, delta);
|
|
30592
|
+
};
|
|
30593
|
+
|
|
30594
|
+
|
|
30595
|
+
|
|
30596
|
+
|
|
30597
|
+
|
|
30598
|
+
const $fa9ac5bfdbbf9dfa$export$9994ad18c2f0e665 = (tokenBalanceResult, totalFees)=>{
|
|
30599
|
+
const balance = ($f730af3b727f04ac$export$22fea095b15361de)(tokenBalanceResult);
|
|
30600
|
+
return balance.gte(totalFees);
|
|
30601
|
+
};
|
|
30602
|
+
const $fa9ac5bfdbbf9dfa$export$da05aed50d75046 = async (config, readOnlyProviders, feeEstimates)=>{
|
|
30603
|
+
let bridgeFeeEstimate = feeEstimates.get(($4b58188d47aafe8d$export$3af78bb3e8650ee6).BRIDGE);
|
|
30604
|
+
if (bridgeFeeEstimate) return bridgeFeeEstimate;
|
|
30605
|
+
bridgeFeeEstimate = await ($8a49d1a3783a2640$export$3aff971444a4f244)(config, readOnlyProviders);
|
|
30606
|
+
feeEstimates.set(($4b58188d47aafe8d$export$3af78bb3e8650ee6).BRIDGE, bridgeFeeEstimate);
|
|
30607
|
+
return bridgeFeeEstimate;
|
|
30608
|
+
};
|
|
30609
|
+
const $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute = (chainId, balance)=>({
|
|
30610
|
+
type: ($4b58188d47aafe8d$export$3af78bb3e8650ee6).BRIDGE,
|
|
30611
|
+
chainId: chainId,
|
|
30612
|
+
asset: {
|
|
30613
|
+
balance: balance.balance,
|
|
30614
|
+
formattedBalance: balance.formattedBalance,
|
|
30615
|
+
token: {
|
|
30616
|
+
name: balance.token.name,
|
|
30617
|
+
symbol: balance.token.symbol,
|
|
30618
|
+
address: balance.token.address,
|
|
30619
|
+
decimals: balance.token.decimals
|
|
30620
|
+
}
|
|
30621
|
+
}
|
|
30622
|
+
});
|
|
30623
|
+
const $fa9ac5bfdbbf9dfa$export$3139474685e4dedd = (address)=>{
|
|
30624
|
+
if (!address || address === "") return true;
|
|
30625
|
+
return false;
|
|
30626
|
+
};
|
|
30627
|
+
const $fa9ac5bfdbbf9dfa$export$ddc7ba2b57d7c5fa = async (config, readOnlyProviders, depositorAddress, availableRoutingOptions, bridgeRequirement, tokenBalanceResults, feeEstimates)=>{
|
|
30628
|
+
if (!availableRoutingOptions.bridge) return undefined;
|
|
30629
|
+
if (bridgeRequirement.l2address === undefined || bridgeRequirement.l2address === "") return undefined;
|
|
30630
|
+
const chainId = ($4013c5c91bb535f6$export$9b794d067cdd1af6)(config);
|
|
30631
|
+
const tokenBalanceResult = tokenBalanceResults.get(chainId);
|
|
30632
|
+
const l1provider = readOnlyProviders.get(chainId);
|
|
30633
|
+
if (!l1provider) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("No L1 provider available", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).PROVIDER_ERROR, {
|
|
30634
|
+
chainId: chainId.toString()
|
|
30635
|
+
});
|
|
30636
|
+
// If no balances on layer 1 then Bridge cannot be an option
|
|
30637
|
+
if (tokenBalanceResult === undefined || tokenBalanceResult.success === false) return undefined;
|
|
30638
|
+
const allowedTokenList = await ($5a5ccedc98d53d25$export$d744af9f1c0712bc)(config, tokenBalanceResults, availableRoutingOptions);
|
|
30639
|
+
if (allowedTokenList.length === 0) return undefined;
|
|
30640
|
+
const bridgeFeeEstimate = await $fa9ac5bfdbbf9dfa$export$da05aed50d75046(config, readOnlyProviders, feeEstimates);
|
|
30641
|
+
// If the user has no ETH to cover the bridge fees or approval fees then bridge cannot be an option
|
|
30642
|
+
if (!$fa9ac5bfdbbf9dfa$export$9994ad18c2f0e665(tokenBalanceResult, bridgeFeeEstimate)) return undefined;
|
|
30643
|
+
const l1RepresentationResult = await ($887d24b47765b1c0$export$952cdf461a00a8c6)(config, bridgeRequirement.l2address);
|
|
30644
|
+
// No mapping on L1 for this token
|
|
30645
|
+
const { l1address: l1address } = l1RepresentationResult;
|
|
30646
|
+
if (l1address === "") return undefined;
|
|
30647
|
+
// Ensure l1address is in the allowed token list
|
|
30648
|
+
if (l1address === ($887d24b47765b1c0$export$c37d8687c27b9660)) {
|
|
30649
|
+
if (!allowedTokenList.find((token)=>!("address" in token))) return undefined;
|
|
30650
|
+
} else if (!allowedTokenList.find((token)=>token.address === l1address)) return undefined;
|
|
30651
|
+
const gasForApproval = await ($07ac9c0576988336$export$a3dd181de896b7c7)(config, readOnlyProviders, l1provider, depositorAddress, l1address, bridgeRequirement.amount);
|
|
30652
|
+
if (!$fa9ac5bfdbbf9dfa$export$9994ad18c2f0e665(tokenBalanceResult, gasForApproval.add(bridgeFeeEstimate))) return undefined;
|
|
30653
|
+
// If the L1 representation of the requirement is ETH then find the ETH balance and check if the balance covers the delta
|
|
30654
|
+
if (l1address === ($887d24b47765b1c0$export$c37d8687c27b9660)) {
|
|
30655
|
+
const nativeETHBalance = tokenBalanceResult.balances.find((balance)=>$fa9ac5bfdbbf9dfa$export$3139474685e4dedd(balance.token.address));
|
|
30656
|
+
if (nativeETHBalance && nativeETHBalance.balance.gte(bridgeRequirement.amount.add(bridgeFeeEstimate))) return $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute(chainId, nativeETHBalance);
|
|
30657
|
+
return undefined;
|
|
30658
|
+
}
|
|
30659
|
+
// Find the balance of the L1 representation of the token and check if the balance covers the delta
|
|
30660
|
+
const erc20balance = tokenBalanceResult.balances.find((balance)=>balance.token.address === l1address);
|
|
30661
|
+
if (erc20balance && erc20balance.balance.gte(bridgeRequirement.amount)) return $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute(chainId, erc20balance);
|
|
30662
|
+
return undefined;
|
|
30663
|
+
};
|
|
30664
|
+
|
|
30665
|
+
|
|
30666
|
+
|
|
30667
|
+
|
|
30668
|
+
const $7bb5af1d8b5d9127$export$8280985cc3da7882 = (config, tokenBalances)=>{
|
|
30669
|
+
const balances = {
|
|
30670
|
+
l1balances: [],
|
|
30671
|
+
l2balances: []
|
|
30672
|
+
};
|
|
30673
|
+
const l1balancesResult = tokenBalances.get(($4013c5c91bb535f6$export$9b794d067cdd1af6)(config));
|
|
30674
|
+
const l2balancesResult = tokenBalances.get(($4013c5c91bb535f6$export$c9af4e4b001c6476)(config));
|
|
30675
|
+
// If there are no l1 balance then cannot bridge
|
|
30676
|
+
if (!l1balancesResult) return balances;
|
|
30677
|
+
if (l1balancesResult.error !== undefined) return balances;
|
|
30678
|
+
if (!l1balancesResult.success) return balances;
|
|
30679
|
+
// If there are no l2 balance then cannot swap
|
|
30680
|
+
if (!l2balancesResult) return balances;
|
|
30681
|
+
if (l2balancesResult.error !== undefined) return balances;
|
|
30682
|
+
if (!l2balancesResult.success) return balances;
|
|
30683
|
+
const l1balances = l1balancesResult.balances;
|
|
30684
|
+
const l2balances = l2balancesResult.balances;
|
|
30685
|
+
return {
|
|
30686
|
+
l1balances: l1balances,
|
|
30687
|
+
l2balances: l2balances
|
|
30688
|
+
};
|
|
30689
|
+
};
|
|
30690
|
+
|
|
30691
|
+
|
|
30692
|
+
|
|
30693
|
+
|
|
30694
|
+
|
|
30695
|
+
const $62e968a3dd87940e$export$8059963805b7876c = (dexQuote, tokenAddress)=>{
|
|
30696
|
+
let fees = (BigNumber$1).from(0);
|
|
30697
|
+
dexQuote.quote.fees.forEach((fee)=>{
|
|
30698
|
+
if (fee.amount.token.address === tokenAddress) fees = fees.add(fee.amount.value);
|
|
30699
|
+
});
|
|
30700
|
+
if (dexQuote.approval) {
|
|
30701
|
+
if (dexQuote.approval.token.address === tokenAddress) fees = fees.add(dexQuote.approval.value);
|
|
30702
|
+
}
|
|
30703
|
+
return fees;
|
|
30704
|
+
};
|
|
30705
|
+
// The token that is being bridged may also be a balance requirement
|
|
30706
|
+
// Since this token is going to be swapped after bridging then get the
|
|
30707
|
+
// balance requirement amount so this can be considered when bridging
|
|
30708
|
+
// enough of the token across
|
|
30709
|
+
const $62e968a3dd87940e$var$getAmountFromBalanceRequirement = (balanceRequirements, tokenAddress)=>{
|
|
30710
|
+
let amount = (BigNumber$1).from(0);
|
|
30711
|
+
balanceRequirements.balanceRequirements.forEach((requirement)=>{
|
|
30712
|
+
if (requirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE || requirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) {
|
|
30713
|
+
if (requirement.required.token.address === tokenAddress) amount = amount.add(requirement.required.balance);
|
|
30714
|
+
}
|
|
30715
|
+
});
|
|
30716
|
+
return amount;
|
|
30717
|
+
};
|
|
30718
|
+
const $62e968a3dd87940e$export$df667c749c93b110 = (dexQuotes, l1balances, l2balances, l1tol2addresses, balanceRequirements)=>{
|
|
30719
|
+
const bridgeRequirements = [];
|
|
30720
|
+
for (const [tokenAddress, quote] of dexQuotes){
|
|
30721
|
+
// Get the L2 balance for the token address
|
|
30722
|
+
const l2balance = l2balances.find((balance)=>balance.token.address === tokenAddress);
|
|
30723
|
+
const l1tol2TokenMapping = l1tol2addresses.find((token)=>token.l2address === tokenAddress);
|
|
30724
|
+
if (!l1tol2TokenMapping) continue;
|
|
30725
|
+
const { l1address: l1address, l2address: l2address } = l1tol2TokenMapping;
|
|
30726
|
+
if (!l1address) continue;
|
|
30727
|
+
// If the user does not have any L1 balance for this token then cannot bridge
|
|
30728
|
+
const l1balance = l1balances.find((balance)=>{
|
|
30729
|
+
if (balance.token.address === undefined && l1address === ($887d24b47765b1c0$export$c37d8687c27b9660)) return true;
|
|
30730
|
+
return balance.token.address === l1address;
|
|
30731
|
+
});
|
|
30732
|
+
if (!l1balance) continue;
|
|
30733
|
+
// Get the total amount using slippage to ensure a small buffer is added to cover price fluctuations
|
|
30734
|
+
const quotedAmount = quote.quote.amountWithMaxSlippage.value;
|
|
30735
|
+
// Add fees to the quoted amount if the fees are in the same token as the token being swapped
|
|
30736
|
+
const fees = $62e968a3dd87940e$export$8059963805b7876c(quote, tokenAddress);
|
|
30737
|
+
// If the token being bridged is a balance requirement then add this to the total
|
|
30738
|
+
// to ensure when its swapped the balance requirement can still be fulfilled
|
|
30739
|
+
const balanceRequirementAmount = $62e968a3dd87940e$var$getAmountFromBalanceRequirement(balanceRequirements, tokenAddress);
|
|
30740
|
+
// Add all the amounts together
|
|
30741
|
+
const totalAmount = quotedAmount.add(fees).add(balanceRequirementAmount);
|
|
30742
|
+
// Subtract any L2 balance from the total amount to only bridge the necessary amount
|
|
30743
|
+
const amountToBridge = l2balance ? totalAmount.sub(l2balance.balance) : totalAmount;
|
|
30744
|
+
if (amountToBridge.lte(0)) continue;
|
|
30745
|
+
if (amountToBridge.gt(l1balance.balance)) continue;
|
|
30746
|
+
bridgeRequirements.push({
|
|
30747
|
+
amount: amountToBridge,
|
|
30748
|
+
formattedAmount: (utils$1).formatUnits(amountToBridge, l1balance.token.decimals),
|
|
30749
|
+
l2address: // L2 address is used for the bridge requirement as the bridge route uses the indexer to find L1 address
|
|
30750
|
+
l2address
|
|
30751
|
+
});
|
|
30752
|
+
}
|
|
30753
|
+
return bridgeRequirements;
|
|
30754
|
+
};
|
|
30755
|
+
|
|
30756
|
+
|
|
30757
|
+
|
|
30758
|
+
const $7500587317643fc8$export$c3e193fd573f1a94 = async (config, swappableTokens)=>{
|
|
30759
|
+
const l1tol2addressMappingPromises = swappableTokens.map((token)=>($887d24b47765b1c0$export$952cdf461a00a8c6)(config, token.address ?? ""));
|
|
30760
|
+
return await Promise.all(l1tol2addressMappingPromises);
|
|
30761
|
+
};
|
|
30762
|
+
|
|
30763
|
+
|
|
30764
|
+
|
|
30765
|
+
|
|
30766
|
+
const $d54df4a884f14123$export$d46f2133747ffd93 = async (config, dexQuoteCache, ownerAddress, requiredTokenAddress, insufficientRequirement, filteredSwappableTokens)=>{
|
|
30767
|
+
const filteredSwappableTokensAddresses = [];
|
|
30768
|
+
for (const token of filteredSwappableTokens){
|
|
30769
|
+
if (!token.address) continue;
|
|
30770
|
+
filteredSwappableTokensAddresses.push(token.address);
|
|
30771
|
+
}
|
|
30772
|
+
const dexQuotes = await ($3ee85f12225c19f3$export$fb80fe94a81a3132)(config, dexQuoteCache, ownerAddress, {
|
|
30773
|
+
address: requiredTokenAddress,
|
|
30774
|
+
amount: insufficientRequirement.delta.balance
|
|
30775
|
+
}, filteredSwappableTokensAddresses);
|
|
30776
|
+
return dexQuotes;
|
|
30777
|
+
};
|
|
30778
|
+
|
|
30779
|
+
|
|
30780
|
+
const $afd57acae9471ac5$export$b94e88f4f8805f71 = (bridgeableTokens, swappableTokens, l1balances, l2balances, availableRoutingOptions, requiredTokenAddress)=>{
|
|
30781
|
+
if (bridgeableTokens.length === 0) return true;
|
|
30782
|
+
if (swappableTokens.length === 0) return true;
|
|
30783
|
+
if (l1balances.length === 0) return true;
|
|
30784
|
+
if (l2balances.length === 0) return true;
|
|
30785
|
+
if (!availableRoutingOptions.bridge) return true;
|
|
30786
|
+
if (!availableRoutingOptions.swap) return true;
|
|
30787
|
+
if (requiredTokenAddress === undefined) return true;
|
|
30788
|
+
if (requiredTokenAddress === "") return true;
|
|
30789
|
+
return false;
|
|
30790
|
+
};
|
|
30791
|
+
const $afd57acae9471ac5$export$ed7c59bd8d1bb5a7 = (requiredTokenAddress, bridgeableTokens, swappableTokens, l1tol2Addresses)=>{
|
|
30792
|
+
const filteredSwappableTokens = [];
|
|
30793
|
+
for (const addresses of l1tol2Addresses){
|
|
30794
|
+
if (addresses.l1address === "") continue;
|
|
30795
|
+
if (addresses.l2address === "") continue;
|
|
30796
|
+
if (!bridgeableTokens.includes(addresses.l1address)) continue;
|
|
30797
|
+
// Filter out the token that is required from the swappable tokens list
|
|
30798
|
+
if (addresses.l2address === requiredTokenAddress) continue;
|
|
30799
|
+
const tokenInfo = swappableTokens.find((token)=>token.address === addresses.l2address);
|
|
30800
|
+
if (!tokenInfo) continue;
|
|
30801
|
+
filteredSwappableTokens.push(tokenInfo);
|
|
30802
|
+
}
|
|
30803
|
+
return filteredSwappableTokens;
|
|
30804
|
+
};
|
|
30805
|
+
// Modifies a users balance to include the amount as if the user successfully bridged
|
|
30806
|
+
// This is so the swap route can check against the balance once the user has performed a bridge
|
|
30807
|
+
const $afd57acae9471ac5$var$modifyTokenBalancesWithBridgedAmount = (config, tokenBalances, l2balances, bridgedTokens, swappableTokens)=>{
|
|
30808
|
+
const modifiedTokenBalances = new Map();
|
|
30809
|
+
for (const [chainId, tokenBalance] of tokenBalances)modifiedTokenBalances.set(chainId, {
|
|
30810
|
+
success: tokenBalance.success,
|
|
30811
|
+
balances: tokenBalance.balances
|
|
30812
|
+
});
|
|
30813
|
+
// Construct a map of balances to the L2 token address to make
|
|
30814
|
+
// it easier to adjust the balances for the tokens that can be bridged
|
|
30815
|
+
const balanceMap = new Map();
|
|
30816
|
+
for (const balance of l2balances){
|
|
30817
|
+
if (!balance.token.address) continue;
|
|
30818
|
+
balanceMap.set(balance.token.address, balance);
|
|
30819
|
+
}
|
|
30820
|
+
// Go through each of the tokens that can be bridged
|
|
30821
|
+
// and adjust the balances to fake the bridge
|
|
30822
|
+
for (const bridgedToken of bridgedTokens){
|
|
30823
|
+
const { amount: amount, l2address: l2address } = bridgedToken;
|
|
30824
|
+
if (l2address === "") continue;
|
|
30825
|
+
let l2balance = (BigNumber$1).from(0);
|
|
30826
|
+
// Find the current balance of this token
|
|
30827
|
+
const currentBalance = balanceMap.get(l2address);
|
|
30828
|
+
if (currentBalance) l2balance = currentBalance.balance;
|
|
30829
|
+
const newBalance = l2balance.add(amount);
|
|
30830
|
+
const tokenInfo = swappableTokens.find((token)=>token.address === l2address);
|
|
30831
|
+
balanceMap.set(l2address, {
|
|
30832
|
+
balance: newBalance,
|
|
30833
|
+
formattedBalance: (utils$1).formatUnits(newBalance, tokenInfo.decimals),
|
|
30834
|
+
token: tokenInfo
|
|
30835
|
+
});
|
|
30836
|
+
}
|
|
30837
|
+
const updatedBalances = Array.from(balanceMap.values());
|
|
30838
|
+
modifiedTokenBalances.set(($4013c5c91bb535f6$export$c9af4e4b001c6476)(config), {
|
|
30839
|
+
success: true,
|
|
30840
|
+
balances: updatedBalances
|
|
30841
|
+
});
|
|
30842
|
+
return modifiedTokenBalances;
|
|
30843
|
+
};
|
|
30844
|
+
const $afd57acae9471ac5$export$1fc63300bde5e690 = (tokenBalances, swapRoutes)=>{
|
|
30845
|
+
const originalSwapSteps = [];
|
|
30846
|
+
for (const route of swapRoutes){
|
|
30847
|
+
const { chainId: chainId, asset: asset } = route;
|
|
30848
|
+
const tokenBalance = tokenBalances.get(chainId);
|
|
30849
|
+
if (!tokenBalance) continue;
|
|
30850
|
+
let originalBalance = (BigNumber$1).from(0);
|
|
30851
|
+
let originalFormattedBalance = "0";
|
|
30852
|
+
const l2balance = tokenBalance.balances.find((balance)=>balance.token.address === asset.token.address);
|
|
30853
|
+
if (l2balance) {
|
|
30854
|
+
originalBalance = l2balance.balance;
|
|
30855
|
+
originalFormattedBalance = l2balance.formattedBalance;
|
|
30856
|
+
}
|
|
30857
|
+
route.asset.balance = originalBalance;
|
|
30858
|
+
route.asset.formattedBalance = originalFormattedBalance;
|
|
30859
|
+
originalSwapSteps.push(route);
|
|
30860
|
+
}
|
|
30861
|
+
return originalSwapSteps;
|
|
30862
|
+
};
|
|
30863
|
+
const $afd57acae9471ac5$export$d9b96654eebdaf2a = (bridgeFundingSteps, swapFundingSteps, l1tol2Addresses)=>{
|
|
30864
|
+
const bridgeAndSwapRoutes = [];
|
|
30865
|
+
for (const bridgeFundingStep of bridgeFundingSteps){
|
|
30866
|
+
if (!bridgeFundingStep) continue;
|
|
30867
|
+
const mapping = l1tol2Addresses.find((addresses)=>{
|
|
30868
|
+
if (bridgeFundingStep.asset.token.address === undefined) return addresses.l1address === ($887d24b47765b1c0$export$c37d8687c27b9660) && addresses.l2address;
|
|
30869
|
+
return addresses.l1address === bridgeFundingStep.asset.token.address && addresses.l2address;
|
|
30870
|
+
});
|
|
30871
|
+
if (!mapping) continue;
|
|
30872
|
+
const swapFundingStep = swapFundingSteps.find((step)=>step.asset.token.address === mapping.l2address);
|
|
30873
|
+
if (!swapFundingStep) continue;
|
|
30874
|
+
bridgeAndSwapRoutes.push({
|
|
30875
|
+
bridgeFundingStep: bridgeFundingStep,
|
|
30876
|
+
swapFundingStep: swapFundingStep
|
|
30877
|
+
});
|
|
30878
|
+
}
|
|
30879
|
+
return bridgeAndSwapRoutes;
|
|
30880
|
+
};
|
|
30881
|
+
const $afd57acae9471ac5$export$f95ed27e871fe308 = async (config, readOnlyProviders, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, feeEstimates, tokenBalances, bridgeableTokens, swappableTokens, balanceRequirements)=>{
|
|
30882
|
+
const { l1balances: l1balances, l2balances: l2balances } = ($7bb5af1d8b5d9127$export$8280985cc3da7882)(config, tokenBalances);
|
|
30883
|
+
const requiredTokenAddress = insufficientRequirement.required.token.address;
|
|
30884
|
+
if ($afd57acae9471ac5$export$b94e88f4f8805f71(bridgeableTokens, swappableTokens, l1balances, l2balances, availableRoutingOptions, requiredTokenAddress)) return [];
|
|
30885
|
+
// Fetch L2 to L1 address mapping and based on the L1 address existing then
|
|
30886
|
+
// filter the bridgeable and swappable tokens list further to only include
|
|
30887
|
+
// tokens that can be both swapped and bridged
|
|
30888
|
+
const l1tol2Addresses = await ($7500587317643fc8$export$c3e193fd573f1a94)(config, swappableTokens);
|
|
30889
|
+
const filteredSwappableTokens = $afd57acae9471ac5$export$ed7c59bd8d1bb5a7(requiredTokenAddress, bridgeableTokens, swappableTokens, l1tol2Addresses);
|
|
30890
|
+
if (filteredSwappableTokens.length === 0) return [];
|
|
30891
|
+
// Fetch all the dex quotes from the list of swappable tokens
|
|
30892
|
+
const dexQuotes = await ($d54df4a884f14123$export$d46f2133747ffd93)(config, dexQuoteCache, ownerAddress, requiredTokenAddress, insufficientRequirement, filteredSwappableTokens);
|
|
30893
|
+
// Construct bridge requirements based on L2 balances, slippage and swap fees
|
|
30894
|
+
const bridgeRequirements = ($62e968a3dd87940e$export$df667c749c93b110)(dexQuotes, l1balances, l2balances, l1tol2Addresses, balanceRequirements);
|
|
30895
|
+
if (bridgeRequirements.length === 0) return [];
|
|
30896
|
+
// Create a mapping of bridge routes to L2 addresses
|
|
30897
|
+
const bridgePromises = new Map();
|
|
30898
|
+
// Create map of bridgeable tokens to make it easier to get the amount that was bridged when modifying the users balance later
|
|
30899
|
+
const bridgeableRequirementsMap = new Map();
|
|
30900
|
+
const bridgedTokens = [];
|
|
30901
|
+
for (const bridgeRequirement of bridgeRequirements){
|
|
30902
|
+
if (!bridgeRequirement.l2address) continue;
|
|
30903
|
+
bridgePromises.set(bridgeRequirement.l2address, ($fa9ac5bfdbbf9dfa$export$ddc7ba2b57d7c5fa)(config, readOnlyProviders, ownerAddress, availableRoutingOptions, bridgeRequirement, tokenBalances, feeEstimates));
|
|
30904
|
+
bridgeableRequirementsMap.set(bridgeRequirement.l2address, {
|
|
30905
|
+
amount: bridgeRequirement.amount,
|
|
30906
|
+
formattedAmount: bridgeRequirement.formattedAmount,
|
|
30907
|
+
l2address: bridgeRequirement.l2address
|
|
30908
|
+
});
|
|
30909
|
+
}
|
|
30910
|
+
const bridgeResults = await Promise.all(bridgePromises.values());
|
|
30911
|
+
const bridgeKeys = Array.from(bridgePromises.keys());
|
|
30912
|
+
// Create an array to store all the tokens that are able to be bridged
|
|
30913
|
+
const swappableTokensAfterBridging = [];
|
|
30914
|
+
// Iterate through all the bridge route results
|
|
30915
|
+
// If a bridge route result was successful then add this token to the
|
|
30916
|
+
// list of tokens that should be checked with the swap route
|
|
30917
|
+
bridgeResults.forEach((result, index)=>{
|
|
30918
|
+
const key = bridgeKeys[index];
|
|
30919
|
+
if (result === undefined) return;
|
|
30920
|
+
swappableTokensAfterBridging.push(key);
|
|
30921
|
+
const bridgedToken = bridgeableRequirementsMap.get(key);
|
|
30922
|
+
if (!bridgedToken) return;
|
|
30923
|
+
bridgedTokens.push({
|
|
30924
|
+
amount: bridgedToken.amount,
|
|
30925
|
+
formattedAmount: bridgedToken.formattedAmount,
|
|
30926
|
+
l2address: bridgedToken.l2address
|
|
30927
|
+
});
|
|
30928
|
+
});
|
|
30929
|
+
// Bridge route determined that no tokens could be bridged
|
|
30930
|
+
if (swappableTokensAfterBridging.length === 0) return [];
|
|
30931
|
+
if (bridgedTokens.length === 0) return []; // No tokens were bridged
|
|
30932
|
+
// Modify the users L2 balance to include the amount as if the user successfully bridged
|
|
30933
|
+
const modifiedTokenBalances = $afd57acae9471ac5$var$modifyTokenBalancesWithBridgedAmount(config, tokenBalances, l2balances, bridgedTokens, swappableTokens);
|
|
30934
|
+
// Call the swap route with the faked bridged balances
|
|
30935
|
+
const swapRoutes = await ($91807edfd7057288$export$8e03ea04d59f2402)(config, availableRoutingOptions, dexQuoteCache, ownerAddress, insufficientRequirement, modifiedTokenBalances, swappableTokensAfterBridging);
|
|
30936
|
+
if (!swapRoutes) return [];
|
|
30937
|
+
const originalBalanceSwapRoutes = $afd57acae9471ac5$export$1fc63300bde5e690(tokenBalances, swapRoutes);
|
|
30938
|
+
return $afd57acae9471ac5$export$d9b96654eebdaf2a(bridgeResults, originalBalanceSwapRoutes, l1tol2Addresses);
|
|
30939
|
+
};
|
|
30940
|
+
|
|
30621
30941
|
|
|
30622
30942
|
|
|
30623
30943
|
|
|
@@ -30648,6 +30968,7 @@ const $5649bc8af91da370$export$1fb2bd867f4a9be3 = async (config, availableRoutin
|
|
|
30648
30968
|
|
|
30649
30969
|
|
|
30650
30970
|
|
|
30971
|
+
|
|
30651
30972
|
const $c16168a9c28ae4fd$var$hasAvailableRoutingOptions = (availableRoutingOptions)=>availableRoutingOptions.bridge || availableRoutingOptions.swap || availableRoutingOptions.onRamp;
|
|
30652
30973
|
const $c16168a9c28ae4fd$export$31ce7ba1a2956195 = (balanceRequirements)=>{
|
|
30653
30974
|
let insufficientBalanceCount = 0;
|
|
@@ -30659,6 +30980,18 @@ const $c16168a9c28ae4fd$export$31ce7ba1a2956195 = (balanceRequirements)=>{
|
|
|
30659
30980
|
if (insufficientBalanceCount === 1) return insufficientRequirement;
|
|
30660
30981
|
return undefined;
|
|
30661
30982
|
};
|
|
30983
|
+
const $c16168a9c28ae4fd$export$ab86023c267660 = async (config, readOnlyProviders, availableRoutingOptions, insufficientRequirement, ownerAddress, tokenBalances, feeEstimates)=>{
|
|
30984
|
+
let bridgeFundingStep;
|
|
30985
|
+
if (insufficientRequirement === undefined) return undefined;
|
|
30986
|
+
if (insufficientRequirement.type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE && insufficientRequirement.type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) return undefined;
|
|
30987
|
+
const bridgeRequirement = {
|
|
30988
|
+
amount: insufficientRequirement.delta.balance,
|
|
30989
|
+
formattedAmount: insufficientRequirement.delta.formattedBalance,
|
|
30990
|
+
l2address: insufficientRequirement.required.token.address ?? ""
|
|
30991
|
+
};
|
|
30992
|
+
if (availableRoutingOptions.bridge && insufficientRequirement) bridgeFundingStep = await ($fa9ac5bfdbbf9dfa$export$ddc7ba2b57d7c5fa)(config, readOnlyProviders, ownerAddress, availableRoutingOptions, bridgeRequirement, tokenBalances, feeEstimates);
|
|
30993
|
+
return bridgeFundingStep;
|
|
30994
|
+
};
|
|
30662
30995
|
const $c16168a9c28ae4fd$export$814624e957fa0f11 = async (config, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, swapTokenAllowList)=>{
|
|
30663
30996
|
const fundingSteps = [];
|
|
30664
30997
|
if (!availableRoutingOptions.swap) return fundingSteps;
|
|
@@ -30672,6 +31005,27 @@ const $c16168a9c28ae4fd$export$814624e957fa0f11 = async (config, availableRoutin
|
|
|
30672
31005
|
if (swappableTokens.length === 0) return fundingSteps;
|
|
30673
31006
|
return await ($91807edfd7057288$export$8e03ea04d59f2402)(config, availableRoutingOptions, dexQuoteCache, ownerAddress, insufficientRequirement, tokenBalances, swappableTokens);
|
|
30674
31007
|
};
|
|
31008
|
+
const $c16168a9c28ae4fd$export$2becd43da9d21f73 = async (config, readOnlyProviders, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, tokenAllowList, feeEstimates, balanceRequirements)=>{
|
|
31009
|
+
if (!insufficientRequirement) return [];
|
|
31010
|
+
const l1balancesResult = tokenBalances.get(($4013c5c91bb535f6$export$9b794d067cdd1af6)(config));
|
|
31011
|
+
const l2balancesResult = tokenBalances.get(($4013c5c91bb535f6$export$c9af4e4b001c6476)(config));
|
|
31012
|
+
// If there are no l1 balance then cannot bridge
|
|
31013
|
+
if (!l1balancesResult) return [];
|
|
31014
|
+
if (l1balancesResult.error !== undefined || !l1balancesResult.success) return [];
|
|
31015
|
+
// If there are no l2 balance then cannot swap
|
|
31016
|
+
if (!l2balancesResult) return [];
|
|
31017
|
+
if (l2balancesResult.error !== undefined || !l2balancesResult.success) return [];
|
|
31018
|
+
// Get a list of all the swappable tokens
|
|
31019
|
+
const bridgeTokenAllowList = tokenAllowList?.bridge ?? [];
|
|
31020
|
+
const bridgeableL1Addresses = bridgeTokenAllowList.map((token)=>{
|
|
31021
|
+
if (token.address === undefined) return $887d24b47765b1c0$export$c37d8687c27b9660;
|
|
31022
|
+
return token.address;
|
|
31023
|
+
});
|
|
31024
|
+
const swapTokenAllowList = tokenAllowList?.swap ?? [];
|
|
31025
|
+
if (insufficientRequirement.type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE && insufficientRequirement.type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) return [];
|
|
31026
|
+
const routes = await ($afd57acae9471ac5$export$f95ed27e871fe308)(config, readOnlyProviders, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, feeEstimates, tokenBalances, bridgeableL1Addresses, swapTokenAllowList, balanceRequirements);
|
|
31027
|
+
return routes;
|
|
31028
|
+
};
|
|
30675
31029
|
const $c16168a9c28ae4fd$export$e1b6e4d22d0365ee = async (config, availableRoutingOptions, insufficientRequirement)=>{
|
|
30676
31030
|
if (!availableRoutingOptions.onRamp) return undefined;
|
|
30677
31031
|
if (insufficientRequirement === undefined) return undefined;
|
|
@@ -30700,16 +31054,24 @@ const $c16168a9c28ae4fd$export$92606e71d0a264ff = async (config, ownerAddress, b
|
|
|
30700
31054
|
const feeEstimates = new Map();
|
|
30701
31055
|
// Dex quotes cache
|
|
30702
31056
|
const dexQuoteCache = new Map();
|
|
30703
|
-
// Ensures only 1 balance requirement is insufficient
|
|
31057
|
+
// Ensures only 1 balance requirement is insufficient
|
|
30704
31058
|
const insufficientRequirement = $c16168a9c28ae4fd$export$31ce7ba1a2956195(balanceRequirements);
|
|
31059
|
+
const routePromises = [];
|
|
31060
|
+
routePromises.push($c16168a9c28ae4fd$export$ab86023c267660(config, readOnlyProviders, availableRoutingOptions, insufficientRequirement, ownerAddress, tokenBalances, feeEstimates));
|
|
31061
|
+
routePromises.push($c16168a9c28ae4fd$export$814624e957fa0f11(config, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, allowList.swap));
|
|
31062
|
+
routePromises.push($c16168a9c28ae4fd$export$e1b6e4d22d0365ee(config, availableRoutingOptions, insufficientRequirement));
|
|
31063
|
+
routePromises.push($c16168a9c28ae4fd$export$2becd43da9d21f73(config, readOnlyProviders, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, allowList, feeEstimates, balanceRequirements));
|
|
31064
|
+
const resolved = await Promise.all(routePromises);
|
|
30705
31065
|
let bridgeFundingStep;
|
|
30706
|
-
|
|
30707
|
-
|
|
30708
|
-
|
|
30709
|
-
|
|
30710
|
-
|
|
30711
|
-
|
|
30712
|
-
|
|
31066
|
+
let swapFundingSteps = [];
|
|
31067
|
+
let onRampFundingStep;
|
|
31068
|
+
let bridgeAndSwapFundingSteps = [];
|
|
31069
|
+
resolved.forEach((result, index)=>{
|
|
31070
|
+
if (index === 0) bridgeFundingStep = result;
|
|
31071
|
+
if (index === 1) swapFundingSteps = result;
|
|
31072
|
+
if (index === 2) onRampFundingStep = result;
|
|
31073
|
+
if (index === 3) bridgeAndSwapFundingSteps = result;
|
|
31074
|
+
});
|
|
30713
31075
|
const response = {
|
|
30714
31076
|
response: {
|
|
30715
31077
|
type: ($b23305044c0e096a$export$3057de18ac0c076).NO_ROUTES,
|
|
@@ -30718,7 +31080,7 @@ const $c16168a9c28ae4fd$export$92606e71d0a264ff = async (config, ownerAddress, b
|
|
|
30718
31080
|
fundingRoutes: []
|
|
30719
31081
|
};
|
|
30720
31082
|
let priority = 0;
|
|
30721
|
-
if (bridgeFundingStep || swapFundingSteps.length > 0 || onRampFundingStep) {
|
|
31083
|
+
if (bridgeFundingStep || swapFundingSteps.length > 0 || onRampFundingStep || bridgeAndSwapFundingSteps.length > 0) {
|
|
30722
31084
|
response.response.type = ($b23305044c0e096a$export$3057de18ac0c076).ROUTES_FOUND;
|
|
30723
31085
|
response.response.message = "Routes found";
|
|
30724
31086
|
}
|
|
@@ -30751,6 +31113,22 @@ const $c16168a9c28ae4fd$export$92606e71d0a264ff = async (config, ownerAddress, b
|
|
|
30751
31113
|
]
|
|
30752
31114
|
});
|
|
30753
31115
|
}
|
|
31116
|
+
if (bridgeAndSwapFundingSteps) {
|
|
31117
|
+
priority++;
|
|
31118
|
+
bridgeAndSwapFundingSteps.forEach((bridgeAndSwapFundingStep)=>{
|
|
31119
|
+
const bridgeStep = bridgeAndSwapFundingStep.bridgeFundingStep;
|
|
31120
|
+
const swapStep = bridgeAndSwapFundingStep.swapFundingStep;
|
|
31121
|
+
response.fundingRoutes.push({
|
|
31122
|
+
priority: priority,
|
|
31123
|
+
steps: [
|
|
31124
|
+
bridgeStep,
|
|
31125
|
+
swapStep
|
|
31126
|
+
]
|
|
31127
|
+
});
|
|
31128
|
+
});
|
|
31129
|
+
}
|
|
31130
|
+
// eslint-disable-next-line no-console
|
|
31131
|
+
console.log("** response", response);
|
|
30754
31132
|
return response;
|
|
30755
31133
|
};
|
|
30756
31134
|
|
|
@@ -30925,7 +31303,6 @@ const $a7367d01c6e76b1c$export$d62081fac18000c2 = (orderHash, orderComponents, a
|
|
|
30925
31303
|
|
|
30926
31304
|
|
|
30927
31305
|
|
|
30928
|
-
|
|
30929
31306
|
const $9051cee080948594$export$9ac1563efd38130 = 1; // 100%
|
|
30930
31307
|
const $9051cee080948594$export$768e717351d4b176 = 6; // will allow 0.000001 (0.0001%) as the minimum value
|
|
30931
31308
|
const $9051cee080948594$var$calculateFeesPercent = (orderFee, amountBn)=>{
|
|
@@ -30937,7 +31314,7 @@ const $9051cee080948594$var$calculateFeesPercent = (orderFee, amountBn)=>{
|
|
|
30937
31314
|
};
|
|
30938
31315
|
const $9051cee080948594$var$calculateFeesToken = (orderFee, decimals)=>{
|
|
30939
31316
|
const feeToken = orderFee.amount;
|
|
30940
|
-
const bnFeeAmount = (
|
|
31317
|
+
const bnFeeAmount = (utils$1).parseUnits(feeToken.token, decimals);
|
|
30941
31318
|
return bnFeeAmount;
|
|
30942
31319
|
};
|
|
30943
31320
|
const $9051cee080948594$export$1e69c9cfc42e28d8 = (orderFees, weiAmount, decimals = 18)=>{
|
|
@@ -31169,7 +31546,6 @@ const $9c3db1bb9c8b69d3$export$70b61ad426ddbe54 = async (config, provider, order
|
|
|
31169
31546
|
|
|
31170
31547
|
|
|
31171
31548
|
|
|
31172
|
-
|
|
31173
31549
|
const $9085b221b72ac69e$export$af768ccdf17d5c04 = (id, contractAddress, spenderAddress)=>({
|
|
31174
31550
|
type: ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC721,
|
|
31175
31551
|
id: id,
|
|
@@ -31177,7 +31553,7 @@ const $9085b221b72ac69e$export$af768ccdf17d5c04 = (id, contractAddress, spenderA
|
|
|
31177
31553
|
spenderAddress: spenderAddress
|
|
31178
31554
|
});
|
|
31179
31555
|
const $9085b221b72ac69e$export$586d02673c66d423 = (buyToken, decimals = 18)=>{
|
|
31180
|
-
const bnAmount = (
|
|
31556
|
+
const bnAmount = (utils$1).parseUnits(buyToken.amount, decimals);
|
|
31181
31557
|
if (buyToken.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE) return {
|
|
31182
31558
|
type: ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE,
|
|
31183
31559
|
amount: bnAmount.toString()
|
|
@@ -31358,11 +31734,11 @@ async function $d35036efee31c5d1$export$dc8635800ef20f4b(provider, requirements)
|
|
|
31358
31734
|
const itemRequirements = requirements.map((itemRequirementParam, index)=>{
|
|
31359
31735
|
if (itemRequirementParam.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE) return {
|
|
31360
31736
|
...itemRequirementParam,
|
|
31361
|
-
amount: (
|
|
31737
|
+
amount: (utils$1).parseUnits(itemRequirementParam.amount, 18)
|
|
31362
31738
|
};
|
|
31363
31739
|
if (itemRequirementParam.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) return {
|
|
31364
31740
|
...itemRequirementParam,
|
|
31365
|
-
amount: (
|
|
31741
|
+
amount: (utils$1).parseUnits(itemRequirementParam.amount, decimals[index])
|
|
31366
31742
|
};
|
|
31367
31743
|
return itemRequirementParam;
|
|
31368
31744
|
});
|
|
@@ -31621,7 +31997,7 @@ var checkout_sdk = /*#__PURE__*/Object.freeze({
|
|
|
31621
31997
|
function $parcel$export(e, n, v, s) {
|
|
31622
31998
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
31623
31999
|
}
|
|
31624
|
-
const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.22.
|
|
32000
|
+
const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.22.2";
|
|
31625
32001
|
const $d663162fd5a0853f$export$83bf90b30cdfd29f = ()=>false;
|
|
31626
32002
|
const $d663162fd5a0853f$export$1169f5475725171b = ()=>$d663162fd5a0853f$export$38a083d9fb5551ca;
|
|
31627
32003
|
|
|
@@ -31686,6 +32062,7 @@ var $207ed853f11d19d5$export$5a0ace85cae72d45;
|
|
|
31686
32062
|
IMTBLWidgetEvents["IMTBL_SWAP_WIDGET_EVENT"] = "imtbl-swap-widget";
|
|
31687
32063
|
IMTBLWidgetEvents["IMTBL_BRIDGE_WIDGET_EVENT"] = "imtbl-bridge-widget";
|
|
31688
32064
|
IMTBLWidgetEvents["IMTBL_ONRAMP_WIDGET_EVENT"] = "imtbl-onramp-widget";
|
|
32065
|
+
IMTBLWidgetEvents["IMTBL_PRIMARY_REVENUE_WIDGET_EVENT"] = "imtbl-primary-revenue-widget";
|
|
31689
32066
|
})($207ed853f11d19d5$export$5a0ace85cae72d45 || ($207ed853f11d19d5$export$5a0ace85cae72d45 = {}));
|
|
31690
32067
|
|
|
31691
32068
|
|
|
@@ -31725,6 +32102,20 @@ $parcel$export($53d219e7f6bf0cd6$exports, "SwapEventType", () => $53d219e7f6bf0c
|
|
|
31725
32102
|
})($53d219e7f6bf0cd6$export$140a49745ab55563 || ($53d219e7f6bf0cd6$export$140a49745ab55563 = {}));
|
|
31726
32103
|
|
|
31727
32104
|
|
|
32105
|
+
var $8c83f59522c4ca40$exports = {};
|
|
32106
|
+
|
|
32107
|
+
$parcel$export($8c83f59522c4ca40$exports, "PrimaryRevenueEventType", () => $8c83f59522c4ca40$export$b33478ffb988bd5e);
|
|
32108
|
+
/**
|
|
32109
|
+
* Enum representing possible Primary Revenue Widget event types.
|
|
32110
|
+
*/ var $8c83f59522c4ca40$export$b33478ffb988bd5e;
|
|
32111
|
+
(function(PrimaryRevenueEventType) {
|
|
32112
|
+
PrimaryRevenueEventType["CLOSE_WIDGET"] = "close-widget";
|
|
32113
|
+
PrimaryRevenueEventType["SUCCESS"] = "success";
|
|
32114
|
+
PrimaryRevenueEventType["FAILURE"] = "failure";
|
|
32115
|
+
PrimaryRevenueEventType["REJECTED"] = "rejected";
|
|
32116
|
+
})($8c83f59522c4ca40$export$b33478ffb988bd5e || ($8c83f59522c4ca40$export$b33478ffb988bd5e = {}));
|
|
32117
|
+
|
|
32118
|
+
|
|
31728
32119
|
var $15cc9e120aa6f3bf$exports = {};
|
|
31729
32120
|
|
|
31730
32121
|
$parcel$export($15cc9e120aa6f3bf$exports, "BridgeEventType", () => $15cc9e120aa6f3bf$export$d1bfa21f7c76447a);
|
|
@@ -31991,6 +32382,7 @@ var checkout_widgets = /*#__PURE__*/Object.freeze({
|
|
|
31991
32382
|
get OnRampEventType () { return $d882ddc5600b1284$export$66ec39c0924078d8; },
|
|
31992
32383
|
OnRampReact: $f94f63f2c041a04c$export$9e363c61ea99bbb4,
|
|
31993
32384
|
get OrchestrationEventType () { return $ad06b030b1a3ba34$export$b80d2daf830437b9; },
|
|
32385
|
+
get PrimaryRevenueEventType () { return $8c83f59522c4ca40$export$b33478ffb988bd5e; },
|
|
31994
32386
|
get SwapEventType () { return $53d219e7f6bf0cd6$export$140a49745ab55563; },
|
|
31995
32387
|
SwapReact: $a4fbb8e3a6aeff58$export$971e031379577f4,
|
|
31996
32388
|
UpdateConfig: $430e3eda76fa4d5f$export$bf1548ba7e61c17f,
|