@imtbl/sdk 0.36.4 → 0.37.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/checkout.js CHANGED
@@ -3234,105 +3234,6 @@ axios.default = axios;
3234
3234
  // this module should only have a default export
3235
3235
  var axios$1 = axios;
3236
3236
 
3237
- /* eslint-disable @typescript-eslint/naming-convention */
3238
- /**
3239
- * @constant {string} ETH_SEPOLIA_CHAIN_ID - The chain ID for the Ethereum Sepolia testnet (EIP-155 compatible format).
3240
- */
3241
- const ETH_SEPOLIA_CHAIN_ID = '11155111';
3242
- /**
3243
- * @constant {string} ETH_MAINNET_CHAIN_ID - The chain ID for the Ethereum mainnet (EIP-155 compatible format).
3244
- */
3245
- const ETH_MAINNET_CHAIN_ID = '1';
3246
- /**
3247
- * @constant {string} ZKEVM_DEVNET_CHAIN_ID - The chain ID for the zkEVM devnet (EIP-155 compatible format).
3248
- */
3249
- const ZKEVM_DEVNET_CHAIN_ID = '15003';
3250
- /**
3251
- * @constant {string} ZKEVM_TESTNET_CHAIN_ID - The chain ID for the zkEVM testnet (EIP-155 compatible format).
3252
- */
3253
- const ZKEVM_TESTNET_CHAIN_ID = '13473';
3254
- /**
3255
- * @constant {string} ZKEVM_MAINNET_CHAIN_ID - The chain ID for the zkEVM mainnet (EIP-155 compatible format).
3256
- */
3257
- const ZKEVM_MAINNET_CHAIN_ID = '13371'; // @TODO confirm this is still correct
3258
- /**
3259
- * @constant {BridgeInstance} ETH_SEPOLIA_TO_ZKEVM_DEVNET - A bridge instance configuration for bridging between
3260
- * the Ethereum Sepolia testnet and the zkEVM devnet.
3261
- */
3262
- const ETH_SEPOLIA_TO_ZKEVM_DEVNET = {
3263
- rootChainID: ETH_SEPOLIA_CHAIN_ID,
3264
- childChainID: ZKEVM_DEVNET_CHAIN_ID,
3265
- };
3266
- /**
3267
- * @constant {BridgeInstance} ETH_SEPOLIA_TO_ZKEVM_TESTNET - A bridge instance configuration for bridging
3268
- * between the Ethereum Sepolia testnet and the zkEVM testnet.
3269
- */
3270
- const ETH_SEPOLIA_TO_ZKEVM_TESTNET = {
3271
- rootChainID: ETH_SEPOLIA_CHAIN_ID,
3272
- childChainID: ZKEVM_TESTNET_CHAIN_ID,
3273
- };
3274
- /**
3275
- * @constant {BridgeInstance} ETH_MAINNET_TO_ZKEVM_MAINNET - A bridge instance configuration for bridging
3276
- * between the Ethereum mainnet and the zkEVM mainnet.
3277
- */
3278
- const ETH_MAINNET_TO_ZKEVM_MAINNET = {
3279
- rootChainID: ETH_MAINNET_CHAIN_ID,
3280
- childChainID: ZKEVM_MAINNET_CHAIN_ID,
3281
- };
3282
- /**
3283
- * @typedef {Object} axelarAPIEndpoints - API endpoints for the testnet & mainnet Axelar environment configurations
3284
- */
3285
- const axelarAPIEndpoints = {
3286
- testnet: 'https://testnet.api.gmp.axelarscan.io',
3287
- mainnet: 'https://api.gmp.axelarscan.io',
3288
- devnet: '',
3289
- };
3290
- /**
3291
- * @typedef {Object} axelarChains
3292
- * @property {AxelarChainDetails} [chainId] - Mapping of the ChainId to the Axelar chain id string and symbol.
3293
- */
3294
- const axelarChains = {
3295
- 11155111: {
3296
- id: 'ethereum-sepolia',
3297
- symbol: 'ETH',
3298
- },
3299
- 1: {
3300
- id: 'ethereum',
3301
- symbol: 'ETH',
3302
- },
3303
- 15003: {
3304
- id: 'immutable',
3305
- symbol: 'IMX',
3306
- },
3307
- 13473: {
3308
- id: 'immutable',
3309
- symbol: 'IMX',
3310
- },
3311
- 13371: {
3312
- id: 'immutable',
3313
- symbol: 'IMX',
3314
- }, // immutable zkevm mainnet
3315
- };
3316
- /**
3317
- * @typedef {Object} bridgeMethods
3318
- * @property {string} deposit - The set of contract methods for depositing.
3319
- * @property {string} withdraw - The set of contract methods for withdrawing.
3320
- */
3321
- const bridgeMethods = {
3322
- deposit: {
3323
- token: 'deposit',
3324
- tokenTo: 'depositTo',
3325
- native: 'depositETH',
3326
- nativeTo: 'depositToETH',
3327
- },
3328
- withdraw: {
3329
- token: 'withdraw',
3330
- tokenTo: 'withdrawTo',
3331
- native: 'withdrawIMX',
3332
- nativeTo: 'withdrawIMXTo',
3333
- },
3334
- };
3335
-
3336
3237
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
3337
3238
 
3338
3239
  function getDefaultExportFromCjs (x) {
@@ -12519,6 +12420,105 @@ function parseUnits(value, unitName) {
12519
12420
  return parseFixed(value, (unitName != null) ? unitName : 18);
12520
12421
  }
12521
12422
 
12423
+ /* eslint-disable @typescript-eslint/naming-convention */
12424
+ /**
12425
+ * @constant {string} ETH_SEPOLIA_CHAIN_ID - The chain ID for the Ethereum Sepolia testnet (EIP-155 compatible format).
12426
+ */
12427
+ const ETH_SEPOLIA_CHAIN_ID = '11155111';
12428
+ /**
12429
+ * @constant {string} ETH_MAINNET_CHAIN_ID - The chain ID for the Ethereum mainnet (EIP-155 compatible format).
12430
+ */
12431
+ const ETH_MAINNET_CHAIN_ID = '1';
12432
+ /**
12433
+ * @constant {string} ZKEVM_DEVNET_CHAIN_ID - The chain ID for the zkEVM devnet (EIP-155 compatible format).
12434
+ */
12435
+ const ZKEVM_DEVNET_CHAIN_ID = '15003';
12436
+ /**
12437
+ * @constant {string} ZKEVM_TESTNET_CHAIN_ID - The chain ID for the zkEVM testnet (EIP-155 compatible format).
12438
+ */
12439
+ const ZKEVM_TESTNET_CHAIN_ID = '13473';
12440
+ /**
12441
+ * @constant {string} ZKEVM_MAINNET_CHAIN_ID - The chain ID for the zkEVM mainnet (EIP-155 compatible format).
12442
+ */
12443
+ const ZKEVM_MAINNET_CHAIN_ID = '13371'; // @TODO confirm this is still correct
12444
+ /**
12445
+ * @constant {BridgeInstance} ETH_SEPOLIA_TO_ZKEVM_DEVNET - A bridge instance configuration for bridging between
12446
+ * the Ethereum Sepolia testnet and the zkEVM devnet.
12447
+ */
12448
+ const ETH_SEPOLIA_TO_ZKEVM_DEVNET = {
12449
+ rootChainID: ETH_SEPOLIA_CHAIN_ID,
12450
+ childChainID: ZKEVM_DEVNET_CHAIN_ID,
12451
+ };
12452
+ /**
12453
+ * @constant {BridgeInstance} ETH_SEPOLIA_TO_ZKEVM_TESTNET - A bridge instance configuration for bridging
12454
+ * between the Ethereum Sepolia testnet and the zkEVM testnet.
12455
+ */
12456
+ const ETH_SEPOLIA_TO_ZKEVM_TESTNET = {
12457
+ rootChainID: ETH_SEPOLIA_CHAIN_ID,
12458
+ childChainID: ZKEVM_TESTNET_CHAIN_ID,
12459
+ };
12460
+ /**
12461
+ * @constant {BridgeInstance} ETH_MAINNET_TO_ZKEVM_MAINNET - A bridge instance configuration for bridging
12462
+ * between the Ethereum mainnet and the zkEVM mainnet.
12463
+ */
12464
+ const ETH_MAINNET_TO_ZKEVM_MAINNET = {
12465
+ rootChainID: ETH_MAINNET_CHAIN_ID,
12466
+ childChainID: ZKEVM_MAINNET_CHAIN_ID,
12467
+ };
12468
+ /**
12469
+ * @typedef {Object} axelarAPIEndpoints - API endpoints for the testnet & mainnet Axelar environment configurations
12470
+ */
12471
+ const axelarAPIEndpoints = {
12472
+ testnet: 'https://testnet.api.gmp.axelarscan.io',
12473
+ mainnet: 'https://api.gmp.axelarscan.io',
12474
+ devnet: '',
12475
+ };
12476
+ /**
12477
+ * @typedef {Object} axelarChains
12478
+ * @property {AxelarChainDetails} [chainId] - Mapping of the ChainId to the Axelar chain id string and symbol.
12479
+ */
12480
+ const axelarChains = {
12481
+ 11155111: {
12482
+ id: 'ethereum-sepolia',
12483
+ symbol: 'ETH',
12484
+ },
12485
+ 1: {
12486
+ id: 'ethereum',
12487
+ symbol: 'ETH',
12488
+ },
12489
+ 15003: {
12490
+ id: 'immutable',
12491
+ symbol: 'IMX',
12492
+ },
12493
+ 13473: {
12494
+ id: 'immutable',
12495
+ symbol: 'IMX',
12496
+ },
12497
+ 13371: {
12498
+ id: 'immutable',
12499
+ symbol: 'IMX',
12500
+ }, // immutable zkevm mainnet
12501
+ };
12502
+ /**
12503
+ * @typedef {Object} bridgeMethods
12504
+ * @property {string} deposit - The set of contract methods for depositing.
12505
+ * @property {string} withdraw - The set of contract methods for withdrawing.
12506
+ */
12507
+ const bridgeMethods = {
12508
+ deposit: {
12509
+ token: 'deposit',
12510
+ tokenTo: 'depositTo',
12511
+ native: 'depositETH',
12512
+ nativeTo: 'depositToETH',
12513
+ },
12514
+ withdraw: {
12515
+ token: 'withdraw',
12516
+ tokenTo: 'withdrawTo',
12517
+ native: 'withdrawIMX',
12518
+ nativeTo: 'withdrawIMXTo',
12519
+ },
12520
+ };
12521
+
12522
12522
  const ROOT_ERC20_BRIDGE_FLOW_RATE = [
12523
12523
  {
12524
12524
  inputs: [
@@ -14779,6 +14779,7 @@ var BridgeErrorType;
14779
14779
  BridgeErrorType["AXELAR_CHAIN_NOT_FOUND"] = "AXELAR_CHAIN_NOT_FOUND";
14780
14780
  BridgeErrorType["AXELAR_GAS_ESTIMATE_FAILED"] = "AXELAR_GAS_ESTIMATE_FAILED";
14781
14781
  BridgeErrorType["INVALID_RECIPIENT"] = "INVALID_RECIPIENT";
14782
+ BridgeErrorType["FLOW_RATE_ERROR"] = "FLOW_RATE_ERROR";
14782
14783
  })(BridgeErrorType || (BridgeErrorType = {}));
14783
14784
  /**
14784
14785
  * Represents a custom error for bridge operations.
@@ -16091,16 +16092,17 @@ var BridgeFeeActions;
16091
16092
  */
16092
16093
  var BridgeMethodsGasLimit;
16093
16094
  (function (BridgeMethodsGasLimit) {
16094
- BridgeMethodsGasLimit[BridgeMethodsGasLimit["DEPOSIT_SOURCE"] = 500000] = "DEPOSIT_SOURCE";
16095
- BridgeMethodsGasLimit[BridgeMethodsGasLimit["DEPOSIT_DESTINATION"] = 700000] = "DEPOSIT_DESTINATION";
16096
- BridgeMethodsGasLimit[BridgeMethodsGasLimit["WITHDRAW_SOURCE"] = 400000] = "WITHDRAW_SOURCE";
16097
- BridgeMethodsGasLimit[BridgeMethodsGasLimit["WITHDRAW_DESTINATION"] = 700000] = "WITHDRAW_DESTINATION";
16098
- BridgeMethodsGasLimit[BridgeMethodsGasLimit["MAP_TOKEN_SOURCE"] = 300000] = "MAP_TOKEN_SOURCE";
16099
- BridgeMethodsGasLimit[BridgeMethodsGasLimit["MAP_TOKEN_DESTINATION"] = 700000] = "MAP_TOKEN_DESTINATION";
16095
+ BridgeMethodsGasLimit[BridgeMethodsGasLimit["DEPOSIT_SOURCE"] = 200000] = "DEPOSIT_SOURCE";
16096
+ BridgeMethodsGasLimit[BridgeMethodsGasLimit["DEPOSIT_DESTINATION"] = 200000] = "DEPOSIT_DESTINATION";
16097
+ BridgeMethodsGasLimit[BridgeMethodsGasLimit["WITHDRAW_SOURCE"] = 200000] = "WITHDRAW_SOURCE";
16098
+ BridgeMethodsGasLimit[BridgeMethodsGasLimit["WITHDRAW_DESTINATION"] = 250000] = "WITHDRAW_DESTINATION";
16099
+ BridgeMethodsGasLimit[BridgeMethodsGasLimit["MAP_TOKEN_SOURCE"] = 200000] = "MAP_TOKEN_SOURCE";
16100
+ BridgeMethodsGasLimit[BridgeMethodsGasLimit["MAP_TOKEN_DESTINATION"] = 200000] = "MAP_TOKEN_DESTINATION";
16100
16101
  BridgeMethodsGasLimit[BridgeMethodsGasLimit["FINALISE_WITHDRAWAL"] = 200000] = "FINALISE_WITHDRAWAL";
16101
16102
  })(BridgeMethodsGasLimit || (BridgeMethodsGasLimit = {}));
16102
16103
  var StatusResponse;
16103
16104
  (function (StatusResponse) {
16105
+ StatusResponse["PENDING"] = "PENDING";
16104
16106
  StatusResponse["PROCESSING"] = "PROCESSING";
16105
16107
  StatusResponse["COMPLETE"] = "COMPLETE";
16106
16108
  StatusResponse["RETRY"] = "RETRY";
@@ -16109,6 +16111,109 @@ var StatusResponse;
16109
16111
  StatusResponse["FLOW_RATE_CONTROLLED"] = "FLOW_RATE_CONTROLLED";
16110
16112
  })(StatusResponse || (StatusResponse = {}));
16111
16113
 
16114
+ var GMPStatus;
16115
+ (function (GMPStatus) {
16116
+ GMPStatus["SRC_GATEWAY_CALLED"] = "source_gateway_called";
16117
+ GMPStatus["DEST_GATEWAY_APPROVED"] = "destination_gateway_approved";
16118
+ GMPStatus["DEST_EXECUTED"] = "destination_executed";
16119
+ GMPStatus["EXPRESS_EXECUTED"] = "express_executed";
16120
+ GMPStatus["DEST_EXECUTE_ERROR"] = "error";
16121
+ GMPStatus["DEST_EXECUTING"] = "executing";
16122
+ GMPStatus["APPROVING"] = "approving";
16123
+ GMPStatus["FORECALLED"] = "forecalled";
16124
+ GMPStatus["FORECALLED_WITHOUT_GAS_PAID"] = "forecalled_without_gas_paid";
16125
+ GMPStatus["NOT_EXECUTED"] = "not_executed";
16126
+ GMPStatus["NOT_EXECUTED_WITHOUT_GAS_PAID"] = "not_executed_without_gas_paid";
16127
+ GMPStatus["INSUFFICIENT_FEE"] = "insufficient_fee";
16128
+ GMPStatus["UNKNOWN_ERROR"] = "unknown_error";
16129
+ GMPStatus["CANNOT_FETCH_STATUS"] = "cannot_fetch_status";
16130
+ GMPStatus["SRC_GATEWAY_CONFIRMED"] = "confirmed";
16131
+ })(GMPStatus || (GMPStatus = {}));
16132
+ var GasPaidStatus;
16133
+ (function (GasPaidStatus) {
16134
+ GasPaidStatus["GAS_UNPAID"] = "gas_unpaid";
16135
+ GasPaidStatus["GAS_PAID"] = "gas_paid";
16136
+ GasPaidStatus["GAS_PAID_NOT_ENOUGH_GAS"] = "gas_paid_not_enough_gas";
16137
+ GasPaidStatus["GAS_PAID_ENOUGH_GAS"] = "gas_paid_enough_gas";
16138
+ })(GasPaidStatus || (GasPaidStatus = {}));
16139
+
16140
+ /* eslint-disable @typescript-eslint/naming-convention */
16141
+ const parseGMPStatus = (response) => {
16142
+ const { error, status } = response;
16143
+ if (status === 'error' && error)
16144
+ return GMPStatus.DEST_EXECUTE_ERROR;
16145
+ if (status === 'executed')
16146
+ return GMPStatus.DEST_EXECUTED;
16147
+ if (status === 'approved')
16148
+ return GMPStatus.DEST_GATEWAY_APPROVED;
16149
+ if (status === 'called')
16150
+ return GMPStatus.SRC_GATEWAY_CALLED;
16151
+ if (status === 'executing')
16152
+ return GMPStatus.DEST_EXECUTING;
16153
+ return status;
16154
+ };
16155
+ const parseGMPError = (response) => {
16156
+ if (response.error) {
16157
+ return {
16158
+ message: response.error.error.message,
16159
+ txHash: response.error.error.transactionHash,
16160
+ chain: response.error.chain,
16161
+ };
16162
+ }
16163
+ if (response.is_insufficient_fee) {
16164
+ return {
16165
+ message: 'Insufficient fee',
16166
+ txHash: response.call.transaction.hash,
16167
+ chain: response.call.chain,
16168
+ };
16169
+ }
16170
+ return undefined;
16171
+ };
16172
+ const execGet = async (base, params) => fetch(`${base}?${new URLSearchParams(params).toString()}`, {
16173
+ method: 'GET',
16174
+ headers: { 'Content-Type': 'application/json' },
16175
+ cache: 'no-store',
16176
+ })
16177
+ .then((res) => res.json())
16178
+ .then((res) => res.data);
16179
+ const fetchGMPTransaction = async (axelarGMPApiUrl, txHash, txLogIndex) => execGet(axelarGMPApiUrl, {
16180
+ method: 'searchGMP',
16181
+ txHash,
16182
+ txLogIndex,
16183
+ })
16184
+ .then((data) => data.find((gmpTx) => gmpTx.id.indexOf(txHash) > -1 || gmpTx.call.transactionHash.indexOf(txHash) > -1))
16185
+ .catch(() => undefined);
16186
+ const queryTransactionStatus = async (axelarGMPApiUrl, txHash, txLogIndex) => {
16187
+ const txDetails = await fetchGMPTransaction(axelarGMPApiUrl, txHash, txLogIndex);
16188
+ if (!txDetails)
16189
+ return { status: GMPStatus.CANNOT_FETCH_STATUS };
16190
+ const { call, gas_status, gas_paid, executed, express_executed, approved, callback, } = txDetails;
16191
+ const gasPaidInfo = {
16192
+ status: gas_status,
16193
+ details: gas_paid,
16194
+ };
16195
+ // Note: Currently, the GMP API doesn't always return the `total` field in the `time_spent` object
16196
+ // This is a temporary fix to ensure that the `total` field is always present
16197
+ // TODO: Remove this once the API is fixed
16198
+ const timeSpent = txDetails.time_spent;
16199
+ if (timeSpent) {
16200
+ timeSpent.total = timeSpent.total
16201
+ || Object.values(timeSpent).reduce((accumulator, value) => accumulator + value, 0);
16202
+ }
16203
+ return {
16204
+ status: parseGMPStatus(txDetails),
16205
+ error: parseGMPError(txDetails),
16206
+ timeSpent,
16207
+ gasPaidInfo,
16208
+ callTx: call,
16209
+ executed,
16210
+ expressExecuted: express_executed,
16211
+ approved,
16212
+ callback,
16213
+ };
16214
+ };
16215
+
16216
+ /* eslint-disable no-console */
16112
16217
  /* eslint-disable class-methods-use-this */
16113
16218
  /**
16114
16219
  * Represents a token bridge, which manages asset transfers between two chains.
@@ -16300,6 +16405,7 @@ class TokenBridge {
16300
16405
  to: req.token,
16301
16406
  value: 0,
16302
16407
  from: req.senderAddress,
16408
+ chainId: parseInt(req.sourceChainId, 10),
16303
16409
  };
16304
16410
  return {
16305
16411
  contractToApprove: sourceBridgeAddress,
@@ -16445,6 +16551,7 @@ class TokenBridge {
16445
16551
  data,
16446
16552
  to: contractAddress,
16447
16553
  value: amount.add(fees.bridgeFee).toString(),
16554
+ chainId: parseInt(sourceChainId, 10),
16448
16555
  },
16449
16556
  };
16450
16557
  }
@@ -16464,6 +16571,7 @@ class TokenBridge {
16464
16571
  data,
16465
16572
  to: contractAddress,
16466
16573
  value: fees.bridgeFee.toString(),
16574
+ chainId: parseInt(sourceChainId, 10),
16467
16575
  },
16468
16576
  };
16469
16577
  }
@@ -16512,6 +16620,21 @@ class TokenBridge {
16512
16620
  throw new BridgeError(`Childchain provider chainID ${childNetwork.chainId} does not match expected chainID ${this.config.bridgeInstance.childChainID}. ${errMessage}`, BridgeErrorType.UNSUPPORTED_ERROR);
16513
16621
  }
16514
16622
  }
16623
+ getAxelarEndpoint(source) {
16624
+ let axelarAPIEndpoint;
16625
+ if (source === ETH_MAINNET_TO_ZKEVM_MAINNET.rootChainID
16626
+ || source === ETH_MAINNET_TO_ZKEVM_MAINNET.childChainID) {
16627
+ axelarAPIEndpoint = axelarAPIEndpoints.mainnet;
16628
+ }
16629
+ else if (source === ETH_SEPOLIA_TO_ZKEVM_TESTNET.rootChainID
16630
+ || source === ETH_SEPOLIA_TO_ZKEVM_TESTNET.childChainID) {
16631
+ axelarAPIEndpoint = axelarAPIEndpoints.testnet;
16632
+ }
16633
+ else {
16634
+ axelarAPIEndpoint = axelarAPIEndpoints.devnet;
16635
+ }
16636
+ return axelarAPIEndpoint;
16637
+ }
16515
16638
  /**
16516
16639
  * Calculate the gas amount for a transaction using axelarjs-sdk.
16517
16640
  * @param {*} source - The source chainId.
@@ -16530,18 +16653,7 @@ class TokenBridge {
16530
16653
  if (!destinationAxelar) {
16531
16654
  throw new BridgeError(`Destination chainID ${destination} can not be matched to an Axelar chain.`, BridgeErrorType.AXELAR_CHAIN_NOT_FOUND);
16532
16655
  }
16533
- let axelarApiEndpoint;
16534
- if (source === ETH_MAINNET_TO_ZKEVM_MAINNET.rootChainID
16535
- || source === ETH_MAINNET_TO_ZKEVM_MAINNET.childChainID) {
16536
- axelarApiEndpoint = axelarAPIEndpoints.mainnet;
16537
- }
16538
- else if (source === ETH_SEPOLIA_TO_ZKEVM_TESTNET.rootChainID
16539
- || source === ETH_SEPOLIA_TO_ZKEVM_TESTNET.childChainID) {
16540
- axelarApiEndpoint = axelarAPIEndpoints.testnet;
16541
- }
16542
- else {
16543
- axelarApiEndpoint = axelarAPIEndpoints.devnet;
16544
- }
16656
+ const axelarAPIEndpoint = this.getAxelarEndpoint(source);
16545
16657
  let axiosResponse;
16546
16658
  const estimateGasReq = {
16547
16659
  method: 'estimateGasFee',
@@ -16552,7 +16664,7 @@ class TokenBridge {
16552
16664
  gasMultiplier,
16553
16665
  };
16554
16666
  try {
16555
- axiosResponse = await axios$1.post(axelarApiEndpoint, estimateGasReq);
16667
+ axiosResponse = await axios$1.post(axelarAPIEndpoint, estimateGasReq);
16556
16668
  }
16557
16669
  catch (error) {
16558
16670
  axiosResponse = error.response;
@@ -16569,30 +16681,136 @@ class TokenBridge {
16569
16681
  throw new BridgeError(`Estimating Axelar Gas failed with the reason: ${err}`, BridgeErrorType.AXELAR_GAS_ESTIMATE_FAILED);
16570
16682
  }
16571
16683
  }
16572
- // STUBBED ENDPOINTS FOR PHASE 2 -------------------------------------------
16573
16684
  /**
16574
16685
  * Queries the status of a bridge transaction.
16575
16686
  *
16576
- * @param {TokenMappingRequest} req - The request object containing the token, rootChainId and childChainId.
16577
- * @returns {Promise<TokenMappingResponse>} - A promise that resolves to an object containing the token mappings.
16687
+ * @param {TxStatusRequest} req - The request object containing an array of transactions to query.
16688
+ * @returns {Promise<TxStatusResponse>} - A promise that resolves to an array of transaction statuses.
16578
16689
  * @throws {BridgeError} - If an error occurs during the query, a BridgeError will be thrown with a specific error type.
16579
- * @dev this SDK method is currently stubbed
16580
16690
  */
16581
16691
  async getTransactionStatus(req) {
16582
- // eslint-disable-next-line no-console
16583
- console.log('stubbed response with req', req);
16584
- // Return the token mappings
16585
- return {
16586
- transactions: [{
16587
- transactionHash: '0x1234....',
16588
- status: StatusResponse.COMPLETE,
16589
- data: 'stubbed data',
16590
- }, {
16591
- transactionHash: '0xABCD....',
16592
- status: StatusResponse.PROCESSING,
16593
- data: 'stubbed data',
16594
- }],
16692
+ const axelarAPIEndpoint = this.getAxelarEndpoint(req.sourceChainId);
16693
+ const txStatusResponse = {
16694
+ transactions: [],
16595
16695
  };
16696
+ const abiCoder = new AbiCoder();
16697
+ const statusPromises = [];
16698
+ for (const transaction of req.transactions) {
16699
+ statusPromises.push(queryTransactionStatus(axelarAPIEndpoint, transaction.txHash));
16700
+ }
16701
+ let statusResponses;
16702
+ try {
16703
+ statusResponses = await Promise.all(statusPromises);
16704
+ }
16705
+ catch (err) {
16706
+ throw new BridgeError(`Failed to fetch the Axelar Status with the reason: ${err}`, BridgeErrorType.AXELAR_GAS_ESTIMATE_FAILED);
16707
+ }
16708
+ const unpaidGasStatus = [GasPaidStatus.GAS_UNPAID, GasPaidStatus.GAS_PAID_NOT_ENOUGH_GAS];
16709
+ const isWithdraw = [
16710
+ ZKEVM_DEVNET_CHAIN_ID,
16711
+ ZKEVM_TESTNET_CHAIN_ID,
16712
+ ZKEVM_MAINNET_CHAIN_ID
16713
+ ].includes(req.sourceChainId);
16714
+ let rootBridge;
16715
+ if (isWithdraw) {
16716
+ rootBridge = await withBridgeError(async () => {
16717
+ const contract = new Contract(this.config.bridgeContracts.rootERC20BridgeFlowRate, ROOT_ERC20_BRIDGE_FLOW_RATE, this.config.rootProvider);
16718
+ return contract;
16719
+ }, BridgeErrorType.INTERNAL_ERROR);
16720
+ }
16721
+ const flowRatePromises = [];
16722
+ const flowRatePromisesReceivers = [];
16723
+ for (let i = 0, l = statusResponses.length; i < l; i++) {
16724
+ let metaStatus;
16725
+ // consolidate axelar statuses to our own simplified metaStatus
16726
+ switch (statusResponses[i].status) {
16727
+ case GMPStatus.CANNOT_FETCH_STATUS:
16728
+ metaStatus = StatusResponse.PENDING;
16729
+ break;
16730
+ case GMPStatus.SRC_GATEWAY_CALLED:
16731
+ case GMPStatus.DEST_GATEWAY_APPROVED:
16732
+ case GMPStatus.DEST_EXECUTING:
16733
+ case GMPStatus.SRC_GATEWAY_CONFIRMED:
16734
+ case GMPStatus.APPROVING:
16735
+ metaStatus = StatusResponse.PROCESSING;
16736
+ break;
16737
+ case GMPStatus.NOT_EXECUTED:
16738
+ metaStatus = StatusResponse.RETRY;
16739
+ break;
16740
+ case GMPStatus.NOT_EXECUTED_WITHOUT_GAS_PAID:
16741
+ case GMPStatus.INSUFFICIENT_FEE:
16742
+ metaStatus = StatusResponse.NOT_ENOUGH_GAS;
16743
+ break;
16744
+ case GMPStatus.DEST_EXECUTED:
16745
+ metaStatus = StatusResponse.COMPLETE;
16746
+ break;
16747
+ default:
16748
+ metaStatus = StatusResponse.ERROR;
16749
+ }
16750
+ if (statusResponses[i].gasPaidInfo) {
16751
+ if (unpaidGasStatus.includes(statusResponses[i].gasPaidInfo.status)) {
16752
+ metaStatus = StatusResponse.NOT_ENOUGH_GAS;
16753
+ }
16754
+ }
16755
+ let txItem = {
16756
+ txHash: req.transactions[i].txHash,
16757
+ status: metaStatus,
16758
+ data: {
16759
+ gmpResponse: statusResponses[i].status,
16760
+ },
16761
+ };
16762
+ let decodedData;
16763
+ if (statusResponses[i]?.callTx?.returnValues?.payload) {
16764
+ decodedData = abiCoder.decode(['bytes32', 'address', 'address', 'address', 'uint256'], statusResponses[i].callTx.returnValues.payload);
16765
+ txItem = {
16766
+ ...txItem,
16767
+ token: decodedData[1],
16768
+ sender: decodedData[2],
16769
+ receiver: decodedData[3],
16770
+ amount: decodedData[4],
16771
+ };
16772
+ }
16773
+ let flowRatePromiseIndex;
16774
+ if (metaStatus === StatusResponse.COMPLETE
16775
+ && isWithdraw && txItem.receiver) {
16776
+ // consolidate the calls we have to make to the flow rate by receiver
16777
+ if (!flowRatePromisesReceivers.includes(txItem.receiver)) {
16778
+ flowRatePromises.push(rootBridge.getPendingWithdrawals(txItem.receiver, [0]));
16779
+ flowRatePromisesReceivers.push(txItem.receiver);
16780
+ flowRatePromiseIndex = flowRatePromisesReceivers.length - 1;
16781
+ }
16782
+ else {
16783
+ flowRatePromiseIndex = flowRatePromisesReceivers.findIndex((el) => el === txItem.receiver);
16784
+ }
16785
+ txItem.data.flowRatePromiseIndex = flowRatePromiseIndex;
16786
+ }
16787
+ txStatusResponse.transactions.push(txItem);
16788
+ } // for
16789
+ let flowRateResponses = [];
16790
+ if (flowRatePromises.length > 0) {
16791
+ try {
16792
+ flowRateResponses = await Promise.all(flowRatePromises);
16793
+ }
16794
+ catch (err) {
16795
+ throw new BridgeError(`Failed to fetch the Flow Rate statuses with the reason: ${err}`, BridgeErrorType.FLOW_RATE_ERROR);
16796
+ }
16797
+ }
16798
+ for (const txStatusRes of txStatusResponse.transactions) {
16799
+ if (txStatusRes.data.flowRatePromiseIndex !== -1 && flowRateResponses[txStatusRes.data.flowRatePromiseIndex]) {
16800
+ const flowRatedTx = flowRateResponses[txStatusRes.data.flowRatePromiseIndex].find((el) => (el.amount.toString() === txStatusRes.amount.toString()
16801
+ && el.token === txStatusRes.token
16802
+ && el.withdrawer === txStatusRes.sender));
16803
+ if (flowRatedTx) {
16804
+ txStatusRes.status = StatusResponse.FLOW_RATE_CONTROLLED;
16805
+ txStatusRes.data = {
16806
+ timestamp: flowRatedTx.timestamp.toString(),
16807
+ };
16808
+ }
16809
+ }
16810
+ delete txStatusRes.data.flowRatePromiseIndex;
16811
+ }
16812
+ // Return the tx status response
16813
+ return txStatusResponse;
16596
16814
  }
16597
16815
  /**
16598
16816
  * Queries for the information about which tokens are flowrated and how long the delay is.
@@ -16731,7 +16949,7 @@ const CONTRACTS_FOR_BRIDGE = new Map()
16731
16949
  .set(ETH_SEPOLIA_TO_ZKEVM_TESTNET, {
16732
16950
  rootERC20BridgeFlowRate: '0x0D3C59c779Fd552C27b23F723E80246c840100F5',
16733
16951
  childERC20Bridge: '0x0D3C59c779Fd552C27b23F723E80246c840100F5',
16734
- wrappedIMX: '0xa86C6C6d3D51c0592BE85dA05A9b06B62360D56E',
16952
+ wrappedIMX: '0x1CcCa691501174B4A623CeDA58cC8f1a76dc3439',
16735
16953
  })
16736
16954
  .set(ETH_MAINNET_TO_ZKEVM_MAINNET, {
16737
16955
  rootERC20BridgeFlowRate: '0x0',
@@ -20951,13 +21169,13 @@ var ProtocolData;
20951
21169
  })(ProtocolData.order_type || (ProtocolData.order_type = {}));
20952
21170
  })(ProtocolData || (ProtocolData = {}));
20953
21171
 
20954
- var FeeType;
21172
+ var FeeType$1;
20955
21173
  (function (FeeType) {
20956
21174
  FeeType["MAKER_ECOSYSTEM"] = "MAKER_ECOSYSTEM";
20957
21175
  FeeType["TAKER_ECOSYSTEM"] = "TAKER_ECOSYSTEM";
20958
21176
  FeeType["PROTOCOL"] = "PROTOCOL";
20959
21177
  FeeType["ROYALTY"] = "ROYALTY";
20960
- })(FeeType || (FeeType = {}));
21178
+ })(FeeType$1 || (FeeType$1 = {}));
20961
21179
  var TransactionPurpose;
20962
21180
  (function (TransactionPurpose) {
20963
21181
  TransactionPurpose["APPROVAL"] = "APPROVAL";
@@ -21519,7 +21737,7 @@ class ImmutableApiClient {
21519
21737
  ],
21520
21738
  fees: makerFees.map((x) => ({
21521
21739
  amount: x.amount,
21522
- type: FeeType.MAKER_ECOSYSTEM,
21740
+ type: FeeType$1.MAKER_ECOSYSTEM,
21523
21741
  recipient_address: x.recipientAddress,
21524
21742
  })),
21525
21743
  end_at: new Date(parseInt(`${orderComponents.endTime.toString()}000`, 10)).toISOString(),
@@ -21733,7 +21951,7 @@ class Orderbook {
21733
21951
  order_id: listingId,
21734
21952
  fees: takerFees.map((fee) => ({
21735
21953
  amount: fee.amount,
21736
- type: FeeType.TAKER_ECOSYSTEM,
21954
+ type: FeeType$1.TAKER_ECOSYSTEM,
21737
21955
  recipient_address: fee.recipientAddress,
21738
21956
  })),
21739
21957
  },
@@ -21756,7 +21974,7 @@ class Orderbook {
21756
21974
  order_id: listingRequest.listingId,
21757
21975
  fees: listingRequest.takerFees.map((fee) => ({
21758
21976
  amount: fee.amount,
21759
- type: FeeType.TAKER_ECOSYSTEM,
21977
+ type: FeeType$1.TAKER_ECOSYSTEM,
21760
21978
  recipient_address: fee.recipientAddress,
21761
21979
  })),
21762
21980
  })));
@@ -25833,7 +26051,7 @@ class APIError extends Error {
25833
26051
 
25834
26052
  /* eslint-disable implicit-arrow-linebreak */
25835
26053
  const defaultHeaders = {
25836
- sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.36.4',
26054
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.37.0',
25837
26055
  };
25838
26056
  /**
25839
26057
  * createAPIConfiguration to create a custom Configuration
@@ -26552,6 +26770,21 @@ var RoutingOutcomeType;
26552
26770
  RoutingOutcomeType["NO_ROUTES_FOUND"] = "NO_ROUTES_FOUND";
26553
26771
  RoutingOutcomeType["NO_ROUTE_OPTIONS"] = "NO_ROUTE_OPTIONS";
26554
26772
  })(RoutingOutcomeType || (RoutingOutcomeType = {}));
26773
+ /**
26774
+ * An enum representing the funding step types
26775
+ * @enum {string}
26776
+ * @property {string} GAS - If the fee is a gas fee.
26777
+ * @property {string} BRIDGE_FEE - If the fee is a bridge fee.
26778
+ * @property {string} SWAP_FEE - If the fee is a swap fee.
26779
+ * @property {string} IMMUTABLE_FEE - If the fee is an immutable fee.
26780
+ */
26781
+ var FeeType;
26782
+ (function (FeeType) {
26783
+ FeeType["GAS"] = "GAS";
26784
+ FeeType["BRIDGE_FEE"] = "BRIDGE_FEE";
26785
+ FeeType["SWAP_FEE"] = "SWAP_FEE";
26786
+ FeeType["IMMUTABLE_FEE"] = "IMMUTABLE_FEE";
26787
+ })(FeeType || (FeeType = {}));
26555
26788
  /**
26556
26789
  * An enum representing the funding step types
26557
26790
  * @enum {string}
@@ -27157,7 +27390,7 @@ const GAS_OVERRIDES = {
27157
27390
  maxPriorityFeePerGas: BigNumber$1.from(101e9),
27158
27391
  };
27159
27392
 
27160
- const SDK_VERSION_MARKER = '0.36.4';
27393
+ const SDK_VERSION_MARKER = '0.37.0';
27161
27394
  // This SDK version is replaced by the `yarn build` command ran on the root level
27162
27395
  const globalPackageVersion = () => SDK_VERSION_MARKER;
27163
27396
 
@@ -28051,8 +28284,8 @@ const erc20ItemAggregator = (itemRequirements) => {
28051
28284
  aggregatedItemRequirements.push(itemRequirement);
28052
28285
  return;
28053
28286
  }
28054
- const { contractAddress, spenderAddress, amount } = itemRequirement;
28055
- const key = `${contractAddress}${spenderAddress}`;
28287
+ const { tokenAddress, spenderAddress, amount } = itemRequirement;
28288
+ const key = `${tokenAddress}${spenderAddress}`;
28056
28289
  const aggregateItem = aggregatedMap.get(key);
28057
28290
  if (aggregateItem && aggregateItem.type === ItemType.ERC20) {
28058
28291
  aggregateItem.amount = BigNumber$1.from(aggregateItem.amount).add(amount);
@@ -28118,10 +28351,10 @@ const hasERC20Allowances = async (provider, ownerAddress, itemRequirements) => {
28118
28351
  for (const itemRequirement of itemRequirements) {
28119
28352
  if (itemRequirement.type !== ItemType.ERC20)
28120
28353
  continue;
28121
- const { contractAddress, spenderAddress } = itemRequirement;
28122
- const key = `${contractAddress}${spenderAddress}`;
28354
+ const { tokenAddress, spenderAddress } = itemRequirement;
28355
+ const key = `${tokenAddress}${spenderAddress}`;
28123
28356
  erc20s.set(key, itemRequirement);
28124
- allowancePromises.set(key, getERC20Allowance(provider, ownerAddress, contractAddress, spenderAddress));
28357
+ allowancePromises.set(key, getERC20Allowance(provider, ownerAddress, tokenAddress, spenderAddress));
28125
28358
  }
28126
28359
  const allowances = await Promise.all(allowancePromises.values());
28127
28360
  const allowancePromiseIds = Array.from(allowancePromises.keys());
@@ -28140,8 +28373,8 @@ const hasERC20Allowances = async (provider, ownerAddress, itemRequirements) => {
28140
28373
  continue;
28141
28374
  }
28142
28375
  sufficient = false; // Set sufficient false on the root of the return object when an ERC20 is insufficient
28143
- const { contractAddress, spenderAddress } = itemRequirement;
28144
- const key = `${contractAddress}${spenderAddress}`;
28376
+ const { tokenAddress, spenderAddress } = itemRequirement;
28377
+ const key = `${tokenAddress}${spenderAddress}`;
28145
28378
  const delta = itemRequirement.amount.sub(allowances[index]);
28146
28379
  // Create maps for both the insufficient ERC20 data and the transaction promises using the same key so the results can be merged
28147
28380
  insufficientERC20s.set(key, {
@@ -28151,7 +28384,7 @@ const hasERC20Allowances = async (provider, ownerAddress, itemRequirements) => {
28151
28384
  itemRequirement,
28152
28385
  approvalTransaction: undefined,
28153
28386
  });
28154
- transactionPromises.set(key, getERC20ApprovalTransaction(provider, ownerAddress, contractAddress, spenderAddress, delta));
28387
+ transactionPromises.set(key, getERC20ApprovalTransaction(provider, ownerAddress, tokenAddress, spenderAddress, delta));
28155
28388
  }
28156
28389
  // Resolves the approval transactions and merges them with the insufficient ERC20 data
28157
28390
  const transactions = await Promise.all(transactionPromises.values());
@@ -28336,8 +28569,8 @@ const erc20BalanceAggregator = (itemRequirements) => {
28336
28569
  aggregatedItemRequirements.push(itemRequirement);
28337
28570
  return;
28338
28571
  }
28339
- const { contractAddress, amount } = itemRequirement;
28340
- const key = `${contractAddress}`;
28572
+ const { tokenAddress, amount } = itemRequirement;
28573
+ const key = `${tokenAddress}`;
28341
28574
  const aggregateItem = aggregatedMap.get(key);
28342
28575
  if (aggregateItem && aggregateItem.type === ItemType.ERC20) {
28343
28576
  aggregateItem.amount = BigNumber$1.from(aggregateItem.amount).add(amount);
@@ -28370,14 +28603,21 @@ const balanceAggregator = (itemRequirements) => erc721BalanceAggregator(erc20Bal
28370
28603
  /* eslint-disable arrow-body-style */
28371
28604
  const getTokensFromRequirements = (itemRequirements) => itemRequirements
28372
28605
  .map((itemRequirement) => {
28373
- if (itemRequirement.type === ItemType.NATIVE) {
28374
- return {
28375
- address: NATIVE,
28376
- };
28606
+ switch (itemRequirement.type) {
28607
+ case ItemType.ERC20:
28608
+ return {
28609
+ address: itemRequirement.tokenAddress,
28610
+ };
28611
+ case ItemType.NATIVE:
28612
+ return {
28613
+ address: NATIVE,
28614
+ };
28615
+ case ItemType.ERC721:
28616
+ default:
28617
+ return {
28618
+ address: itemRequirement.contractAddress,
28619
+ };
28377
28620
  }
28378
- return {
28379
- address: itemRequirement.contractAddress,
28380
- };
28381
28621
  });
28382
28622
  /**
28383
28623
  * Gets the balance requirement with delta for an ERC721 requirement.
@@ -28427,7 +28667,7 @@ const getTokenBalanceRequirement = (itemRequirement, balances) => {
28427
28667
  // Get the requirements related balance
28428
28668
  if (itemRequirement.type === ItemType.ERC20) {
28429
28669
  itemBalanceResult = balances.find((balance) => {
28430
- return balance.token?.address === itemRequirement.contractAddress;
28670
+ return balance.token?.address === itemRequirement.tokenAddress;
28431
28671
  });
28432
28672
  }
28433
28673
  else if (itemRequirement.type === ItemType.NATIVE) {
@@ -28491,7 +28731,7 @@ const getTokenBalanceRequirement = (itemRequirement, balances) => {
28491
28731
  token: {
28492
28732
  name,
28493
28733
  symbol,
28494
- address: itemRequirement.contractAddress,
28734
+ address: itemRequirement.tokenAddress,
28495
28735
  decimals,
28496
28736
  },
28497
28737
  };
@@ -28650,7 +28890,7 @@ const getGasItemRequirement = (gas, transactionOrGas) => {
28650
28890
  return {
28651
28891
  type: ItemType.ERC20,
28652
28892
  amount: gas,
28653
- contractAddress: transactionOrGas.gasToken.contractAddress,
28893
+ tokenAddress: transactionOrGas.gasToken.tokenAddress,
28654
28894
  spenderAddress: '',
28655
28895
  };
28656
28896
  };
@@ -28873,36 +29113,37 @@ const quoteFetcher = async (config, chainId, walletAddress, requiredToken, swapp
28873
29113
  }
28874
29114
  };
28875
29115
 
28876
- const constructFees$1 = (approvalGasFees, swapGasFees, swapFees) => {
29116
+ const constructFees$1 = (approvalGasFee, swapGasFee, swapFees) => {
28877
29117
  let approvalGasFeeAmount = BigNumber$1.from(0);
28878
29118
  let approvalGasFeeFormatted = '0';
28879
29119
  let approvalToken;
28880
- if (approvalGasFees) {
28881
- approvalGasFeeAmount = approvalGasFees.value;
28882
- approvalGasFeeFormatted = utils$1.formatUnits(approvalGasFees.value, approvalGasFees.token.decimals);
29120
+ if (approvalGasFee) {
29121
+ approvalGasFeeAmount = approvalGasFee.value;
29122
+ approvalGasFeeFormatted = utils$1.formatUnits(approvalGasFee.value, approvalGasFee.token.decimals);
28883
29123
  approvalToken = {
28884
- name: approvalGasFees.token.name ?? '',
28885
- symbol: approvalGasFees.token.symbol ?? '',
28886
- address: approvalGasFees.token.address,
28887
- decimals: approvalGasFees.token.decimals,
29124
+ name: approvalGasFee.token.name ?? '',
29125
+ symbol: approvalGasFee.token.symbol ?? '',
29126
+ address: approvalGasFee.token.address,
29127
+ decimals: approvalGasFee.token.decimals,
28888
29128
  };
28889
29129
  }
28890
29130
  let swapGasFeeAmount = BigNumber$1.from(0);
28891
29131
  let swapGasFeeFormatted = '0';
28892
29132
  let swapGasToken;
28893
- if (swapGasFees) {
28894
- swapGasFeeAmount = swapGasFees.value;
28895
- swapGasFeeFormatted = utils$1.formatUnits(swapGasFees.value, swapGasFees.token.decimals);
29133
+ if (swapGasFee) {
29134
+ swapGasFeeAmount = swapGasFee.value;
29135
+ swapGasFeeFormatted = utils$1.formatUnits(swapGasFee.value, swapGasFee.token.decimals);
28896
29136
  swapGasToken = {
28897
- name: swapGasFees.token.name ?? '',
28898
- symbol: swapGasFees.token.symbol ?? '',
28899
- address: swapGasFees.token.address,
28900
- decimals: swapGasFees.token.decimals,
29137
+ name: swapGasFee.token.name ?? '',
29138
+ symbol: swapGasFee.token.symbol ?? '',
29139
+ address: swapGasFee.token.address,
29140
+ decimals: swapGasFee.token.decimals,
28901
29141
  };
28902
29142
  }
28903
29143
  const fees = [];
28904
29144
  for (const swapFee of swapFees) {
28905
29145
  fees.push({
29146
+ type: FeeType.SWAP_FEE,
28906
29147
  amount: swapFee.amount.value,
28907
29148
  formattedAmount: utils$1.formatUnits(swapFee.amount.value, swapFee.amount.token.decimals),
28908
29149
  token: {
@@ -28914,12 +29155,14 @@ const constructFees$1 = (approvalGasFees, swapGasFees, swapFees) => {
28914
29155
  });
28915
29156
  }
28916
29157
  return {
28917
- approvalGasFees: {
29158
+ approvalGasFee: {
29159
+ type: FeeType.GAS,
28918
29160
  amount: approvalGasFeeAmount,
28919
29161
  formattedAmount: approvalGasFeeFormatted,
28920
29162
  token: approvalToken,
28921
29163
  },
28922
- swapGasFees: {
29164
+ swapGasFee: {
29165
+ type: FeeType.GAS,
28923
29166
  amount: swapGasFeeAmount,
28924
29167
  formattedAmount: swapGasFeeFormatted,
28925
29168
  token: swapGasToken,
@@ -29004,7 +29247,7 @@ const checkUserCanCoverApprovalFees = (l2Balances, approval) => {
29004
29247
  // The user has enough to cover approval gas fees
29005
29248
  return { sufficient: true, approvalGasFee, approvalGasTokenAddress };
29006
29249
  };
29007
- const checkUserCanCoverSwapFees = (l2Balances, approvalFees, swapGasFees, swapFees, tokenBeingSwapped) => {
29250
+ const checkUserCanCoverSwapFees = (l2Balances, approvalFees, swapGasFee, swapFees, tokenBeingSwapped) => {
29008
29251
  // Set up a map of token addresses to amounts for each of the swap fees
29009
29252
  const feeMap = new Map();
29010
29253
  // Add the approval fee to list of fees
@@ -29012,13 +29255,13 @@ const checkUserCanCoverSwapFees = (l2Balances, approvalFees, swapGasFees, swapFe
29012
29255
  feeMap.set(approvalFees.approvalGasTokenAddress, approvalFees.approvalGasFee);
29013
29256
  }
29014
29257
  // Add the swap gas fee to list of fees
29015
- if (swapGasFees) {
29016
- const fee = feeMap.get(swapGasFees.token.address);
29258
+ if (swapGasFee) {
29259
+ const fee = feeMap.get(swapGasFee.token.address);
29017
29260
  if (fee) {
29018
- feeMap.set(swapGasFees.token.address, fee.add(swapGasFees.value));
29261
+ feeMap.set(swapGasFee.token.address, fee.add(swapGasFee.value));
29019
29262
  }
29020
29263
  else {
29021
- feeMap.set(swapGasFees.token.address, swapGasFees.value);
29264
+ feeMap.set(swapGasFee.token.address, swapGasFee.value);
29022
29265
  }
29023
29266
  }
29024
29267
  // Add the token being swapped to list of fees to ensure the user can cover the fee + the token swap
@@ -29272,31 +29515,39 @@ const hasSufficientL1Eth = (tokenBalanceResult, totalFees) => {
29272
29515
  const balance = getEthBalance(tokenBalanceResult);
29273
29516
  return balance.gte(totalFees);
29274
29517
  };
29275
- const constructFees = (bridgeGasFees, bridgeFee, imtblFee, approvalGasFees, token) => {
29518
+ const constructFees = (bridgeGasFee, bridgeFee, imtblFee, approvalGasFee, token) => {
29276
29519
  const bridgeFeeDecimals = token?.decimals ?? DEFAULT_TOKEN_DECIMALS$1;
29520
+ const bridgeFees = [];
29521
+ if (bridgeFee.gt(0)) {
29522
+ bridgeFees.push({
29523
+ type: FeeType.BRIDGE_FEE,
29524
+ amount: bridgeFee,
29525
+ formattedAmount: utils$1.formatUnits(bridgeFee, bridgeFeeDecimals),
29526
+ token,
29527
+ });
29528
+ }
29529
+ if (imtblFee.gt(0)) {
29530
+ bridgeFees.push({
29531
+ type: FeeType.IMMUTABLE_FEE,
29532
+ amount: imtblFee,
29533
+ formattedAmount: utils$1.formatUnits(imtblFee, bridgeFeeDecimals),
29534
+ token,
29535
+ });
29536
+ }
29277
29537
  return {
29278
- approvalGasFees: {
29279
- amount: approvalGasFees,
29280
- formattedAmount: utils$1.formatUnits(approvalGasFees, DEFAULT_TOKEN_DECIMALS$1),
29538
+ approvalGasFee: {
29539
+ type: FeeType.GAS,
29540
+ amount: approvalGasFee,
29541
+ formattedAmount: utils$1.formatUnits(approvalGasFee, DEFAULT_TOKEN_DECIMALS$1),
29281
29542
  token,
29282
29543
  },
29283
- bridgeGasFees: {
29284
- amount: bridgeGasFees,
29285
- formattedAmount: utils$1.formatUnits(bridgeGasFees, DEFAULT_TOKEN_DECIMALS$1),
29544
+ bridgeGasFee: {
29545
+ type: FeeType.GAS,
29546
+ amount: bridgeGasFee,
29547
+ formattedAmount: utils$1.formatUnits(bridgeGasFee, DEFAULT_TOKEN_DECIMALS$1),
29286
29548
  token,
29287
29549
  },
29288
- bridgeFees: [
29289
- {
29290
- amount: bridgeFee,
29291
- formattedAmount: utils$1.formatUnits(bridgeFee, bridgeFeeDecimals),
29292
- token,
29293
- },
29294
- {
29295
- amount: imtblFee,
29296
- formattedAmount: utils$1.formatUnits(imtblFee, bridgeFeeDecimals),
29297
- token,
29298
- },
29299
- ],
29550
+ bridgeFees,
29300
29551
  };
29301
29552
  };
29302
29553
  const constructBridgeFundingRoute = (chainId, balance, bridgeRequirement, itemType, fees) => ({
@@ -30155,13 +30406,13 @@ const calculateFees = (orderFees, weiAmount, decimals = 18) => {
30155
30406
  return calculateFeesResult;
30156
30407
  };
30157
30408
 
30158
- const getItemRequirement = (type, contractAddress, amount, spenderAddress) => {
30409
+ const getItemRequirement = (type, tokenAddress, amount, spenderAddress) => {
30159
30410
  switch (type) {
30160
30411
  case ItemType.ERC20:
30161
30412
  return {
30162
30413
  type,
30163
30414
  amount,
30164
- contractAddress,
30415
+ tokenAddress,
30165
30416
  spenderAddress,
30166
30417
  };
30167
30418
  case ItemType.NATIVE:
@@ -30384,7 +30635,7 @@ const getBuyToken = (buyToken, decimals = 18) => {
30384
30635
  return {
30385
30636
  type: ItemType.ERC20,
30386
30637
  amount: bnAmount.toString(),
30387
- contractAddress: buyToken.contractAddress,
30638
+ contractAddress: buyToken.tokenAddress,
30388
30639
  };
30389
30640
  };
30390
30641
  const sell = async (config, provider, orders) => {
@@ -30398,7 +30649,7 @@ const sell = async (config, provider, orders) => {
30398
30649
  let decimals = 18;
30399
30650
  if (buyToken.type === ItemType.ERC20) {
30400
30651
  // get this from the allowed list
30401
- const buyTokenContract = new Contract$1(buyToken.contractAddress, JSON.stringify(ERC20ABI), provider);
30652
+ const buyTokenContract = new Contract$1(buyToken.tokenAddress, JSON.stringify(ERC20ABI), provider);
30402
30653
  decimals = await measureAsyncExecution(config, 'Time to get decimals of token contract for the buy token', buyTokenContract.decimals());
30403
30654
  }
30404
30655
  const buyTokenOrNative = getBuyToken(buyToken, decimals);
@@ -30550,8 +30801,8 @@ async function getItemRequirementsFromRequirements(provider, requirements) {
30550
30801
  const decimalPromises = [];
30551
30802
  requirements.forEach((itemRequirementParam) => {
30552
30803
  if (itemRequirementParam.type === ItemType.ERC20) {
30553
- const { contractAddress } = itemRequirementParam;
30554
- decimalPromises.push(getTokenContract(contractAddress, ERC20ABI, provider).decimals());
30804
+ const { tokenAddress } = itemRequirementParam;
30805
+ decimalPromises.push(getTokenContract(tokenAddress, ERC20ABI, provider).decimals());
30555
30806
  }
30556
30807
  });
30557
30808
  const decimals = await Promise.all(decimalPromises);
@@ -30866,7 +31117,7 @@ class Checkout {
30866
31117
  try {
30867
31118
  itemRequirements = await getItemRequirementsFromRequirements(web3Provider, params.itemRequirements);
30868
31119
  }
30869
- catch {
31120
+ catch (error) {
30870
31121
  throw new CheckoutError('Failed to map item requirements', CheckoutErrorType.ITEM_REQUIREMENTS_ERROR);
30871
31122
  }
30872
31123
  return await smartCheckout(this.config, web3Provider, itemRequirements, params.transactionOrGasAmount);
@@ -30934,4 +31185,4 @@ class Checkout {
30934
31185
  }
30935
31186
  }
30936
31187
 
30937
- 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 };
31188
+ 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 };