@cryptorubic/web3 0.5.1-alpha.ton-debug.1 → 0.5.1-fix-polygon.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.
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@cryptorubic/web3",
3
- "version": "0.5.1-alpha.ton-debug.1",
3
+ "version": "0.5.1-fix-polygon.0",
4
4
  "dependencies": {
5
5
  "tslib": "^2.3.0",
6
6
  "bignumber.js": "9.1.2",
7
- "@cryptorubic/core": "0.5.1-alpha.ton-debug.1",
7
+ "@cryptorubic/core": "0.5.1-fix-polygon.0",
8
8
  "viem": "^2.19.1",
9
9
  "web3-utils": "^4.3.1",
10
10
  "@ton/ton": "^15.1.0",
11
11
  "@solana/web3.js": "1.95.3",
12
12
  "@solflare-wallet/utl-sdk": "^1.4.0",
13
13
  "@ethersproject/bignumber": "^5.7.0",
14
- "@cryptorubic/tron-types": "0.5.1-alpha.ton-debug.1",
14
+ "@cryptorubic/tron-types": "0.5.1-fix-polygon.0",
15
15
  "bitcoin-address-validation": "^2.2.3",
16
16
  "axios": "0.27.2",
17
17
  "crc-32": "^1.2.2",
@@ -11,7 +11,7 @@ export declare class EvmAdapter extends AbstractAdapter<PublicActions & PublicCl
11
11
  needPreswapAction(token: TokenAmount, contractAddress: string, walletAddress: string, amount: string): Promise<boolean>;
12
12
  handlePreswap(contractAddress: string, walletAddress: string, tokenAmount: TokenAmount): Promise<void>;
13
13
  constructor(adapterOptions: EvmAdapterOptions, logger?: ICustomLogger);
14
- protected createPublicClient(rpcList: string[]): (PublicActions & PublicClient) | null;
14
+ private createPublicClient;
15
15
  read<T>(address: string, abi: Abi, method: string, methodArgs?: unknown[]): Promise<T>;
16
16
  writeContract(address: string, abi: Abi, method: string, value?: string, methodArgs?: unknown[]): Promise<string>;
17
17
  write(address: string, to: string, value: string, data: string): Promise<string>;
@@ -10,6 +10,15 @@ const bignumber_js_1 = require("bignumber.js");
10
10
  const web3_pure_1 = require("../../utils/web3-pure");
11
11
  const possible_errors_1 = require("./constants/possible-errors");
12
12
  const uni_v3_permit_abi_1 = require("./constants/uni-v3-permit-abi");
13
+ const defaultTransportConfig = {
14
+ batch: { batchSize: 2000, wait: 16 },
15
+ retryCount: 2,
16
+ retryDelay: 100,
17
+ timeout: 5000
18
+ };
19
+ const defaultFallbackConfig = {
20
+ rank: true
21
+ };
13
22
  class EvmAdapter extends abstract_adapter_1.AbstractAdapter {
14
23
  async needPreswapAction(token, contractAddress, walletAddress, amount) {
15
24
  return this.needApprove(token, contractAddress, walletAddress, amount);
@@ -29,29 +38,24 @@ class EvmAdapter extends abstract_adapter_1.AbstractAdapter {
29
38
  }
30
39
  constructor(adapterOptions, logger) {
31
40
  super(adapterOptions.blockchain, logger);
32
- this.public = this.createPublicClient(adapterOptions.rpcList);
41
+ this.public = this.createPublicClient(adapterOptions.rpcList, adapterOptions?.transportConfig || defaultTransportConfig, adapterOptions?.fallbackConfig || defaultFallbackConfig);
33
42
  }
34
- createPublicClient(rpcList) {
43
+ createPublicClient(rpcList, transportConfig, fallbackConfig) {
35
44
  if (!rpcList?.[0]) {
36
45
  this.logger?.customError('RPC list is empty');
37
46
  return null;
38
47
  }
39
- const transports = rpcList.map((rpc) => (0, viem_1.http)(rpc, {
40
- batch: { batchSize: 2000, wait: 16 },
48
+ const transports = rpcList.map((rpc) => (0, viem_1.http)(rpc), {
41
49
  onFetchResponse: (response) => {
42
50
  this.handlePossibleError(response);
43
51
  },
44
- retryCount: 2,
45
- retryDelay: 100,
46
- timeout: 5000
47
- }));
52
+ ...transportConfig
53
+ });
48
54
  const chain = viem_blockchain_mapping_1.viemBlockchainMapping[this.blockchain];
49
55
  return (0, viem_1.createPublicClient)({
50
56
  // @ts-ignore
51
57
  chain,
52
- transport: (0, viem_1.fallback)(transports, {
53
- rank: true
54
- })
58
+ transport: (0, viem_1.fallback)(transports, fallbackConfig)
55
59
  });
56
60
  }
57
61
  async read(address, abi, method, methodArgs = []) {
@@ -1,6 +1,9 @@
1
1
  import { EvmBlockchainName } from '@cryptorubic/core';
2
+ import { HttpTransportConfig, FallbackTransportConfig } from 'viem';
2
3
  export interface EvmAdapterOptions {
3
4
  blockchain: EvmBlockchainName;
4
5
  rpcList: string[];
5
6
  walletAddress?: string;
7
+ transportConfig?: HttpTransportConfig;
8
+ fallbackConfig?: FallbackTransportConfig;
6
9
  }
@@ -127,21 +127,16 @@ class TonApiService {
127
127
  return res.decoded;
128
128
  }
129
129
  async fetchTokenInfo(tokenAddress) {
130
- try {
131
- const res = await this.httpClient.get(`${this.tonApiUrl}/v2/jettons/${tokenAddress}`, {
132
- headers: {
133
- apiKey: this.apiKey,
134
- referer: 'https://api.rubic.exchange'
135
- }
136
- });
137
- if ('error' in res) {
138
- throw new Error(`[TonApiService] Error in fetchTokenInfo - ${res.error}`);
130
+ const res = await this.httpClient.get(`${this.tonApiUrl}/v2/jettons/${tokenAddress}`, {
131
+ headers: {
132
+ apiKey: this.apiKey,
133
+ referer: 'https://api.rubic.exchange'
139
134
  }
140
- return res.metadata;
141
- }
142
- catch (err) {
143
- throw new Error(`[TonApiService] Error in fetchTokenInfo - ${err}`);
135
+ });
136
+ if ('error' in res) {
137
+ throw new Error(`[TonApiService] Error in fetchTokenInfo - ${res.error}`);
144
138
  }
139
+ return res.metadata;
145
140
  }
146
141
  /**
147
142
  *
@@ -70,7 +70,10 @@ class BlockchainAdapterFactoryService {
70
70
  if (viem_blockchain_mapping_1.viemBlockchainMapping?.[blockchain]) {
71
71
  return new evm_adapter_1.EvmAdapter({
72
72
  blockchain: blockchain,
73
- rpcList: rpcs
73
+ rpcList: rpcs,
74
+ ...(blockchain === core_1.BLOCKCHAIN_NAME.POLYGON && {
75
+ fallbackConfig: { rank: false }
76
+ })
74
77
  }, this.createLogger?.(`EVM_ADAPTER_${blockchain}`));
75
78
  }
76
79
  }