@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/checkout_sdk.js
CHANGED
|
@@ -9,7 +9,6 @@ import { keccak256 as keccak256$1 } from '@ethersproject/solidity';
|
|
|
9
9
|
import { SwapRouter } from '@uniswap/router-sdk';
|
|
10
10
|
import FormData from 'form-data';
|
|
11
11
|
import { Seaport as Seaport$1 } from '@opensea/seaport-js';
|
|
12
|
-
import { parseUnits } from 'ethers/lib/utils';
|
|
13
12
|
|
|
14
13
|
var Environment$1;
|
|
15
14
|
(function (Environment) {
|
|
@@ -16922,11 +16921,14 @@ class Orderbook {
|
|
|
16922
16921
|
})),
|
|
16923
16922
|
},
|
|
16924
16923
|
]);
|
|
16925
|
-
if (fulfillmentDataRes.result.length
|
|
16926
|
-
throw new Error(
|
|
16924
|
+
if (fulfillmentDataRes.result.unfulfillable_orders?.length > 0) {
|
|
16925
|
+
throw new Error(`Unable to prepare fulfillment date: ${fulfillmentDataRes.result.unfulfillable_orders[0].reason}`);
|
|
16927
16926
|
}
|
|
16928
|
-
|
|
16929
|
-
|
|
16927
|
+
else if (fulfillmentDataRes.result.fulfillable_orders?.length !== 1) {
|
|
16928
|
+
throw new Error('unexpected fulfillable order result length');
|
|
16929
|
+
}
|
|
16930
|
+
const extraData = fulfillmentDataRes.result.fulfillable_orders[0].extra_data;
|
|
16931
|
+
const orderResult = fulfillmentDataRes.result.fulfillable_orders[0].order;
|
|
16930
16932
|
if (orderResult.status !== OrderStatus$1.ACTIVE) {
|
|
16931
16933
|
throw new Error(`Cannot fulfil order that is not active. Current status: ${orderResult.status}`);
|
|
16932
16934
|
}
|
|
@@ -19813,7 +19815,7 @@ class APIError extends Error {
|
|
|
19813
19815
|
|
|
19814
19816
|
/* eslint-disable implicit-arrow-linebreak */
|
|
19815
19817
|
const defaultHeaders = {
|
|
19816
|
-
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.22.
|
|
19818
|
+
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.22.2',
|
|
19817
19819
|
};
|
|
19818
19820
|
/**
|
|
19819
19821
|
* createAPIConfiguration to create a custom Configuration
|
|
@@ -22244,6 +22246,7 @@ const $7f2e17f026d4fc8d$export$f1ca3744c025ab81 = async (config, provider)=>{
|
|
|
22244
22246
|
|
|
22245
22247
|
|
|
22246
22248
|
|
|
22249
|
+
|
|
22247
22250
|
var $b23305044c0e096a$export$3057de18ac0c076;
|
|
22248
22251
|
(function(RouteCalculatorType) {
|
|
22249
22252
|
RouteCalculatorType["ROUTES_FOUND"] = "ROUTES_FOUND";
|
|
@@ -22305,214 +22308,6 @@ const $33acec7b4a26c053$export$23ddeb2642d2f9d = async (config, readOnlyProvider
|
|
|
22305
22308
|
};
|
|
22306
22309
|
|
|
22307
22310
|
|
|
22308
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
22309
|
-
|
|
22310
|
-
|
|
22311
|
-
|
|
22312
|
-
const $f730af3b727f04ac$export$22fea095b15361de = (balances)=>{
|
|
22313
|
-
for (const balance of balances.balances){
|
|
22314
|
-
if (!balance.token.address || balance.token.address === "") return balance.balance;
|
|
22315
|
-
}
|
|
22316
|
-
return (BigNumber$1).from(0);
|
|
22317
|
-
};
|
|
22318
|
-
|
|
22319
|
-
|
|
22320
|
-
|
|
22321
|
-
|
|
22322
|
-
|
|
22323
|
-
|
|
22324
|
-
const $8a49d1a3783a2640$export$3aff971444a4f244 = async (config, readOnlyProviders)=>{
|
|
22325
|
-
try {
|
|
22326
|
-
const estimate = await (0, $2e7bf45a7c9a9570$export$942c8de7174809fc)({
|
|
22327
|
-
gasEstimateType: (0, $de275b98d2b651c3$export$788b1fd17f3dad84).BRIDGE_TO_L2,
|
|
22328
|
-
isSpendingCapApprovalRequired: false
|
|
22329
|
-
}, readOnlyProviders, config);
|
|
22330
|
-
const gasEstimate = estimate.gasFee.estimatedAmount;
|
|
22331
|
-
const bridgeFee = estimate.bridgeFee.estimatedAmount;
|
|
22332
|
-
let totalFees = (0, BigNumber$1).from(0);
|
|
22333
|
-
if (gasEstimate) totalFees = totalFees.add(gasEstimate);
|
|
22334
|
-
if (bridgeFee) totalFees = totalFees.add(bridgeFee);
|
|
22335
|
-
return totalFees;
|
|
22336
|
-
} catch (err) {
|
|
22337
|
-
throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Error estimating gas for bridge", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).BRIDGE_GAS_ESTIMATE_ERROR, {
|
|
22338
|
-
message: err.message
|
|
22339
|
-
});
|
|
22340
|
-
}
|
|
22341
|
-
};
|
|
22342
|
-
|
|
22343
|
-
|
|
22344
|
-
|
|
22345
|
-
const $823db9fb0ca4bc15$export$c37d8687c27b9660 = "0x0000000000000000000000000000000000000001";
|
|
22346
|
-
const $823db9fb0ca4bc15$export$1430626eec86fce9 = (chainId)=>{
|
|
22347
|
-
if (chainId === ($0472f23319457bfb$export$c06e1e7429de6283).IMTBL_ZKEVM_TESTNET) return "imtbl-zkevm-testnet";
|
|
22348
|
-
return "";
|
|
22349
|
-
};
|
|
22350
|
-
const $823db9fb0ca4bc15$export$53e663abd9b77fc1 = async (chainId, config)=>{
|
|
22351
|
-
const imxMappingConfig = await config.remote.getConfig("imxAddressMapping");
|
|
22352
|
-
return imxMappingConfig[chainId] ?? "";
|
|
22353
|
-
};
|
|
22354
|
-
|
|
22355
|
-
|
|
22356
|
-
|
|
22357
|
-
|
|
22358
|
-
|
|
22359
|
-
|
|
22360
|
-
|
|
22361
|
-
const $07ac9c0576988336$export$7847f5f5cce25dfa = async (config, readOnlyProviders, l1provider, depositorAddress, fromChainId, toChainId, token, depositAmount)=>{
|
|
22362
|
-
try {
|
|
22363
|
-
const tokenBridge = await $67fc622a2b913d5f$export$989eefe1274a439c(fromChainId, toChainId, readOnlyProviders, config);
|
|
22364
|
-
const { unsignedTx: unsignedTx } = await tokenBridge.getUnsignedApproveDepositBridgeTx({
|
|
22365
|
-
depositorAddress: depositorAddress,
|
|
22366
|
-
token: token,
|
|
22367
|
-
depositAmount: depositAmount
|
|
22368
|
-
});
|
|
22369
|
-
if (unsignedTx === null) return (0, BigNumber$1).from(0);
|
|
22370
|
-
return await l1provider.estimateGas(unsignedTx);
|
|
22371
|
-
} catch (err) {
|
|
22372
|
-
throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Error occurred while attempting ot estimate gas for approval transaction", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).BRIDGE_GAS_ESTIMATE_ERROR, {
|
|
22373
|
-
message: err.message
|
|
22374
|
-
});
|
|
22375
|
-
}
|
|
22376
|
-
};
|
|
22377
|
-
const $07ac9c0576988336$export$a3dd181de896b7c7 = async (config, readOnlyProviders, l1provider, depositorAddress, l1Address, delta)=>{
|
|
22378
|
-
if (l1Address === ($823db9fb0ca4bc15$export$c37d8687c27b9660)) return (BigNumber$1).from(0); // Native ETH does not require approval
|
|
22379
|
-
const fromChainId = ($4013c5c91bb535f6$export$9b794d067cdd1af6)(config);
|
|
22380
|
-
const toChainId = ($4013c5c91bb535f6$export$c9af4e4b001c6476)(config);
|
|
22381
|
-
return await $07ac9c0576988336$export$7847f5f5cce25dfa(config, readOnlyProviders, l1provider, depositorAddress, fromChainId, toChainId, l1Address, delta);
|
|
22382
|
-
};
|
|
22383
|
-
|
|
22384
|
-
|
|
22385
|
-
|
|
22386
|
-
|
|
22387
|
-
const $5a5ccedc98d53d25$var$filterTokens = (allowedTokens, balances)=>{
|
|
22388
|
-
if (balances && balances.success) return allowedTokens.filter((token)=>{
|
|
22389
|
-
if ("address" in token) return balances.balances.find((balance)=>balance.token.address === token.address && balance.balance.gt(0));
|
|
22390
|
-
return balances.balances.find((balance)=>!("address" in balance.token) && balance.balance.gt(0));
|
|
22391
|
-
});
|
|
22392
|
-
return [];
|
|
22393
|
-
};
|
|
22394
|
-
const $5a5ccedc98d53d25$export$9ec9fc71f3ce62c4 = async (config, availableRoutingOptions)=>{
|
|
22395
|
-
if (availableRoutingOptions.onRamp) {
|
|
22396
|
-
const onRampOptions = await config.remote.getConfig("onramp");
|
|
22397
|
-
const onRampAllowList = {};
|
|
22398
|
-
Object.entries(onRampOptions).forEach(([onRampProvider, onRampProviderConfig])=>{
|
|
22399
|
-
// Allowed list per onRamp provider
|
|
22400
|
-
onRampAllowList[onRampProvider] = onRampProviderConfig.tokens ?? [];
|
|
22401
|
-
});
|
|
22402
|
-
return onRampAllowList;
|
|
22403
|
-
}
|
|
22404
|
-
return {};
|
|
22405
|
-
};
|
|
22406
|
-
const $5a5ccedc98d53d25$export$d744af9f1c0712bc = async (config, tokenBalances, availableRoutingOptions)=>{
|
|
22407
|
-
if (availableRoutingOptions.bridge) {
|
|
22408
|
-
const allowedTokens = (await config.remote.getConfig("bridge"))?.tokens ?? [];
|
|
22409
|
-
const balances = tokenBalances.get(($4013c5c91bb535f6$export$9b794d067cdd1af6)(config));
|
|
22410
|
-
return $5a5ccedc98d53d25$var$filterTokens(allowedTokens, balances);
|
|
22411
|
-
}
|
|
22412
|
-
return [];
|
|
22413
|
-
};
|
|
22414
|
-
const $5a5ccedc98d53d25$export$87ed7f956d73690 = async (config, tokenBalances, availableRoutingOptions)=>{
|
|
22415
|
-
if (availableRoutingOptions.swap) {
|
|
22416
|
-
const allowedTokens = (await config.remote.getConfig("dex"))?.tokens ?? [];
|
|
22417
|
-
const balances = tokenBalances.get(($4013c5c91bb535f6$export$c9af4e4b001c6476)(config));
|
|
22418
|
-
return $5a5ccedc98d53d25$var$filterTokens(allowedTokens, balances);
|
|
22419
|
-
}
|
|
22420
|
-
return [];
|
|
22421
|
-
};
|
|
22422
|
-
const $5a5ccedc98d53d25$export$1ad29657d49c5440 = async (config, tokenBalances, availableRoutingOptions)=>{
|
|
22423
|
-
const tokenAllowList = {};
|
|
22424
|
-
tokenAllowList.swap = await $5a5ccedc98d53d25$export$87ed7f956d73690(config, tokenBalances, availableRoutingOptions);
|
|
22425
|
-
tokenAllowList.bridge = await $5a5ccedc98d53d25$export$d744af9f1c0712bc(config, tokenBalances, availableRoutingOptions);
|
|
22426
|
-
tokenAllowList.onRamp = await $5a5ccedc98d53d25$export$9ec9fc71f3ce62c4(config, availableRoutingOptions);
|
|
22427
|
-
return tokenAllowList;
|
|
22428
|
-
};
|
|
22429
|
-
|
|
22430
|
-
|
|
22431
|
-
const $fa9ac5bfdbbf9dfa$export$9994ad18c2f0e665 = (balances, totalFees)=>{
|
|
22432
|
-
const balance = ($f730af3b727f04ac$export$22fea095b15361de)(balances);
|
|
22433
|
-
return balance.gte(totalFees);
|
|
22434
|
-
};
|
|
22435
|
-
const $fa9ac5bfdbbf9dfa$export$97330fab5f794e7f = (balanceRequirement)=>{
|
|
22436
|
-
if (balanceRequirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE) return $d85ad1457a3f1a83$export$b80040cb173ba6e9;
|
|
22437
|
-
if (balanceRequirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) return balanceRequirement.required.token.address ?? "";
|
|
22438
|
-
return "";
|
|
22439
|
-
};
|
|
22440
|
-
const $fa9ac5bfdbbf9dfa$export$952cdf461a00a8c6 = async (config, balanceRequirement)=>{
|
|
22441
|
-
const l2address = $fa9ac5bfdbbf9dfa$export$97330fab5f794e7f(balanceRequirement);
|
|
22442
|
-
if (l2address === "") return "";
|
|
22443
|
-
if (l2address === ($d85ad1457a3f1a83$export$b80040cb173ba6e9)) return await ($823db9fb0ca4bc15$export$53e663abd9b77fc1)(($4013c5c91bb535f6$export$9b794d067cdd1af6)(config), config);
|
|
22444
|
-
const chainName = ($823db9fb0ca4bc15$export$1430626eec86fce9)(($4013c5c91bb535f6$export$c9af4e4b001c6476)(config));
|
|
22445
|
-
if (chainName === "") return ""; // Chain name not a valid indexer chain name
|
|
22446
|
-
const blockchainData = ($67fc622a2b913d5f$export$436dd76f23f463ff)(config);
|
|
22447
|
-
const tokenData = await blockchainData.getToken({
|
|
22448
|
-
chainName: chainName,
|
|
22449
|
-
contractAddress: l2address
|
|
22450
|
-
});
|
|
22451
|
-
const l1address = tokenData.result.root_contract_address;
|
|
22452
|
-
if (l1address === null) return ""; // No L1 representation of this token
|
|
22453
|
-
return l1address;
|
|
22454
|
-
};
|
|
22455
|
-
const $fa9ac5bfdbbf9dfa$export$da05aed50d75046 = async (config, readOnlyProviders, feeEstimates)=>{
|
|
22456
|
-
let bridgeFeeEstimate = feeEstimates.get(($4b58188d47aafe8d$export$3af78bb3e8650ee6).BRIDGE);
|
|
22457
|
-
if (bridgeFeeEstimate) return bridgeFeeEstimate;
|
|
22458
|
-
bridgeFeeEstimate = await ($8a49d1a3783a2640$export$3aff971444a4f244)(config, readOnlyProviders);
|
|
22459
|
-
feeEstimates.set(($4b58188d47aafe8d$export$3af78bb3e8650ee6).BRIDGE, bridgeFeeEstimate);
|
|
22460
|
-
return bridgeFeeEstimate;
|
|
22461
|
-
};
|
|
22462
|
-
const $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute = (chainId, balance)=>({
|
|
22463
|
-
type: ($4b58188d47aafe8d$export$3af78bb3e8650ee6).BRIDGE,
|
|
22464
|
-
chainId: chainId,
|
|
22465
|
-
asset: {
|
|
22466
|
-
balance: balance.balance,
|
|
22467
|
-
formattedBalance: balance.formattedBalance,
|
|
22468
|
-
token: {
|
|
22469
|
-
name: balance.token.name,
|
|
22470
|
-
symbol: balance.token.symbol,
|
|
22471
|
-
address: balance.token.address,
|
|
22472
|
-
decimals: balance.token.decimals
|
|
22473
|
-
}
|
|
22474
|
-
}
|
|
22475
|
-
});
|
|
22476
|
-
const $fa9ac5bfdbbf9dfa$export$3139474685e4dedd = (address)=>{
|
|
22477
|
-
if (!address || address === "") return true;
|
|
22478
|
-
return false;
|
|
22479
|
-
};
|
|
22480
|
-
const $fa9ac5bfdbbf9dfa$export$ddc7ba2b57d7c5fa = async (config, readOnlyProviders, depositorAddress, availableRoutingOptions, balanceRequirement, balances, feeEstimates)=>{
|
|
22481
|
-
if (!availableRoutingOptions.bridge) return undefined;
|
|
22482
|
-
const chainId = ($4013c5c91bb535f6$export$9b794d067cdd1af6)(config);
|
|
22483
|
-
const tokenBalanceResult = balances.get(chainId);
|
|
22484
|
-
const l1provider = readOnlyProviders.get(chainId);
|
|
22485
|
-
if (!l1provider) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("No L1 provider available", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).PROVIDER_ERROR, {
|
|
22486
|
-
chainId: chainId.toString()
|
|
22487
|
-
});
|
|
22488
|
-
// If no balances on layer 1 then Bridge cannot be an option
|
|
22489
|
-
if (tokenBalanceResult === undefined || tokenBalanceResult.success === false) return undefined;
|
|
22490
|
-
const allowedTokenList = await ($5a5ccedc98d53d25$export$d744af9f1c0712bc)(config, balances, availableRoutingOptions);
|
|
22491
|
-
if (allowedTokenList.length === 0) return undefined;
|
|
22492
|
-
const bridgeFeeEstimate = await $fa9ac5bfdbbf9dfa$export$da05aed50d75046(config, readOnlyProviders, feeEstimates);
|
|
22493
|
-
// If the user has no ETH to cover the bridge fees or approval fees then bridge cannot be an option
|
|
22494
|
-
if (!$fa9ac5bfdbbf9dfa$export$9994ad18c2f0e665(tokenBalanceResult, bridgeFeeEstimate)) return undefined;
|
|
22495
|
-
const l1address = await $fa9ac5bfdbbf9dfa$export$952cdf461a00a8c6(config, balanceRequirement);
|
|
22496
|
-
if (l1address === "") return undefined;
|
|
22497
|
-
// Ensure l1address is in the allowed token list
|
|
22498
|
-
if (l1address === ($823db9fb0ca4bc15$export$c37d8687c27b9660)) {
|
|
22499
|
-
if (!allowedTokenList.find((token)=>!("address" in token))) return undefined;
|
|
22500
|
-
} else if (!allowedTokenList.find((token)=>token.address === l1address)) return undefined;
|
|
22501
|
-
const gasForApproval = await ($07ac9c0576988336$export$a3dd181de896b7c7)(config, readOnlyProviders, l1provider, depositorAddress, l1address, balanceRequirement.delta.balance);
|
|
22502
|
-
if (!$fa9ac5bfdbbf9dfa$export$9994ad18c2f0e665(tokenBalanceResult, gasForApproval.add(bridgeFeeEstimate))) return undefined;
|
|
22503
|
-
// If the L1 representation of the requirement is ETH then find the ETH balance and check if the balance covers the delta
|
|
22504
|
-
if (l1address === ($823db9fb0ca4bc15$export$c37d8687c27b9660)) {
|
|
22505
|
-
const nativeETHBalance = tokenBalanceResult.balances.find((balance)=>$fa9ac5bfdbbf9dfa$export$3139474685e4dedd(balance.token.address));
|
|
22506
|
-
if (nativeETHBalance && nativeETHBalance.balance.gte(balanceRequirement.delta.balance.add(bridgeFeeEstimate))) return $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute(chainId, nativeETHBalance);
|
|
22507
|
-
return undefined;
|
|
22508
|
-
}
|
|
22509
|
-
// Find the balance of the L1 representation of the token and check if the balance covers the delta
|
|
22510
|
-
const erc20balance = tokenBalanceResult.balances.find((balance)=>balance.token.address === l1address);
|
|
22511
|
-
if (erc20balance && erc20balance.balance.gte(balanceRequirement.delta.balance)) return $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute(chainId, erc20balance);
|
|
22512
|
-
return undefined;
|
|
22513
|
-
};
|
|
22514
|
-
|
|
22515
|
-
|
|
22516
22311
|
|
|
22517
22312
|
|
|
22518
22313
|
|
|
@@ -22541,11 +22336,13 @@ async function $0e0060cb42e136d2$export$339cb2be73677b30(config, existingReadOnl
|
|
|
22541
22336
|
|
|
22542
22337
|
const $049bba630af05555$export$6946a1f17c2bbf26 = async (config, chainId, walletAddress, requiredToken, swappableTokens)=>{
|
|
22543
22338
|
const dexQuotes = new Map();
|
|
22339
|
+
// Apply a small slippage percent as a buffer to cover price fluctuations between token pairs
|
|
22340
|
+
const slippagePercent = 1;
|
|
22544
22341
|
try {
|
|
22545
22342
|
const exchange = await $67fc622a2b913d5f$export$7cf6178417769841(chainId, config);
|
|
22546
22343
|
const dexTransactionResponsePromises = [];
|
|
22547
22344
|
// Create a quote for each swappable token
|
|
22548
|
-
for (const swappableToken of swappableTokens)dexTransactionResponsePromises.push(exchange.getUnsignedSwapTxFromAmountOut(walletAddress, swappableToken, requiredToken.address, requiredToken.amount));
|
|
22345
|
+
for (const swappableToken of swappableTokens)dexTransactionResponsePromises.push(exchange.getUnsignedSwapTxFromAmountOut(walletAddress, swappableToken, requiredToken.address, requiredToken.amount, slippagePercent));
|
|
22549
22346
|
// Resolve all the quotes and link them back to the swappable token
|
|
22550
22347
|
// The swappable token array is in the same position in the array as the quote in the promise array
|
|
22551
22348
|
const dexTransactionResponse = await Promise.all(dexTransactionResponsePromises);
|
|
@@ -22566,7 +22363,7 @@ const $049bba630af05555$export$6946a1f17c2bbf26 = async (config, chainId, wallet
|
|
|
22566
22363
|
|
|
22567
22364
|
const $3ee85f12225c19f3$export$fb80fe94a81a3132 = async (config, dexQuoteCache, walletAddress, requiredToken, swappableTokens)=>{
|
|
22568
22365
|
const dexQuotes = dexQuoteCache.get(requiredToken.address);
|
|
22569
|
-
if (dexQuotes) return dexQuotes;
|
|
22366
|
+
if (dexQuotes && dexQuotes.size > 0) return dexQuotes;
|
|
22570
22367
|
const quotes = await ($049bba630af05555$export$6946a1f17c2bbf26)(config, ($4013c5c91bb535f6$export$c9af4e4b001c6476)(config), walletAddress, requiredToken, swappableTokens);
|
|
22571
22368
|
dexQuoteCache.set(requiredToken.address, quotes);
|
|
22572
22369
|
return quotes;
|
|
@@ -22703,6 +22500,506 @@ const $91807edfd7057288$export$8e03ea04d59f2402 = async (config, availableRoutin
|
|
|
22703
22500
|
|
|
22704
22501
|
|
|
22705
22502
|
|
|
22503
|
+
const $5a5ccedc98d53d25$var$filterTokens = (allowedTokens, balances)=>{
|
|
22504
|
+
if (balances && balances.success) return allowedTokens.filter((token)=>{
|
|
22505
|
+
if ("address" in token) return balances.balances.find((balance)=>balance.token.address === token.address && balance.balance.gt(0));
|
|
22506
|
+
return balances.balances.find((balance)=>!("address" in balance.token) && balance.balance.gt(0));
|
|
22507
|
+
});
|
|
22508
|
+
return [];
|
|
22509
|
+
};
|
|
22510
|
+
const $5a5ccedc98d53d25$export$9ec9fc71f3ce62c4 = async (config, availableRoutingOptions)=>{
|
|
22511
|
+
if (availableRoutingOptions.onRamp) {
|
|
22512
|
+
const onRampOptions = await config.remote.getConfig("onramp");
|
|
22513
|
+
const onRampAllowList = {};
|
|
22514
|
+
Object.entries(onRampOptions).forEach(([onRampProvider, onRampProviderConfig])=>{
|
|
22515
|
+
// Allowed list per onRamp provider
|
|
22516
|
+
onRampAllowList[onRampProvider] = onRampProviderConfig.tokens ?? [];
|
|
22517
|
+
});
|
|
22518
|
+
return onRampAllowList;
|
|
22519
|
+
}
|
|
22520
|
+
return {};
|
|
22521
|
+
};
|
|
22522
|
+
const $5a5ccedc98d53d25$export$d744af9f1c0712bc = async (config, tokenBalances, availableRoutingOptions)=>{
|
|
22523
|
+
if (availableRoutingOptions.bridge) {
|
|
22524
|
+
const allowedTokens = (await config.remote.getConfig("bridge"))?.tokens ?? [];
|
|
22525
|
+
const balances = tokenBalances.get(($4013c5c91bb535f6$export$9b794d067cdd1af6)(config));
|
|
22526
|
+
return $5a5ccedc98d53d25$var$filterTokens(allowedTokens, balances);
|
|
22527
|
+
}
|
|
22528
|
+
return [];
|
|
22529
|
+
};
|
|
22530
|
+
const $5a5ccedc98d53d25$export$87ed7f956d73690 = async (config, tokenBalances, availableRoutingOptions)=>{
|
|
22531
|
+
if (availableRoutingOptions.swap) {
|
|
22532
|
+
const allowedTokens = (await config.remote.getConfig("dex"))?.tokens ?? [];
|
|
22533
|
+
const balances = tokenBalances.get(($4013c5c91bb535f6$export$c9af4e4b001c6476)(config));
|
|
22534
|
+
return $5a5ccedc98d53d25$var$filterTokens(allowedTokens, balances);
|
|
22535
|
+
}
|
|
22536
|
+
return [];
|
|
22537
|
+
};
|
|
22538
|
+
const $5a5ccedc98d53d25$export$1ad29657d49c5440 = async (config, tokenBalances, availableRoutingOptions)=>{
|
|
22539
|
+
const tokenAllowList = {};
|
|
22540
|
+
tokenAllowList.swap = await $5a5ccedc98d53d25$export$87ed7f956d73690(config, tokenBalances, availableRoutingOptions);
|
|
22541
|
+
tokenAllowList.bridge = await $5a5ccedc98d53d25$export$d744af9f1c0712bc(config, tokenBalances, availableRoutingOptions);
|
|
22542
|
+
tokenAllowList.onRamp = await $5a5ccedc98d53d25$export$9ec9fc71f3ce62c4(config, availableRoutingOptions);
|
|
22543
|
+
return tokenAllowList;
|
|
22544
|
+
};
|
|
22545
|
+
|
|
22546
|
+
|
|
22547
|
+
|
|
22548
|
+
|
|
22549
|
+
|
|
22550
|
+
|
|
22551
|
+
|
|
22552
|
+
|
|
22553
|
+
|
|
22554
|
+
const $f730af3b727f04ac$export$22fea095b15361de = (balances)=>{
|
|
22555
|
+
for (const balance of balances.balances){
|
|
22556
|
+
if (!balance.token.address || balance.token.address === "") return balance.balance;
|
|
22557
|
+
}
|
|
22558
|
+
return (BigNumber$1).from(0);
|
|
22559
|
+
};
|
|
22560
|
+
|
|
22561
|
+
|
|
22562
|
+
|
|
22563
|
+
|
|
22564
|
+
|
|
22565
|
+
|
|
22566
|
+
const $8a49d1a3783a2640$export$3aff971444a4f244 = async (config, readOnlyProviders)=>{
|
|
22567
|
+
try {
|
|
22568
|
+
const estimate = await (0, $2e7bf45a7c9a9570$export$942c8de7174809fc)({
|
|
22569
|
+
gasEstimateType: (0, $de275b98d2b651c3$export$788b1fd17f3dad84).BRIDGE_TO_L2,
|
|
22570
|
+
isSpendingCapApprovalRequired: false
|
|
22571
|
+
}, readOnlyProviders, config);
|
|
22572
|
+
const gasEstimate = estimate.gasFee.estimatedAmount;
|
|
22573
|
+
const bridgeFee = estimate.bridgeFee.estimatedAmount;
|
|
22574
|
+
let totalFees = (0, BigNumber$1).from(0);
|
|
22575
|
+
if (gasEstimate) totalFees = totalFees.add(gasEstimate);
|
|
22576
|
+
if (bridgeFee) totalFees = totalFees.add(bridgeFee);
|
|
22577
|
+
return totalFees;
|
|
22578
|
+
} catch (err) {
|
|
22579
|
+
throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Error estimating gas for bridge", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).BRIDGE_GAS_ESTIMATE_ERROR, {
|
|
22580
|
+
message: err.message
|
|
22581
|
+
});
|
|
22582
|
+
}
|
|
22583
|
+
};
|
|
22584
|
+
|
|
22585
|
+
|
|
22586
|
+
|
|
22587
|
+
|
|
22588
|
+
|
|
22589
|
+
|
|
22590
|
+
|
|
22591
|
+
|
|
22592
|
+
|
|
22593
|
+
const $887d24b47765b1c0$export$c37d8687c27b9660 = "0x0000000000000000000000000000000000000001";
|
|
22594
|
+
const $887d24b47765b1c0$export$1430626eec86fce9 = (chainId)=>{
|
|
22595
|
+
if (chainId === ($0472f23319457bfb$export$c06e1e7429de6283).IMTBL_ZKEVM_TESTNET) return "imtbl-zkevm-testnet";
|
|
22596
|
+
return "";
|
|
22597
|
+
};
|
|
22598
|
+
const $887d24b47765b1c0$export$53e663abd9b77fc1 = async (chainId, config)=>{
|
|
22599
|
+
const imxMappingConfig = await config.remote.getConfig("imxAddressMapping");
|
|
22600
|
+
return imxMappingConfig[chainId] ?? "";
|
|
22601
|
+
};
|
|
22602
|
+
const $887d24b47765b1c0$export$952cdf461a00a8c6 = async (config, l2address)=>{
|
|
22603
|
+
if (l2address === "") return {
|
|
22604
|
+
l1address: "",
|
|
22605
|
+
l2address: l2address
|
|
22606
|
+
};
|
|
22607
|
+
if (l2address === ($d85ad1457a3f1a83$export$b80040cb173ba6e9)) return {
|
|
22608
|
+
l1address: await $887d24b47765b1c0$export$53e663abd9b77fc1(($4013c5c91bb535f6$export$9b794d067cdd1af6)(config), config),
|
|
22609
|
+
l2address: ($d85ad1457a3f1a83$export$b80040cb173ba6e9)
|
|
22610
|
+
};
|
|
22611
|
+
const chainName = $887d24b47765b1c0$export$1430626eec86fce9(($4013c5c91bb535f6$export$c9af4e4b001c6476)(config));
|
|
22612
|
+
if (chainName === "") return {
|
|
22613
|
+
l1address: "",
|
|
22614
|
+
l2address: l2address
|
|
22615
|
+
}; // Chain name not a valid indexer chain name
|
|
22616
|
+
const blockchainData = ($67fc622a2b913d5f$export$436dd76f23f463ff)(config);
|
|
22617
|
+
const tokenData = await blockchainData.getToken({
|
|
22618
|
+
chainName: chainName,
|
|
22619
|
+
contractAddress: l2address
|
|
22620
|
+
});
|
|
22621
|
+
const l1address = tokenData.result.root_contract_address;
|
|
22622
|
+
if (l1address === null) return {
|
|
22623
|
+
l1address: "",
|
|
22624
|
+
l2address: l2address
|
|
22625
|
+
}; // No L1 representation of this token
|
|
22626
|
+
return {
|
|
22627
|
+
l1address: l1address,
|
|
22628
|
+
l2address: l2address
|
|
22629
|
+
};
|
|
22630
|
+
};
|
|
22631
|
+
|
|
22632
|
+
|
|
22633
|
+
const $07ac9c0576988336$export$7847f5f5cce25dfa = async (config, readOnlyProviders, l1provider, depositorAddress, fromChainId, toChainId, token, depositAmount)=>{
|
|
22634
|
+
try {
|
|
22635
|
+
const tokenBridge = await $67fc622a2b913d5f$export$989eefe1274a439c(fromChainId, toChainId, readOnlyProviders, config);
|
|
22636
|
+
const { unsignedTx: unsignedTx } = await tokenBridge.getUnsignedApproveDepositBridgeTx({
|
|
22637
|
+
depositorAddress: depositorAddress,
|
|
22638
|
+
token: token,
|
|
22639
|
+
depositAmount: depositAmount
|
|
22640
|
+
});
|
|
22641
|
+
if (unsignedTx === null) return (0, BigNumber$1).from(0);
|
|
22642
|
+
return await l1provider.estimateGas(unsignedTx);
|
|
22643
|
+
} catch (err) {
|
|
22644
|
+
throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("Error occurred while attempting ot estimate gas for approval transaction", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).BRIDGE_GAS_ESTIMATE_ERROR, {
|
|
22645
|
+
message: err.message
|
|
22646
|
+
});
|
|
22647
|
+
}
|
|
22648
|
+
};
|
|
22649
|
+
const $07ac9c0576988336$export$a3dd181de896b7c7 = async (config, readOnlyProviders, l1provider, depositorAddress, l1Address, delta)=>{
|
|
22650
|
+
if (l1Address === ($887d24b47765b1c0$export$c37d8687c27b9660)) return (BigNumber$1).from(0); // Native ETH does not require approval
|
|
22651
|
+
const fromChainId = ($4013c5c91bb535f6$export$9b794d067cdd1af6)(config);
|
|
22652
|
+
const toChainId = ($4013c5c91bb535f6$export$c9af4e4b001c6476)(config);
|
|
22653
|
+
return await $07ac9c0576988336$export$7847f5f5cce25dfa(config, readOnlyProviders, l1provider, depositorAddress, fromChainId, toChainId, l1Address, delta);
|
|
22654
|
+
};
|
|
22655
|
+
|
|
22656
|
+
|
|
22657
|
+
|
|
22658
|
+
|
|
22659
|
+
|
|
22660
|
+
const $fa9ac5bfdbbf9dfa$export$9994ad18c2f0e665 = (tokenBalanceResult, totalFees)=>{
|
|
22661
|
+
const balance = ($f730af3b727f04ac$export$22fea095b15361de)(tokenBalanceResult);
|
|
22662
|
+
return balance.gte(totalFees);
|
|
22663
|
+
};
|
|
22664
|
+
const $fa9ac5bfdbbf9dfa$export$da05aed50d75046 = async (config, readOnlyProviders, feeEstimates)=>{
|
|
22665
|
+
let bridgeFeeEstimate = feeEstimates.get(($4b58188d47aafe8d$export$3af78bb3e8650ee6).BRIDGE);
|
|
22666
|
+
if (bridgeFeeEstimate) return bridgeFeeEstimate;
|
|
22667
|
+
bridgeFeeEstimate = await ($8a49d1a3783a2640$export$3aff971444a4f244)(config, readOnlyProviders);
|
|
22668
|
+
feeEstimates.set(($4b58188d47aafe8d$export$3af78bb3e8650ee6).BRIDGE, bridgeFeeEstimate);
|
|
22669
|
+
return bridgeFeeEstimate;
|
|
22670
|
+
};
|
|
22671
|
+
const $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute = (chainId, balance)=>({
|
|
22672
|
+
type: ($4b58188d47aafe8d$export$3af78bb3e8650ee6).BRIDGE,
|
|
22673
|
+
chainId: chainId,
|
|
22674
|
+
asset: {
|
|
22675
|
+
balance: balance.balance,
|
|
22676
|
+
formattedBalance: balance.formattedBalance,
|
|
22677
|
+
token: {
|
|
22678
|
+
name: balance.token.name,
|
|
22679
|
+
symbol: balance.token.symbol,
|
|
22680
|
+
address: balance.token.address,
|
|
22681
|
+
decimals: balance.token.decimals
|
|
22682
|
+
}
|
|
22683
|
+
}
|
|
22684
|
+
});
|
|
22685
|
+
const $fa9ac5bfdbbf9dfa$export$3139474685e4dedd = (address)=>{
|
|
22686
|
+
if (!address || address === "") return true;
|
|
22687
|
+
return false;
|
|
22688
|
+
};
|
|
22689
|
+
const $fa9ac5bfdbbf9dfa$export$ddc7ba2b57d7c5fa = async (config, readOnlyProviders, depositorAddress, availableRoutingOptions, bridgeRequirement, tokenBalanceResults, feeEstimates)=>{
|
|
22690
|
+
if (!availableRoutingOptions.bridge) return undefined;
|
|
22691
|
+
if (bridgeRequirement.l2address === undefined || bridgeRequirement.l2address === "") return undefined;
|
|
22692
|
+
const chainId = ($4013c5c91bb535f6$export$9b794d067cdd1af6)(config);
|
|
22693
|
+
const tokenBalanceResult = tokenBalanceResults.get(chainId);
|
|
22694
|
+
const l1provider = readOnlyProviders.get(chainId);
|
|
22695
|
+
if (!l1provider) throw new ($a8bc256d81a5e2c1$export$b722478a3cbfa3bc)("No L1 provider available", ($a8bc256d81a5e2c1$export$e3dc0620abde7f5a).PROVIDER_ERROR, {
|
|
22696
|
+
chainId: chainId.toString()
|
|
22697
|
+
});
|
|
22698
|
+
// If no balances on layer 1 then Bridge cannot be an option
|
|
22699
|
+
if (tokenBalanceResult === undefined || tokenBalanceResult.success === false) return undefined;
|
|
22700
|
+
const allowedTokenList = await ($5a5ccedc98d53d25$export$d744af9f1c0712bc)(config, tokenBalanceResults, availableRoutingOptions);
|
|
22701
|
+
if (allowedTokenList.length === 0) return undefined;
|
|
22702
|
+
const bridgeFeeEstimate = await $fa9ac5bfdbbf9dfa$export$da05aed50d75046(config, readOnlyProviders, feeEstimates);
|
|
22703
|
+
// If the user has no ETH to cover the bridge fees or approval fees then bridge cannot be an option
|
|
22704
|
+
if (!$fa9ac5bfdbbf9dfa$export$9994ad18c2f0e665(tokenBalanceResult, bridgeFeeEstimate)) return undefined;
|
|
22705
|
+
const l1RepresentationResult = await ($887d24b47765b1c0$export$952cdf461a00a8c6)(config, bridgeRequirement.l2address);
|
|
22706
|
+
// No mapping on L1 for this token
|
|
22707
|
+
const { l1address: l1address } = l1RepresentationResult;
|
|
22708
|
+
if (l1address === "") return undefined;
|
|
22709
|
+
// Ensure l1address is in the allowed token list
|
|
22710
|
+
if (l1address === ($887d24b47765b1c0$export$c37d8687c27b9660)) {
|
|
22711
|
+
if (!allowedTokenList.find((token)=>!("address" in token))) return undefined;
|
|
22712
|
+
} else if (!allowedTokenList.find((token)=>token.address === l1address)) return undefined;
|
|
22713
|
+
const gasForApproval = await ($07ac9c0576988336$export$a3dd181de896b7c7)(config, readOnlyProviders, l1provider, depositorAddress, l1address, bridgeRequirement.amount);
|
|
22714
|
+
if (!$fa9ac5bfdbbf9dfa$export$9994ad18c2f0e665(tokenBalanceResult, gasForApproval.add(bridgeFeeEstimate))) return undefined;
|
|
22715
|
+
// If the L1 representation of the requirement is ETH then find the ETH balance and check if the balance covers the delta
|
|
22716
|
+
if (l1address === ($887d24b47765b1c0$export$c37d8687c27b9660)) {
|
|
22717
|
+
const nativeETHBalance = tokenBalanceResult.balances.find((balance)=>$fa9ac5bfdbbf9dfa$export$3139474685e4dedd(balance.token.address));
|
|
22718
|
+
if (nativeETHBalance && nativeETHBalance.balance.gte(bridgeRequirement.amount.add(bridgeFeeEstimate))) return $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute(chainId, nativeETHBalance);
|
|
22719
|
+
return undefined;
|
|
22720
|
+
}
|
|
22721
|
+
// Find the balance of the L1 representation of the token and check if the balance covers the delta
|
|
22722
|
+
const erc20balance = tokenBalanceResult.balances.find((balance)=>balance.token.address === l1address);
|
|
22723
|
+
if (erc20balance && erc20balance.balance.gte(bridgeRequirement.amount)) return $fa9ac5bfdbbf9dfa$var$constructBridgeFundingRoute(chainId, erc20balance);
|
|
22724
|
+
return undefined;
|
|
22725
|
+
};
|
|
22726
|
+
|
|
22727
|
+
|
|
22728
|
+
|
|
22729
|
+
|
|
22730
|
+
const $7bb5af1d8b5d9127$export$8280985cc3da7882 = (config, tokenBalances)=>{
|
|
22731
|
+
const balances = {
|
|
22732
|
+
l1balances: [],
|
|
22733
|
+
l2balances: []
|
|
22734
|
+
};
|
|
22735
|
+
const l1balancesResult = tokenBalances.get(($4013c5c91bb535f6$export$9b794d067cdd1af6)(config));
|
|
22736
|
+
const l2balancesResult = tokenBalances.get(($4013c5c91bb535f6$export$c9af4e4b001c6476)(config));
|
|
22737
|
+
// If there are no l1 balance then cannot bridge
|
|
22738
|
+
if (!l1balancesResult) return balances;
|
|
22739
|
+
if (l1balancesResult.error !== undefined) return balances;
|
|
22740
|
+
if (!l1balancesResult.success) return balances;
|
|
22741
|
+
// If there are no l2 balance then cannot swap
|
|
22742
|
+
if (!l2balancesResult) return balances;
|
|
22743
|
+
if (l2balancesResult.error !== undefined) return balances;
|
|
22744
|
+
if (!l2balancesResult.success) return balances;
|
|
22745
|
+
const l1balances = l1balancesResult.balances;
|
|
22746
|
+
const l2balances = l2balancesResult.balances;
|
|
22747
|
+
return {
|
|
22748
|
+
l1balances: l1balances,
|
|
22749
|
+
l2balances: l2balances
|
|
22750
|
+
};
|
|
22751
|
+
};
|
|
22752
|
+
|
|
22753
|
+
|
|
22754
|
+
|
|
22755
|
+
|
|
22756
|
+
|
|
22757
|
+
const $62e968a3dd87940e$export$8059963805b7876c = (dexQuote, tokenAddress)=>{
|
|
22758
|
+
let fees = (BigNumber$1).from(0);
|
|
22759
|
+
dexQuote.quote.fees.forEach((fee)=>{
|
|
22760
|
+
if (fee.amount.token.address === tokenAddress) fees = fees.add(fee.amount.value);
|
|
22761
|
+
});
|
|
22762
|
+
if (dexQuote.approval) {
|
|
22763
|
+
if (dexQuote.approval.token.address === tokenAddress) fees = fees.add(dexQuote.approval.value);
|
|
22764
|
+
}
|
|
22765
|
+
return fees;
|
|
22766
|
+
};
|
|
22767
|
+
// The token that is being bridged may also be a balance requirement
|
|
22768
|
+
// Since this token is going to be swapped after bridging then get the
|
|
22769
|
+
// balance requirement amount so this can be considered when bridging
|
|
22770
|
+
// enough of the token across
|
|
22771
|
+
const $62e968a3dd87940e$var$getAmountFromBalanceRequirement = (balanceRequirements, tokenAddress)=>{
|
|
22772
|
+
let amount = (BigNumber$1).from(0);
|
|
22773
|
+
balanceRequirements.balanceRequirements.forEach((requirement)=>{
|
|
22774
|
+
if (requirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE || requirement.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) {
|
|
22775
|
+
if (requirement.required.token.address === tokenAddress) amount = amount.add(requirement.required.balance);
|
|
22776
|
+
}
|
|
22777
|
+
});
|
|
22778
|
+
return amount;
|
|
22779
|
+
};
|
|
22780
|
+
const $62e968a3dd87940e$export$df667c749c93b110 = (dexQuotes, l1balances, l2balances, l1tol2addresses, balanceRequirements)=>{
|
|
22781
|
+
const bridgeRequirements = [];
|
|
22782
|
+
for (const [tokenAddress, quote] of dexQuotes){
|
|
22783
|
+
// Get the L2 balance for the token address
|
|
22784
|
+
const l2balance = l2balances.find((balance)=>balance.token.address === tokenAddress);
|
|
22785
|
+
const l1tol2TokenMapping = l1tol2addresses.find((token)=>token.l2address === tokenAddress);
|
|
22786
|
+
if (!l1tol2TokenMapping) continue;
|
|
22787
|
+
const { l1address: l1address, l2address: l2address } = l1tol2TokenMapping;
|
|
22788
|
+
if (!l1address) continue;
|
|
22789
|
+
// If the user does not have any L1 balance for this token then cannot bridge
|
|
22790
|
+
const l1balance = l1balances.find((balance)=>{
|
|
22791
|
+
if (balance.token.address === undefined && l1address === ($887d24b47765b1c0$export$c37d8687c27b9660)) return true;
|
|
22792
|
+
return balance.token.address === l1address;
|
|
22793
|
+
});
|
|
22794
|
+
if (!l1balance) continue;
|
|
22795
|
+
// Get the total amount using slippage to ensure a small buffer is added to cover price fluctuations
|
|
22796
|
+
const quotedAmount = quote.quote.amountWithMaxSlippage.value;
|
|
22797
|
+
// Add fees to the quoted amount if the fees are in the same token as the token being swapped
|
|
22798
|
+
const fees = $62e968a3dd87940e$export$8059963805b7876c(quote, tokenAddress);
|
|
22799
|
+
// If the token being bridged is a balance requirement then add this to the total
|
|
22800
|
+
// to ensure when its swapped the balance requirement can still be fulfilled
|
|
22801
|
+
const balanceRequirementAmount = $62e968a3dd87940e$var$getAmountFromBalanceRequirement(balanceRequirements, tokenAddress);
|
|
22802
|
+
// Add all the amounts together
|
|
22803
|
+
const totalAmount = quotedAmount.add(fees).add(balanceRequirementAmount);
|
|
22804
|
+
// Subtract any L2 balance from the total amount to only bridge the necessary amount
|
|
22805
|
+
const amountToBridge = l2balance ? totalAmount.sub(l2balance.balance) : totalAmount;
|
|
22806
|
+
if (amountToBridge.lte(0)) continue;
|
|
22807
|
+
if (amountToBridge.gt(l1balance.balance)) continue;
|
|
22808
|
+
bridgeRequirements.push({
|
|
22809
|
+
amount: amountToBridge,
|
|
22810
|
+
formattedAmount: (utils).formatUnits(amountToBridge, l1balance.token.decimals),
|
|
22811
|
+
l2address: // L2 address is used for the bridge requirement as the bridge route uses the indexer to find L1 address
|
|
22812
|
+
l2address
|
|
22813
|
+
});
|
|
22814
|
+
}
|
|
22815
|
+
return bridgeRequirements;
|
|
22816
|
+
};
|
|
22817
|
+
|
|
22818
|
+
|
|
22819
|
+
|
|
22820
|
+
const $7500587317643fc8$export$c3e193fd573f1a94 = async (config, swappableTokens)=>{
|
|
22821
|
+
const l1tol2addressMappingPromises = swappableTokens.map((token)=>($887d24b47765b1c0$export$952cdf461a00a8c6)(config, token.address ?? ""));
|
|
22822
|
+
return await Promise.all(l1tol2addressMappingPromises);
|
|
22823
|
+
};
|
|
22824
|
+
|
|
22825
|
+
|
|
22826
|
+
|
|
22827
|
+
|
|
22828
|
+
const $d54df4a884f14123$export$d46f2133747ffd93 = async (config, dexQuoteCache, ownerAddress, requiredTokenAddress, insufficientRequirement, filteredSwappableTokens)=>{
|
|
22829
|
+
const filteredSwappableTokensAddresses = [];
|
|
22830
|
+
for (const token of filteredSwappableTokens){
|
|
22831
|
+
if (!token.address) continue;
|
|
22832
|
+
filteredSwappableTokensAddresses.push(token.address);
|
|
22833
|
+
}
|
|
22834
|
+
const dexQuotes = await ($3ee85f12225c19f3$export$fb80fe94a81a3132)(config, dexQuoteCache, ownerAddress, {
|
|
22835
|
+
address: requiredTokenAddress,
|
|
22836
|
+
amount: insufficientRequirement.delta.balance
|
|
22837
|
+
}, filteredSwappableTokensAddresses);
|
|
22838
|
+
return dexQuotes;
|
|
22839
|
+
};
|
|
22840
|
+
|
|
22841
|
+
|
|
22842
|
+
const $afd57acae9471ac5$export$b94e88f4f8805f71 = (bridgeableTokens, swappableTokens, l1balances, l2balances, availableRoutingOptions, requiredTokenAddress)=>{
|
|
22843
|
+
if (bridgeableTokens.length === 0) return true;
|
|
22844
|
+
if (swappableTokens.length === 0) return true;
|
|
22845
|
+
if (l1balances.length === 0) return true;
|
|
22846
|
+
if (l2balances.length === 0) return true;
|
|
22847
|
+
if (!availableRoutingOptions.bridge) return true;
|
|
22848
|
+
if (!availableRoutingOptions.swap) return true;
|
|
22849
|
+
if (requiredTokenAddress === undefined) return true;
|
|
22850
|
+
if (requiredTokenAddress === "") return true;
|
|
22851
|
+
return false;
|
|
22852
|
+
};
|
|
22853
|
+
const $afd57acae9471ac5$export$ed7c59bd8d1bb5a7 = (requiredTokenAddress, bridgeableTokens, swappableTokens, l1tol2Addresses)=>{
|
|
22854
|
+
const filteredSwappableTokens = [];
|
|
22855
|
+
for (const addresses of l1tol2Addresses){
|
|
22856
|
+
if (addresses.l1address === "") continue;
|
|
22857
|
+
if (addresses.l2address === "") continue;
|
|
22858
|
+
if (!bridgeableTokens.includes(addresses.l1address)) continue;
|
|
22859
|
+
// Filter out the token that is required from the swappable tokens list
|
|
22860
|
+
if (addresses.l2address === requiredTokenAddress) continue;
|
|
22861
|
+
const tokenInfo = swappableTokens.find((token)=>token.address === addresses.l2address);
|
|
22862
|
+
if (!tokenInfo) continue;
|
|
22863
|
+
filteredSwappableTokens.push(tokenInfo);
|
|
22864
|
+
}
|
|
22865
|
+
return filteredSwappableTokens;
|
|
22866
|
+
};
|
|
22867
|
+
// Modifies a users balance to include the amount as if the user successfully bridged
|
|
22868
|
+
// This is so the swap route can check against the balance once the user has performed a bridge
|
|
22869
|
+
const $afd57acae9471ac5$var$modifyTokenBalancesWithBridgedAmount = (config, tokenBalances, l2balances, bridgedTokens, swappableTokens)=>{
|
|
22870
|
+
const modifiedTokenBalances = new Map();
|
|
22871
|
+
for (const [chainId, tokenBalance] of tokenBalances)modifiedTokenBalances.set(chainId, {
|
|
22872
|
+
success: tokenBalance.success,
|
|
22873
|
+
balances: tokenBalance.balances
|
|
22874
|
+
});
|
|
22875
|
+
// Construct a map of balances to the L2 token address to make
|
|
22876
|
+
// it easier to adjust the balances for the tokens that can be bridged
|
|
22877
|
+
const balanceMap = new Map();
|
|
22878
|
+
for (const balance of l2balances){
|
|
22879
|
+
if (!balance.token.address) continue;
|
|
22880
|
+
balanceMap.set(balance.token.address, balance);
|
|
22881
|
+
}
|
|
22882
|
+
// Go through each of the tokens that can be bridged
|
|
22883
|
+
// and adjust the balances to fake the bridge
|
|
22884
|
+
for (const bridgedToken of bridgedTokens){
|
|
22885
|
+
const { amount: amount, l2address: l2address } = bridgedToken;
|
|
22886
|
+
if (l2address === "") continue;
|
|
22887
|
+
let l2balance = (BigNumber$1).from(0);
|
|
22888
|
+
// Find the current balance of this token
|
|
22889
|
+
const currentBalance = balanceMap.get(l2address);
|
|
22890
|
+
if (currentBalance) l2balance = currentBalance.balance;
|
|
22891
|
+
const newBalance = l2balance.add(amount);
|
|
22892
|
+
const tokenInfo = swappableTokens.find((token)=>token.address === l2address);
|
|
22893
|
+
balanceMap.set(l2address, {
|
|
22894
|
+
balance: newBalance,
|
|
22895
|
+
formattedBalance: (utils).formatUnits(newBalance, tokenInfo.decimals),
|
|
22896
|
+
token: tokenInfo
|
|
22897
|
+
});
|
|
22898
|
+
}
|
|
22899
|
+
const updatedBalances = Array.from(balanceMap.values());
|
|
22900
|
+
modifiedTokenBalances.set(($4013c5c91bb535f6$export$c9af4e4b001c6476)(config), {
|
|
22901
|
+
success: true,
|
|
22902
|
+
balances: updatedBalances
|
|
22903
|
+
});
|
|
22904
|
+
return modifiedTokenBalances;
|
|
22905
|
+
};
|
|
22906
|
+
const $afd57acae9471ac5$export$1fc63300bde5e690 = (tokenBalances, swapRoutes)=>{
|
|
22907
|
+
const originalSwapSteps = [];
|
|
22908
|
+
for (const route of swapRoutes){
|
|
22909
|
+
const { chainId: chainId, asset: asset } = route;
|
|
22910
|
+
const tokenBalance = tokenBalances.get(chainId);
|
|
22911
|
+
if (!tokenBalance) continue;
|
|
22912
|
+
let originalBalance = (BigNumber$1).from(0);
|
|
22913
|
+
let originalFormattedBalance = "0";
|
|
22914
|
+
const l2balance = tokenBalance.balances.find((balance)=>balance.token.address === asset.token.address);
|
|
22915
|
+
if (l2balance) {
|
|
22916
|
+
originalBalance = l2balance.balance;
|
|
22917
|
+
originalFormattedBalance = l2balance.formattedBalance;
|
|
22918
|
+
}
|
|
22919
|
+
route.asset.balance = originalBalance;
|
|
22920
|
+
route.asset.formattedBalance = originalFormattedBalance;
|
|
22921
|
+
originalSwapSteps.push(route);
|
|
22922
|
+
}
|
|
22923
|
+
return originalSwapSteps;
|
|
22924
|
+
};
|
|
22925
|
+
const $afd57acae9471ac5$export$d9b96654eebdaf2a = (bridgeFundingSteps, swapFundingSteps, l1tol2Addresses)=>{
|
|
22926
|
+
const bridgeAndSwapRoutes = [];
|
|
22927
|
+
for (const bridgeFundingStep of bridgeFundingSteps){
|
|
22928
|
+
if (!bridgeFundingStep) continue;
|
|
22929
|
+
const mapping = l1tol2Addresses.find((addresses)=>{
|
|
22930
|
+
if (bridgeFundingStep.asset.token.address === undefined) return addresses.l1address === ($887d24b47765b1c0$export$c37d8687c27b9660) && addresses.l2address;
|
|
22931
|
+
return addresses.l1address === bridgeFundingStep.asset.token.address && addresses.l2address;
|
|
22932
|
+
});
|
|
22933
|
+
if (!mapping) continue;
|
|
22934
|
+
const swapFundingStep = swapFundingSteps.find((step)=>step.asset.token.address === mapping.l2address);
|
|
22935
|
+
if (!swapFundingStep) continue;
|
|
22936
|
+
bridgeAndSwapRoutes.push({
|
|
22937
|
+
bridgeFundingStep: bridgeFundingStep,
|
|
22938
|
+
swapFundingStep: swapFundingStep
|
|
22939
|
+
});
|
|
22940
|
+
}
|
|
22941
|
+
return bridgeAndSwapRoutes;
|
|
22942
|
+
};
|
|
22943
|
+
const $afd57acae9471ac5$export$f95ed27e871fe308 = async (config, readOnlyProviders, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, feeEstimates, tokenBalances, bridgeableTokens, swappableTokens, balanceRequirements)=>{
|
|
22944
|
+
const { l1balances: l1balances, l2balances: l2balances } = ($7bb5af1d8b5d9127$export$8280985cc3da7882)(config, tokenBalances);
|
|
22945
|
+
const requiredTokenAddress = insufficientRequirement.required.token.address;
|
|
22946
|
+
if ($afd57acae9471ac5$export$b94e88f4f8805f71(bridgeableTokens, swappableTokens, l1balances, l2balances, availableRoutingOptions, requiredTokenAddress)) return [];
|
|
22947
|
+
// Fetch L2 to L1 address mapping and based on the L1 address existing then
|
|
22948
|
+
// filter the bridgeable and swappable tokens list further to only include
|
|
22949
|
+
// tokens that can be both swapped and bridged
|
|
22950
|
+
const l1tol2Addresses = await ($7500587317643fc8$export$c3e193fd573f1a94)(config, swappableTokens);
|
|
22951
|
+
const filteredSwappableTokens = $afd57acae9471ac5$export$ed7c59bd8d1bb5a7(requiredTokenAddress, bridgeableTokens, swappableTokens, l1tol2Addresses);
|
|
22952
|
+
if (filteredSwappableTokens.length === 0) return [];
|
|
22953
|
+
// Fetch all the dex quotes from the list of swappable tokens
|
|
22954
|
+
const dexQuotes = await ($d54df4a884f14123$export$d46f2133747ffd93)(config, dexQuoteCache, ownerAddress, requiredTokenAddress, insufficientRequirement, filteredSwappableTokens);
|
|
22955
|
+
// Construct bridge requirements based on L2 balances, slippage and swap fees
|
|
22956
|
+
const bridgeRequirements = ($62e968a3dd87940e$export$df667c749c93b110)(dexQuotes, l1balances, l2balances, l1tol2Addresses, balanceRequirements);
|
|
22957
|
+
if (bridgeRequirements.length === 0) return [];
|
|
22958
|
+
// Create a mapping of bridge routes to L2 addresses
|
|
22959
|
+
const bridgePromises = new Map();
|
|
22960
|
+
// Create map of bridgeable tokens to make it easier to get the amount that was bridged when modifying the users balance later
|
|
22961
|
+
const bridgeableRequirementsMap = new Map();
|
|
22962
|
+
const bridgedTokens = [];
|
|
22963
|
+
for (const bridgeRequirement of bridgeRequirements){
|
|
22964
|
+
if (!bridgeRequirement.l2address) continue;
|
|
22965
|
+
bridgePromises.set(bridgeRequirement.l2address, ($fa9ac5bfdbbf9dfa$export$ddc7ba2b57d7c5fa)(config, readOnlyProviders, ownerAddress, availableRoutingOptions, bridgeRequirement, tokenBalances, feeEstimates));
|
|
22966
|
+
bridgeableRequirementsMap.set(bridgeRequirement.l2address, {
|
|
22967
|
+
amount: bridgeRequirement.amount,
|
|
22968
|
+
formattedAmount: bridgeRequirement.formattedAmount,
|
|
22969
|
+
l2address: bridgeRequirement.l2address
|
|
22970
|
+
});
|
|
22971
|
+
}
|
|
22972
|
+
const bridgeResults = await Promise.all(bridgePromises.values());
|
|
22973
|
+
const bridgeKeys = Array.from(bridgePromises.keys());
|
|
22974
|
+
// Create an array to store all the tokens that are able to be bridged
|
|
22975
|
+
const swappableTokensAfterBridging = [];
|
|
22976
|
+
// Iterate through all the bridge route results
|
|
22977
|
+
// If a bridge route result was successful then add this token to the
|
|
22978
|
+
// list of tokens that should be checked with the swap route
|
|
22979
|
+
bridgeResults.forEach((result, index)=>{
|
|
22980
|
+
const key = bridgeKeys[index];
|
|
22981
|
+
if (result === undefined) return;
|
|
22982
|
+
swappableTokensAfterBridging.push(key);
|
|
22983
|
+
const bridgedToken = bridgeableRequirementsMap.get(key);
|
|
22984
|
+
if (!bridgedToken) return;
|
|
22985
|
+
bridgedTokens.push({
|
|
22986
|
+
amount: bridgedToken.amount,
|
|
22987
|
+
formattedAmount: bridgedToken.formattedAmount,
|
|
22988
|
+
l2address: bridgedToken.l2address
|
|
22989
|
+
});
|
|
22990
|
+
});
|
|
22991
|
+
// Bridge route determined that no tokens could be bridged
|
|
22992
|
+
if (swappableTokensAfterBridging.length === 0) return [];
|
|
22993
|
+
if (bridgedTokens.length === 0) return []; // No tokens were bridged
|
|
22994
|
+
// Modify the users L2 balance to include the amount as if the user successfully bridged
|
|
22995
|
+
const modifiedTokenBalances = $afd57acae9471ac5$var$modifyTokenBalancesWithBridgedAmount(config, tokenBalances, l2balances, bridgedTokens, swappableTokens);
|
|
22996
|
+
// Call the swap route with the faked bridged balances
|
|
22997
|
+
const swapRoutes = await ($91807edfd7057288$export$8e03ea04d59f2402)(config, availableRoutingOptions, dexQuoteCache, ownerAddress, insufficientRequirement, modifiedTokenBalances, swappableTokensAfterBridging);
|
|
22998
|
+
if (!swapRoutes) return [];
|
|
22999
|
+
const originalBalanceSwapRoutes = $afd57acae9471ac5$export$1fc63300bde5e690(tokenBalances, swapRoutes);
|
|
23000
|
+
return $afd57acae9471ac5$export$d9b96654eebdaf2a(bridgeResults, originalBalanceSwapRoutes, l1tol2Addresses);
|
|
23001
|
+
};
|
|
23002
|
+
|
|
22706
23003
|
|
|
22707
23004
|
|
|
22708
23005
|
|
|
@@ -22733,6 +23030,7 @@ const $5649bc8af91da370$export$1fb2bd867f4a9be3 = async (config, availableRoutin
|
|
|
22733
23030
|
|
|
22734
23031
|
|
|
22735
23032
|
|
|
23033
|
+
|
|
22736
23034
|
const $c16168a9c28ae4fd$var$hasAvailableRoutingOptions = (availableRoutingOptions)=>availableRoutingOptions.bridge || availableRoutingOptions.swap || availableRoutingOptions.onRamp;
|
|
22737
23035
|
const $c16168a9c28ae4fd$export$31ce7ba1a2956195 = (balanceRequirements)=>{
|
|
22738
23036
|
let insufficientBalanceCount = 0;
|
|
@@ -22744,6 +23042,18 @@ const $c16168a9c28ae4fd$export$31ce7ba1a2956195 = (balanceRequirements)=>{
|
|
|
22744
23042
|
if (insufficientBalanceCount === 1) return insufficientRequirement;
|
|
22745
23043
|
return undefined;
|
|
22746
23044
|
};
|
|
23045
|
+
const $c16168a9c28ae4fd$export$ab86023c267660 = async (config, readOnlyProviders, availableRoutingOptions, insufficientRequirement, ownerAddress, tokenBalances, feeEstimates)=>{
|
|
23046
|
+
let bridgeFundingStep;
|
|
23047
|
+
if (insufficientRequirement === undefined) return undefined;
|
|
23048
|
+
if (insufficientRequirement.type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE && insufficientRequirement.type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) return undefined;
|
|
23049
|
+
const bridgeRequirement = {
|
|
23050
|
+
amount: insufficientRequirement.delta.balance,
|
|
23051
|
+
formattedAmount: insufficientRequirement.delta.formattedBalance,
|
|
23052
|
+
l2address: insufficientRequirement.required.token.address ?? ""
|
|
23053
|
+
};
|
|
23054
|
+
if (availableRoutingOptions.bridge && insufficientRequirement) bridgeFundingStep = await ($fa9ac5bfdbbf9dfa$export$ddc7ba2b57d7c5fa)(config, readOnlyProviders, ownerAddress, availableRoutingOptions, bridgeRequirement, tokenBalances, feeEstimates);
|
|
23055
|
+
return bridgeFundingStep;
|
|
23056
|
+
};
|
|
22747
23057
|
const $c16168a9c28ae4fd$export$814624e957fa0f11 = async (config, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, swapTokenAllowList)=>{
|
|
22748
23058
|
const fundingSteps = [];
|
|
22749
23059
|
if (!availableRoutingOptions.swap) return fundingSteps;
|
|
@@ -22757,6 +23067,27 @@ const $c16168a9c28ae4fd$export$814624e957fa0f11 = async (config, availableRoutin
|
|
|
22757
23067
|
if (swappableTokens.length === 0) return fundingSteps;
|
|
22758
23068
|
return await ($91807edfd7057288$export$8e03ea04d59f2402)(config, availableRoutingOptions, dexQuoteCache, ownerAddress, insufficientRequirement, tokenBalances, swappableTokens);
|
|
22759
23069
|
};
|
|
23070
|
+
const $c16168a9c28ae4fd$export$2becd43da9d21f73 = async (config, readOnlyProviders, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, tokenAllowList, feeEstimates, balanceRequirements)=>{
|
|
23071
|
+
if (!insufficientRequirement) return [];
|
|
23072
|
+
const l1balancesResult = tokenBalances.get(($4013c5c91bb535f6$export$9b794d067cdd1af6)(config));
|
|
23073
|
+
const l2balancesResult = tokenBalances.get(($4013c5c91bb535f6$export$c9af4e4b001c6476)(config));
|
|
23074
|
+
// If there are no l1 balance then cannot bridge
|
|
23075
|
+
if (!l1balancesResult) return [];
|
|
23076
|
+
if (l1balancesResult.error !== undefined || !l1balancesResult.success) return [];
|
|
23077
|
+
// If there are no l2 balance then cannot swap
|
|
23078
|
+
if (!l2balancesResult) return [];
|
|
23079
|
+
if (l2balancesResult.error !== undefined || !l2balancesResult.success) return [];
|
|
23080
|
+
// Get a list of all the swappable tokens
|
|
23081
|
+
const bridgeTokenAllowList = tokenAllowList?.bridge ?? [];
|
|
23082
|
+
const bridgeableL1Addresses = bridgeTokenAllowList.map((token)=>{
|
|
23083
|
+
if (token.address === undefined) return $887d24b47765b1c0$export$c37d8687c27b9660;
|
|
23084
|
+
return token.address;
|
|
23085
|
+
});
|
|
23086
|
+
const swapTokenAllowList = tokenAllowList?.swap ?? [];
|
|
23087
|
+
if (insufficientRequirement.type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE && insufficientRequirement.type !== ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) return [];
|
|
23088
|
+
const routes = await ($afd57acae9471ac5$export$f95ed27e871fe308)(config, readOnlyProviders, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, feeEstimates, tokenBalances, bridgeableL1Addresses, swapTokenAllowList, balanceRequirements);
|
|
23089
|
+
return routes;
|
|
23090
|
+
};
|
|
22760
23091
|
const $c16168a9c28ae4fd$export$e1b6e4d22d0365ee = async (config, availableRoutingOptions, insufficientRequirement)=>{
|
|
22761
23092
|
if (!availableRoutingOptions.onRamp) return undefined;
|
|
22762
23093
|
if (insufficientRequirement === undefined) return undefined;
|
|
@@ -22785,16 +23116,24 @@ const $c16168a9c28ae4fd$export$92606e71d0a264ff = async (config, ownerAddress, b
|
|
|
22785
23116
|
const feeEstimates = new Map();
|
|
22786
23117
|
// Dex quotes cache
|
|
22787
23118
|
const dexQuoteCache = new Map();
|
|
22788
|
-
// Ensures only 1 balance requirement is insufficient
|
|
23119
|
+
// Ensures only 1 balance requirement is insufficient
|
|
22789
23120
|
const insufficientRequirement = $c16168a9c28ae4fd$export$31ce7ba1a2956195(balanceRequirements);
|
|
23121
|
+
const routePromises = [];
|
|
23122
|
+
routePromises.push($c16168a9c28ae4fd$export$ab86023c267660(config, readOnlyProviders, availableRoutingOptions, insufficientRequirement, ownerAddress, tokenBalances, feeEstimates));
|
|
23123
|
+
routePromises.push($c16168a9c28ae4fd$export$814624e957fa0f11(config, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, allowList.swap));
|
|
23124
|
+
routePromises.push($c16168a9c28ae4fd$export$e1b6e4d22d0365ee(config, availableRoutingOptions, insufficientRequirement));
|
|
23125
|
+
routePromises.push($c16168a9c28ae4fd$export$2becd43da9d21f73(config, readOnlyProviders, availableRoutingOptions, insufficientRequirement, dexQuoteCache, ownerAddress, tokenBalances, allowList, feeEstimates, balanceRequirements));
|
|
23126
|
+
const resolved = await Promise.all(routePromises);
|
|
22790
23127
|
let bridgeFundingStep;
|
|
22791
|
-
|
|
22792
|
-
|
|
22793
|
-
|
|
22794
|
-
|
|
22795
|
-
|
|
22796
|
-
|
|
22797
|
-
|
|
23128
|
+
let swapFundingSteps = [];
|
|
23129
|
+
let onRampFundingStep;
|
|
23130
|
+
let bridgeAndSwapFundingSteps = [];
|
|
23131
|
+
resolved.forEach((result, index)=>{
|
|
23132
|
+
if (index === 0) bridgeFundingStep = result;
|
|
23133
|
+
if (index === 1) swapFundingSteps = result;
|
|
23134
|
+
if (index === 2) onRampFundingStep = result;
|
|
23135
|
+
if (index === 3) bridgeAndSwapFundingSteps = result;
|
|
23136
|
+
});
|
|
22798
23137
|
const response = {
|
|
22799
23138
|
response: {
|
|
22800
23139
|
type: ($b23305044c0e096a$export$3057de18ac0c076).NO_ROUTES,
|
|
@@ -22803,7 +23142,7 @@ const $c16168a9c28ae4fd$export$92606e71d0a264ff = async (config, ownerAddress, b
|
|
|
22803
23142
|
fundingRoutes: []
|
|
22804
23143
|
};
|
|
22805
23144
|
let priority = 0;
|
|
22806
|
-
if (bridgeFundingStep || swapFundingSteps.length > 0 || onRampFundingStep) {
|
|
23145
|
+
if (bridgeFundingStep || swapFundingSteps.length > 0 || onRampFundingStep || bridgeAndSwapFundingSteps.length > 0) {
|
|
22807
23146
|
response.response.type = ($b23305044c0e096a$export$3057de18ac0c076).ROUTES_FOUND;
|
|
22808
23147
|
response.response.message = "Routes found";
|
|
22809
23148
|
}
|
|
@@ -22836,6 +23175,22 @@ const $c16168a9c28ae4fd$export$92606e71d0a264ff = async (config, ownerAddress, b
|
|
|
22836
23175
|
]
|
|
22837
23176
|
});
|
|
22838
23177
|
}
|
|
23178
|
+
if (bridgeAndSwapFundingSteps) {
|
|
23179
|
+
priority++;
|
|
23180
|
+
bridgeAndSwapFundingSteps.forEach((bridgeAndSwapFundingStep)=>{
|
|
23181
|
+
const bridgeStep = bridgeAndSwapFundingStep.bridgeFundingStep;
|
|
23182
|
+
const swapStep = bridgeAndSwapFundingStep.swapFundingStep;
|
|
23183
|
+
response.fundingRoutes.push({
|
|
23184
|
+
priority: priority,
|
|
23185
|
+
steps: [
|
|
23186
|
+
bridgeStep,
|
|
23187
|
+
swapStep
|
|
23188
|
+
]
|
|
23189
|
+
});
|
|
23190
|
+
});
|
|
23191
|
+
}
|
|
23192
|
+
// eslint-disable-next-line no-console
|
|
23193
|
+
console.log("** response", response);
|
|
22839
23194
|
return response;
|
|
22840
23195
|
};
|
|
22841
23196
|
|
|
@@ -23010,7 +23365,6 @@ const $a7367d01c6e76b1c$export$d62081fac18000c2 = (orderHash, orderComponents, a
|
|
|
23010
23365
|
|
|
23011
23366
|
|
|
23012
23367
|
|
|
23013
|
-
|
|
23014
23368
|
const $9051cee080948594$export$9ac1563efd38130 = 1; // 100%
|
|
23015
23369
|
const $9051cee080948594$export$768e717351d4b176 = 6; // will allow 0.000001 (0.0001%) as the minimum value
|
|
23016
23370
|
const $9051cee080948594$var$calculateFeesPercent = (orderFee, amountBn)=>{
|
|
@@ -23022,7 +23376,7 @@ const $9051cee080948594$var$calculateFeesPercent = (orderFee, amountBn)=>{
|
|
|
23022
23376
|
};
|
|
23023
23377
|
const $9051cee080948594$var$calculateFeesToken = (orderFee, decimals)=>{
|
|
23024
23378
|
const feeToken = orderFee.amount;
|
|
23025
|
-
const bnFeeAmount = (parseUnits
|
|
23379
|
+
const bnFeeAmount = (utils).parseUnits(feeToken.token, decimals);
|
|
23026
23380
|
return bnFeeAmount;
|
|
23027
23381
|
};
|
|
23028
23382
|
const $9051cee080948594$export$1e69c9cfc42e28d8 = (orderFees, weiAmount, decimals = 18)=>{
|
|
@@ -23254,7 +23608,6 @@ const $9c3db1bb9c8b69d3$export$70b61ad426ddbe54 = async (config, provider, order
|
|
|
23254
23608
|
|
|
23255
23609
|
|
|
23256
23610
|
|
|
23257
|
-
|
|
23258
23611
|
const $9085b221b72ac69e$export$af768ccdf17d5c04 = (id, contractAddress, spenderAddress)=>({
|
|
23259
23612
|
type: ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC721,
|
|
23260
23613
|
id: id,
|
|
@@ -23262,7 +23615,7 @@ const $9085b221b72ac69e$export$af768ccdf17d5c04 = (id, contractAddress, spenderA
|
|
|
23262
23615
|
spenderAddress: spenderAddress
|
|
23263
23616
|
});
|
|
23264
23617
|
const $9085b221b72ac69e$export$586d02673c66d423 = (buyToken, decimals = 18)=>{
|
|
23265
|
-
const bnAmount = (parseUnits
|
|
23618
|
+
const bnAmount = (utils).parseUnits(buyToken.amount, decimals);
|
|
23266
23619
|
if (buyToken.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE) return {
|
|
23267
23620
|
type: ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE,
|
|
23268
23621
|
amount: bnAmount.toString()
|
|
@@ -23443,11 +23796,11 @@ async function $d35036efee31c5d1$export$dc8635800ef20f4b(provider, requirements)
|
|
|
23443
23796
|
const itemRequirements = requirements.map((itemRequirementParam, index)=>{
|
|
23444
23797
|
if (itemRequirementParam.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).NATIVE) return {
|
|
23445
23798
|
...itemRequirementParam,
|
|
23446
|
-
amount: (parseUnits
|
|
23799
|
+
amount: (utils).parseUnits(itemRequirementParam.amount, 18)
|
|
23447
23800
|
};
|
|
23448
23801
|
if (itemRequirementParam.type === ($4b58188d47aafe8d$export$1fc8f52ad1810e52).ERC20) return {
|
|
23449
23802
|
...itemRequirementParam,
|
|
23450
|
-
amount: (parseUnits
|
|
23803
|
+
amount: (utils).parseUnits(itemRequirementParam.amount, decimals[index])
|
|
23451
23804
|
};
|
|
23452
23805
|
return itemRequirementParam;
|
|
23453
23806
|
});
|