@imtbl/sdk 0.31.3 → 0.33.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14832,13 +14832,13 @@ const subtractAmount = (a, b) => {
14832
14832
  /**
14833
14833
  * Converts our internal token type which could be ERC20 or Native
14834
14834
  * into a format consumable by Checkout. They require an address to be
14835
- * present. We populate the address with empty string if it's Native.
14835
+ * present. We populate the address with the string 'native' if it's Native.
14836
14836
  * If it's ERC20, we don't need to change it.
14837
14837
  */
14838
14838
  const toPublicTokenType = (token) => {
14839
14839
  if (token.type === 'native') {
14840
14840
  return {
14841
- address: '',
14841
+ address: 'native',
14842
14842
  chainId: token.chainId,
14843
14843
  decimals: token.decimals,
14844
14844
  symbol: token.symbol,
@@ -15150,7 +15150,7 @@ const doesChainSupportEIP1559$1 = (fee) => {
15150
15150
  /**
15151
15151
  * Fetch the current gas price estimate. Supports both EIP-1559 and non-EIP1559 chains
15152
15152
  * @param {JsonRpcProvider} provider - The JSON RPC provider used to fetch fee data
15153
- * @param {Coin} nativeToken - The native token of the chain. Gas prices will be denominated in this token
15153
+ * @param {Native} nativeToken - The native token of the chain. Gas prices will be denominated in this token
15154
15154
  * @returns {Amount | null} - The gas price in the smallest denomination of the chain's currency,
15155
15155
  * or null if no gas price is available
15156
15156
  */
@@ -15275,9 +15275,6 @@ class NativeTokenService {
15275
15275
  this.wrappedToken = wrappedToken;
15276
15276
  }
15277
15277
  wrapAmount(amount) {
15278
- if (!canUnwrapToken(amount.token)) {
15279
- throw new Error(`cannot wrap non-native token: ${amount.token.address}`);
15280
- }
15281
15278
  return newAmount(amount.value, this.wrappedToken);
15282
15279
  }
15283
15280
  unwrapAmount(amount) {
@@ -20987,7 +20984,7 @@ class APIError extends Error {
20987
20984
 
20988
20985
  /* eslint-disable implicit-arrow-linebreak */
20989
20986
  const defaultHeaders = {
20990
- sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.31.3',
20987
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.33.0',
20991
20988
  };
20992
20989
  /**
20993
20990
  * createAPIConfiguration to create a custom Configuration
@@ -21600,412 +21597,73 @@ const validateProviderDefaults = {
21600
21597
  allowUnsupportedProvider: false,
21601
21598
  };
21602
21599
 
21603
- const ENV_DEVELOPMENT = 'development';
21604
- const IMX_ADDRESS_ZKEVM = '0x0000000000000000000000000000000000001010';
21605
- const DEFAULT_TOKEN_DECIMALS$1 = 18;
21606
- const ZKEVM_NATIVE_TOKEN = {
21607
- name: 'IMX',
21608
- symbol: 'IMX',
21609
- decimals: DEFAULT_TOKEN_DECIMALS$1,
21610
- address: IMX_ADDRESS_ZKEVM,
21611
- };
21612
21600
  /**
21613
- * Base URL for the Immutable API based on the environment.
21614
- * @property {string} DEVELOPMENT - The base URL for the development environment.
21615
- * @property {string} SANDBOX - The base URL for the sandbox environment.
21616
- * @property {string} PRODUCTION - The base URL for the production environment.
21601
+ * An enum representing the checkout status types
21602
+ * @enum {string}
21603
+ * @property {string} SUCCESS - If checkout succeeded as the transactions were able to be processed
21604
+ * @property {string} FAILED - If checkout failed due to transactions not settling on chain
21605
+ * @property {string} INSUFFICIENT_FUNDS - If checkout failed due to insufficient funds
21617
21606
  */
21618
- const IMMUTABLE_API_BASE_URL = {
21619
- [ENV_DEVELOPMENT]: 'https://api.dev.immutable.com',
21620
- [Environment$1.SANDBOX]: 'https://api.sandbox.immutable.com',
21621
- [Environment$1.PRODUCTION]: 'https://api.immutable.com',
21622
- };
21607
+ var CheckoutStatus;
21608
+ (function (CheckoutStatus) {
21609
+ CheckoutStatus["SUCCESS"] = "SUCCESS";
21610
+ CheckoutStatus["FAILED"] = "FAILED";
21611
+ CheckoutStatus["INSUFFICIENT_FUNDS"] = "INSUFFICIENT_FUNDS";
21612
+ })(CheckoutStatus || (CheckoutStatus = {}));
21623
21613
  /**
21624
- * Base URL for the checkout API based on the environment.
21625
- * @property {string} DEVELOPMENT - The base URL for the development environment.
21626
- * @property {string} SANDBOX - The base URL for the sandbox environment.
21627
- * @property {string} PRODUCTION - The base URL for the production environment.
21614
+ * An enum representing the item types
21615
+ * @enum {string}
21616
+ * @property {string} NATIVE - If the item is a native token.
21617
+ * @property {string} ERC20 - If the item is an ERC20 token.
21618
+ * @property {string} ERC721 - If the item is an ERC721 token.
21628
21619
  */
21629
- const CHECKOUT_API_BASE_URL = {
21630
- [ENV_DEVELOPMENT]: 'https://checkout-api.dev.immutable.com',
21631
- [Environment$1.SANDBOX]: 'https://checkout-api.sandbox.immutable.com',
21632
- [Environment$1.PRODUCTION]: 'https://checkout-api.immutable.com',
21633
- };
21620
+ var ItemType;
21621
+ (function (ItemType) {
21622
+ ItemType["NATIVE"] = "NATIVE";
21623
+ ItemType["ERC20"] = "ERC20";
21624
+ ItemType["ERC721"] = "ERC721";
21625
+ })(ItemType || (ItemType = {}));
21634
21626
  /**
21635
- * Smart Checkout routing default onramp enabled flag
21627
+ * An enum representing transaction or gas types
21628
+ * @enum {string}
21629
+ * @property {string} TRANSACTION - If the type is a transaction
21630
+ * @property {string} GAS - If the type is the gas amount
21636
21631
  */
21637
- const DEFAULT_ON_RAMP_ENABLED = true;
21632
+ var TransactionOrGasType;
21633
+ (function (TransactionOrGasType) {
21634
+ TransactionOrGasType["TRANSACTION"] = "TRANSACTION";
21635
+ TransactionOrGasType["GAS"] = "GAS";
21636
+ })(TransactionOrGasType || (TransactionOrGasType = {}));
21638
21637
  /**
21639
- * Smart Checkout routing default swap enabled flag
21638
+ * An enum representing the gas token types
21639
+ * @enum {string}
21640
+ * @property {string} NATIVE - If the gas token is a native token.
21641
+ * @property {string} ERC20 - If the gas token is an ERC20 token.
21640
21642
  */
21641
- const DEFAULT_SWAP_ENABLED = true;
21643
+ var GasTokenType;
21644
+ (function (GasTokenType) {
21645
+ GasTokenType["NATIVE"] = "NATIVE";
21646
+ GasTokenType["ERC20"] = "ERC20";
21647
+ })(GasTokenType || (GasTokenType = {}));
21642
21648
  /**
21643
- * Smart Checkout routing default bridge enabled flag
21649
+ * An enum representing the routing outcome types
21650
+ * @enum {string}
21651
+ * @property {string} ROUTES_FOUND - If funding routes were found for the transaction.
21652
+ * @property {string} NO_ROUTES_FOUND - If no funding routes were found for the transaction.
21653
+ * @property {string} NO_ROUTE_OPTIONS - If no routing options were available for the transaction.
21644
21654
  */
21645
- const DEFAULT_BRIDGE_ENABLED = true;
21646
- const TRANSAK_API_BASE_URL = {
21647
- [Environment$1.SANDBOX]: 'https://global-stg.transak.com',
21648
- [Environment$1.PRODUCTION]: 'https://global.transak.com/',
21649
- };
21650
- const PRODUCTION_CHAIN_ID_NETWORK_MAP = new Map([
21651
- [
21652
- ChainId.ETHEREUM,
21653
- {
21654
- chainIdHex: `0x${ChainId.ETHEREUM.toString(16)}`,
21655
- chainName: ChainName.ETHEREUM,
21656
- rpcUrls: ['https://checkout-api.immutable.com/v1/rpc/eth-mainnet'],
21657
- nativeCurrency: {
21658
- name: ChainName.ETHEREUM,
21659
- symbol: 'ETH',
21660
- decimals: 18,
21661
- },
21662
- blockExplorerUrls: ['https://etherscan.io/'],
21663
- },
21664
- ],
21665
- [
21666
- ChainId.IMTBL_ZKEVM_MAINNET,
21667
- {
21668
- chainIdHex: `0x${ChainId.IMTBL_ZKEVM_MAINNET.toString(16)}`,
21669
- chainName: ChainName.IMTBL_ZKEVM_MAINNET,
21670
- rpcUrls: ['https://rpc.immutable.com'],
21671
- nativeCurrency: ZKEVM_NATIVE_TOKEN,
21672
- },
21673
- ],
21674
- ]);
21675
- const SANDBOX_CHAIN_ID_NETWORK_MAP = new Map([
21676
- [
21677
- ChainId.SEPOLIA,
21678
- {
21679
- chainIdHex: `0x${ChainId.SEPOLIA.toString(16)}`,
21680
- chainName: ChainName.SEPOLIA,
21681
- rpcUrls: [
21682
- 'https://checkout-api.sandbox.immutable.com/v1/rpc/eth-sepolia',
21683
- ],
21684
- nativeCurrency: {
21685
- name: 'Sep Eth',
21686
- symbol: 'ETH',
21687
- decimals: 18,
21688
- },
21689
- blockExplorerUrls: ['https://sepolia.etherscan.io/'],
21690
- },
21691
- ],
21692
- [
21693
- ChainId.IMTBL_ZKEVM_TESTNET,
21694
- {
21695
- chainIdHex: `0x${ChainId.IMTBL_ZKEVM_TESTNET.toString(16)}`,
21696
- chainName: ChainName.IMTBL_ZKEVM_TESTNET,
21697
- rpcUrls: ['https://rpc.testnet.immutable.com'],
21698
- nativeCurrency: ZKEVM_NATIVE_TOKEN,
21699
- },
21700
- ],
21701
- ]);
21702
- const DEV_CHAIN_ID_NETWORK_MAP = new Map([
21703
- [
21704
- ChainId.SEPOLIA,
21705
- {
21706
- chainIdHex: `0x${ChainId.SEPOLIA.toString(16)}`,
21707
- chainName: ChainName.SEPOLIA,
21708
- rpcUrls: ['https://checkout-api.dev.immutable.com/v1/rpc/eth-sepolia'],
21709
- nativeCurrency: {
21710
- name: 'Sep Eth',
21711
- symbol: 'ETH',
21712
- decimals: 18,
21713
- },
21714
- blockExplorerUrls: ['https://sepolia.etherscan.io/'],
21715
- },
21716
- ],
21717
- [
21718
- ChainId.IMTBL_ZKEVM_DEVNET,
21719
- {
21720
- chainIdHex: `0x${ChainId.IMTBL_ZKEVM_DEVNET.toString(16)}`,
21721
- chainName: ChainName.IMTBL_ZKEVM_DEVNET,
21722
- rpcUrls: ['https://rpc.dev.immutable.com'],
21723
- nativeCurrency: ZKEVM_NATIVE_TOKEN,
21724
- },
21725
- ],
21726
- ]);
21655
+ var RoutingOutcomeType;
21656
+ (function (RoutingOutcomeType) {
21657
+ RoutingOutcomeType["ROUTES_FOUND"] = "ROUTES_FOUND";
21658
+ RoutingOutcomeType["NO_ROUTES_FOUND"] = "NO_ROUTES_FOUND";
21659
+ RoutingOutcomeType["NO_ROUTE_OPTIONS"] = "NO_ROUTE_OPTIONS";
21660
+ })(RoutingOutcomeType || (RoutingOutcomeType = {}));
21727
21661
  /**
21728
- * Blockscout API configuration per chain
21729
- */
21730
- const BLOCKSCOUT_CHAIN_URL_MAP = {
21731
- [ChainId.IMTBL_ZKEVM_TESTNET]: {
21732
- url: 'https://explorer.testnet.immutable.com',
21733
- nativeToken: SANDBOX_CHAIN_ID_NETWORK_MAP.get(ChainId.IMTBL_ZKEVM_TESTNET).nativeCurrency,
21734
- },
21735
- [ChainId.IMTBL_ZKEVM_MAINNET]: {
21736
- url: 'https://explorer.mainnet.immutable.com',
21737
- nativeToken: PRODUCTION_CHAIN_ID_NETWORK_MAP.get(ChainId.IMTBL_ZKEVM_MAINNET).nativeCurrency,
21738
- },
21739
- [ChainId.SEPOLIA]: {
21740
- url: 'https://eth-sepolia.blockscout.com',
21741
- nativeToken: SANDBOX_CHAIN_ID_NETWORK_MAP.get(ChainId.SEPOLIA).nativeCurrency,
21742
- },
21743
- [ChainId.ETHEREUM]: {
21744
- url: 'https://eth.blockscout.com/',
21745
- nativeToken: PRODUCTION_CHAIN_ID_NETWORK_MAP.get(ChainId.ETHEREUM).nativeCurrency,
21746
- },
21747
- };
21748
- const ERC20ABI = [
21749
- {
21750
- constant: true,
21751
- inputs: [],
21752
- name: 'name',
21753
- outputs: [
21754
- {
21755
- name: '',
21756
- type: 'string',
21757
- },
21758
- ],
21759
- payable: false,
21760
- type: 'function',
21761
- },
21762
- {
21763
- constant: true,
21764
- inputs: [],
21765
- name: 'decimals',
21766
- outputs: [
21767
- {
21768
- name: '',
21769
- type: 'uint8',
21770
- },
21771
- ],
21772
- payable: false,
21773
- type: 'function',
21774
- },
21775
- {
21776
- constant: true,
21777
- inputs: [
21778
- {
21779
- name: '_owner',
21780
- type: 'address',
21781
- },
21782
- ],
21783
- name: 'balanceOf',
21784
- outputs: [
21785
- {
21786
- name: 'balance',
21787
- type: 'uint256',
21788
- },
21789
- ],
21790
- payable: false,
21791
- type: 'function',
21792
- },
21793
- {
21794
- constant: true,
21795
- inputs: [],
21796
- name: 'symbol',
21797
- outputs: [
21798
- {
21799
- name: '',
21800
- type: 'string',
21801
- },
21802
- ],
21803
- payable: false,
21804
- type: 'function',
21805
- },
21806
- {
21807
- constant: true,
21808
- inputs: [
21809
- {
21810
- name: '_owner',
21811
- type: 'address',
21812
- },
21813
- {
21814
- name: '_spender',
21815
- type: 'address',
21816
- },
21817
- ],
21818
- name: 'allowance',
21819
- outputs: [
21820
- {
21821
- name: '',
21822
- type: 'uint256',
21823
- },
21824
- ],
21825
- payable: false,
21826
- stateMutability: 'view',
21827
- type: 'function',
21828
- },
21829
- {
21830
- constant: false,
21831
- inputs: [
21832
- {
21833
- name: '_spender',
21834
- type: 'address',
21835
- },
21836
- {
21837
- name: '_value',
21838
- type: 'uint256',
21839
- },
21840
- ],
21841
- name: 'approve',
21842
- outputs: [
21843
- {
21844
- name: '',
21845
- type: 'bool',
21846
- },
21847
- ],
21848
- payable: false,
21849
- stateMutability: 'nonpayable',
21850
- type: 'function',
21851
- },
21852
- ];
21853
- const ERC721ABI = [
21854
- {
21855
- constant: false,
21856
- inputs: [
21857
- {
21858
- internalType: 'address',
21859
- name: 'to',
21860
- type: 'address',
21861
- },
21862
- {
21863
- internalType: 'uint256',
21864
- name: 'tokenId',
21865
- type: 'uint256',
21866
- },
21867
- ],
21868
- name: 'approve',
21869
- outputs: [],
21870
- payable: false,
21871
- stateMutability: 'nonpayable',
21872
- type: 'function',
21873
- },
21874
- {
21875
- constant: true,
21876
- inputs: [
21877
- {
21878
- internalType: 'address',
21879
- name: 'owner',
21880
- type: 'address',
21881
- },
21882
- {
21883
- internalType: 'address',
21884
- name: 'operator',
21885
- type: 'address',
21886
- },
21887
- ],
21888
- name: 'isApprovedForAll',
21889
- outputs: [
21890
- {
21891
- internalType: 'bool',
21892
- name: '',
21893
- type: 'bool',
21894
- },
21895
- ],
21896
- payable: false,
21897
- stateMutability: 'view',
21898
- type: 'function',
21899
- },
21900
- {
21901
- constant: true,
21902
- inputs: [
21903
- {
21904
- internalType: 'uint256',
21905
- name: 'tokenId',
21906
- type: 'uint256',
21907
- },
21908
- ],
21909
- name: 'getApproved',
21910
- outputs: [
21911
- {
21912
- internalType: 'address',
21913
- name: '',
21914
- type: 'address',
21915
- },
21916
- ],
21917
- payable: false,
21918
- stateMutability: 'view',
21919
- type: 'function',
21920
- },
21921
- {
21922
- inputs: [
21923
- {
21924
- internalType: 'uint256',
21925
- name: 'tokenId',
21926
- type: 'uint256',
21927
- },
21928
- ],
21929
- name: 'ownerOf',
21930
- outputs: [
21931
- {
21932
- internalType: 'address',
21933
- name: '',
21934
- type: 'address',
21935
- },
21936
- ],
21937
- stateMutability: 'view',
21938
- type: 'function',
21939
- },
21940
- ];
21941
-
21942
- /**
21943
- * An enum representing the checkout status types
21944
- * @enum {string}
21945
- * @property {string} SUCCESS - If checkout succeeded as the transactions were able to be processed
21946
- * @property {string} FAILED - If checkout failed due to transactions not settling on chain
21947
- * @property {string} INSUFFICIENT_FUNDS - If checkout failed due to insufficient funds
21948
- */
21949
- var CheckoutStatus;
21950
- (function (CheckoutStatus) {
21951
- CheckoutStatus["SUCCESS"] = "SUCCESS";
21952
- CheckoutStatus["FAILED"] = "FAILED";
21953
- CheckoutStatus["INSUFFICIENT_FUNDS"] = "INSUFFICIENT_FUNDS";
21954
- })(CheckoutStatus || (CheckoutStatus = {}));
21955
- /**
21956
- * An enum representing the item types
21957
- * @enum {string}
21958
- * @property {string} NATIVE - If the item is a native token.
21959
- * @property {string} ERC20 - If the item is an ERC20 token.
21960
- * @property {string} ERC721 - If the item is an ERC721 token.
21961
- */
21962
- var ItemType;
21963
- (function (ItemType) {
21964
- ItemType["NATIVE"] = "NATIVE";
21965
- ItemType["ERC20"] = "ERC20";
21966
- ItemType["ERC721"] = "ERC721";
21967
- })(ItemType || (ItemType = {}));
21968
- /**
21969
- * An enum representing transaction or gas types
21970
- * @enum {string}
21971
- * @property {string} TRANSACTION - If the type is a transaction
21972
- * @property {string} GAS - If the type is the gas amount
21973
- */
21974
- var TransactionOrGasType;
21975
- (function (TransactionOrGasType) {
21976
- TransactionOrGasType["TRANSACTION"] = "TRANSACTION";
21977
- TransactionOrGasType["GAS"] = "GAS";
21978
- })(TransactionOrGasType || (TransactionOrGasType = {}));
21979
- /**
21980
- * An enum representing the gas token types
21981
- * @enum {string}
21982
- * @property {string} NATIVE - If the gas token is a native token.
21983
- * @property {string} ERC20 - If the gas token is an ERC20 token.
21984
- */
21985
- var GasTokenType;
21986
- (function (GasTokenType) {
21987
- GasTokenType["NATIVE"] = "NATIVE";
21988
- GasTokenType["ERC20"] = "ERC20";
21989
- })(GasTokenType || (GasTokenType = {}));
21990
- /**
21991
- * An enum representing the routing outcome types
21992
- * @enum {string}
21993
- * @property {string} ROUTES_FOUND - If funding routes were found for the transaction.
21994
- * @property {string} NO_ROUTES_FOUND - If no funding routes were found for the transaction.
21995
- * @property {string} NO_ROUTE_OPTIONS - If no routing options were available for the transaction.
21996
- */
21997
- var RoutingOutcomeType;
21998
- (function (RoutingOutcomeType) {
21999
- RoutingOutcomeType["ROUTES_FOUND"] = "ROUTES_FOUND";
22000
- RoutingOutcomeType["NO_ROUTES_FOUND"] = "NO_ROUTES_FOUND";
22001
- RoutingOutcomeType["NO_ROUTE_OPTIONS"] = "NO_ROUTE_OPTIONS";
22002
- })(RoutingOutcomeType || (RoutingOutcomeType = {}));
22003
- /**
22004
- * An enum representing the funding step types
22005
- * @enum {string}
22006
- * @property {string} BRIDGE - If the funding step is a bridge.
22007
- * @property {string} SWAP - If the funding step is a swap.
22008
- * @property {string} ONRAMP - If the funding step is an onramp.
21662
+ * An enum representing the funding step types
21663
+ * @enum {string}
21664
+ * @property {string} BRIDGE - If the funding step is a bridge.
21665
+ * @property {string} SWAP - If the funding step is a swap.
21666
+ * @property {string} ONRAMP - If the funding step is an onramp.
22009
21667
  */
22010
21668
  var FundingStepType;
22011
21669
  (function (FundingStepType) {
@@ -22112,158 +21770,507 @@ fn, customError) => {
22112
21770
  }
22113
21771
  };
22114
21772
 
22115
- // this function needs to be in a separate file to prevent circular dependencies with ./network
22116
- // this gives us access to the properties of the underlying provider object
22117
- async function getUnderlyingChainId(web3Provider) {
22118
- if (!web3Provider.provider?.request) {
22119
- throw new CheckoutError('Parsed provider is not a valid Web3Provider', CheckoutErrorType.WEB3_PROVIDER_ERROR);
22120
- }
22121
- const chainId = await web3Provider.provider.request({
22122
- method: WalletAction.GET_CHAINID,
22123
- params: [],
22124
- });
22125
- return parseInt(chainId, 16);
22126
- }
22127
-
22128
- /* eslint-disable @typescript-eslint/no-explicit-any */
22129
- const UNRECOGNISED_CHAIN_ERROR_CODE = 4902; // error code (MetaMask)
22130
- // these functions should not be exported. These functions should be used as part of an exported function e.g switchWalletNetwork() above.
22131
- // make sure to check if(provider.provider?.request) in the exported function and throw an error
22132
- // eslint-disable-next-line consistent-return
22133
- async function switchNetworkInWallet(networkMap, web3Provider, chainId) {
22134
- if (web3Provider.provider?.request) {
22135
- return await web3Provider.provider.request({
22136
- method: WalletAction.SWITCH_NETWORK,
22137
- params: [
22138
- {
22139
- chainId: networkMap.get(chainId)?.chainIdHex,
22140
- },
22141
- ],
22142
- });
22143
- }
22144
- }
22145
- // TODO: Should these functions always return something?
22146
- // eslint-disable-next-line consistent-return
22147
- async function addNetworkToWallet(networkMap, web3Provider, chainId) {
22148
- if (web3Provider.provider?.request) {
22149
- const networkDetails = networkMap.get(chainId);
22150
- const addNetwork = {
22151
- chainId: networkDetails?.chainIdHex,
22152
- chainName: networkDetails?.chainName,
22153
- rpcUrls: networkDetails?.rpcUrls,
22154
- nativeCurrency: networkDetails?.nativeCurrency,
22155
- blockExplorerUrls: networkDetails?.blockExplorerUrls,
22156
- };
22157
- return await web3Provider.provider.request({
22158
- method: WalletAction.ADD_NETWORK,
22159
- params: [addNetwork],
22160
- });
22161
- }
22162
- }
22163
- async function getNetworkAllowList(config, { type = NetworkFilterTypes.ALL, exclude }) {
22164
- const { networkMap } = config;
22165
- const allowedNetworkConfig = (await config.remote.getConfig('allowedNetworks'));
22166
- const list = allowedNetworkConfig.filter((network) => {
22167
- const allowAllTokens = type === NetworkFilterTypes.ALL;
22168
- const networkNotExcluded = !(exclude || [])
22169
- .map((exc) => exc.chainId)
22170
- .includes(network.chainId);
22171
- return allowAllTokens && networkNotExcluded;
22172
- });
22173
- const allowedNetworks = [];
22174
- list.forEach((element) => {
22175
- const newNetwork = networkMap.get(element.chainId);
22176
- if (newNetwork) {
22177
- allowedNetworks.push({
22178
- name: newNetwork.chainName,
22179
- chainId: parseInt(newNetwork.chainIdHex, 16),
22180
- nativeCurrency: newNetwork.nativeCurrency,
22181
- isSupported: true,
22182
- });
22183
- }
22184
- });
22185
- return {
22186
- networks: allowedNetworks,
22187
- };
22188
- }
22189
- async function getNetworkInfo(config, web3Provider) {
22190
- const { networkMap } = config;
22191
- return withCheckoutError(async () => {
22192
- try {
22193
- const network = await web3Provider.getNetwork();
22194
- if (Array.from(networkMap.keys()).includes(network.chainId)) {
22195
- const chainIdNetworkInfo = networkMap.get(network.chainId);
22196
- return {
22197
- name: chainIdNetworkInfo.chainName,
22198
- chainId: parseInt(chainIdNetworkInfo.chainIdHex, 16),
22199
- nativeCurrency: chainIdNetworkInfo.nativeCurrency,
22200
- isSupported: true,
22201
- };
22202
- }
22203
- return {
22204
- chainId: network.chainId,
22205
- name: network.name,
22206
- isSupported: false,
22207
- };
22208
- }
22209
- catch (err) {
22210
- const chainId = await getUnderlyingChainId(web3Provider);
22211
- const isSupported = Array.from(networkMap.keys()).includes(chainId);
22212
- return {
22213
- chainId,
22214
- isSupported,
22215
- };
22216
- }
22217
- }, {
22218
- type: CheckoutErrorType.GET_NETWORK_INFO_ERROR,
22219
- });
22220
- }
22221
- async function switchWalletNetwork(config, web3Provider, chainId) {
22222
- const { networkMap } = config;
22223
- const allowedNetworks = await getNetworkAllowList(config, {
22224
- type: NetworkFilterTypes.ALL,
22225
- });
22226
- if (!allowedNetworks.networks.some((network) => network.chainId === chainId)) {
22227
- throw new CheckoutError(`Chain:${chainId} is not a supported chain`, CheckoutErrorType.CHAIN_NOT_SUPPORTED_ERROR);
22228
- }
22229
- if (web3Provider.provider?.isPassport) {
22230
- throw new CheckoutError('Switching networks with Passport provider is not supported', CheckoutErrorType.SWITCH_NETWORK_UNSUPPORTED);
22231
- }
22232
- // WT-1146 - Refer to the README in this folder for explanation on the switch network flow
22233
- try {
22234
- await switchNetworkInWallet(networkMap, web3Provider, chainId);
22235
- }
22236
- catch (err) {
22237
- if (err.code === UNRECOGNISED_CHAIN_ERROR_CODE) {
22238
- try {
22239
- await addNetworkToWallet(networkMap, web3Provider, chainId);
22240
- // eslint-disable-next-line @typescript-eslint/no-shadow
22241
- }
22242
- catch (err) {
22243
- throw new CheckoutError('User cancelled add network request', CheckoutErrorType.USER_REJECTED_REQUEST_ERROR);
22244
- }
22245
- }
22246
- else {
22247
- throw new CheckoutError('User cancelled switch network request', CheckoutErrorType.USER_REJECTED_REQUEST_ERROR);
22248
- }
22249
- }
22250
- const newProvider = new Web3Provider(web3Provider.provider);
22251
- const newProviderNetwork = await newProvider.getNetwork();
22252
- if (newProviderNetwork.chainId !== chainId) {
22253
- throw new CheckoutError('User cancelled switch network request', CheckoutErrorType.USER_REJECTED_REQUEST_ERROR);
22254
- }
22255
- const networkInfo = await getNetworkInfo(config, newProvider);
22256
- return {
22257
- network: networkInfo,
22258
- provider: newProvider,
22259
- };
22260
- }
21773
+ // this function needs to be in a separate file to prevent circular dependencies with ./network
21774
+ // this gives us access to the properties of the underlying provider object
21775
+ async function getUnderlyingChainId(web3Provider) {
21776
+ if (!web3Provider.provider?.request) {
21777
+ throw new CheckoutError('Parsed provider is not a valid Web3Provider', CheckoutErrorType.WEB3_PROVIDER_ERROR);
21778
+ }
21779
+ const chainId = await web3Provider.provider.request({
21780
+ method: WalletAction.GET_CHAINID,
21781
+ params: [],
21782
+ });
21783
+ return parseInt(chainId, 16);
21784
+ }
21785
+
21786
+ /* eslint-disable @typescript-eslint/no-explicit-any */
21787
+ const UNRECOGNISED_CHAIN_ERROR_CODE = 4902; // error code (MetaMask)
21788
+ // these functions should not be exported. These functions should be used as part of an exported function e.g switchWalletNetwork() above.
21789
+ // make sure to check if(provider.provider?.request) in the exported function and throw an error
21790
+ // eslint-disable-next-line consistent-return
21791
+ async function switchNetworkInWallet(networkMap, web3Provider, chainId) {
21792
+ if (web3Provider.provider?.request) {
21793
+ return await web3Provider.provider.request({
21794
+ method: WalletAction.SWITCH_NETWORK,
21795
+ params: [
21796
+ {
21797
+ chainId: networkMap.get(chainId)?.chainIdHex,
21798
+ },
21799
+ ],
21800
+ });
21801
+ }
21802
+ }
21803
+ // TODO: Should these functions always return something?
21804
+ // eslint-disable-next-line consistent-return
21805
+ async function addNetworkToWallet(networkMap, web3Provider, chainId) {
21806
+ if (web3Provider.provider?.request) {
21807
+ const networkDetails = networkMap.get(chainId);
21808
+ const addNetwork = {
21809
+ chainId: networkDetails?.chainIdHex,
21810
+ chainName: networkDetails?.chainName,
21811
+ rpcUrls: networkDetails?.rpcUrls,
21812
+ nativeCurrency: networkDetails?.nativeCurrency,
21813
+ blockExplorerUrls: networkDetails?.blockExplorerUrls,
21814
+ };
21815
+ return await web3Provider.provider.request({
21816
+ method: WalletAction.ADD_NETWORK,
21817
+ params: [addNetwork],
21818
+ });
21819
+ }
21820
+ }
21821
+ async function getNetworkAllowList(config, { type = NetworkFilterTypes.ALL, exclude }) {
21822
+ const { networkMap } = config;
21823
+ const allowedNetworkConfig = (await config.remote.getConfig('allowedNetworks'));
21824
+ const list = allowedNetworkConfig.filter((network) => {
21825
+ const allowAllTokens = type === NetworkFilterTypes.ALL;
21826
+ const networkNotExcluded = !(exclude || [])
21827
+ .map((exc) => exc.chainId)
21828
+ .includes(network.chainId);
21829
+ return allowAllTokens && networkNotExcluded;
21830
+ });
21831
+ const allowedNetworks = [];
21832
+ list.forEach((element) => {
21833
+ const newNetwork = networkMap.get(element.chainId);
21834
+ if (newNetwork) {
21835
+ allowedNetworks.push({
21836
+ name: newNetwork.chainName,
21837
+ chainId: parseInt(newNetwork.chainIdHex, 16),
21838
+ nativeCurrency: newNetwork.nativeCurrency,
21839
+ isSupported: true,
21840
+ });
21841
+ }
21842
+ });
21843
+ return {
21844
+ networks: allowedNetworks,
21845
+ };
21846
+ }
21847
+ async function getNetworkInfo(config, web3Provider) {
21848
+ const { networkMap } = config;
21849
+ return withCheckoutError(async () => {
21850
+ try {
21851
+ const network = await web3Provider.getNetwork();
21852
+ if (Array.from(networkMap.keys()).includes(network.chainId)) {
21853
+ const chainIdNetworkInfo = networkMap.get(network.chainId);
21854
+ return {
21855
+ name: chainIdNetworkInfo.chainName,
21856
+ chainId: parseInt(chainIdNetworkInfo.chainIdHex, 16),
21857
+ nativeCurrency: chainIdNetworkInfo.nativeCurrency,
21858
+ isSupported: true,
21859
+ };
21860
+ }
21861
+ return {
21862
+ chainId: network.chainId,
21863
+ name: network.name,
21864
+ isSupported: false,
21865
+ };
21866
+ }
21867
+ catch (err) {
21868
+ const chainId = await getUnderlyingChainId(web3Provider);
21869
+ const isSupported = Array.from(networkMap.keys()).includes(chainId);
21870
+ return {
21871
+ chainId,
21872
+ isSupported,
21873
+ };
21874
+ }
21875
+ }, {
21876
+ type: CheckoutErrorType.GET_NETWORK_INFO_ERROR,
21877
+ });
21878
+ }
21879
+ async function switchWalletNetwork(config, web3Provider, chainId) {
21880
+ const { networkMap } = config;
21881
+ const allowedNetworks = await getNetworkAllowList(config, {
21882
+ type: NetworkFilterTypes.ALL,
21883
+ });
21884
+ if (!allowedNetworks.networks.some((network) => network.chainId === chainId)) {
21885
+ throw new CheckoutError(`Chain:${chainId} is not a supported chain`, CheckoutErrorType.CHAIN_NOT_SUPPORTED_ERROR);
21886
+ }
21887
+ if (web3Provider.provider?.isPassport) {
21888
+ throw new CheckoutError('Switching networks with Passport provider is not supported', CheckoutErrorType.SWITCH_NETWORK_UNSUPPORTED);
21889
+ }
21890
+ // WT-1146 - Refer to the README in this folder for explanation on the switch network flow
21891
+ try {
21892
+ await switchNetworkInWallet(networkMap, web3Provider, chainId);
21893
+ }
21894
+ catch (err) {
21895
+ if (err.code === UNRECOGNISED_CHAIN_ERROR_CODE) {
21896
+ try {
21897
+ await addNetworkToWallet(networkMap, web3Provider, chainId);
21898
+ // eslint-disable-next-line @typescript-eslint/no-shadow
21899
+ }
21900
+ catch (err) {
21901
+ throw new CheckoutError('User cancelled add network request', CheckoutErrorType.USER_REJECTED_REQUEST_ERROR);
21902
+ }
21903
+ }
21904
+ else {
21905
+ throw new CheckoutError('User cancelled switch network request', CheckoutErrorType.USER_REJECTED_REQUEST_ERROR);
21906
+ }
21907
+ }
21908
+ const newProvider = new Web3Provider(web3Provider.provider);
21909
+ const newProviderNetwork = await newProvider.getNetwork();
21910
+ if (newProviderNetwork.chainId !== chainId) {
21911
+ throw new CheckoutError('User cancelled switch network request', CheckoutErrorType.USER_REJECTED_REQUEST_ERROR);
21912
+ }
21913
+ const networkInfo = await getNetworkInfo(config, newProvider);
21914
+ return {
21915
+ network: networkInfo,
21916
+ provider: newProvider,
21917
+ };
21918
+ }
21919
+
21920
+ const ENV_DEVELOPMENT = 'development';
21921
+ const DEFAULT_TOKEN_DECIMALS$1 = 18;
21922
+ const NATIVE = 'native';
21923
+ const ZKEVM_NATIVE_TOKEN = {
21924
+ name: 'IMX',
21925
+ symbol: 'IMX',
21926
+ decimals: DEFAULT_TOKEN_DECIMALS$1,
21927
+ };
21928
+ /**
21929
+ * Base URL for the Immutable API based on the environment.
21930
+ * @property {string} DEVELOPMENT - The base URL for the development environment.
21931
+ * @property {string} SANDBOX - The base URL for the sandbox environment.
21932
+ * @property {string} PRODUCTION - The base URL for the production environment.
21933
+ */
21934
+ const IMMUTABLE_API_BASE_URL = {
21935
+ [ENV_DEVELOPMENT]: 'https://api.dev.immutable.com',
21936
+ [Environment$1.SANDBOX]: 'https://api.sandbox.immutable.com',
21937
+ [Environment$1.PRODUCTION]: 'https://api.immutable.com',
21938
+ };
21939
+ /**
21940
+ * Base URL for the checkout API based on the environment.
21941
+ * @property {string} DEVELOPMENT - The base URL for the development environment.
21942
+ * @property {string} SANDBOX - The base URL for the sandbox environment.
21943
+ * @property {string} PRODUCTION - The base URL for the production environment.
21944
+ */
21945
+ const CHECKOUT_API_BASE_URL = {
21946
+ [ENV_DEVELOPMENT]: 'https://checkout-api.dev.immutable.com',
21947
+ [Environment$1.SANDBOX]: 'https://checkout-api.sandbox.immutable.com',
21948
+ [Environment$1.PRODUCTION]: 'https://checkout-api.immutable.com',
21949
+ };
21950
+ /**
21951
+ * Smart Checkout routing default onramp enabled flag
21952
+ */
21953
+ const DEFAULT_ON_RAMP_ENABLED = true;
21954
+ /**
21955
+ * Smart Checkout routing default swap enabled flag
21956
+ */
21957
+ const DEFAULT_SWAP_ENABLED = true;
21958
+ /**
21959
+ * Smart Checkout routing default bridge enabled flag
21960
+ */
21961
+ const DEFAULT_BRIDGE_ENABLED = true;
21962
+ const TRANSAK_API_BASE_URL = {
21963
+ [Environment$1.SANDBOX]: 'https://global-stg.transak.com',
21964
+ [Environment$1.PRODUCTION]: 'https://global.transak.com/',
21965
+ };
21966
+ const PRODUCTION_CHAIN_ID_NETWORK_MAP = new Map([
21967
+ [
21968
+ ChainId.ETHEREUM,
21969
+ {
21970
+ chainIdHex: `0x${ChainId.ETHEREUM.toString(16)}`,
21971
+ chainName: ChainName.ETHEREUM,
21972
+ rpcUrls: ['https://checkout-api.immutable.com/v1/rpc/eth-mainnet'],
21973
+ nativeCurrency: {
21974
+ name: ChainName.ETHEREUM,
21975
+ symbol: 'ETH',
21976
+ decimals: 18,
21977
+ },
21978
+ blockExplorerUrls: ['https://etherscan.io/'],
21979
+ },
21980
+ ],
21981
+ [
21982
+ ChainId.IMTBL_ZKEVM_MAINNET,
21983
+ {
21984
+ chainIdHex: `0x${ChainId.IMTBL_ZKEVM_MAINNET.toString(16)}`,
21985
+ chainName: ChainName.IMTBL_ZKEVM_MAINNET,
21986
+ rpcUrls: ['https://rpc.immutable.com'],
21987
+ nativeCurrency: ZKEVM_NATIVE_TOKEN,
21988
+ },
21989
+ ],
21990
+ ]);
21991
+ const SANDBOX_CHAIN_ID_NETWORK_MAP = new Map([
21992
+ [
21993
+ ChainId.SEPOLIA,
21994
+ {
21995
+ chainIdHex: `0x${ChainId.SEPOLIA.toString(16)}`,
21996
+ chainName: ChainName.SEPOLIA,
21997
+ rpcUrls: [
21998
+ 'https://checkout-api.sandbox.immutable.com/v1/rpc/eth-sepolia',
21999
+ ],
22000
+ nativeCurrency: {
22001
+ name: 'Sep Eth',
22002
+ symbol: 'ETH',
22003
+ decimals: 18,
22004
+ },
22005
+ blockExplorerUrls: ['https://sepolia.etherscan.io/'],
22006
+ },
22007
+ ],
22008
+ [
22009
+ ChainId.IMTBL_ZKEVM_TESTNET,
22010
+ {
22011
+ chainIdHex: `0x${ChainId.IMTBL_ZKEVM_TESTNET.toString(16)}`,
22012
+ chainName: ChainName.IMTBL_ZKEVM_TESTNET,
22013
+ rpcUrls: ['https://rpc.testnet.immutable.com'],
22014
+ nativeCurrency: ZKEVM_NATIVE_TOKEN,
22015
+ },
22016
+ ],
22017
+ ]);
22018
+ const DEV_CHAIN_ID_NETWORK_MAP = new Map([
22019
+ [
22020
+ ChainId.SEPOLIA,
22021
+ {
22022
+ chainIdHex: `0x${ChainId.SEPOLIA.toString(16)}`,
22023
+ chainName: ChainName.SEPOLIA,
22024
+ rpcUrls: ['https://checkout-api.dev.immutable.com/v1/rpc/eth-sepolia'],
22025
+ nativeCurrency: {
22026
+ name: 'Sep Eth',
22027
+ symbol: 'ETH',
22028
+ decimals: 18,
22029
+ },
22030
+ blockExplorerUrls: ['https://sepolia.etherscan.io/'],
22031
+ },
22032
+ ],
22033
+ [
22034
+ ChainId.IMTBL_ZKEVM_DEVNET,
22035
+ {
22036
+ chainIdHex: `0x${ChainId.IMTBL_ZKEVM_DEVNET.toString(16)}`,
22037
+ chainName: ChainName.IMTBL_ZKEVM_DEVNET,
22038
+ rpcUrls: ['https://rpc.dev.immutable.com'],
22039
+ nativeCurrency: ZKEVM_NATIVE_TOKEN,
22040
+ },
22041
+ ],
22042
+ ]);
22043
+ /**
22044
+ * Blockscout API configuration per chain
22045
+ */
22046
+ const BLOCKSCOUT_CHAIN_URL_MAP = {
22047
+ [ChainId.IMTBL_ZKEVM_TESTNET]: {
22048
+ url: 'https://explorer.testnet.immutable.com',
22049
+ nativeToken: SANDBOX_CHAIN_ID_NETWORK_MAP.get(ChainId.IMTBL_ZKEVM_TESTNET).nativeCurrency,
22050
+ },
22051
+ [ChainId.IMTBL_ZKEVM_MAINNET]: {
22052
+ url: 'https://explorer.mainnet.immutable.com',
22053
+ nativeToken: PRODUCTION_CHAIN_ID_NETWORK_MAP.get(ChainId.IMTBL_ZKEVM_MAINNET).nativeCurrency,
22054
+ },
22055
+ [ChainId.SEPOLIA]: {
22056
+ url: 'https://eth-sepolia.blockscout.com',
22057
+ nativeToken: SANDBOX_CHAIN_ID_NETWORK_MAP.get(ChainId.SEPOLIA).nativeCurrency,
22058
+ },
22059
+ [ChainId.ETHEREUM]: {
22060
+ url: 'https://eth.blockscout.com/',
22061
+ nativeToken: PRODUCTION_CHAIN_ID_NETWORK_MAP.get(ChainId.ETHEREUM).nativeCurrency,
22062
+ },
22063
+ };
22064
+ const ERC20ABI = [
22065
+ {
22066
+ constant: true,
22067
+ inputs: [],
22068
+ name: 'name',
22069
+ outputs: [
22070
+ {
22071
+ name: '',
22072
+ type: 'string',
22073
+ },
22074
+ ],
22075
+ payable: false,
22076
+ type: 'function',
22077
+ },
22078
+ {
22079
+ constant: true,
22080
+ inputs: [],
22081
+ name: 'decimals',
22082
+ outputs: [
22083
+ {
22084
+ name: '',
22085
+ type: 'uint8',
22086
+ },
22087
+ ],
22088
+ payable: false,
22089
+ type: 'function',
22090
+ },
22091
+ {
22092
+ constant: true,
22093
+ inputs: [
22094
+ {
22095
+ name: '_owner',
22096
+ type: 'address',
22097
+ },
22098
+ ],
22099
+ name: 'balanceOf',
22100
+ outputs: [
22101
+ {
22102
+ name: 'balance',
22103
+ type: 'uint256',
22104
+ },
22105
+ ],
22106
+ payable: false,
22107
+ type: 'function',
22108
+ },
22109
+ {
22110
+ constant: true,
22111
+ inputs: [],
22112
+ name: 'symbol',
22113
+ outputs: [
22114
+ {
22115
+ name: '',
22116
+ type: 'string',
22117
+ },
22118
+ ],
22119
+ payable: false,
22120
+ type: 'function',
22121
+ },
22122
+ {
22123
+ constant: true,
22124
+ inputs: [
22125
+ {
22126
+ name: '_owner',
22127
+ type: 'address',
22128
+ },
22129
+ {
22130
+ name: '_spender',
22131
+ type: 'address',
22132
+ },
22133
+ ],
22134
+ name: 'allowance',
22135
+ outputs: [
22136
+ {
22137
+ name: '',
22138
+ type: 'uint256',
22139
+ },
22140
+ ],
22141
+ payable: false,
22142
+ stateMutability: 'view',
22143
+ type: 'function',
22144
+ },
22145
+ {
22146
+ constant: false,
22147
+ inputs: [
22148
+ {
22149
+ name: '_spender',
22150
+ type: 'address',
22151
+ },
22152
+ {
22153
+ name: '_value',
22154
+ type: 'uint256',
22155
+ },
22156
+ ],
22157
+ name: 'approve',
22158
+ outputs: [
22159
+ {
22160
+ name: '',
22161
+ type: 'bool',
22162
+ },
22163
+ ],
22164
+ payable: false,
22165
+ stateMutability: 'nonpayable',
22166
+ type: 'function',
22167
+ },
22168
+ ];
22169
+ const ERC721ABI = [
22170
+ {
22171
+ constant: false,
22172
+ inputs: [
22173
+ {
22174
+ internalType: 'address',
22175
+ name: 'to',
22176
+ type: 'address',
22177
+ },
22178
+ {
22179
+ internalType: 'uint256',
22180
+ name: 'tokenId',
22181
+ type: 'uint256',
22182
+ },
22183
+ ],
22184
+ name: 'approve',
22185
+ outputs: [],
22186
+ payable: false,
22187
+ stateMutability: 'nonpayable',
22188
+ type: 'function',
22189
+ },
22190
+ {
22191
+ constant: true,
22192
+ inputs: [
22193
+ {
22194
+ internalType: 'address',
22195
+ name: 'owner',
22196
+ type: 'address',
22197
+ },
22198
+ {
22199
+ internalType: 'address',
22200
+ name: 'operator',
22201
+ type: 'address',
22202
+ },
22203
+ ],
22204
+ name: 'isApprovedForAll',
22205
+ outputs: [
22206
+ {
22207
+ internalType: 'bool',
22208
+ name: '',
22209
+ type: 'bool',
22210
+ },
22211
+ ],
22212
+ payable: false,
22213
+ stateMutability: 'view',
22214
+ type: 'function',
22215
+ },
22216
+ {
22217
+ constant: true,
22218
+ inputs: [
22219
+ {
22220
+ internalType: 'uint256',
22221
+ name: 'tokenId',
22222
+ type: 'uint256',
22223
+ },
22224
+ ],
22225
+ name: 'getApproved',
22226
+ outputs: [
22227
+ {
22228
+ internalType: 'address',
22229
+ name: '',
22230
+ type: 'address',
22231
+ },
22232
+ ],
22233
+ payable: false,
22234
+ stateMutability: 'view',
22235
+ type: 'function',
22236
+ },
22237
+ {
22238
+ inputs: [
22239
+ {
22240
+ internalType: 'uint256',
22241
+ name: 'tokenId',
22242
+ type: 'uint256',
22243
+ },
22244
+ ],
22245
+ name: 'ownerOf',
22246
+ outputs: [
22247
+ {
22248
+ internalType: 'address',
22249
+ name: '',
22250
+ type: 'address',
22251
+ },
22252
+ ],
22253
+ stateMutability: 'view',
22254
+ type: 'function',
22255
+ },
22256
+ ];
22257
+ // Gas overrides -- Anti-spam mechanism for when the baseFee drops low
22258
+ // https://github.com/immutable/imx-docs/blob/main/docs/main/zkEVM/overview/gas-configuration.md
22259
+ const GAS_OVERRIDES = {
22260
+ maxFeePerGas: BigNumber$1.from(102e9),
22261
+ maxPriorityFeePerGas: BigNumber$1.from(101e9),
22262
+ };
22263
+
22264
+ const SDK_VERSION_MARKER = '0.33.0';
22265
+ // This SDK version is replaced by the `yarn build` command ran on the root level
22266
+ const globalPackageVersion = () => SDK_VERSION_MARKER;
22261
22267
 
22262
22268
  class RemoteConfigFetcher {
22263
22269
  isDevelopment;
22264
22270
  isProduction;
22265
22271
  configCache;
22266
22272
  tokensCache;
22273
+ version = 'v1';
22267
22274
  constructor(params) {
22268
22275
  this.isDevelopment = params.isDevelopment;
22269
22276
  this.isProduction = params.isProduction;
@@ -22291,14 +22298,14 @@ class RemoteConfigFetcher {
22291
22298
  async loadConfig() {
22292
22299
  if (this.configCache)
22293
22300
  return this.configCache;
22294
- const response = await RemoteConfigFetcher.makeHttpRequest(`${this.getEndpoint()}/v1/config`);
22301
+ const response = await RemoteConfigFetcher.makeHttpRequest(`${this.getEndpoint()}/${this.version}/config`);
22295
22302
  this.configCache = response.data;
22296
22303
  return this.configCache;
22297
22304
  }
22298
22305
  async loadConfigTokens() {
22299
22306
  if (this.tokensCache)
22300
22307
  return this.tokensCache;
22301
- const response = await RemoteConfigFetcher.makeHttpRequest(`${this.getEndpoint()}/v1/config/tokens`);
22308
+ const response = await RemoteConfigFetcher.makeHttpRequest(`${this.getEndpoint()}/${this.version}/config/tokens`);
22302
22309
  this.tokensCache = response.data;
22303
22310
  return this.tokensCache;
22304
22311
  }
@@ -22414,6 +22421,7 @@ const getTokenAllowList = async (config, { type = TokenFilterTypes.ALL, chainId,
22414
22421
  tokens: tokens.filter((token) => !exclude.map((e) => e.address).includes(token.address || '')),
22415
22422
  };
22416
22423
  };
22424
+ const isNativeToken = (address) => !address || address.toLocaleLowerCase() === NATIVE;
22417
22425
 
22418
22426
  const CACHE_DATA_TTL = 60; // seconds
22419
22427
  /**
@@ -22613,7 +22621,7 @@ const getIndexerBalance = async (walletAddress, chainId, filterTokens) => {
22613
22621
  // Shuffle the mapping of the tokens configuration so it is a hashmap
22614
22622
  // for faster access to tokens config objects.
22615
22623
  const shouldFilter = filterTokens.length > 0;
22616
- const mapFilterTokens = Object.assign({}, ...(filterTokens.map((t) => ({ [t.address || '']: t }))));
22624
+ const mapFilterTokens = Object.assign({}, ...(filterTokens.map((t) => ({ [t.address || NATIVE]: t }))));
22617
22625
  // Get blockscout client for the given chain
22618
22626
  let blockscoutClient = blockscoutClientMap.get(chainId);
22619
22627
  if (!blockscoutClient) {
@@ -22654,6 +22662,7 @@ const getIndexerBalance = async (walletAddress, chainId, filterTokens) => {
22654
22662
  const nativeBalances = async (client) => {
22655
22663
  try {
22656
22664
  const respNative = await client.getNativeTokenByWalletAddress({ walletAddress });
22665
+ respNative.token.address ||= NATIVE;
22657
22666
  items.push(respNative);
22658
22667
  }
22659
22668
  catch (err) {
@@ -22696,8 +22705,7 @@ const getBalances = async (config, web3Provider, walletAddress, tokens) => {
22696
22705
  const allBalancePromises = [];
22697
22706
  tokens
22698
22707
  .forEach((token) => {
22699
- // Check for NATIVE token
22700
- if (!token.address || token.address === IMX_ADDRESS_ZKEVM) {
22708
+ if (!token.address || token.address.toLocaleLowerCase() === NATIVE) {
22701
22709
  allBalancePromises.push(getBalance(config, web3Provider, walletAddress));
22702
22710
  }
22703
22711
  else {
@@ -22883,11 +22891,17 @@ async function getWalletAllowList(params) {
22883
22891
  };
22884
22892
  }
22885
22893
 
22894
+ const setTransactionGasLimits = (transaction) => {
22895
+ const rawTx = transaction;
22896
+ rawTx.maxFeePerGas = GAS_OVERRIDES.maxFeePerGas;
22897
+ rawTx.maxPriorityFeePerGas = GAS_OVERRIDES.maxPriorityFeePerGas;
22898
+ return rawTx;
22899
+ };
22886
22900
  const sendTransaction = async (web3Provider, transaction) => {
22887
22901
  try {
22888
- const transactionResponse = await web3Provider
22889
- .getSigner()
22890
- .sendTransaction(transaction);
22902
+ const signer = web3Provider.getSigner();
22903
+ const rawTx = setTransactionGasLimits(transaction);
22904
+ const transactionResponse = await signer.sendTransaction(rawTx);
22891
22905
  return {
22892
22906
  transactionResponse,
22893
22907
  };
@@ -23050,25 +23064,21 @@ async function swapGasEstimator(config) {
23050
23064
  const exchange = await createExchangeInstance(chainId, config);
23051
23065
  // Create a fake transaction to get the gas from the quote
23052
23066
  const { swap } = await exchange.getUnsignedSwapTxFromAmountIn(DUMMY_WALLET_ADDRESS, inAddress, outAddress, BigNumber$1.from(utils.parseUnits('1', DEFAULT_TOKEN_DECIMALS)));
23053
- if (swap.gasFeeEstimate === null) {
23067
+ if (!swap.gasFeeEstimate) {
23054
23068
  return {
23055
23069
  gasEstimateType: GasEstimateType.SWAP,
23056
23070
  gasFee: {},
23057
23071
  };
23058
23072
  }
23059
- let estimatedAmount;
23060
- if (swap.gasFeeEstimate.value) {
23061
- estimatedAmount = BigNumber$1.from(swap.gasFeeEstimate.value);
23062
- }
23063
23073
  return {
23064
23074
  gasEstimateType: GasEstimateType.SWAP,
23065
23075
  gasFee: {
23066
- estimatedAmount,
23076
+ estimatedAmount: swap.gasFeeEstimate.value ? BigNumber$1.from(swap.gasFeeEstimate.value) : undefined,
23067
23077
  token: {
23068
- address: swap.gasFeeEstimate?.token.address,
23069
- symbol: swap.gasFeeEstimate?.token.symbol ?? '',
23070
- name: swap.gasFeeEstimate?.token.name ?? '',
23071
- decimals: swap.gasFeeEstimate?.token.decimals ?? DEFAULT_TOKEN_DECIMALS,
23078
+ address: swap.gasFeeEstimate.token.address,
23079
+ symbol: swap.gasFeeEstimate.token.symbol ?? '',
23080
+ name: swap.gasFeeEstimate.token.name ?? '',
23081
+ decimals: swap.gasFeeEstimate.token.decimals ?? DEFAULT_TOKEN_DECIMALS,
23072
23082
  },
23073
23083
  },
23074
23084
  };
@@ -23459,7 +23469,7 @@ const getTokensFromRequirements = (itemRequirements) => itemRequirements
23459
23469
  .map((itemRequirement) => {
23460
23470
  if (itemRequirement.type === ItemType.NATIVE) {
23461
23471
  return {
23462
- address: IMX_ADDRESS_ZKEVM,
23472
+ address: NATIVE,
23463
23473
  };
23464
23474
  }
23465
23475
  return {
@@ -23519,8 +23529,7 @@ const getTokenBalanceRequirement = (itemRequirement, balances) => {
23519
23529
  }
23520
23530
  else if (itemRequirement.type === ItemType.NATIVE) {
23521
23531
  itemBalanceResult = balances.find((balance) => {
23522
- return balance.token?.address === ''
23523
- || balance.token?.address === IMX_ADDRESS_ZKEVM;
23532
+ return isNativeToken(balance.token?.address);
23524
23533
  });
23525
23534
  }
23526
23535
  // Calculate the balance delta
@@ -23548,7 +23557,6 @@ const getTokenBalanceRequirement = (itemRequirement, balances) => {
23548
23557
  name,
23549
23558
  symbol,
23550
23559
  decimals: DEFAULT_TOKEN_DECIMALS$1,
23551
- address: IMX_ADDRESS_ZKEVM,
23552
23560
  },
23553
23561
  };
23554
23562
  }
@@ -23607,9 +23615,13 @@ const getTokenBalanceRequirement = (itemRequirement, balances) => {
23607
23615
  const getTokenBalances = async (config, provider, ownerAddress, itemRequirements) => {
23608
23616
  try {
23609
23617
  const tokenMap = new Map();
23610
- getTokensFromRequirements(itemRequirements).forEach((item) => tokenMap.set((item.address || '').toLocaleLowerCase(), item));
23611
- const { balances } = await getAllBalances(config, provider, ownerAddress);
23612
- return balances.filter((balance) => tokenMap.get((balance.token.address || '').toLocaleLowerCase()));
23618
+ getTokensFromRequirements(itemRequirements).forEach((item) => {
23619
+ if (!item.address)
23620
+ return;
23621
+ tokenMap.set(item.address.toLocaleLowerCase(), item);
23622
+ });
23623
+ const { balances } = await getAllBalances(config, provider, ownerAddress, getL2ChainId(config));
23624
+ return balances.filter((balance) => tokenMap.get((balance.token.address || NATIVE).toLocaleLowerCase()));
23613
23625
  }
23614
23626
  catch (error) {
23615
23627
  throw new CheckoutError('Failed to get balances', CheckoutErrorType.GET_BALANCE_ERROR);
@@ -24015,7 +24027,7 @@ const constructFees$1 = (approvalGasFees, swapGasFees, swapFees) => {
24015
24027
  const constructSwapRoute = (chainId, fundsRequired, userBalance, fees) => {
24016
24028
  const tokenAddress = userBalance.token.address;
24017
24029
  let type = ItemType.ERC20;
24018
- if (tokenAddress === IMX_ADDRESS_ZKEVM) {
24030
+ if (isNativeToken(tokenAddress)) {
24019
24031
  type = ItemType.NATIVE;
24020
24032
  }
24021
24033
  return {
@@ -24036,16 +24048,24 @@ const constructSwapRoute = (chainId, fundsRequired, userBalance, fees) => {
24036
24048
  fees,
24037
24049
  };
24038
24050
  };
24051
+ const isBalanceRequirementTokenValid = (balanceRequirement) => {
24052
+ if (balanceRequirement.type === ItemType.ERC20) {
24053
+ return !!balanceRequirement.required.token.address;
24054
+ }
24055
+ if (balanceRequirement.type === ItemType.NATIVE) {
24056
+ return isNativeToken(balanceRequirement.required.token.address);
24057
+ }
24058
+ return false;
24059
+ };
24039
24060
  const getRequiredToken = (balanceRequirement) => {
24040
24061
  let address = '';
24041
24062
  let amount = BigNumber$1.from(0);
24042
24063
  switch (balanceRequirement.type) {
24043
24064
  case ItemType.ERC20:
24044
- address = balanceRequirement.required.token.address ?? '';
24065
+ address = balanceRequirement.required.token.address;
24045
24066
  amount = balanceRequirement.delta.balance;
24046
24067
  break;
24047
24068
  case ItemType.NATIVE:
24048
- address = IMX_ADDRESS_ZKEVM;
24049
24069
  amount = balanceRequirement.delta.balance;
24050
24070
  break;
24051
24071
  }
@@ -24066,7 +24086,8 @@ const checkUserCanCoverApprovalFees = (l2Balances, approval) => {
24066
24086
  };
24067
24087
  }
24068
24088
  // Find the users balance of the approval token
24069
- const l2BalanceOfApprovalToken = l2Balances.find((balance) => balance.token.address === approvalGasTokenAddress);
24089
+ const l2BalanceOfApprovalToken = l2Balances.find((balance) => (isNativeToken(balance.token.address) && isNativeToken(approvalGasTokenAddress))
24090
+ || balance.token.address === approvalGasTokenAddress);
24070
24091
  if (!l2BalanceOfApprovalToken)
24071
24092
  return { sufficient: false, approvalGasFee, approvalGasTokenAddress };
24072
24093
  // If the user does not have enough of the token to cover approval fees then return sufficient false
@@ -24084,7 +24105,7 @@ const checkUserCanCoverSwapFees = (l2Balances, approvalFees, swapGasFees, swapFe
24084
24105
  // Set up a map of token addresses to amounts for each of the swap fees
24085
24106
  const feeMap = new Map();
24086
24107
  // Add the approval fee to list of fees
24087
- if (approvalFees.approvalGasTokenAddress !== '') {
24108
+ if (approvalFees.approvalGasFee.gt(BigNumber$1.from(0))) {
24088
24109
  feeMap.set(approvalFees.approvalGasTokenAddress, approvalFees.approvalGasFee);
24089
24110
  }
24090
24111
  // Add the swap gas fee to list of fees
@@ -24120,7 +24141,8 @@ const checkUserCanCoverSwapFees = (l2Balances, approvalFees, swapGasFees, swapFe
24120
24141
  for (const [tokenAddress, fee] of feeMap.entries()) {
24121
24142
  if (fee === BigNumber$1.from(0))
24122
24143
  continue;
24123
- const l2BalanceOfFeeToken = l2Balances.find((balance) => balance.token.address === tokenAddress);
24144
+ const l2BalanceOfFeeToken = l2Balances.find((balance) => (isNativeToken(balance.token.address) && isNativeToken(tokenAddress))
24145
+ || balance.token.address === tokenAddress);
24124
24146
  if (!l2BalanceOfFeeToken) {
24125
24147
  return false;
24126
24148
  }
@@ -24172,9 +24194,9 @@ const swapRoute = async (config, availableRoutingOptions, walletAddress, balance
24172
24194
  return fundingSteps;
24173
24195
  if (swappableTokens.length === 0)
24174
24196
  return fundingSteps;
24175
- const requiredToken = getRequiredToken(balanceRequirement);
24176
- if (requiredToken.address === '')
24197
+ if (!isBalanceRequirementTokenValid(balanceRequirement))
24177
24198
  return fundingSteps;
24199
+ const requiredToken = getRequiredToken(balanceRequirement);
24178
24200
  const chainId = getL2ChainId(config);
24179
24201
  const l2TokenBalanceResult = tokenBalanceResults.get(chainId);
24180
24202
  if (!l2TokenBalanceResult)
@@ -24271,7 +24293,7 @@ const allowListCheck = async (config, tokenBalances, availableRoutingOptions) =>
24271
24293
 
24272
24294
  const getEthBalance = (balances) => {
24273
24295
  for (const balance of balances.balances) {
24274
- if (!balance.token.address || balance.token.address === '') {
24296
+ if (isNativeToken(balance.token.address)) {
24275
24297
  return balance.balance;
24276
24298
  }
24277
24299
  }
@@ -24327,25 +24349,28 @@ const getImxL1Representation = async (chainId, config) => {
24327
24349
  return imxMappingConfig[chainId] ?? '';
24328
24350
  };
24329
24351
  const fetchL1Representation = async (config, l2address) => {
24330
- if (l2address === '')
24331
- return { l1address: '', l2address };
24332
- if (l2address === IMX_ADDRESS_ZKEVM) {
24352
+ if (isNativeToken(l2address)) {
24333
24353
  return {
24334
24354
  l1address: await getImxL1Representation(getL1ChainId(config), config),
24335
- l2address: IMX_ADDRESS_ZKEVM,
24355
+ l2address: NATIVE,
24336
24356
  };
24337
24357
  }
24338
24358
  const chainName = getIndexerChainName(getL2ChainId(config));
24339
- if (chainName === '')
24340
- return { l1address: '', l2address }; // Chain name not a valid indexer chain name
24341
24359
  const blockchainData = createBlockchainDataInstance(config);
24342
24360
  const tokenData = await blockchainData.getToken({
24343
24361
  chainName,
24344
24362
  contractAddress: l2address,
24345
24363
  });
24364
+ // TODO: When bridge is ready we need to understand how L2 ETH will be mapped back to L1 ETH
24346
24365
  const l1address = tokenData.result.root_contract_address;
24366
+ if (l1address === INDEXER_ETH_ROOT_CONTRACT_ADDRESS) {
24367
+ return {
24368
+ l1address: 'native',
24369
+ l2address,
24370
+ };
24371
+ }
24347
24372
  if (l1address === null)
24348
- return { l1address: '', l2address }; // No L1 representation of this token
24373
+ return undefined; // No L1 representation of this token
24349
24374
  return {
24350
24375
  l1address,
24351
24376
  l2address,
@@ -24432,16 +24457,9 @@ const constructBridgeFundingRoute = (chainId, balance, bridgeRequirement, itemTy
24432
24457
  },
24433
24458
  fees,
24434
24459
  });
24435
- const isNativeEth = (address) => {
24436
- if (!address || address === '')
24437
- return true;
24438
- return false;
24439
- };
24440
24460
  const bridgeRoute = async (config, readOnlyProviders, depositorAddress, availableRoutingOptions, bridgeRequirement, tokenBalanceResults, feeEstimates) => {
24441
24461
  if (!availableRoutingOptions.bridge)
24442
24462
  return undefined;
24443
- if (bridgeRequirement.l2address === undefined || bridgeRequirement.l2address === '')
24444
- return undefined;
24445
24463
  const chainId = getL1ChainId(config);
24446
24464
  const tokenBalanceResult = tokenBalanceResults.get(chainId);
24447
24465
  const l1provider = readOnlyProviders.get(chainId);
@@ -24459,12 +24477,11 @@ const bridgeRoute = async (config, readOnlyProviders, depositorAddress, availabl
24459
24477
  if (!hasSufficientL1Eth(tokenBalanceResult, bridgeFeeEstimate.totalFees))
24460
24478
  return undefined;
24461
24479
  const l1RepresentationResult = await fetchL1Representation(config, bridgeRequirement.l2address);
24462
- // No mapping on L1 for this token
24463
- const { l1address } = l1RepresentationResult;
24464
- if (l1address === '')
24480
+ if (!l1RepresentationResult)
24465
24481
  return undefined;
24466
24482
  // Ensure l1address is in the allowed token list
24467
- if (l1address === INDEXER_ETH_ROOT_CONTRACT_ADDRESS) {
24483
+ const { l1address } = l1RepresentationResult;
24484
+ if (isNativeToken(l1address)) {
24468
24485
  if (!allowedTokenList.find((token) => !('address' in token)))
24469
24486
  return undefined;
24470
24487
  }
@@ -24474,9 +24491,9 @@ const bridgeRoute = async (config, readOnlyProviders, depositorAddress, availabl
24474
24491
  const gasForApproval = await estimateGasForBridgeApproval(config, readOnlyProviders, l1provider, depositorAddress, l1address, bridgeRequirement.amount);
24475
24492
  let totalFees = bridgeFeeEstimate.bridgeFee.estimatedAmount;
24476
24493
  // If the L1 representation of the requirement is ETH then find the ETH balance and check if the balance covers the delta
24477
- if (l1address === INDEXER_ETH_ROOT_CONTRACT_ADDRESS) {
24494
+ if (isNativeToken(l1address)) {
24478
24495
  const nativeETHBalance = tokenBalanceResult.balances
24479
- .find((balance) => isNativeEth(balance.token.address));
24496
+ .find((balance) => isNativeToken(balance.token.address));
24480
24497
  if (bridgeFeeEstimate.gasFee.estimatedAmount) {
24481
24498
  totalFees = totalFees.add(bridgeFeeEstimate.gasFee.estimatedAmount);
24482
24499
  }
@@ -24632,8 +24649,10 @@ const constructBridgeRequirements = (dexQuotes, l1balances, l2balances, l1tol2ad
24632
24649
  };
24633
24650
 
24634
24651
  const fetchL1ToL2Mappings = async (config, swappableTokens) => {
24635
- const l1tol2addressMappingPromises = swappableTokens.map((token) => fetchL1Representation(config, token.address ?? ''));
24636
- return await Promise.all(l1tol2addressMappingPromises);
24652
+ const l1tol2addressMappingPromises = swappableTokens
24653
+ .map((token) => fetchL1Representation(config, token.address ?? ''));
24654
+ const mappings = await Promise.all(l1tol2addressMappingPromises);
24655
+ return mappings.filter((mapping) => mapping !== undefined);
24637
24656
  };
24638
24657
 
24639
24658
  // Fetch all the dex quotes from the list of swappable tokens
@@ -24673,10 +24692,7 @@ const abortBridgeAndSwap = (bridgeableTokens, swappableTokens, l1balances, l2bal
24673
24692
  const filterSwappableTokensByBridgeableAddresses = (requiredTokenAddress, bridgeableTokens, swappableTokens, l1tol2Addresses) => {
24674
24693
  const filteredSwappableTokens = [];
24675
24694
  for (const addresses of l1tol2Addresses) {
24676
- if (addresses.l1address === '')
24677
- continue;
24678
- if (addresses.l2address === '')
24679
- continue;
24695
+ // TODO: Check for ETH (native) L1 in bridgeableTokens first
24680
24696
  if (!bridgeableTokens.includes(addresses.l1address))
24681
24697
  continue;
24682
24698
  // Filter out the token that is required from the swappable tokens list
@@ -24865,7 +24881,7 @@ const onRampRoute = async (config, availableRoutingOptions, balanceRequirement)
24865
24881
  type: FundingStepType.ONRAMP,
24866
24882
  chainId: getL2ChainId(config),
24867
24883
  fundingItem: {
24868
- type: required.token.address === IMX_ADDRESS_ZKEVM ? ItemType.NATIVE : ItemType.ERC20,
24884
+ type: isNativeToken(required.token.address) ? ItemType.NATIVE : ItemType.ERC20,
24869
24885
  fundsRequired: {
24870
24886
  amount: delta.balance,
24871
24887
  formattedAmount: delta.formattedBalance,
@@ -25101,8 +25117,8 @@ var SignTransactionStatusType;
25101
25117
  const signApprovalTransactions = async (provider, approvalTransactions) => {
25102
25118
  let receipts = [];
25103
25119
  try {
25104
- const response = await Promise.all(approvalTransactions.map((transaction) => provider.getSigner().sendTransaction(transaction)));
25105
- receipts = await Promise.all(response.map((transaction) => transaction.wait()));
25120
+ const response = await Promise.all(approvalTransactions.map((transaction) => sendTransaction(provider, transaction)));
25121
+ receipts = await Promise.all(response.map((transaction) => transaction.transactionResponse.wait()));
25106
25122
  }
25107
25123
  catch (err) {
25108
25124
  throw new CheckoutError('An error occurred while executing the approval transaction', CheckoutErrorType.EXECUTE_APPROVAL_TRANSACTION_ERROR, {
@@ -25125,8 +25141,8 @@ const signApprovalTransactions = async (provider, approvalTransactions) => {
25125
25141
  const signFulfillmentTransactions = async (provider, fulfillmentTransactions) => {
25126
25142
  let receipts = [];
25127
25143
  try {
25128
- const response = await Promise.all(fulfillmentTransactions.map((transaction) => provider.getSigner().sendTransaction(transaction)));
25129
- receipts = await Promise.all(response.map((transaction) => transaction.wait()));
25144
+ const response = await Promise.all(fulfillmentTransactions.map((transaction) => sendTransaction(provider, transaction)));
25145
+ receipts = await Promise.all(response.map((transaction) => transaction.transactionResponse.wait()));
25130
25146
  }
25131
25147
  catch (err) {
25132
25148
  throw new CheckoutError('An error occurred while executing the fulfillment transaction', CheckoutErrorType.EXECUTE_FULFILLMENT_TRANSACTION_ERROR, {
@@ -25702,10 +25718,6 @@ async function getItemRequirementsFromRequirements(provider, requirements) {
25702
25718
  return itemRequirements;
25703
25719
  }
25704
25720
 
25705
- const SDK_VERSION_MARKER = '0.31.3';
25706
- // This SDK version is replaced by the `yarn build` command ran on the root level
25707
- const globalPackageVersion = () => SDK_VERSION_MARKER;
25708
-
25709
25721
  /**
25710
25722
  * Validates and builds a version string based on the given SemanticVersion object.
25711
25723
  * If the version is undefined or has an invalid major version, it returns the default checkout version.