@cryptorubic/web3 0.4.3 → 0.5.1

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/README.md ADDED
@@ -0,0 +1 @@
1
+ # web3
package/package.json CHANGED
@@ -1,24 +1,21 @@
1
1
  {
2
2
  "name": "@cryptorubic/web3",
3
- "version": "0.4.3",
4
- "scripts": {
5
- "build": "tsc --project tsconfig.lib.json --outDir ../../dist && cp package.json ../../dist/packages/web3"
6
- },
3
+ "version": "0.5.1",
7
4
  "dependencies": {
8
- "@cryptorubic/core": "0.0.1",
9
- "@cryptorubic/tron-types": "0.0.1",
10
- "@ethersproject/bignumber": "^5.7.0",
5
+ "tslib": "^2.3.0",
6
+ "bignumber.js": "9.1.2",
7
+ "@cryptorubic/core": "0.5.1",
8
+ "viem": "^2.19.1",
9
+ "web3-utils": "^4.3.1",
10
+ "@ton/ton": "^15.1.0",
11
11
  "@solana/web3.js": "1.95.3",
12
12
  "@solflare-wallet/utl-sdk": "^1.4.0",
13
- "@ton/ton": "^15.1.0",
14
- "axios": "0.27.2",
15
- "bignumber.js": "9.1.2",
13
+ "@ethersproject/bignumber": "^5.7.0",
14
+ "@cryptorubic/tron-types": "0.5.1",
16
15
  "bitcoin-address-validation": "^2.2.3",
16
+ "axios": "0.27.2",
17
17
  "crc-32": "^1.2.2",
18
- "tronweb": "^6.0.0-beta.4",
19
- "tslib": "^2.3.0",
20
- "viem": "^2.19.1",
21
- "web3-utils": "^4.3.1"
18
+ "tronweb": "^6.0.0-beta.4"
22
19
  },
23
20
  "type": "commonjs",
24
21
  "main": "./src/index.js",
@@ -28,5 +25,6 @@
28
25
  },
29
26
  "author": {
30
27
  "name": "Sleta Dmitrii"
31
- }
28
+ },
29
+ "types": "./src/index.d.ts"
32
30
  }
@@ -34,11 +34,11 @@ class BitcoinAdapter extends abstract_adapter_1.AbstractAdapter {
34
34
  recipient,
35
35
  amount: {
36
36
  amount,
37
- decimals: 8,
37
+ decimals: 8
38
38
  },
39
- ...(memo && { memo }),
40
- },
41
- ],
39
+ ...(memo && { memo })
40
+ }
41
+ ]
42
42
  }, (error, txHash) => {
43
43
  if (error) {
44
44
  reject(error);
@@ -9,19 +9,19 @@ exports.erc20TokenAbi = [
9
9
  outputs: [{ name: '', type: 'string' }],
10
10
  payable: false,
11
11
  stateMutability: 'view',
12
- type: 'function',
12
+ type: 'function'
13
13
  },
14
14
  {
15
15
  constant: false,
16
16
  inputs: [
17
17
  { name: '_spender', type: 'address' },
18
- { name: '_value', type: 'uint256' },
18
+ { name: '_value', type: 'uint256' }
19
19
  ],
20
20
  name: 'approve',
21
21
  outputs: [],
22
22
  payable: false,
23
23
  stateMutability: 'nonpayable',
24
- type: 'function',
24
+ type: 'function'
25
25
  },
26
26
  {
27
27
  constant: true,
@@ -30,7 +30,7 @@ exports.erc20TokenAbi = [
30
30
  outputs: [{ name: '', type: 'uint256' }],
31
31
  payable: false,
32
32
  stateMutability: 'view',
33
- type: 'function',
33
+ type: 'function'
34
34
  },
35
35
  {
36
36
  constant: true,
@@ -39,7 +39,7 @@ exports.erc20TokenAbi = [
39
39
  outputs: [{ name: '', type: 'uint256' }],
40
40
  payable: false,
41
41
  stateMutability: 'view',
42
- type: 'function',
42
+ type: 'function'
43
43
  },
44
44
  {
45
45
  constant: true,
@@ -48,7 +48,7 @@ exports.erc20TokenAbi = [
48
48
  outputs: [{ name: '', type: 'uint256' }],
49
49
  payable: false,
50
50
  stateMutability: 'view',
51
- type: 'function',
51
+ type: 'function'
52
52
  },
53
53
  {
54
54
  constant: true,
@@ -57,30 +57,30 @@ exports.erc20TokenAbi = [
57
57
  outputs: [{ name: '', type: 'string' }],
58
58
  payable: false,
59
59
  stateMutability: 'view',
60
- type: 'function',
60
+ type: 'function'
61
61
  },
62
62
  {
63
63
  constant: false,
64
64
  inputs: [
65
65
  { name: '_to', type: 'address' },
66
- { name: '_value', type: 'uint256' },
66
+ { name: '_value', type: 'uint256' }
67
67
  ],
68
68
  name: 'transfer',
69
69
  outputs: [],
70
70
  payable: false,
71
71
  stateMutability: 'nonpayable',
72
- type: 'function',
72
+ type: 'function'
73
73
  },
74
74
  {
75
75
  constant: true,
76
76
  inputs: [
77
77
  { name: '_owner', type: 'address' },
78
- { name: '_spender', type: 'address' },
78
+ { name: '_spender', type: 'address' }
79
79
  ],
80
80
  name: 'allowance',
81
81
  outputs: [{ name: 'remaining', type: 'uint256' }],
82
82
  payable: false,
83
83
  stateMutability: 'view',
84
- type: 'function',
85
- },
84
+ type: 'function'
85
+ }
86
86
  ];
@@ -10,5 +10,5 @@ exports.possibleErrors = [
10
10
  'account suspended, please top up to reenable',
11
11
  'your account has been suspended',
12
12
  'too many requests, we recommend you to use free api key',
13
- 'origin not allowed',
13
+ 'origin not allowed'
14
14
  ];
@@ -7,65 +7,65 @@ exports.TRC20_CONTRACT_ABI = [
7
7
  name: 'symbol',
8
8
  outputs: [{ type: 'string' }],
9
9
  stateMutability: 'view',
10
- type: 'function',
10
+ type: 'function'
11
11
  },
12
12
  {
13
13
  inputs: [
14
14
  { name: 'owner', type: 'address' },
15
- { name: 'spender', type: 'address' },
15
+ { name: 'spender', type: 'address' }
16
16
  ],
17
17
  name: 'allowance',
18
18
  outputs: [{ type: 'uint256' }],
19
19
  stateMutability: 'view',
20
- type: 'function',
20
+ type: 'function'
21
21
  },
22
22
  {
23
23
  inputs: [
24
24
  { name: 'spender', type: 'address' },
25
- { name: 'value', type: 'uint256' },
25
+ { name: 'value', type: 'uint256' }
26
26
  ],
27
27
  name: 'approve',
28
28
  outputs: [{ type: 'bool' }],
29
29
  stateMutability: 'nonpayable',
30
- type: 'function',
30
+ type: 'function'
31
31
  },
32
32
  {
33
33
  inputs: [{ name: 'account', type: 'address' }],
34
34
  name: 'balanceOf',
35
35
  outputs: [{ type: 'uint256' }],
36
36
  stateMutability: 'view',
37
- type: 'function',
37
+ type: 'function'
38
38
  },
39
39
  {
40
40
  inputs: [],
41
41
  name: 'decimals',
42
42
  outputs: [{ type: 'uint8' }],
43
43
  stateMutability: 'view',
44
- type: 'function',
44
+ type: 'function'
45
45
  },
46
46
  {
47
47
  inputs: [],
48
48
  name: 'name',
49
49
  outputs: [{ type: 'string' }],
50
50
  stateMutability: 'view',
51
- type: 'function',
51
+ type: 'function'
52
52
  },
53
53
  {
54
54
  inputs: [],
55
55
  name: 'totalSupply',
56
56
  outputs: [{ type: 'uint256' }],
57
57
  stateMutability: 'view',
58
- type: 'function',
58
+ type: 'function'
59
59
  },
60
60
  {
61
61
  inputs: [
62
62
  { name: 'to', type: 'address' },
63
- { name: 'value', type: 'uint256' },
63
+ { name: 'value', type: 'uint256' }
64
64
  ],
65
65
  name: 'transfer',
66
66
  outputs: [{ type: 'bool' }],
67
67
  stateMutability: 'nonpayable',
68
- type: 'function',
68
+ type: 'function'
69
69
  },
70
70
  {
71
71
  inputs: [
@@ -73,12 +73,12 @@ exports.TRC20_CONTRACT_ABI = [
73
73
  { name: 'to', type: 'address' },
74
74
  {
75
75
  name: 'value',
76
- type: 'uint256',
77
- },
76
+ type: 'uint256'
77
+ }
78
78
  ],
79
79
  name: 'transferFrom',
80
80
  outputs: [{ type: 'bool' }],
81
81
  stateMutability: 'nonpayable',
82
- type: 'function',
83
- },
82
+ type: 'function'
83
+ }
84
84
  ];
@@ -7,20 +7,20 @@ exports.TRON_MULTICALL_ABI = [
7
7
  {
8
8
  components: [
9
9
  { internalType: 'address', name: 'target', type: 'address' },
10
- { internalType: 'bytes', name: 'callData', type: 'bytes' },
10
+ { internalType: 'bytes', name: 'callData', type: 'bytes' }
11
11
  ],
12
12
  internalType: 'struct Multicall.Call[]',
13
13
  name: 'calls',
14
- type: 'tuple[]',
15
- },
14
+ type: 'tuple[]'
15
+ }
16
16
  ],
17
17
  name: 'aggregateViewCalls',
18
18
  outputs: [
19
19
  { internalType: 'uint256', name: 'blockNumber', type: 'uint256' },
20
20
  { internalType: 'bytes[]', name: 'returnData', type: 'bytes[]' },
21
- { internalType: 'bool[]', name: 'results', type: 'bool[]' },
21
+ { internalType: 'bool[]', name: 'results', type: 'bool[]' }
22
22
  ],
23
23
  stateMutability: 'view',
24
- type: 'function',
25
- },
24
+ type: 'function'
25
+ }
26
26
  ];
@@ -7,66 +7,66 @@ exports.UNI_V3_PERMIT_2_ABI = [
7
7
  {
8
8
  internalType: 'address',
9
9
  name: 'owner',
10
- type: 'address',
10
+ type: 'address'
11
11
  },
12
12
  {
13
13
  internalType: 'address',
14
14
  name: 'token',
15
- type: 'address',
15
+ type: 'address'
16
16
  },
17
17
  {
18
18
  internalType: 'address',
19
19
  name: 'spender',
20
- type: 'address',
21
- },
20
+ type: 'address'
21
+ }
22
22
  ],
23
23
  name: 'allowance',
24
24
  outputs: [
25
25
  {
26
26
  internalType: 'uint160',
27
27
  name: 'amount',
28
- type: 'uint160',
28
+ type: 'uint160'
29
29
  },
30
30
  {
31
31
  internalType: 'uint48',
32
32
  name: 'expiration',
33
- type: 'uint48',
33
+ type: 'uint48'
34
34
  },
35
35
  {
36
36
  internalType: 'uint48',
37
37
  name: 'nonce',
38
- type: 'uint48',
39
- },
38
+ type: 'uint48'
39
+ }
40
40
  ],
41
41
  stateMutability: 'view',
42
- type: 'function',
42
+ type: 'function'
43
43
  },
44
44
  {
45
45
  inputs: [
46
46
  {
47
47
  internalType: 'address',
48
48
  name: 'token',
49
- type: 'address',
49
+ type: 'address'
50
50
  },
51
51
  {
52
52
  internalType: 'address',
53
53
  name: 'spender',
54
- type: 'address',
54
+ type: 'address'
55
55
  },
56
56
  {
57
57
  internalType: 'uint160',
58
58
  name: 'amount',
59
- type: 'uint160',
59
+ type: 'uint160'
60
60
  },
61
61
  {
62
62
  internalType: 'uint48',
63
63
  name: 'expiration',
64
- type: 'uint48',
65
- },
64
+ type: 'uint48'
65
+ }
66
66
  ],
67
67
  name: 'approve',
68
68
  outputs: [],
69
69
  stateMutability: 'nonpayable',
70
- type: 'function',
71
- },
70
+ type: 'function'
71
+ }
72
72
  ];
@@ -24,7 +24,7 @@ class EvmAdapter extends abstract_adapter_1.AbstractAdapter {
24
24
  ? '0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000'
25
25
  : tokenAmount.blockchain;
26
26
  await this.writeContract(fromTokenAddress, erc20_token_abi_1.erc20TokenAbi, 'approve', '0', [
27
- approveAmount,
27
+ approveAmount
28
28
  ]);
29
29
  }
30
30
  constructor(adapterOptions, logger) {
@@ -43,15 +43,15 @@ class EvmAdapter extends abstract_adapter_1.AbstractAdapter {
43
43
  },
44
44
  retryCount: 2,
45
45
  retryDelay: 100,
46
- timeout: 5000,
46
+ timeout: 5000
47
47
  }));
48
48
  const chain = viem_blockchain_mapping_1.viemBlockchainMapping[this.blockchain];
49
49
  return (0, viem_1.createPublicClient)({
50
50
  // @ts-ignore
51
51
  chain,
52
52
  transport: (0, viem_1.fallback)(transports, {
53
- rank: true,
54
- }),
53
+ rank: true
54
+ })
55
55
  });
56
56
  }
57
57
  async read(address, abi, method, methodArgs = []) {
@@ -59,7 +59,7 @@ class EvmAdapter extends abstract_adapter_1.AbstractAdapter {
59
59
  abi,
60
60
  address: address,
61
61
  args: methodArgs,
62
- functionName: method,
62
+ functionName: method
63
63
  });
64
64
  return result;
65
65
  }
@@ -71,7 +71,7 @@ class EvmAdapter extends abstract_adapter_1.AbstractAdapter {
71
71
  args: methodArgs,
72
72
  functionName: method,
73
73
  chain: this.public.chain,
74
- value: (0, viem_1.parseEther)(value),
74
+ value: (0, viem_1.parseEther)(value)
75
75
  });
76
76
  return result;
77
77
  }
@@ -81,7 +81,7 @@ class EvmAdapter extends abstract_adapter_1.AbstractAdapter {
81
81
  to: to,
82
82
  value: (0, viem_1.parseEther)(value),
83
83
  data: data,
84
- chain: this.public.chain,
84
+ chain: this.public.chain
85
85
  });
86
86
  return result;
87
87
  }
@@ -113,11 +113,11 @@ class EvmAdapter extends abstract_adapter_1.AbstractAdapter {
113
113
  const contract = {
114
114
  abi,
115
115
  address: address,
116
- functionName: method,
116
+ functionName: method
117
117
  };
118
118
  const contracts = methodArgs.map((multicallArguments) => ({
119
119
  ...contract,
120
- args: multicallArguments,
120
+ args: multicallArguments
121
121
  }));
122
122
  return this.multicallByContract({ contracts }, allowErrors);
123
123
  }
@@ -126,12 +126,12 @@ class EvmAdapter extends abstract_adapter_1.AbstractAdapter {
126
126
  const data = (0, viem_1.encodeFunctionData)({
127
127
  abi: contractAbi,
128
128
  args: parameters,
129
- functionName: method,
129
+ functionName: method
130
130
  });
131
131
  return {
132
132
  data: data,
133
133
  to: contractAddress,
134
- value: value || '0',
134
+ value: value || '0'
135
135
  };
136
136
  }
137
137
  catch (err) {
@@ -144,11 +144,11 @@ class EvmAdapter extends abstract_adapter_1.AbstractAdapter {
144
144
  account: from,
145
145
  data: config.data,
146
146
  to: config.to,
147
- ...(config.value && { value: BigInt(config.value) }),
147
+ ...(config.value && { value: BigInt(config.value) })
148
148
  };
149
149
  const gasLimitWei = await Promise.race([
150
150
  this.public.estimateGas(callParams),
151
- new Promise((_, reject) => setTimeout(() => reject('Timeout'), timeout)),
151
+ new Promise((_, reject) => setTimeout(() => reject('Timeout'), timeout))
152
152
  ]);
153
153
  return gasLimitWei?.toString();
154
154
  }
@@ -163,13 +163,13 @@ class EvmAdapter extends abstract_adapter_1.AbstractAdapter {
163
163
  const contracts = filteredTokenAddresses.flatMap((contractAddress) => {
164
164
  const contract = {
165
165
  abi: erc20_token_abi_1.erc20TokenAbi,
166
- address: contractAddress,
166
+ address: contractAddress
167
167
  };
168
168
  return ['decimals', 'symbol', 'name'].map((method) => ({ ...contract, functionName: method }));
169
169
  });
170
170
  const results = contracts.length
171
171
  ? (await this.multicallByContract({
172
- contracts,
172
+ contracts
173
173
  }))
174
174
  : [];
175
175
  const tokens = [];
@@ -183,7 +183,7 @@ class EvmAdapter extends abstract_adapter_1.AbstractAdapter {
183
183
  blockchain: this.blockchain,
184
184
  decimals,
185
185
  name,
186
- symbol,
186
+ symbol
187
187
  });
188
188
  tokens.push(token);
189
189
  }
@@ -216,7 +216,7 @@ class EvmAdapter extends abstract_adapter_1.AbstractAdapter {
216
216
  async getBalance(walletAddress, tokenAddress) {
217
217
  if (!tokenAddress) {
218
218
  const nativeBalance = await this.public.getBalance({
219
- address: walletAddress,
219
+ address: walletAddress
220
220
  });
221
221
  return new bignumber_js_1.default(nativeBalance.toString());
222
222
  }
@@ -225,7 +225,7 @@ class EvmAdapter extends abstract_adapter_1.AbstractAdapter {
225
225
  }
226
226
  async getTransactionCount(walletAddress) {
227
227
  const transactionCount = await this.public?.getTransactionCount({
228
- address: walletAddress,
228
+ address: walletAddress
229
229
  });
230
230
  return transactionCount ?? 0;
231
231
  }
@@ -234,8 +234,8 @@ class EvmAdapter extends abstract_adapter_1.AbstractAdapter {
234
234
  this.read(fromTokenAddress, erc20_token_abi_1.erc20TokenAbi, 'decimals'),
235
235
  this.read(fromTokenAddress, erc20_token_abi_1.erc20TokenAbi, 'allowance', [
236
236
  walletAddress,
237
- spenderAddress,
238
- ]),
237
+ spenderAddress
238
+ ])
239
239
  ]);
240
240
  const allowanceWeiBN = new bignumber_js_1.default(allowance);
241
241
  const allowanceNonWei = core_1.Token.fromWei(allowanceWeiBN, Number(decimals));
@@ -247,7 +247,7 @@ class EvmAdapter extends abstract_adapter_1.AbstractAdapter {
247
247
  return {
248
248
  data: tx.data,
249
249
  to: tx.to,
250
- value: tx.value,
250
+ value: tx.value
251
251
  };
252
252
  }
253
253
  async needApprove(token, contractAddress, walletAddress, amount) {
@@ -277,7 +277,7 @@ class EvmAdapter extends abstract_adapter_1.AbstractAdapter {
277
277
  return {
278
278
  data: tx.data,
279
279
  value: tx.value,
280
- to: tx.to,
280
+ to: tx.to
281
281
  };
282
282
  }
283
283
  async approveOnPermit2(fromAddress, tokenAddress, permit2Address, spenderAddress, deadline = new bignumber_js_1.default(1000000), amount) {
@@ -310,7 +310,7 @@ class EvmAdapter extends abstract_adapter_1.AbstractAdapter {
310
310
  return {
311
311
  baseFee: lastBaseFeePerGas?.toFixed(),
312
312
  maxFeePerGas: maxFeePerGas?.toFixed(),
313
- maxPriorityFeePerGas: maxPriorityFeePerGas?.toFixed(),
313
+ maxPriorityFeePerGas: maxPriorityFeePerGas?.toFixed()
314
314
  };
315
315
  }
316
316
  /**
@@ -335,7 +335,7 @@ class EvmAdapter extends abstract_adapter_1.AbstractAdapter {
335
335
  const feeHistory = await this.public.getFeeHistory({
336
336
  blockCount: HISTORICAL_BLOCKS,
337
337
  rewardPercentiles: [50],
338
- blockTag: 'pending',
338
+ blockTag: 'pending'
339
339
  });
340
340
  if (!feeHistory?.reward) {
341
341
  throw new Error('No fee history found');
@@ -351,7 +351,7 @@ class EvmAdapter extends abstract_adapter_1.AbstractAdapter {
351
351
  blockCount: 1,
352
352
  rewardPercentiles: [50],
353
353
  // blockTag: 'pending',
354
- blockNumber: blockNumber,
354
+ blockNumber: blockNumber
355
355
  });
356
356
  if (!feeHistory?.baseFeePerGas.length) {
357
357
  throw new Error('No fee history found');
@@ -368,7 +368,7 @@ class EvmAdapter extends abstract_adapter_1.AbstractAdapter {
368
368
  this.logger?.customError('Rpc fetch error', {
369
369
  blockchain: this.blockchain,
370
370
  text: await response.text(),
371
- url: response.url,
371
+ url: response.url
372
372
  });
373
373
  }
374
374
  }
@@ -50,7 +50,7 @@ class SolanaAdapter extends abstract_adapter_1.AbstractAdapter {
50
50
  blockchain: core_1.BLOCKCHAIN_NAME.SOLANA,
51
51
  decimals: token.decimals,
52
52
  name: token.name,
53
- symbol: token.symbol,
53
+ symbol: token.symbol
54
54
  });
55
55
  });
56
56
  if (nativeTokenIndex === -1) {
@@ -28,7 +28,7 @@ class TonAdapter extends abstract_adapter_1.AbstractAdapter {
28
28
  blockchain: core_1.BLOCKCHAIN_NAME.TON,
29
29
  decimals: Number(decimals),
30
30
  name,
31
- symbol,
31
+ symbol
32
32
  }));
33
33
  return necessaryInfo;
34
34
  }
@@ -69,7 +69,7 @@ class TonAdapter extends abstract_adapter_1.AbstractAdapter {
69
69
  const transferAmount = BigInt(amount);
70
70
  const encodeConfig = {
71
71
  address: receiver,
72
- amount: transferAmount.toString(),
72
+ amount: transferAmount.toString()
73
73
  };
74
74
  return encodeConfig;
75
75
  }
@@ -92,7 +92,7 @@ class TonAdapter extends abstract_adapter_1.AbstractAdapter {
92
92
  const encodeConfig = {
93
93
  address: jettonWalletAddress.toRawString(),
94
94
  amount: (0, ton_1.toNano)('0.05').toString(),
95
- payload: body.toBoc().toString('base64'),
95
+ payload: body.toBoc().toString('base64')
96
96
  };
97
97
  return encodeConfig;
98
98
  }