@imtbl/sdk 0.44.1 → 0.44.3

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/checkout.js CHANGED
@@ -15746,6 +15746,7 @@ var BridgeMethodsGasLimit;
15746
15746
  BridgeMethodsGasLimit[BridgeMethodsGasLimit["MAP_TOKEN_SOURCE"] = 200000] = "MAP_TOKEN_SOURCE";
15747
15747
  BridgeMethodsGasLimit[BridgeMethodsGasLimit["MAP_TOKEN_DESTINATION"] = 200000] = "MAP_TOKEN_DESTINATION";
15748
15748
  BridgeMethodsGasLimit[BridgeMethodsGasLimit["FINALISE_WITHDRAWAL"] = 200000] = "FINALISE_WITHDRAWAL";
15749
+ BridgeMethodsGasLimit[BridgeMethodsGasLimit["APPROVE_TOKEN"] = 55000] = "APPROVE_TOKEN";
15749
15750
  })(BridgeMethodsGasLimit || (BridgeMethodsGasLimit = {}));
15750
15751
  var StatusResponse;
15751
15752
  (function (StatusResponse) {
@@ -15933,8 +15934,12 @@ class TokenBridge {
15933
15934
  throw new BridgeError(`Finalised withdrawals must be on the root chain (${this.config.bridgeInstance.rootChainID})`, BridgeErrorType.UNSUPPORTED_ERROR);
15934
15935
  }
15935
15936
  let sourceChainGas = BigNumber.from(0);
15937
+ let approvalFee = BigNumber.from(0);
15936
15938
  let bridgeFee = BigNumber.from(0);
15937
15939
  const imtblFee = BigNumber.from(0);
15940
+ if ('token' in req && req.token !== 'NATIVE') {
15941
+ approvalFee = await this.getGasEstimates(this.config.rootProvider, BridgeMethodsGasLimit.APPROVE_TOKEN);
15942
+ }
15938
15943
  if (req.action === BridgeFeeActions.FINALISE_WITHDRAWAL) {
15939
15944
  sourceChainGas = await this.getGasEstimates(this.config.rootProvider, BridgeMethodsGasLimit.FINALISE_WITHDRAWAL);
15940
15945
  }
@@ -15945,9 +15950,10 @@ class TokenBridge {
15945
15950
  const feeResult = await this.calculateBridgeFee(req.sourceChainId, req.destinationChainId, BridgeMethodsGasLimit[`${req.action}_DESTINATION`], req.gasMultiplier);
15946
15951
  bridgeFee = feeResult.bridgeFee;
15947
15952
  }
15948
- const totalFees = sourceChainGas.add(bridgeFee).add(imtblFee);
15953
+ const totalFees = sourceChainGas.add(approvalFee).add(bridgeFee).add(imtblFee);
15949
15954
  return {
15950
15955
  sourceChainGas,
15956
+ approvalFee,
15951
15957
  bridgeFee,
15952
15958
  imtblFee,
15953
15959
  totalFees,
@@ -16177,6 +16183,8 @@ class TokenBridge {
16177
16183
  gasMultiplier,
16178
16184
  sourceChainId,
16179
16185
  destinationChainId,
16186
+ token,
16187
+ amount,
16180
16188
  });
16181
16189
  const canReceive = await this.checkReceiver(provider, recipient);
16182
16190
  if (!canReceive) {
@@ -16336,38 +16344,84 @@ class TokenBridge {
16336
16344
  * @throws {BridgeError} - If an error occurs during the query, a BridgeError will be thrown with a specific error type.
16337
16345
  */
16338
16346
  async getTransactionStatus(req) {
16339
- const axelarAPIEndpoint = this.getAxelarEndpoint(req.sourceChainId);
16340
16347
  const txStatusResponse = {
16341
16348
  transactions: [],
16342
16349
  };
16343
- const abiCoder = new AbiCoder();
16344
- const statusPromises = [];
16345
- for (const transaction of req.transactions) {
16346
- statusPromises.push(queryTransactionStatus(axelarAPIEndpoint, transaction.txHash));
16350
+ const txStatusItems = await this.getAxelarStatus(req.transactions, req.sourceChainId);
16351
+ const uniqueReceivers = await this.getUniqueReceivers(txStatusItems, req.sourceChainId);
16352
+ const pendingWithdrawalPromises = [];
16353
+ for (const address of uniqueReceivers) {
16354
+ pendingWithdrawalPromises.push(this.getPendingWithdrawals({ recipient: address }));
16347
16355
  }
16348
- let statusResponses;
16356
+ let pendingWithdrawalResponses = [];
16349
16357
  try {
16350
- statusResponses = await Promise.all(statusPromises);
16358
+ pendingWithdrawalResponses = await Promise.all(pendingWithdrawalPromises);
16351
16359
  }
16352
16360
  catch (err) {
16353
- throw new BridgeError(`Failed to fetch the Axelar Status with the reason: ${err}`, BridgeErrorType.AXELAR_GAS_ESTIMATE_FAILED);
16361
+ console.log('err', err);
16362
+ throw new BridgeError(`Failed to fetch the pending withdrawals with: ${err}`, BridgeErrorType.FLOW_RATE_ERROR);
16354
16363
  }
16355
- const unpaidGasStatus = [GasPaidStatus.GAS_UNPAID, GasPaidStatus.GAS_PAID_NOT_ENOUGH_GAS];
16364
+ txStatusResponse.transactions = txStatusItems;
16365
+ // try match a completed transaction to a pending flowRate transaction
16366
+ for (const txStatusRes of txStatusResponse.transactions) {
16367
+ if (txStatusRes.status === StatusResponse.COMPLETE) {
16368
+ (() => {
16369
+ for (const pendingWithdrawals of pendingWithdrawalResponses) {
16370
+ const flowRatedTxIndex = pendingWithdrawals.pending.findIndex((el) => (el.amount.toString() === txStatusRes.amount.toString()
16371
+ && el.token === txStatusRes.token
16372
+ && el.withdrawer === txStatusRes.sender
16373
+ && el.recipient === txStatusRes.recipient));
16374
+ if (flowRatedTxIndex !== -1) {
16375
+ txStatusRes.status = StatusResponse.FLOW_RATE_CONTROLLED;
16376
+ txStatusRes.data = {
16377
+ canWithdraw: pendingWithdrawals.pending[flowRatedTxIndex].canWithdraw,
16378
+ timeoutStart: pendingWithdrawals.pending[flowRatedTxIndex].timeoutStart,
16379
+ timeoutEnd: pendingWithdrawals.pending[flowRatedTxIndex].timeoutEnd,
16380
+ };
16381
+ pendingWithdrawals.pending.splice(flowRatedTxIndex, 1);
16382
+ return;
16383
+ }
16384
+ }
16385
+ })();
16386
+ }
16387
+ }
16388
+ // Return the tx status response
16389
+ return txStatusResponse;
16390
+ }
16391
+ async getUniqueReceivers(txStatusItems, sourceChainId) {
16392
+ const uniqueReceivers = [];
16356
16393
  const isWithdraw = [
16357
16394
  ZKEVM_DEVNET_CHAIN_ID,
16358
16395
  ZKEVM_TESTNET_CHAIN_ID,
16359
16396
  ZKEVM_MAINNET_CHAIN_ID
16360
- ].includes(req.sourceChainId);
16361
- let rootBridge;
16362
- if (isWithdraw) {
16363
- rootBridge = await withBridgeError(async () => {
16364
- const contract = new Contract(this.config.bridgeContracts.rootERC20BridgeFlowRate, ROOT_ERC20_BRIDGE_FLOW_RATE, this.config.rootProvider);
16365
- return contract;
16366
- }, BridgeErrorType.INTERNAL_ERROR);
16397
+ ].includes(sourceChainId);
16398
+ for (let i = 0, l = txStatusItems.length; i < l; i++) {
16399
+ if (txStatusItems[i].status === StatusResponse.COMPLETE
16400
+ && isWithdraw && txStatusItems[i].recipient) {
16401
+ const receiverIndex = uniqueReceivers.findIndex((el) => el === txStatusItems[i].recipient);
16402
+ if (receiverIndex === -1) {
16403
+ uniqueReceivers.push(txStatusItems[i].recipient);
16404
+ }
16405
+ }
16406
+ } // for
16407
+ return uniqueReceivers;
16408
+ }
16409
+ async getAxelarStatus(transactions, sourceChainId) {
16410
+ const txStatusItems = [];
16411
+ const statusPromises = [];
16412
+ const axelarAPIEndpoint = this.getAxelarEndpoint(sourceChainId);
16413
+ const unpaidGasStatus = [GasPaidStatus.GAS_UNPAID, GasPaidStatus.GAS_PAID_NOT_ENOUGH_GAS];
16414
+ const abiCoder = new AbiCoder();
16415
+ for (const transaction of transactions) {
16416
+ statusPromises.push(queryTransactionStatus(axelarAPIEndpoint, transaction.txHash));
16417
+ }
16418
+ let statusResponses;
16419
+ try {
16420
+ statusResponses = await Promise.all(statusPromises);
16421
+ }
16422
+ catch (err) {
16423
+ throw new BridgeError(`Failed to fetch the Axelar Status with the reason: ${err}`, BridgeErrorType.AXELAR_GAS_ESTIMATE_FAILED);
16367
16424
  }
16368
- const flowRatePromises = [];
16369
- const flowRateLengthPromises = [];
16370
- const flowRatePromisesReceivers = [];
16371
16425
  for (let i = 0, l = statusResponses.length; i < l; i++) {
16372
16426
  let metaStatus;
16373
16427
  // consolidate axelar statuses to our own simplified metaStatus
@@ -16401,7 +16455,7 @@ class TokenBridge {
16401
16455
  }
16402
16456
  }
16403
16457
  let txItem = {
16404
- txHash: req.transactions[i].txHash,
16458
+ txHash: transactions[i].txHash,
16405
16459
  status: metaStatus,
16406
16460
  data: {
16407
16461
  gmpResponse: statusResponses[i].status,
@@ -16418,61 +16472,9 @@ class TokenBridge {
16418
16472
  amount: decodedData[4],
16419
16473
  };
16420
16474
  }
16421
- let flowRatePromiseIndex = flowRatePromisesReceivers.findIndex((el) => el === txItem.recipient);
16422
- if (metaStatus === StatusResponse.COMPLETE
16423
- && isWithdraw && txItem.recipient) {
16424
- // consolidate the calls we have to make to the flow rate by receiver
16425
- if (flowRatePromiseIndex === -1) {
16426
- flowRatePromisesReceivers.push(txItem.recipient);
16427
- flowRatePromiseIndex = flowRatePromisesReceivers.length - 1;
16428
- }
16429
- txItem.data.flowRatePromiseIndex = flowRatePromiseIndex;
16430
- }
16431
- txStatusResponse.transactions.push(txItem);
16475
+ txStatusItems.push(txItem);
16432
16476
  } // for
16433
- for (const flowRateReceiver of flowRatePromisesReceivers) {
16434
- flowRateLengthPromises.push(rootBridge.getPendingWithdrawalsLength(flowRateReceiver));
16435
- }
16436
- let flowRateLengthResponses = [];
16437
- try {
16438
- flowRateLengthResponses = await Promise.all(flowRateLengthPromises);
16439
- }
16440
- catch (err) {
16441
- throw new BridgeError(`Failed to fetch the Flow Rate pending lengths with the reason: ${err}`, BridgeErrorType.FLOW_RATE_ERROR);
16442
- }
16443
- for (let i = 0, l = flowRatePromisesReceivers.length; i < l; i++) {
16444
- const indices = [];
16445
- const indicesLength = flowRateLengthResponses[i].toNumber();
16446
- for (let j = 0; j < indicesLength; j++) {
16447
- indices.push(j);
16448
- }
16449
- flowRatePromises.push(rootBridge.getPendingWithdrawals(flowRatePromisesReceivers[i], indices));
16450
- }
16451
- let flowRateResponses = [];
16452
- if (flowRatePromises.length > 0) {
16453
- try {
16454
- flowRateResponses = await Promise.all(flowRatePromises);
16455
- }
16456
- catch (err) {
16457
- throw new BridgeError(`Failed to fetch the Flow Rate statuses with the reason: ${err}`, BridgeErrorType.FLOW_RATE_ERROR);
16458
- }
16459
- }
16460
- for (const txStatusRes of txStatusResponse.transactions) {
16461
- if (txStatusRes.data.flowRatePromiseIndex !== -1 && flowRateResponses[txStatusRes.data.flowRatePromiseIndex]) {
16462
- const flowRatedTx = flowRateResponses[txStatusRes.data.flowRatePromiseIndex].find((el) => (el.amount.toString() === txStatusRes.amount.toString()
16463
- && el.token === txStatusRes.token
16464
- && el.withdrawer === txStatusRes.sender));
16465
- if (flowRatedTx) {
16466
- txStatusRes.status = StatusResponse.FLOW_RATE_CONTROLLED;
16467
- txStatusRes.data = {
16468
- timestamp: flowRatedTx.timestamp.toString(),
16469
- };
16470
- }
16471
- }
16472
- delete txStatusRes.data.flowRatePromiseIndex;
16473
- }
16474
- // Return the tx status response
16475
- return txStatusResponse;
16477
+ return txStatusItems;
16476
16478
  }
16477
16479
  /**
16478
16480
  * Queries for the information about which tokens are flowrated and how long the delay is.
@@ -16498,6 +16500,7 @@ class TokenBridge {
16498
16500
  token = ETHEREUM_NATIVE_TOKEN_ADDRESS;
16499
16501
  }
16500
16502
  contractPromises.push(rootBridge.flowRateBuckets(token));
16503
+ contractPromises.push(rootBridge.largeTransferThresholds(token));
16501
16504
  }
16502
16505
  let contractPromisesRes;
16503
16506
  try {
@@ -16507,19 +16510,25 @@ class TokenBridge {
16507
16510
  throw new BridgeError('unable to query contract for flowrate info', BridgeErrorType.INTERNAL_ERROR);
16508
16511
  }
16509
16512
  const tokensRes = {};
16510
- // @note it's i + 2 because the first 2 promises are not token buckets
16513
+ const withdrawalQueueActivated = contractPromisesRes[0];
16514
+ const withdrawalDelay = contractPromisesRes[1].toNumber();
16515
+ // remove first 2 items from promise all response
16516
+ contractPromisesRes.splice(0, 2);
16517
+ // the remaining items should be sets of 2 per token
16511
16518
  for (let i = 0, l = req.tokens.length; i < l; i++) {
16519
+ const shifter = i * 2;
16512
16520
  tokensRes[req.tokens[i]] = {
16513
- capacity: contractPromisesRes[i + 2].capacity,
16514
- depth: contractPromisesRes[i + 2].depth,
16515
- refillTime: contractPromisesRes[i + 2].refillTime.toNumber(),
16516
- refillRate: contractPromisesRes[i + 2].refillRate,
16521
+ capacity: contractPromisesRes[shifter].capacity,
16522
+ depth: contractPromisesRes[shifter].depth,
16523
+ refillTime: contractPromisesRes[shifter].refillTime.toNumber(),
16524
+ refillRate: contractPromisesRes[shifter].refillRate,
16525
+ largeTransferThreshold: contractPromisesRes[shifter + 1],
16517
16526
  };
16518
16527
  }
16519
16528
  // Return the token mappings
16520
16529
  return {
16521
- withdrawalQueueActivated: contractPromisesRes[0],
16522
- withdrawalDelay: contractPromisesRes[1].toNumber(),
16530
+ withdrawalQueueActivated,
16531
+ withdrawalDelay,
16523
16532
  tokens: tokensRes,
16524
16533
  };
16525
16534
  }
@@ -16566,6 +16575,7 @@ class TokenBridge {
16566
16575
  canWithdraw: true,
16567
16576
  };
16568
16577
  }
16578
+ pendingWithdrawals.pending[i].recipient = req.recipient;
16569
16579
  pendingWithdrawals.pending[i].withdrawer = pending[i].withdrawer;
16570
16580
  pendingWithdrawals.pending[i].token = pending[i].token;
16571
16581
  pendingWithdrawals.pending[i].amount = pending[i].amount;
@@ -16609,6 +16619,7 @@ class TokenBridge {
16609
16619
  pendingWithdrawal: {
16610
16620
  canWithdraw: false,
16611
16621
  withdrawer: pending[0].withdrawer,
16622
+ recipient: req.recipient,
16612
16623
  token: pending[0].token,
16613
16624
  amount: pending[0].amount,
16614
16625
  timeoutStart: pending[0].timestamp.toNumber(),
@@ -16622,6 +16633,7 @@ class TokenBridge {
16622
16633
  pendingWithdrawal: {
16623
16634
  canWithdraw: true,
16624
16635
  withdrawer: pending[0].withdrawer,
16636
+ recipient: req.recipient,
16625
16637
  token: pending[0].token,
16626
16638
  amount: pending[0].amount,
16627
16639
  timeoutStart: pending[0].timestamp.toNumber(),
@@ -16647,10 +16659,38 @@ class TokenBridge {
16647
16659
  */
16648
16660
  async getTokenMapping(req) {
16649
16661
  // eslint-disable-next-line no-console
16650
- console.log('stubbed response with req', req);
16662
+ if (req.rootToken.toUpperCase() === 'NATIVE'
16663
+ || req.rootToken === this.config.bridgeContracts.rootChainWrappedETH) {
16664
+ const childBridge = await withBridgeError(async () => {
16665
+ const contract = new Contract(this.config.bridgeContracts.childERC20Bridge, CHILD_ERC20_BRIDGE, this.config.childProvider);
16666
+ return contract;
16667
+ }, BridgeErrorType.INTERNAL_ERROR);
16668
+ const childETHToken = await childBridge.childETHToken();
16669
+ return {
16670
+ rootToken: req.rootToken,
16671
+ childToken: childETHToken,
16672
+ };
16673
+ }
16674
+ const rootBridge = await withBridgeError(async () => {
16675
+ const contract = new Contract(this.config.bridgeContracts.rootERC20BridgeFlowRate, ROOT_ERC20_BRIDGE_FLOW_RATE, this.config.rootProvider);
16676
+ return contract;
16677
+ }, BridgeErrorType.INTERNAL_ERROR);
16678
+ const rootTokenChildAddress = await rootBridge.rootTokenToChildToken(req.rootToken);
16679
+ if (rootTokenChildAddress === AddressZero) {
16680
+ return {
16681
+ rootToken: req.rootToken,
16682
+ childToken: null,
16683
+ };
16684
+ }
16685
+ if (rootTokenChildAddress === req.rootToken) {
16686
+ return {
16687
+ rootToken: req.rootToken,
16688
+ childToken: 'NATIVE',
16689
+ };
16690
+ }
16651
16691
  return {
16652
- rootToken: '0xF57e7e7C23978C3cAEC3C3548E3D615c346e79fF',
16653
- childToken: 'NATIVE',
16692
+ rootToken: req.rootToken,
16693
+ childToken: rootTokenChildAddress,
16654
16694
  };
16655
16695
  }
16656
16696
  }
@@ -25921,7 +25961,7 @@ class APIError extends Error {
25921
25961
 
25922
25962
  /* eslint-disable implicit-arrow-linebreak */
25923
25963
  const defaultHeaders = {
25924
- sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.44.1',
25964
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.44.3',
25925
25965
  };
25926
25966
  /**
25927
25967
  * createAPIConfiguration to create a custom Configuration
@@ -26600,12 +26640,14 @@ const validateProviderDefaults = {
26600
26640
  * @property {string} SUCCESS - If checkout succeeded as the transactions were able to be processed
26601
26641
  * @property {string} FAILED - If checkout failed due to transactions not settling on chain
26602
26642
  * @property {string} INSUFFICIENT_FUNDS - If checkout failed due to insufficient funds
26643
+ * @property {string} FULFILLMENTS_UNSETTLED - If checkout succeeded but the fulfillment transactions are not yet settled
26603
26644
  */
26604
26645
  var CheckoutStatus;
26605
26646
  (function (CheckoutStatus) {
26606
26647
  CheckoutStatus["SUCCESS"] = "SUCCESS";
26607
26648
  CheckoutStatus["FAILED"] = "FAILED";
26608
26649
  CheckoutStatus["INSUFFICIENT_FUNDS"] = "INSUFFICIENT_FUNDS";
26650
+ CheckoutStatus["FULFILLMENTS_UNSETTLED"] = "FULFILLMENTS_UNSETTLED";
26609
26651
  })(CheckoutStatus || (CheckoutStatus = {}));
26610
26652
  /**
26611
26653
  * An enum representing the item types
@@ -26916,7 +26958,7 @@ async function switchWalletNetwork(config, web3Provider, chainId) {
26916
26958
  // eslint-disable-next-line @typescript-eslint/no-shadow
26917
26959
  }
26918
26960
  catch (err) {
26919
- throw new CheckoutError('User cancelled add network request', CheckoutErrorType.USER_REJECTED_REQUEST_ERROR);
26961
+ throw new CheckoutError('User cancelled add network request', CheckoutErrorType.USER_REJECTED_REQUEST_ERROR, { error: err });
26920
26962
  }
26921
26963
  }
26922
26964
  else {
@@ -27280,7 +27322,7 @@ const GAS_OVERRIDES = {
27280
27322
  maxPriorityFeePerGas: BigNumber$1.from(101e9),
27281
27323
  };
27282
27324
 
27283
- const SDK_VERSION_MARKER = '0.44.1';
27325
+ const SDK_VERSION_MARKER = '0.44.3';
27284
27326
  // This SDK version is replaced by the `yarn build` command ran on the root level
27285
27327
  const globalPackageVersion = () => SDK_VERSION_MARKER;
27286
27328
 
@@ -27310,8 +27352,8 @@ class RemoteConfigFetcher {
27310
27352
  try {
27311
27353
  responseData = JSON.parse(response.data);
27312
27354
  }
27313
- catch (jsonError) {
27314
- throw new CheckoutError('Invalid configuration', CheckoutErrorType.API_ERROR);
27355
+ catch (err) {
27356
+ throw new CheckoutError('Invalid configuration', CheckoutErrorType.API_ERROR, { error: err });
27315
27357
  }
27316
27358
  }
27317
27359
  return responseData;
@@ -27324,7 +27366,7 @@ class RemoteConfigFetcher {
27324
27366
  response = await this.httpClient.get(`${this.getEndpoint()}/${this.version}/config`);
27325
27367
  }
27326
27368
  catch (err) {
27327
- throw new CheckoutError(`Error: ${err.message}`, CheckoutErrorType.API_ERROR);
27369
+ throw new CheckoutError(`Error: ${err.message}`, CheckoutErrorType.API_ERROR, { error: err });
27328
27370
  }
27329
27371
  // Ensure that the configuration is valid
27330
27372
  this.configCache = this.parseResponse(response);
@@ -27338,7 +27380,7 @@ class RemoteConfigFetcher {
27338
27380
  response = await this.httpClient.get(`${this.getEndpoint()}/${this.version}/config/tokens`);
27339
27381
  }
27340
27382
  catch (err) {
27341
- throw new CheckoutError(`Error: ${err.message}`, CheckoutErrorType.API_ERROR);
27383
+ throw new CheckoutError(`Error: ${err.message}`, CheckoutErrorType.API_ERROR, { error: err });
27342
27384
  }
27343
27385
  // Ensure that the configuration is valid
27344
27386
  this.tokensCache = this.parseResponse(response);
@@ -27701,7 +27743,7 @@ const getIndexerBalance = async (config, walletAddress, chainId, filterTokens) =
27701
27743
  // means we are safe to assume that a 404 is a missing wallet due to inactivity
27702
27744
  // or simply an incorrect wallet address was provided.
27703
27745
  if (err?.code !== HttpStatusCode$2.NotFound) {
27704
- throw new CheckoutError(err.message || 'InternalServerError | getTokensByWalletAddress', CheckoutErrorType.GET_INDEXER_BALANCE_ERROR, err);
27746
+ throw new CheckoutError(err.message || 'InternalServerError | getTokensByWalletAddress', CheckoutErrorType.GET_INDEXER_BALANCE_ERROR, { error: err });
27705
27747
  }
27706
27748
  }
27707
27749
  };
@@ -27720,7 +27762,7 @@ const getIndexerBalance = async (config, walletAddress, chainId, filterTokens) =
27720
27762
  // means we are safe to assume that a 404 is a missing wallet due to inactivity
27721
27763
  // or simply an incorrect wallet address was provided.
27722
27764
  if (err?.code !== HttpStatusCode$2.NotFound) {
27723
- throw new CheckoutError(err.message || 'InternalServerError | getNativeTokenByWalletAddress', CheckoutErrorType.GET_INDEXER_BALANCE_ERROR, err);
27765
+ throw new CheckoutError(err.message || 'InternalServerError | getNativeTokenByWalletAddress', CheckoutErrorType.GET_INDEXER_BALANCE_ERROR, { error: err });
27724
27766
  }
27725
27767
  }
27726
27768
  };
@@ -27833,6 +27875,7 @@ async function checkIsWalletConnected(web3Provider) {
27833
27875
  }
27834
27876
  catch (err) {
27835
27877
  throw new CheckoutError('Check wallet connection request failed', CheckoutErrorType.PROVIDER_REQUEST_FAILED_ERROR, {
27878
+ error: err,
27836
27879
  rpcMethod: WalletAction.CHECK_CONNECTION,
27837
27880
  });
27838
27881
  }
@@ -27925,7 +27968,7 @@ async function validateProvider(config, web3Provider, validateProviderOptions) {
27925
27968
  }
27926
27969
  }
27927
27970
  catch (err) {
27928
- throw new CheckoutError('Unable to detect the web3Provider network', CheckoutErrorType.WEB3_PROVIDER_ERROR);
27971
+ throw new CheckoutError('Unable to detect the web3Provider network', CheckoutErrorType.WEB3_PROVIDER_ERROR, { error: err });
27929
27972
  }
27930
27973
  if (web3ChainId !== underlyingChainId && !options.allowMistmatchedChainId) {
27931
27974
  throw new CheckoutError('Your wallet has changed network, please switch to a supported network', CheckoutErrorType.WEB3_PROVIDER_ERROR);
@@ -27977,15 +28020,15 @@ const sendTransaction = async (web3Provider, transaction) => {
27977
28020
  }
27978
28021
  catch (err) {
27979
28022
  if (err.code === ethers.errors.INSUFFICIENT_FUNDS) {
27980
- throw new CheckoutError(err.message, CheckoutErrorType.INSUFFICIENT_FUNDS);
28023
+ throw new CheckoutError(err.message, CheckoutErrorType.INSUFFICIENT_FUNDS, { error: err });
27981
28024
  }
27982
28025
  if (err.code === ethers.errors.ACTION_REJECTED) {
27983
- throw new CheckoutError(err.message, CheckoutErrorType.USER_REJECTED_REQUEST_ERROR);
28026
+ throw new CheckoutError(err.message, CheckoutErrorType.USER_REJECTED_REQUEST_ERROR, { error: err });
27984
28027
  }
27985
28028
  if (err.code === ethers.errors.UNPREDICTABLE_GAS_LIMIT) {
27986
- throw new CheckoutError(err.message, CheckoutErrorType.UNPREDICTABLE_GAS_LIMIT);
28029
+ throw new CheckoutError(err.message, CheckoutErrorType.UNPREDICTABLE_GAS_LIMIT, { error: err });
27987
28030
  }
27988
- throw new CheckoutError(err.message, CheckoutErrorType.TRANSACTION_FAILED);
28031
+ throw new CheckoutError(err.message, CheckoutErrorType.TRANSACTION_FAILED, { error: err });
27989
28032
  }
27990
28033
  };
27991
28034
 
@@ -27998,6 +28041,8 @@ async function getBridgeFeeEstimate$1(tokenBridge, fromChainId, toChainId, confi
27998
28041
  gasMultiplier: 1.1,
27999
28042
  sourceChainId: fromChainId.toString(),
28000
28043
  destinationChainId: toChainId.toString(),
28044
+ token: NATIVE.toUpperCase(),
28045
+ amount: BigNumber$1.from(0),
28001
28046
  });
28002
28047
  }
28003
28048
 
@@ -28077,6 +28122,7 @@ async function bridgeToL2GasEstimator(readOnlyProviders, config) {
28077
28122
  gasEstimateType: GasEstimateType.BRIDGE_TO_L2,
28078
28123
  fees: {
28079
28124
  sourceChainGas: BigNumber$1.from(0),
28125
+ approvalFee: BigNumber$1.from(0),
28080
28126
  bridgeFee: BigNumber$1.from(0),
28081
28127
  imtblFee: BigNumber$1.from(0),
28082
28128
  totalFees: BigNumber$1.from(0),
@@ -28226,7 +28272,7 @@ const getERC20Allowance = async (provider, ownerAddress, contractAddress, spende
28226
28272
  return await contract.allowance(ownerAddress, spenderAddress);
28227
28273
  }
28228
28274
  catch (err) {
28229
- throw new CheckoutError('Failed to get the allowance for ERC20', CheckoutErrorType.GET_ERC20_ALLOWANCE_ERROR, { contractAddress });
28275
+ throw new CheckoutError('Failed to get the allowance for ERC20', CheckoutErrorType.GET_ERC20_ALLOWANCE_ERROR, { contractAddress, error: err });
28230
28276
  }
28231
28277
  };
28232
28278
  // Returns the approval transaction for the ERC20 that the owner can sign
@@ -28239,8 +28285,8 @@ const getERC20ApprovalTransaction = async (provider, ownerAddress, contractAddre
28239
28285
  approveTransaction.from = ownerAddress;
28240
28286
  return approveTransaction;
28241
28287
  }
28242
- catch {
28243
- throw new CheckoutError('Failed to get the approval transaction for ERC20', CheckoutErrorType.GET_ERC20_ALLOWANCE_ERROR, { contractAddress });
28288
+ catch (err) {
28289
+ throw new CheckoutError('Failed to get the approval transaction for ERC20', CheckoutErrorType.GET_ERC20_ALLOWANCE_ERROR, { contractAddress, error: err });
28244
28290
  }
28245
28291
  };
28246
28292
  const hasERC20Allowances = async (provider, ownerAddress, itemRequirements) => {
@@ -28312,7 +28358,12 @@ const getERC721ApprovedForAll = async (provider, ownerAddress, contractAddress,
28312
28358
  return await contract.isApprovedForAll(ownerAddress, spenderAddress);
28313
28359
  }
28314
28360
  catch (err) {
28315
- throw new CheckoutError('Failed to check approval for all ERC721s of collection', CheckoutErrorType.GET_ERC721_ALLOWANCE_ERROR, { ownerAddress, contractAddress, spenderAddress });
28361
+ throw new CheckoutError('Failed to check approval for all ERC721s of collection', CheckoutErrorType.GET_ERC721_ALLOWANCE_ERROR, {
28362
+ ownerAddress,
28363
+ contractAddress,
28364
+ spenderAddress,
28365
+ error: err,
28366
+ });
28316
28367
  }
28317
28368
  };
28318
28369
  // Returns a populated transaction to approve the ERC721 for the spender.
@@ -28326,7 +28377,11 @@ const getApproveTransaction = async (provider, ownerAddress, contractAddress, sp
28326
28377
  }
28327
28378
  catch (err) {
28328
28379
  throw new CheckoutError('Failed to get the approval transaction for ERC721', CheckoutErrorType.GET_ERC721_ALLOWANCE_ERROR, {
28329
- id: id.toString(), contractAddress, spenderAddress, ownerAddress,
28380
+ id: id.toString(),
28381
+ contractAddress,
28382
+ spenderAddress,
28383
+ ownerAddress,
28384
+ error: err,
28330
28385
  });
28331
28386
  }
28332
28387
  };
@@ -28338,7 +28393,11 @@ const getERC721ApprovedAddress = async (provider, contractAddress, id) => {
28338
28393
  return await contract.getApproved(id);
28339
28394
  }
28340
28395
  catch (err) {
28341
- throw new CheckoutError('Failed to get approved address for ERC721', CheckoutErrorType.GET_ERC721_ALLOWANCE_ERROR, { id: id.toString(), contractAddress });
28396
+ throw new CheckoutError('Failed to get approved address for ERC721', CheckoutErrorType.GET_ERC721_ALLOWANCE_ERROR, {
28397
+ id: id.toString(),
28398
+ contractAddress,
28399
+ error: err,
28400
+ });
28342
28401
  }
28343
28402
  };
28344
28403
  const convertIdToNumber = (id, contractAddress) => {
@@ -28666,8 +28725,8 @@ const getTokenBalances = async (config, provider, ownerAddress, itemRequirements
28666
28725
  const { balances } = await getAllBalances(config, provider, ownerAddress, getL2ChainId(config));
28667
28726
  return balances.filter((balance) => tokenMap.get((balance.token.address || NATIVE).toLocaleLowerCase()));
28668
28727
  }
28669
- catch (error) {
28670
- throw new CheckoutError('Failed to get balances', CheckoutErrorType.GET_BALANCE_ERROR);
28728
+ catch (err) {
28729
+ throw new CheckoutError('Failed to get balances', CheckoutErrorType.GET_BALANCE_ERROR, { error: err });
28671
28730
  }
28672
28731
  };
28673
28732
  /**
@@ -28705,8 +28764,8 @@ const getERC721Balances = async (provider, ownerAddress, itemRequirements) => {
28705
28764
  });
28706
28765
  });
28707
28766
  }
28708
- catch (error) {
28709
- throw new CheckoutError('Failed to get ERC721 balances', CheckoutErrorType.GET_ERC721_BALANCE_ERROR);
28767
+ catch (err) {
28768
+ throw new CheckoutError('Failed to get ERC721 balances', CheckoutErrorType.GET_ERC721_BALANCE_ERROR, { error: err });
28710
28769
  }
28711
28770
  return erc721Balances;
28712
28771
  };
@@ -28776,7 +28835,7 @@ const estimateGas = async (provider, transaction) => {
28776
28835
  return await provider.estimateGas(transaction);
28777
28836
  }
28778
28837
  catch (err) {
28779
- throw new CheckoutError('Failed to estimate gas for transaction', CheckoutErrorType.UNPREDICTABLE_GAS_LIMIT);
28838
+ throw new CheckoutError('Failed to estimate gas for transaction', CheckoutErrorType.UNPREDICTABLE_GAS_LIMIT, { error: err });
28780
28839
  }
28781
28840
  };
28782
28841
  const getGasItemRequirement = (gas, transactionOrGas) => {
@@ -28840,14 +28899,14 @@ const availabilityService = (isDevelopment, isProduction) => {
28840
28899
  try {
28841
28900
  response = await globalAxios.post(`${postEndpoint()}/v1/availability/checkout/swap`);
28842
28901
  }
28843
- catch (error) {
28902
+ catch (err) {
28844
28903
  // The request was made and the server responded with a status code
28845
28904
  // that falls out of the range of 2xx
28846
- response = error.response;
28905
+ response = err.response;
28847
28906
  // If 403 then the service is geo-blocked
28848
28907
  if (response.status === 403)
28849
28908
  return false;
28850
- throw new CheckoutError(`Error fetching from api: ${response.status} ${response.statusText}`, CheckoutErrorType.API_ERROR);
28909
+ throw new CheckoutError(`Error fetching from api: ${response.status} ${response.statusText}`, CheckoutErrorType.API_ERROR, { error: err });
28851
28910
  }
28852
28911
  return true;
28853
28912
  };
@@ -29358,7 +29417,7 @@ const getBridgeFeeEstimate = async (config, readOnlyProviders, fromChainId, toCh
29358
29417
  };
29359
29418
  }
29360
29419
  catch (err) {
29361
- throw new CheckoutError('Error estimating gas for bridge', CheckoutErrorType.BRIDGE_GAS_ESTIMATE_ERROR, { message: err.message });
29420
+ throw new CheckoutError('Error estimating gas for bridge', CheckoutErrorType.BRIDGE_GAS_ESTIMATE_ERROR, { error: err });
29362
29421
  }
29363
29422
  };
29364
29423
 
@@ -30008,7 +30067,7 @@ const routingCalculator = async (config, ownerAddress, balanceRequirements, avai
30008
30067
  readOnlyProviders = await createReadOnlyProviders(config);
30009
30068
  }
30010
30069
  catch (err) {
30011
- throw new CheckoutError('Error occurred while creating read only providers', CheckoutErrorType.PROVIDER_ERROR, { message: err.message });
30070
+ throw new CheckoutError('Error occurred while creating read only providers', CheckoutErrorType.PROVIDER_ERROR, { error: err });
30012
30071
  }
30013
30072
  const tokenBalances = await measureAsyncExecution(config, 'Time to get token balances inside router', getAllTokenBalances(config, readOnlyProviders, ownerAddress, availableRoutingOptions));
30014
30073
  const allowList = await measureAsyncExecution(config, 'Time to get routing allowlist', allowListCheck(config, tokenBalances, availableRoutingOptions));
@@ -30131,9 +30190,7 @@ const signApprovalTransactions = async (provider, approvalTransactions) => {
30131
30190
  receipts = await Promise.all(response.map((transaction) => transaction.transactionResponse.wait()));
30132
30191
  }
30133
30192
  catch (err) {
30134
- throw new CheckoutError('An error occurred while executing the approval transaction', CheckoutErrorType.EXECUTE_APPROVAL_TRANSACTION_ERROR, {
30135
- message: err.message,
30136
- });
30193
+ throw new CheckoutError('An error occurred while executing the approval transaction', CheckoutErrorType.EXECUTE_APPROVAL_TRANSACTION_ERROR, { error: err });
30137
30194
  }
30138
30195
  for (const receipt of receipts) {
30139
30196
  if (receipt.status === 0) {
@@ -30155,9 +30212,7 @@ const signFulfillmentTransactions = async (provider, fulfillmentTransactions) =>
30155
30212
  receipts = await Promise.all(response.map((transaction) => transaction.transactionResponse.wait()));
30156
30213
  }
30157
30214
  catch (err) {
30158
- throw new CheckoutError('An error occurred while executing the fulfillment transaction', CheckoutErrorType.EXECUTE_FULFILLMENT_TRANSACTION_ERROR, {
30159
- message: err.message,
30160
- });
30215
+ throw new CheckoutError('An error occurred while executing the fulfillment transaction', CheckoutErrorType.EXECUTE_FULFILLMENT_TRANSACTION_ERROR, { error: err });
30161
30216
  }
30162
30217
  for (const receipt of receipts) {
30163
30218
  if (receipt.status === 0) {
@@ -30183,9 +30238,7 @@ const signMessage = async (provider, unsignedMessage) => {
30183
30238
  };
30184
30239
  }
30185
30240
  catch (err) {
30186
- throw new CheckoutError('An error occurred while signing the message', CheckoutErrorType.SIGN_MESSAGE_ERROR, {
30187
- message: err.message,
30188
- });
30241
+ throw new CheckoutError('An error occurred while signing the message', CheckoutErrorType.SIGN_MESSAGE_ERROR, { error: err });
30189
30242
  }
30190
30243
  };
30191
30244
 
@@ -30341,7 +30394,9 @@ const getTransactionOrGas = (gasLimit, fulfillmentTransactions) => {
30341
30394
  },
30342
30395
  };
30343
30396
  };
30344
- const buy = async (config, provider, orders) => {
30397
+ const buy = async (config, provider, orders, overrides = {
30398
+ waitFulfillmentSettlements: true,
30399
+ }) => {
30345
30400
  if (orders.length === 0) {
30346
30401
  throw new CheckoutError('No orders were provided to the orders array. Please provide at least one order.', CheckoutErrorType.FULFILL_ORDER_LISTING_ERROR);
30347
30402
  }
@@ -30366,8 +30421,8 @@ const buy = async (config, provider, orders) => {
30366
30421
  }
30367
30422
  catch (err) {
30368
30423
  throw new CheckoutError('An error occurred while getting the order listing', CheckoutErrorType.GET_ORDER_LISTING_ERROR, {
30424
+ error: err,
30369
30425
  orderId: id,
30370
- message: err.message,
30371
30426
  });
30372
30427
  }
30373
30428
  if (order.result.buy.length === 0) {
@@ -30406,7 +30461,7 @@ const buy = async (config, provider, orders) => {
30406
30461
  if (!err.message.includes('The fulfiller does not have the balances needed to fulfill')) {
30407
30462
  throw new CheckoutError('Error occurred while trying to fulfill the order', CheckoutErrorType.FULFILL_ORDER_LISTING_ERROR, {
30408
30463
  orderId: id,
30409
- message: err.message,
30464
+ error: err,
30410
30465
  });
30411
30466
  }
30412
30467
  }
@@ -30465,22 +30520,37 @@ const buy = async (config, provider, orders) => {
30465
30520
  }
30466
30521
  }
30467
30522
  catch (err) {
30468
- throw new CheckoutError('Error fetching fulfillment transaction', CheckoutErrorType.FULFILL_ORDER_LISTING_ERROR, {
30469
- message: err.message,
30470
- });
30523
+ throw new CheckoutError('Error fetching fulfillment transaction', CheckoutErrorType.FULFILL_ORDER_LISTING_ERROR, { error: err });
30471
30524
  }
30472
- const fulfillmentResult = await signFulfillmentTransactions(provider, unsignedFulfillmentTransactions);
30473
- if (fulfillmentResult.type === SignTransactionStatusType.FAILED) {
30525
+ if (overrides.waitFulfillmentSettlements) {
30526
+ const fulfillmentResult = await signFulfillmentTransactions(provider, unsignedFulfillmentTransactions);
30527
+ if (fulfillmentResult.type === SignTransactionStatusType.FAILED) {
30528
+ return {
30529
+ status: CheckoutStatus.FAILED,
30530
+ transactionHash: fulfillmentResult.transactionHash,
30531
+ reason: fulfillmentResult.reason,
30532
+ smartCheckoutResult,
30533
+ };
30534
+ }
30474
30535
  return {
30475
- status: CheckoutStatus.FAILED,
30476
- transactionHash: fulfillmentResult.transactionHash,
30477
- reason: fulfillmentResult.reason,
30536
+ status: CheckoutStatus.SUCCESS,
30478
30537
  smartCheckoutResult,
30479
30538
  };
30480
30539
  }
30540
+ let transactions;
30541
+ try {
30542
+ const response = await Promise.all(unsignedFulfillmentTransactions.map((transaction) => sendTransaction(provider, transaction)));
30543
+ transactions = response.map((result) => result.transactionResponse);
30544
+ }
30545
+ catch (err) {
30546
+ throw new CheckoutError('An error occurred while executing the fulfillment transaction', CheckoutErrorType.EXECUTE_FULFILLMENT_TRANSACTION_ERROR, {
30547
+ message: err.message,
30548
+ });
30549
+ }
30481
30550
  return {
30482
- status: CheckoutStatus.SUCCESS,
30551
+ status: CheckoutStatus.FULFILLMENTS_UNSETTLED,
30483
30552
  smartCheckoutResult,
30553
+ transactions,
30484
30554
  };
30485
30555
  }
30486
30556
  return {
@@ -30505,7 +30575,7 @@ const cancel = async (config, provider, orderIds) => {
30505
30575
  catch (err) {
30506
30576
  throw new CheckoutError('An error occurred while cancelling the order listing', CheckoutErrorType.CANCEL_ORDER_LISTING_ERROR, {
30507
30577
  orderId,
30508
- message: err.message,
30578
+ error: err,
30509
30579
  });
30510
30580
  }
30511
30581
  const result = await signFulfillmentTransactions(provider, [unsignedCancelOrderTransaction]);
@@ -30574,7 +30644,7 @@ const sell = async (config, provider, orders) => {
30574
30644
  }
30575
30645
  catch (err) {
30576
30646
  throw new CheckoutError('An error occurred while preparing the listing', CheckoutErrorType.PREPARE_ORDER_LISTING_ERROR, {
30577
- message: err.message,
30647
+ error: err,
30578
30648
  id: sellToken.id,
30579
30649
  collectionAddress: sellToken.collectionAddress,
30580
30650
  });
@@ -30630,7 +30700,7 @@ const sell = async (config, provider, orders) => {
30630
30700
  }
30631
30701
  catch (err) {
30632
30702
  throw new CheckoutError('An error occurred while creating the listing', CheckoutErrorType.CREATE_ORDER_LISTING_ERROR, {
30633
- message: err.message,
30703
+ error: err,
30634
30704
  collectionId: sellToken.id,
30635
30705
  collectionAddress: sellToken.collectionAddress,
30636
30706
  });
@@ -30927,7 +30997,7 @@ class Checkout {
30927
30997
  }
30928
30998
  }
30929
30999
  catch (err) {
30930
- reject(new CheckoutError('Failed to load widgets script', CheckoutErrorType.WIDGETS_SCRIPT_LOAD_ERROR, { message: err.message }));
31000
+ reject(new CheckoutError('Failed to load widgets script', CheckoutErrorType.WIDGETS_SCRIPT_LOAD_ERROR, { error: err }));
30931
31001
  }
30932
31002
  });
30933
31003
  return factory;
@@ -31057,7 +31127,7 @@ class Checkout {
31057
31127
  console.warn('This endpoint currently only processes the first order in the array.');
31058
31128
  }
31059
31129
  const web3Provider = await validateProvider(this.config, params.provider);
31060
- return await buy(this.config, web3Provider, params.orders);
31130
+ return await buy(this.config, web3Provider, params.orders, params.overrides);
31061
31131
  }
31062
31132
  /**
31063
31133
  * Determines the requirements for performing a sell.
@@ -31093,8 +31163,8 @@ class Checkout {
31093
31163
  try {
31094
31164
  itemRequirements = await getItemRequirementsFromRequirements(web3Provider, params.itemRequirements);
31095
31165
  }
31096
- catch (error) {
31097
- throw new CheckoutError('Failed to map item requirements', CheckoutErrorType.ITEM_REQUIREMENTS_ERROR);
31166
+ catch (err) {
31167
+ throw new CheckoutError('Failed to map item requirements', CheckoutErrorType.ITEM_REQUIREMENTS_ERROR, { error: err });
31098
31168
  }
31099
31169
  return await smartCheckout(this.config, web3Provider, itemRequirements, params.transactionOrGasAmount);
31100
31170
  }