@cryptorubic/web3 1.0.0-alpha.no-sdk.29 → 1.0.0-alpha.no-sdk.31

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cryptorubic/web3",
3
- "version": "1.0.0-alpha.no-sdk.29",
3
+ "version": "1.0.0-alpha.no-sdk.31",
4
4
  "dependencies": {
5
5
  "@ethersproject/bignumber": "^5.8.0",
6
6
  "@mysten/sui": "^1.24.0",
@@ -15,6 +15,7 @@ export declare class BitcoinAdapter extends AbstractAdapter<BtcWallet, BtcWallet
15
15
  readonly signer: BitcoinAdapterSigner;
16
16
  get public(): BtcWallet;
17
17
  constructor(httpClient: HttpClient, logger?: ICustomLogger, clientParams?: ClientAdaptersFactoryParams);
18
+ initWeb3Client(): void;
18
19
  callContractMethod<T extends Web3PrimitiveType = string>(): Promise<T>;
19
20
  read<T>(args: unknown): Promise<T>;
20
21
  getTransactionStatus(txHash: string): Promise<TxStatus>;
@@ -15,6 +15,9 @@ class BitcoinAdapter extends abstract_adapter_1.AbstractAdapter {
15
15
  this.httpClient = httpClient;
16
16
  this.signer = new bitcoin_adapter_signer_1.BitcoinAdapterSigner(httpClient, logger, clientParams);
17
17
  }
18
+ initWeb3Client() {
19
+ super.public = null;
20
+ }
18
21
  callContractMethod() {
19
22
  throw new Error('Method not implemented.');
20
23
  }
@@ -15,10 +15,12 @@ import { ApprovableAdapter } from '../models/approve-adapter';
15
15
  import { AllowanceInfo } from '../models/common-types';
16
16
  import { TxStatus } from '../models/web3-public-models/tx-status';
17
17
  export declare class EvmAdapter extends AbstractAdapter<PublicActions & PublicClient, WalletClient & WalletActions, EvmBlockchainName> implements ApprovableAdapter<EvmTransactionConfig> {
18
+ private readonly adapterOptions;
18
19
  readonly signer: EvmAdapterSigner;
19
20
  needPreswapAction(token: TokenAmount, contractAddress: string, walletAddress: string, amount: string): Promise<boolean>;
20
21
  handlePreswap(contractAddress: string, walletAddress: string, tokenAmount: TokenAmount): Promise<void>;
21
22
  constructor(httpClient: HttpClient, adapterOptions: EvmAdapterOptions, logger?: ICustomLogger, clientParams?: ClientAdaptersFactoryParams);
23
+ initWeb3Client(): void;
22
24
  callContractMethod<T extends Web3PrimitiveType = string>(contractAddress: string, contractAbi: Abi, methodName: string, methodArguments?: unknown[], options?: {
23
25
  from?: string;
24
26
  value?: string;
@@ -31,9 +31,12 @@ class EvmAdapter extends abstract_adapter_1.AbstractAdapter {
31
31
  }
32
32
  constructor(httpClient, adapterOptions, logger, clientParams) {
33
33
  super(adapterOptions.blockchain, logger);
34
- this.public = this.createPublicClient(adapterOptions.rpcList);
34
+ this.adapterOptions = adapterOptions;
35
35
  this.signer = new evm_adapter_signer_1.EvmAdapterSigner(this.public, httpClient, logger, clientParams);
36
36
  }
37
+ initWeb3Client() {
38
+ this.public = this.createPublicClient(this.adapterOptions.rpcList);
39
+ }
37
40
  async callContractMethod(contractAddress, contractAbi, methodName, methodArguments = [], options = {}) {
38
41
  return this.public.readContract({
39
42
  abi: contractAbi,
@@ -10,9 +10,11 @@ import { Web3PrimitiveType } from '../../../utils/models/primitive-types';
10
10
  import { ContractMulticallResponse } from '../models/web3-public-models/contract-multicall-response';
11
11
  import { TxStatus } from '../models/web3-public-models/tx-status';
12
12
  export declare class SolanaAdapter extends AbstractAdapter<Connection, SolanaWeb3, SolanaBlockchainName> {
13
+ private readonly rpcList;
13
14
  private readonly httpClient;
14
15
  readonly signer: SolanaAdapterSigner;
15
16
  constructor(rpcList: string[], httpClient: HttpClient, logger?: ICustomLogger, clientParams?: ClientAdaptersFactoryParams);
17
+ initWeb3Client(): void;
16
18
  callContractMethod<T extends Web3PrimitiveType = string>(): Promise<T>;
17
19
  read<T>(): Promise<T>;
18
20
  getTransactionStatus(txHash: string): Promise<TxStatus>;
@@ -15,10 +15,13 @@ const tx_status_1 = require("../models/web3-public-models/tx-status");
15
15
  class SolanaAdapter extends abstract_adapter_1.AbstractAdapter {
16
16
  constructor(rpcList, httpClient, logger, clientParams) {
17
17
  super(core_1.BLOCKCHAIN_NAME.SOLANA, logger);
18
+ this.rpcList = rpcList;
18
19
  this.httpClient = httpClient;
19
- this.public = this.createConection(rpcList);
20
20
  this.signer = new solana_adapter_signer_1.SolanaAdapterSigner(this.public, httpClient, logger, clientParams);
21
21
  }
22
+ initWeb3Client() {
23
+ this.public = this.createConection(this.rpcList);
24
+ }
22
25
  async callContractMethod() {
23
26
  throw new Error('Method call is not supported');
24
27
  }
@@ -10,8 +10,10 @@ import { Web3PrimitiveType } from '../../../utils/models/primitive-types';
10
10
  import { ContractMulticallResponse } from '../models/web3-public-models/contract-multicall-response';
11
11
  import { TxStatus } from '../models/web3-public-models/tx-status';
12
12
  export declare class SuiAdapter extends AbstractAdapter<SuiClient, WalletAdapter, SuiBlockchainName> {
13
+ private readonly rpcList;
13
14
  readonly signer: SuiAdapterSigner;
14
15
  constructor(rpcList: string[], httpClient: HttpClient, logger?: ICustomLogger, clientParams?: ClientAdaptersFactoryParams);
16
+ initWeb3Client(): void;
15
17
  callContractMethod<T extends Web3PrimitiveType = string>(): Promise<T>;
16
18
  read<T>(): Promise<T>;
17
19
  getTransactionStatus(srcTxHash: string): Promise<TxStatus>;
@@ -11,9 +11,13 @@ const tx_status_1 = require("../models/web3-public-models/tx-status");
11
11
  class SuiAdapter extends abstract_adapter_1.AbstractAdapter {
12
12
  constructor(rpcList, httpClient, logger, clientParams) {
13
13
  super(core_1.BLOCKCHAIN_NAME.SUI, logger);
14
+ this.rpcList = rpcList;
14
15
  this.public = new client_1.SuiClient({ url: rpcList[0] });
15
16
  this.signer = new sui_adapter_signer_1.SuiAdapterSigner(this.public, httpClient, logger, clientParams);
16
17
  }
18
+ initWeb3Client() {
19
+ this.public = new client_1.SuiClient({ url: this.rpcList[0] });
20
+ }
17
21
  async callContractMethod() {
18
22
  throw new Error('Method call is not supported');
19
23
  }
@@ -11,9 +11,11 @@ import { Web3PrimitiveType } from '../../../utils/models/primitive-types';
11
11
  import { ContractMulticallResponse } from '../models/web3-public-models/contract-multicall-response';
12
12
  import { TxStatus } from '../models/web3-public-models/tx-status';
13
13
  export declare class TonAdapter extends AbstractAdapter<TonClient, TonConnectUI, TonBlockchainName> {
14
+ private readonly config;
14
15
  readonly signer: TonAdapterSigner;
15
16
  private readonly tonApi;
16
17
  constructor(httpClient: HttpClient, config: TonAdapterConfig, logger?: ICustomLogger, clientParams?: ClientAdaptersFactoryParams);
18
+ initWeb3Client(): void;
17
19
  read<T>(): Promise<T>;
18
20
  callContractMethod<T extends Web3PrimitiveType = string>(): Promise<T>;
19
21
  getTransactionStatus(srcTxHash: string): Promise<TxStatus>;
@@ -12,10 +12,14 @@ const tx_status_1 = require("../models/web3-public-models/tx-status");
12
12
  class TonAdapter extends abstract_adapter_1.AbstractAdapter {
13
13
  constructor(httpClient, config, logger, clientParams) {
14
14
  super(core_1.BLOCKCHAIN_NAME.TON, logger);
15
+ this.config = config;
15
16
  this.tonApi = new ton_api_service_1.TonApiService(httpClient, config.tonApiConfig, logger);
16
17
  this.public = new ton_1.TonClient(config.tonClientConfig);
17
18
  this.signer = new ton_adapter_signer_1.TonAdapterSigner(this.tonApi, this.public, httpClient, logger, clientParams);
18
19
  }
20
+ initWeb3Client() {
21
+ this.public = new ton_1.TonClient(this.config.tonClientConfig);
22
+ }
19
23
  async read() {
20
24
  throw new Error('Method read is not supported');
21
25
  }
@@ -15,12 +15,14 @@ import { AllowanceInfo } from '../models/common-types';
15
15
  import { ApprovableAdapter } from '../models/approve-adapter';
16
16
  import { TxStatus } from '../models/web3-public-models/tx-status';
17
17
  export declare class TronAdapter extends AbstractAdapter<TronWeb, TronWeb, TronBlockchainName> implements ApprovableAdapter<TronTransactionConfig> {
18
+ private readonly rpcList;
18
19
  readonly signer: TronAdapterSigner;
19
20
  private readonly multicallAddress;
20
21
  needPreswapAction(): Promise<boolean>;
21
22
  constructor(rpcList: (string | {
22
23
  fullHost: string;
23
24
  })[], httpClient: HttpClient, logger?: ICustomLogger, clientParams?: ClientAdaptersFactoryParams);
25
+ initWeb3Client(): void;
24
26
  callContractMethod<T extends Web3PrimitiveType = string>(contractAddress: string, contractAbi: Abi, methodName: string, methodArguments?: unknown[]): Promise<T>;
25
27
  getTransactionStatus(srcTxHash: string): Promise<TxStatus>;
26
28
  /**
@@ -19,11 +19,14 @@ class TronAdapter extends abstract_adapter_1.AbstractAdapter {
19
19
  }
20
20
  constructor(rpcList, httpClient, logger, clientParams) {
21
21
  super(core_1.BLOCKCHAIN_NAME.TRON, logger);
22
+ this.rpcList = rpcList;
22
23
  this.multicallAddress = 'T9ziQU4EBteJzjzMzhHELdhgWFqwzS5Vki';
23
- const rpc = typeof rpcList[0] === 'string' ? rpcList[0] : rpcList[0].fullHost;
24
- this.public = new tronweb_1.TronWeb({ fullHost: rpc });
25
24
  this.signer = new tron_adapter_signer_1.TronAdapterSigner(this.public, httpClient, logger, clientParams);
26
25
  }
26
+ initWeb3Client() {
27
+ const rpc = typeof this.rpcList[0] === 'string' ? this.rpcList[0] : this.rpcList[0].fullHost;
28
+ this.public = new tronweb_1.TronWeb({ fullHost: rpc });
29
+ }
27
30
  async callContractMethod(contractAddress, contractAbi, methodName, methodArguments = []) {
28
31
  this.public.setAddress(contractAddress);
29
32
  const contract = await this.public.contract(contractAbi, contractAddress);
@@ -14,6 +14,12 @@ export declare abstract class AbstractAdapter<P, W, B extends BlockchainName, Se
14
14
  protected set public(value: P | null);
15
15
  get public(): P;
16
16
  protected constructor(blockchain: B, logger?: ICustomLogger);
17
+ /**
18
+ * Used to set this.public property, if it's not set - you can't send rpc requests to blockchain.
19
+ * Mostly you need to instantiate it at the same time as BlockchainAdapterFactoryService.createAdapter() called.
20
+ * In rubic-app it's called on wallet connection to prevent unnecessary rpc requests `net_listening` from viem library.
21
+ */
22
+ abstract initWeb3Client(): void;
17
23
  /**
18
24
  * Gets account native or token balance in wei.
19
25
  * @param userAddress Wallet address, whose balance you want to find out.
@@ -5,9 +5,9 @@ const rubic_api_link_mapping_1 = require("../../../constants/rubic-api-link-mapp
5
5
  const wrong_network_error_1 = require("../../../../errors/swap/wrong-network.error");
6
6
  class AbstractAdapterSigner {
7
7
  get apiUrl() {
8
- if (!this.clientParams) {
9
- this.logger?.customError('clientParams is not set for apiUrl call.');
10
- throw new Error('clientParams is not set for apiUrl call.');
8
+ if (!this.clientParams?.envType) {
9
+ this.logger?.customError('clientParams.envType is not set for apiUrl call.');
10
+ throw new Error('clientParams.envType is not set for apiUrl call.');
11
11
  }
12
12
  const rubicApiLink = rubic_api_link_mapping_1.rubicApiLinkMapping[this.clientParams.envType];
13
13
  return rubicApiLink ? rubicApiLink : 'https://dev1-api-v2.rubic.exchange';
@@ -55,6 +55,9 @@ class BlockchainAdapterFactoryService {
55
55
  });
56
56
  const store = Object.fromEntries(activeAdapters);
57
57
  this.logger?.customLog('Adapters store created');
58
+ if (!this.clientParams?.lazyLoadWeb3) {
59
+ Object.values(store).forEach((adapter) => adapter.initWeb3Client());
60
+ }
58
61
  return store;
59
62
  }
60
63
  createAdapter(blockchain, rpcs) {
@@ -73,7 +73,6 @@ exports.viemBlockchainMapping = {
73
73
  [core_1.BLOCKCHAIN_NAME.CORE]: chain_configs_1.viemConfig[core_1.BLOCKCHAIN_NAME.CORE],
74
74
  [core_1.BLOCKCHAIN_NAME.BERACHAIN]: chain_configs_1.viemConfig[core_1.BLOCKCHAIN_NAME.BERACHAIN],
75
75
  [core_1.BLOCKCHAIN_NAME.SONEIUM]: chain_configs_1.viemConfig[core_1.BLOCKCHAIN_NAME.SONEIUM],
76
- [core_1.BLOCKCHAIN_NAME.WANCHAIN]: chains_1.wanchain,
77
76
  [core_1.BLOCKCHAIN_NAME.UNICHAIN]: chain_configs_1.viemConfig[core_1.BLOCKCHAIN_NAME.UNICHAIN],
78
77
  [core_1.BLOCKCHAIN_NAME.MORPH]: chain_configs_1.viemConfig[core_1.BLOCKCHAIN_NAME.MORPH], // viem Morph config without multicall address
79
78
  [core_1.BLOCKCHAIN_NAME.HEMI]: chain_configs_1.viemConfig[core_1.BLOCKCHAIN_NAME.HEMI],
@@ -12,4 +12,5 @@ export interface AdapterFactoryParams {
12
12
  }
13
13
  export interface ClientAdaptersFactoryParams {
14
14
  envType: EnvType;
15
+ lazyLoadWeb3?: boolean;
15
16
  }