@imtbl/sdk 0.1.10-alpha.4 → 0.2.1-alpha

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.
@@ -10387,9 +10387,8 @@ class ExchangeError extends Error {
10387
10387
  }
10388
10388
  }
10389
10389
  class InvalidConfigurationError extends ExchangeError {
10390
- constructor() {
10391
- const message = 'Invalid configuration';
10392
- super(message, ExchangeErrorCode.INVALID_CONFIGURATION);
10390
+ constructor(message) {
10391
+ super(message || 'Invalid configuration', ExchangeErrorCode.INVALID_CONFIGURATION);
10393
10392
  }
10394
10393
  }
10395
10394
  class ChainNotSupportedError extends ExchangeError {
@@ -12490,20 +12489,84 @@ function getSwap(nativeToken, routeAndQuote, fromAddress, slippage, deadline, pe
12490
12489
  };
12491
12490
  }
12492
12491
 
12492
+ const CONTRACTS_FOR_CHAIN_ID = {
12493
+ [IMMUTABLE_TESTNET_CHAIN_ID]: {
12494
+ multicall: '0xb18c44b211065E69844FbA9AE146DA362104AfBf',
12495
+ coreFactory: '0x12739A8f1A8035F439092D016DAE19A2874F30d2',
12496
+ quoterV2: '0xF674847fBcca5C80315e3AE37043Dce99F6CC529',
12497
+ peripheryRouter: '0x0Afe6F5f4DC34461A801420634239FFaD50A2e44',
12498
+ },
12499
+ };
12500
+ const SUPPORTED_SANDBOX_CHAINS = {
12501
+ [IMMUTABLE_TESTNET_CHAIN_ID]: {
12502
+ chainId: IMMUTABLE_TESTNET_CHAIN_ID,
12503
+ rpcUrl: IMMUTABLE_TESTNET_RPC_URL,
12504
+ contracts: CONTRACTS_FOR_CHAIN_ID[IMMUTABLE_TESTNET_CHAIN_ID],
12505
+ commonRoutingTokens: IMMUTABLE_TESTNET_COMMON_ROUTING_TOKENS,
12506
+ nativeToken: TIMX_IMMUTABLE_TESTNET,
12507
+ },
12508
+ };
12509
+ const SUPPORTED_PRODUCTION_CHAINS = {};
12510
+ const SUPPORTED_CHAIN_IDS_FOR_ENVIRONMENT = {
12511
+ [Environment$1.SANDBOX]: SUPPORTED_SANDBOX_CHAINS,
12512
+ [Environment$1.PRODUCTION]: SUPPORTED_PRODUCTION_CHAINS,
12513
+ };
12514
+ function validateOverrides(overrides) {
12515
+ Object.entries(overrides).forEach(([key, value]) => {
12516
+ if (!value) {
12517
+ throw new InvalidConfigurationError(`Missing override: ${key}`);
12518
+ }
12519
+ });
12520
+ Object.entries(overrides.exchangeContracts).forEach(([key, contract]) => {
12521
+ if (!isValidNonZeroAddress(contract)) {
12522
+ throw new InvalidConfigurationError(`Invalid exchange contract address for ${key}`);
12523
+ }
12524
+ });
12525
+ }
12526
+ /**
12527
+ * {@link ExchangeConfiguration} is used to configure the {@link Exchange} class.
12528
+ * @param chainId the ID of the chain to configure. {@link SUPPORTED_CHAIN_IDS_FOR_ENVIRONMENT} contains the supported chains for each environment.
12529
+ * @param baseConfig the base {@link ImmutableConfiguration} for the {@link Exchange} class
12530
+ */
12531
+ class ExchangeConfiguration {
12532
+ baseConfig;
12533
+ chain;
12534
+ constructor({ chainId, baseConfig, overrides }) {
12535
+ this.baseConfig = baseConfig;
12536
+ if (overrides) {
12537
+ validateOverrides(overrides);
12538
+ this.chain = {
12539
+ chainId,
12540
+ rpcUrl: overrides.rpcURL,
12541
+ contracts: overrides.exchangeContracts,
12542
+ commonRoutingTokens: overrides.commonRoutingTokens,
12543
+ nativeToken: overrides.nativeToken,
12544
+ };
12545
+ return;
12546
+ }
12547
+ const chain = SUPPORTED_CHAIN_IDS_FOR_ENVIRONMENT[baseConfig.environment][chainId];
12548
+ if (!chain) {
12549
+ throw new ChainNotSupportedError(chainId, baseConfig.environment);
12550
+ }
12551
+ this.chain = chain;
12552
+ }
12553
+ }
12554
+
12493
12555
  class Exchange {
12494
12556
  provider;
12495
12557
  router;
12496
12558
  chainId;
12497
12559
  nativeToken;
12498
12560
  constructor(configuration) {
12499
- this.chainId = configuration.chain.chainId;
12500
- this.nativeToken = configuration.chain.nativeToken;
12501
- this.provider = new ethers.providers.JsonRpcProvider(configuration.chain.rpcUrl);
12502
- this.router = new Router(this.provider, configuration.chain.commonRoutingTokens, {
12503
- multicallAddress: configuration.chain.contracts.multicall,
12504
- factoryAddress: configuration.chain.contracts.coreFactory,
12505
- quoterAddress: configuration.chain.contracts.quoterV2,
12506
- peripheryRouterAddress: configuration.chain.contracts.peripheryRouter,
12561
+ const config = new ExchangeConfiguration(configuration);
12562
+ this.chainId = config.chain.chainId;
12563
+ this.nativeToken = config.chain.nativeToken;
12564
+ this.provider = new ethers.providers.JsonRpcProvider(config.chain.rpcUrl);
12565
+ this.router = new Router(this.provider, config.chain.commonRoutingTokens, {
12566
+ multicallAddress: config.chain.contracts.multicall,
12567
+ factoryAddress: config.chain.contracts.coreFactory,
12568
+ quoterAddress: config.chain.contracts.quoterV2,
12569
+ peripheryRouterAddress: config.chain.contracts.peripheryRouter,
12507
12570
  });
12508
12571
  }
12509
12572
  static validate(tokenInAddress, tokenOutAddress, maxHops, slippagePercent, fromAddress) {
@@ -12583,67 +12646,6 @@ class Exchange {
12583
12646
  }
12584
12647
  }
12585
12648
 
12586
- const CONTRACTS_FOR_CHAIN_ID = {
12587
- [IMMUTABLE_TESTNET_CHAIN_ID]: {
12588
- multicall: '0xb18c44b211065E69844FbA9AE146DA362104AfBf',
12589
- coreFactory: '0x12739A8f1A8035F439092D016DAE19A2874F30d2',
12590
- quoterV2: '0xF674847fBcca5C80315e3AE37043Dce99F6CC529',
12591
- peripheryRouter: '0x0Afe6F5f4DC34461A801420634239FFaD50A2e44',
12592
- },
12593
- };
12594
- const SUPPORTED_SANDBOX_CHAINS = {
12595
- [IMMUTABLE_TESTNET_CHAIN_ID]: {
12596
- chainId: IMMUTABLE_TESTNET_CHAIN_ID,
12597
- rpcUrl: IMMUTABLE_TESTNET_RPC_URL,
12598
- contracts: CONTRACTS_FOR_CHAIN_ID[IMMUTABLE_TESTNET_CHAIN_ID],
12599
- commonRoutingTokens: IMMUTABLE_TESTNET_COMMON_ROUTING_TOKENS,
12600
- nativeToken: TIMX_IMMUTABLE_TESTNET,
12601
- },
12602
- };
12603
- const SUPPORTED_PRODUCTION_CHAINS = {};
12604
- const SUPPORTED_CHAIN_IDS_FOR_ENVIRONMENT = {
12605
- [Environment$1.SANDBOX]: SUPPORTED_SANDBOX_CHAINS,
12606
- [Environment$1.PRODUCTION]: SUPPORTED_PRODUCTION_CHAINS,
12607
- };
12608
- function validateOverrides(overrides) {
12609
- if (!overrides.rpcURL || !overrides.exchangeContracts || !overrides.commonRoutingTokens || !overrides.nativeToken) {
12610
- throw new InvalidConfigurationError();
12611
- }
12612
- Object.values(overrides.exchangeContracts).forEach((contract) => {
12613
- if (!isValidNonZeroAddress(contract)) {
12614
- throw new InvalidConfigurationError();
12615
- }
12616
- });
12617
- }
12618
- /**
12619
- * {@link ExchangeConfiguration} is used to configure the {@link Exchange} class.
12620
- * @param chainId the ID of the chain to configure. {@link SUPPORTED_CHAIN_IDS_FOR_ENVIRONMENT} contains the supported chains for each environment.
12621
- * @param baseConfig the base {@link ImmutableConfiguration} for the {@link Exchange} class
12622
- */
12623
- class ExchangeConfiguration {
12624
- baseConfig;
12625
- chain;
12626
- constructor({ chainId, baseConfig, overrides }) {
12627
- this.baseConfig = baseConfig;
12628
- if (overrides) {
12629
- validateOverrides(overrides);
12630
- this.chain = {
12631
- chainId,
12632
- rpcUrl: overrides.rpcURL,
12633
- contracts: overrides.exchangeContracts,
12634
- commonRoutingTokens: overrides.commonRoutingTokens,
12635
- nativeToken: overrides.nativeToken,
12636
- };
12637
- return;
12638
- }
12639
- const chain = SUPPORTED_CHAIN_IDS_FOR_ENVIRONMENT[baseConfig.environment][chainId];
12640
- if (!chain) {
12641
- throw new ChainNotSupportedError(chainId, baseConfig.environment);
12642
- }
12643
- this.chain = chain;
12644
- }
12645
- }
12646
-
12647
12649
  /* eslint-disable class-methods-use-this */
12648
12650
 
12649
12651
  const $762782b6c862d954$export$db5daa1b5156ccfe = [
@@ -13396,13 +13398,13 @@ async function $67fc622a2b913d5f$export$989eefe1274a439c(fromChainId, toChainId,
13396
13398
  }
13397
13399
  async function $67fc622a2b913d5f$export$7cf6178417769841(chainId, config) {
13398
13400
  const dexConfig = await config.remote.getConfig("dex");
13399
- return new (Exchange)(new (ExchangeConfiguration)({
13401
+ return new (Exchange)({
13400
13402
  chainId: chainId,
13401
13403
  baseConfig: new (ImmutableConfiguration)({
13402
13404
  environment: config.environment
13403
13405
  }),
13404
13406
  overrides: dexConfig?.overrides
13405
- }));
13407
+ });
13406
13408
  }
13407
13409
 
13408
13410
 
@@ -15288,8 +15288,8 @@ interface ImtblWalletProps extends React.DetailedHTMLProps<React.HTMLAttributes<
15288
15288
  * @property {string | undefined} walletProvider - The preferred wallet provider to connect to.
15289
15289
  * @property {string | undefined} widgetConfig - The configuration for the swap widget.
15290
15290
  * @property {string | undefined} amount - The amount to swap.
15291
- * @property {string | undefined} fromContractAddress - The contract address of the source token.
15292
- * @property {string | undefined} toContractAddress - The contract address of the destination token.
15291
+ * @property {string | undefined} fromContractAddress - The contract address of the source token. If the string is 'NATIVE' then the native token will be used.
15292
+ * @property {string | undefined} toContractAddress - The contract address of the destination token. If the string is 'NATIVE' then the native token will be used.
15293
15293
  */
15294
15294
  interface ImtblSwapProps extends React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement> {
15295
15295
  walletProvider?: string;
@@ -15344,9 +15344,9 @@ declare function ConnectReact(): JSX.Element;
15344
15344
  * @interface SwapReactProps
15345
15345
  * @property {WalletProviderName | undefined} walletProvider - The name of the wallet provider.
15346
15346
  * @property {Web3Provider | undefined} provider - The Web3 provider.
15347
- * @property {string | undefined} fromContractAddress - The address of the contract swapping from.
15347
+ * @property {string | undefined} fromContractAddress - The address of the contract swapping from. If the string is 'NATIVE' then the native token is used.
15348
15348
  * @property {string | undefined} amount - The amount.
15349
- * @property {string | undefined} toContractAddress - The address of the contract swapping to.
15349
+ * @property {string | undefined} toContractAddress - The address of the contract swapping to. If the string is 'NATIVE' then the native token is used.
15350
15350
  */
15351
15351
  interface SwapReactProps {
15352
15352
  walletProvider?: WalletProviderName;
@@ -4,7 +4,7 @@ import { useEffect } from 'react';
4
4
  function $parcel$export(e, n, v, s) {
5
5
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
6
6
  }
7
- const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.1.10-alpha.4";
7
+ const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.2.1-alpha";
8
8
  const $d663162fd5a0853f$export$83bf90b30cdfd29f = ()=>false;
9
9
  const $d663162fd5a0853f$export$1169f5475725171b = ()=>$d663162fd5a0853f$export$38a083d9fb5551ca;
10
10
 
@@ -16,7 +16,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
16
16
  chainID,
17
17
  coreContractAddress,
18
18
  registrationContractAddress,
19
- sdkVersion: 'ts-immutable-sdk-0.1.10-alpha.4',
19
+ sdkVersion: 'ts-immutable-sdk-0.2.1-alpha',
20
20
  });
21
21
  /**
22
22
  * Sets `sdkVersion` at the time of build