@imtbl/sdk 0.36.5 → 0.38.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 +58 -58
- package/dist/checkout.d.ts +633 -194
- package/dist/checkout.js +222 -106
- 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 +227 -110
- package/dist/index.d.ts +510 -66
- package/dist/index.js +227 -110
- package/dist/passport.js +2 -2
- package/package.json +4 -1
package/dist/checkout.js
CHANGED
|
@@ -21169,13 +21169,13 @@ var ProtocolData;
|
|
|
21169
21169
|
})(ProtocolData.order_type || (ProtocolData.order_type = {}));
|
|
21170
21170
|
})(ProtocolData || (ProtocolData = {}));
|
|
21171
21171
|
|
|
21172
|
-
var FeeType;
|
|
21172
|
+
var FeeType$1;
|
|
21173
21173
|
(function (FeeType) {
|
|
21174
21174
|
FeeType["MAKER_ECOSYSTEM"] = "MAKER_ECOSYSTEM";
|
|
21175
21175
|
FeeType["TAKER_ECOSYSTEM"] = "TAKER_ECOSYSTEM";
|
|
21176
21176
|
FeeType["PROTOCOL"] = "PROTOCOL";
|
|
21177
21177
|
FeeType["ROYALTY"] = "ROYALTY";
|
|
21178
|
-
})(FeeType || (FeeType = {}));
|
|
21178
|
+
})(FeeType$1 || (FeeType$1 = {}));
|
|
21179
21179
|
var TransactionPurpose;
|
|
21180
21180
|
(function (TransactionPurpose) {
|
|
21181
21181
|
TransactionPurpose["APPROVAL"] = "APPROVAL";
|
|
@@ -21737,7 +21737,7 @@ class ImmutableApiClient {
|
|
|
21737
21737
|
],
|
|
21738
21738
|
fees: makerFees.map((x) => ({
|
|
21739
21739
|
amount: x.amount,
|
|
21740
|
-
type: FeeType.MAKER_ECOSYSTEM,
|
|
21740
|
+
type: FeeType$1.MAKER_ECOSYSTEM,
|
|
21741
21741
|
recipient_address: x.recipientAddress,
|
|
21742
21742
|
})),
|
|
21743
21743
|
end_at: new Date(parseInt(`${orderComponents.endTime.toString()}000`, 10)).toISOString(),
|
|
@@ -21951,7 +21951,7 @@ class Orderbook {
|
|
|
21951
21951
|
order_id: listingId,
|
|
21952
21952
|
fees: takerFees.map((fee) => ({
|
|
21953
21953
|
amount: fee.amount,
|
|
21954
|
-
type: FeeType.TAKER_ECOSYSTEM,
|
|
21954
|
+
type: FeeType$1.TAKER_ECOSYSTEM,
|
|
21955
21955
|
recipient_address: fee.recipientAddress,
|
|
21956
21956
|
})),
|
|
21957
21957
|
},
|
|
@@ -21974,7 +21974,7 @@ class Orderbook {
|
|
|
21974
21974
|
order_id: listingRequest.listingId,
|
|
21975
21975
|
fees: listingRequest.takerFees.map((fee) => ({
|
|
21976
21976
|
amount: fee.amount,
|
|
21977
|
-
type: FeeType.TAKER_ECOSYSTEM,
|
|
21977
|
+
type: FeeType$1.TAKER_ECOSYSTEM,
|
|
21978
21978
|
recipient_address: fee.recipientAddress,
|
|
21979
21979
|
})),
|
|
21980
21980
|
})));
|
|
@@ -26051,7 +26051,7 @@ class APIError extends Error {
|
|
|
26051
26051
|
|
|
26052
26052
|
/* eslint-disable implicit-arrow-linebreak */
|
|
26053
26053
|
const defaultHeaders = {
|
|
26054
|
-
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.
|
|
26054
|
+
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.38.0',
|
|
26055
26055
|
};
|
|
26056
26056
|
/**
|
|
26057
26057
|
* createAPIConfiguration to create a custom Configuration
|
|
@@ -26497,6 +26497,7 @@ var ConnectEventType;
|
|
|
26497
26497
|
ConnectEventType["CLOSE_WIDGET"] = "close-widget";
|
|
26498
26498
|
ConnectEventType["SUCCESS"] = "success";
|
|
26499
26499
|
ConnectEventType["FAILURE"] = "failure";
|
|
26500
|
+
ConnectEventType["LANGUAGE_CHANGED"] = "language-changed";
|
|
26500
26501
|
})(ConnectEventType || (ConnectEventType = {}));
|
|
26501
26502
|
|
|
26502
26503
|
/**
|
|
@@ -26507,6 +26508,7 @@ var WalletEventType;
|
|
|
26507
26508
|
WalletEventType["CLOSE_WIDGET"] = "close-widget";
|
|
26508
26509
|
WalletEventType["NETWORK_SWITCH"] = "network-switch";
|
|
26509
26510
|
WalletEventType["DISCONNECT_WALLET"] = "disconnect-wallet";
|
|
26511
|
+
WalletEventType["LANGUAGE_CHANGED"] = "language-changed";
|
|
26510
26512
|
})(WalletEventType || (WalletEventType = {}));
|
|
26511
26513
|
|
|
26512
26514
|
/**
|
|
@@ -26518,6 +26520,7 @@ var SwapEventType;
|
|
|
26518
26520
|
SwapEventType["SUCCESS"] = "success";
|
|
26519
26521
|
SwapEventType["FAILURE"] = "failure";
|
|
26520
26522
|
SwapEventType["REJECTED"] = "rejected";
|
|
26523
|
+
SwapEventType["LANGUAGE_CHANGED"] = "language-changed";
|
|
26521
26524
|
})(SwapEventType || (SwapEventType = {}));
|
|
26522
26525
|
|
|
26523
26526
|
/**
|
|
@@ -26530,6 +26533,7 @@ var SaleEventType;
|
|
|
26530
26533
|
SaleEventType["FAILURE"] = "failure";
|
|
26531
26534
|
SaleEventType["REJECTED"] = "rejected";
|
|
26532
26535
|
SaleEventType["TRANSACTION_SUCCESS"] = "transaction-success";
|
|
26536
|
+
SaleEventType["LANGUAGE_CHANGED"] = "language-changed";
|
|
26533
26537
|
})(SaleEventType || (SaleEventType = {}));
|
|
26534
26538
|
|
|
26535
26539
|
/**
|
|
@@ -26540,6 +26544,7 @@ var BridgeEventType;
|
|
|
26540
26544
|
BridgeEventType["CLOSE_WIDGET"] = "close-widget";
|
|
26541
26545
|
BridgeEventType["FAILURE"] = "failure";
|
|
26542
26546
|
BridgeEventType["TRANSACTION_SENT"] = "transaction-sent";
|
|
26547
|
+
BridgeEventType["LANGUAGE_CHANGED"] = "language-changed";
|
|
26543
26548
|
})(BridgeEventType || (BridgeEventType = {}));
|
|
26544
26549
|
|
|
26545
26550
|
/**
|
|
@@ -26562,6 +26567,7 @@ var OnRampEventType;
|
|
|
26562
26567
|
OnRampEventType["CLOSE_WIDGET"] = "close-widget";
|
|
26563
26568
|
OnRampEventType["SUCCESS"] = "success";
|
|
26564
26569
|
OnRampEventType["FAILURE"] = "failure";
|
|
26570
|
+
OnRampEventType["LANGUAGE_CHANGED"] = "language-changed";
|
|
26565
26571
|
})(OnRampEventType || (OnRampEventType = {}));
|
|
26566
26572
|
|
|
26567
26573
|
/**
|
|
@@ -26770,6 +26776,21 @@ var RoutingOutcomeType;
|
|
|
26770
26776
|
RoutingOutcomeType["NO_ROUTES_FOUND"] = "NO_ROUTES_FOUND";
|
|
26771
26777
|
RoutingOutcomeType["NO_ROUTE_OPTIONS"] = "NO_ROUTE_OPTIONS";
|
|
26772
26778
|
})(RoutingOutcomeType || (RoutingOutcomeType = {}));
|
|
26779
|
+
/**
|
|
26780
|
+
* An enum representing the funding step types
|
|
26781
|
+
* @enum {string}
|
|
26782
|
+
* @property {string} GAS - If the fee is a gas fee.
|
|
26783
|
+
* @property {string} BRIDGE_FEE - If the fee is a bridge fee.
|
|
26784
|
+
* @property {string} SWAP_FEE - If the fee is a swap fee.
|
|
26785
|
+
* @property {string} IMMUTABLE_FEE - If the fee is an immutable fee.
|
|
26786
|
+
*/
|
|
26787
|
+
var FeeType;
|
|
26788
|
+
(function (FeeType) {
|
|
26789
|
+
FeeType["GAS"] = "GAS";
|
|
26790
|
+
FeeType["BRIDGE_FEE"] = "BRIDGE_FEE";
|
|
26791
|
+
FeeType["SWAP_FEE"] = "SWAP_FEE";
|
|
26792
|
+
FeeType["IMMUTABLE_FEE"] = "IMMUTABLE_FEE";
|
|
26793
|
+
})(FeeType || (FeeType = {}));
|
|
26773
26794
|
/**
|
|
26774
26795
|
* An enum representing the funding step types
|
|
26775
26796
|
* @enum {string}
|
|
@@ -27375,32 +27396,21 @@ const GAS_OVERRIDES = {
|
|
|
27375
27396
|
maxPriorityFeePerGas: BigNumber$1.from(101e9),
|
|
27376
27397
|
};
|
|
27377
27398
|
|
|
27378
|
-
const SDK_VERSION_MARKER = '0.
|
|
27399
|
+
const SDK_VERSION_MARKER = '0.38.0';
|
|
27379
27400
|
// This SDK version is replaced by the `yarn build` command ran on the root level
|
|
27380
27401
|
const globalPackageVersion = () => SDK_VERSION_MARKER;
|
|
27381
27402
|
|
|
27382
27403
|
class RemoteConfigFetcher {
|
|
27404
|
+
httpClient;
|
|
27383
27405
|
isDevelopment;
|
|
27384
27406
|
isProduction;
|
|
27385
27407
|
configCache;
|
|
27386
27408
|
tokensCache;
|
|
27387
27409
|
version = 'v1';
|
|
27388
|
-
constructor(params) {
|
|
27410
|
+
constructor(httpClient, params) {
|
|
27389
27411
|
this.isDevelopment = params.isDevelopment;
|
|
27390
27412
|
this.isProduction = params.isProduction;
|
|
27391
|
-
|
|
27392
|
-
static async makeHttpRequest(url) {
|
|
27393
|
-
let response;
|
|
27394
|
-
try {
|
|
27395
|
-
response = await globalAxios.get(url);
|
|
27396
|
-
}
|
|
27397
|
-
catch (error) {
|
|
27398
|
-
throw new CheckoutError(`Error fetching from api: ${error.message}`, CheckoutErrorType.API_ERROR);
|
|
27399
|
-
}
|
|
27400
|
-
if (response.status !== 200) {
|
|
27401
|
-
throw new CheckoutError(`Error fetching from api: ${response.status} ${response.statusText}`, CheckoutErrorType.API_ERROR);
|
|
27402
|
-
}
|
|
27403
|
-
return response;
|
|
27413
|
+
this.httpClient = httpClient;
|
|
27404
27414
|
}
|
|
27405
27415
|
getEndpoint = () => {
|
|
27406
27416
|
if (this.isDevelopment)
|
|
@@ -27412,14 +27422,14 @@ class RemoteConfigFetcher {
|
|
|
27412
27422
|
async loadConfig() {
|
|
27413
27423
|
if (this.configCache)
|
|
27414
27424
|
return this.configCache;
|
|
27415
|
-
const response = await
|
|
27425
|
+
const response = await this.httpClient.get(`${this.getEndpoint()}/${this.version}/config`);
|
|
27416
27426
|
this.configCache = response.data;
|
|
27417
27427
|
return this.configCache;
|
|
27418
27428
|
}
|
|
27419
27429
|
async loadConfigTokens() {
|
|
27420
27430
|
if (this.tokensCache)
|
|
27421
27431
|
return this.tokensCache;
|
|
27422
|
-
const response = await
|
|
27432
|
+
const response = await this.httpClient.get(`${this.getEndpoint()}/${this.version}/config/tokens`);
|
|
27423
27433
|
this.tokensCache = response.data;
|
|
27424
27434
|
return this.tokensCache;
|
|
27425
27435
|
}
|
|
@@ -27437,6 +27447,7 @@ class RemoteConfigFetcher {
|
|
|
27437
27447
|
return {};
|
|
27438
27448
|
return config[chainId] ?? [];
|
|
27439
27449
|
}
|
|
27450
|
+
getHttpClient = () => this.httpClient;
|
|
27440
27451
|
}
|
|
27441
27452
|
|
|
27442
27453
|
class CheckoutConfigurationError extends Error {
|
|
@@ -27487,7 +27498,7 @@ class CheckoutConfiguration {
|
|
|
27487
27498
|
remote;
|
|
27488
27499
|
environment;
|
|
27489
27500
|
networkMap;
|
|
27490
|
-
constructor(config) {
|
|
27501
|
+
constructor(config, httpClient) {
|
|
27491
27502
|
if (!Object.values(Environment$1).includes(config.baseConfig.environment)) {
|
|
27492
27503
|
throw new CheckoutConfigurationError('Invalid checkout configuration of environment');
|
|
27493
27504
|
}
|
|
@@ -27498,7 +27509,7 @@ class CheckoutConfiguration {
|
|
|
27498
27509
|
this.isSwapEnabled = config.swap?.enable ?? DEFAULT_SWAP_ENABLED;
|
|
27499
27510
|
this.isBridgeEnabled = config.bridge?.enable ?? DEFAULT_BRIDGE_ENABLED;
|
|
27500
27511
|
this.networkMap = networkMap(this.isProduction, this.isDevelopment);
|
|
27501
|
-
this.remote = new RemoteConfigFetcher({
|
|
27512
|
+
this.remote = new RemoteConfigFetcher(httpClient, {
|
|
27502
27513
|
isDevelopment: this.isDevelopment,
|
|
27503
27514
|
isProduction: this.isProduction,
|
|
27504
27515
|
});
|
|
@@ -27563,9 +27574,7 @@ class Blockscout {
|
|
|
27563
27574
|
ttl;
|
|
27564
27575
|
chainId;
|
|
27565
27576
|
cacheMap;
|
|
27566
|
-
|
|
27567
|
-
return globalAxios.get(url);
|
|
27568
|
-
}
|
|
27577
|
+
httpClient;
|
|
27569
27578
|
setCache(key, data) {
|
|
27570
27579
|
this.cacheMap[key] = { data, ttl: new Date().getTime() + this.ttl * 1000 };
|
|
27571
27580
|
}
|
|
@@ -27577,11 +27586,13 @@ class Blockscout {
|
|
|
27577
27586
|
}
|
|
27578
27587
|
/**
|
|
27579
27588
|
* Blockscout constructor
|
|
27589
|
+
* @param httpClient Client used for http requests
|
|
27580
27590
|
* @param chainId target chain
|
|
27581
27591
|
* @param ttl cache TTL
|
|
27582
27592
|
*/
|
|
27583
|
-
constructor(
|
|
27584
|
-
this.
|
|
27593
|
+
constructor(httpClient, chainId, ttl) {
|
|
27594
|
+
this.httpClient = httpClient;
|
|
27595
|
+
this.chainId = chainId;
|
|
27585
27596
|
this.url = BLOCKSCOUT_CHAIN_URL_MAP[this.chainId].url;
|
|
27586
27597
|
const native = BLOCKSCOUT_CHAIN_URL_MAP[this.chainId].nativeToken;
|
|
27587
27598
|
this.nativeToken = {
|
|
@@ -27591,7 +27602,7 @@ class Blockscout {
|
|
|
27591
27602
|
symbol: native.symbol,
|
|
27592
27603
|
};
|
|
27593
27604
|
this.cacheMap = {};
|
|
27594
|
-
this.ttl =
|
|
27605
|
+
this.ttl = ttl !== undefined ? ttl : CACHE_DATA_TTL;
|
|
27595
27606
|
}
|
|
27596
27607
|
/**
|
|
27597
27608
|
* isChainSupported verifies if the chain is supported by Blockscout
|
|
@@ -27619,7 +27630,7 @@ class Blockscout {
|
|
|
27619
27630
|
const cached = this.getCache(url);
|
|
27620
27631
|
if (cached)
|
|
27621
27632
|
return Promise.resolve(cached);
|
|
27622
|
-
const response = await
|
|
27633
|
+
const response = await this.httpClient.get(url);
|
|
27623
27634
|
if (response.status >= 400) {
|
|
27624
27635
|
return Promise.reject({
|
|
27625
27636
|
code: response.status,
|
|
@@ -27660,7 +27671,7 @@ class Blockscout {
|
|
|
27660
27671
|
const cached = this.getCache(url);
|
|
27661
27672
|
if (cached)
|
|
27662
27673
|
return Promise.resolve(cached);
|
|
27663
|
-
const response = await
|
|
27674
|
+
const response = await this.httpClient.get(url);
|
|
27664
27675
|
if (response.status >= 400) {
|
|
27665
27676
|
return Promise.reject({
|
|
27666
27677
|
code: response.status,
|
|
@@ -27745,7 +27756,7 @@ const blockscoutClientMap = new Map();
|
|
|
27745
27756
|
// This function is a utility function that can be used to reset the
|
|
27746
27757
|
// blockscout map and therefore clear all the cache.
|
|
27747
27758
|
const resetBlockscoutClientMap = () => blockscoutClientMap.clear();
|
|
27748
|
-
const getIndexerBalance = async (walletAddress, chainId, filterTokens) => {
|
|
27759
|
+
const getIndexerBalance = async (config, walletAddress, chainId, filterTokens) => {
|
|
27749
27760
|
// Shuffle the mapping of the tokens configuration so it is a hashmap
|
|
27750
27761
|
// for faster access to tokens config objects.
|
|
27751
27762
|
const shouldFilter = filterTokens !== undefined;
|
|
@@ -27753,7 +27764,8 @@ const getIndexerBalance = async (walletAddress, chainId, filterTokens) => {
|
|
|
27753
27764
|
// Get blockscout client for the given chain
|
|
27754
27765
|
let blockscoutClient = blockscoutClientMap.get(chainId);
|
|
27755
27766
|
if (!blockscoutClient) {
|
|
27756
|
-
|
|
27767
|
+
const httpClient = config.remote.getHttpClient();
|
|
27768
|
+
blockscoutClient = new Blockscout(httpClient, chainId);
|
|
27757
27769
|
blockscoutClientMap.set(chainId, blockscoutClient);
|
|
27758
27770
|
}
|
|
27759
27771
|
// Hold the items in an array for post-fetching processing
|
|
@@ -27888,7 +27900,7 @@ const getAllBalances = async (config, web3Provider, walletAddress, chainId) => {
|
|
|
27888
27900
|
const isL1Chain = getL1ChainId(config) === chainId;
|
|
27889
27901
|
if (!address)
|
|
27890
27902
|
address = await web3Provider?.getSigner().getAddress();
|
|
27891
|
-
return await measureAsyncExecution(config, `Time to fetch balances using blockscout for ${chainId}`, getIndexerBalance(address, chainId, isL1Chain ? tokens : undefined));
|
|
27903
|
+
return await measureAsyncExecution(config, `Time to fetch balances using blockscout for ${chainId}`, getIndexerBalance(config, address, chainId, isL1Chain ? tokens : undefined));
|
|
27892
27904
|
}
|
|
27893
27905
|
if (!web3Provider) {
|
|
27894
27906
|
throw new CheckoutError('indexer is disabled for this chain, you must provide a provider.', CheckoutErrorType.MISSING_PARAMS);
|
|
@@ -28269,8 +28281,8 @@ const erc20ItemAggregator = (itemRequirements) => {
|
|
|
28269
28281
|
aggregatedItemRequirements.push(itemRequirement);
|
|
28270
28282
|
return;
|
|
28271
28283
|
}
|
|
28272
|
-
const {
|
|
28273
|
-
const key = `${
|
|
28284
|
+
const { tokenAddress, spenderAddress, amount } = itemRequirement;
|
|
28285
|
+
const key = `${tokenAddress}${spenderAddress}`;
|
|
28274
28286
|
const aggregateItem = aggregatedMap.get(key);
|
|
28275
28287
|
if (aggregateItem && aggregateItem.type === ItemType.ERC20) {
|
|
28276
28288
|
aggregateItem.amount = BigNumber$1.from(aggregateItem.amount).add(amount);
|
|
@@ -28336,10 +28348,10 @@ const hasERC20Allowances = async (provider, ownerAddress, itemRequirements) => {
|
|
|
28336
28348
|
for (const itemRequirement of itemRequirements) {
|
|
28337
28349
|
if (itemRequirement.type !== ItemType.ERC20)
|
|
28338
28350
|
continue;
|
|
28339
|
-
const {
|
|
28340
|
-
const key = `${
|
|
28351
|
+
const { tokenAddress, spenderAddress } = itemRequirement;
|
|
28352
|
+
const key = `${tokenAddress}${spenderAddress}`;
|
|
28341
28353
|
erc20s.set(key, itemRequirement);
|
|
28342
|
-
allowancePromises.set(key, getERC20Allowance(provider, ownerAddress,
|
|
28354
|
+
allowancePromises.set(key, getERC20Allowance(provider, ownerAddress, tokenAddress, spenderAddress));
|
|
28343
28355
|
}
|
|
28344
28356
|
const allowances = await Promise.all(allowancePromises.values());
|
|
28345
28357
|
const allowancePromiseIds = Array.from(allowancePromises.keys());
|
|
@@ -28358,8 +28370,8 @@ const hasERC20Allowances = async (provider, ownerAddress, itemRequirements) => {
|
|
|
28358
28370
|
continue;
|
|
28359
28371
|
}
|
|
28360
28372
|
sufficient = false; // Set sufficient false on the root of the return object when an ERC20 is insufficient
|
|
28361
|
-
const {
|
|
28362
|
-
const key = `${
|
|
28373
|
+
const { tokenAddress, spenderAddress } = itemRequirement;
|
|
28374
|
+
const key = `${tokenAddress}${spenderAddress}`;
|
|
28363
28375
|
const delta = itemRequirement.amount.sub(allowances[index]);
|
|
28364
28376
|
// Create maps for both the insufficient ERC20 data and the transaction promises using the same key so the results can be merged
|
|
28365
28377
|
insufficientERC20s.set(key, {
|
|
@@ -28369,7 +28381,7 @@ const hasERC20Allowances = async (provider, ownerAddress, itemRequirements) => {
|
|
|
28369
28381
|
itemRequirement,
|
|
28370
28382
|
approvalTransaction: undefined,
|
|
28371
28383
|
});
|
|
28372
|
-
transactionPromises.set(key, getERC20ApprovalTransaction(provider, ownerAddress,
|
|
28384
|
+
transactionPromises.set(key, getERC20ApprovalTransaction(provider, ownerAddress, tokenAddress, spenderAddress, delta));
|
|
28373
28385
|
}
|
|
28374
28386
|
// Resolves the approval transactions and merges them with the insufficient ERC20 data
|
|
28375
28387
|
const transactions = await Promise.all(transactionPromises.values());
|
|
@@ -28554,8 +28566,8 @@ const erc20BalanceAggregator = (itemRequirements) => {
|
|
|
28554
28566
|
aggregatedItemRequirements.push(itemRequirement);
|
|
28555
28567
|
return;
|
|
28556
28568
|
}
|
|
28557
|
-
const {
|
|
28558
|
-
const key = `${
|
|
28569
|
+
const { tokenAddress, amount } = itemRequirement;
|
|
28570
|
+
const key = `${tokenAddress}`;
|
|
28559
28571
|
const aggregateItem = aggregatedMap.get(key);
|
|
28560
28572
|
if (aggregateItem && aggregateItem.type === ItemType.ERC20) {
|
|
28561
28573
|
aggregateItem.amount = BigNumber$1.from(aggregateItem.amount).add(amount);
|
|
@@ -28588,14 +28600,21 @@ const balanceAggregator = (itemRequirements) => erc721BalanceAggregator(erc20Bal
|
|
|
28588
28600
|
/* eslint-disable arrow-body-style */
|
|
28589
28601
|
const getTokensFromRequirements = (itemRequirements) => itemRequirements
|
|
28590
28602
|
.map((itemRequirement) => {
|
|
28591
|
-
|
|
28592
|
-
|
|
28593
|
-
|
|
28594
|
-
|
|
28603
|
+
switch (itemRequirement.type) {
|
|
28604
|
+
case ItemType.ERC20:
|
|
28605
|
+
return {
|
|
28606
|
+
address: itemRequirement.tokenAddress,
|
|
28607
|
+
};
|
|
28608
|
+
case ItemType.NATIVE:
|
|
28609
|
+
return {
|
|
28610
|
+
address: NATIVE,
|
|
28611
|
+
};
|
|
28612
|
+
case ItemType.ERC721:
|
|
28613
|
+
default:
|
|
28614
|
+
return {
|
|
28615
|
+
address: itemRequirement.contractAddress,
|
|
28616
|
+
};
|
|
28595
28617
|
}
|
|
28596
|
-
return {
|
|
28597
|
-
address: itemRequirement.contractAddress,
|
|
28598
|
-
};
|
|
28599
28618
|
});
|
|
28600
28619
|
/**
|
|
28601
28620
|
* Gets the balance requirement with delta for an ERC721 requirement.
|
|
@@ -28645,7 +28664,7 @@ const getTokenBalanceRequirement = (itemRequirement, balances) => {
|
|
|
28645
28664
|
// Get the requirements related balance
|
|
28646
28665
|
if (itemRequirement.type === ItemType.ERC20) {
|
|
28647
28666
|
itemBalanceResult = balances.find((balance) => {
|
|
28648
|
-
return balance.token?.address === itemRequirement.
|
|
28667
|
+
return balance.token?.address === itemRequirement.tokenAddress;
|
|
28649
28668
|
});
|
|
28650
28669
|
}
|
|
28651
28670
|
else if (itemRequirement.type === ItemType.NATIVE) {
|
|
@@ -28709,7 +28728,7 @@ const getTokenBalanceRequirement = (itemRequirement, balances) => {
|
|
|
28709
28728
|
token: {
|
|
28710
28729
|
name,
|
|
28711
28730
|
symbol,
|
|
28712
|
-
address: itemRequirement.
|
|
28731
|
+
address: itemRequirement.tokenAddress,
|
|
28713
28732
|
decimals,
|
|
28714
28733
|
},
|
|
28715
28734
|
};
|
|
@@ -28868,7 +28887,7 @@ const getGasItemRequirement = (gas, transactionOrGas) => {
|
|
|
28868
28887
|
return {
|
|
28869
28888
|
type: ItemType.ERC20,
|
|
28870
28889
|
amount: gas,
|
|
28871
|
-
|
|
28890
|
+
tokenAddress: transactionOrGas.gasToken.tokenAddress,
|
|
28872
28891
|
spenderAddress: '',
|
|
28873
28892
|
};
|
|
28874
28893
|
};
|
|
@@ -29091,36 +29110,37 @@ const quoteFetcher = async (config, chainId, walletAddress, requiredToken, swapp
|
|
|
29091
29110
|
}
|
|
29092
29111
|
};
|
|
29093
29112
|
|
|
29094
|
-
const constructFees$1 = (
|
|
29113
|
+
const constructFees$1 = (approvalGasFee, swapGasFee, swapFees) => {
|
|
29095
29114
|
let approvalGasFeeAmount = BigNumber$1.from(0);
|
|
29096
29115
|
let approvalGasFeeFormatted = '0';
|
|
29097
29116
|
let approvalToken;
|
|
29098
|
-
if (
|
|
29099
|
-
approvalGasFeeAmount =
|
|
29100
|
-
approvalGasFeeFormatted = utils$1.formatUnits(
|
|
29117
|
+
if (approvalGasFee) {
|
|
29118
|
+
approvalGasFeeAmount = approvalGasFee.value;
|
|
29119
|
+
approvalGasFeeFormatted = utils$1.formatUnits(approvalGasFee.value, approvalGasFee.token.decimals);
|
|
29101
29120
|
approvalToken = {
|
|
29102
|
-
name:
|
|
29103
|
-
symbol:
|
|
29104
|
-
address:
|
|
29105
|
-
decimals:
|
|
29121
|
+
name: approvalGasFee.token.name ?? '',
|
|
29122
|
+
symbol: approvalGasFee.token.symbol ?? '',
|
|
29123
|
+
address: approvalGasFee.token.address,
|
|
29124
|
+
decimals: approvalGasFee.token.decimals,
|
|
29106
29125
|
};
|
|
29107
29126
|
}
|
|
29108
29127
|
let swapGasFeeAmount = BigNumber$1.from(0);
|
|
29109
29128
|
let swapGasFeeFormatted = '0';
|
|
29110
29129
|
let swapGasToken;
|
|
29111
|
-
if (
|
|
29112
|
-
swapGasFeeAmount =
|
|
29113
|
-
swapGasFeeFormatted = utils$1.formatUnits(
|
|
29130
|
+
if (swapGasFee) {
|
|
29131
|
+
swapGasFeeAmount = swapGasFee.value;
|
|
29132
|
+
swapGasFeeFormatted = utils$1.formatUnits(swapGasFee.value, swapGasFee.token.decimals);
|
|
29114
29133
|
swapGasToken = {
|
|
29115
|
-
name:
|
|
29116
|
-
symbol:
|
|
29117
|
-
address:
|
|
29118
|
-
decimals:
|
|
29134
|
+
name: swapGasFee.token.name ?? '',
|
|
29135
|
+
symbol: swapGasFee.token.symbol ?? '',
|
|
29136
|
+
address: swapGasFee.token.address,
|
|
29137
|
+
decimals: swapGasFee.token.decimals,
|
|
29119
29138
|
};
|
|
29120
29139
|
}
|
|
29121
29140
|
const fees = [];
|
|
29122
29141
|
for (const swapFee of swapFees) {
|
|
29123
29142
|
fees.push({
|
|
29143
|
+
type: FeeType.SWAP_FEE,
|
|
29124
29144
|
amount: swapFee.amount.value,
|
|
29125
29145
|
formattedAmount: utils$1.formatUnits(swapFee.amount.value, swapFee.amount.token.decimals),
|
|
29126
29146
|
token: {
|
|
@@ -29132,12 +29152,14 @@ const constructFees$1 = (approvalGasFees, swapGasFees, swapFees) => {
|
|
|
29132
29152
|
});
|
|
29133
29153
|
}
|
|
29134
29154
|
return {
|
|
29135
|
-
|
|
29155
|
+
approvalGasFee: {
|
|
29156
|
+
type: FeeType.GAS,
|
|
29136
29157
|
amount: approvalGasFeeAmount,
|
|
29137
29158
|
formattedAmount: approvalGasFeeFormatted,
|
|
29138
29159
|
token: approvalToken,
|
|
29139
29160
|
},
|
|
29140
|
-
|
|
29161
|
+
swapGasFee: {
|
|
29162
|
+
type: FeeType.GAS,
|
|
29141
29163
|
amount: swapGasFeeAmount,
|
|
29142
29164
|
formattedAmount: swapGasFeeFormatted,
|
|
29143
29165
|
token: swapGasToken,
|
|
@@ -29222,7 +29244,7 @@ const checkUserCanCoverApprovalFees = (l2Balances, approval) => {
|
|
|
29222
29244
|
// The user has enough to cover approval gas fees
|
|
29223
29245
|
return { sufficient: true, approvalGasFee, approvalGasTokenAddress };
|
|
29224
29246
|
};
|
|
29225
|
-
const checkUserCanCoverSwapFees = (l2Balances, approvalFees,
|
|
29247
|
+
const checkUserCanCoverSwapFees = (l2Balances, approvalFees, swapGasFee, swapFees, tokenBeingSwapped) => {
|
|
29226
29248
|
// Set up a map of token addresses to amounts for each of the swap fees
|
|
29227
29249
|
const feeMap = new Map();
|
|
29228
29250
|
// Add the approval fee to list of fees
|
|
@@ -29230,13 +29252,13 @@ const checkUserCanCoverSwapFees = (l2Balances, approvalFees, swapGasFees, swapFe
|
|
|
29230
29252
|
feeMap.set(approvalFees.approvalGasTokenAddress, approvalFees.approvalGasFee);
|
|
29231
29253
|
}
|
|
29232
29254
|
// Add the swap gas fee to list of fees
|
|
29233
|
-
if (
|
|
29234
|
-
const fee = feeMap.get(
|
|
29255
|
+
if (swapGasFee) {
|
|
29256
|
+
const fee = feeMap.get(swapGasFee.token.address);
|
|
29235
29257
|
if (fee) {
|
|
29236
|
-
feeMap.set(
|
|
29258
|
+
feeMap.set(swapGasFee.token.address, fee.add(swapGasFee.value));
|
|
29237
29259
|
}
|
|
29238
29260
|
else {
|
|
29239
|
-
feeMap.set(
|
|
29261
|
+
feeMap.set(swapGasFee.token.address, swapGasFee.value);
|
|
29240
29262
|
}
|
|
29241
29263
|
}
|
|
29242
29264
|
// Add the token being swapped to list of fees to ensure the user can cover the fee + the token swap
|
|
@@ -29490,31 +29512,39 @@ const hasSufficientL1Eth = (tokenBalanceResult, totalFees) => {
|
|
|
29490
29512
|
const balance = getEthBalance(tokenBalanceResult);
|
|
29491
29513
|
return balance.gte(totalFees);
|
|
29492
29514
|
};
|
|
29493
|
-
const constructFees = (
|
|
29515
|
+
const constructFees = (bridgeGasFee, bridgeFee, imtblFee, approvalGasFee, token) => {
|
|
29494
29516
|
const bridgeFeeDecimals = token?.decimals ?? DEFAULT_TOKEN_DECIMALS$1;
|
|
29517
|
+
const bridgeFees = [];
|
|
29518
|
+
if (bridgeFee.gt(0)) {
|
|
29519
|
+
bridgeFees.push({
|
|
29520
|
+
type: FeeType.BRIDGE_FEE,
|
|
29521
|
+
amount: bridgeFee,
|
|
29522
|
+
formattedAmount: utils$1.formatUnits(bridgeFee, bridgeFeeDecimals),
|
|
29523
|
+
token,
|
|
29524
|
+
});
|
|
29525
|
+
}
|
|
29526
|
+
if (imtblFee.gt(0)) {
|
|
29527
|
+
bridgeFees.push({
|
|
29528
|
+
type: FeeType.IMMUTABLE_FEE,
|
|
29529
|
+
amount: imtblFee,
|
|
29530
|
+
formattedAmount: utils$1.formatUnits(imtblFee, bridgeFeeDecimals),
|
|
29531
|
+
token,
|
|
29532
|
+
});
|
|
29533
|
+
}
|
|
29495
29534
|
return {
|
|
29496
|
-
|
|
29497
|
-
|
|
29498
|
-
|
|
29535
|
+
approvalGasFee: {
|
|
29536
|
+
type: FeeType.GAS,
|
|
29537
|
+
amount: approvalGasFee,
|
|
29538
|
+
formattedAmount: utils$1.formatUnits(approvalGasFee, DEFAULT_TOKEN_DECIMALS$1),
|
|
29499
29539
|
token,
|
|
29500
29540
|
},
|
|
29501
|
-
|
|
29502
|
-
|
|
29503
|
-
|
|
29541
|
+
bridgeGasFee: {
|
|
29542
|
+
type: FeeType.GAS,
|
|
29543
|
+
amount: bridgeGasFee,
|
|
29544
|
+
formattedAmount: utils$1.formatUnits(bridgeGasFee, DEFAULT_TOKEN_DECIMALS$1),
|
|
29504
29545
|
token,
|
|
29505
29546
|
},
|
|
29506
|
-
bridgeFees
|
|
29507
|
-
{
|
|
29508
|
-
amount: bridgeFee,
|
|
29509
|
-
formattedAmount: utils$1.formatUnits(bridgeFee, bridgeFeeDecimals),
|
|
29510
|
-
token,
|
|
29511
|
-
},
|
|
29512
|
-
{
|
|
29513
|
-
amount: imtblFee,
|
|
29514
|
-
formattedAmount: utils$1.formatUnits(imtblFee, bridgeFeeDecimals),
|
|
29515
|
-
token,
|
|
29516
|
-
},
|
|
29517
|
-
],
|
|
29547
|
+
bridgeFees,
|
|
29518
29548
|
};
|
|
29519
29549
|
};
|
|
29520
29550
|
const constructBridgeFundingRoute = (chainId, balance, bridgeRequirement, itemType, fees) => ({
|
|
@@ -30373,13 +30403,13 @@ const calculateFees = (orderFees, weiAmount, decimals = 18) => {
|
|
|
30373
30403
|
return calculateFeesResult;
|
|
30374
30404
|
};
|
|
30375
30405
|
|
|
30376
|
-
const getItemRequirement = (type,
|
|
30406
|
+
const getItemRequirement = (type, tokenAddress, amount, spenderAddress) => {
|
|
30377
30407
|
switch (type) {
|
|
30378
30408
|
case ItemType.ERC20:
|
|
30379
30409
|
return {
|
|
30380
30410
|
type,
|
|
30381
30411
|
amount,
|
|
30382
|
-
|
|
30412
|
+
tokenAddress,
|
|
30383
30413
|
spenderAddress,
|
|
30384
30414
|
};
|
|
30385
30415
|
case ItemType.NATIVE:
|
|
@@ -30602,7 +30632,7 @@ const getBuyToken = (buyToken, decimals = 18) => {
|
|
|
30602
30632
|
return {
|
|
30603
30633
|
type: ItemType.ERC20,
|
|
30604
30634
|
amount: bnAmount.toString(),
|
|
30605
|
-
contractAddress: buyToken.
|
|
30635
|
+
contractAddress: buyToken.tokenAddress,
|
|
30606
30636
|
};
|
|
30607
30637
|
};
|
|
30608
30638
|
const sell = async (config, provider, orders) => {
|
|
@@ -30616,7 +30646,7 @@ const sell = async (config, provider, orders) => {
|
|
|
30616
30646
|
let decimals = 18;
|
|
30617
30647
|
if (buyToken.type === ItemType.ERC20) {
|
|
30618
30648
|
// get this from the allowed list
|
|
30619
|
-
const buyTokenContract = new Contract$1(buyToken.
|
|
30649
|
+
const buyTokenContract = new Contract$1(buyToken.tokenAddress, JSON.stringify(ERC20ABI), provider);
|
|
30620
30650
|
decimals = await measureAsyncExecution(config, 'Time to get decimals of token contract for the buy token', buyTokenContract.decimals());
|
|
30621
30651
|
}
|
|
30622
30652
|
const buyTokenOrNative = getBuyToken(buyToken, decimals);
|
|
@@ -30768,8 +30798,8 @@ async function getItemRequirementsFromRequirements(provider, requirements) {
|
|
|
30768
30798
|
const decimalPromises = [];
|
|
30769
30799
|
requirements.forEach((itemRequirementParam) => {
|
|
30770
30800
|
if (itemRequirementParam.type === ItemType.ERC20) {
|
|
30771
|
-
const {
|
|
30772
|
-
decimalPromises.push(getTokenContract(
|
|
30801
|
+
const { tokenAddress } = itemRequirementParam;
|
|
30802
|
+
decimalPromises.push(getTokenContract(tokenAddress, ERC20ABI, provider).decimals());
|
|
30773
30803
|
}
|
|
30774
30804
|
});
|
|
30775
30805
|
const decimals = await Promise.all(decimalPromises);
|
|
@@ -30863,6 +30893,90 @@ function loadUnresolved(version) {
|
|
|
30863
30893
|
return { loaded: false, element: tag };
|
|
30864
30894
|
}
|
|
30865
30895
|
|
|
30896
|
+
const PUBLISHABLE_KEY_PREFIX = 'pk_imapik-';
|
|
30897
|
+
const publishableKeyDomainAllowlist = [
|
|
30898
|
+
'https://checkout-api.dev.immutable.com',
|
|
30899
|
+
'https://checkout-api.sandbox.immutable.com',
|
|
30900
|
+
'https://checkout-api.immutable.com',
|
|
30901
|
+
];
|
|
30902
|
+
class HttpClient {
|
|
30903
|
+
config;
|
|
30904
|
+
axiosInstance;
|
|
30905
|
+
constructor(config) {
|
|
30906
|
+
this.config = config;
|
|
30907
|
+
this.axiosInstance = globalAxios.create();
|
|
30908
|
+
this.setupInterceptors();
|
|
30909
|
+
}
|
|
30910
|
+
// eslint-disable-next-line class-methods-use-this
|
|
30911
|
+
shouldAddPublishableKey(url) {
|
|
30912
|
+
// Check if the request is going to a whitelisted domain
|
|
30913
|
+
return publishableKeyDomainAllowlist.some((domain) => url.startsWith(domain));
|
|
30914
|
+
}
|
|
30915
|
+
setupInterceptors() {
|
|
30916
|
+
this.axiosInstance.interceptors.request.use((config) => {
|
|
30917
|
+
const publishableKey = this.config?.baseConfig?.publishableKey;
|
|
30918
|
+
if (publishableKey && this.shouldAddPublishableKey(config.url || '')) {
|
|
30919
|
+
if (!publishableKey.startsWith(PUBLISHABLE_KEY_PREFIX)) {
|
|
30920
|
+
throw new Error('Invalid Publishable key. Create your Publishable key in Immutable developer hub.'
|
|
30921
|
+
+ ' https://hub.immutable.com');
|
|
30922
|
+
}
|
|
30923
|
+
// Add publishable key header for whitelisted domains
|
|
30924
|
+
// eslint-disable-next-line no-param-reassign
|
|
30925
|
+
config.headers['x-immutable-publishable-key'] = publishableKey;
|
|
30926
|
+
}
|
|
30927
|
+
return config;
|
|
30928
|
+
}, (error) => Promise.reject(error));
|
|
30929
|
+
}
|
|
30930
|
+
// eslint-disable-next-line class-methods-use-this
|
|
30931
|
+
processResponse(response) {
|
|
30932
|
+
if (response && response?.status !== 200) {
|
|
30933
|
+
throw new CheckoutError(`Error: ${response.status} ${response.statusText}`, CheckoutErrorType.API_ERROR);
|
|
30934
|
+
}
|
|
30935
|
+
}
|
|
30936
|
+
async request(config) {
|
|
30937
|
+
let response;
|
|
30938
|
+
try {
|
|
30939
|
+
response = await this.axiosInstance.request(config);
|
|
30940
|
+
}
|
|
30941
|
+
catch (error) {
|
|
30942
|
+
throw new CheckoutError(error.message, CheckoutErrorType.API_ERROR);
|
|
30943
|
+
}
|
|
30944
|
+
this.processResponse(response);
|
|
30945
|
+
return response;
|
|
30946
|
+
}
|
|
30947
|
+
async get(url, config) {
|
|
30948
|
+
const requestConfig = {
|
|
30949
|
+
...config,
|
|
30950
|
+
url,
|
|
30951
|
+
};
|
|
30952
|
+
return await this.request(requestConfig);
|
|
30953
|
+
}
|
|
30954
|
+
async post(url, data, config) {
|
|
30955
|
+
const requestConfig = {
|
|
30956
|
+
...config,
|
|
30957
|
+
data,
|
|
30958
|
+
url,
|
|
30959
|
+
};
|
|
30960
|
+
return await this.request(requestConfig);
|
|
30961
|
+
}
|
|
30962
|
+
async put(url, data, config) {
|
|
30963
|
+
const requestConfig = {
|
|
30964
|
+
...config,
|
|
30965
|
+
data,
|
|
30966
|
+
url,
|
|
30967
|
+
};
|
|
30968
|
+
return await this.request(requestConfig);
|
|
30969
|
+
}
|
|
30970
|
+
async delete(url, data, config) {
|
|
30971
|
+
const requestConfig = {
|
|
30972
|
+
...config,
|
|
30973
|
+
data,
|
|
30974
|
+
url,
|
|
30975
|
+
};
|
|
30976
|
+
return await this.request(requestConfig);
|
|
30977
|
+
}
|
|
30978
|
+
}
|
|
30979
|
+
|
|
30866
30980
|
const SANDBOX_CONFIGURATION = {
|
|
30867
30981
|
baseConfig: {
|
|
30868
30982
|
environment: Environment$1.SANDBOX,
|
|
@@ -30873,6 +30987,7 @@ const WIDGETS_SCRIPT_TIMEOUT = 100;
|
|
|
30873
30987
|
// Checkout SDK
|
|
30874
30988
|
class Checkout {
|
|
30875
30989
|
readOnlyProviders;
|
|
30990
|
+
httpClient;
|
|
30876
30991
|
config;
|
|
30877
30992
|
fiatRampService;
|
|
30878
30993
|
availability;
|
|
@@ -30882,7 +30997,8 @@ class Checkout {
|
|
|
30882
30997
|
* @param {CheckoutModuleConfiguration} [config=SANDBOX_CONFIGURATION] - The configuration object for the CheckoutModule.
|
|
30883
30998
|
*/
|
|
30884
30999
|
constructor(config = SANDBOX_CONFIGURATION) {
|
|
30885
|
-
this.
|
|
31000
|
+
this.httpClient = new HttpClient(config);
|
|
31001
|
+
this.config = new CheckoutConfiguration(config, this.httpClient);
|
|
30886
31002
|
this.fiatRampService = new FiatRampService(this.config);
|
|
30887
31003
|
this.readOnlyProviders = new Map();
|
|
30888
31004
|
this.availability = availabilityService(this.config.isDevelopment, this.config.isProduction);
|
|
@@ -31084,7 +31200,7 @@ class Checkout {
|
|
|
31084
31200
|
try {
|
|
31085
31201
|
itemRequirements = await getItemRequirementsFromRequirements(web3Provider, params.itemRequirements);
|
|
31086
31202
|
}
|
|
31087
|
-
catch {
|
|
31203
|
+
catch (error) {
|
|
31088
31204
|
throw new CheckoutError('Failed to map item requirements', CheckoutErrorType.ITEM_REQUIREMENTS_ERROR);
|
|
31089
31205
|
}
|
|
31090
31206
|
return await smartCheckout(this.config, web3Provider, itemRequirements, params.transactionOrGasAmount);
|
|
@@ -31152,4 +31268,4 @@ class Checkout {
|
|
|
31152
31268
|
}
|
|
31153
31269
|
}
|
|
31154
31270
|
|
|
31155
|
-
export { BridgeEventType, ChainId, ChainName, ChainSlug, Checkout, CheckoutConfiguration, CheckoutErrorType, CheckoutStatus, ConnectEventType, ConnectTargetLayer, ExchangeType, FundingStepType, GasEstimateType, GasTokenType, IMMUTABLE_API_BASE_URL, IMTBLWidgetEvents, ItemType, NetworkFilterTypes, OnRampEventType, OrchestrationEventType, ProviderEventType, RoutingOutcomeType, SaleEventType, SwapEventType, TokenFilterTypes, TransactionOrGasType, WalletEventType, WalletFilterTypes, WalletProviderName, WidgetTheme, WidgetType };
|
|
31271
|
+
export { BridgeEventType, ChainId, ChainName, ChainSlug, Checkout, CheckoutConfiguration, CheckoutErrorType, CheckoutStatus, ConnectEventType, ConnectTargetLayer, ExchangeType, FeeType, FundingStepType, GasEstimateType, GasTokenType, IMMUTABLE_API_BASE_URL, IMTBLWidgetEvents, ItemType, NetworkFilterTypes, OnRampEventType, OrchestrationEventType, ProviderEventType, RoutingOutcomeType, SaleEventType, SwapEventType, TokenFilterTypes, TransactionOrGasType, WalletEventType, WalletFilterTypes, WalletProviderName, WidgetTheme, WidgetType };
|