@cryptorubic/web3 1.0.0-alpha.no-sdk.33 → 1.0.0-alpha.no-sdk.34

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.33",
3
+ "version": "1.0.0-alpha.no-sdk.34",
4
4
  "dependencies": {
5
5
  "@ethersproject/bignumber": "^5.8.0",
6
6
  "@mysten/sui": "^1.24.0",
@@ -33,7 +33,7 @@ class EvmAdapter extends abstract_adapter_1.AbstractAdapter {
33
33
  super(adapterOptions.blockchain, logger);
34
34
  this.adapterOptions = adapterOptions;
35
35
  this.clientParams = clientParams;
36
- this.signer = new evm_adapter_signer_1.EvmAdapterSigner(this.public, httpClient, logger, clientParams);
36
+ this.signer = new evm_adapter_signer_1.EvmAdapterSigner(this.publicRef, httpClient, logger, clientParams);
37
37
  }
38
38
  initWeb3Client() {
39
39
  this.public = this.createPublicClient(this.adapterOptions.rpcList);
@@ -5,8 +5,11 @@ import { Abi, PublicActions, PublicClient, TransactionReceipt, WalletActions, Wa
5
5
  import { EvmSendTxParams, EvmTransactionOptions } from '../models/evm-send-tx-params';
6
6
  import { Web3Error } from '../utils/parse-evm-error';
7
7
  export declare class EvmAdapterSigner extends AbstractAdapterSigner<WalletClient & WalletActions, EvmSendTxParams, TransactionReceipt> {
8
- private readonly evmPublic;
9
- constructor(evmPublic: PublicActions & PublicClient, httpClient: HttpClient, logger?: ICustomLogger, clientParams?: ClientAdaptersFactoryParams);
8
+ private readonly publicRef;
9
+ get publicClient(): PublicActions & PublicClient;
10
+ constructor(publicRef: {
11
+ public: (PublicActions & PublicClient) | null;
12
+ }, httpClient: HttpClient, logger?: ICustomLogger, clientParams?: ClientAdaptersFactoryParams);
10
13
  getBlockchainName(): Promise<BlockchainName | undefined>;
11
14
  /**
12
15
  * Sends Eth in transaction and resolve the promise when the transaction is included in the block.
@@ -11,9 +11,17 @@ const parse_evm_error_1 = require("../utils/parse-evm-error");
11
11
  const rubic_sdk_error_1 = require("../../../../errors/rubic-sdk.error");
12
12
  const tx_reverted_in_chain_error_1 = require("../../../../errors/common/tx-reverted-in-chain.error");
13
13
  class EvmAdapterSigner extends abstract_adapter_signer_1.AbstractAdapterSigner {
14
- constructor(evmPublic, httpClient, logger, clientParams) {
14
+ get publicClient() {
15
+ if (!this.publicRef.public) {
16
+ const msg = `Trying to access undefined publicClient in EvmAdapterSigner.`;
17
+ this.logger?.customLog(msg);
18
+ throw new Error(msg);
19
+ }
20
+ return this.publicRef.public;
21
+ }
22
+ constructor(publicRef, httpClient, logger, clientParams) {
15
23
  super(httpClient, logger, clientParams);
16
- this.evmPublic = evmPublic;
24
+ this.publicRef = publicRef;
17
25
  }
18
26
  async getBlockchainName() {
19
27
  const userChainId = await this.wallet.getChainId();
@@ -64,7 +72,7 @@ class EvmAdapterSigner extends abstract_adapter_signer_1.AbstractAdapterSigner {
64
72
  value,
65
73
  ...(params.txOptions.data && { data: params.txOptions.data })
66
74
  };
67
- const gas = await this.evmPublic.estimateGas(gaslessParams);
75
+ const gas = await this.publicClient.estimateGas(gaslessParams);
68
76
  const gasfulParams = {
69
77
  ...gaslessParams,
70
78
  ...(0, options_1.getGasOptions)(params.txOptions),
@@ -76,7 +84,7 @@ class EvmAdapterSigner extends abstract_adapter_signer_1.AbstractAdapterSigner {
76
84
  gas
77
85
  };
78
86
  try {
79
- await this.evmPublic.estimateGas(gasfulViemParams);
87
+ await this.publicClient.estimateGas(gasfulViemParams);
80
88
  }
81
89
  catch {
82
90
  throw new rubic_sdk_error_1.RubicSdkError('Low native value');
@@ -160,7 +168,7 @@ class EvmAdapterSigner extends abstract_adapter_signer_1.AbstractAdapterSigner {
160
168
  }),
161
169
  account: this.walletAddress
162
170
  };
163
- const gas = await this.evmPublic.estimateContractGas(gaslessParams);
171
+ const gas = await this.publicClient.estimateContractGas(gaslessParams);
164
172
  const gasfulParams = {
165
173
  ...gaslessParams,
166
174
  ...(0, options_1.getGasOptions)(options),
@@ -172,7 +180,7 @@ class EvmAdapterSigner extends abstract_adapter_signer_1.AbstractAdapterSigner {
172
180
  gas
173
181
  };
174
182
  try {
175
- await this.evmPublic.estimateContractGas(gasfulViemParams);
183
+ await this.publicClient.estimateContractGas(gasfulViemParams);
176
184
  }
177
185
  catch {
178
186
  throw new rubic_sdk_error_1.RubicSdkError('Low native value');
@@ -235,7 +243,7 @@ class EvmAdapterSigner extends abstract_adapter_signer_1.AbstractAdapterSigner {
235
243
  account: address,
236
244
  args: methodArgs,
237
245
  functionName: method,
238
- chain: this.evmPublic.chain,
246
+ chain: this.publicClient.chain,
239
247
  value: (0, viem_1.parseEther)(value)
240
248
  });
241
249
  return result;
@@ -246,7 +254,7 @@ class EvmAdapterSigner extends abstract_adapter_signer_1.AbstractAdapterSigner {
246
254
  to: to,
247
255
  value: (0, viem_1.parseEther)(value),
248
256
  data: data,
249
- chain: this.evmPublic.chain,
257
+ chain: this.publicClient.chain,
250
258
  ...(options.gas && { gas: BigInt(options.gas) }),
251
259
  ...(0, options_1.getViemGasOptions)(options)
252
260
  });
@@ -5,8 +5,11 @@ import { SolanaSendTxParams } from '../models/solana-send-tx-params';
5
5
  import { Connection } from '@solana/web3.js';
6
6
  import { AbstractAdapterSigner } from '../../common/signer/abstract-adapter-signer';
7
7
  export declare class SolanaAdapterSigner extends AbstractAdapterSigner<SolanaWeb3, SolanaSendTxParams, string> {
8
- private readonly connection;
9
- constructor(connection: Connection, httpClient: HttpClient, logger?: ICustomLogger, clientParams?: ClientAdaptersFactoryParams);
8
+ private readonly publicRef;
9
+ get publicClient(): Connection;
10
+ constructor(publicRef: {
11
+ public: Connection | null;
12
+ }, httpClient: HttpClient, logger?: ICustomLogger, clientParams?: ClientAdaptersFactoryParams);
10
13
  write<T>(): Promise<T>;
11
14
  getBlockchainName(): Promise<BlockchainName>;
12
15
  sendTransaction(params: SolanaSendTxParams): Promise<string>;
@@ -10,9 +10,17 @@ const errors_1 = require("../../utils/errors");
10
10
  const abstract_adapter_signer_1 = require("../../common/signer/abstract-adapter-signer");
11
11
  const tx_reverted_in_chain_error_1 = require("../../../../errors/common/tx-reverted-in-chain.error");
12
12
  class SolanaAdapterSigner extends abstract_adapter_signer_1.AbstractAdapterSigner {
13
- constructor(connection, httpClient, logger, clientParams) {
13
+ get publicClient() {
14
+ if (!this.publicRef.public) {
15
+ const msg = `Trying to access undefined publicClient in SolanaAdapterSigner.`;
16
+ this.logger?.customLog(msg);
17
+ throw new Error(msg);
18
+ }
19
+ return this.publicRef.public;
20
+ }
21
+ constructor(publicRef, httpClient, logger, clientParams) {
14
22
  super(httpClient, logger, clientParams);
15
- this.connection = connection;
23
+ this.publicRef = publicRef;
16
24
  }
17
25
  async write() {
18
26
  throw new Error('Method write is not supported');
@@ -36,7 +44,7 @@ class SolanaAdapterSigner extends abstract_adapter_signer_1.AbstractAdapterSigne
36
44
  }
37
45
  else {
38
46
  try {
39
- const simulation = await this.connection.simulateTransaction(signedTx, {
47
+ const simulation = await this.publicClient.simulateTransaction(signedTx, {
40
48
  sigVerify: true,
41
49
  replaceRecentBlockhash: false
42
50
  });
@@ -45,7 +53,7 @@ class SolanaAdapterSigner extends abstract_adapter_signer_1.AbstractAdapterSigne
45
53
  catch (err) {
46
54
  console.log(err);
47
55
  }
48
- signature = await this.connection.sendRawTransaction(signedTx.serialize(), {
56
+ signature = await this.publicClient.sendRawTransaction(signedTx.serialize(), {
49
57
  maxRetries: 3,
50
58
  skipPreflight: false
51
59
  });
@@ -67,7 +75,7 @@ class SolanaAdapterSigner extends abstract_adapter_signer_1.AbstractAdapterSigne
67
75
  let fetchedTx = null;
68
76
  while (!fetchedTx && Date.now() < deadline) {
69
77
  await (0, waitFor_1.waitFor)(5000);
70
- fetchedTx = await this.connection.getTransaction(signature, {
78
+ fetchedTx = await this.publicClient.getTransaction(signature, {
71
79
  commitment: 'confirmed',
72
80
  maxSupportedTransactionVersion: 1
73
81
  });
@@ -17,7 +17,7 @@ class SolanaAdapter extends abstract_adapter_1.AbstractAdapter {
17
17
  super(core_1.BLOCKCHAIN_NAME.SOLANA, logger);
18
18
  this.rpcList = rpcList;
19
19
  this.httpClient = httpClient;
20
- this.signer = new solana_adapter_signer_1.SolanaAdapterSigner(this.public, httpClient, logger, clientParams);
20
+ this.signer = new solana_adapter_signer_1.SolanaAdapterSigner(this.publicRef, httpClient, logger, clientParams);
21
21
  }
22
22
  initWeb3Client() {
23
23
  this.public = this.createConection(this.rpcList);
@@ -5,8 +5,11 @@ import { SuiSendTxParams } from '../models/sui-send-tx-params';
5
5
  import { WalletAdapter } from '@suiet/wallet-sdk';
6
6
  import { ExecuteTransactionBlockParams, SuiClient, SuiTransactionBlockResponse } from '@mysten/sui/dist/cjs/client';
7
7
  export declare class SuiAdapterSigner extends AbstractAdapterSigner<WalletAdapter, SuiSendTxParams, string> {
8
- private readonly suiClient;
9
- constructor(suiClient: SuiClient, httpClient: HttpClient, logger?: ICustomLogger, clientParams?: ClientAdaptersFactoryParams);
8
+ private readonly publicRef;
9
+ get publicClient(): SuiClient;
10
+ constructor(publicRef: {
11
+ public: SuiClient | null;
12
+ }, httpClient: HttpClient, logger?: ICustomLogger, clientParams?: ClientAdaptersFactoryParams);
10
13
  write<T>(): Promise<T>;
11
14
  getBlockchainName(): Promise<BlockchainName>;
12
15
  sendTransaction(params: SuiSendTxParams): Promise<string>;
@@ -6,9 +6,17 @@ const abstract_adapter_signer_1 = require("../../common/signer/abstract-adapter-
6
6
  const user_reject_error_1 = require("../../../../errors/blockchain/user-reject.error");
7
7
  const parse_evm_error_1 = require("../../adapter-evm/utils/parse-evm-error");
8
8
  class SuiAdapterSigner extends abstract_adapter_signer_1.AbstractAdapterSigner {
9
- constructor(suiClient, httpClient, logger, clientParams) {
9
+ get publicClient() {
10
+ if (!this.publicRef.public) {
11
+ const msg = `Trying to access undefined publicClient in SuiAdapterSigner.`;
12
+ this.logger?.customLog(msg);
13
+ throw new Error(msg);
14
+ }
15
+ return this.publicRef.public;
16
+ }
17
+ constructor(publicRef, httpClient, logger, clientParams) {
10
18
  super(httpClient, logger, clientParams);
11
- this.suiClient = suiClient;
19
+ this.publicRef = publicRef;
12
20
  }
13
21
  async write() {
14
22
  throw new Error('Method write is not supported');
@@ -41,7 +49,7 @@ class SuiAdapterSigner extends abstract_adapter_signer_1.AbstractAdapterSigner {
41
49
  }
42
50
  }
43
51
  executeTxBlock(params) {
44
- return this.suiClient.executeTransactionBlock(params);
52
+ return this.publicClient.executeTransactionBlock(params);
45
53
  }
46
54
  }
47
55
  exports.SuiAdapterSigner = SuiAdapterSigner;
@@ -12,8 +12,7 @@ class SuiAdapter extends abstract_adapter_1.AbstractAdapter {
12
12
  constructor(rpcList, httpClient, logger, clientParams) {
13
13
  super(core_1.BLOCKCHAIN_NAME.SUI, logger);
14
14
  this.rpcList = rpcList;
15
- this.public = new client_1.SuiClient({ url: rpcList[0] });
16
- this.signer = new sui_adapter_signer_1.SuiAdapterSigner(this.public, httpClient, logger, clientParams);
15
+ this.signer = new sui_adapter_signer_1.SuiAdapterSigner(this.publicRef, httpClient, logger, clientParams);
17
16
  }
18
17
  initWeb3Client() {
19
18
  this.public = new client_1.SuiClient({ url: this.rpcList[0] });
@@ -10,8 +10,11 @@ import { TonClient } from '@ton/ton';
10
10
  import { TonTransactionConfig } from '../../../../utils/models/ton-transaction-config';
11
11
  export declare class TonAdapterSigner extends AbstractAdapterSigner<TonConnectUI, TonSendTxParams, string> {
12
12
  private readonly tonApi;
13
- private readonly tonClient;
14
- constructor(tonApi: TonApiService, tonClient: TonClient, httpClient: HttpClient, logger?: ICustomLogger, clientParams?: ClientAdaptersFactoryParams);
13
+ private readonly publicRef;
14
+ get publicClient(): TonClient;
15
+ constructor(tonApi: TonApiService, publicRef: {
16
+ public: TonClient | null;
17
+ }, httpClient: HttpClient, logger?: ICustomLogger, clientParams?: ClientAdaptersFactoryParams);
15
18
  write<T>(): Promise<T>;
16
19
  getBlockchainName(): Promise<BlockchainName>;
17
20
  sendTransaction(params: TonSendTxParams): Promise<string>;
@@ -9,10 +9,18 @@ const errors_1 = require("../../utils/errors");
9
9
  const core_2 = require("@ton/core");
10
10
  const waitFor_1 = require("../../utils/waitFor");
11
11
  class TonAdapterSigner extends abstract_adapter_signer_1.AbstractAdapterSigner {
12
- constructor(tonApi, tonClient, httpClient, logger, clientParams) {
12
+ get publicClient() {
13
+ if (!this.publicRef.public) {
14
+ const msg = `Trying to access undefined publicClient in TonAdapterSigner.`;
15
+ this.logger?.customLog(msg);
16
+ throw new Error(msg);
17
+ }
18
+ return this.publicRef.public;
19
+ }
20
+ constructor(tonApi, publicRef, httpClient, logger, clientParams) {
13
21
  super(httpClient, logger, clientParams);
14
22
  this.tonApi = tonApi;
15
- this.tonClient = tonClient;
23
+ this.publicRef = publicRef;
16
24
  }
17
25
  async write() {
18
26
  throw new Error('Method write is not supported');
@@ -149,7 +157,7 @@ class TonAdapterSigner extends abstract_adapter_signer_1.AbstractAdapterSigner {
149
157
  return inMsgHashBase64Url;
150
158
  }
151
159
  async getJettonWalletAddress(address, contractAddress) {
152
- const addressResult = await this.tonClient.runMethod(contractAddress, 'get_wallet_address', [
160
+ const addressResult = await this.publicClient.runMethod(contractAddress, 'get_wallet_address', [
153
161
  { type: 'slice', cell: (0, core_2.beginCell)().storeAddress(address).endCell() }
154
162
  ]);
155
163
  return addressResult.stack.readAddress();
@@ -14,8 +14,7 @@ class TonAdapter extends abstract_adapter_1.AbstractAdapter {
14
14
  super(core_1.BLOCKCHAIN_NAME.TON, logger);
15
15
  this.config = config;
16
16
  this.tonApi = new ton_api_service_1.TonApiService(httpClient, config.tonApiConfig, logger);
17
- this.public = new ton_1.TonClient(config.tonClientConfig);
18
- this.signer = new ton_adapter_signer_1.TonAdapterSigner(this.tonApi, this.public, httpClient, logger, clientParams);
17
+ this.signer = new ton_adapter_signer_1.TonAdapterSigner(this.tonApi, this.publicRef, httpClient, logger, clientParams);
19
18
  }
20
19
  initWeb3Client() {
21
20
  this.public = new ton_1.TonClient(this.config.tonClientConfig);
@@ -5,8 +5,11 @@ import { ClientAdaptersFactoryParams } from '../../../models/create-factory-para
5
5
  import { TronSendTxParams } from '../models/tron-send-tx-params';
6
6
  import { TronParameters } from '../../../../utils/models/tron-parameters';
7
7
  export declare class TronAdapterSigner extends AbstractAdapterSigner<TronWeb, TronSendTxParams, string> {
8
- private readonly tronWeb;
9
- constructor(tronWeb: TronWeb, httpClient: HttpClient, logger?: ICustomLogger, clientParams?: ClientAdaptersFactoryParams);
8
+ private readonly publicRef;
9
+ get publicClient(): TronWeb;
10
+ constructor(publicRef: {
11
+ public: TronWeb | null;
12
+ }, httpClient: HttpClient, logger?: ICustomLogger, clientParams?: ClientAdaptersFactoryParams);
10
13
  write(contractAddress: string, methodSignature: string, parameters: TronParameters): Promise<string>;
11
14
  getBlockchainName(): Promise<BlockchainName>;
12
15
  sendTransaction(params: TronSendTxParams): Promise<string>;
@@ -5,9 +5,17 @@ const abstract_adapter_signer_1 = require("../../common/signer/abstract-adapter-
5
5
  const core_1 = require("@cryptorubic/core");
6
6
  const parse_tron_error_1 = require("../utils/parse-tron-error");
7
7
  class TronAdapterSigner extends abstract_adapter_signer_1.AbstractAdapterSigner {
8
- constructor(tronWeb, httpClient, logger, clientParams) {
8
+ get publicClient() {
9
+ if (!this.publicRef.public) {
10
+ const msg = `Trying to access undefined publicClient in TronAdapterSigner.`;
11
+ this.logger?.customLog(msg);
12
+ throw new Error(msg);
13
+ }
14
+ return this.publicRef.public;
15
+ }
16
+ constructor(publicRef, httpClient, logger, clientParams) {
9
17
  super(httpClient, logger, clientParams);
10
- this.tronWeb = tronWeb;
18
+ this.publicRef = publicRef;
11
19
  }
12
20
  async write(contractAddress, methodSignature, parameters) {
13
21
  const transaction = await this.wallet.transactionBuilder.triggerSmartContract(contractAddress, methodSignature, {}, parameters, this.walletAddress);
@@ -20,9 +28,9 @@ class TronAdapterSigner extends abstract_adapter_signer_1.AbstractAdapterSigner
20
28
  }
21
29
  async sendTransaction(params) {
22
30
  try {
23
- const transaction = await this.tronWeb.transactionBuilder.triggerSmartContract(params.contractAddress, params.methodSignature, params.txOptions, params.parameters, this.walletAddress);
24
- const signedTransaction = await this.tronWeb.trx.sign(transaction.transaction);
25
- const receipt = await this.tronWeb.trx.sendRawTransaction(signedTransaction);
31
+ const transaction = await this.publicClient.transactionBuilder.triggerSmartContract(params.contractAddress, params.methodSignature, params.txOptions, params.parameters, this.walletAddress);
32
+ const signedTransaction = await this.publicClient.trx.sign(transaction.transaction);
33
+ const receipt = await this.publicClient.trx.sendRawTransaction(signedTransaction);
26
34
  if (params.txOptions.onTransactionHash) {
27
35
  params.txOptions.onTransactionHash(receipt.transaction.txID);
28
36
  }
@@ -35,7 +43,7 @@ class TronAdapterSigner extends abstract_adapter_signer_1.AbstractAdapterSigner
35
43
  }
36
44
  async trySendTransaction(params) {
37
45
  try {
38
- await this.tronWeb.transactionBuilder.estimateEnergy(params.contractAddress, params.methodSignature, {}, params.parameters, this.walletAddress);
46
+ await this.publicClient.transactionBuilder.estimateEnergy(params.contractAddress, params.methodSignature, {}, params.parameters, this.walletAddress);
39
47
  }
40
48
  catch (err) {
41
49
  const errMessage = typeof err === 'object' ? err.message : err;
@@ -21,7 +21,7 @@ class TronAdapter extends abstract_adapter_1.AbstractAdapter {
21
21
  super(core_1.BLOCKCHAIN_NAME.TRON, logger);
22
22
  this.rpcList = rpcList;
23
23
  this.multicallAddress = 'T9ziQU4EBteJzjzMzhHELdhgWFqwzS5Vki';
24
- this.signer = new tron_adapter_signer_1.TronAdapterSigner(this.public, httpClient, logger, clientParams);
24
+ this.signer = new tron_adapter_signer_1.TronAdapterSigner(this.publicRef, httpClient, logger, clientParams);
25
25
  }
26
26
  initWeb3Client() {
27
27
  const rpc = typeof this.rpcList[0] === 'string' ? this.rpcList[0] : this.rpcList[0].fullHost;
@@ -10,9 +10,12 @@ export declare abstract class AbstractAdapter<P, W, B extends BlockchainName, Se
10
10
  abstract signer: AbstractAdapterSigner<W, SendTxParams, SendTxResponse>;
11
11
  protected readonly logger?: ICustomLogger;
12
12
  protected readonly blockchain: B;
13
- private _public;
13
+ private _publicRef;
14
14
  protected set public(value: P | null);
15
15
  get public(): P;
16
+ get publicRef(): {
17
+ public: P | null;
18
+ };
16
19
  get connected(): boolean;
17
20
  protected constructor(blockchain: B, logger?: ICustomLogger);
18
21
  /**
@@ -8,21 +8,24 @@ const tx_status_1 = require("../models/web3-public-models/tx-status");
8
8
  const waitFor_1 = require("../utils/waitFor");
9
9
  class AbstractAdapter {
10
10
  set public(value) {
11
- this._public = value;
11
+ this._publicRef.public = value;
12
12
  }
13
13
  get public() {
14
- if (!this._public) {
14
+ if (!this._publicRef.public) {
15
15
  const msg = `Trying to access undefined public client in ${this.blockchain} adapter.`;
16
16
  this.logger?.customLog(msg);
17
17
  throw new Error(msg);
18
18
  }
19
- return this._public;
19
+ return this._publicRef.public;
20
+ }
21
+ get publicRef() {
22
+ return this._publicRef;
20
23
  }
21
24
  get connected() {
22
- return !!this._public;
25
+ return !!this._publicRef.public;
23
26
  }
24
27
  constructor(blockchain, logger) {
25
- this._public = null;
28
+ this._publicRef = { public: null };
26
29
  this.blockchain = blockchain;
27
30
  if (logger) {
28
31
  this.logger = logger;