@imtbl/sdk 0.31.3 → 0.33.0
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/sdk.js +6 -6
- package/dist/browser/checkout/widgets.js +52 -52
- package/dist/{checkout_sdk.d.ts → checkout.d.ts} +23 -26
- package/dist/{checkout_sdk.js → checkout.js} +629 -617
- package/dist/config.js +1 -2
- package/dist/immutablex_client.js +1 -1
- package/dist/index.browser.js +3 -3
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +413 -402
- package/dist/index.d.ts +386 -389
- package/dist/index.js +413 -402
- package/dist/passport.js +2 -2
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -62,7 +62,6 @@ class ImmutableConfiguration {
|
|
|
62
62
|
}
|
|
63
63
|
const API_KEY_PREFIX = 'sk_imapik-';
|
|
64
64
|
const PUBLISHABLE_KEY_PREFIX = 'pk_imapik-';
|
|
65
|
-
const PUBLISHABLE_KEY_LENGTH = 30;
|
|
66
65
|
const addApiKeyToAxiosHeader = (apiKey) => {
|
|
67
66
|
if (!apiKey.startsWith(API_KEY_PREFIX)) {
|
|
68
67
|
throw new Error('Invalid API key. Create your api key in Immutable developer hub. https://hub.immutable.com');
|
|
@@ -70,7 +69,7 @@ const addApiKeyToAxiosHeader = (apiKey) => {
|
|
|
70
69
|
globalAxios$1.defaults.headers.common['x-immutable-api-key'] = apiKey;
|
|
71
70
|
};
|
|
72
71
|
const addPublishableKeyToAxiosHeader = (publishableKey) => {
|
|
73
|
-
if (!publishableKey.startsWith(PUBLISHABLE_KEY_PREFIX)
|
|
72
|
+
if (!publishableKey.startsWith(PUBLISHABLE_KEY_PREFIX)) {
|
|
74
73
|
throw new Error('Invalid Publishable key. Create your Publishable key in Immutable developer hub.'
|
|
75
74
|
+ ' https://hub.immutable.com');
|
|
76
75
|
}
|
|
@@ -3792,7 +3791,7 @@ class MultiRollupApiClients {
|
|
|
3792
3791
|
}
|
|
3793
3792
|
|
|
3794
3793
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
3795
|
-
const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.
|
|
3794
|
+
const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.33.0' };
|
|
3796
3795
|
const createConfig = ({ basePath, headers, }) => {
|
|
3797
3796
|
if (!basePath.trim()) {
|
|
3798
3797
|
throw Error('basePath can not be empty');
|
|
@@ -3852,7 +3851,7 @@ class APIError extends Error {
|
|
|
3852
3851
|
|
|
3853
3852
|
/* eslint-disable implicit-arrow-linebreak */
|
|
3854
3853
|
const defaultHeaders = {
|
|
3855
|
-
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.
|
|
3854
|
+
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.33.0',
|
|
3856
3855
|
};
|
|
3857
3856
|
/**
|
|
3858
3857
|
* createAPIConfiguration to create a custom Configuration
|
|
@@ -4263,7 +4262,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
|
|
|
4263
4262
|
chainID,
|
|
4264
4263
|
coreContractAddress,
|
|
4265
4264
|
registrationContractAddress,
|
|
4266
|
-
sdkVersion: 'ts-immutable-sdk-0.
|
|
4265
|
+
sdkVersion: 'ts-immutable-sdk-0.33.0',
|
|
4267
4266
|
});
|
|
4268
4267
|
/**
|
|
4269
4268
|
* Sets `sdkVersion` at the time of build
|
|
@@ -28688,13 +28687,13 @@ const subtractAmount = (a, b) => {
|
|
|
28688
28687
|
/**
|
|
28689
28688
|
* Converts our internal token type which could be ERC20 or Native
|
|
28690
28689
|
* into a format consumable by Checkout. They require an address to be
|
|
28691
|
-
* present. We populate the address with
|
|
28690
|
+
* present. We populate the address with the string 'native' if it's Native.
|
|
28692
28691
|
* If it's ERC20, we don't need to change it.
|
|
28693
28692
|
*/
|
|
28694
28693
|
const toPublicTokenType = (token) => {
|
|
28695
28694
|
if (token.type === 'native') {
|
|
28696
28695
|
return {
|
|
28697
|
-
address: '',
|
|
28696
|
+
address: 'native',
|
|
28698
28697
|
chainId: token.chainId,
|
|
28699
28698
|
decimals: token.decimals,
|
|
28700
28699
|
symbol: token.symbol,
|
|
@@ -29006,7 +29005,7 @@ const doesChainSupportEIP1559$1 = (fee) => {
|
|
|
29006
29005
|
/**
|
|
29007
29006
|
* Fetch the current gas price estimate. Supports both EIP-1559 and non-EIP1559 chains
|
|
29008
29007
|
* @param {JsonRpcProvider} provider - The JSON RPC provider used to fetch fee data
|
|
29009
|
-
* @param {
|
|
29008
|
+
* @param {Native} nativeToken - The native token of the chain. Gas prices will be denominated in this token
|
|
29010
29009
|
* @returns {Amount | null} - The gas price in the smallest denomination of the chain's currency,
|
|
29011
29010
|
* or null if no gas price is available
|
|
29012
29011
|
*/
|
|
@@ -29131,9 +29130,6 @@ class NativeTokenService {
|
|
|
29131
29130
|
this.wrappedToken = wrappedToken;
|
|
29132
29131
|
}
|
|
29133
29132
|
wrapAmount(amount) {
|
|
29134
|
-
if (!canUnwrapToken(amount.token)) {
|
|
29135
|
-
throw new Error(`cannot wrap non-native token: ${amount.token.address}`);
|
|
29136
|
-
}
|
|
29137
29133
|
return newAmount(amount.value, this.wrappedToken);
|
|
29138
29134
|
}
|
|
29139
29135
|
unwrapAmount(amount) {
|
|
@@ -30012,14 +30008,333 @@ const validateProviderDefaults = {
|
|
|
30012
30008
|
allowUnsupportedProvider: false,
|
|
30013
30009
|
};
|
|
30014
30010
|
|
|
30011
|
+
/**
|
|
30012
|
+
* An enum representing the checkout status types
|
|
30013
|
+
* @enum {string}
|
|
30014
|
+
* @property {string} SUCCESS - If checkout succeeded as the transactions were able to be processed
|
|
30015
|
+
* @property {string} FAILED - If checkout failed due to transactions not settling on chain
|
|
30016
|
+
* @property {string} INSUFFICIENT_FUNDS - If checkout failed due to insufficient funds
|
|
30017
|
+
*/
|
|
30018
|
+
var CheckoutStatus;
|
|
30019
|
+
(function (CheckoutStatus) {
|
|
30020
|
+
CheckoutStatus["SUCCESS"] = "SUCCESS";
|
|
30021
|
+
CheckoutStatus["FAILED"] = "FAILED";
|
|
30022
|
+
CheckoutStatus["INSUFFICIENT_FUNDS"] = "INSUFFICIENT_FUNDS";
|
|
30023
|
+
})(CheckoutStatus || (CheckoutStatus = {}));
|
|
30024
|
+
/**
|
|
30025
|
+
* An enum representing the item types
|
|
30026
|
+
* @enum {string}
|
|
30027
|
+
* @property {string} NATIVE - If the item is a native token.
|
|
30028
|
+
* @property {string} ERC20 - If the item is an ERC20 token.
|
|
30029
|
+
* @property {string} ERC721 - If the item is an ERC721 token.
|
|
30030
|
+
*/
|
|
30031
|
+
var ItemType;
|
|
30032
|
+
(function (ItemType) {
|
|
30033
|
+
ItemType["NATIVE"] = "NATIVE";
|
|
30034
|
+
ItemType["ERC20"] = "ERC20";
|
|
30035
|
+
ItemType["ERC721"] = "ERC721";
|
|
30036
|
+
})(ItemType || (ItemType = {}));
|
|
30037
|
+
/**
|
|
30038
|
+
* An enum representing transaction or gas types
|
|
30039
|
+
* @enum {string}
|
|
30040
|
+
* @property {string} TRANSACTION - If the type is a transaction
|
|
30041
|
+
* @property {string} GAS - If the type is the gas amount
|
|
30042
|
+
*/
|
|
30043
|
+
var TransactionOrGasType;
|
|
30044
|
+
(function (TransactionOrGasType) {
|
|
30045
|
+
TransactionOrGasType["TRANSACTION"] = "TRANSACTION";
|
|
30046
|
+
TransactionOrGasType["GAS"] = "GAS";
|
|
30047
|
+
})(TransactionOrGasType || (TransactionOrGasType = {}));
|
|
30048
|
+
/**
|
|
30049
|
+
* An enum representing the gas token types
|
|
30050
|
+
* @enum {string}
|
|
30051
|
+
* @property {string} NATIVE - If the gas token is a native token.
|
|
30052
|
+
* @property {string} ERC20 - If the gas token is an ERC20 token.
|
|
30053
|
+
*/
|
|
30054
|
+
var GasTokenType;
|
|
30055
|
+
(function (GasTokenType) {
|
|
30056
|
+
GasTokenType["NATIVE"] = "NATIVE";
|
|
30057
|
+
GasTokenType["ERC20"] = "ERC20";
|
|
30058
|
+
})(GasTokenType || (GasTokenType = {}));
|
|
30059
|
+
/**
|
|
30060
|
+
* An enum representing the routing outcome types
|
|
30061
|
+
* @enum {string}
|
|
30062
|
+
* @property {string} ROUTES_FOUND - If funding routes were found for the transaction.
|
|
30063
|
+
* @property {string} NO_ROUTES_FOUND - If no funding routes were found for the transaction.
|
|
30064
|
+
* @property {string} NO_ROUTE_OPTIONS - If no routing options were available for the transaction.
|
|
30065
|
+
*/
|
|
30066
|
+
var RoutingOutcomeType;
|
|
30067
|
+
(function (RoutingOutcomeType) {
|
|
30068
|
+
RoutingOutcomeType["ROUTES_FOUND"] = "ROUTES_FOUND";
|
|
30069
|
+
RoutingOutcomeType["NO_ROUTES_FOUND"] = "NO_ROUTES_FOUND";
|
|
30070
|
+
RoutingOutcomeType["NO_ROUTE_OPTIONS"] = "NO_ROUTE_OPTIONS";
|
|
30071
|
+
})(RoutingOutcomeType || (RoutingOutcomeType = {}));
|
|
30072
|
+
/**
|
|
30073
|
+
* An enum representing the funding step types
|
|
30074
|
+
* @enum {string}
|
|
30075
|
+
* @property {string} BRIDGE - If the funding step is a bridge.
|
|
30076
|
+
* @property {string} SWAP - If the funding step is a swap.
|
|
30077
|
+
* @property {string} ONRAMP - If the funding step is an onramp.
|
|
30078
|
+
*/
|
|
30079
|
+
var FundingStepType;
|
|
30080
|
+
(function (FundingStepType) {
|
|
30081
|
+
FundingStepType["BRIDGE"] = "BRIDGE";
|
|
30082
|
+
FundingStepType["SWAP"] = "SWAP";
|
|
30083
|
+
FundingStepType["ONRAMP"] = "ONRAMP";
|
|
30084
|
+
})(FundingStepType || (FundingStepType = {}));
|
|
30085
|
+
|
|
30086
|
+
// import { Passport } from '@imtbl/passport';
|
|
30087
|
+
/**
|
|
30088
|
+
* An enum representing the type of exchange.
|
|
30089
|
+
* @enum {string}
|
|
30090
|
+
* @property {string} ONRAMP - The exchange type for transacting.
|
|
30091
|
+
*/
|
|
30092
|
+
var ExchangeType;
|
|
30093
|
+
(function (ExchangeType) {
|
|
30094
|
+
ExchangeType["ONRAMP"] = "onramp";
|
|
30095
|
+
})(ExchangeType || (ExchangeType = {}));
|
|
30096
|
+
|
|
30097
|
+
/**
|
|
30098
|
+
* Enum representing different types of errors that can occur during the checkout process.
|
|
30099
|
+
*/
|
|
30100
|
+
var CheckoutErrorType;
|
|
30101
|
+
(function (CheckoutErrorType) {
|
|
30102
|
+
CheckoutErrorType["WEB3_PROVIDER_ERROR"] = "WEB3_PROVIDER_ERROR";
|
|
30103
|
+
CheckoutErrorType["PROVIDER_ERROR"] = "PROVIDER_ERROR";
|
|
30104
|
+
CheckoutErrorType["DEFAULT_PROVIDER_ERROR"] = "DEFAULT_PROVIDER_ERROR";
|
|
30105
|
+
CheckoutErrorType["CONNECT_PROVIDER_ERROR"] = "CONNECT_PROVIDER_ERROR";
|
|
30106
|
+
CheckoutErrorType["GET_BALANCE_ERROR"] = "GET_BALANCE_ERROR";
|
|
30107
|
+
CheckoutErrorType["GET_INDEXER_BALANCE_ERROR"] = "GET_INDEXER_BALANCE_ERROR";
|
|
30108
|
+
CheckoutErrorType["GET_ERC20_BALANCE_ERROR"] = "GET_ERC20_BALANCE_ERROR";
|
|
30109
|
+
CheckoutErrorType["GET_ERC721_BALANCE_ERROR"] = "GET_ERC721_BALANCE_ERROR";
|
|
30110
|
+
CheckoutErrorType["GET_NETWORK_INFO_ERROR"] = "GET_NETWORK_INFO_ERROR";
|
|
30111
|
+
CheckoutErrorType["METAMASK_PROVIDER_ERROR"] = "METAMASK_PROVIDER_ERROR";
|
|
30112
|
+
CheckoutErrorType["CHAIN_NOT_SUPPORTED_ERROR"] = "CHAIN_NOT_SUPPORTED_ERROR";
|
|
30113
|
+
CheckoutErrorType["PROVIDER_REQUEST_MISSING_ERROR"] = "PROVIDER_REQUEST_MISSING_ERROR";
|
|
30114
|
+
CheckoutErrorType["PROVIDER_REQUEST_FAILED_ERROR"] = "PROVIDER_REQUEST_FAILED_ERROR";
|
|
30115
|
+
CheckoutErrorType["USER_REJECTED_REQUEST_ERROR"] = "USER_REJECTED_REQUEST_ERROR";
|
|
30116
|
+
CheckoutErrorType["TRANSACTION_FAILED"] = "TRANSACTION_FAILED";
|
|
30117
|
+
CheckoutErrorType["INSUFFICIENT_FUNDS"] = "INSUFFICIENT_FUNDS";
|
|
30118
|
+
CheckoutErrorType["UNPREDICTABLE_GAS_LIMIT"] = "UNPREDICTABLE_GAS_LIMIT";
|
|
30119
|
+
CheckoutErrorType["INVALID_GAS_ESTIMATE_TYPE"] = "INVALID_GAS_ESTIMATE_TYPE";
|
|
30120
|
+
CheckoutErrorType["UNSUPPORTED_TOKEN_TYPE_ERROR"] = "UNSUPPORTED_TOKEN_TYPE_ERROR";
|
|
30121
|
+
CheckoutErrorType["UNSUPPORTED_BALANCE_REQUIREMENT_ERROR"] = "UNSUPPORTED_BALANCE_REQUIREMENT_ERROR";
|
|
30122
|
+
CheckoutErrorType["GET_ORDER_LISTING_ERROR"] = "GET_ORDER_LISTING_ERROR";
|
|
30123
|
+
CheckoutErrorType["CANCEL_ORDER_LISTING_ERROR"] = "CANCEL_ORDER_LISTING_ERROR";
|
|
30124
|
+
CheckoutErrorType["PREPARE_ORDER_LISTING_ERROR"] = "PREPARE_ORDER_LISTING_ERROR";
|
|
30125
|
+
CheckoutErrorType["CREATE_ORDER_LISTING_ERROR"] = "CREATE_ORDER_LISTING_ERROR";
|
|
30126
|
+
CheckoutErrorType["FULFILL_ORDER_LISTING_ERROR"] = "FULFILL_ORDER_LISTING_ERROR";
|
|
30127
|
+
CheckoutErrorType["SWITCH_NETWORK_UNSUPPORTED"] = "SWITCH_NETWORK_UNSUPPORTED";
|
|
30128
|
+
CheckoutErrorType["GET_ERC20_ALLOWANCE_ERROR"] = "GET_ERC20_ALLOWANCE_ERROR";
|
|
30129
|
+
CheckoutErrorType["GET_ERC721_ALLOWANCE_ERROR"] = "GET_ERC721_ALLOWANCE_ERROR";
|
|
30130
|
+
CheckoutErrorType["EXECUTE_APPROVAL_TRANSACTION_ERROR"] = "EXECUTE_APPROVAL_TRANSACTION_ERROR";
|
|
30131
|
+
CheckoutErrorType["EXECUTE_FULFILLMENT_TRANSACTION_ERROR"] = "EXECUTE_FULFILLMENT_TRANSACTION_ERROR";
|
|
30132
|
+
CheckoutErrorType["SIGN_MESSAGE_ERROR"] = "SIGN_MESSAGE_ERROR";
|
|
30133
|
+
CheckoutErrorType["BRIDGE_GAS_ESTIMATE_ERROR"] = "BRIDGE_GAS_ESTIMATE_ERROR";
|
|
30134
|
+
CheckoutErrorType["ORDER_FEE_ERROR"] = "ORDER_FEE_ERROR";
|
|
30135
|
+
CheckoutErrorType["ITEM_REQUIREMENTS_ERROR"] = "ITEM_REQUIREMENTS_ERROR";
|
|
30136
|
+
CheckoutErrorType["API_ERROR"] = "API_ERROR";
|
|
30137
|
+
CheckoutErrorType["ORDER_EXPIRED_ERROR"] = "ORDER_EXPIRED_ERROR";
|
|
30138
|
+
CheckoutErrorType["WIDGETS_SCRIPT_LOAD_ERROR"] = "WIDGETS_SCRIPT_LOAD_ERROR";
|
|
30139
|
+
})(CheckoutErrorType || (CheckoutErrorType = {}));
|
|
30140
|
+
/* The CheckoutError class is a custom error class in TypeScript that includes a message, type, and
|
|
30141
|
+
optional data object. */
|
|
30142
|
+
class CheckoutError extends Error {
|
|
30143
|
+
message;
|
|
30144
|
+
type;
|
|
30145
|
+
data;
|
|
30146
|
+
constructor(message, type, data) {
|
|
30147
|
+
super(message);
|
|
30148
|
+
this.message = message;
|
|
30149
|
+
this.type = type;
|
|
30150
|
+
this.data = data;
|
|
30151
|
+
}
|
|
30152
|
+
}
|
|
30153
|
+
var CheckoutInternalErrorType;
|
|
30154
|
+
(function (CheckoutInternalErrorType) {
|
|
30155
|
+
CheckoutInternalErrorType["REJECTED_SWITCH_AFTER_ADDING_NETWORK"] = "REJECTED_SWITCH_AFTER_ADDING_NETWORK";
|
|
30156
|
+
})(CheckoutInternalErrorType || (CheckoutInternalErrorType = {}));
|
|
30157
|
+
const withCheckoutError = async (
|
|
30158
|
+
/**
|
|
30159
|
+
* Wraps a function that returns a Promise and catches any errors that occur. If an error is caught,
|
|
30160
|
+
* it is wrapped in a CheckoutError and rethrown.
|
|
30161
|
+
*/
|
|
30162
|
+
fn, customError) => {
|
|
30163
|
+
try {
|
|
30164
|
+
return await fn();
|
|
30165
|
+
}
|
|
30166
|
+
catch (error) {
|
|
30167
|
+
const cause = `${error.message}` || 'UnknownError';
|
|
30168
|
+
const errorMessage = customError.message
|
|
30169
|
+
? `[${customError.type}]:${customError.message}. Cause:${cause}`
|
|
30170
|
+
: `[${customError.type}] Cause:${cause}`;
|
|
30171
|
+
if (error instanceof CheckoutError) {
|
|
30172
|
+
throw new CheckoutError(errorMessage, customError.type, {
|
|
30173
|
+
...customError.data,
|
|
30174
|
+
innerErrorType: error.type,
|
|
30175
|
+
...error.data,
|
|
30176
|
+
});
|
|
30177
|
+
}
|
|
30178
|
+
throw new CheckoutError(errorMessage, customError.type, {
|
|
30179
|
+
...customError.data,
|
|
30180
|
+
});
|
|
30181
|
+
}
|
|
30182
|
+
};
|
|
30183
|
+
|
|
30184
|
+
// this function needs to be in a separate file to prevent circular dependencies with ./network
|
|
30185
|
+
// this gives us access to the properties of the underlying provider object
|
|
30186
|
+
async function getUnderlyingChainId(web3Provider) {
|
|
30187
|
+
if (!web3Provider.provider?.request) {
|
|
30188
|
+
throw new CheckoutError('Parsed provider is not a valid Web3Provider', CheckoutErrorType.WEB3_PROVIDER_ERROR);
|
|
30189
|
+
}
|
|
30190
|
+
const chainId = await web3Provider.provider.request({
|
|
30191
|
+
method: WalletAction.GET_CHAINID,
|
|
30192
|
+
params: [],
|
|
30193
|
+
});
|
|
30194
|
+
return parseInt(chainId, 16);
|
|
30195
|
+
}
|
|
30196
|
+
|
|
30197
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
30198
|
+
const UNRECOGNISED_CHAIN_ERROR_CODE = 4902; // error code (MetaMask)
|
|
30199
|
+
// these functions should not be exported. These functions should be used as part of an exported function e.g switchWalletNetwork() above.
|
|
30200
|
+
// make sure to check if(provider.provider?.request) in the exported function and throw an error
|
|
30201
|
+
// eslint-disable-next-line consistent-return
|
|
30202
|
+
async function switchNetworkInWallet(networkMap, web3Provider, chainId) {
|
|
30203
|
+
if (web3Provider.provider?.request) {
|
|
30204
|
+
return await web3Provider.provider.request({
|
|
30205
|
+
method: WalletAction.SWITCH_NETWORK,
|
|
30206
|
+
params: [
|
|
30207
|
+
{
|
|
30208
|
+
chainId: networkMap.get(chainId)?.chainIdHex,
|
|
30209
|
+
},
|
|
30210
|
+
],
|
|
30211
|
+
});
|
|
30212
|
+
}
|
|
30213
|
+
}
|
|
30214
|
+
// TODO: Should these functions always return something?
|
|
30215
|
+
// eslint-disable-next-line consistent-return
|
|
30216
|
+
async function addNetworkToWallet(networkMap, web3Provider, chainId) {
|
|
30217
|
+
if (web3Provider.provider?.request) {
|
|
30218
|
+
const networkDetails = networkMap.get(chainId);
|
|
30219
|
+
const addNetwork = {
|
|
30220
|
+
chainId: networkDetails?.chainIdHex,
|
|
30221
|
+
chainName: networkDetails?.chainName,
|
|
30222
|
+
rpcUrls: networkDetails?.rpcUrls,
|
|
30223
|
+
nativeCurrency: networkDetails?.nativeCurrency,
|
|
30224
|
+
blockExplorerUrls: networkDetails?.blockExplorerUrls,
|
|
30225
|
+
};
|
|
30226
|
+
return await web3Provider.provider.request({
|
|
30227
|
+
method: WalletAction.ADD_NETWORK,
|
|
30228
|
+
params: [addNetwork],
|
|
30229
|
+
});
|
|
30230
|
+
}
|
|
30231
|
+
}
|
|
30232
|
+
async function getNetworkAllowList(config, { type = NetworkFilterTypes.ALL, exclude }) {
|
|
30233
|
+
const { networkMap } = config;
|
|
30234
|
+
const allowedNetworkConfig = (await config.remote.getConfig('allowedNetworks'));
|
|
30235
|
+
const list = allowedNetworkConfig.filter((network) => {
|
|
30236
|
+
const allowAllTokens = type === NetworkFilterTypes.ALL;
|
|
30237
|
+
const networkNotExcluded = !(exclude || [])
|
|
30238
|
+
.map((exc) => exc.chainId)
|
|
30239
|
+
.includes(network.chainId);
|
|
30240
|
+
return allowAllTokens && networkNotExcluded;
|
|
30241
|
+
});
|
|
30242
|
+
const allowedNetworks = [];
|
|
30243
|
+
list.forEach((element) => {
|
|
30244
|
+
const newNetwork = networkMap.get(element.chainId);
|
|
30245
|
+
if (newNetwork) {
|
|
30246
|
+
allowedNetworks.push({
|
|
30247
|
+
name: newNetwork.chainName,
|
|
30248
|
+
chainId: parseInt(newNetwork.chainIdHex, 16),
|
|
30249
|
+
nativeCurrency: newNetwork.nativeCurrency,
|
|
30250
|
+
isSupported: true,
|
|
30251
|
+
});
|
|
30252
|
+
}
|
|
30253
|
+
});
|
|
30254
|
+
return {
|
|
30255
|
+
networks: allowedNetworks,
|
|
30256
|
+
};
|
|
30257
|
+
}
|
|
30258
|
+
async function getNetworkInfo(config, web3Provider) {
|
|
30259
|
+
const { networkMap } = config;
|
|
30260
|
+
return withCheckoutError(async () => {
|
|
30261
|
+
try {
|
|
30262
|
+
const network = await web3Provider.getNetwork();
|
|
30263
|
+
if (Array.from(networkMap.keys()).includes(network.chainId)) {
|
|
30264
|
+
const chainIdNetworkInfo = networkMap.get(network.chainId);
|
|
30265
|
+
return {
|
|
30266
|
+
name: chainIdNetworkInfo.chainName,
|
|
30267
|
+
chainId: parseInt(chainIdNetworkInfo.chainIdHex, 16),
|
|
30268
|
+
nativeCurrency: chainIdNetworkInfo.nativeCurrency,
|
|
30269
|
+
isSupported: true,
|
|
30270
|
+
};
|
|
30271
|
+
}
|
|
30272
|
+
return {
|
|
30273
|
+
chainId: network.chainId,
|
|
30274
|
+
name: network.name,
|
|
30275
|
+
isSupported: false,
|
|
30276
|
+
};
|
|
30277
|
+
}
|
|
30278
|
+
catch (err) {
|
|
30279
|
+
const chainId = await getUnderlyingChainId(web3Provider);
|
|
30280
|
+
const isSupported = Array.from(networkMap.keys()).includes(chainId);
|
|
30281
|
+
return {
|
|
30282
|
+
chainId,
|
|
30283
|
+
isSupported,
|
|
30284
|
+
};
|
|
30285
|
+
}
|
|
30286
|
+
}, {
|
|
30287
|
+
type: CheckoutErrorType.GET_NETWORK_INFO_ERROR,
|
|
30288
|
+
});
|
|
30289
|
+
}
|
|
30290
|
+
async function switchWalletNetwork(config, web3Provider, chainId) {
|
|
30291
|
+
const { networkMap } = config;
|
|
30292
|
+
const allowedNetworks = await getNetworkAllowList(config, {
|
|
30293
|
+
type: NetworkFilterTypes.ALL,
|
|
30294
|
+
});
|
|
30295
|
+
if (!allowedNetworks.networks.some((network) => network.chainId === chainId)) {
|
|
30296
|
+
throw new CheckoutError(`Chain:${chainId} is not a supported chain`, CheckoutErrorType.CHAIN_NOT_SUPPORTED_ERROR);
|
|
30297
|
+
}
|
|
30298
|
+
if (web3Provider.provider?.isPassport) {
|
|
30299
|
+
throw new CheckoutError('Switching networks with Passport provider is not supported', CheckoutErrorType.SWITCH_NETWORK_UNSUPPORTED);
|
|
30300
|
+
}
|
|
30301
|
+
// WT-1146 - Refer to the README in this folder for explanation on the switch network flow
|
|
30302
|
+
try {
|
|
30303
|
+
await switchNetworkInWallet(networkMap, web3Provider, chainId);
|
|
30304
|
+
}
|
|
30305
|
+
catch (err) {
|
|
30306
|
+
if (err.code === UNRECOGNISED_CHAIN_ERROR_CODE) {
|
|
30307
|
+
try {
|
|
30308
|
+
await addNetworkToWallet(networkMap, web3Provider, chainId);
|
|
30309
|
+
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
30310
|
+
}
|
|
30311
|
+
catch (err) {
|
|
30312
|
+
throw new CheckoutError('User cancelled add network request', CheckoutErrorType.USER_REJECTED_REQUEST_ERROR);
|
|
30313
|
+
}
|
|
30314
|
+
}
|
|
30315
|
+
else {
|
|
30316
|
+
throw new CheckoutError('User cancelled switch network request', CheckoutErrorType.USER_REJECTED_REQUEST_ERROR);
|
|
30317
|
+
}
|
|
30318
|
+
}
|
|
30319
|
+
const newProvider = new providers.Web3Provider(web3Provider.provider);
|
|
30320
|
+
const newProviderNetwork = await newProvider.getNetwork();
|
|
30321
|
+
if (newProviderNetwork.chainId !== chainId) {
|
|
30322
|
+
throw new CheckoutError('User cancelled switch network request', CheckoutErrorType.USER_REJECTED_REQUEST_ERROR);
|
|
30323
|
+
}
|
|
30324
|
+
const networkInfo = await getNetworkInfo(config, newProvider);
|
|
30325
|
+
return {
|
|
30326
|
+
network: networkInfo,
|
|
30327
|
+
provider: newProvider,
|
|
30328
|
+
};
|
|
30329
|
+
}
|
|
30330
|
+
|
|
30015
30331
|
const ENV_DEVELOPMENT = 'development';
|
|
30016
|
-
const IMX_ADDRESS_ZKEVM = '0x0000000000000000000000000000000000001010';
|
|
30017
30332
|
const DEFAULT_TOKEN_DECIMALS$1 = 18;
|
|
30333
|
+
const NATIVE = 'native';
|
|
30018
30334
|
const ZKEVM_NATIVE_TOKEN = {
|
|
30019
30335
|
name: 'IMX',
|
|
30020
30336
|
symbol: 'IMX',
|
|
30021
30337
|
decimals: DEFAULT_TOKEN_DECIMALS$1,
|
|
30022
|
-
address: IMX_ADDRESS_ZKEVM,
|
|
30023
30338
|
};
|
|
30024
30339
|
/**
|
|
30025
30340
|
* Base URL for the Immutable API based on the environment.
|
|
@@ -30350,332 +30665,23 @@ const ERC721ABI = [
|
|
|
30350
30665
|
type: 'function',
|
|
30351
30666
|
},
|
|
30352
30667
|
];
|
|
30353
|
-
|
|
30354
|
-
|
|
30355
|
-
|
|
30356
|
-
|
|
30357
|
-
|
|
30358
|
-
* @property {string} FAILED - If checkout failed due to transactions not settling on chain
|
|
30359
|
-
* @property {string} INSUFFICIENT_FUNDS - If checkout failed due to insufficient funds
|
|
30360
|
-
*/
|
|
30361
|
-
var CheckoutStatus;
|
|
30362
|
-
(function (CheckoutStatus) {
|
|
30363
|
-
CheckoutStatus["SUCCESS"] = "SUCCESS";
|
|
30364
|
-
CheckoutStatus["FAILED"] = "FAILED";
|
|
30365
|
-
CheckoutStatus["INSUFFICIENT_FUNDS"] = "INSUFFICIENT_FUNDS";
|
|
30366
|
-
})(CheckoutStatus || (CheckoutStatus = {}));
|
|
30367
|
-
/**
|
|
30368
|
-
* An enum representing the item types
|
|
30369
|
-
* @enum {string}
|
|
30370
|
-
* @property {string} NATIVE - If the item is a native token.
|
|
30371
|
-
* @property {string} ERC20 - If the item is an ERC20 token.
|
|
30372
|
-
* @property {string} ERC721 - If the item is an ERC721 token.
|
|
30373
|
-
*/
|
|
30374
|
-
var ItemType;
|
|
30375
|
-
(function (ItemType) {
|
|
30376
|
-
ItemType["NATIVE"] = "NATIVE";
|
|
30377
|
-
ItemType["ERC20"] = "ERC20";
|
|
30378
|
-
ItemType["ERC721"] = "ERC721";
|
|
30379
|
-
})(ItemType || (ItemType = {}));
|
|
30380
|
-
/**
|
|
30381
|
-
* An enum representing transaction or gas types
|
|
30382
|
-
* @enum {string}
|
|
30383
|
-
* @property {string} TRANSACTION - If the type is a transaction
|
|
30384
|
-
* @property {string} GAS - If the type is the gas amount
|
|
30385
|
-
*/
|
|
30386
|
-
var TransactionOrGasType;
|
|
30387
|
-
(function (TransactionOrGasType) {
|
|
30388
|
-
TransactionOrGasType["TRANSACTION"] = "TRANSACTION";
|
|
30389
|
-
TransactionOrGasType["GAS"] = "GAS";
|
|
30390
|
-
})(TransactionOrGasType || (TransactionOrGasType = {}));
|
|
30391
|
-
/**
|
|
30392
|
-
* An enum representing the gas token types
|
|
30393
|
-
* @enum {string}
|
|
30394
|
-
* @property {string} NATIVE - If the gas token is a native token.
|
|
30395
|
-
* @property {string} ERC20 - If the gas token is an ERC20 token.
|
|
30396
|
-
*/
|
|
30397
|
-
var GasTokenType;
|
|
30398
|
-
(function (GasTokenType) {
|
|
30399
|
-
GasTokenType["NATIVE"] = "NATIVE";
|
|
30400
|
-
GasTokenType["ERC20"] = "ERC20";
|
|
30401
|
-
})(GasTokenType || (GasTokenType = {}));
|
|
30402
|
-
/**
|
|
30403
|
-
* An enum representing the routing outcome types
|
|
30404
|
-
* @enum {string}
|
|
30405
|
-
* @property {string} ROUTES_FOUND - If funding routes were found for the transaction.
|
|
30406
|
-
* @property {string} NO_ROUTES_FOUND - If no funding routes were found for the transaction.
|
|
30407
|
-
* @property {string} NO_ROUTE_OPTIONS - If no routing options were available for the transaction.
|
|
30408
|
-
*/
|
|
30409
|
-
var RoutingOutcomeType;
|
|
30410
|
-
(function (RoutingOutcomeType) {
|
|
30411
|
-
RoutingOutcomeType["ROUTES_FOUND"] = "ROUTES_FOUND";
|
|
30412
|
-
RoutingOutcomeType["NO_ROUTES_FOUND"] = "NO_ROUTES_FOUND";
|
|
30413
|
-
RoutingOutcomeType["NO_ROUTE_OPTIONS"] = "NO_ROUTE_OPTIONS";
|
|
30414
|
-
})(RoutingOutcomeType || (RoutingOutcomeType = {}));
|
|
30415
|
-
/**
|
|
30416
|
-
* An enum representing the funding step types
|
|
30417
|
-
* @enum {string}
|
|
30418
|
-
* @property {string} BRIDGE - If the funding step is a bridge.
|
|
30419
|
-
* @property {string} SWAP - If the funding step is a swap.
|
|
30420
|
-
* @property {string} ONRAMP - If the funding step is an onramp.
|
|
30421
|
-
*/
|
|
30422
|
-
var FundingStepType;
|
|
30423
|
-
(function (FundingStepType) {
|
|
30424
|
-
FundingStepType["BRIDGE"] = "BRIDGE";
|
|
30425
|
-
FundingStepType["SWAP"] = "SWAP";
|
|
30426
|
-
FundingStepType["ONRAMP"] = "ONRAMP";
|
|
30427
|
-
})(FundingStepType || (FundingStepType = {}));
|
|
30428
|
-
|
|
30429
|
-
// import { Passport } from '@imtbl/passport';
|
|
30430
|
-
/**
|
|
30431
|
-
* An enum representing the type of exchange.
|
|
30432
|
-
* @enum {string}
|
|
30433
|
-
* @property {string} ONRAMP - The exchange type for transacting.
|
|
30434
|
-
*/
|
|
30435
|
-
var ExchangeType;
|
|
30436
|
-
(function (ExchangeType) {
|
|
30437
|
-
ExchangeType["ONRAMP"] = "onramp";
|
|
30438
|
-
})(ExchangeType || (ExchangeType = {}));
|
|
30439
|
-
|
|
30440
|
-
/**
|
|
30441
|
-
* Enum representing different types of errors that can occur during the checkout process.
|
|
30442
|
-
*/
|
|
30443
|
-
var CheckoutErrorType;
|
|
30444
|
-
(function (CheckoutErrorType) {
|
|
30445
|
-
CheckoutErrorType["WEB3_PROVIDER_ERROR"] = "WEB3_PROVIDER_ERROR";
|
|
30446
|
-
CheckoutErrorType["PROVIDER_ERROR"] = "PROVIDER_ERROR";
|
|
30447
|
-
CheckoutErrorType["DEFAULT_PROVIDER_ERROR"] = "DEFAULT_PROVIDER_ERROR";
|
|
30448
|
-
CheckoutErrorType["CONNECT_PROVIDER_ERROR"] = "CONNECT_PROVIDER_ERROR";
|
|
30449
|
-
CheckoutErrorType["GET_BALANCE_ERROR"] = "GET_BALANCE_ERROR";
|
|
30450
|
-
CheckoutErrorType["GET_INDEXER_BALANCE_ERROR"] = "GET_INDEXER_BALANCE_ERROR";
|
|
30451
|
-
CheckoutErrorType["GET_ERC20_BALANCE_ERROR"] = "GET_ERC20_BALANCE_ERROR";
|
|
30452
|
-
CheckoutErrorType["GET_ERC721_BALANCE_ERROR"] = "GET_ERC721_BALANCE_ERROR";
|
|
30453
|
-
CheckoutErrorType["GET_NETWORK_INFO_ERROR"] = "GET_NETWORK_INFO_ERROR";
|
|
30454
|
-
CheckoutErrorType["METAMASK_PROVIDER_ERROR"] = "METAMASK_PROVIDER_ERROR";
|
|
30455
|
-
CheckoutErrorType["CHAIN_NOT_SUPPORTED_ERROR"] = "CHAIN_NOT_SUPPORTED_ERROR";
|
|
30456
|
-
CheckoutErrorType["PROVIDER_REQUEST_MISSING_ERROR"] = "PROVIDER_REQUEST_MISSING_ERROR";
|
|
30457
|
-
CheckoutErrorType["PROVIDER_REQUEST_FAILED_ERROR"] = "PROVIDER_REQUEST_FAILED_ERROR";
|
|
30458
|
-
CheckoutErrorType["USER_REJECTED_REQUEST_ERROR"] = "USER_REJECTED_REQUEST_ERROR";
|
|
30459
|
-
CheckoutErrorType["TRANSACTION_FAILED"] = "TRANSACTION_FAILED";
|
|
30460
|
-
CheckoutErrorType["INSUFFICIENT_FUNDS"] = "INSUFFICIENT_FUNDS";
|
|
30461
|
-
CheckoutErrorType["UNPREDICTABLE_GAS_LIMIT"] = "UNPREDICTABLE_GAS_LIMIT";
|
|
30462
|
-
CheckoutErrorType["INVALID_GAS_ESTIMATE_TYPE"] = "INVALID_GAS_ESTIMATE_TYPE";
|
|
30463
|
-
CheckoutErrorType["UNSUPPORTED_TOKEN_TYPE_ERROR"] = "UNSUPPORTED_TOKEN_TYPE_ERROR";
|
|
30464
|
-
CheckoutErrorType["UNSUPPORTED_BALANCE_REQUIREMENT_ERROR"] = "UNSUPPORTED_BALANCE_REQUIREMENT_ERROR";
|
|
30465
|
-
CheckoutErrorType["GET_ORDER_LISTING_ERROR"] = "GET_ORDER_LISTING_ERROR";
|
|
30466
|
-
CheckoutErrorType["CANCEL_ORDER_LISTING_ERROR"] = "CANCEL_ORDER_LISTING_ERROR";
|
|
30467
|
-
CheckoutErrorType["PREPARE_ORDER_LISTING_ERROR"] = "PREPARE_ORDER_LISTING_ERROR";
|
|
30468
|
-
CheckoutErrorType["CREATE_ORDER_LISTING_ERROR"] = "CREATE_ORDER_LISTING_ERROR";
|
|
30469
|
-
CheckoutErrorType["FULFILL_ORDER_LISTING_ERROR"] = "FULFILL_ORDER_LISTING_ERROR";
|
|
30470
|
-
CheckoutErrorType["SWITCH_NETWORK_UNSUPPORTED"] = "SWITCH_NETWORK_UNSUPPORTED";
|
|
30471
|
-
CheckoutErrorType["GET_ERC20_ALLOWANCE_ERROR"] = "GET_ERC20_ALLOWANCE_ERROR";
|
|
30472
|
-
CheckoutErrorType["GET_ERC721_ALLOWANCE_ERROR"] = "GET_ERC721_ALLOWANCE_ERROR";
|
|
30473
|
-
CheckoutErrorType["EXECUTE_APPROVAL_TRANSACTION_ERROR"] = "EXECUTE_APPROVAL_TRANSACTION_ERROR";
|
|
30474
|
-
CheckoutErrorType["EXECUTE_FULFILLMENT_TRANSACTION_ERROR"] = "EXECUTE_FULFILLMENT_TRANSACTION_ERROR";
|
|
30475
|
-
CheckoutErrorType["SIGN_MESSAGE_ERROR"] = "SIGN_MESSAGE_ERROR";
|
|
30476
|
-
CheckoutErrorType["BRIDGE_GAS_ESTIMATE_ERROR"] = "BRIDGE_GAS_ESTIMATE_ERROR";
|
|
30477
|
-
CheckoutErrorType["ORDER_FEE_ERROR"] = "ORDER_FEE_ERROR";
|
|
30478
|
-
CheckoutErrorType["ITEM_REQUIREMENTS_ERROR"] = "ITEM_REQUIREMENTS_ERROR";
|
|
30479
|
-
CheckoutErrorType["API_ERROR"] = "API_ERROR";
|
|
30480
|
-
CheckoutErrorType["ORDER_EXPIRED_ERROR"] = "ORDER_EXPIRED_ERROR";
|
|
30481
|
-
CheckoutErrorType["WIDGETS_SCRIPT_LOAD_ERROR"] = "WIDGETS_SCRIPT_LOAD_ERROR";
|
|
30482
|
-
})(CheckoutErrorType || (CheckoutErrorType = {}));
|
|
30483
|
-
/* The CheckoutError class is a custom error class in TypeScript that includes a message, type, and
|
|
30484
|
-
optional data object. */
|
|
30485
|
-
class CheckoutError extends Error {
|
|
30486
|
-
message;
|
|
30487
|
-
type;
|
|
30488
|
-
data;
|
|
30489
|
-
constructor(message, type, data) {
|
|
30490
|
-
super(message);
|
|
30491
|
-
this.message = message;
|
|
30492
|
-
this.type = type;
|
|
30493
|
-
this.data = data;
|
|
30494
|
-
}
|
|
30495
|
-
}
|
|
30496
|
-
var CheckoutInternalErrorType;
|
|
30497
|
-
(function (CheckoutInternalErrorType) {
|
|
30498
|
-
CheckoutInternalErrorType["REJECTED_SWITCH_AFTER_ADDING_NETWORK"] = "REJECTED_SWITCH_AFTER_ADDING_NETWORK";
|
|
30499
|
-
})(CheckoutInternalErrorType || (CheckoutInternalErrorType = {}));
|
|
30500
|
-
const withCheckoutError = async (
|
|
30501
|
-
/**
|
|
30502
|
-
* Wraps a function that returns a Promise and catches any errors that occur. If an error is caught,
|
|
30503
|
-
* it is wrapped in a CheckoutError and rethrown.
|
|
30504
|
-
*/
|
|
30505
|
-
fn, customError) => {
|
|
30506
|
-
try {
|
|
30507
|
-
return await fn();
|
|
30508
|
-
}
|
|
30509
|
-
catch (error) {
|
|
30510
|
-
const cause = `${error.message}` || 'UnknownError';
|
|
30511
|
-
const errorMessage = customError.message
|
|
30512
|
-
? `[${customError.type}]:${customError.message}. Cause:${cause}`
|
|
30513
|
-
: `[${customError.type}] Cause:${cause}`;
|
|
30514
|
-
if (error instanceof CheckoutError) {
|
|
30515
|
-
throw new CheckoutError(errorMessage, customError.type, {
|
|
30516
|
-
...customError.data,
|
|
30517
|
-
innerErrorType: error.type,
|
|
30518
|
-
...error.data,
|
|
30519
|
-
});
|
|
30520
|
-
}
|
|
30521
|
-
throw new CheckoutError(errorMessage, customError.type, {
|
|
30522
|
-
...customError.data,
|
|
30523
|
-
});
|
|
30524
|
-
}
|
|
30668
|
+
// Gas overrides -- Anti-spam mechanism for when the baseFee drops low
|
|
30669
|
+
// https://github.com/immutable/imx-docs/blob/main/docs/main/zkEVM/overview/gas-configuration.md
|
|
30670
|
+
const GAS_OVERRIDES = {
|
|
30671
|
+
maxFeePerGas: ethers.BigNumber.from(102e9),
|
|
30672
|
+
maxPriorityFeePerGas: ethers.BigNumber.from(101e9),
|
|
30525
30673
|
};
|
|
30526
30674
|
|
|
30527
|
-
|
|
30528
|
-
//
|
|
30529
|
-
|
|
30530
|
-
if (!web3Provider.provider?.request) {
|
|
30531
|
-
throw new CheckoutError('Parsed provider is not a valid Web3Provider', CheckoutErrorType.WEB3_PROVIDER_ERROR);
|
|
30532
|
-
}
|
|
30533
|
-
const chainId = await web3Provider.provider.request({
|
|
30534
|
-
method: WalletAction.GET_CHAINID,
|
|
30535
|
-
params: [],
|
|
30536
|
-
});
|
|
30537
|
-
return parseInt(chainId, 16);
|
|
30538
|
-
}
|
|
30539
|
-
|
|
30540
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
30541
|
-
const UNRECOGNISED_CHAIN_ERROR_CODE = 4902; // error code (MetaMask)
|
|
30542
|
-
// these functions should not be exported. These functions should be used as part of an exported function e.g switchWalletNetwork() above.
|
|
30543
|
-
// make sure to check if(provider.provider?.request) in the exported function and throw an error
|
|
30544
|
-
// eslint-disable-next-line consistent-return
|
|
30545
|
-
async function switchNetworkInWallet(networkMap, web3Provider, chainId) {
|
|
30546
|
-
if (web3Provider.provider?.request) {
|
|
30547
|
-
return await web3Provider.provider.request({
|
|
30548
|
-
method: WalletAction.SWITCH_NETWORK,
|
|
30549
|
-
params: [
|
|
30550
|
-
{
|
|
30551
|
-
chainId: networkMap.get(chainId)?.chainIdHex,
|
|
30552
|
-
},
|
|
30553
|
-
],
|
|
30554
|
-
});
|
|
30555
|
-
}
|
|
30556
|
-
}
|
|
30557
|
-
// TODO: Should these functions always return something?
|
|
30558
|
-
// eslint-disable-next-line consistent-return
|
|
30559
|
-
async function addNetworkToWallet(networkMap, web3Provider, chainId) {
|
|
30560
|
-
if (web3Provider.provider?.request) {
|
|
30561
|
-
const networkDetails = networkMap.get(chainId);
|
|
30562
|
-
const addNetwork = {
|
|
30563
|
-
chainId: networkDetails?.chainIdHex,
|
|
30564
|
-
chainName: networkDetails?.chainName,
|
|
30565
|
-
rpcUrls: networkDetails?.rpcUrls,
|
|
30566
|
-
nativeCurrency: networkDetails?.nativeCurrency,
|
|
30567
|
-
blockExplorerUrls: networkDetails?.blockExplorerUrls,
|
|
30568
|
-
};
|
|
30569
|
-
return await web3Provider.provider.request({
|
|
30570
|
-
method: WalletAction.ADD_NETWORK,
|
|
30571
|
-
params: [addNetwork],
|
|
30572
|
-
});
|
|
30573
|
-
}
|
|
30574
|
-
}
|
|
30575
|
-
async function getNetworkAllowList(config, { type = NetworkFilterTypes.ALL, exclude }) {
|
|
30576
|
-
const { networkMap } = config;
|
|
30577
|
-
const allowedNetworkConfig = (await config.remote.getConfig('allowedNetworks'));
|
|
30578
|
-
const list = allowedNetworkConfig.filter((network) => {
|
|
30579
|
-
const allowAllTokens = type === NetworkFilterTypes.ALL;
|
|
30580
|
-
const networkNotExcluded = !(exclude || [])
|
|
30581
|
-
.map((exc) => exc.chainId)
|
|
30582
|
-
.includes(network.chainId);
|
|
30583
|
-
return allowAllTokens && networkNotExcluded;
|
|
30584
|
-
});
|
|
30585
|
-
const allowedNetworks = [];
|
|
30586
|
-
list.forEach((element) => {
|
|
30587
|
-
const newNetwork = networkMap.get(element.chainId);
|
|
30588
|
-
if (newNetwork) {
|
|
30589
|
-
allowedNetworks.push({
|
|
30590
|
-
name: newNetwork.chainName,
|
|
30591
|
-
chainId: parseInt(newNetwork.chainIdHex, 16),
|
|
30592
|
-
nativeCurrency: newNetwork.nativeCurrency,
|
|
30593
|
-
isSupported: true,
|
|
30594
|
-
});
|
|
30595
|
-
}
|
|
30596
|
-
});
|
|
30597
|
-
return {
|
|
30598
|
-
networks: allowedNetworks,
|
|
30599
|
-
};
|
|
30600
|
-
}
|
|
30601
|
-
async function getNetworkInfo(config, web3Provider) {
|
|
30602
|
-
const { networkMap } = config;
|
|
30603
|
-
return withCheckoutError(async () => {
|
|
30604
|
-
try {
|
|
30605
|
-
const network = await web3Provider.getNetwork();
|
|
30606
|
-
if (Array.from(networkMap.keys()).includes(network.chainId)) {
|
|
30607
|
-
const chainIdNetworkInfo = networkMap.get(network.chainId);
|
|
30608
|
-
return {
|
|
30609
|
-
name: chainIdNetworkInfo.chainName,
|
|
30610
|
-
chainId: parseInt(chainIdNetworkInfo.chainIdHex, 16),
|
|
30611
|
-
nativeCurrency: chainIdNetworkInfo.nativeCurrency,
|
|
30612
|
-
isSupported: true,
|
|
30613
|
-
};
|
|
30614
|
-
}
|
|
30615
|
-
return {
|
|
30616
|
-
chainId: network.chainId,
|
|
30617
|
-
name: network.name,
|
|
30618
|
-
isSupported: false,
|
|
30619
|
-
};
|
|
30620
|
-
}
|
|
30621
|
-
catch (err) {
|
|
30622
|
-
const chainId = await getUnderlyingChainId(web3Provider);
|
|
30623
|
-
const isSupported = Array.from(networkMap.keys()).includes(chainId);
|
|
30624
|
-
return {
|
|
30625
|
-
chainId,
|
|
30626
|
-
isSupported,
|
|
30627
|
-
};
|
|
30628
|
-
}
|
|
30629
|
-
}, {
|
|
30630
|
-
type: CheckoutErrorType.GET_NETWORK_INFO_ERROR,
|
|
30631
|
-
});
|
|
30632
|
-
}
|
|
30633
|
-
async function switchWalletNetwork(config, web3Provider, chainId) {
|
|
30634
|
-
const { networkMap } = config;
|
|
30635
|
-
const allowedNetworks = await getNetworkAllowList(config, {
|
|
30636
|
-
type: NetworkFilterTypes.ALL,
|
|
30637
|
-
});
|
|
30638
|
-
if (!allowedNetworks.networks.some((network) => network.chainId === chainId)) {
|
|
30639
|
-
throw new CheckoutError(`Chain:${chainId} is not a supported chain`, CheckoutErrorType.CHAIN_NOT_SUPPORTED_ERROR);
|
|
30640
|
-
}
|
|
30641
|
-
if (web3Provider.provider?.isPassport) {
|
|
30642
|
-
throw new CheckoutError('Switching networks with Passport provider is not supported', CheckoutErrorType.SWITCH_NETWORK_UNSUPPORTED);
|
|
30643
|
-
}
|
|
30644
|
-
// WT-1146 - Refer to the README in this folder for explanation on the switch network flow
|
|
30645
|
-
try {
|
|
30646
|
-
await switchNetworkInWallet(networkMap, web3Provider, chainId);
|
|
30647
|
-
}
|
|
30648
|
-
catch (err) {
|
|
30649
|
-
if (err.code === UNRECOGNISED_CHAIN_ERROR_CODE) {
|
|
30650
|
-
try {
|
|
30651
|
-
await addNetworkToWallet(networkMap, web3Provider, chainId);
|
|
30652
|
-
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
30653
|
-
}
|
|
30654
|
-
catch (err) {
|
|
30655
|
-
throw new CheckoutError('User cancelled add network request', CheckoutErrorType.USER_REJECTED_REQUEST_ERROR);
|
|
30656
|
-
}
|
|
30657
|
-
}
|
|
30658
|
-
else {
|
|
30659
|
-
throw new CheckoutError('User cancelled switch network request', CheckoutErrorType.USER_REJECTED_REQUEST_ERROR);
|
|
30660
|
-
}
|
|
30661
|
-
}
|
|
30662
|
-
const newProvider = new providers.Web3Provider(web3Provider.provider);
|
|
30663
|
-
const newProviderNetwork = await newProvider.getNetwork();
|
|
30664
|
-
if (newProviderNetwork.chainId !== chainId) {
|
|
30665
|
-
throw new CheckoutError('User cancelled switch network request', CheckoutErrorType.USER_REJECTED_REQUEST_ERROR);
|
|
30666
|
-
}
|
|
30667
|
-
const networkInfo = await getNetworkInfo(config, newProvider);
|
|
30668
|
-
return {
|
|
30669
|
-
network: networkInfo,
|
|
30670
|
-
provider: newProvider,
|
|
30671
|
-
};
|
|
30672
|
-
}
|
|
30675
|
+
const SDK_VERSION_MARKER = '0.33.0';
|
|
30676
|
+
// This SDK version is replaced by the `yarn build` command ran on the root level
|
|
30677
|
+
const globalPackageVersion = () => SDK_VERSION_MARKER;
|
|
30673
30678
|
|
|
30674
30679
|
class RemoteConfigFetcher {
|
|
30675
30680
|
isDevelopment;
|
|
30676
30681
|
isProduction;
|
|
30677
30682
|
configCache;
|
|
30678
30683
|
tokensCache;
|
|
30684
|
+
version = 'v1';
|
|
30679
30685
|
constructor(params) {
|
|
30680
30686
|
this.isDevelopment = params.isDevelopment;
|
|
30681
30687
|
this.isProduction = params.isProduction;
|
|
@@ -30703,14 +30709,14 @@ class RemoteConfigFetcher {
|
|
|
30703
30709
|
async loadConfig() {
|
|
30704
30710
|
if (this.configCache)
|
|
30705
30711
|
return this.configCache;
|
|
30706
|
-
const response = await RemoteConfigFetcher.makeHttpRequest(`${this.getEndpoint()}/
|
|
30712
|
+
const response = await RemoteConfigFetcher.makeHttpRequest(`${this.getEndpoint()}/${this.version}/config`);
|
|
30707
30713
|
this.configCache = response.data;
|
|
30708
30714
|
return this.configCache;
|
|
30709
30715
|
}
|
|
30710
30716
|
async loadConfigTokens() {
|
|
30711
30717
|
if (this.tokensCache)
|
|
30712
30718
|
return this.tokensCache;
|
|
30713
|
-
const response = await RemoteConfigFetcher.makeHttpRequest(`${this.getEndpoint()}/
|
|
30719
|
+
const response = await RemoteConfigFetcher.makeHttpRequest(`${this.getEndpoint()}/${this.version}/config/tokens`);
|
|
30714
30720
|
this.tokensCache = response.data;
|
|
30715
30721
|
return this.tokensCache;
|
|
30716
30722
|
}
|
|
@@ -30826,6 +30832,7 @@ const getTokenAllowList = async (config, { type = TokenFilterTypes.ALL, chainId,
|
|
|
30826
30832
|
tokens: tokens.filter((token) => !exclude.map((e) => e.address).includes(token.address || '')),
|
|
30827
30833
|
};
|
|
30828
30834
|
};
|
|
30835
|
+
const isNativeToken = (address) => !address || address.toLocaleLowerCase() === NATIVE;
|
|
30829
30836
|
|
|
30830
30837
|
const CACHE_DATA_TTL = 60; // seconds
|
|
30831
30838
|
/**
|
|
@@ -31025,7 +31032,7 @@ const getIndexerBalance = async (walletAddress, chainId, filterTokens) => {
|
|
|
31025
31032
|
// Shuffle the mapping of the tokens configuration so it is a hashmap
|
|
31026
31033
|
// for faster access to tokens config objects.
|
|
31027
31034
|
const shouldFilter = filterTokens.length > 0;
|
|
31028
|
-
const mapFilterTokens = Object.assign({}, ...(filterTokens.map((t) => ({ [t.address ||
|
|
31035
|
+
const mapFilterTokens = Object.assign({}, ...(filterTokens.map((t) => ({ [t.address || NATIVE]: t }))));
|
|
31029
31036
|
// Get blockscout client for the given chain
|
|
31030
31037
|
let blockscoutClient = blockscoutClientMap.get(chainId);
|
|
31031
31038
|
if (!blockscoutClient) {
|
|
@@ -31066,6 +31073,7 @@ const getIndexerBalance = async (walletAddress, chainId, filterTokens) => {
|
|
|
31066
31073
|
const nativeBalances = async (client) => {
|
|
31067
31074
|
try {
|
|
31068
31075
|
const respNative = await client.getNativeTokenByWalletAddress({ walletAddress });
|
|
31076
|
+
respNative.token.address ||= NATIVE;
|
|
31069
31077
|
items.push(respNative);
|
|
31070
31078
|
}
|
|
31071
31079
|
catch (err) {
|
|
@@ -31108,8 +31116,7 @@ const getBalances = async (config, web3Provider, walletAddress, tokens) => {
|
|
|
31108
31116
|
const allBalancePromises = [];
|
|
31109
31117
|
tokens
|
|
31110
31118
|
.forEach((token) => {
|
|
31111
|
-
|
|
31112
|
-
if (!token.address || token.address === IMX_ADDRESS_ZKEVM) {
|
|
31119
|
+
if (!token.address || token.address.toLocaleLowerCase() === NATIVE) {
|
|
31113
31120
|
allBalancePromises.push(getBalance(config, web3Provider, walletAddress));
|
|
31114
31121
|
}
|
|
31115
31122
|
else {
|
|
@@ -31295,11 +31302,17 @@ async function getWalletAllowList(params) {
|
|
|
31295
31302
|
};
|
|
31296
31303
|
}
|
|
31297
31304
|
|
|
31305
|
+
const setTransactionGasLimits = (transaction) => {
|
|
31306
|
+
const rawTx = transaction;
|
|
31307
|
+
rawTx.maxFeePerGas = GAS_OVERRIDES.maxFeePerGas;
|
|
31308
|
+
rawTx.maxPriorityFeePerGas = GAS_OVERRIDES.maxPriorityFeePerGas;
|
|
31309
|
+
return rawTx;
|
|
31310
|
+
};
|
|
31298
31311
|
const sendTransaction = async (web3Provider, transaction) => {
|
|
31299
31312
|
try {
|
|
31300
|
-
const
|
|
31301
|
-
|
|
31302
|
-
|
|
31313
|
+
const signer = web3Provider.getSigner();
|
|
31314
|
+
const rawTx = setTransactionGasLimits(transaction);
|
|
31315
|
+
const transactionResponse = await signer.sendTransaction(rawTx);
|
|
31303
31316
|
return {
|
|
31304
31317
|
transactionResponse,
|
|
31305
31318
|
};
|
|
@@ -31462,25 +31475,21 @@ async function swapGasEstimator(config) {
|
|
|
31462
31475
|
const exchange = await createExchangeInstance(chainId, config);
|
|
31463
31476
|
// Create a fake transaction to get the gas from the quote
|
|
31464
31477
|
const { swap } = await exchange.getUnsignedSwapTxFromAmountIn(DUMMY_WALLET_ADDRESS, inAddress, outAddress, ethers.BigNumber.from(ethers.utils.parseUnits('1', DEFAULT_TOKEN_DECIMALS)));
|
|
31465
|
-
if (swap.gasFeeEstimate
|
|
31478
|
+
if (!swap.gasFeeEstimate) {
|
|
31466
31479
|
return {
|
|
31467
31480
|
gasEstimateType: GasEstimateType.SWAP,
|
|
31468
31481
|
gasFee: {},
|
|
31469
31482
|
};
|
|
31470
31483
|
}
|
|
31471
|
-
let estimatedAmount;
|
|
31472
|
-
if (swap.gasFeeEstimate.value) {
|
|
31473
|
-
estimatedAmount = ethers.BigNumber.from(swap.gasFeeEstimate.value);
|
|
31474
|
-
}
|
|
31475
31484
|
return {
|
|
31476
31485
|
gasEstimateType: GasEstimateType.SWAP,
|
|
31477
31486
|
gasFee: {
|
|
31478
|
-
estimatedAmount,
|
|
31487
|
+
estimatedAmount: swap.gasFeeEstimate.value ? ethers.BigNumber.from(swap.gasFeeEstimate.value) : undefined,
|
|
31479
31488
|
token: {
|
|
31480
|
-
address: swap.gasFeeEstimate
|
|
31481
|
-
symbol: swap.gasFeeEstimate
|
|
31482
|
-
name: swap.gasFeeEstimate
|
|
31483
|
-
decimals: swap.gasFeeEstimate
|
|
31489
|
+
address: swap.gasFeeEstimate.token.address,
|
|
31490
|
+
symbol: swap.gasFeeEstimate.token.symbol ?? '',
|
|
31491
|
+
name: swap.gasFeeEstimate.token.name ?? '',
|
|
31492
|
+
decimals: swap.gasFeeEstimate.token.decimals ?? DEFAULT_TOKEN_DECIMALS,
|
|
31484
31493
|
},
|
|
31485
31494
|
},
|
|
31486
31495
|
};
|
|
@@ -31871,7 +31880,7 @@ const getTokensFromRequirements = (itemRequirements) => itemRequirements
|
|
|
31871
31880
|
.map((itemRequirement) => {
|
|
31872
31881
|
if (itemRequirement.type === ItemType.NATIVE) {
|
|
31873
31882
|
return {
|
|
31874
|
-
address:
|
|
31883
|
+
address: NATIVE,
|
|
31875
31884
|
};
|
|
31876
31885
|
}
|
|
31877
31886
|
return {
|
|
@@ -31931,8 +31940,7 @@ const getTokenBalanceRequirement = (itemRequirement, balances) => {
|
|
|
31931
31940
|
}
|
|
31932
31941
|
else if (itemRequirement.type === ItemType.NATIVE) {
|
|
31933
31942
|
itemBalanceResult = balances.find((balance) => {
|
|
31934
|
-
return balance.token?.address
|
|
31935
|
-
|| balance.token?.address === IMX_ADDRESS_ZKEVM;
|
|
31943
|
+
return isNativeToken(balance.token?.address);
|
|
31936
31944
|
});
|
|
31937
31945
|
}
|
|
31938
31946
|
// Calculate the balance delta
|
|
@@ -31960,7 +31968,6 @@ const getTokenBalanceRequirement = (itemRequirement, balances) => {
|
|
|
31960
31968
|
name,
|
|
31961
31969
|
symbol,
|
|
31962
31970
|
decimals: DEFAULT_TOKEN_DECIMALS$1,
|
|
31963
|
-
address: IMX_ADDRESS_ZKEVM,
|
|
31964
31971
|
},
|
|
31965
31972
|
};
|
|
31966
31973
|
}
|
|
@@ -32019,9 +32026,13 @@ const getTokenBalanceRequirement = (itemRequirement, balances) => {
|
|
|
32019
32026
|
const getTokenBalances = async (config, provider, ownerAddress, itemRequirements) => {
|
|
32020
32027
|
try {
|
|
32021
32028
|
const tokenMap = new Map();
|
|
32022
|
-
getTokensFromRequirements(itemRequirements).forEach((item) =>
|
|
32023
|
-
|
|
32024
|
-
|
|
32029
|
+
getTokensFromRequirements(itemRequirements).forEach((item) => {
|
|
32030
|
+
if (!item.address)
|
|
32031
|
+
return;
|
|
32032
|
+
tokenMap.set(item.address.toLocaleLowerCase(), item);
|
|
32033
|
+
});
|
|
32034
|
+
const { balances } = await getAllBalances(config, provider, ownerAddress, getL2ChainId(config));
|
|
32035
|
+
return balances.filter((balance) => tokenMap.get((balance.token.address || NATIVE).toLocaleLowerCase()));
|
|
32025
32036
|
}
|
|
32026
32037
|
catch (error) {
|
|
32027
32038
|
throw new CheckoutError('Failed to get balances', CheckoutErrorType.GET_BALANCE_ERROR);
|
|
@@ -32427,7 +32438,7 @@ const constructFees$1 = (approvalGasFees, swapGasFees, swapFees) => {
|
|
|
32427
32438
|
const constructSwapRoute = (chainId, fundsRequired, userBalance, fees) => {
|
|
32428
32439
|
const tokenAddress = userBalance.token.address;
|
|
32429
32440
|
let type = ItemType.ERC20;
|
|
32430
|
-
if (tokenAddress
|
|
32441
|
+
if (isNativeToken(tokenAddress)) {
|
|
32431
32442
|
type = ItemType.NATIVE;
|
|
32432
32443
|
}
|
|
32433
32444
|
return {
|
|
@@ -32448,16 +32459,24 @@ const constructSwapRoute = (chainId, fundsRequired, userBalance, fees) => {
|
|
|
32448
32459
|
fees,
|
|
32449
32460
|
};
|
|
32450
32461
|
};
|
|
32462
|
+
const isBalanceRequirementTokenValid = (balanceRequirement) => {
|
|
32463
|
+
if (balanceRequirement.type === ItemType.ERC20) {
|
|
32464
|
+
return !!balanceRequirement.required.token.address;
|
|
32465
|
+
}
|
|
32466
|
+
if (balanceRequirement.type === ItemType.NATIVE) {
|
|
32467
|
+
return isNativeToken(balanceRequirement.required.token.address);
|
|
32468
|
+
}
|
|
32469
|
+
return false;
|
|
32470
|
+
};
|
|
32451
32471
|
const getRequiredToken = (balanceRequirement) => {
|
|
32452
32472
|
let address = '';
|
|
32453
32473
|
let amount = ethers.BigNumber.from(0);
|
|
32454
32474
|
switch (balanceRequirement.type) {
|
|
32455
32475
|
case ItemType.ERC20:
|
|
32456
|
-
address = balanceRequirement.required.token.address
|
|
32476
|
+
address = balanceRequirement.required.token.address;
|
|
32457
32477
|
amount = balanceRequirement.delta.balance;
|
|
32458
32478
|
break;
|
|
32459
32479
|
case ItemType.NATIVE:
|
|
32460
|
-
address = IMX_ADDRESS_ZKEVM;
|
|
32461
32480
|
amount = balanceRequirement.delta.balance;
|
|
32462
32481
|
break;
|
|
32463
32482
|
}
|
|
@@ -32478,7 +32497,8 @@ const checkUserCanCoverApprovalFees = (l2Balances, approval) => {
|
|
|
32478
32497
|
};
|
|
32479
32498
|
}
|
|
32480
32499
|
// Find the users balance of the approval token
|
|
32481
|
-
const l2BalanceOfApprovalToken = l2Balances.find((balance) => balance.token.address
|
|
32500
|
+
const l2BalanceOfApprovalToken = l2Balances.find((balance) => (isNativeToken(balance.token.address) && isNativeToken(approvalGasTokenAddress))
|
|
32501
|
+
|| balance.token.address === approvalGasTokenAddress);
|
|
32482
32502
|
if (!l2BalanceOfApprovalToken)
|
|
32483
32503
|
return { sufficient: false, approvalGasFee, approvalGasTokenAddress };
|
|
32484
32504
|
// If the user does not have enough of the token to cover approval fees then return sufficient false
|
|
@@ -32496,7 +32516,7 @@ const checkUserCanCoverSwapFees = (l2Balances, approvalFees, swapGasFees, swapFe
|
|
|
32496
32516
|
// Set up a map of token addresses to amounts for each of the swap fees
|
|
32497
32517
|
const feeMap = new Map();
|
|
32498
32518
|
// Add the approval fee to list of fees
|
|
32499
|
-
if (approvalFees.
|
|
32519
|
+
if (approvalFees.approvalGasFee.gt(ethers.BigNumber.from(0))) {
|
|
32500
32520
|
feeMap.set(approvalFees.approvalGasTokenAddress, approvalFees.approvalGasFee);
|
|
32501
32521
|
}
|
|
32502
32522
|
// Add the swap gas fee to list of fees
|
|
@@ -32532,7 +32552,8 @@ const checkUserCanCoverSwapFees = (l2Balances, approvalFees, swapGasFees, swapFe
|
|
|
32532
32552
|
for (const [tokenAddress, fee] of feeMap.entries()) {
|
|
32533
32553
|
if (fee === ethers.BigNumber.from(0))
|
|
32534
32554
|
continue;
|
|
32535
|
-
const l2BalanceOfFeeToken = l2Balances.find((balance) => balance.token.address
|
|
32555
|
+
const l2BalanceOfFeeToken = l2Balances.find((balance) => (isNativeToken(balance.token.address) && isNativeToken(tokenAddress))
|
|
32556
|
+
|| balance.token.address === tokenAddress);
|
|
32536
32557
|
if (!l2BalanceOfFeeToken) {
|
|
32537
32558
|
return false;
|
|
32538
32559
|
}
|
|
@@ -32584,9 +32605,9 @@ const swapRoute = async (config, availableRoutingOptions, walletAddress, balance
|
|
|
32584
32605
|
return fundingSteps;
|
|
32585
32606
|
if (swappableTokens.length === 0)
|
|
32586
32607
|
return fundingSteps;
|
|
32587
|
-
|
|
32588
|
-
if (requiredToken.address === '')
|
|
32608
|
+
if (!isBalanceRequirementTokenValid(balanceRequirement))
|
|
32589
32609
|
return fundingSteps;
|
|
32610
|
+
const requiredToken = getRequiredToken(balanceRequirement);
|
|
32590
32611
|
const chainId = getL2ChainId(config);
|
|
32591
32612
|
const l2TokenBalanceResult = tokenBalanceResults.get(chainId);
|
|
32592
32613
|
if (!l2TokenBalanceResult)
|
|
@@ -32683,7 +32704,7 @@ const allowListCheck = async (config, tokenBalances, availableRoutingOptions) =>
|
|
|
32683
32704
|
|
|
32684
32705
|
const getEthBalance = (balances) => {
|
|
32685
32706
|
for (const balance of balances.balances) {
|
|
32686
|
-
if (
|
|
32707
|
+
if (isNativeToken(balance.token.address)) {
|
|
32687
32708
|
return balance.balance;
|
|
32688
32709
|
}
|
|
32689
32710
|
}
|
|
@@ -32739,25 +32760,28 @@ const getImxL1Representation = async (chainId, config) => {
|
|
|
32739
32760
|
return imxMappingConfig[chainId] ?? '';
|
|
32740
32761
|
};
|
|
32741
32762
|
const fetchL1Representation = async (config, l2address) => {
|
|
32742
|
-
if (l2address
|
|
32743
|
-
return { l1address: '', l2address };
|
|
32744
|
-
if (l2address === IMX_ADDRESS_ZKEVM) {
|
|
32763
|
+
if (isNativeToken(l2address)) {
|
|
32745
32764
|
return {
|
|
32746
32765
|
l1address: await getImxL1Representation(getL1ChainId(config), config),
|
|
32747
|
-
l2address:
|
|
32766
|
+
l2address: NATIVE,
|
|
32748
32767
|
};
|
|
32749
32768
|
}
|
|
32750
32769
|
const chainName = getIndexerChainName(getL2ChainId(config));
|
|
32751
|
-
if (chainName === '')
|
|
32752
|
-
return { l1address: '', l2address }; // Chain name not a valid indexer chain name
|
|
32753
32770
|
const blockchainData = createBlockchainDataInstance(config);
|
|
32754
32771
|
const tokenData = await blockchainData.getToken({
|
|
32755
32772
|
chainName,
|
|
32756
32773
|
contractAddress: l2address,
|
|
32757
32774
|
});
|
|
32775
|
+
// TODO: When bridge is ready we need to understand how L2 ETH will be mapped back to L1 ETH
|
|
32758
32776
|
const l1address = tokenData.result.root_contract_address;
|
|
32777
|
+
if (l1address === INDEXER_ETH_ROOT_CONTRACT_ADDRESS) {
|
|
32778
|
+
return {
|
|
32779
|
+
l1address: 'native',
|
|
32780
|
+
l2address,
|
|
32781
|
+
};
|
|
32782
|
+
}
|
|
32759
32783
|
if (l1address === null)
|
|
32760
|
-
return
|
|
32784
|
+
return undefined; // No L1 representation of this token
|
|
32761
32785
|
return {
|
|
32762
32786
|
l1address,
|
|
32763
32787
|
l2address,
|
|
@@ -32844,16 +32868,9 @@ const constructBridgeFundingRoute = (chainId, balance, bridgeRequirement, itemTy
|
|
|
32844
32868
|
},
|
|
32845
32869
|
fees,
|
|
32846
32870
|
});
|
|
32847
|
-
const isNativeEth = (address) => {
|
|
32848
|
-
if (!address || address === '')
|
|
32849
|
-
return true;
|
|
32850
|
-
return false;
|
|
32851
|
-
};
|
|
32852
32871
|
const bridgeRoute = async (config, readOnlyProviders, depositorAddress, availableRoutingOptions, bridgeRequirement, tokenBalanceResults, feeEstimates) => {
|
|
32853
32872
|
if (!availableRoutingOptions.bridge)
|
|
32854
32873
|
return undefined;
|
|
32855
|
-
if (bridgeRequirement.l2address === undefined || bridgeRequirement.l2address === '')
|
|
32856
|
-
return undefined;
|
|
32857
32874
|
const chainId = getL1ChainId(config);
|
|
32858
32875
|
const tokenBalanceResult = tokenBalanceResults.get(chainId);
|
|
32859
32876
|
const l1provider = readOnlyProviders.get(chainId);
|
|
@@ -32871,12 +32888,11 @@ const bridgeRoute = async (config, readOnlyProviders, depositorAddress, availabl
|
|
|
32871
32888
|
if (!hasSufficientL1Eth(tokenBalanceResult, bridgeFeeEstimate.totalFees))
|
|
32872
32889
|
return undefined;
|
|
32873
32890
|
const l1RepresentationResult = await fetchL1Representation(config, bridgeRequirement.l2address);
|
|
32874
|
-
|
|
32875
|
-
const { l1address } = l1RepresentationResult;
|
|
32876
|
-
if (l1address === '')
|
|
32891
|
+
if (!l1RepresentationResult)
|
|
32877
32892
|
return undefined;
|
|
32878
32893
|
// Ensure l1address is in the allowed token list
|
|
32879
|
-
|
|
32894
|
+
const { l1address } = l1RepresentationResult;
|
|
32895
|
+
if (isNativeToken(l1address)) {
|
|
32880
32896
|
if (!allowedTokenList.find((token) => !('address' in token)))
|
|
32881
32897
|
return undefined;
|
|
32882
32898
|
}
|
|
@@ -32886,9 +32902,9 @@ const bridgeRoute = async (config, readOnlyProviders, depositorAddress, availabl
|
|
|
32886
32902
|
const gasForApproval = await estimateGasForBridgeApproval(config, readOnlyProviders, l1provider, depositorAddress, l1address, bridgeRequirement.amount);
|
|
32887
32903
|
let totalFees = bridgeFeeEstimate.bridgeFee.estimatedAmount;
|
|
32888
32904
|
// If the L1 representation of the requirement is ETH then find the ETH balance and check if the balance covers the delta
|
|
32889
|
-
if (l1address
|
|
32905
|
+
if (isNativeToken(l1address)) {
|
|
32890
32906
|
const nativeETHBalance = tokenBalanceResult.balances
|
|
32891
|
-
.find((balance) =>
|
|
32907
|
+
.find((balance) => isNativeToken(balance.token.address));
|
|
32892
32908
|
if (bridgeFeeEstimate.gasFee.estimatedAmount) {
|
|
32893
32909
|
totalFees = totalFees.add(bridgeFeeEstimate.gasFee.estimatedAmount);
|
|
32894
32910
|
}
|
|
@@ -33044,8 +33060,10 @@ const constructBridgeRequirements = (dexQuotes, l1balances, l2balances, l1tol2ad
|
|
|
33044
33060
|
};
|
|
33045
33061
|
|
|
33046
33062
|
const fetchL1ToL2Mappings = async (config, swappableTokens) => {
|
|
33047
|
-
const l1tol2addressMappingPromises = swappableTokens
|
|
33048
|
-
|
|
33063
|
+
const l1tol2addressMappingPromises = swappableTokens
|
|
33064
|
+
.map((token) => fetchL1Representation(config, token.address ?? ''));
|
|
33065
|
+
const mappings = await Promise.all(l1tol2addressMappingPromises);
|
|
33066
|
+
return mappings.filter((mapping) => mapping !== undefined);
|
|
33049
33067
|
};
|
|
33050
33068
|
|
|
33051
33069
|
// Fetch all the dex quotes from the list of swappable tokens
|
|
@@ -33085,10 +33103,7 @@ const abortBridgeAndSwap = (bridgeableTokens, swappableTokens, l1balances, l2bal
|
|
|
33085
33103
|
const filterSwappableTokensByBridgeableAddresses = (requiredTokenAddress, bridgeableTokens, swappableTokens, l1tol2Addresses) => {
|
|
33086
33104
|
const filteredSwappableTokens = [];
|
|
33087
33105
|
for (const addresses of l1tol2Addresses) {
|
|
33088
|
-
|
|
33089
|
-
continue;
|
|
33090
|
-
if (addresses.l2address === '')
|
|
33091
|
-
continue;
|
|
33106
|
+
// TODO: Check for ETH (native) L1 in bridgeableTokens first
|
|
33092
33107
|
if (!bridgeableTokens.includes(addresses.l1address))
|
|
33093
33108
|
continue;
|
|
33094
33109
|
// Filter out the token that is required from the swappable tokens list
|
|
@@ -33277,7 +33292,7 @@ const onRampRoute = async (config, availableRoutingOptions, balanceRequirement)
|
|
|
33277
33292
|
type: FundingStepType.ONRAMP,
|
|
33278
33293
|
chainId: getL2ChainId(config),
|
|
33279
33294
|
fundingItem: {
|
|
33280
|
-
type: required.token.address
|
|
33295
|
+
type: isNativeToken(required.token.address) ? ItemType.NATIVE : ItemType.ERC20,
|
|
33281
33296
|
fundsRequired: {
|
|
33282
33297
|
amount: delta.balance,
|
|
33283
33298
|
formattedAmount: delta.formattedBalance,
|
|
@@ -33513,8 +33528,8 @@ var SignTransactionStatusType;
|
|
|
33513
33528
|
const signApprovalTransactions = async (provider, approvalTransactions) => {
|
|
33514
33529
|
let receipts = [];
|
|
33515
33530
|
try {
|
|
33516
|
-
const response = await Promise.all(approvalTransactions.map((transaction) =>
|
|
33517
|
-
receipts = await Promise.all(response.map((transaction) => transaction.wait()));
|
|
33531
|
+
const response = await Promise.all(approvalTransactions.map((transaction) => sendTransaction(provider, transaction)));
|
|
33532
|
+
receipts = await Promise.all(response.map((transaction) => transaction.transactionResponse.wait()));
|
|
33518
33533
|
}
|
|
33519
33534
|
catch (err) {
|
|
33520
33535
|
throw new CheckoutError('An error occurred while executing the approval transaction', CheckoutErrorType.EXECUTE_APPROVAL_TRANSACTION_ERROR, {
|
|
@@ -33537,8 +33552,8 @@ const signApprovalTransactions = async (provider, approvalTransactions) => {
|
|
|
33537
33552
|
const signFulfillmentTransactions = async (provider, fulfillmentTransactions) => {
|
|
33538
33553
|
let receipts = [];
|
|
33539
33554
|
try {
|
|
33540
|
-
const response = await Promise.all(fulfillmentTransactions.map((transaction) =>
|
|
33541
|
-
receipts = await Promise.all(response.map((transaction) => transaction.wait()));
|
|
33555
|
+
const response = await Promise.all(fulfillmentTransactions.map((transaction) => sendTransaction(provider, transaction)));
|
|
33556
|
+
receipts = await Promise.all(response.map((transaction) => transaction.transactionResponse.wait()));
|
|
33542
33557
|
}
|
|
33543
33558
|
catch (err) {
|
|
33544
33559
|
throw new CheckoutError('An error occurred while executing the fulfillment transaction', CheckoutErrorType.EXECUTE_FULFILLMENT_TRANSACTION_ERROR, {
|
|
@@ -34114,10 +34129,6 @@ async function getItemRequirementsFromRequirements(provider, requirements) {
|
|
|
34114
34129
|
return itemRequirements;
|
|
34115
34130
|
}
|
|
34116
34131
|
|
|
34117
|
-
const SDK_VERSION_MARKER = '0.31.3';
|
|
34118
|
-
// This SDK version is replaced by the `yarn build` command ran on the root level
|
|
34119
|
-
const globalPackageVersion = () => SDK_VERSION_MARKER;
|
|
34120
|
-
|
|
34121
34132
|
/**
|
|
34122
34133
|
* Validates and builds a version string based on the given SemanticVersion object.
|
|
34123
34134
|
* If the version is undefined or has an invalid major version, it returns the default checkout version.
|
|
@@ -34470,7 +34481,7 @@ class Checkout {
|
|
|
34470
34481
|
}
|
|
34471
34482
|
}
|
|
34472
34483
|
|
|
34473
|
-
var
|
|
34484
|
+
var checkout = /*#__PURE__*/Object.freeze({
|
|
34474
34485
|
__proto__: null,
|
|
34475
34486
|
get BridgeEventType () { return BridgeEventType; },
|
|
34476
34487
|
CHECKOUT_API_BASE_URL: CHECKOUT_API_BASE_URL,
|
|
@@ -34505,7 +34516,7 @@ var checkout_sdk = /*#__PURE__*/Object.freeze({
|
|
|
34505
34516
|
});
|
|
34506
34517
|
|
|
34507
34518
|
exports.blockchainData = blockchain_data;
|
|
34508
|
-
exports.
|
|
34519
|
+
exports.checkout = checkout;
|
|
34509
34520
|
exports.config = config;
|
|
34510
34521
|
exports.immutablexClient = immutablex_client;
|
|
34511
34522
|
exports.orderbook = orderbook;
|