@imtbl/sdk 0.4.1-alpha.1 → 0.4.2-alpha.1

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/index.js CHANGED
@@ -20,7 +20,7 @@ import { BigNumber as BigNumber$2 } from '@ethersproject/bignumber';
20
20
  import detectEthereumProvider from '@metamask/detect-provider';
21
21
  import { Token, TradeType, CurrencyAmount, Percent } from '@uniswap/sdk-core';
22
22
  import assert from 'assert';
23
- import { FeeAmount, Route, SwapQuoter, Pool, Trade } from '@uniswap/v3-sdk';
23
+ import { FeeAmount, Route, SwapQuoter, Pool, Trade, toHex as toHex$1, encodeRouteToPath } from '@uniswap/v3-sdk';
24
24
  import JSBI from 'jsbi';
25
25
  import { keccak256 as keccak256$1 } from '@ethersproject/solidity';
26
26
  import { SwapRouter } from '@uniswap/router-sdk';
@@ -3340,7 +3340,7 @@ let Configuration$1 = class Configuration {
3340
3340
  /* tslint:disable */
3341
3341
  /* eslint-disable */
3342
3342
  /**
3343
- * Immutable X API
3343
+ * Immutable zkEVM API
3344
3344
  * Immutable Multi Rollup API
3345
3345
  *
3346
3346
  * The version of the OpenAPI document: 1.0.0
@@ -3352,7 +3352,7 @@ let Configuration$1 = class Configuration {
3352
3352
  */
3353
3353
  // Some imports not used depending on template conditions
3354
3354
  // @ts-ignore
3355
- const BASE_PATH$1 = "https://indexer-mr.sandbox.imtbl.com".replace(/\/+$/, "");
3355
+ const BASE_PATH$1 = "https://api.sandbox.immutable.com".replace(/\/+$/, "");
3356
3356
  /**
3357
3357
  *
3358
3358
  * @export
@@ -3389,7 +3389,7 @@ let RequiredError$1 = class RequiredError extends Error {
3389
3389
  /* tslint:disable */
3390
3390
  /* eslint-disable */
3391
3391
  /**
3392
- * Immutable X API
3392
+ * Immutable zkEVM API
3393
3393
  * Immutable Multi Rollup API
3394
3394
  *
3395
3395
  * The version of the OpenAPI document: 1.0.0
@@ -3487,7 +3487,7 @@ const createRequestFunction$1 = function (axiosArgs, globalAxios, BASE_PATH, con
3487
3487
  /* tslint:disable */
3488
3488
  /* eslint-disable */
3489
3489
  /**
3490
- * Immutable X API
3490
+ * Immutable zkEVM API
3491
3491
  * Immutable Multi Rollup API
3492
3492
  *
3493
3493
  * The version of the OpenAPI document: 1.0.0
@@ -3721,7 +3721,7 @@ class ActivitiesApi extends BaseAPI$1 {
3721
3721
  /* tslint:disable */
3722
3722
  /* eslint-disable */
3723
3723
  /**
3724
- * Immutable X API
3724
+ * Immutable zkEVM API
3725
3725
  * Immutable Multi Rollup API
3726
3726
  *
3727
3727
  * The version of the OpenAPI document: 1.0.0
@@ -3836,7 +3836,7 @@ class ChainsApi extends BaseAPI$1 {
3836
3836
  /* tslint:disable */
3837
3837
  /* eslint-disable */
3838
3838
  /**
3839
- * Immutable X API
3839
+ * Immutable zkEVM API
3840
3840
  * Immutable Multi Rollup API
3841
3841
  *
3842
3842
  * The version of the OpenAPI document: 1.0.0
@@ -4024,7 +4024,7 @@ class CollectionsApi extends BaseAPI$1 {
4024
4024
  /* tslint:disable */
4025
4025
  /* eslint-disable */
4026
4026
  /**
4027
- * Immutable X API
4027
+ * Immutable zkEVM API
4028
4028
  * Immutable Multi Rollup API
4029
4029
  *
4030
4030
  * The version of the OpenAPI document: 1.0.0
@@ -4157,7 +4157,7 @@ class NftOwnersApi extends BaseAPI$1 {
4157
4157
  /* tslint:disable */
4158
4158
  /* eslint-disable */
4159
4159
  /**
4160
- * Immutable X API
4160
+ * Immutable zkEVM API
4161
4161
  * Immutable Multi Rollup API
4162
4162
  *
4163
4163
  * The version of the OpenAPI document: 1.0.0
@@ -4442,7 +4442,7 @@ class NftsApi extends BaseAPI$1 {
4442
4442
  /* tslint:disable */
4443
4443
  /* eslint-disable */
4444
4444
  /**
4445
- * Immutable X API
4445
+ * Immutable zkEVM API
4446
4446
  * Immutable Multi Rollup API
4447
4447
  *
4448
4448
  * The version of the OpenAPI document: 1.0.0
@@ -4734,7 +4734,7 @@ class OrdersApi extends BaseAPI$1 {
4734
4734
  /* tslint:disable */
4735
4735
  /* eslint-disable */
4736
4736
  /**
4737
- * Immutable X API
4737
+ * Immutable zkEVM API
4738
4738
  * Immutable Multi Rollup API
4739
4739
  *
4740
4740
  * The version of the OpenAPI document: 1.0.0
@@ -4847,7 +4847,7 @@ class PassportApi extends BaseAPI$1 {
4847
4847
  /* tslint:disable */
4848
4848
  /* eslint-disable */
4849
4849
  /**
4850
- * Immutable X API
4850
+ * Immutable zkEVM API
4851
4851
  * Immutable Multi Rollup API
4852
4852
  *
4853
4853
  * The version of the OpenAPI document: 1.0.0
@@ -5035,7 +5035,7 @@ class TokensApi extends BaseAPI$1 {
5035
5035
  /* tslint:disable */
5036
5036
  /* eslint-disable */
5037
5037
  /**
5038
- * Immutable X API
5038
+ * Immutable zkEVM API
5039
5039
  * Immutable Multi Rollup API
5040
5040
  *
5041
5041
  * The version of the OpenAPI document: 1.0.0
@@ -5123,7 +5123,7 @@ let Configuration$2 = class Configuration {
5123
5123
  /* tslint:disable */
5124
5124
  /* eslint-disable */
5125
5125
  /**
5126
- * Immutable X API
5126
+ * Immutable zkEVM API
5127
5127
  * Immutable Multi Rollup API
5128
5128
  *
5129
5129
  * The version of the OpenAPI document: 1.0.0
@@ -5140,7 +5140,7 @@ const APIError400AllOfCodeEnum = {
5140
5140
  /* tslint:disable */
5141
5141
  /* eslint-disable */
5142
5142
  /**
5143
- * Immutable X API
5143
+ * Immutable zkEVM API
5144
5144
  * Immutable Multi Rollup API
5145
5145
  *
5146
5146
  * The version of the OpenAPI document: 1.0.0
@@ -5157,7 +5157,7 @@ const APIError401AllOfCodeEnum = {
5157
5157
  /* tslint:disable */
5158
5158
  /* eslint-disable */
5159
5159
  /**
5160
- * Immutable X API
5160
+ * Immutable zkEVM API
5161
5161
  * Immutable Multi Rollup API
5162
5162
  *
5163
5163
  * The version of the OpenAPI document: 1.0.0
@@ -5174,7 +5174,7 @@ const APIError403AllOfCodeEnum = {
5174
5174
  /* tslint:disable */
5175
5175
  /* eslint-disable */
5176
5176
  /**
5177
- * Immutable X API
5177
+ * Immutable zkEVM API
5178
5178
  * Immutable Multi Rollup API
5179
5179
  *
5180
5180
  * The version of the OpenAPI document: 1.0.0
@@ -5191,7 +5191,7 @@ const APIError404AllOfCodeEnum = {
5191
5191
  /* tslint:disable */
5192
5192
  /* eslint-disable */
5193
5193
  /**
5194
- * Immutable X API
5194
+ * Immutable zkEVM API
5195
5195
  * Immutable Multi Rollup API
5196
5196
  *
5197
5197
  * The version of the OpenAPI document: 1.0.0
@@ -5208,7 +5208,7 @@ const APIError429AllOfCodeEnum = {
5208
5208
  /* tslint:disable */
5209
5209
  /* eslint-disable */
5210
5210
  /**
5211
- * Immutable X API
5211
+ * Immutable zkEVM API
5212
5212
  * Immutable Multi Rollup API
5213
5213
  *
5214
5214
  * The version of the OpenAPI document: 1.0.0
@@ -5225,7 +5225,7 @@ const APIError500AllOfCodeEnum = {
5225
5225
  /* tslint:disable */
5226
5226
  /* eslint-disable */
5227
5227
  /**
5228
- * Immutable X API
5228
+ * Immutable zkEVM API
5229
5229
  * Immutable Multi Rollup API
5230
5230
  *
5231
5231
  * The version of the OpenAPI document: 1.0.0
@@ -5244,13 +5244,15 @@ const ActivityType = {
5244
5244
  Mint: 'mint',
5245
5245
  Burn: 'burn',
5246
5246
  Transfer: 'transfer',
5247
- Sale: 'sale'
5247
+ Sale: 'sale',
5248
+ Deposit: 'deposit',
5249
+ Withdrawal: 'withdrawal'
5248
5250
  };
5249
5251
 
5250
5252
  /* tslint:disable */
5251
5253
  /* eslint-disable */
5252
5254
  /**
5253
- * Immutable X API
5255
+ * Immutable zkEVM API
5254
5256
  * Immutable Multi Rollup API
5255
5257
  *
5256
5258
  * The version of the OpenAPI document: 1.0.0
@@ -5272,7 +5274,7 @@ const CollectionContractType = {
5272
5274
  /* tslint:disable */
5273
5275
  /* eslint-disable */
5274
5276
  /**
5275
- * Immutable X API
5277
+ * Immutable zkEVM API
5276
5278
  * Immutable Multi Rollup API
5277
5279
  *
5278
5280
  * The version of the OpenAPI document: 1.0.0
@@ -5289,7 +5291,7 @@ const CreateOrderProtocolDataOrderTypeEnum = {
5289
5291
  /* tslint:disable */
5290
5292
  /* eslint-disable */
5291
5293
  /**
5292
- * Immutable X API
5294
+ * Immutable zkEVM API
5293
5295
  * Immutable Multi Rollup API
5294
5296
  *
5295
5297
  * The version of the OpenAPI document: 1.0.0
@@ -5306,7 +5308,7 @@ const ERC20ItemItemTypeEnum = {
5306
5308
  /* tslint:disable */
5307
5309
  /* eslint-disable */
5308
5310
  /**
5309
- * Immutable X API
5311
+ * Immutable zkEVM API
5310
5312
  * Immutable Multi Rollup API
5311
5313
  *
5312
5314
  * The version of the OpenAPI document: 1.0.0
@@ -5323,7 +5325,7 @@ const ERC721ItemItemTypeEnum = {
5323
5325
  /* tslint:disable */
5324
5326
  /* eslint-disable */
5325
5327
  /**
5326
- * Immutable X API
5328
+ * Immutable zkEVM API
5327
5329
  * Immutable Multi Rollup API
5328
5330
  *
5329
5331
  * The version of the OpenAPI document: 1.0.0
@@ -5340,7 +5342,7 @@ const FeeFeeTypeEnum = {
5340
5342
  /* tslint:disable */
5341
5343
  /* eslint-disable */
5342
5344
  /**
5343
- * Immutable X API
5345
+ * Immutable zkEVM API
5344
5346
  * Immutable Multi Rollup API
5345
5347
  *
5346
5348
  * The version of the OpenAPI document: 1.0.0
@@ -5362,7 +5364,7 @@ const NFTContractType = {
5362
5364
  /* tslint:disable */
5363
5365
  /* eslint-disable */
5364
5366
  /**
5365
- * Immutable X API
5367
+ * Immutable zkEVM API
5366
5368
  * Immutable Multi Rollup API
5367
5369
  *
5368
5370
  * The version of the OpenAPI document: 1.0.0
@@ -5379,7 +5381,7 @@ const NativeItemItemTypeEnum = {
5379
5381
  /* tslint:disable */
5380
5382
  /* eslint-disable */
5381
5383
  /**
5382
- * Immutable X API
5384
+ * Immutable zkEVM API
5383
5385
  * Immutable Multi Rollup API
5384
5386
  *
5385
5387
  * The version of the OpenAPI document: 1.0.0
@@ -5406,7 +5408,7 @@ const OrderStatus$1 = {
5406
5408
  /* tslint:disable */
5407
5409
  /* eslint-disable */
5408
5410
  /**
5409
- * Immutable X API
5411
+ * Immutable zkEVM API
5410
5412
  * Immutable Multi Rollup API
5411
5413
  *
5412
5414
  * The version of the OpenAPI document: 1.0.0
@@ -5423,7 +5425,7 @@ const SaleFeeTypeEnum = {
5423
5425
  /* tslint:disable */
5424
5426
  /* eslint-disable */
5425
5427
  /**
5426
- * Immutable X API
5428
+ * Immutable zkEVM API
5427
5429
  * Immutable Multi Rollup API
5428
5430
  *
5429
5431
  * The version of the OpenAPI document: 1.0.0
@@ -5445,7 +5447,7 @@ const TokenContractType = {
5445
5447
  /* tslint:disable */
5446
5448
  /* eslint-disable */
5447
5449
  /**
5448
- * Immutable X API
5450
+ * Immutable zkEVM API
5449
5451
  * Immutable Multi Rollup API
5450
5452
  *
5451
5453
  * The version of the OpenAPI document: 1.0.0
@@ -5532,7 +5534,7 @@ class MultiRollupApiClients {
5532
5534
  }
5533
5535
 
5534
5536
  // eslint-disable-next-line @typescript-eslint/naming-convention
5535
- const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.4.1-alpha.1' };
5537
+ const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.4.2-alpha.1' };
5536
5538
  const createConfig = ({ basePath, headers, }) => {
5537
5539
  if (!basePath.trim()) {
5538
5540
  throw Error('basePath can not be empty');
@@ -5592,7 +5594,7 @@ class APIError extends Error {
5592
5594
 
5593
5595
  /* eslint-disable implicit-arrow-linebreak */
5594
5596
  const defaultHeaders = {
5595
- sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.4.1-alpha.1',
5597
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.4.2-alpha.1',
5596
5598
  };
5597
5599
  /**
5598
5600
  * createAPIConfiguration to create a custom Configuration
@@ -5858,7 +5860,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
5858
5860
  chainID,
5859
5861
  coreContractAddress,
5860
5862
  registrationContractAddress,
5861
- sdkVersion: 'ts-immutable-sdk-0.4.1-alpha.1',
5863
+ sdkVersion: 'ts-immutable-sdk-0.4.2-alpha.1',
5862
5864
  });
5863
5865
  /**
5864
5866
  * Sets `sdkVersion` at the time of build
@@ -11289,7 +11291,7 @@ class PassportConfiguration {
11289
11291
  this.magicProviderId = 'fSMzaRQ4O7p4fttl7pCyGVtJS_G70P8SNsLXtPPGHo0=';
11290
11292
  this.passportDomain = 'https://passport.sandbox.immutable.com';
11291
11293
  this.imxPublicApiDomain = 'https://api.sandbox.immutable.com';
11292
- this.zkEvmRpcUrl = 'https://zkevm-rpc.sandbox.x.immutable.com';
11294
+ this.zkEvmRpcUrl = 'https://rpc.testnet.immutable.com';
11293
11295
  this.zkEvmChainId = 'eip155:13392';
11294
11296
  this.relayerUrl = 'https://api.sandbox.immutable.com/relayer-mr';
11295
11297
  this.multiRollupConfig = multiRollupConfig.getSandbox();
@@ -11674,7 +11676,7 @@ const chainIdNumber = (chainId) => {
11674
11676
  const MAX_TRANSACTION_HASH_RETRIEVAL_RETRIES = 30;
11675
11677
  const TRANSACTION_HASH_RETRIEVAL_WAIT = 1000;
11676
11678
  const sendTransaction = async ({ params, magicProvider, jsonRpcProvider, relayerClient, guardianClient, config, user, }) => {
11677
- const popupWindowSize = { width: 480, height: 580 };
11679
+ const popupWindowSize = { width: 480, height: 520 };
11678
11680
  guardianClient.loading(popupWindowSize);
11679
11681
  const transactionRequest = params[0];
11680
11682
  if (!transactionRequest.to) {
@@ -12964,7 +12966,7 @@ class ERC721 {
12964
12966
  /* Autogenerated file. Do not edit manually. */
12965
12967
  /* tslint:disable */
12966
12968
  /* eslint-disable */
12967
- const _abi$3 = [
12969
+ const _abi$5 = [
12968
12970
  {
12969
12971
  inputs: [
12970
12972
  {
@@ -13853,12 +13855,12 @@ const _abi$3 = [
13853
13855
  },
13854
13856
  ];
13855
13857
  class ImmutableERC721Base__factory {
13856
- static abi = _abi$3;
13858
+ static abi = _abi$5;
13857
13859
  static createInterface() {
13858
- return new utils$2.Interface(_abi$3);
13860
+ return new utils$2.Interface(_abi$5);
13859
13861
  }
13860
13862
  static connect(address, signerOrProvider) {
13861
- return new Contract$1(address, _abi$3, signerOrProvider);
13863
+ return new Contract$1(address, _abi$5, signerOrProvider);
13862
13864
  }
13863
13865
  }
13864
13866
 
@@ -21066,6 +21068,13 @@ function arrayifyInteger(value) {
21066
21068
  }
21067
21069
  return result;
21068
21070
  }
21071
+ function unarrayifyInteger(data, offset, length) {
21072
+ let result = 0;
21073
+ for (let i = 0; i < length; i++) {
21074
+ result = (result * 256) + data[offset + i];
21075
+ }
21076
+ return result;
21077
+ }
21069
21078
  function _encode(object) {
21070
21079
  if (Array.isArray(object)) {
21071
21080
  let payload = [];
@@ -21098,6 +21107,72 @@ function _encode(object) {
21098
21107
  function encode(object) {
21099
21108
  return hexlify(_encode(object));
21100
21109
  }
21110
+ function _decodeChildren(data, offset, childOffset, length) {
21111
+ const result = [];
21112
+ while (childOffset < offset + 1 + length) {
21113
+ const decoded = _decode(data, childOffset);
21114
+ result.push(decoded.result);
21115
+ childOffset += decoded.consumed;
21116
+ if (childOffset > offset + 1 + length) {
21117
+ logger$9.throwError("child data too short", Logger.errors.BUFFER_OVERRUN, {});
21118
+ }
21119
+ }
21120
+ return { consumed: (1 + length), result: result };
21121
+ }
21122
+ // returns { consumed: number, result: Object }
21123
+ function _decode(data, offset) {
21124
+ if (data.length === 0) {
21125
+ logger$9.throwError("data too short", Logger.errors.BUFFER_OVERRUN, {});
21126
+ }
21127
+ // Array with extra length prefix
21128
+ if (data[offset] >= 0xf8) {
21129
+ const lengthLength = data[offset] - 0xf7;
21130
+ if (offset + 1 + lengthLength > data.length) {
21131
+ logger$9.throwError("data short segment too short", Logger.errors.BUFFER_OVERRUN, {});
21132
+ }
21133
+ const length = unarrayifyInteger(data, offset + 1, lengthLength);
21134
+ if (offset + 1 + lengthLength + length > data.length) {
21135
+ logger$9.throwError("data long segment too short", Logger.errors.BUFFER_OVERRUN, {});
21136
+ }
21137
+ return _decodeChildren(data, offset, offset + 1 + lengthLength, lengthLength + length);
21138
+ }
21139
+ else if (data[offset] >= 0xc0) {
21140
+ const length = data[offset] - 0xc0;
21141
+ if (offset + 1 + length > data.length) {
21142
+ logger$9.throwError("data array too short", Logger.errors.BUFFER_OVERRUN, {});
21143
+ }
21144
+ return _decodeChildren(data, offset, offset + 1, length);
21145
+ }
21146
+ else if (data[offset] >= 0xb8) {
21147
+ const lengthLength = data[offset] - 0xb7;
21148
+ if (offset + 1 + lengthLength > data.length) {
21149
+ logger$9.throwError("data array too short", Logger.errors.BUFFER_OVERRUN, {});
21150
+ }
21151
+ const length = unarrayifyInteger(data, offset + 1, lengthLength);
21152
+ if (offset + 1 + lengthLength + length > data.length) {
21153
+ logger$9.throwError("data array too short", Logger.errors.BUFFER_OVERRUN, {});
21154
+ }
21155
+ const result = hexlify(data.slice(offset + 1 + lengthLength, offset + 1 + lengthLength + length));
21156
+ return { consumed: (1 + lengthLength + length), result: result };
21157
+ }
21158
+ else if (data[offset] >= 0x80) {
21159
+ const length = data[offset] - 0x80;
21160
+ if (offset + 1 + length > data.length) {
21161
+ logger$9.throwError("data too short", Logger.errors.BUFFER_OVERRUN, {});
21162
+ }
21163
+ const result = hexlify(data.slice(offset + 1, offset + 1 + length));
21164
+ return { consumed: (1 + length), result: result };
21165
+ }
21166
+ return { consumed: 1, result: hexlify(data[offset]) };
21167
+ }
21168
+ function decode(data) {
21169
+ const bytes = arrayify(data);
21170
+ const decoded = _decode(bytes, 0);
21171
+ if (decoded.consumed !== bytes.length) {
21172
+ logger$9.throwArgumentError("invalid rlp data", "data", data);
21173
+ }
21174
+ return decoded.result;
21175
+ }
21101
21176
 
21102
21177
  const version$5 = "address/5.7.0";
21103
21178
 
@@ -23964,6 +24039,19 @@ const ROOT_ERC20_PREDICATE = [
23964
24039
  stateMutability: 'view',
23965
24040
  type: 'function',
23966
24041
  },
24042
+ {
24043
+ inputs: [],
24044
+ name: 'NATIVE_TOKEN',
24045
+ outputs: [
24046
+ {
24047
+ internalType: 'address',
24048
+ name: '',
24049
+ type: 'address',
24050
+ },
24051
+ ],
24052
+ stateMutability: 'view',
24053
+ type: 'function',
24054
+ },
23967
24055
  {
23968
24056
  inputs: [],
23969
24057
  name: 'WITHDRAW_SIG',
@@ -24021,6 +24109,19 @@ const ROOT_ERC20_PREDICATE = [
24021
24109
  stateMutability: 'nonpayable',
24022
24110
  type: 'function',
24023
24111
  },
24112
+ {
24113
+ inputs: [
24114
+ {
24115
+ internalType: 'address',
24116
+ name: 'receiver',
24117
+ type: 'address',
24118
+ },
24119
+ ],
24120
+ name: 'depositNativeTo',
24121
+ outputs: [],
24122
+ stateMutability: 'payable',
24123
+ type: 'function',
24124
+ },
24024
24125
  {
24025
24126
  inputs: [
24026
24127
  {
@@ -24099,7 +24200,13 @@ const ROOT_ERC20_PREDICATE = [
24099
24200
  },
24100
24201
  ],
24101
24202
  name: 'mapToken',
24102
- outputs: [],
24203
+ outputs: [
24204
+ {
24205
+ internalType: 'address',
24206
+ name: '',
24207
+ type: 'address',
24208
+ },
24209
+ ],
24103
24210
  stateMutability: 'nonpayable',
24104
24211
  type: 'function',
24105
24212
  },
@@ -24394,6 +24501,8 @@ var BridgeErrorType;
24394
24501
  BridgeErrorType["INTERNAL_ERROR"] = "INTERNAL_ERROR";
24395
24502
  BridgeErrorType["PROVIDER_ERROR"] = "PROVIDER_ERROR";
24396
24503
  BridgeErrorType["TRANSACTION_REVERTED"] = "TRANSACTION_REVERTED";
24504
+ BridgeErrorType["INVALID_TOKEN"] = "INVALID_TOKEN";
24505
+ BridgeErrorType["INVALID_TRANSACTION"] = "INVALID_TRANSACTION";
24397
24506
  })(BridgeErrorType || (BridgeErrorType = {}));
24398
24507
  /**
24399
24508
  * Represents a custom error for bridge operations.
@@ -24421,14 +24530,18 @@ class BridgeError extends Error {
24421
24530
  * @template T - The type of the value that the Promise resolves to.
24422
24531
  * @param {() => Promise<T>} fn - The function to wrap with error handling.
24423
24532
  * @param {BridgeErrorType} customErrorType - The custom error type to use for the error.
24533
+ * @param {string} [details] - Additional details to add to the error message.
24424
24534
  * @returns {Promise<T>} The result of the wrapped function or a rejected promise with a BridgeError.
24425
24535
  */
24426
- const withBridgeError = async (fn, customErrorType) => {
24536
+ const withBridgeError = async (fn, customErrorType, details) => {
24427
24537
  try {
24428
24538
  return await fn();
24429
24539
  }
24430
24540
  catch (error) {
24431
- const errorMessage = `${customErrorType}: ${error.message}` || 'UnknownError';
24541
+ let errorMessage = `${customErrorType}: ${error.message}` || 'UnknownError';
24542
+ if (details) {
24543
+ errorMessage = `${details}: ${errorMessage}`;
24544
+ }
24432
24545
  throw new BridgeError(errorMessage, customErrorType);
24433
24546
  }
24434
24547
  };
@@ -24943,202 +25056,1839 @@ async function getBlockNumberClosestToTimestamp(provider, targetTimestamp, block
24943
25056
  return lowerBlockNumber;
24944
25057
  }
24945
25058
 
24946
- /**
24947
- * Represents a token bridge, which manages asset transfers between two chains.
24948
- */
24949
- class TokenBridge {
24950
- /**
24951
- * @property {BridgeConfiguration} config - The bridge configuration object.
24952
- */
24953
- config;
24954
- /**
24955
- * Constructs a TokenBridge instance.
24956
- *
24957
- * @param {BridgeConfiguration} config - The bridge configuration object.
24958
- */
24959
- constructor(config) {
24960
- this.config = config;
24961
- }
24962
- /**
24963
- * Retrieves the bridge fee for a specific token.
24964
- *
24965
- * @param {BridgeFeeRequest} req - The fee request object containing the token address for which the fee is required.
24966
- * @returns {Promise<BridgeFeeResponse>} - A promise that resolves to an object containing the bridge fee for the specified token and a flag indicating if the token is bridgeable.
24967
- * @throws {BridgeError} - If an error occurs during the fee retrieval, a BridgeError will be thrown with a specific error type.
24968
- *
24969
- * Possible BridgeError types include:
24970
- * - INVALID_ADDRESS: The token address provided in the request is invalid.
24971
- *
24972
- * @example
24973
- * const feeRequest = {
24974
- * token: '0x123456...', // ERC20 token address
24975
- * };
24976
- *
24977
- * bridgeSdk.getFee(feeRequest)
24978
- * .then((feeResponse) => {
24979
- * console.log('Bridgeable:', feeResponse.bridgeable);
24980
- * console.log('Fee Amount:', feeResponse.feeAmount.toString());
24981
- * })
24982
- * .catch((error) => {
24983
- * console.error('Error:', error.message);
24984
- * });
24985
- */
24986
- async getFee(req) {
24987
- if (!isAddress(req.token)) {
24988
- throw new BridgeError(`token address ${req.token} is not a valid address`, BridgeErrorType.INVALID_ADDRESS);
24989
- }
24990
- return {
24991
- bridgeable: true,
24992
- feeAmount: await this.getFeeForToken(req.token),
24993
- };
24994
- }
24995
- /**
24996
- * Generates an unsigned deposit transaction for a user to sign and submit to the bridge.
24997
- *
24998
- * @param {BridgeDepositRequest} req - The deposit request object containing the required data for depositing tokens.
24999
- * @returns {Promise<BridgeDepositResponse>} - A promise that resolves to an object containing the unsigned transaction data.
25000
- * @throws {BridgeError} - If an error occurs during the generation of the unsigned transaction, a BridgeError will be thrown with a specific error type.
25001
- *
25002
- * Possible BridgeError types include:
25003
- * - UNSUPPORTED_ERROR: The operation is not supported. Currently thrown when attempting to deposit native tokens.
25004
- * - INVALID_ADDRESS: An Ethereum address provided in the request is invalid. This could be the depositor's, recipient's or the token's address.
25005
- * - INVALID_AMOUNT: The deposit amount provided in the request is invalid (less than or equal to 0).
25006
- * - INTERNAL_ERROR: An unexpected error occurred during the execution, likely due to the bridge SDK implementation.
25007
- *
25008
- * @example
25009
- * const depositRequest = {
25010
- * token: '0x123456...', // ERC20 token address
25011
- * depositorAddress: '0xabcdef...', // User's wallet address
25012
- * recipientAddress: '0x987654...', // Destination wallet address on the target chain
25013
- * depositAmount: ethers.utils.parseUnits('100', 18), // Deposit amount in wei
25014
- * };
25015
- *
25016
- * bridgeSdk.getUnsignedDepositTx(depositRequest)
25017
- * .then((depositResponse) => {
25018
- * console.log(depositResponse.unsignedTx);
25019
- * })
25020
- * .catch((error) => {
25021
- * console.error('Error:', error.message);
25022
- * });
25023
- */
25024
- async getUnsignedDepositTx(req) {
25025
- if (req.token === 'NATIVE') {
25026
- throw new BridgeError('native token deposit is not yet supported', BridgeErrorType.UNSUPPORTED_ERROR);
25027
- }
25028
- if (!isAddress(req.depositorAddress)) {
25029
- throw new BridgeError(`depositor address ${req.depositorAddress} is not a valid address`, BridgeErrorType.INVALID_ADDRESS);
25030
- }
25031
- if (!isAddress(req.recipientAddress)) {
25032
- throw new BridgeError(`recipient address ${req.recipientAddress} is not a valid address`, BridgeErrorType.INVALID_ADDRESS);
25033
- }
25034
- // If the token is ERC20, the address must be valid
25035
- if (req.token !== 'NATIVE' && !isAddress(req.token)) {
25036
- throw new BridgeError(`token address ${req.token} is not a valid address`, BridgeErrorType.INVALID_ADDRESS);
25037
- }
25038
- // The deposit amount cannot be <= 0
25039
- if (req.depositAmount.isNegative() || req.depositAmount.isZero()) {
25040
- throw new BridgeError(`deposit amount ${req.depositAmount.toString()} is invalid`, BridgeErrorType.INVALID_AMOUNT);
25041
- }
25042
- // Convert the addresses to correct format addresses (e.g. prepend 0x if not already)
25043
- const depositor = getAddress(req.depositorAddress);
25044
- const receipient = getAddress(req.recipientAddress);
25045
- const token = getAddress(req.token);
25046
- const rootERC20PredicateContract = await withBridgeError(async () => {
25047
- const contract = new Contract(this.config.bridgeContracts.rootChainERC20Predicate, ROOT_ERC20_PREDICATE);
25048
- return contract;
25049
- }, BridgeErrorType.INTERNAL_ERROR);
25050
- // Encode the function data into a payload
25051
- const data = await withBridgeError(async () => rootERC20PredicateContract.interface.encodeFunctionData('depositTo', [token, receipient, req.depositAmount]), BridgeErrorType.INTERNAL_ERROR);
25052
- return {
25053
- unsignedTx: {
25054
- data,
25055
- to: this.config.bridgeContracts.rootChainERC20Predicate,
25056
- value: 0,
25057
- from: depositor,
25059
+ const CHILD_ERC20_PREDICATE = [
25060
+ {
25061
+ inputs: [
25062
+ {
25063
+ internalType: 'string',
25064
+ name: 'only',
25065
+ type: 'string',
25058
25066
  },
25059
- };
25060
- }
25061
- /**
25062
- * Retrieves the unsigned approval transaction for a deposit to the bridge.
25063
- *
25064
- * @param {ApproveBridgeRequest} req - The approve bridge request object containing the depositor address, token address, and deposit amount.
25065
- * @returns {Promise<ApproveBridgeResponse>} - A promise that resolves to an object containing the unsigned approval transaction and a flag indicating if the approval is required.
25066
- * @throws {BridgeError} - If an error occurs during the transaction creation, a BridgeError will be thrown with a specific error type.
25067
- *
25068
- * Possible BridgeError types include:
25069
- * - UNSUPPORTED_ERROR: The operation is not supported. Currently thrown when attempting to deposit native tokens.
25070
- * - INVALID_ADDRESS: An Ethereum address provided in the request is invalid.
25071
- * - INVALID_AMOUNT: The deposit amount provided in the request is invalid (less than or equal to 0).
25072
- * - INTERNAL_ERROR: An unexpected error occurred during the execution, likely due to the bridge SDK implementation.
25073
- * - PROVIDER_ERROR: An error occurred while interacting with the Ethereum provider. This includes issues calling the ERC20 smart contract
25074
- *
25075
- * @example
25076
- * const approveRequest = {
25077
- * depositorAddress: '0x123456...', // Depositor's Ethereum address
25078
- * token: '0xabcdef...', // ERC20 token address
25079
- * depositAmount: ethers.utils.parseUnits('100', 18), // Deposit amount in token's smallest unit (e.g., wei for Ether)
25080
- * };
25081
- *
25082
- * bridgeSdk.getUnsignedApproveBridgeTx(approveRequest)
25083
- * .then((approveResponse) => {
25084
- * console.log('Approval Required:', approveResponse.required);
25085
- * console.log('Unsigned Approval Transaction:', approveResponse.unsignedTx);
25086
- * })
25087
- * .catch((error) => {
25088
- * console.error('Error:', error.message);
25089
- * });
25090
- */
25091
- async getUnsignedApproveBridgeTx(req) {
25092
- // If the token is NATIVE, no approval is required
25093
- if (req.token === 'NATIVE') {
25094
- // When native tokens are supported, change this to return required: false
25095
- throw new BridgeError('native token deposit is not yet supported', BridgeErrorType.UNSUPPORTED_ERROR);
25096
- }
25097
- if (!isAddress(req.depositorAddress)) {
25098
- throw new BridgeError(`depositor address ${req.depositorAddress} is not a valid address`, BridgeErrorType.INVALID_ADDRESS);
25099
- }
25100
- // If the token is ERC20, the address must be valid
25101
- if (req.token !== 'NATIVE' && !isAddress(req.token)) {
25102
- throw new BridgeError(`token address ${req.token} is not a valid address`, BridgeErrorType.INVALID_ADDRESS);
25103
- }
25104
- // The deposit amount cannot be <= 0
25105
- if (req.depositAmount.isNegative() || req.depositAmount.isZero()) {
25106
- throw new BridgeError(`deposit amount ${req.depositAmount.toString()} is invalid`, BridgeErrorType.INVALID_AMOUNT);
25107
- }
25108
- const erc20Contract = await withBridgeError(async () => new Contract(req.token, ERC20$1, this.config.rootProvider), BridgeErrorType.INTERNAL_ERROR);
25109
- // Get the current approved allowance of the RootERC20Predicate
25110
- const rootERC20PredicateAllowance = await withBridgeError(() => erc20Contract.allowance(req.depositorAddress, this.config.bridgeContracts.rootChainERC20Predicate), BridgeErrorType.PROVIDER_ERROR);
25111
- // If the allowance is greater than or equal to the deposit amount, no approval is required
25112
- if (rootERC20PredicateAllowance.gte(req.depositAmount)) {
25113
- return {
25114
- unsignedTx: null,
25115
- required: false,
25116
- };
25117
- }
25118
- // Calculate the amount of tokens that need to be approved for deposit
25119
- const approvalAmountRequired = req.depositAmount.sub(rootERC20PredicateAllowance);
25120
- // Encode the approve function call data for the ERC20 contract
25121
- const data = await withBridgeError(async () => erc20Contract.interface.encodeFunctionData('approve', [
25122
- this.config.bridgeContracts.rootChainERC20Predicate,
25123
- approvalAmountRequired,
25124
- ]), BridgeErrorType.INTERNAL_ERROR);
25125
- // Create the unsigned transaction for the approval
25126
- const unsignedTx = {
25127
- data,
25128
- to: req.token,
25129
- value: 0,
25130
- from: req.depositorAddress,
25131
- };
25132
- return {
25133
- unsignedTx,
25134
- required: true,
25135
- };
25067
+ ],
25068
+ name: 'Unauthorized',
25069
+ type: 'error',
25070
+ },
25071
+ {
25072
+ anonymous: false,
25073
+ inputs: [
25074
+ {
25075
+ indexed: false,
25076
+ internalType: 'uint8',
25077
+ name: 'version',
25078
+ type: 'uint8',
25079
+ },
25080
+ ],
25081
+ name: 'Initialized',
25082
+ type: 'event',
25083
+ },
25084
+ {
25085
+ anonymous: false,
25086
+ inputs: [
25087
+ {
25088
+ indexed: true,
25089
+ internalType: 'address',
25090
+ name: 'rootToken',
25091
+ type: 'address',
25092
+ },
25093
+ {
25094
+ indexed: true,
25095
+ internalType: 'address',
25096
+ name: 'childToken',
25097
+ type: 'address',
25098
+ },
25099
+ {
25100
+ indexed: false,
25101
+ internalType: 'address',
25102
+ name: 'sender',
25103
+ type: 'address',
25104
+ },
25105
+ {
25106
+ indexed: true,
25107
+ internalType: 'address',
25108
+ name: 'receiver',
25109
+ type: 'address',
25110
+ },
25111
+ {
25112
+ indexed: false,
25113
+ internalType: 'uint256',
25114
+ name: 'amount',
25115
+ type: 'uint256',
25116
+ },
25117
+ ],
25118
+ name: 'L2ERC20Deposit',
25119
+ type: 'event',
25120
+ },
25121
+ {
25122
+ anonymous: false,
25123
+ inputs: [
25124
+ {
25125
+ indexed: true,
25126
+ internalType: 'address',
25127
+ name: 'rootToken',
25128
+ type: 'address',
25129
+ },
25130
+ {
25131
+ indexed: true,
25132
+ internalType: 'address',
25133
+ name: 'childToken',
25134
+ type: 'address',
25135
+ },
25136
+ {
25137
+ indexed: false,
25138
+ internalType: 'address',
25139
+ name: 'sender',
25140
+ type: 'address',
25141
+ },
25142
+ {
25143
+ indexed: true,
25144
+ internalType: 'address',
25145
+ name: 'receiver',
25146
+ type: 'address',
25147
+ },
25148
+ {
25149
+ indexed: false,
25150
+ internalType: 'uint256',
25151
+ name: 'amount',
25152
+ type: 'uint256',
25153
+ },
25154
+ ],
25155
+ name: 'L2ERC20Withdraw',
25156
+ type: 'event',
25157
+ },
25158
+ {
25159
+ anonymous: false,
25160
+ inputs: [
25161
+ {
25162
+ indexed: true,
25163
+ internalType: 'address',
25164
+ name: 'rootToken',
25165
+ type: 'address',
25166
+ },
25167
+ {
25168
+ indexed: true,
25169
+ internalType: 'address',
25170
+ name: 'childToken',
25171
+ type: 'address',
25172
+ },
25173
+ ],
25174
+ name: 'L2TokenMapped',
25175
+ type: 'event',
25176
+ },
25177
+ {
25178
+ inputs: [],
25179
+ name: 'DEPOSIT_SIG',
25180
+ outputs: [
25181
+ {
25182
+ internalType: 'bytes32',
25183
+ name: '',
25184
+ type: 'bytes32',
25185
+ },
25186
+ ],
25187
+ stateMutability: 'view',
25188
+ type: 'function',
25189
+ },
25190
+ {
25191
+ inputs: [],
25192
+ name: 'MAP_TOKEN_SIG',
25193
+ outputs: [
25194
+ {
25195
+ internalType: 'bytes32',
25196
+ name: '',
25197
+ type: 'bytes32',
25198
+ },
25199
+ ],
25200
+ stateMutability: 'view',
25201
+ type: 'function',
25202
+ },
25203
+ {
25204
+ inputs: [],
25205
+ name: 'NATIVE_TOKEN_CONTRACT',
25206
+ outputs: [
25207
+ {
25208
+ internalType: 'address',
25209
+ name: '',
25210
+ type: 'address',
25211
+ },
25212
+ ],
25213
+ stateMutability: 'view',
25214
+ type: 'function',
25215
+ },
25216
+ {
25217
+ inputs: [],
25218
+ name: 'NATIVE_TRANSFER_PRECOMPILE',
25219
+ outputs: [
25220
+ {
25221
+ internalType: 'address',
25222
+ name: '',
25223
+ type: 'address',
25224
+ },
25225
+ ],
25226
+ stateMutability: 'view',
25227
+ type: 'function',
25228
+ },
25229
+ {
25230
+ inputs: [],
25231
+ name: 'NATIVE_TRANSFER_PRECOMPILE_GAS',
25232
+ outputs: [
25233
+ {
25234
+ internalType: 'uint256',
25235
+ name: '',
25236
+ type: 'uint256',
25237
+ },
25238
+ ],
25239
+ stateMutability: 'view',
25240
+ type: 'function',
25241
+ },
25242
+ {
25243
+ inputs: [],
25244
+ name: 'SYSTEM',
25245
+ outputs: [
25246
+ {
25247
+ internalType: 'address',
25248
+ name: '',
25249
+ type: 'address',
25250
+ },
25251
+ ],
25252
+ stateMutability: 'view',
25253
+ type: 'function',
25254
+ },
25255
+ {
25256
+ inputs: [],
25257
+ name: 'VALIDATOR_PKCHECK_PRECOMPILE',
25258
+ outputs: [
25259
+ {
25260
+ internalType: 'address',
25261
+ name: '',
25262
+ type: 'address',
25263
+ },
25264
+ ],
25265
+ stateMutability: 'view',
25266
+ type: 'function',
25267
+ },
25268
+ {
25269
+ inputs: [],
25270
+ name: 'VALIDATOR_PKCHECK_PRECOMPILE_GAS',
25271
+ outputs: [
25272
+ {
25273
+ internalType: 'uint256',
25274
+ name: '',
25275
+ type: 'uint256',
25276
+ },
25277
+ ],
25278
+ stateMutability: 'view',
25279
+ type: 'function',
25280
+ },
25281
+ {
25282
+ inputs: [],
25283
+ name: 'WITHDRAW_SIG',
25284
+ outputs: [
25285
+ {
25286
+ internalType: 'bytes32',
25287
+ name: '',
25288
+ type: 'bytes32',
25289
+ },
25290
+ ],
25291
+ stateMutability: 'view',
25292
+ type: 'function',
25293
+ },
25294
+ {
25295
+ inputs: [],
25296
+ name: 'childTokenTemplate',
25297
+ outputs: [
25298
+ {
25299
+ internalType: 'address',
25300
+ name: '',
25301
+ type: 'address',
25302
+ },
25303
+ ],
25304
+ stateMutability: 'view',
25305
+ type: 'function',
25306
+ },
25307
+ {
25308
+ inputs: [
25309
+ {
25310
+ internalType: 'address',
25311
+ name: 'newL2StateSender',
25312
+ type: 'address',
25313
+ },
25314
+ {
25315
+ internalType: 'address',
25316
+ name: 'newStateReceiver',
25317
+ type: 'address',
25318
+ },
25319
+ {
25320
+ internalType: 'address',
25321
+ name: 'newRootERC20Predicate',
25322
+ type: 'address',
25323
+ },
25324
+ {
25325
+ internalType: 'address',
25326
+ name: 'newChildTokenTemplate',
25327
+ type: 'address',
25328
+ },
25329
+ {
25330
+ internalType: 'address',
25331
+ name: 'newNativeTokenRootAddress',
25332
+ type: 'address',
25333
+ },
25334
+ ],
25335
+ name: 'initialize',
25336
+ outputs: [],
25337
+ stateMutability: 'nonpayable',
25338
+ type: 'function',
25339
+ },
25340
+ {
25341
+ inputs: [],
25342
+ name: 'l2StateSender',
25343
+ outputs: [
25344
+ {
25345
+ internalType: 'contract IStateSender',
25346
+ name: '',
25347
+ type: 'address',
25348
+ },
25349
+ ],
25350
+ stateMutability: 'view',
25351
+ type: 'function',
25352
+ },
25353
+ {
25354
+ inputs: [
25355
+ {
25356
+ internalType: 'uint256',
25357
+ name: '',
25358
+ type: 'uint256',
25359
+ },
25360
+ {
25361
+ internalType: 'address',
25362
+ name: 'sender',
25363
+ type: 'address',
25364
+ },
25365
+ {
25366
+ internalType: 'bytes',
25367
+ name: 'data',
25368
+ type: 'bytes',
25369
+ },
25370
+ ],
25371
+ name: 'onStateReceive',
25372
+ outputs: [],
25373
+ stateMutability: 'nonpayable',
25374
+ type: 'function',
25375
+ },
25376
+ {
25377
+ inputs: [],
25378
+ name: 'rootERC20Predicate',
25379
+ outputs: [
25380
+ {
25381
+ internalType: 'address',
25382
+ name: '',
25383
+ type: 'address',
25384
+ },
25385
+ ],
25386
+ stateMutability: 'view',
25387
+ type: 'function',
25388
+ },
25389
+ {
25390
+ inputs: [
25391
+ {
25392
+ internalType: 'address',
25393
+ name: '',
25394
+ type: 'address',
25395
+ },
25396
+ ],
25397
+ name: 'rootTokenToChildToken',
25398
+ outputs: [
25399
+ {
25400
+ internalType: 'address',
25401
+ name: '',
25402
+ type: 'address',
25403
+ },
25404
+ ],
25405
+ stateMutability: 'view',
25406
+ type: 'function',
25407
+ },
25408
+ {
25409
+ inputs: [],
25410
+ name: 'stateReceiver',
25411
+ outputs: [
25412
+ {
25413
+ internalType: 'address',
25414
+ name: '',
25415
+ type: 'address',
25416
+ },
25417
+ ],
25418
+ stateMutability: 'view',
25419
+ type: 'function',
25420
+ },
25421
+ {
25422
+ inputs: [
25423
+ {
25424
+ internalType: 'contract IChildERC20',
25425
+ name: 'childToken',
25426
+ type: 'address',
25427
+ },
25428
+ {
25429
+ internalType: 'uint256',
25430
+ name: 'amount',
25431
+ type: 'uint256',
25432
+ },
25433
+ ],
25434
+ name: 'withdraw',
25435
+ outputs: [],
25436
+ stateMutability: 'nonpayable',
25437
+ type: 'function',
25438
+ },
25439
+ {
25440
+ inputs: [
25441
+ {
25442
+ internalType: 'contract IChildERC20',
25443
+ name: 'childToken',
25444
+ type: 'address',
25445
+ },
25446
+ {
25447
+ internalType: 'address',
25448
+ name: 'receiver',
25449
+ type: 'address',
25450
+ },
25451
+ {
25452
+ internalType: 'uint256',
25453
+ name: 'amount',
25454
+ type: 'uint256',
25455
+ },
25456
+ ],
25457
+ name: 'withdrawTo',
25458
+ outputs: [],
25459
+ stateMutability: 'nonpayable',
25460
+ type: 'function',
25461
+ },
25462
+ ];
25463
+
25464
+ const CHECKPOINT_MANAGER = [
25465
+ {
25466
+ anonymous: false,
25467
+ inputs: [
25468
+ {
25469
+ indexed: false,
25470
+ internalType: 'uint8',
25471
+ name: 'version',
25472
+ type: 'uint8',
25473
+ },
25474
+ ],
25475
+ name: 'Initialized',
25476
+ type: 'event',
25477
+ },
25478
+ {
25479
+ inputs: [],
25480
+ name: 'DOMAIN',
25481
+ outputs: [
25482
+ {
25483
+ internalType: 'bytes32',
25484
+ name: '',
25485
+ type: 'bytes32',
25486
+ },
25487
+ ],
25488
+ stateMutability: 'view',
25489
+ type: 'function',
25490
+ },
25491
+ {
25492
+ inputs: [],
25493
+ name: 'bls',
25494
+ outputs: [
25495
+ {
25496
+ internalType: 'contract IBLS',
25497
+ name: '',
25498
+ type: 'address',
25499
+ },
25500
+ ],
25501
+ stateMutability: 'view',
25502
+ type: 'function',
25503
+ },
25504
+ {
25505
+ inputs: [],
25506
+ name: 'bn256G2',
25507
+ outputs: [
25508
+ {
25509
+ internalType: 'contract IBN256G2',
25510
+ name: '',
25511
+ type: 'address',
25512
+ },
25513
+ ],
25514
+ stateMutability: 'view',
25515
+ type: 'function',
25516
+ },
25517
+ {
25518
+ inputs: [],
25519
+ name: 'chainId',
25520
+ outputs: [
25521
+ {
25522
+ internalType: 'uint256',
25523
+ name: '',
25524
+ type: 'uint256',
25525
+ },
25526
+ ],
25527
+ stateMutability: 'view',
25528
+ type: 'function',
25529
+ },
25530
+ {
25531
+ inputs: [
25532
+ {
25533
+ internalType: 'uint256',
25534
+ name: '',
25535
+ type: 'uint256',
25536
+ },
25537
+ ],
25538
+ name: 'checkpointBlockNumbers',
25539
+ outputs: [
25540
+ {
25541
+ internalType: 'uint256',
25542
+ name: '',
25543
+ type: 'uint256',
25544
+ },
25545
+ ],
25546
+ stateMutability: 'view',
25547
+ type: 'function',
25548
+ },
25549
+ {
25550
+ inputs: [
25551
+ {
25552
+ internalType: 'uint256',
25553
+ name: '',
25554
+ type: 'uint256',
25555
+ },
25556
+ ],
25557
+ name: 'checkpoints',
25558
+ outputs: [
25559
+ {
25560
+ internalType: 'uint256',
25561
+ name: 'epoch',
25562
+ type: 'uint256',
25563
+ },
25564
+ {
25565
+ internalType: 'uint256',
25566
+ name: 'blockNumber',
25567
+ type: 'uint256',
25568
+ },
25569
+ {
25570
+ internalType: 'bytes32',
25571
+ name: 'eventRoot',
25572
+ type: 'bytes32',
25573
+ },
25574
+ ],
25575
+ stateMutability: 'view',
25576
+ type: 'function',
25577
+ },
25578
+ {
25579
+ inputs: [],
25580
+ name: 'currentCheckpointBlockNumber',
25581
+ outputs: [
25582
+ {
25583
+ internalType: 'uint256',
25584
+ name: '',
25585
+ type: 'uint256',
25586
+ },
25587
+ ],
25588
+ stateMutability: 'view',
25589
+ type: 'function',
25590
+ },
25591
+ {
25592
+ inputs: [],
25593
+ name: 'currentEpoch',
25594
+ outputs: [
25595
+ {
25596
+ internalType: 'uint256',
25597
+ name: '',
25598
+ type: 'uint256',
25599
+ },
25600
+ ],
25601
+ stateMutability: 'view',
25602
+ type: 'function',
25603
+ },
25604
+ {
25605
+ inputs: [
25606
+ {
25607
+ internalType: 'uint256',
25608
+ name: '',
25609
+ type: 'uint256',
25610
+ },
25611
+ ],
25612
+ name: 'currentValidatorSet',
25613
+ outputs: [
25614
+ {
25615
+ internalType: 'address',
25616
+ name: '_address',
25617
+ type: 'address',
25618
+ },
25619
+ {
25620
+ internalType: 'uint256',
25621
+ name: 'votingPower',
25622
+ type: 'uint256',
25623
+ },
25624
+ ],
25625
+ stateMutability: 'view',
25626
+ type: 'function',
25627
+ },
25628
+ {
25629
+ inputs: [],
25630
+ name: 'currentValidatorSetHash',
25631
+ outputs: [
25632
+ {
25633
+ internalType: 'bytes32',
25634
+ name: '',
25635
+ type: 'bytes32',
25636
+ },
25637
+ ],
25638
+ stateMutability: 'view',
25639
+ type: 'function',
25640
+ },
25641
+ {
25642
+ inputs: [],
25643
+ name: 'currentValidatorSetLength',
25644
+ outputs: [
25645
+ {
25646
+ internalType: 'uint256',
25647
+ name: '',
25648
+ type: 'uint256',
25649
+ },
25650
+ ],
25651
+ stateMutability: 'view',
25652
+ type: 'function',
25653
+ },
25654
+ {
25655
+ inputs: [
25656
+ {
25657
+ internalType: 'uint256',
25658
+ name: 'blockNumber',
25659
+ type: 'uint256',
25660
+ },
25661
+ ],
25662
+ name: 'getCheckpointBlock',
25663
+ outputs: [
25664
+ {
25665
+ internalType: 'bool',
25666
+ name: '',
25667
+ type: 'bool',
25668
+ },
25669
+ {
25670
+ internalType: 'uint256',
25671
+ name: '',
25672
+ type: 'uint256',
25673
+ },
25674
+ ],
25675
+ stateMutability: 'view',
25676
+ type: 'function',
25677
+ },
25678
+ {
25679
+ inputs: [
25680
+ {
25681
+ internalType: 'uint256',
25682
+ name: 'blockNumber',
25683
+ type: 'uint256',
25684
+ },
25685
+ {
25686
+ internalType: 'bytes32',
25687
+ name: 'leaf',
25688
+ type: 'bytes32',
25689
+ },
25690
+ {
25691
+ internalType: 'uint256',
25692
+ name: 'leafIndex',
25693
+ type: 'uint256',
25694
+ },
25695
+ {
25696
+ internalType: 'bytes32[]',
25697
+ name: 'proof',
25698
+ type: 'bytes32[]',
25699
+ },
25700
+ ],
25701
+ name: 'getEventMembershipByBlockNumber',
25702
+ outputs: [
25703
+ {
25704
+ internalType: 'bool',
25705
+ name: '',
25706
+ type: 'bool',
25707
+ },
25708
+ ],
25709
+ stateMutability: 'view',
25710
+ type: 'function',
25711
+ },
25712
+ {
25713
+ inputs: [
25714
+ {
25715
+ internalType: 'uint256',
25716
+ name: 'epoch',
25717
+ type: 'uint256',
25718
+ },
25719
+ {
25720
+ internalType: 'bytes32',
25721
+ name: 'leaf',
25722
+ type: 'bytes32',
25723
+ },
25724
+ {
25725
+ internalType: 'uint256',
25726
+ name: 'leafIndex',
25727
+ type: 'uint256',
25728
+ },
25729
+ {
25730
+ internalType: 'bytes32[]',
25731
+ name: 'proof',
25732
+ type: 'bytes32[]',
25733
+ },
25734
+ ],
25735
+ name: 'getEventMembershipByEpoch',
25736
+ outputs: [
25737
+ {
25738
+ internalType: 'bool',
25739
+ name: '',
25740
+ type: 'bool',
25741
+ },
25742
+ ],
25743
+ stateMutability: 'view',
25744
+ type: 'function',
25745
+ },
25746
+ {
25747
+ inputs: [
25748
+ {
25749
+ internalType: 'uint256',
25750
+ name: 'blockNumber',
25751
+ type: 'uint256',
25752
+ },
25753
+ ],
25754
+ name: 'getEventRootByBlock',
25755
+ outputs: [
25756
+ {
25757
+ internalType: 'bytes32',
25758
+ name: '',
25759
+ type: 'bytes32',
25760
+ },
25761
+ ],
25762
+ stateMutability: 'view',
25763
+ type: 'function',
25764
+ },
25765
+ {
25766
+ inputs: [
25767
+ {
25768
+ internalType: 'contract IBLS',
25769
+ name: 'newBls',
25770
+ type: 'address',
25771
+ },
25772
+ {
25773
+ internalType: 'contract IBN256G2',
25774
+ name: 'newBn256G2',
25775
+ type: 'address',
25776
+ },
25777
+ {
25778
+ internalType: 'uint256',
25779
+ name: 'chainId_',
25780
+ type: 'uint256',
25781
+ },
25782
+ {
25783
+ components: [
25784
+ {
25785
+ internalType: 'address',
25786
+ name: '_address',
25787
+ type: 'address',
25788
+ },
25789
+ {
25790
+ internalType: 'uint256[4]',
25791
+ name: 'blsKey',
25792
+ type: 'uint256[4]',
25793
+ },
25794
+ {
25795
+ internalType: 'uint256',
25796
+ name: 'votingPower',
25797
+ type: 'uint256',
25798
+ },
25799
+ ],
25800
+ internalType: 'struct ICheckpointManager.Validator[]',
25801
+ name: 'newValidatorSet',
25802
+ type: 'tuple[]',
25803
+ },
25804
+ ],
25805
+ name: 'initialize',
25806
+ outputs: [],
25807
+ stateMutability: 'nonpayable',
25808
+ type: 'function',
25809
+ },
25810
+ {
25811
+ inputs: [
25812
+ {
25813
+ components: [
25814
+ {
25815
+ internalType: 'bytes32',
25816
+ name: 'blockHash',
25817
+ type: 'bytes32',
25818
+ },
25819
+ {
25820
+ internalType: 'uint256',
25821
+ name: 'blockRound',
25822
+ type: 'uint256',
25823
+ },
25824
+ {
25825
+ internalType: 'bytes32',
25826
+ name: 'currentValidatorSetHash',
25827
+ type: 'bytes32',
25828
+ },
25829
+ ],
25830
+ internalType: 'struct ICheckpointManager.CheckpointMetadata',
25831
+ name: 'checkpointMetadata',
25832
+ type: 'tuple',
25833
+ },
25834
+ {
25835
+ components: [
25836
+ {
25837
+ internalType: 'uint256',
25838
+ name: 'epoch',
25839
+ type: 'uint256',
25840
+ },
25841
+ {
25842
+ internalType: 'uint256',
25843
+ name: 'blockNumber',
25844
+ type: 'uint256',
25845
+ },
25846
+ {
25847
+ internalType: 'bytes32',
25848
+ name: 'eventRoot',
25849
+ type: 'bytes32',
25850
+ },
25851
+ ],
25852
+ internalType: 'struct ICheckpointManager.Checkpoint',
25853
+ name: 'checkpoint',
25854
+ type: 'tuple',
25855
+ },
25856
+ {
25857
+ internalType: 'uint256[2]',
25858
+ name: 'signature',
25859
+ type: 'uint256[2]',
25860
+ },
25861
+ {
25862
+ components: [
25863
+ {
25864
+ internalType: 'address',
25865
+ name: '_address',
25866
+ type: 'address',
25867
+ },
25868
+ {
25869
+ internalType: 'uint256[4]',
25870
+ name: 'blsKey',
25871
+ type: 'uint256[4]',
25872
+ },
25873
+ {
25874
+ internalType: 'uint256',
25875
+ name: 'votingPower',
25876
+ type: 'uint256',
25877
+ },
25878
+ ],
25879
+ internalType: 'struct ICheckpointManager.Validator[]',
25880
+ name: 'newValidatorSet',
25881
+ type: 'tuple[]',
25882
+ },
25883
+ {
25884
+ internalType: 'bytes',
25885
+ name: 'bitmap',
25886
+ type: 'bytes',
25887
+ },
25888
+ ],
25889
+ name: 'submit',
25890
+ outputs: [],
25891
+ stateMutability: 'nonpayable',
25892
+ type: 'function',
25893
+ },
25894
+ {
25895
+ inputs: [],
25896
+ name: 'totalVotingPower',
25897
+ outputs: [
25898
+ {
25899
+ internalType: 'uint256',
25900
+ name: '',
25901
+ type: 'uint256',
25902
+ },
25903
+ ],
25904
+ stateMutability: 'view',
25905
+ type: 'function',
25906
+ },
25907
+ ];
25908
+
25909
+ function decodeExtraData(extraData) {
25910
+ const decoded = decode(`0x${extraData.substring(66)}`);
25911
+ const blockExtraData = {
25912
+ validators: decoded[0],
25913
+ parent: decoded[1],
25914
+ committed: decoded[2],
25915
+ checkpoint: {
25916
+ blockRound: decoded[3][0],
25917
+ epochNumber: parseInt(decoded[3][1], 16),
25918
+ currentValidatorHash: decoded[3][2],
25919
+ nextValidatorHash: decoded[3][3],
25920
+ eventRoot: decoded[3][4],
25921
+ },
25922
+ };
25923
+ return blockExtraData;
25924
+ }
25925
+
25926
+ /**
25927
+ * @constant {string} ETH_SEPOLIA_CHAIN_ID - The chain ID for the Ethereum Sepolia testnet (EIP-155 compatible format).
25928
+ */
25929
+ const ETH_SEPOLIA_CHAIN_ID = '11155111';
25930
+ /**
25931
+ * @constant {string} ETH_MAINNET_CHAIN_ID - The chain ID for the Ethereum mainnet (EIP-155 compatible format).
25932
+ */
25933
+ const ETH_MAINNET_CHAIN_ID = '1';
25934
+ /**
25935
+ * @constant {string} ZKEVM_DEVNET_CHAIN_ID - The chain ID for the zkEVM devnet (EIP-155 compatible format).
25936
+ */
25937
+ const ZKEVM_DEVNET_CHAIN_ID = '13433';
25938
+ /**
25939
+ /**
25940
+ * @constant {string} ZKEVM_TESTNET_CHAIN_ID - The chain ID for the zkEVM testnet (EIP-155 compatible format).
25941
+ */
25942
+ const ZKEVM_TESTNET_CHAIN_ID = '13372';
25943
+ /**
25944
+ * @constant {string} ZKEVM_MAINNET_CHAIN_ID - The chain ID for the zkEVM mainnet (EIP-155 compatible format).
25945
+ */
25946
+ const ZKEVM_MAINNET_CHAIN_ID = '13371';
25947
+ /**
25948
+ * @constant {string} L2_STATE_SENDER_ADDRESS - Address of bridge contract to the rootchain
25949
+ */
25950
+ const L2_STATE_SENDER_ADDRESS = '0x0000000000000000000000000000000000001002';
25951
+ /**
25952
+ * The constant value representing the native token in the token bridge context.
25953
+ * The key is used to indicate the native token of a blockchain network (like Ether in Ethereum) in methods that normally require a token address.
25954
+ * @constant {string}
25955
+ */
25956
+ const NATIVE_TOKEN_BRIDGE_KEY = '0x0000000000000000000000000000000000000001';
25957
+ /**
25958
+ * @constant {BridgeInstance} ETH_SEPOLIA_TO_ZKEVM_DEVNET - A bridge instance configuration for bridging between the Ethereum Sepolia testnet and the zkEVM devnet.
25959
+ */
25960
+ const ETH_SEPOLIA_TO_ZKEVM_DEVNET = {
25961
+ rootChainID: ETH_SEPOLIA_CHAIN_ID,
25962
+ childChainID: ZKEVM_DEVNET_CHAIN_ID,
25963
+ };
25964
+ /**
25965
+ * @constant {BridgeInstance} ETH_SEPOLIA_TO_ZKEVM_TESTNET - A bridge instance configuration for bridging between the Ethereum Sepolia testnet and the zkEVM testnet.
25966
+ */
25967
+ const ETH_SEPOLIA_TO_ZKEVM_TESTNET = {
25968
+ rootChainID: ETH_SEPOLIA_CHAIN_ID,
25969
+ childChainID: ZKEVM_TESTNET_CHAIN_ID,
25970
+ };
25971
+ /**
25972
+ * @constant {BridgeInstance} ETH_MAINNET_TO_ZKEVM_MAINNET - A bridge instance configuration for bridging between the Ethereum mainnet and the zkEVM mainnet.
25973
+ */
25974
+ const ETH_MAINNET_TO_ZKEVM_MAINNET = {
25975
+ rootChainID: ETH_MAINNET_CHAIN_ID,
25976
+ childChainID: ZKEVM_MAINNET_CHAIN_ID,
25977
+ };
25978
+
25979
+ const L2_STATE_SENDER = [
25980
+ {
25981
+ anonymous: false,
25982
+ inputs: [
25983
+ {
25984
+ indexed: true,
25985
+ internalType: 'uint256',
25986
+ name: 'id',
25987
+ type: 'uint256',
25988
+ },
25989
+ {
25990
+ indexed: true,
25991
+ internalType: 'address',
25992
+ name: 'sender',
25993
+ type: 'address',
25994
+ },
25995
+ {
25996
+ indexed: true,
25997
+ internalType: 'address',
25998
+ name: 'receiver',
25999
+ type: 'address',
26000
+ },
26001
+ {
26002
+ indexed: false,
26003
+ internalType: 'bytes',
26004
+ name: 'data',
26005
+ type: 'bytes',
26006
+ },
26007
+ ],
26008
+ name: 'L2StateSynced',
26009
+ type: 'event',
26010
+ },
26011
+ {
26012
+ inputs: [],
26013
+ name: 'MAX_LENGTH',
26014
+ outputs: [
26015
+ {
26016
+ internalType: 'uint256',
26017
+ name: '',
26018
+ type: 'uint256',
26019
+ },
26020
+ ],
26021
+ stateMutability: 'view',
26022
+ type: 'function',
26023
+ },
26024
+ {
26025
+ inputs: [],
26026
+ name: 'counter',
26027
+ outputs: [
26028
+ {
26029
+ internalType: 'uint256',
26030
+ name: '',
26031
+ type: 'uint256',
26032
+ },
26033
+ ],
26034
+ stateMutability: 'view',
26035
+ type: 'function',
26036
+ },
26037
+ {
26038
+ inputs: [
26039
+ {
26040
+ internalType: 'address',
26041
+ name: 'receiver',
26042
+ type: 'address',
26043
+ },
26044
+ {
26045
+ internalType: 'bytes',
26046
+ name: 'data',
26047
+ type: 'bytes',
26048
+ },
26049
+ ],
26050
+ name: 'syncState',
26051
+ outputs: [],
26052
+ stateMutability: 'nonpayable',
26053
+ type: 'function',
26054
+ },
26055
+ ];
26056
+
26057
+ const EXIT_HELPER = [
26058
+ {
26059
+ anonymous: false,
26060
+ inputs: [
26061
+ {
26062
+ indexed: true,
26063
+ internalType: 'uint256',
26064
+ name: 'id',
26065
+ type: 'uint256',
26066
+ },
26067
+ {
26068
+ indexed: true,
26069
+ internalType: 'bool',
26070
+ name: 'success',
26071
+ type: 'bool',
26072
+ },
26073
+ {
26074
+ indexed: false,
26075
+ internalType: 'bytes',
26076
+ name: 'returnData',
26077
+ type: 'bytes',
26078
+ },
26079
+ ],
26080
+ name: 'ExitProcessed',
26081
+ type: 'event',
26082
+ },
26083
+ {
26084
+ anonymous: false,
26085
+ inputs: [
26086
+ {
26087
+ indexed: false,
26088
+ internalType: 'uint8',
26089
+ name: 'version',
26090
+ type: 'uint8',
26091
+ },
26092
+ ],
26093
+ name: 'Initialized',
26094
+ type: 'event',
26095
+ },
26096
+ {
26097
+ inputs: [
26098
+ {
26099
+ components: [
26100
+ {
26101
+ internalType: 'uint256',
26102
+ name: 'blockNumber',
26103
+ type: 'uint256',
26104
+ },
26105
+ {
26106
+ internalType: 'uint256',
26107
+ name: 'leafIndex',
26108
+ type: 'uint256',
26109
+ },
26110
+ {
26111
+ internalType: 'bytes',
26112
+ name: 'unhashedLeaf',
26113
+ type: 'bytes',
26114
+ },
26115
+ {
26116
+ internalType: 'bytes32[]',
26117
+ name: 'proof',
26118
+ type: 'bytes32[]',
26119
+ },
26120
+ ],
26121
+ internalType: 'struct IExitHelper.BatchExitInput[]',
26122
+ name: 'inputs',
26123
+ type: 'tuple[]',
26124
+ },
26125
+ ],
26126
+ name: 'batchExit',
26127
+ outputs: [],
26128
+ stateMutability: 'nonpayable',
26129
+ type: 'function',
26130
+ },
26131
+ {
26132
+ inputs: [],
26133
+ name: 'checkpointManager',
26134
+ outputs: [
26135
+ {
26136
+ internalType: 'contract ICheckpointManager',
26137
+ name: '',
26138
+ type: 'address',
26139
+ },
26140
+ ],
26141
+ stateMutability: 'view',
26142
+ type: 'function',
26143
+ },
26144
+ {
26145
+ inputs: [
26146
+ {
26147
+ internalType: 'uint256',
26148
+ name: 'blockNumber',
26149
+ type: 'uint256',
26150
+ },
26151
+ {
26152
+ internalType: 'uint256',
26153
+ name: 'leafIndex',
26154
+ type: 'uint256',
26155
+ },
26156
+ {
26157
+ internalType: 'bytes',
26158
+ name: 'unhashedLeaf',
26159
+ type: 'bytes',
26160
+ },
26161
+ {
26162
+ internalType: 'bytes32[]',
26163
+ name: 'proof',
26164
+ type: 'bytes32[]',
26165
+ },
26166
+ ],
26167
+ name: 'exit',
26168
+ outputs: [],
26169
+ stateMutability: 'nonpayable',
26170
+ type: 'function',
26171
+ },
26172
+ {
26173
+ inputs: [
26174
+ {
26175
+ internalType: 'contract ICheckpointManager',
26176
+ name: 'newCheckpointManager',
26177
+ type: 'address',
26178
+ },
26179
+ ],
26180
+ name: 'initialize',
26181
+ outputs: [],
26182
+ stateMutability: 'nonpayable',
26183
+ type: 'function',
26184
+ },
26185
+ {
26186
+ inputs: [
26187
+ {
26188
+ internalType: 'uint256',
26189
+ name: '',
26190
+ type: 'uint256',
26191
+ },
26192
+ ],
26193
+ name: 'processedExits',
26194
+ outputs: [
26195
+ {
26196
+ internalType: 'bool',
26197
+ name: '',
26198
+ type: 'bool',
26199
+ },
26200
+ ],
26201
+ stateMutability: 'view',
26202
+ type: 'function',
26203
+ },
26204
+ ];
26205
+
26206
+ const CHILD_ERC20 = [
26207
+ {
26208
+ anonymous: false,
26209
+ inputs: [
26210
+ {
26211
+ indexed: true,
26212
+ internalType: 'address',
26213
+ name: 'owner',
26214
+ type: 'address',
26215
+ },
26216
+ {
26217
+ indexed: true,
26218
+ internalType: 'address',
26219
+ name: 'spender',
26220
+ type: 'address',
26221
+ },
26222
+ {
26223
+ indexed: false,
26224
+ internalType: 'uint256',
26225
+ name: 'value',
26226
+ type: 'uint256',
26227
+ },
26228
+ ],
26229
+ name: 'Approval',
26230
+ type: 'event',
26231
+ },
26232
+ {
26233
+ anonymous: false,
26234
+ inputs: [
26235
+ {
26236
+ indexed: false,
26237
+ internalType: 'uint8',
26238
+ name: 'version',
26239
+ type: 'uint8',
26240
+ },
26241
+ ],
26242
+ name: 'Initialized',
26243
+ type: 'event',
26244
+ },
26245
+ {
26246
+ anonymous: false,
26247
+ inputs: [
26248
+ {
26249
+ indexed: false,
26250
+ internalType: 'address',
26251
+ name: 'userAddress',
26252
+ type: 'address',
26253
+ },
26254
+ {
26255
+ indexed: false,
26256
+ internalType: 'address',
26257
+ name: 'relayerAddress',
26258
+ type: 'address',
26259
+ },
26260
+ {
26261
+ indexed: false,
26262
+ internalType: 'bytes',
26263
+ name: 'functionSignature',
26264
+ type: 'bytes',
26265
+ },
26266
+ ],
26267
+ name: 'MetaTransactionExecuted',
26268
+ type: 'event',
26269
+ },
26270
+ {
26271
+ anonymous: false,
26272
+ inputs: [
26273
+ {
26274
+ indexed: true,
26275
+ internalType: 'address',
26276
+ name: 'from',
26277
+ type: 'address',
26278
+ },
26279
+ {
26280
+ indexed: true,
26281
+ internalType: 'address',
26282
+ name: 'to',
26283
+ type: 'address',
26284
+ },
26285
+ {
26286
+ indexed: false,
26287
+ internalType: 'uint256',
26288
+ name: 'value',
26289
+ type: 'uint256',
26290
+ },
26291
+ ],
26292
+ name: 'Transfer',
26293
+ type: 'event',
26294
+ },
26295
+ {
26296
+ inputs: [
26297
+ {
26298
+ internalType: 'address',
26299
+ name: 'owner',
26300
+ type: 'address',
26301
+ },
26302
+ {
26303
+ internalType: 'address',
26304
+ name: 'spender',
26305
+ type: 'address',
26306
+ },
26307
+ ],
26308
+ name: 'allowance',
26309
+ outputs: [
26310
+ {
26311
+ internalType: 'uint256',
26312
+ name: '',
26313
+ type: 'uint256',
26314
+ },
26315
+ ],
26316
+ stateMutability: 'view',
26317
+ type: 'function',
26318
+ },
26319
+ {
26320
+ inputs: [
26321
+ {
26322
+ internalType: 'address',
26323
+ name: 'spender',
26324
+ type: 'address',
26325
+ },
26326
+ {
26327
+ internalType: 'uint256',
26328
+ name: 'amount',
26329
+ type: 'uint256',
26330
+ },
26331
+ ],
26332
+ name: 'approve',
26333
+ outputs: [
26334
+ {
26335
+ internalType: 'bool',
26336
+ name: '',
26337
+ type: 'bool',
26338
+ },
26339
+ ],
26340
+ stateMutability: 'nonpayable',
26341
+ type: 'function',
26342
+ },
26343
+ {
26344
+ inputs: [
26345
+ {
26346
+ internalType: 'address',
26347
+ name: 'account',
26348
+ type: 'address',
26349
+ },
26350
+ ],
26351
+ name: 'balanceOf',
26352
+ outputs: [
26353
+ {
26354
+ internalType: 'uint256',
26355
+ name: '',
26356
+ type: 'uint256',
26357
+ },
26358
+ ],
26359
+ stateMutability: 'view',
26360
+ type: 'function',
26361
+ },
26362
+ {
26363
+ inputs: [
26364
+ {
26365
+ internalType: 'address',
26366
+ name: 'account',
26367
+ type: 'address',
26368
+ },
26369
+ {
26370
+ internalType: 'uint256',
26371
+ name: 'amount',
26372
+ type: 'uint256',
26373
+ },
26374
+ ],
26375
+ name: 'burn',
26376
+ outputs: [
26377
+ {
26378
+ internalType: 'bool',
26379
+ name: '',
26380
+ type: 'bool',
26381
+ },
26382
+ ],
26383
+ stateMutability: 'nonpayable',
26384
+ type: 'function',
26385
+ },
26386
+ {
26387
+ inputs: [],
26388
+ name: 'decimals',
26389
+ outputs: [
26390
+ {
26391
+ internalType: 'uint8',
26392
+ name: '',
26393
+ type: 'uint8',
26394
+ },
26395
+ ],
26396
+ stateMutability: 'view',
26397
+ type: 'function',
26398
+ },
26399
+ {
26400
+ inputs: [
26401
+ {
26402
+ internalType: 'address',
26403
+ name: 'spender',
26404
+ type: 'address',
26405
+ },
26406
+ {
26407
+ internalType: 'uint256',
26408
+ name: 'subtractedValue',
26409
+ type: 'uint256',
26410
+ },
26411
+ ],
26412
+ name: 'decreaseAllowance',
26413
+ outputs: [
26414
+ {
26415
+ internalType: 'bool',
26416
+ name: '',
26417
+ type: 'bool',
26418
+ },
26419
+ ],
26420
+ stateMutability: 'nonpayable',
26421
+ type: 'function',
26422
+ },
26423
+ {
26424
+ inputs: [
26425
+ {
26426
+ internalType: 'address',
26427
+ name: 'userAddress',
26428
+ type: 'address',
26429
+ },
26430
+ {
26431
+ internalType: 'bytes',
26432
+ name: 'functionSignature',
26433
+ type: 'bytes',
26434
+ },
26435
+ {
26436
+ internalType: 'bytes32',
26437
+ name: 'sigR',
26438
+ type: 'bytes32',
26439
+ },
26440
+ {
26441
+ internalType: 'bytes32',
26442
+ name: 'sigS',
26443
+ type: 'bytes32',
26444
+ },
26445
+ {
26446
+ internalType: 'uint8',
26447
+ name: 'sigV',
26448
+ type: 'uint8',
26449
+ },
26450
+ ],
26451
+ name: 'executeMetaTransaction',
26452
+ outputs: [
26453
+ {
26454
+ internalType: 'bytes',
26455
+ name: '',
26456
+ type: 'bytes',
26457
+ },
26458
+ ],
26459
+ stateMutability: 'nonpayable',
26460
+ type: 'function',
26461
+ },
26462
+ {
26463
+ inputs: [
26464
+ {
26465
+ internalType: 'address',
26466
+ name: 'user',
26467
+ type: 'address',
26468
+ },
26469
+ ],
26470
+ name: 'getNonce',
26471
+ outputs: [
26472
+ {
26473
+ internalType: 'uint256',
26474
+ name: 'nonce',
26475
+ type: 'uint256',
26476
+ },
26477
+ ],
26478
+ stateMutability: 'view',
26479
+ type: 'function',
26480
+ },
26481
+ {
26482
+ inputs: [
26483
+ {
26484
+ internalType: 'address',
26485
+ name: 'spender',
26486
+ type: 'address',
26487
+ },
26488
+ {
26489
+ internalType: 'uint256',
26490
+ name: 'addedValue',
26491
+ type: 'uint256',
26492
+ },
26493
+ ],
26494
+ name: 'increaseAllowance',
26495
+ outputs: [
26496
+ {
26497
+ internalType: 'bool',
26498
+ name: '',
26499
+ type: 'bool',
26500
+ },
26501
+ ],
26502
+ stateMutability: 'nonpayable',
26503
+ type: 'function',
26504
+ },
26505
+ {
26506
+ inputs: [
26507
+ {
26508
+ internalType: 'address',
26509
+ name: 'rootToken_',
26510
+ type: 'address',
26511
+ },
26512
+ {
26513
+ internalType: 'string',
26514
+ name: 'name_',
26515
+ type: 'string',
26516
+ },
26517
+ {
26518
+ internalType: 'string',
26519
+ name: 'symbol_',
26520
+ type: 'string',
26521
+ },
26522
+ {
26523
+ internalType: 'uint8',
26524
+ name: 'decimals_',
26525
+ type: 'uint8',
26526
+ },
26527
+ ],
26528
+ name: 'initialize',
26529
+ outputs: [],
26530
+ stateMutability: 'nonpayable',
26531
+ type: 'function',
26532
+ },
26533
+ {
26534
+ inputs: [
26535
+ {
26536
+ internalType: 'uint256',
26537
+ name: 'offset',
26538
+ type: 'uint256',
26539
+ },
26540
+ ],
26541
+ name: 'invalidateNext',
26542
+ outputs: [],
26543
+ stateMutability: 'nonpayable',
26544
+ type: 'function',
26545
+ },
26546
+ {
26547
+ inputs: [
26548
+ {
26549
+ internalType: 'address',
26550
+ name: 'account',
26551
+ type: 'address',
26552
+ },
26553
+ {
26554
+ internalType: 'uint256',
26555
+ name: 'amount',
26556
+ type: 'uint256',
26557
+ },
26558
+ ],
26559
+ name: 'mint',
26560
+ outputs: [
26561
+ {
26562
+ internalType: 'bool',
26563
+ name: '',
26564
+ type: 'bool',
26565
+ },
26566
+ ],
26567
+ stateMutability: 'nonpayable',
26568
+ type: 'function',
26569
+ },
26570
+ {
26571
+ inputs: [],
26572
+ name: 'name',
26573
+ outputs: [
26574
+ {
26575
+ internalType: 'string',
26576
+ name: '',
26577
+ type: 'string',
26578
+ },
26579
+ ],
26580
+ stateMutability: 'view',
26581
+ type: 'function',
26582
+ },
26583
+ {
26584
+ inputs: [],
26585
+ name: 'predicate',
26586
+ outputs: [
26587
+ {
26588
+ internalType: 'address',
26589
+ name: '',
26590
+ type: 'address',
26591
+ },
26592
+ ],
26593
+ stateMutability: 'view',
26594
+ type: 'function',
26595
+ },
26596
+ {
26597
+ inputs: [],
26598
+ name: 'rootToken',
26599
+ outputs: [
26600
+ {
26601
+ internalType: 'address',
26602
+ name: '',
26603
+ type: 'address',
26604
+ },
26605
+ ],
26606
+ stateMutability: 'view',
26607
+ type: 'function',
26608
+ },
26609
+ {
26610
+ inputs: [],
26611
+ name: 'symbol',
26612
+ outputs: [
26613
+ {
26614
+ internalType: 'string',
26615
+ name: '',
26616
+ type: 'string',
26617
+ },
26618
+ ],
26619
+ stateMutability: 'view',
26620
+ type: 'function',
26621
+ },
26622
+ {
26623
+ inputs: [],
26624
+ name: 'totalSupply',
26625
+ outputs: [
26626
+ {
26627
+ internalType: 'uint256',
26628
+ name: '',
26629
+ type: 'uint256',
26630
+ },
26631
+ ],
26632
+ stateMutability: 'view',
26633
+ type: 'function',
26634
+ },
26635
+ {
26636
+ inputs: [
26637
+ {
26638
+ internalType: 'address',
26639
+ name: 'to',
26640
+ type: 'address',
26641
+ },
26642
+ {
26643
+ internalType: 'uint256',
26644
+ name: 'amount',
26645
+ type: 'uint256',
26646
+ },
26647
+ ],
26648
+ name: 'transfer',
26649
+ outputs: [
26650
+ {
26651
+ internalType: 'bool',
26652
+ name: '',
26653
+ type: 'bool',
26654
+ },
26655
+ ],
26656
+ stateMutability: 'nonpayable',
26657
+ type: 'function',
26658
+ },
26659
+ {
26660
+ inputs: [
26661
+ {
26662
+ internalType: 'address',
26663
+ name: 'from',
26664
+ type: 'address',
26665
+ },
26666
+ {
26667
+ internalType: 'address',
26668
+ name: 'to',
26669
+ type: 'address',
26670
+ },
26671
+ {
26672
+ internalType: 'uint256',
26673
+ name: 'amount',
26674
+ type: 'uint256',
26675
+ },
26676
+ ],
26677
+ name: 'transferFrom',
26678
+ outputs: [
26679
+ {
26680
+ internalType: 'bool',
26681
+ name: '',
26682
+ type: 'bool',
26683
+ },
26684
+ ],
26685
+ stateMutability: 'nonpayable',
26686
+ type: 'function',
26687
+ },
26688
+ ];
26689
+
26690
+ /**
26691
+ * Represents a token bridge, which manages asset transfers between two chains.
26692
+ */
26693
+ class TokenBridge {
26694
+ /**
26695
+ * @property {BridgeConfiguration} config - The bridge configuration object.
26696
+ */
26697
+ config;
26698
+ /**
26699
+ * Constructs a TokenBridge instance.
26700
+ *
26701
+ * @param {BridgeConfiguration} config - The bridge configuration object.
26702
+ */
26703
+ constructor(config) {
26704
+ this.config = config;
26705
+ }
26706
+ /**
26707
+ * Retrieves the bridge fee for depositing a specific token, used to reimburse the bridge-relayer.
26708
+ * It is clipped from the deposit amount.
26709
+ *
26710
+ * @param {BridgeFeeRequest} req - The fee request object containing the token address for which the fee is required.
26711
+ * @returns {Promise<BridgeFeeResponse>} - A promise that resolves to an object containing the bridge fee for the specified token and a flag indicating if the token is bridgeable.
26712
+ * @throws {BridgeError} - If an error occurs during the fee retrieval, a BridgeError will be thrown with a specific error type.
26713
+ *
26714
+ * Possible BridgeError types include:
26715
+ * - INVALID_ADDRESS: The token address provided in the request is invalid.
26716
+ *
26717
+ * @example
26718
+ * const feeRequest = {
26719
+ * token: '0x123456...', // token
26720
+ * };
26721
+ *
26722
+ * @example
26723
+ * const feeRequest = {
26724
+ * token: 'NATIVE', // token
26725
+ * };
26726
+ *
26727
+ * bridgeSdk.getFee(feeRequest)
26728
+ * .then((feeResponse) => {
26729
+ * console.log('Bridgeable:', feeResponse.bridgeable);
26730
+ * console.log('Fee Amount:', feeResponse.feeAmount.toString());
26731
+ * })
26732
+ * .catch((error) => {
26733
+ * console.error('Error:', error.message);
26734
+ * });
26735
+ */
26736
+ async getFee(req) {
26737
+ this.validateChainConfiguration();
26738
+ if (req.token !== 'NATIVE' && !isAddress(req.token)) {
26739
+ throw new BridgeError(`token address ${req.token} is not a valid address`, BridgeErrorType.INVALID_ADDRESS);
26740
+ }
26741
+ return {
26742
+ bridgeable: true,
26743
+ feeAmount: BigNumber.from(0),
26744
+ };
26745
+ }
26746
+ /**
26747
+ * Retrieves the unsigned approval transaction for a deposit to the bridge.
26748
+ * Approval is required before depositing tokens to the bridge using
26749
+ *
26750
+ * @param {ApproveBridgeRequest} req - The approve bridge request object containing the depositor address, token address, and deposit amount.
26751
+ * @returns {Promise<ApproveBridgeResponse>} - A promise that resolves to an object containing the unsigned approval transaction and a flag indicating if the approval is required.
26752
+ * @throws {BridgeError} - If an error occurs during the transaction creation, a BridgeError will be thrown with a specific error type.
26753
+ *
26754
+ * Possible BridgeError types include:
26755
+ * - UNSUPPORTED_ERROR: The operation is not supported. Currently thrown when attempting to deposit native tokens.
26756
+ * - INVALID_ADDRESS: An Ethereum address provided in the request is invalid.
26757
+ * - INVALID_AMOUNT: The deposit amount provided in the request is invalid (less than or equal to 0).
26758
+ * - INTERNAL_ERROR: An unexpected error occurred during the execution, likely due to the bridge SDK implementation.
26759
+ * - PROVIDER_ERROR: An error occurred while interacting with the Ethereum provider. This includes issues calling the ERC20 smart contract
26760
+ *
26761
+ * @example
26762
+ * const approveRequest = {
26763
+ * depositorAddress: '0x123456...', // Depositor's Ethereum address
26764
+ * token: '0xabcdef...', // ERC20 token address
26765
+ * depositAmount: ethers.utils.parseUnits('100', 18), // Deposit amount in token's smallest unit (e.g., wei for Ether)
26766
+ * };
26767
+ *
26768
+ * bridgeSdk.getUnsignedApproveDepositBridgeTx(approveRequest)
26769
+ * .then((approveResponse) => {
26770
+ * if (approveResponse.unsignedTx) {
26771
+ * // Send the unsigned approval transaction to the depositor to sign and send
26772
+ * } else {
26773
+ * // No approval is required
26774
+ * }
26775
+ * })
26776
+ * .catch((error) => {
26777
+ * console.error('Error:', error.message);
26778
+ * });
26779
+ */
26780
+ async getUnsignedApproveDepositBridgeTx(req) {
26781
+ this.validateChainConfiguration();
26782
+ TokenBridge.validateDepositArgs(req.depositorAddress, req.depositAmount, req.token);
26783
+ // If the token is NATIVE, no approval is required
26784
+ if (req.token === 'NATIVE') {
26785
+ return {
26786
+ unsignedTx: null,
26787
+ };
26788
+ }
26789
+ const erc20Contract = await withBridgeError(async () => new Contract(req.token, ERC20$1, this.config.rootProvider), BridgeErrorType.PROVIDER_ERROR);
26790
+ // Get the current approved allowance of the RootERC20Predicate
26791
+ const rootERC20PredicateAllowance = await withBridgeError(() => erc20Contract.allowance(req.depositorAddress, this.config.bridgeContracts.rootChainERC20Predicate), BridgeErrorType.PROVIDER_ERROR);
26792
+ // If the allowance is greater than or equal to the deposit amount, no approval is required
26793
+ if (rootERC20PredicateAllowance.gte(req.depositAmount)) {
26794
+ return {
26795
+ unsignedTx: null,
26796
+ };
26797
+ }
26798
+ // Calculate the amount of tokens that need to be approved for deposit
26799
+ const approvalAmountRequired = req.depositAmount.sub(rootERC20PredicateAllowance);
26800
+ // Encode the approve function call data for the ERC20 contract
26801
+ const data = await withBridgeError(async () => erc20Contract.interface.encodeFunctionData('approve', [
26802
+ this.config.bridgeContracts.rootChainERC20Predicate,
26803
+ approvalAmountRequired,
26804
+ ]), BridgeErrorType.INTERNAL_ERROR);
26805
+ // Create the unsigned transaction for the approval
26806
+ const unsignedTx = {
26807
+ data,
26808
+ to: req.token,
26809
+ value: 0,
26810
+ from: req.depositorAddress,
26811
+ };
26812
+ return {
26813
+ unsignedTx,
26814
+ };
26815
+ }
26816
+ /**
26817
+ * Generates an unsigned deposit transaction for a user to sign and submit to the bridge.
26818
+ * Must be called after bridgeSdk.getUnsignedApproveDepositBridgeTx to ensure user has approved sufficient tokens for deposit.
26819
+ *
26820
+ * @param {BridgeDepositRequest} req - The deposit request object containing the required data for depositing tokens.
26821
+ * @returns {Promise<BridgeDepositResponse>} - A promise that resolves to an object containing the unsigned transaction data.
26822
+ * @throws {BridgeError} - If an error occurs during the generation of the unsigned transaction, a BridgeError will be thrown with a specific error type.
26823
+ *
26824
+ * Possible BridgeError types include:
26825
+ * - UNSUPPORTED_ERROR: The operation is not supported. Currently thrown when attempting to deposit native tokens.
26826
+ * - INVALID_ADDRESS: An Ethereum address provided in the request is invalid. This could be the depositor's, recipient's or the token's address.
26827
+ * - INVALID_AMOUNT: The deposit amount provided in the request is invalid (less than or equal to 0).
26828
+ * - INTERNAL_ERROR: An unexpected error occurred during the execution, likely due to the bridge SDK implementation.
26829
+ *
26830
+ * @example
26831
+ * const depositERC20Request = {
26832
+ * token: '0x123456...', // ERC20 token address
26833
+ * depositorAddress: '0xabcdef...', // User's wallet address
26834
+ * recipientAddress: '0x987654...', // Destination wallet address on the target chain
26835
+ * depositAmount: ethers.utils.parseUnits('100', 18), // Deposit amount in wei
26836
+ * };
26837
+ *
26838
+ * @example
26839
+ * const depositEtherTokenRequest = {
26840
+ * token: 'NATIVE',
26841
+ * depositorAddress: '0xabcdef...', // User's wallet address
26842
+ * recipientAddress: '0x987654...', // Destination wallet address on the target chain
26843
+ * depositAmount: ethers.utils.parseUnits('100', 18), // Deposit amount in wei
26844
+ * };
26845
+ *
26846
+ * bridgeSdk.getUnsignedDepositTx(depositRequest)
26847
+ * .then((depositResponse) => {
26848
+ * console.log(depositResponse.unsignedTx);
26849
+ * })
26850
+ * .catch((error) => {
26851
+ * console.error('Error:', error.message);
26852
+ * });
26853
+ */
26854
+ async getUnsignedDepositTx(req) {
26855
+ this.validateChainConfiguration();
26856
+ TokenBridge.validateDepositArgs(req.recipientAddress, req.depositAmount, req.token);
26857
+ const rootERC20PredicateContract = await withBridgeError(async () => {
26858
+ const contract = new Contract(this.config.bridgeContracts.rootChainERC20Predicate, ROOT_ERC20_PREDICATE);
26859
+ return contract;
26860
+ }, BridgeErrorType.INTERNAL_ERROR);
26861
+ // Convert the addresses to correct format addresses (e.g. prepend 0x if not already)
26862
+ const receipient = getAddress(req.recipientAddress);
26863
+ // Handle return if it is a native token
26864
+ if (req.token === 'NATIVE') {
26865
+ // Encode the function data into a payload
26866
+ const data = await withBridgeError(async () => rootERC20PredicateContract.interface.encodeFunctionData('depositNativeTo', [receipient]), BridgeErrorType.INTERNAL_ERROR);
26867
+ return {
26868
+ unsignedTx: {
26869
+ data,
26870
+ to: this.config.bridgeContracts.rootChainERC20Predicate,
26871
+ value: req.depositAmount,
26872
+ },
26873
+ };
26874
+ }
26875
+ // Handle return for ERC20
26876
+ const token = getAddress(req.token);
26877
+ // Encode the function data into a payload
26878
+ const data = await withBridgeError(async () => rootERC20PredicateContract.interface.encodeFunctionData('depositTo', [token, receipient, req.depositAmount]), BridgeErrorType.INTERNAL_ERROR);
26879
+ return {
26880
+ unsignedTx: {
26881
+ data,
26882
+ to: this.config.bridgeContracts.rootChainERC20Predicate,
26883
+ value: 0,
26884
+ },
26885
+ };
25136
26886
  }
25137
26887
  /**
25138
26888
  * Waits for the deposit transaction to be confirmed and synced from the root chain to the child chain.
25139
26889
  *
25140
- * @param {WaitForRequest} req - The wait for request object containing the transaction hash.
25141
- * @returns {Promise<WaitForResponse>} - A promise that resolves to an object containing the status of the deposit transaction.
26890
+ * @param {WaitForDepositRequest} req - The wait for request object containing the transaction hash.
26891
+ * @returns {Promise<WaitForDepositResponse>} - A promise that resolves to an object containing the status of the deposit transaction.
25142
26892
  * @throws {BridgeError} - If an error occurs during the transaction confirmation or state sync, a BridgeError will be thrown with a specific error type.
25143
26893
  *
25144
26894
  * Possible BridgeError types include:
@@ -25159,6 +26909,7 @@ class TokenBridge {
25159
26909
  * });
25160
26910
  */
25161
26911
  async waitForDeposit(req) {
26912
+ this.validateChainConfiguration();
25162
26913
  const rootTxReceipt = await withBridgeError(async () => this.config.rootProvider.waitForTransaction(req.transactionHash, this.config.rootChainFinalityBlocks), BridgeErrorType.PROVIDER_ERROR);
25163
26914
  // Throw an error if the transaction was reverted
25164
26915
  if (rootTxReceipt.status !== 1) {
@@ -25167,7 +26918,7 @@ class TokenBridge {
25167
26918
  // Get the state sync ID from the transaction receipt
25168
26919
  const stateSyncID = await withBridgeError(async () => this.getRootStateSyncID(rootTxReceipt), BridgeErrorType.PROVIDER_ERROR);
25169
26920
  // Get the block for the timestamp
25170
- const rootBlock = await this.config.rootProvider.getBlock(rootTxReceipt.blockNumber);
26921
+ const rootBlock = await withBridgeError(async () => await this.config.rootProvider.getBlock(rootTxReceipt.blockNumber), BridgeErrorType.PROVIDER_ERROR, `failed to query block ${rootTxReceipt.blockNumber} on rootchain`);
25171
26922
  // Get the minimum block on childchain which corresponds with the timestamp on rootchain
25172
26923
  const minBlockRange = await withBridgeError(async () => getBlockNumberClosestToTimestamp(this.config.childProvider, rootBlock.timestamp, this.config.blockTime, this.config.clockInaccuracy), BridgeErrorType.PROVIDER_ERROR);
25173
26924
  // Get the upper bound for which we expect the StateSync event to occur
@@ -25178,6 +26929,271 @@ class TokenBridge {
25178
26929
  status: result,
25179
26930
  };
25180
26931
  }
26932
+ /**
26933
+ * Retrieves the corresponding child token address for a given root token address.
26934
+ * This function is used to map a root token to its child token in the context of a bridging system between chains.
26935
+ * If the token is native, a special key is used to represent it.
26936
+ *
26937
+ * @param {RootTokenToChildTokenRequest} req - The request object containing the root token address or the string 'NATIVE'.
26938
+ * @returns {Promise<RootTokenToChildTokenResponse>} - A promise that resolves to an object containing the child token address.
26939
+ * @throws {BridgeError} - If an error occurs during the query, a BridgeError will be thrown with a specific error type.
26940
+ *
26941
+ * Possible BridgeError types include:
26942
+ * - INVALID_ADDRESS: If the Ethereum address provided in the request is invalid.
26943
+ * - PROVIDER_ERROR: If there's an error in querying the rootTokenToChildToken mapping.
26944
+ * - INTERNAL_ERROR: An unexpected error occurred during the execution.
26945
+ *
26946
+ * @example
26947
+ * const request = {
26948
+ * rootToken: '0x123456...', // Root token address or 'NATIVE'
26949
+ * };
26950
+ *
26951
+ * bridgeSdk.rootTokenToChildToken(request)
26952
+ * .then((response) => {
26953
+ * console.log(response.childToken); // Child token address
26954
+ * })
26955
+ * .catch((error) => {
26956
+ * console.error('Error:', error.message);
26957
+ * });
26958
+ */
26959
+ async rootTokenToChildToken(req) {
26960
+ // Validate the chain configuration to ensure proper setup
26961
+ this.validateChainConfiguration();
26962
+ // If the root token is native, use the native token key; otherwise, use the provided root token address
26963
+ const reqTokenAddress = (req.rootToken === 'NATIVE') ? NATIVE_TOKEN_BRIDGE_KEY : req.rootToken;
26964
+ // Validate the request token address
26965
+ if (!isAddress(reqTokenAddress)) {
26966
+ throw new BridgeError(`recipient address ${reqTokenAddress} is not a valid address`, BridgeErrorType.INVALID_ADDRESS);
26967
+ }
26968
+ // Create an instance of the root ERC20 predicate contract
26969
+ const childTokenAddress = await withBridgeError(async () => {
26970
+ const rootERC20Predicate = new Contract(this.config.bridgeContracts.rootChainERC20Predicate, ROOT_ERC20_PREDICATE, this.config.rootProvider);
26971
+ return await rootERC20Predicate.rootTokenToChildToken(reqTokenAddress);
26972
+ }, BridgeErrorType.PROVIDER_ERROR, 'failed to query rootTokenToChildToken mapping');
26973
+ // Return the child token address
26974
+ return {
26975
+ childToken: childTokenAddress,
26976
+ };
26977
+ }
26978
+ /**
26979
+ * Retrieves the corresponding root token address for a given child token address.
26980
+ * This function is used to map a child token back to its root token in the context of a bridging system between chains.
26981
+ *
26982
+ * If the root token address matches the address designated for the native token, the method will return 'NATIVE'.
26983
+ *
26984
+ * @param {ChildTokenToRootTokenRequest} req - The request object containing the child token address.
26985
+ * @returns {Promise<ChildTokenToRootTokenResponse>} - A promise that resolves to an object containing the root token address.
26986
+ * @throws {BridgeError} - If an error occurs during the query, a BridgeError will be thrown with a specific error type.
26987
+ *
26988
+ * Possible BridgeError types include:
26989
+ * - PROVIDER_ERROR: If there's an error in querying the root token from the child token contract.
26990
+ * - INVALID_TOKEN: If the token being withdrawed is not a valid bridgeable token
26991
+ *
26992
+ * @example
26993
+ * const request = {
26994
+ * childToken: '0x123456...', // Child token address
26995
+ * };
26996
+ *
26997
+ * bridgeSdk.childTokenToRootToken(request)
26998
+ * .then((response) => {
26999
+ * console.log(response.rootToken); // Outputs: 'NATIVE' or Root token address
27000
+ * })
27001
+ * .catch((error) => {
27002
+ * console.error('Error:', error.message);
27003
+ * });
27004
+ */
27005
+ async childTokenToRootToken(req) {
27006
+ // Validate the chain configuration to ensure proper setup
27007
+ this.validateChainConfiguration();
27008
+ // Query the corresponding root token address using the child token contract
27009
+ const rootToken = await withBridgeError(async () => {
27010
+ // Create an instance of the child token contract using the given child token address
27011
+ const childToken = new Contract(req.childToken, CHILD_ERC20, this.config.childProvider);
27012
+ return await childToken.rootToken();
27013
+ }, BridgeErrorType.PROVIDER_ERROR, 'failed to query the root token from the child token contract');
27014
+ // Check if the rootToken address is the designated native token address. If it is, return 'NATIVE'. Else, return the root token address.
27015
+ return {
27016
+ rootToken: (rootToken === NATIVE_TOKEN_BRIDGE_KEY) ? 'NATIVE' : rootToken,
27017
+ };
27018
+ }
27019
+ /**
27020
+ * Generates an unsigned transaction that a user can use to initiate a token withdrawal from the bridge.
27021
+ * The user must sign and submit this transaction to execute the withdrawal.
27022
+ *
27023
+ * @param {BridgeWithdrawRequest} req - The withdrawal request object containing the necessary data for withdrawing tokens.
27024
+ * @returns {Promise<BridgeWithdrawResponse>} - A promise that resolves to an object containing the unsigned transaction data.
27025
+ *
27026
+ * @throws {BridgeError} - If an error occurs during the generation of the unsigned transaction, a BridgeError will be thrown with a specific error type.
27027
+ * Possible BridgeError types include:
27028
+ * - INVALID_ADDRESS: The Ethereum address provided in the request is invalid. This could be the user's address or the token's address.
27029
+ * - INVALID_AMOUNT: The withdrawal amount provided in the request is invalid (less than or equal to 0).
27030
+ * - PROVIDER_ERROR: An error occurred when interacting with the Ethereum provider, likely due to a network or connectivity issue.
27031
+ * - INTERNAL_ERROR: An unexpected error occurred during the execution, likely due to the bridge SDK implementation.
27032
+ *
27033
+ * @example
27034
+ * const withdrawRequest = {
27035
+ * token: '0x123456...', // ERC20 token address
27036
+ * recipientAddress: '0xabcdef...', // Address to receive the withdrawn tokens
27037
+ * withdrawAmount: ethers.utils.parseUnits('100', 18), // Withdraw amount in wei
27038
+ * };
27039
+ *
27040
+ * bridgeSdk.getUnsignedWithdrawTx(withdrawRequest)
27041
+ * .then((withdrawalResponse) => {
27042
+ * console.log(withdrawalResponse.unsignedTx);
27043
+ * })
27044
+ * .catch((error) => {
27045
+ * console.error('Error:', error.message);
27046
+ * });
27047
+ */
27048
+ async getUnsignedWithdrawTx(req) {
27049
+ // Ensure the configuration of chains is valid.
27050
+ this.validateChainConfiguration();
27051
+ // Validate the recipient address, withdrawal amount, and token.
27052
+ TokenBridge.validateWithdrawArgs(req.recipientAddress, req.withdrawAmount, req.token);
27053
+ // Create a contract instance for interacting with the ChildERC20Predicate
27054
+ const childERC20PredicateContract = await withBridgeError(async () => {
27055
+ const contract = new Contract(this.config.bridgeContracts.childChainERC20Predicate, CHILD_ERC20_PREDICATE);
27056
+ return contract;
27057
+ }, BridgeErrorType.INTERNAL_ERROR);
27058
+ // Encode the withdrawTo function call data for the ERC20 contract
27059
+ const data = await withBridgeError(async () => childERC20PredicateContract.interface.encodeFunctionData('withdrawTo', [
27060
+ req.token,
27061
+ req.recipientAddress,
27062
+ req.withdrawAmount,
27063
+ ]), BridgeErrorType.INTERNAL_ERROR);
27064
+ // Construct the unsigned transaction for the withdrawal
27065
+ return {
27066
+ unsignedTx: {
27067
+ data,
27068
+ to: this.config.bridgeContracts.childChainERC20Predicate,
27069
+ value: 0,
27070
+ },
27071
+ };
27072
+ }
27073
+ /**
27074
+ * Waits for the withdrawal transaction to be confirmed in the root chain by continuously polling until the transaction is included in a checkpoint.
27075
+ * This function is intended to be used after executing a withdrawal transaction.
27076
+ *
27077
+ * @param {WaitForWithdrawalRequest} req - The request object containing the transaction hash of the withdrawal transaction.
27078
+ * @returns {Promise<WaitForWithdrawalResponse>} - A promise that resolves to an empty object once the withdrawal transaction has been confirmed in the root chain.
27079
+ *
27080
+ * @throws {BridgeError} - If an error occurs during the waiting process, a BridgeError will be thrown with a specific error type.
27081
+ * Possible BridgeError types include:
27082
+ * - PROVIDER_ERROR: An error occurred when interacting with the Ethereum provider, likely due to a network or connectivity issue.
27083
+ *
27084
+ * @example
27085
+ * const waitForWithdrawalRequest = {
27086
+ * transactionHash: '0x123456...', // Transaction hash of the withdrawal transaction
27087
+ * };
27088
+ *
27089
+ * bridgeSdk.waitForWithdrawal(waitForWithdrawalRequest)
27090
+ * .then(() => {
27091
+ * console.log('Withdrawal transaction has been confirmed in the root chain.');
27092
+ * })
27093
+ * .catch((error) => {
27094
+ * console.error('Error:', error.message);
27095
+ * });
27096
+ */
27097
+ async waitForWithdrawal(req) {
27098
+ // Ensure the configuration of chains is valid.
27099
+ this.validateChainConfiguration();
27100
+ // Helper function to pause execution for a specified interval
27101
+ const pause = () => new Promise((resolve) => {
27102
+ setTimeout(resolve, this.config.pollInterval);
27103
+ });
27104
+ await withBridgeError(async () => {
27105
+ // Fetch the receipt of the withdrawal transaction
27106
+ const transactionReceipt = await this.config.childProvider.getTransactionReceipt(req.transactionHash);
27107
+ // Fetch the block in which the withdrawal transaction was included
27108
+ const block = await this.config.childProvider.getBlock(transactionReceipt.blockNumber);
27109
+ // Decode the extra data field from the block header
27110
+ const decodedExtraData = decodeExtraData(block.extraData);
27111
+ // Instantiate the checkpoint manager contract
27112
+ const checkpointManager = new Contract(this.config.bridgeContracts.rootChainCheckpointManager, CHECKPOINT_MANAGER, this.config.rootProvider);
27113
+ // Recursive function to keep checking for the child deposit event
27114
+ const waitForRootEpoch = async () => {
27115
+ // Fetch the current checkpoint epoch from the root chain
27116
+ const currentEpoch = await checkpointManager.currentEpoch();
27117
+ // If the current epoch is greater than or equal to the epoch number of the checkpoint in which the withdrawal transaction was included, the withdrawal has been confirmed in the root chain
27118
+ if (currentEpoch >= decodedExtraData.checkpoint.epochNumber) {
27119
+ return null;
27120
+ }
27121
+ // Pause execution for a specified interval before checking again
27122
+ await pause();
27123
+ // Recursive call
27124
+ return waitForRootEpoch();
27125
+ };
27126
+ // Start waiting for the withdrawal transaction to be confirmed in the root chain
27127
+ await waitForRootEpoch();
27128
+ }, BridgeErrorType.PROVIDER_ERROR);
27129
+ // Return an empty object once the withdrawal transaction has been confirmed in the root chain
27130
+ return {};
27131
+ }
27132
+ /**
27133
+ * Creates an unsigned exit transaction which, when executed, will exit the assets from the child chain to the root chain.
27134
+ * This function should be used after a withdraw transaction has been executed on the child chain.
27135
+ * It should only be executed after `waitForWithdrawal` has completed successfully.
27136
+ *
27137
+ * @param {ExitRequest} req - The request object containing the transaction hash of the withdraw transaction.
27138
+ * @returns {Promise<ExitResponse>} - A promise that resolves to an object containing the unsigned exit transaction.
27139
+ *
27140
+ * @throws {BridgeError} - If an error occurs during the exit transaction creation process, a BridgeError will be thrown with a specific error type.
27141
+ * Possible BridgeError types include:
27142
+ * - PROVIDER_ERROR: An error occurred when interacting with the Ethereum provider, likely due to a network or connectivity issue.
27143
+ * - INVALID_TRANSACTION: The deposit transaction is invalid or the L2StateSynced event log does not match the expected format.
27144
+ * - INTERNAL_ERROR: An internal error occurred during the function call encoding process.
27145
+ *
27146
+ * @example
27147
+ * const exitRequest = {
27148
+ * transactionHash: '0x123456...', // Transaction hash of the deposit transaction
27149
+ * };
27150
+ *
27151
+ * bridgeSdk.getUnsignedExitTx(exitRequest)
27152
+ * .then((response) => {
27153
+ * console.log('Unsigned exit transaction:', response.unsignedTx);
27154
+ * })
27155
+ * .catch((error) => {
27156
+ * console.error('Error:', error.message);
27157
+ * });
27158
+ */
27159
+ async getUnsignedExitTx(req) {
27160
+ // Ensure the configuration of chains is valid
27161
+ this.validateChainConfiguration();
27162
+ // Fetch the receipt of the deposit transaction
27163
+ const txReceipt = await withBridgeError(async () => await this.config.childProvider.getTransactionReceipt(req.transactionHash), BridgeErrorType.PROVIDER_ERROR);
27164
+ // Filter out the StateSynced event log from the transaction receipt
27165
+ const stateSenderLogs = txReceipt.logs.filter((log) => log.address.toLowerCase() === L2_STATE_SENDER_ADDRESS);
27166
+ if (stateSenderLogs.length !== 1) {
27167
+ throw new BridgeError(`expected 1 log in tx ${txReceipt.transactionHash} from address ${L2_STATE_SENDER_ADDRESS}`, BridgeErrorType.INVALID_TRANSACTION);
27168
+ }
27169
+ // Parse the StateSynced event log
27170
+ const l2StateSyncEvent = await withBridgeError(async () => {
27171
+ const l2StateSenderInterface = new Interface(L2_STATE_SENDER);
27172
+ const event = l2StateSenderInterface.parseLog(stateSenderLogs[0]);
27173
+ // Throw an error if the event log doesn't match the expected format
27174
+ if (event.signature !== 'L2StateSynced(uint256,address,address,bytes)') {
27175
+ throw new Error(`expected L2StateSynced event in tx ${txReceipt.transactionHash}`);
27176
+ }
27177
+ return event;
27178
+ }, BridgeErrorType.INVALID_TRANSACTION);
27179
+ // Instantiate the exit helper contract
27180
+ const exitHelper = await withBridgeError(async () => new Contract(this.config.bridgeContracts.rootChainExitHelper, EXIT_HELPER, this.config.rootProvider), BridgeErrorType.PROVIDER_ERROR);
27181
+ // Generate the exit proof
27182
+ const exitProof = await withBridgeError(async () => this.config.childProvider.send('bridge_generateExitProof', [l2StateSyncEvent.args.id.toHexString()]), BridgeErrorType.PROVIDER_ERROR);
27183
+ // Encode the exit function call data
27184
+ const encodedExitTx = await withBridgeError(async () => {
27185
+ const exitEventEncoded = defaultAbiCoder.encode(['uint256', 'address', 'address', 'bytes'], l2StateSyncEvent.args);
27186
+ return exitHelper.interface.encodeFunctionData('exit', [exitProof.Metadata.CheckpointBlock, exitProof.Metadata.LeafIndex, exitEventEncoded, exitProof.Data]);
27187
+ }, BridgeErrorType.INTERNAL_ERROR);
27188
+ // Create the unsigned exit transaction
27189
+ const unsignedTx = {
27190
+ data: encodedExitTx,
27191
+ to: this.config.bridgeContracts.rootChainExitHelper,
27192
+ value: 0,
27193
+ };
27194
+ // Return the unsigned exit transaction
27195
+ return { unsignedTx };
27196
+ }
25181
27197
  async waitForChildStateSync(stateSyncID, interval, minBlockRange, maxBlockRange) {
25182
27198
  const childStateReceiver = new Contract(this.config.bridgeContracts.childChainStateReceiver, CHILD_STATE_RECEIVER, this.config.childProvider);
25183
27199
  // Set up an event filter for the StateSyncResult event
@@ -25228,57 +27244,47 @@ class TokenBridge {
25228
27244
  const stateSyncID = parseInt(stateSyncEvent.args.id, 10);
25229
27245
  return stateSyncID;
25230
27246
  }
25231
- // TODO: please fix this
25232
- // eslint-disable-next-line class-methods-use-this
25233
- async getFeeForToken(
25234
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
25235
- token) {
25236
- return BigNumber.from(0);
25237
- }
25238
- }
25239
-
25240
- /**
25241
- * @constant {string} ETH_SEPOLIA_CHAIN_ID - The chain ID for the Ethereum Sepolia testnet (EIP-155 compatible format).
25242
- */
25243
- const ETH_SEPOLIA_CHAIN_ID = 'eip155:11155111';
25244
- /**
25245
- * @constant {string} ETH_MAINNET_CHAIN_ID - The chain ID for the Ethereum mainnet (EIP-155 compatible format).
25246
- */
25247
- const ETH_MAINNET_CHAIN_ID = 'eip155:1';
25248
- /**
25249
- * @constant {string} ZKEVM_DEVNET_CHAIN_ID - The chain ID for the zkEVM devnet (EIP-155 compatible format).
25250
- */
25251
- const ZKEVM_DEVNET_CHAIN_ID = 'eip155:13423';
25252
- /**
25253
- /**
25254
- * @constant {string} ZKEVM_TESTNET_CHAIN_ID - The chain ID for the zkEVM testnet (EIP-155 compatible format).
25255
- */
25256
- const ZKEVM_TESTNET_CHAIN_ID = 'eip155:13372';
25257
- /**
25258
- * @constant {string} ZKEVM_MAINNET_CHAIN_ID - The chain ID for the zkEVM mainnet (EIP-155 compatible format).
25259
- */
25260
- const ZKEVM_MAINNET_CHAIN_ID = 'eip155:13371';
25261
- /**
25262
- * @constant {BridgeInstance} ETH_SEPOLIA_TO_ZKEVM_DEVNET - A bridge instance configuration for bridging between the Ethereum Sepolia testnet and the zkEVM devnet.
25263
- */
25264
- const ETH_SEPOLIA_TO_ZKEVM_DEVNET = {
25265
- rootChainID: ETH_SEPOLIA_CHAIN_ID,
25266
- childChainID: ZKEVM_DEVNET_CHAIN_ID,
25267
- };
25268
- /**
25269
- * @constant {BridgeInstance} ETH_SEPOLIA_TO_ZKEVM_TESTNET - A bridge instance configuration for bridging between the Ethereum Sepolia testnet and the zkEVM testnet.
25270
- */
25271
- const ETH_SEPOLIA_TO_ZKEVM_TESTNET = {
25272
- rootChainID: ETH_SEPOLIA_CHAIN_ID,
25273
- childChainID: ZKEVM_TESTNET_CHAIN_ID,
25274
- };
25275
- /**
25276
- * @constant {BridgeInstance} ETH_MAINNET_TO_ZKEVM_MAINNET - A bridge instance configuration for bridging between the Ethereum mainnet and the zkEVM mainnet.
25277
- */
25278
- const ETH_MAINNET_TO_ZKEVM_MAINNET = {
25279
- rootChainID: ETH_MAINNET_CHAIN_ID,
25280
- childChainID: ZKEVM_MAINNET_CHAIN_ID,
25281
- };
27247
+ static validateDepositArgs(depositorOrRecipientAddress, depositAmount, token) {
27248
+ if (!isAddress(depositorOrRecipientAddress)) {
27249
+ throw new BridgeError(`address ${depositorOrRecipientAddress} is not a valid address`, BridgeErrorType.INVALID_ADDRESS);
27250
+ }
27251
+ // The deposit amount cannot be <= 0
27252
+ if (depositAmount.isNegative() || depositAmount.isZero()) {
27253
+ throw new BridgeError(`deposit amount ${depositAmount.toString()} is invalid`, BridgeErrorType.INVALID_AMOUNT);
27254
+ }
27255
+ // If the token is not native, it must be a valid address
27256
+ if (token !== 'NATIVE' && !isAddress(token)) {
27257
+ throw new BridgeError(`token address ${token} is not a valid address`, BridgeErrorType.INVALID_ADDRESS);
27258
+ }
27259
+ }
27260
+ static validateWithdrawArgs(withdrawerOrRecipientAddress, withdrawAmount, token) {
27261
+ // Validate the withdrawer address
27262
+ if (!isAddress(withdrawerOrRecipientAddress)) {
27263
+ throw new BridgeError(`withdrawer address ${withdrawerOrRecipientAddress} is not a valid address`, BridgeErrorType.INVALID_ADDRESS);
27264
+ }
27265
+ // Validate the withdrawal amount. It cannot be zero or negative.
27266
+ if (withdrawAmount.isNegative() || withdrawAmount.isZero()) {
27267
+ throw new BridgeError(`withdraw amount ${withdrawAmount.toString()} is invalid`, BridgeErrorType.INVALID_AMOUNT);
27268
+ }
27269
+ // Check if the ERC20 Token is a valid address
27270
+ if (!isAddress(token)) {
27271
+ throw new BridgeError(`token address ${token} is not a valid address`, BridgeErrorType.INVALID_ADDRESS);
27272
+ }
27273
+ }
27274
+ // Query the rootchain and childchain providers to ensure the chainID is as expected by the SDK.
27275
+ // This is to prevent the SDK from being used on the wrong chain, especially after a chain reset.
27276
+ async validateChainConfiguration() {
27277
+ const errMessage = 'Please upgrade to the latest version of the Bridge SDK or provide valid configuration';
27278
+ const rootNetwork = await withBridgeError(async () => this.config.rootProvider.getNetwork(), BridgeErrorType.PROVIDER_ERROR);
27279
+ if (rootNetwork.chainId.toString() !== this.config.bridgeInstance.rootChainID) {
27280
+ throw new BridgeError(`Rootchain provider chainID ${rootNetwork.chainId} does not match expected chainID ${this.config.bridgeInstance.rootChainID}. ${errMessage}`, BridgeErrorType.UNSUPPORTED_ERROR);
27281
+ }
27282
+ const childNetwork = await this.config.childProvider.getNetwork();
27283
+ if (childNetwork.chainId.toString() !== this.config.bridgeInstance.childChainID) {
27284
+ throw new BridgeError(`Childchain provider chainID ${childNetwork.chainId} does not match expected chainID ${this.config.bridgeInstance.childChainID}. ${errMessage}`, BridgeErrorType.UNSUPPORTED_ERROR);
27285
+ }
27286
+ }
27287
+ }
25282
27288
 
25283
27289
  var Environment;
25284
27290
  (function (Environment) {
@@ -25306,20 +27312,26 @@ const SUPPORTED_BRIDGES_FOR_ENVIRONMENT = {
25306
27312
  */
25307
27313
  const CONTRACTS_FOR_BRIDGE = new Map()
25308
27314
  .set(ETH_SEPOLIA_TO_ZKEVM_DEVNET, {
25309
- rootChainERC20Predicate: '0xf0b3435411A74F1aeCBD0fd6D53a90D5227fEeba',
25310
- rootChainStateSender: '0x868097dbAcfD431F441d09D0e4D3B5eD3182E597',
27315
+ rootChainERC20Predicate: '0xAC0f2096732D40096B3356AD76ba60a2f02366c8',
27316
+ rootChainStateSender: '0xeA76fcCdD791A9c231CAda787ae7535c8a5E55B5',
27317
+ rootChainCheckpointManager: '0x321A466aa78F5957C6E2375114915EcD14DAdE44',
27318
+ rootChainExitHelper: '0x55cA8C418bbB0aC87414F9ea6FFC6a33860Cf967',
25311
27319
  childChainERC20Predicate: '0x0000000000000000000000000000000000001004',
25312
27320
  childChainStateReceiver: '0x0000000000000000000000000000000000001001',
25313
27321
  })
25314
27322
  .set(ETH_SEPOLIA_TO_ZKEVM_TESTNET, {
25315
27323
  rootChainERC20Predicate: '0x0C15a8359865867CdCC44f98b2F3fd5DF098C7E0',
25316
27324
  rootChainStateSender: '0x4C80001188db53dbc2eaAb32d5ef825feEedECA5',
27325
+ rootChainCheckpointManager: '0x0F3157bc91f66C350f87172bBB28d9417167074F',
27326
+ rootChainExitHelper: '0xB057A6C4e951a315E9f2DAe6d28B83cD0480e873',
25317
27327
  childChainERC20Predicate: '0x0000000000000000000000000000000000001004',
25318
27328
  childChainStateReceiver: '0x0000000000000000000000000000000000001001',
25319
27329
  })
25320
27330
  .set(ETH_MAINNET_TO_ZKEVM_MAINNET, {
25321
27331
  rootChainERC20Predicate: '0x',
25322
27332
  rootChainStateSender: '0x',
27333
+ rootChainCheckpointManager: '0x',
27334
+ rootChainExitHelper: '0x',
25323
27335
  childChainERC20Predicate: '0x',
25324
27336
  childChainStateReceiver: '0x',
25325
27337
  });
@@ -25509,7 +27521,7 @@ const calculateGasFee = (gasPriceInWei, gasUsed) => gasUsed.mul(gasPriceInWei);
25509
27521
  /* Autogenerated file. Do not edit manually. */
25510
27522
  /* tslint:disable */
25511
27523
  /* eslint-disable */
25512
- const _abi$2 = [
27524
+ const _abi$3 = [
25513
27525
  {
25514
27526
  constant: true,
25515
27527
  inputs: [],
@@ -25732,12 +27744,12 @@ const _abi$2 = [
25732
27744
  },
25733
27745
  ];
25734
27746
  let ERC20__factory$1 = class ERC20__factory {
25735
- static abi = _abi$2;
27747
+ static abi = _abi$3;
25736
27748
  static createInterface() {
25737
- return new utils$2.Interface(_abi$2);
27749
+ return new utils$2.Interface(_abi$3);
25738
27750
  }
25739
27751
  static connect(address, signerOrProvider) {
25740
- return new Contract$1(address, _abi$2, signerOrProvider);
27752
+ return new Contract$1(address, _abi$3, signerOrProvider);
25741
27753
  }
25742
27754
  };
25743
27755
 
@@ -25928,6 +27940,8 @@ const DEFAULT_MAX_HOPS = 2;
25928
27940
  const MAX_MAX_HOPS = 10;
25929
27941
  // a max hop of 1 will require a direct swap with no intermediary pools
25930
27942
  const MIN_MAX_HOPS = 1;
27943
+ // 10% maximum secondary fee
27944
+ const MAX_SECONDARY_FEE_BASIS_POINTS = 10000;
25931
27945
 
25932
27946
  const quoteReturnMapping = {
25933
27947
  // eslint-disable-next-line @typescript-eslint/naming-convention
@@ -25984,37 +27998,377 @@ const tokenInfoToUniswapToken = (tokenInfo) => new Token(tokenInfo.chainId, toke
25984
27998
  /* Autogenerated file. Do not edit manually. */
25985
27999
  /* tslint:disable */
25986
28000
  /* eslint-disable */
25987
- const _abi$1$1 = [
28001
+ const _abi$2 = [
25988
28002
  {
25989
28003
  inputs: [],
25990
28004
  name: "getCurrentBlockTimestamp",
25991
28005
  outputs: [
25992
28006
  {
25993
28007
  internalType: "uint256",
25994
- name: "timestamp",
28008
+ name: "timestamp",
28009
+ type: "uint256",
28010
+ },
28011
+ ],
28012
+ stateMutability: "view",
28013
+ type: "function",
28014
+ },
28015
+ {
28016
+ inputs: [
28017
+ {
28018
+ internalType: "address",
28019
+ name: "addr",
28020
+ type: "address",
28021
+ },
28022
+ ],
28023
+ name: "getEthBalance",
28024
+ outputs: [
28025
+ {
28026
+ internalType: "uint256",
28027
+ name: "balance",
28028
+ type: "uint256",
28029
+ },
28030
+ ],
28031
+ stateMutability: "view",
28032
+ type: "function",
28033
+ },
28034
+ {
28035
+ inputs: [
28036
+ {
28037
+ components: [
28038
+ {
28039
+ internalType: "address",
28040
+ name: "target",
28041
+ type: "address",
28042
+ },
28043
+ {
28044
+ internalType: "uint256",
28045
+ name: "gasLimit",
28046
+ type: "uint256",
28047
+ },
28048
+ {
28049
+ internalType: "bytes",
28050
+ name: "callData",
28051
+ type: "bytes",
28052
+ },
28053
+ ],
28054
+ internalType: "struct UniswapInterfaceMulticall.Call[]",
28055
+ name: "calls",
28056
+ type: "tuple[]",
28057
+ },
28058
+ ],
28059
+ name: "multicall",
28060
+ outputs: [
28061
+ {
28062
+ internalType: "uint256",
28063
+ name: "blockNumber",
28064
+ type: "uint256",
28065
+ },
28066
+ {
28067
+ components: [
28068
+ {
28069
+ internalType: "bool",
28070
+ name: "success",
28071
+ type: "bool",
28072
+ },
28073
+ {
28074
+ internalType: "uint256",
28075
+ name: "gasUsed",
28076
+ type: "uint256",
28077
+ },
28078
+ {
28079
+ internalType: "bytes",
28080
+ name: "returnData",
28081
+ type: "bytes",
28082
+ },
28083
+ ],
28084
+ internalType: "struct UniswapInterfaceMulticall.Result[]",
28085
+ name: "returnData",
28086
+ type: "tuple[]",
28087
+ },
28088
+ ],
28089
+ stateMutability: "nonpayable",
28090
+ type: "function",
28091
+ },
28092
+ ];
28093
+ const _bytecode$2$1 = "0x608060405234801561001057600080fd5b50610567806100206000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c80630f28c97d146100465780631749e1e3146100645780634d2301cc14610085575b600080fd5b61004e610098565b60405161005b919061041f565b60405180910390f35b6100776100723660046102a7565b61009c565b60405161005b929190610428565b61004e610093366004610286565b610220565b4290565b8051439060609067ffffffffffffffff811180156100b957600080fd5b506040519080825280602002602001820160405280156100f357816020015b6100e061023a565b8152602001906001900390816100d85790505b50905060005b835181101561021a57600080600086848151811061011357fe5b60200260200101516000015187858151811061012b57fe5b60200260200101516020015188868151811061014357fe5b60200260200101516040015192509250925060005a90506000808573ffffffffffffffffffffffffffffffffffffffff1685856040516101839190610403565b60006040518083038160008787f1925050503d80600081146101c1576040519150601f19603f3d011682016040523d82523d6000602084013e6101c6565b606091505b509150915060005a8403905060405180606001604052808415158152602001828152602001838152508989815181106101fb57fe5b60200260200101819052505050505050505080806001019150506100f9565b50915091565b73ffffffffffffffffffffffffffffffffffffffff163190565b604051806060016040528060001515815260200160008152602001606081525090565b803573ffffffffffffffffffffffffffffffffffffffff8116811461028157600080fd5b919050565b600060208284031215610297578081fd5b6102a08261025d565b9392505050565b600060208083850312156102b9578182fd5b823567ffffffffffffffff808211156102d0578384fd5b818501915085601f8301126102e3578384fd5b8135818111156102ef57fe5b6102fc8485830201610506565b81815284810190848601875b848110156103f457813587017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0606081838f03011215610346578a8bfd5b60408051606081018181108b8211171561035c57fe5b8252610369848d0161025d565b8152818401358c82015260608401358a811115610384578d8efd5b8085019450508e603f850112610398578c8dfd5b8b8401358a8111156103a657fe5b6103b68d85601f84011601610506565b93508084528f838287010111156103cb578d8efd5b808386018e86013783018c018d9052908101919091528552509287019290870190600101610308565b50909998505050505050505050565b6000825161041581846020870161052a565b9190910192915050565b90815260200190565b600060408083018584526020828186015281865180845260609350838701915083838202880101838901875b838110156104f6578983037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa001855281518051151584528681015187850152880151888401889052805188850181905260806104b582828801858c0161052a565b96880196601f919091017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01694909401909301925090850190600101610454565b50909a9950505050505050505050565b60405181810167ffffffffffffffff8111828210171561052257fe5b604052919050565b60005b8381101561054557818101518382015260200161052d565b83811115610554576000848401525b5050505056fea164736f6c6343000706000a";
28094
+ const isSuperArgs$2$1 = (xs) => xs.length > 1;
28095
+ class Multicall__factory extends ContractFactory {
28096
+ constructor(...args) {
28097
+ if (isSuperArgs$2$1(args)) {
28098
+ super(...args);
28099
+ }
28100
+ else {
28101
+ super(_abi$2, _bytecode$2$1, args[0]);
28102
+ }
28103
+ }
28104
+ deploy(overrides) {
28105
+ return super.deploy(overrides || {});
28106
+ }
28107
+ getDeployTransaction(overrides) {
28108
+ return super.getDeployTransaction(overrides || {});
28109
+ }
28110
+ attach(address) {
28111
+ return super.attach(address);
28112
+ }
28113
+ connect(signer) {
28114
+ return super.connect(signer);
28115
+ }
28116
+ static bytecode = _bytecode$2$1;
28117
+ static abi = _abi$2;
28118
+ static createInterface() {
28119
+ return new utils$2.Interface(_abi$2);
28120
+ }
28121
+ static connect(address, signerOrProvider) {
28122
+ return new Contract$1(address, _abi$2, signerOrProvider);
28123
+ }
28124
+ }
28125
+
28126
+ /* Autogenerated file. Do not edit manually. */
28127
+ /* tslint:disable */
28128
+ /* eslint-disable */
28129
+ const _abi$1$1 = [
28130
+ {
28131
+ inputs: [
28132
+ {
28133
+ internalType: "address",
28134
+ name: "_uniRouter",
28135
+ type: "address",
28136
+ },
28137
+ ],
28138
+ stateMutability: "nonpayable",
28139
+ type: "constructor",
28140
+ },
28141
+ {
28142
+ anonymous: false,
28143
+ inputs: [
28144
+ {
28145
+ indexed: true,
28146
+ internalType: "address",
28147
+ name: "feeToken",
28148
+ type: "address",
28149
+ },
28150
+ {
28151
+ indexed: true,
28152
+ internalType: "address",
28153
+ name: "feePayer",
28154
+ type: "address",
28155
+ },
28156
+ {
28157
+ indexed: true,
28158
+ internalType: "address",
28159
+ name: "feeRecipient",
28160
+ type: "address",
28161
+ },
28162
+ {
28163
+ indexed: false,
28164
+ internalType: "uint256",
28165
+ name: "feeAmount",
28166
+ type: "uint256",
28167
+ },
28168
+ ],
28169
+ name: "FeeTaken",
28170
+ type: "event",
28171
+ },
28172
+ {
28173
+ anonymous: false,
28174
+ inputs: [
28175
+ {
28176
+ indexed: true,
28177
+ internalType: "address",
28178
+ name: "previousOwner",
28179
+ type: "address",
28180
+ },
28181
+ {
28182
+ indexed: true,
28183
+ internalType: "address",
28184
+ name: "newOwner",
28185
+ type: "address",
28186
+ },
28187
+ ],
28188
+ name: "OwnershipTransferred",
28189
+ type: "event",
28190
+ },
28191
+ {
28192
+ anonymous: false,
28193
+ inputs: [
28194
+ {
28195
+ indexed: false,
28196
+ internalType: "address",
28197
+ name: "account",
28198
+ type: "address",
28199
+ },
28200
+ ],
28201
+ name: "Paused",
28202
+ type: "event",
28203
+ },
28204
+ {
28205
+ anonymous: false,
28206
+ inputs: [
28207
+ {
28208
+ indexed: false,
28209
+ internalType: "address",
28210
+ name: "account",
28211
+ type: "address",
28212
+ },
28213
+ ],
28214
+ name: "Unpaused",
28215
+ type: "event",
28216
+ },
28217
+ {
28218
+ inputs: [],
28219
+ name: "BASIS_POINT_PRECISION",
28220
+ outputs: [
28221
+ {
28222
+ internalType: "uint16",
28223
+ name: "",
28224
+ type: "uint16",
28225
+ },
28226
+ ],
28227
+ stateMutability: "view",
28228
+ type: "function",
28229
+ },
28230
+ {
28231
+ inputs: [],
28232
+ name: "MAX_SERVICE_FEE",
28233
+ outputs: [
28234
+ {
28235
+ internalType: "uint16",
28236
+ name: "",
28237
+ type: "uint16",
28238
+ },
28239
+ ],
28240
+ stateMutability: "view",
28241
+ type: "function",
28242
+ },
28243
+ {
28244
+ inputs: [
28245
+ {
28246
+ components: [
28247
+ {
28248
+ internalType: "address",
28249
+ name: "recipient",
28250
+ type: "address",
28251
+ },
28252
+ {
28253
+ internalType: "uint16",
28254
+ name: "feePrcntBasisPoints",
28255
+ type: "uint16",
28256
+ },
28257
+ ],
28258
+ internalType: "struct ISecondaryFee.ServiceFeeParams[]",
28259
+ name: "serviceFee",
28260
+ type: "tuple[]",
28261
+ },
28262
+ {
28263
+ components: [
28264
+ {
28265
+ internalType: "address",
28266
+ name: "tokenIn",
28267
+ type: "address",
28268
+ },
28269
+ {
28270
+ internalType: "address",
28271
+ name: "tokenOut",
28272
+ type: "address",
28273
+ },
28274
+ {
28275
+ internalType: "uint24",
28276
+ name: "fee",
28277
+ type: "uint24",
28278
+ },
28279
+ {
28280
+ internalType: "address",
28281
+ name: "recipient",
28282
+ type: "address",
28283
+ },
28284
+ {
28285
+ internalType: "uint256",
28286
+ name: "amountIn",
28287
+ type: "uint256",
28288
+ },
28289
+ {
28290
+ internalType: "uint256",
28291
+ name: "amountOutMinimum",
28292
+ type: "uint256",
28293
+ },
28294
+ {
28295
+ internalType: "uint160",
28296
+ name: "sqrtPriceLimitX96",
28297
+ type: "uint160",
28298
+ },
28299
+ ],
28300
+ internalType: "struct IV3SwapRouter.ExactInputSingleParams",
28301
+ name: "params",
28302
+ type: "tuple",
28303
+ },
28304
+ ],
28305
+ name: "exactInputSingleWithServiceFee",
28306
+ outputs: [
28307
+ {
28308
+ internalType: "uint256",
28309
+ name: "amountOut",
25995
28310
  type: "uint256",
25996
28311
  },
25997
28312
  ],
25998
- stateMutability: "view",
28313
+ stateMutability: "payable",
25999
28314
  type: "function",
26000
28315
  },
26001
28316
  {
26002
28317
  inputs: [
26003
28318
  {
26004
- internalType: "address",
26005
- name: "addr",
26006
- type: "address",
28319
+ components: [
28320
+ {
28321
+ internalType: "address",
28322
+ name: "recipient",
28323
+ type: "address",
28324
+ },
28325
+ {
28326
+ internalType: "uint16",
28327
+ name: "feePrcntBasisPoints",
28328
+ type: "uint16",
28329
+ },
28330
+ ],
28331
+ internalType: "struct ISecondaryFee.ServiceFeeParams[]",
28332
+ name: "serviceFee",
28333
+ type: "tuple[]",
28334
+ },
28335
+ {
28336
+ components: [
28337
+ {
28338
+ internalType: "bytes",
28339
+ name: "path",
28340
+ type: "bytes",
28341
+ },
28342
+ {
28343
+ internalType: "address",
28344
+ name: "recipient",
28345
+ type: "address",
28346
+ },
28347
+ {
28348
+ internalType: "uint256",
28349
+ name: "amountIn",
28350
+ type: "uint256",
28351
+ },
28352
+ {
28353
+ internalType: "uint256",
28354
+ name: "amountOutMinimum",
28355
+ type: "uint256",
28356
+ },
28357
+ ],
28358
+ internalType: "struct IV3SwapRouter.ExactInputParams",
28359
+ name: "params",
28360
+ type: "tuple",
26007
28361
  },
26008
28362
  ],
26009
- name: "getEthBalance",
28363
+ name: "exactInputWithServiceFee",
26010
28364
  outputs: [
26011
28365
  {
26012
28366
  internalType: "uint256",
26013
- name: "balance",
28367
+ name: "amountOut",
26014
28368
  type: "uint256",
26015
28369
  },
26016
28370
  ],
26017
- stateMutability: "view",
28371
+ stateMutability: "payable",
26018
28372
  type: "function",
26019
28373
  },
26020
28374
  {
@@ -26023,62 +28377,251 @@ const _abi$1$1 = [
26023
28377
  components: [
26024
28378
  {
26025
28379
  internalType: "address",
26026
- name: "target",
28380
+ name: "recipient",
28381
+ type: "address",
28382
+ },
28383
+ {
28384
+ internalType: "uint16",
28385
+ name: "feePrcntBasisPoints",
28386
+ type: "uint16",
28387
+ },
28388
+ ],
28389
+ internalType: "struct ISecondaryFee.ServiceFeeParams[]",
28390
+ name: "serviceFee",
28391
+ type: "tuple[]",
28392
+ },
28393
+ {
28394
+ components: [
28395
+ {
28396
+ internalType: "address",
28397
+ name: "tokenIn",
28398
+ type: "address",
28399
+ },
28400
+ {
28401
+ internalType: "address",
28402
+ name: "tokenOut",
28403
+ type: "address",
28404
+ },
28405
+ {
28406
+ internalType: "uint24",
28407
+ name: "fee",
28408
+ type: "uint24",
28409
+ },
28410
+ {
28411
+ internalType: "address",
28412
+ name: "recipient",
26027
28413
  type: "address",
26028
28414
  },
26029
28415
  {
26030
28416
  internalType: "uint256",
26031
- name: "gasLimit",
28417
+ name: "amountOut",
26032
28418
  type: "uint256",
26033
28419
  },
26034
28420
  {
26035
- internalType: "bytes",
26036
- name: "callData",
26037
- type: "bytes",
28421
+ internalType: "uint256",
28422
+ name: "amountInMaximum",
28423
+ type: "uint256",
28424
+ },
28425
+ {
28426
+ internalType: "uint160",
28427
+ name: "sqrtPriceLimitX96",
28428
+ type: "uint160",
26038
28429
  },
26039
28430
  ],
26040
- internalType: "struct UniswapInterfaceMulticall.Call[]",
26041
- name: "calls",
26042
- type: "tuple[]",
28431
+ internalType: "struct IV3SwapRouter.ExactOutputSingleParams",
28432
+ name: "params",
28433
+ type: "tuple",
26043
28434
  },
26044
28435
  ],
26045
- name: "multicall",
28436
+ name: "exactOutputSingleWithServiceFee",
26046
28437
  outputs: [
26047
28438
  {
26048
28439
  internalType: "uint256",
26049
- name: "blockNumber",
28440
+ name: "amountIn",
26050
28441
  type: "uint256",
26051
28442
  },
28443
+ ],
28444
+ stateMutability: "payable",
28445
+ type: "function",
28446
+ },
28447
+ {
28448
+ inputs: [
26052
28449
  {
26053
28450
  components: [
26054
28451
  {
26055
- internalType: "bool",
26056
- name: "success",
26057
- type: "bool",
28452
+ internalType: "address",
28453
+ name: "recipient",
28454
+ type: "address",
26058
28455
  },
26059
28456
  {
26060
- internalType: "uint256",
26061
- name: "gasUsed",
26062
- type: "uint256",
28457
+ internalType: "uint16",
28458
+ name: "feePrcntBasisPoints",
28459
+ type: "uint16",
26063
28460
  },
28461
+ ],
28462
+ internalType: "struct ISecondaryFee.ServiceFeeParams[]",
28463
+ name: "serviceFee",
28464
+ type: "tuple[]",
28465
+ },
28466
+ {
28467
+ components: [
26064
28468
  {
26065
28469
  internalType: "bytes",
26066
- name: "returnData",
28470
+ name: "path",
26067
28471
  type: "bytes",
26068
28472
  },
28473
+ {
28474
+ internalType: "address",
28475
+ name: "recipient",
28476
+ type: "address",
28477
+ },
28478
+ {
28479
+ internalType: "uint256",
28480
+ name: "amountOut",
28481
+ type: "uint256",
28482
+ },
28483
+ {
28484
+ internalType: "uint256",
28485
+ name: "amountInMaximum",
28486
+ type: "uint256",
28487
+ },
26069
28488
  ],
26070
- internalType: "struct UniswapInterfaceMulticall.Result[]",
26071
- name: "returnData",
26072
- type: "tuple[]",
28489
+ internalType: "struct IV3SwapRouter.ExactOutputParams",
28490
+ name: "params",
28491
+ type: "tuple",
28492
+ },
28493
+ ],
28494
+ name: "exactOutputWithServiceFee",
28495
+ outputs: [
28496
+ {
28497
+ internalType: "uint256",
28498
+ name: "amountIn",
28499
+ type: "uint256",
28500
+ },
28501
+ ],
28502
+ stateMutability: "payable",
28503
+ type: "function",
28504
+ },
28505
+ {
28506
+ inputs: [
28507
+ {
28508
+ internalType: "uint256",
28509
+ name: "deadline",
28510
+ type: "uint256",
28511
+ },
28512
+ {
28513
+ internalType: "bytes[]",
28514
+ name: "data",
28515
+ type: "bytes[]",
28516
+ },
28517
+ ],
28518
+ name: "multicall",
28519
+ outputs: [
28520
+ {
28521
+ internalType: "bytes[]",
28522
+ name: "",
28523
+ type: "bytes[]",
28524
+ },
28525
+ ],
28526
+ stateMutability: "payable",
28527
+ type: "function",
28528
+ },
28529
+ {
28530
+ inputs: [
28531
+ {
28532
+ internalType: "bytes[]",
28533
+ name: "data",
28534
+ type: "bytes[]",
28535
+ },
28536
+ ],
28537
+ name: "multicall",
28538
+ outputs: [
28539
+ {
28540
+ internalType: "bytes[]",
28541
+ name: "results",
28542
+ type: "bytes[]",
28543
+ },
28544
+ ],
28545
+ stateMutability: "nonpayable",
28546
+ type: "function",
28547
+ },
28548
+ {
28549
+ inputs: [],
28550
+ name: "owner",
28551
+ outputs: [
28552
+ {
28553
+ internalType: "address",
28554
+ name: "",
28555
+ type: "address",
28556
+ },
28557
+ ],
28558
+ stateMutability: "view",
28559
+ type: "function",
28560
+ },
28561
+ {
28562
+ inputs: [],
28563
+ name: "pause",
28564
+ outputs: [],
28565
+ stateMutability: "nonpayable",
28566
+ type: "function",
28567
+ },
28568
+ {
28569
+ inputs: [],
28570
+ name: "paused",
28571
+ outputs: [
28572
+ {
28573
+ internalType: "bool",
28574
+ name: "",
28575
+ type: "bool",
28576
+ },
28577
+ ],
28578
+ stateMutability: "view",
28579
+ type: "function",
28580
+ },
28581
+ {
28582
+ inputs: [],
28583
+ name: "renounceOwnership",
28584
+ outputs: [],
28585
+ stateMutability: "nonpayable",
28586
+ type: "function",
28587
+ },
28588
+ {
28589
+ inputs: [
28590
+ {
28591
+ internalType: "address",
28592
+ name: "newOwner",
28593
+ type: "address",
28594
+ },
28595
+ ],
28596
+ name: "transferOwnership",
28597
+ outputs: [],
28598
+ stateMutability: "nonpayable",
28599
+ type: "function",
28600
+ },
28601
+ {
28602
+ inputs: [],
28603
+ name: "uniswapRouter",
28604
+ outputs: [
28605
+ {
28606
+ internalType: "contract IV3SwapRouter",
28607
+ name: "",
28608
+ type: "address",
26073
28609
  },
26074
28610
  ],
28611
+ stateMutability: "view",
28612
+ type: "function",
28613
+ },
28614
+ {
28615
+ inputs: [],
28616
+ name: "unpause",
28617
+ outputs: [],
26075
28618
  stateMutability: "nonpayable",
26076
28619
  type: "function",
26077
28620
  },
26078
28621
  ];
26079
- const _bytecode$1$1 = "0x608060405234801561001057600080fd5b50610567806100206000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c80630f28c97d146100465780631749e1e3146100645780634d2301cc14610085575b600080fd5b61004e610098565b60405161005b919061041f565b60405180910390f35b6100776100723660046102a7565b61009c565b60405161005b929190610428565b61004e610093366004610286565b610220565b4290565b8051439060609067ffffffffffffffff811180156100b957600080fd5b506040519080825280602002602001820160405280156100f357816020015b6100e061023a565b8152602001906001900390816100d85790505b50905060005b835181101561021a57600080600086848151811061011357fe5b60200260200101516000015187858151811061012b57fe5b60200260200101516020015188868151811061014357fe5b60200260200101516040015192509250925060005a90506000808573ffffffffffffffffffffffffffffffffffffffff1685856040516101839190610403565b60006040518083038160008787f1925050503d80600081146101c1576040519150601f19603f3d011682016040523d82523d6000602084013e6101c6565b606091505b509150915060005a8403905060405180606001604052808415158152602001828152602001838152508989815181106101fb57fe5b60200260200101819052505050505050505080806001019150506100f9565b50915091565b73ffffffffffffffffffffffffffffffffffffffff163190565b604051806060016040528060001515815260200160008152602001606081525090565b803573ffffffffffffffffffffffffffffffffffffffff8116811461028157600080fd5b919050565b600060208284031215610297578081fd5b6102a08261025d565b9392505050565b600060208083850312156102b9578182fd5b823567ffffffffffffffff808211156102d0578384fd5b818501915085601f8301126102e3578384fd5b8135818111156102ef57fe5b6102fc8485830201610506565b81815284810190848601875b848110156103f457813587017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0606081838f03011215610346578a8bfd5b60408051606081018181108b8211171561035c57fe5b8252610369848d0161025d565b8152818401358c82015260608401358a811115610384578d8efd5b8085019450508e603f850112610398578c8dfd5b8b8401358a8111156103a657fe5b6103b68d85601f84011601610506565b93508084528f838287010111156103cb578d8efd5b808386018e86013783018c018d9052908101919091528552509287019290870190600101610308565b50909998505050505050505050565b6000825161041581846020870161052a565b9190910192915050565b90815260200190565b600060408083018584526020828186015281865180845260609350838701915083838202880101838901875b838110156104f6578983037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa001855281518051151584528681015187850152880151888401889052805188850181905260806104b582828801858c0161052a565b96880196601f919091017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01694909401909301925090850190600101610454565b50909a9950505050505050505050565b60405181810167ffffffffffffffff8111828210171561052257fe5b604052919050565b60005b8381101561054557818101518382015260200161052d565b83811115610554576000848401525b5050505056fea164736f6c6343000706000a";
28622
+ const _bytecode$1$1 = "0x60806040523480156200001157600080fd5b5060405162002123380380620021238339810160408190526200003491620000c2565b6200003f3362000072565b6000805460ff60a01b19169055600180546001600160a01b0319166001600160a01b0392909216919091179055620000f4565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b600060208284031215620000d557600080fd5b81516001600160a01b0381168114620000ed57600080fd5b9392505050565b61201f80620001046000396000f3fe6080604052600436106100e85760003560e01c8063735de9f71161008a578063ac9650d811610059578063ac9650d814610243578063d9a6f70514610263578063ed921d3c14610279578063f2fde38b1461028c57600080fd5b8063735de9f7146101c5578063742ac944146101fd5780638456cb59146102105780638da5cb5b1461022557600080fd5b80633f4ba83a116100c65780633f4ba83a1461014f5780635ae401dc146101665780635c975abb14610186578063715018a6146101b057600080fd5b80631411734e146100ed57806314d90e1b146101135780631fd168ff1461013c575b600080fd5b6101006100fb366004611a14565b6102ac565b6040519081526020015b60405180910390f35b34801561011f57600080fd5b506101296103e881565b60405161ffff909116815260200161010a565b61010061014a366004611a14565b61040a565b34801561015b57600080fd5b5061016461057a565b005b610179610174366004611ac0565b61058c565b60405161010a9190611b5b565b34801561019257600080fd5b50600054600160a01b900460ff16604051901515815260200161010a565b3480156101bc57600080fd5b506101646105e2565b3480156101d157600080fd5b506001546101e5906001600160a01b031681565b6040516001600160a01b03909116815260200161010a565b61010061020b366004611c50565b6105f4565b34801561021c57600080fd5b50610164610731565b34801561023157600080fd5b506000546001600160a01b03166101e5565b34801561024f57600080fd5b5061017961025e366004611ca5565b610741565b34801561026f57600080fd5b5061012961271081565b610100610287366004611c50565b610836565b34801561029857600080fd5b506101646102a7366004611ce6565b61095e565b60208101516000906001600160a01b031633148015906102d9575060208201516001600160a01b03163014155b156102ff5760405162461bcd60e51b81526004016102f690611d03565b60405180910390fd5b600061030e83600001516109d7565b905060008061037983866040015187602001518a8a808060200260200160405190810160405280939291908181526020016000905b8282101561036f5761036060408302860136819003810190611d50565b81526020019060010190610343565b50505050506109e3565b60408088018390526001600160a01b0380831660208a0152600154915163b858183f60e01b8152939550919350169063b858183f906103bc908890600401611dfc565b6020604051808303816000875af11580156103db573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103ff9190611e0f565b979650505050505050565b6040810151815160009190829061042090610ac4565b9050600061043185600001516109d7565b90506000806000806104a4868a606001518b604001518c602001518f8f808060200260200160405190810160405280939291908181526020016000905b8282101561049a5761048b60408302860136819003810190611d50565b8152602001906001019061046e565b5050505050610af2565b9350935093509350838960400181815250508289602001906001600160a01b031690816001600160a01b031681525050600160009054906101000a90046001600160a01b03166001600160a01b03166309b813468a6040518263ffffffff1660e01b81526004016105159190611dfc565b6020604051808303816000875af1158015610534573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105589190611e0f565b975061056c8787878c604001518587610bd3565b505050505050509392505050565b610582610e16565b61058a610e70565b565b6060834211156105d05760405162461bcd60e51b815260206004820152600f60248201526e111958591b1a5b99481c185cdcd959608a1b60448201526064016102f6565b6105da8383610741565b949350505050565b6105ea610e16565b61058a6000610ec5565b60608101516000906001600160a01b03163314801590610621575060608201516001600160a01b03163014155b1561063e5760405162461bcd60e51b81526004016102f690611d03565b6000806106a18460000151856080015186606001518989808060200260200160405190810160405280939291908181526020016000905b8282101561036f5761069260408302860136819003810190611d50565b81526020019060010190610675565b608086018290526001600160a01b0380821660608801526001546040516304e45aaf60e01b815293955091935016906304e45aaf906106e4908790600401611e28565b6020604051808303816000875af1158015610703573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107279190611e0f565b9695505050505050565b610739610e16565b61058a610f15565b6060816001600160401b0381111561075b5761075b61189c565b60405190808252806020026020018201604052801561078e57816020015b60608152602001906001900390816107795790505b50905060005b8281101561082e576107fe308585848181106107b2576107b2611e87565b90506020028101906107c49190611e9d565b8080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250610f5892505050565b82828151811061081057610810611e87565b6020026020010181905250808061082690611ef9565b915050610794565b505b92915050565b600080826080015190506000806000806108ab87600001518860a0015189608001518a606001518d8d808060200260200160405190810160405280939291908181526020016000905b8282101561049a5761089c60408302860136819003810190611d50565b8152602001906001019061087f565b60808b018490526001600160a01b0380841660608d0152600154604051635023b4df60e01b815295995093975091955093501690635023b4df906108f3908a90600401611e28565b6020604051808303816000875af1158015610912573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109369190611e0f565b955061095285886000015189602001518a608001518587610bd3565b50505050509392505050565b610966610e16565b6001600160a01b0381166109cb5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084016102f6565b6109d481610ec5565b50565b60006108308282610f84565b600080548190600160a01b900460ff16610a2257600080610a048786610fe9565b9092509050610a138288611f12565b9650610a1f88826111c6565b50505b6040516323b872dd60e01b8152336004820152306024820152604481018690526001600160a01b038716906323b872dd906064016020604051808303816000875af1158015610a75573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a999190611f25565b50610aa48686611341565b306001600160a01b03851603610ab8573393505b50929491935090915050565b60008060148351610ad59190611f12565b90506000610ae584836014611438565b90506105da816000610f84565b6000806060818082610b0e60005460ff600160a01b9091041690565b610b2e57610b1c8988610fe9565b9092509050610b2b828a611f47565b98505b6001600160a01b0388163014610b42573097505b610b4c8b8b611341565b6040516323b872dd60e01b8152336004820152306024820152604481018b90526001600160a01b038c16906323b872dd906064016020604051808303816000875af1158015610b9f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bc39190611f25565b50979a9699509697505050505050565b600054600160a01b900460ff16610bee57610bee8482611545565b6040516370a0823160e01b81523060048201526000906001600160a01b038616906370a0823190602401602060405180830381865afa158015610c35573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c599190611e0f565b9050610c658385611f12565b811015610cb45760405162461bcd60e51b815260206004820181905260248201527f696e636f72726563742066656520616d6f756e7420646973747269627574656460448201526064016102f6565b60405163a9059cbb60e01b8152336004820152602481018890526001600160a01b0386169063a9059cbb906044016020604051808303816000875af1158015610d01573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d259190611f25565b506040516370a0823160e01b81523060048201526000906001600160a01b038816906370a0823190602401602060405180830381865afa158015610d6d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d919190611e0f565b90508015610e0c5760405163a9059cbb60e01b8152336004820152602481018290526001600160a01b0388169063a9059cbb906044016020604051808303816000875af1158015610de6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e0a9190611f25565b505b5050505050505050565b6000546001600160a01b0316331461058a5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016102f6565b610e786116b4565b6000805460ff60a01b191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b610f1d611704565b6000805460ff60a01b1916600160a01b1790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258610ea83390565b6060610f7d8383604051806060016040528060278152602001611fc360279139611751565b9392505050565b6000610f91826014611f47565b83511015610fd95760405162461bcd60e51b8152602060048201526015602482015274746f416464726573735f6f75744f66426f756e647360581b60448201526064016102f6565b500160200151600160601b900490565b6000606081805b845181101561103a5784818151811061100b5761100b611e87565b60200260200101516020015161ffff16826110269190611f47565b91508061103281611ef9565b915050610ff0565b506103e881111561108d5760405162461bcd60e51b815260206004820152601d60248201527f5365727669636520666565203e204d41585f534552564943455f46454500000060448201526064016102f6565b60008085516001600160401b038111156110a9576110a961189c565b6040519080825280602002602001820160405280156110ee57816020015b60408051808201909152600080825260208201528152602001906001900390816110c75790505b50905060005b86518110156111b757600061271061ffff1688838151811061111857611118611e87565b60200260200101516020015161ffff168a6111339190611f5a565b61113d9190611f71565b9050604051806040016040528089848151811061115c5761115c611e87565b6020026020010151600001516001600160a01b031681526020018281525083838151811061118c5761118c611e87565b60209081029190910101526111a18185611f47565b93505080806111af90611ef9565b9150506110f4565b509093509150505b9250929050565b60005b815181101561133c57826001600160a01b03166323b872dd338484815181106111f4576111f4611e87565b60200260200101516000015185858151811061121257611212611e87565b60209081029190910181015101516040516001600160e01b031960e086901b1681526001600160a01b03938416600482015292909116602483015260448201526064016020604051808303816000875af1158015611274573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112989190611f25565b508181815181106112ab576112ab611e87565b6020026020010151600001516001600160a01b0316336001600160a01b0316846001600160a01b03167f1f9a9fdac86b6ca3c5300bec0b61555cded1f1a234378602dcca6c27085eac8e85858151811061130757611307611e87565b60200260200101516020015160405161132291815260200190565b60405180910390a48061133481611ef9565b9150506111c9565b505050565b600154604051636eb1769f60e11b81523060048201526001600160a01b039182166024820152829184169063dd62ed3e90604401602060405180830381865afa158015611392573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113b69190611e0f565b10156114345760015460405163095ea7b360e01b81526001600160a01b03918216600482015260001960248201529083169063095ea7b3906044016020604051808303816000875af1158015611410573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061133c9190611f25565b5050565b60608161144681601f611f47565b10156114855760405162461bcd60e51b815260206004820152600e60248201526d736c6963655f6f766572666c6f7760901b60448201526064016102f6565b61148f8284611f47565b845110156114d35760405162461bcd60e51b8152602060048201526011602482015270736c6963655f6f75744f66426f756e647360781b60448201526064016102f6565b6060821580156114f2576040519150600082526020820160405261153c565b6040519150601f8416801560200281840101858101878315602002848b0101015b8183101561152b578051835260209283019201611513565b5050858452601f01601f1916604052505b50949350505050565b60005b815181101561133c57826001600160a01b031663a9059cbb83838151811061157257611572611e87565b60200260200101516000015184848151811061159057611590611e87565b6020026020010151602001516040518363ffffffff1660e01b81526004016115cd9291906001600160a01b03929092168252602082015260400190565b6020604051808303816000875af11580156115ec573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116109190611f25565b5081818151811061162357611623611e87565b6020026020010151600001516001600160a01b0316336001600160a01b0316846001600160a01b03167f1f9a9fdac86b6ca3c5300bec0b61555cded1f1a234378602dcca6c27085eac8e85858151811061167f5761167f611e87565b60200260200101516020015160405161169a91815260200190565b60405180910390a4806116ac81611ef9565b915050611548565b600054600160a01b900460ff1661058a5760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b60448201526064016102f6565b600054600160a01b900460ff161561058a5760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b60448201526064016102f6565b6060600080856001600160a01b03168560405161176e9190611f93565b600060405180830381855af49150503d80600081146117a9576040519150601f19603f3d011682016040523d82523d6000602084013e6117ae565b606091505b50915091506107278683838760608315611829578251600003611822576001600160a01b0385163b6118225760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016102f6565b50816105da565b6105da838381511561183e5781518083602001fd5b8060405162461bcd60e51b81526004016102f69190611faf565b60008083601f84011261186a57600080fd5b5081356001600160401b0381111561188157600080fd5b6020830191508360208260061b85010111156111bf57600080fd5b634e487b7160e01b600052604160045260246000fd5b604051608081016001600160401b03811182821017156118d4576118d461189c565b60405290565b60405160e081016001600160401b03811182821017156118d4576118d461189c565b604051601f8201601f191681016001600160401b03811182821017156119245761192461189c565b604052919050565b6001600160a01b03811681146109d457600080fd5b803561194c8161192c565b919050565b60006080828403121561196357600080fd5b61196b6118b2565b905081356001600160401b038082111561198457600080fd5b818401915084601f83011261199857600080fd5b81356020828211156119ac576119ac61189c565b6119be601f8301601f191682016118fc565b925081835286818386010111156119d457600080fd5b818185018285013760008183850101528285526119f2818701611941565b8186015250505050604082013560408201526060820135606082015292915050565b600080600060408486031215611a2957600080fd5b83356001600160401b0380821115611a4057600080fd5b611a4c87838801611858565b90955093506020860135915080821115611a6557600080fd5b50611a7286828701611951565b9150509250925092565b60008083601f840112611a8e57600080fd5b5081356001600160401b03811115611aa557600080fd5b6020830191508360208260051b85010111156111bf57600080fd5b600080600060408486031215611ad557600080fd5b8335925060208401356001600160401b03811115611af257600080fd5b611afe86828701611a7c565b9497909650939450505050565b60005b83811015611b26578181015183820152602001611b0e565b50506000910152565b60008151808452611b47816020860160208601611b0b565b601f01601f19169290920160200192915050565b6000602080830181845280855180835260408601915060408160051b870101925083870160005b82811015611bb057603f19888603018452611b9e858351611b2f565b94509285019290850190600101611b82565b5092979650505050505050565b600060e08284031215611bcf57600080fd5b611bd76118da565b90508135611be48161192c565b81526020820135611bf48161192c565b6020820152604082013562ffffff81168114611c0f57600080fd5b6040820152611c2060608301611941565b60608201526080820135608082015260a082013560a0820152611c4560c08301611941565b60c082015292915050565b60008060006101008486031215611c6657600080fd5b83356001600160401b03811115611c7c57600080fd5b611c8886828701611858565b9094509250611c9c90508560208601611bbd565b90509250925092565b60008060208385031215611cb857600080fd5b82356001600160401b03811115611cce57600080fd5b611cda85828601611a7c565b90969095509350505050565b600060208284031215611cf857600080fd5b8135610f7d8161192c565b6020808252602d908201527f726563697069656e74206d757374206265206d73672e73656e646572206f722060408201526c1d1a1a5cc818dbdb9d1c9858dd609a1b606082015260800190565b600060408284031215611d6257600080fd5b604051604081018181106001600160401b0382111715611d8457611d8461189c565b6040528235611d928161192c565b8152602083013561ffff81168114611da957600080fd5b60208201529392505050565b6000815160808452611dca6080850182611b2f565b6020848101516001600160a01b0316908601526040808501519086015260609384015193909401929092525090919050565b602081526000610f7d6020830184611db5565b600060208284031215611e2157600080fd5b5051919050565b60e08101610830828480516001600160a01b03908116835260208083015182169084015260408083015162ffffff16908401526060808301518216908401526080808301519084015260a0828101519084015260c09182015116910152565b634e487b7160e01b600052603260045260246000fd5b6000808335601e19843603018112611eb457600080fd5b8301803591506001600160401b03821115611ece57600080fd5b6020019150368190038213156111bf57600080fd5b634e487b7160e01b600052601160045260246000fd5b600060018201611f0b57611f0b611ee3565b5060010190565b8181038181111561083057610830611ee3565b600060208284031215611f3757600080fd5b81518015158114610f7d57600080fd5b8082018082111561083057610830611ee3565b808202811582820484141761083057610830611ee3565b600082611f8e57634e487b7160e01b600052601260045260246000fd5b500490565b60008251611fa5818460208701611b0b565b9190910192915050565b602081526000610f7d6020830184611b2f56fe416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a26469706673582212203925f97cd63c2e61736a2a442ff1d4bf966f453350e9df354a849229f69092cf64736f6c63430008130033";
26080
28623
  const isSuperArgs$1$1 = (xs) => xs.length > 1;
26081
- class Multicall__factory extends ContractFactory {
28624
+ class SecondaryFee__factory extends ContractFactory {
26082
28625
  constructor(...args) {
26083
28626
  if (isSuperArgs$1$1(args)) {
26084
28627
  super(...args);
@@ -26087,11 +28630,11 @@ class Multicall__factory extends ContractFactory {
26087
28630
  super(_abi$1$1, _bytecode$1$1, args[0]);
26088
28631
  }
26089
28632
  }
26090
- deploy(overrides) {
26091
- return super.deploy(overrides || {});
28633
+ deploy(_uniRouter, overrides) {
28634
+ return super.deploy(_uniRouter, overrides || {});
26092
28635
  }
26093
- getDeployTransaction(overrides) {
26094
- return super.getDeployTransaction(overrides || {});
28636
+ getDeployTransaction(_uniRouter, overrides) {
28637
+ return super.getDeployTransaction(_uniRouter, overrides || {});
26095
28638
  }
26096
28639
  attach(address) {
26097
28640
  return super.attach(address);
@@ -27487,7 +30030,81 @@ maxHops) => {
27487
30030
  return routes;
27488
30031
  };
27489
30032
 
27490
- function createSwapParameters(trade, fromAddress, slippage, deadline) {
30033
+ const zeroNativeCurrencyValue = '0x00';
30034
+ const multicallWithDeadlineFunctionSignature = 'multicall(uint256,bytes[])';
30035
+ function buildSwapParametersForSinglePoolSwap(fromAddress, trade, route, amountIn, amountOut, secondaryFees, secondaryFeeContract) {
30036
+ const secondaryFeeValues = secondaryFees.map((fee) => ({
30037
+ feePrcntBasisPoints: fee.feeBasisPoints,
30038
+ recipient: fee.feeRecipient,
30039
+ }));
30040
+ if (trade.tradeType === TradeType.EXACT_INPUT) {
30041
+ return secondaryFeeContract.encodeFunctionData('exactInputSingleWithServiceFee', [secondaryFeeValues, {
30042
+ tokenIn: route.tokenPath[0].address,
30043
+ tokenOut: route.tokenPath[1].address,
30044
+ fee: route.pools[0].fee,
30045
+ recipient: fromAddress,
30046
+ amountIn,
30047
+ amountOutMinimum: amountOut,
30048
+ sqrtPriceLimitX96: 0,
30049
+ }]);
30050
+ }
30051
+ return secondaryFeeContract.encodeFunctionData('exactOutputSingleWithServiceFee', [secondaryFeeValues, {
30052
+ tokenIn: route.tokenPath[0].address,
30053
+ tokenOut: route.tokenPath[1].address,
30054
+ fee: route.pools[0].fee,
30055
+ recipient: fromAddress,
30056
+ amountInMaximum: amountIn,
30057
+ amountOut,
30058
+ sqrtPriceLimitX96: 0,
30059
+ }]);
30060
+ }
30061
+ function buildSwapParametersForMultiPoolSwap(fromAddress, trade, route, amountIn, amountOut, secondaryFees, secondaryFeeContract) {
30062
+ const path = encodeRouteToPath(route, trade.tradeType === TradeType.EXACT_OUTPUT);
30063
+ const secondaryFeeValues = secondaryFees.map((fee) => ({
30064
+ feePrcntBasisPoints: fee.feeBasisPoints,
30065
+ recipient: fee.feeRecipient,
30066
+ }));
30067
+ if (trade.tradeType === TradeType.EXACT_INPUT) {
30068
+ return secondaryFeeContract.encodeFunctionData('exactInputWithServiceFee', [secondaryFeeValues, {
30069
+ path,
30070
+ recipient: fromAddress,
30071
+ amountIn,
30072
+ amountOutMinimum: amountOut,
30073
+ }]);
30074
+ }
30075
+ return secondaryFeeContract.encodeFunctionData('exactOutputWithServiceFee', [secondaryFeeValues, {
30076
+ path,
30077
+ recipient: fromAddress,
30078
+ amountInMaximum: amountIn,
30079
+ amountOut,
30080
+ }]);
30081
+ }
30082
+ /**
30083
+ * Builds swap parameters
30084
+ * @param fromAddress the msg.sender of the transaction
30085
+ * @param secondaryFeeAddress the secondary fee contract address
30086
+ * @param trade details of the swap, including the route, input/output tokens and amounts
30087
+ * @param options additional swap options
30088
+ * @returns calldata for the swap
30089
+ */
30090
+ function buildSwapParameters(fromAddress, trade, options, secondaryFees, secondaryFeeContract) {
30091
+ // @dev we don't support multiple swaps in a single transaction
30092
+ // there will always be only one swap in the trade regardless of the trade type
30093
+ const { route, inputAmount, outputAmount } = trade.swaps[0];
30094
+ const amountIn = toHex$1(trade.maximumAmountIn(options.slippageTolerance, inputAmount).quotient);
30095
+ const amountOut = toHex$1(trade.minimumAmountOut(options.slippageTolerance, outputAmount).quotient);
30096
+ const isSinglePoolSwap = route.pools.length === 1;
30097
+ if (isSinglePoolSwap) {
30098
+ return buildSwapParametersForSinglePoolSwap(fromAddress, trade, route, amountIn, amountOut, secondaryFees, secondaryFeeContract);
30099
+ }
30100
+ return buildSwapParametersForMultiPoolSwap(fromAddress, trade, route, amountIn, amountOut, secondaryFees, secondaryFeeContract);
30101
+ }
30102
+ function createSwapCallParametersWithFees(trade, fromAddress, swapOptions, secondaryFees) {
30103
+ const secondaryFeeContract = SecondaryFee__factory.createInterface();
30104
+ const swapWithFeesCalldata = buildSwapParameters(fromAddress, trade, swapOptions, secondaryFees, secondaryFeeContract);
30105
+ return secondaryFeeContract.encodeFunctionData(multicallWithDeadlineFunctionSignature, [swapOptions.deadlineOrPreviousBlockhash, [swapWithFeesCalldata]]);
30106
+ }
30107
+ function createSwapParameters(trade, fromAddress, slippage, deadline, secondaryFees) {
27491
30108
  // Create an unchecked trade to be used in generating swap parameters.
27492
30109
  const uncheckedTrade = Trade.createUncheckedTrade({
27493
30110
  route: trade.route,
@@ -27501,20 +30118,24 @@ function createSwapParameters(trade, fromAddress, slippage, deadline) {
27501
30118
  recipient: fromAddress,
27502
30119
  deadlineOrPreviousBlockhash: deadline,
27503
30120
  };
27504
- // Generate the parameters.
27505
- return SwapRouter.swapCallParameters([uncheckedTrade], options);
30121
+ if (secondaryFees.length === 0) {
30122
+ // Generate swap parameters without secondary fee contract details
30123
+ return SwapRouter.swapCallParameters([uncheckedTrade], options).calldata;
30124
+ }
30125
+ return createSwapCallParametersWithFees(uncheckedTrade, fromAddress, options, secondaryFees);
27506
30126
  }
27507
- function getSwap(nativeToken, routeAndQuote, fromAddress, slippage, deadline, peripheryRouterAddress, gasPrice) {
27508
- const params = createSwapParameters(routeAndQuote.trade, fromAddress, slippage, deadline);
30127
+ function getSwap(nativeToken, routeAndQuote, fromAddress, slippage, deadline, peripheryRouterAddress, secondaryFeesAddress, gasPrice, secondaryFees) {
30128
+ const calldata = createSwapParameters(routeAndQuote.trade, fromAddress, slippage, deadline, secondaryFees);
30129
+ // TODO: Add additional gas fee estimates for secondary fees
27509
30130
  const gasFeeEstimate = gasPrice ? {
27510
30131
  token: nativeToken,
27511
30132
  value: calculateGasFee(gasPrice, routeAndQuote.trade.gasEstimate),
27512
30133
  } : null;
27513
30134
  return {
27514
30135
  transaction: {
27515
- data: params.calldata,
27516
- to: peripheryRouterAddress,
27517
- value: params.value,
30136
+ data: calldata,
30137
+ to: secondaryFees.length > 0 ? secondaryFeesAddress : peripheryRouterAddress,
30138
+ value: zeroNativeCurrencyValue,
27518
30139
  from: fromAddress,
27519
30140
  },
27520
30141
  gasFeeEstimate,
@@ -27527,6 +30148,7 @@ const CONTRACTS_FOR_CHAIN_ID = {
27527
30148
  coreFactory: '0x12739A8f1A8035F439092D016DAE19A2874F30d2',
27528
30149
  quoterV2: '0xF674847fBcca5C80315e3AE37043Dce99F6CC529',
27529
30150
  peripheryRouter: '0x0Afe6F5f4DC34461A801420634239FFaD50A2e44',
30151
+ secondaryFee: '0x8dBE1f0900C5e92ad87A54521902a33ba1598C51',
27530
30152
  },
27531
30153
  };
27532
30154
  const SUPPORTED_SANDBOX_CHAINS = {
@@ -27555,29 +30177,36 @@ function validateOverrides(overrides) {
27555
30177
  throw new InvalidConfigurationError(`Invalid exchange contract address for ${key}`);
27556
30178
  }
27557
30179
  });
27558
- if (!overrides.secondaryFees) {
27559
- return;
27560
- }
27561
- for (const secondaryFee of overrides.secondaryFees) {
30180
+ }
30181
+ function validateSecondaryFees(secondaryFees) {
30182
+ let totalSecondaryFeeBasisPoints = 0;
30183
+ for (const secondaryFee of secondaryFees) {
27562
30184
  if (!isValidNonZeroAddress(secondaryFee.feeRecipient)) {
27563
30185
  throw new InvalidConfigurationError(`Invalid secondary fee recipient address: ${secondaryFee.feeRecipient}`);
27564
30186
  }
27565
- if (secondaryFee.feeBasisPoints < 0 || secondaryFee.feeBasisPoints > 10000) {
27566
- throw new InvalidConfigurationError(`Invalid secondary fee percentage: ${secondaryFee.feeBasisPoints}`);
30187
+ if (secondaryFee.feeBasisPoints < 0 || secondaryFee.feeBasisPoints > MAX_SECONDARY_FEE_BASIS_POINTS) {
30188
+ throw new InvalidConfigurationError(`Invalid secondary fee basis points: ${secondaryFee.feeBasisPoints}`);
27567
30189
  }
30190
+ totalSecondaryFeeBasisPoints += secondaryFee.feeBasisPoints;
30191
+ }
30192
+ if (totalSecondaryFeeBasisPoints > MAX_SECONDARY_FEE_BASIS_POINTS) {
30193
+ throw new InvalidConfigurationError(`Invalid total secondary fee basis points: ${totalSecondaryFeeBasisPoints}`);
27568
30194
  }
27569
30195
  }
27570
30196
  /**
27571
30197
  * {@link ExchangeConfiguration} is used to configure the {@link Exchange} class.
27572
30198
  * @param chainId the ID of the chain to configure. {@link SUPPORTED_CHAIN_IDS_FOR_ENVIRONMENT} contains the supported chains for each environment.
27573
30199
  * @param baseConfig the base {@link ImmutableConfiguration} for the {@link Exchange} class
30200
+ * @param secondaryFees an optional array of {@link SecondaryFee}s to apply to all transactions. Total secondary fees must be less than {@link MAX_SECONDARY_FEE_BASIS_POINTS}.
27574
30201
  */
27575
30202
  class ExchangeConfiguration {
27576
30203
  baseConfig;
27577
30204
  chain;
27578
- secondaryFees;
27579
- constructor({ chainId, baseConfig, overrides }) {
30205
+ secondaryFees = [];
30206
+ constructor({ chainId, baseConfig, secondaryFees, overrides, }) {
27580
30207
  this.baseConfig = baseConfig;
30208
+ this.secondaryFees = secondaryFees || [];
30209
+ validateSecondaryFees(this.secondaryFees);
27581
30210
  if (overrides) {
27582
30211
  validateOverrides(overrides);
27583
30212
  this.chain = {
@@ -27587,10 +30216,9 @@ class ExchangeConfiguration {
27587
30216
  commonRoutingTokens: overrides.commonRoutingTokens,
27588
30217
  nativeToken: overrides.nativeToken,
27589
30218
  };
27590
- this.secondaryFees = overrides.secondaryFees ? overrides.secondaryFees : [];
30219
+ this.secondaryFees = secondaryFees || [];
27591
30220
  return;
27592
30221
  }
27593
- this.secondaryFees = [];
27594
30222
  const chain = SUPPORTED_CHAIN_IDS_FOR_ENVIRONMENT[baseConfig.environment][chainId];
27595
30223
  if (!chain) {
27596
30224
  throw new ChainNotSupportedError(chainId, baseConfig.environment);
@@ -27609,13 +30237,14 @@ class Exchange {
27609
30237
  const config = new ExchangeConfiguration(configuration);
27610
30238
  this.chainId = config.chain.chainId;
27611
30239
  this.nativeToken = config.chain.nativeToken;
27612
- this.provider = new ethers.providers.JsonRpcProvider(config.chain.rpcUrl);
27613
30240
  this.secondaryFees = config.secondaryFees;
30241
+ this.provider = new ethers.providers.JsonRpcProvider(config.chain.rpcUrl);
27614
30242
  this.router = new Router(this.provider, config.chain.commonRoutingTokens, {
27615
30243
  multicallAddress: config.chain.contracts.multicall,
27616
30244
  factoryAddress: config.chain.contracts.coreFactory,
27617
30245
  quoterAddress: config.chain.contracts.quoterV2,
27618
30246
  peripheryRouterAddress: config.chain.contracts.peripheryRouter,
30247
+ secondaryFeeAddress: config.chain.contracts.secondaryFee,
27619
30248
  });
27620
30249
  }
27621
30250
  static validate(tokenInAddress, tokenOutAddress, maxHops, slippagePercent, fromAddress) {
@@ -27653,7 +30282,7 @@ class Exchange {
27653
30282
  const gasPrice = await fetchGasPrice(this.provider);
27654
30283
  // we always use the tokenIn address because we are always selling the tokenIn
27655
30284
  const approval = await getApproval(this.nativeToken, this.provider, fromAddress, tokenInAddress, ethers.BigNumber.from(amount), this.router.routingContracts.peripheryRouterAddress, gasPrice);
27656
- const swap = getSwap(this.nativeToken, routeAndQuote, fromAddress, slippagePercent, deadline, this.router.routingContracts.peripheryRouterAddress, gasPrice);
30285
+ const swap = getSwap(this.nativeToken, routeAndQuote, fromAddress, slippagePercent, deadline, this.router.routingContracts.peripheryRouterAddress, this.router.routingContracts.secondaryFeeAddress, gasPrice, this.secondaryFees);
27657
30286
  const quote = getQuote(otherToken, tradeType, routeAndQuote.trade, slippagePercent);
27658
30287
  return {
27659
30288
  approval,
@@ -27693,9 +30322,6 @@ class Exchange {
27693
30322
  async getUnsignedSwapTxFromAmountOut(fromAddress, tokenInAddress, tokenOutAddress, amountOut, slippagePercent = DEFAULT_SLIPPAGE, maxHops = DEFAULT_MAX_HOPS, deadline = DEFAULT_DEADLINE) {
27694
30323
  return await this.getUnsignedSwapTx(fromAddress, tokenInAddress, tokenOutAddress, amountOut, slippagePercent, maxHops, deadline, TradeType.EXACT_OUTPUT);
27695
30324
  }
27696
- thereAreSecondaryFees() {
27697
- return this.secondaryFees.length > 0;
27698
- }
27699
30325
  }
27700
30326
 
27701
30327
  /* eslint-disable class-methods-use-this */
@@ -28841,7 +31467,7 @@ class $a8cb37a3fc8eb863$export$1f60ba4ec72508a0 {
28841
31467
  function $parcel$export(e, n, v, s) {
28842
31468
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
28843
31469
  }
28844
- const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.4.1-alpha.1";
31470
+ const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.4.2-alpha.1";
28845
31471
  const $d663162fd5a0853f$export$83bf90b30cdfd29f = ()=>false;
28846
31472
  const $d663162fd5a0853f$export$1169f5475725171b = ()=>$d663162fd5a0853f$export$38a083d9fb5551ca;
28847
31473