wative 1.2.8 → 1.2.11
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/lib/assets.d.ts.map +1 -1
- package/lib/index.esm.js +1 -1
- package/lib/index.umd.js +1 -1
- package/lib/tools.d.ts.map +1 -1
- package/lib/wallet-cli.esm.js +1 -1
- package/lib/wallet-cli.umd.js +1 -1
- package/lib/web3.d.ts +6 -2
- package/lib/web3.d.ts.map +1 -1
- package/package.json +21 -22
- package/src/account.ts +0 -864
- package/src/assets.ts +0 -399
- package/src/chain.ts +0 -28
- package/src/config.ts +0 -2074
- package/src/daemon-watcher.js +0 -181
- package/src/home_page.ts +0 -36
- package/src/index.d.ts +0 -12
- package/src/index.ts +0 -53
- package/src/network.ts +0 -819
- package/src/ssh/client.ts +0 -389
- package/src/ssh/config_manager.ts +0 -304
- package/src/ssh/index.ts +0 -66
- package/src/ssh/service_manager.ts +0 -685
- package/src/ssh/types.ts +0 -50
- package/src/ssh/utils.ts +0 -89
- package/src/ssh/wative_server.ts +0 -534
- package/src/tools.ts +0 -923
- package/src/tx_gas_utils.ts +0 -119
- package/src/utils.ts +0 -916
- package/src/wallet-cli.ts +0 -39
- package/src/wative.ts +0 -633
- package/src/web3.ts +0 -415
package/src/web3.ts
DELETED
|
@@ -1,415 +0,0 @@
|
|
|
1
|
-
import Web3 from 'web3';
|
|
2
|
-
import { chunkArray, excutePromiseFunction, sleep } from './utils';
|
|
3
|
-
import { Connection, PublicKey } from "@solana/web3.js";
|
|
4
|
-
import { getMint, getAssociatedTokenAddressSync } from "@solana/spl-token"
|
|
5
|
-
import { Metaplex, token } from "@metaplex-foundation/js";
|
|
6
|
-
import { BigNumber } from "bignumber.js";
|
|
7
|
-
|
|
8
|
-
const chainIdAccountBalanceMap: any = {};
|
|
9
|
-
|
|
10
|
-
export const getChainIdByEvm = async (rpc_url: string) => {
|
|
11
|
-
let web3 = new Web3(rpc_url);
|
|
12
|
-
let result = await excutePromiseFunction(web3.eth.getChainId, []);
|
|
13
|
-
return result;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export const getAccountBalanceInEvm = async (account: string, rpc_url: string) => {
|
|
17
|
-
const web3 = new Web3(rpc_url);
|
|
18
|
-
let result = await excutePromiseFunction(web3.eth.getBalance, [account]);
|
|
19
|
-
return result;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export const getAccountBalanceInSolana = async (account: string, rpc_url: string) => {
|
|
23
|
-
const connection = new Connection(rpc_url);
|
|
24
|
-
let result = await excutePromiseFunction(connection.getBalance.bind(connection), [new PublicKey(account)]);
|
|
25
|
-
return result;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export const getTokenInfoInEvm = async (token_address: string, rpc_url: string) => {
|
|
29
|
-
const web3 = new Web3(rpc_url);
|
|
30
|
-
const erc20 = new web3.eth.Contract([
|
|
31
|
-
{
|
|
32
|
-
"constant": true,
|
|
33
|
-
"inputs": [],
|
|
34
|
-
"name": "symbol",
|
|
35
|
-
"outputs": [
|
|
36
|
-
{
|
|
37
|
-
"name": "",
|
|
38
|
-
"type": "string"
|
|
39
|
-
}
|
|
40
|
-
],
|
|
41
|
-
"payable": false,
|
|
42
|
-
"stateMutability": "view",
|
|
43
|
-
"type": "function"
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
"constant": true,
|
|
47
|
-
"inputs": [],
|
|
48
|
-
"name": "name",
|
|
49
|
-
"outputs": [
|
|
50
|
-
{
|
|
51
|
-
"name": "",
|
|
52
|
-
"type": "string"
|
|
53
|
-
}
|
|
54
|
-
],
|
|
55
|
-
"payable": false,
|
|
56
|
-
"stateMutability": "view",
|
|
57
|
-
"type": "function"
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
"constant": true,
|
|
61
|
-
"inputs": [],
|
|
62
|
-
"name": "decimals",
|
|
63
|
-
"outputs": [
|
|
64
|
-
{
|
|
65
|
-
"name": "",
|
|
66
|
-
"type": "uint256"
|
|
67
|
-
}
|
|
68
|
-
],
|
|
69
|
-
"payable": false,
|
|
70
|
-
"stateMutability": "view",
|
|
71
|
-
"type": "function"
|
|
72
|
-
}
|
|
73
|
-
], token_address);
|
|
74
|
-
|
|
75
|
-
let sysmbol_result = await excutePromiseFunction(erc20.methods.symbol().call.bind(erc20), []);
|
|
76
|
-
let name_result = await excutePromiseFunction(erc20.methods.name().call.bind(erc20), []);
|
|
77
|
-
let decimals_result = await excutePromiseFunction(erc20.methods.decimals().call.bind(erc20), []);
|
|
78
|
-
|
|
79
|
-
if (!sysmbol_result.status || !name_result.status || !decimals_result.status) {
|
|
80
|
-
return {
|
|
81
|
-
status: false,
|
|
82
|
-
output: "Failed to get token info"
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
return {
|
|
86
|
-
status: true,
|
|
87
|
-
output: {
|
|
88
|
-
symbol: sysmbol_result.output,
|
|
89
|
-
name: name_result.output,
|
|
90
|
-
decimals: decimals_result.output
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export const getTokenInfoInSolana = async (token_address: string, rpc_url: string) => {
|
|
96
|
-
const connection = new Connection(rpc_url);
|
|
97
|
-
const metaplex = Metaplex.make(connection);
|
|
98
|
-
const mintAddress = new PublicKey(token_address);
|
|
99
|
-
const token_mint_info = await excutePromiseFunction(getMint, [connection, mintAddress]);
|
|
100
|
-
let result = {
|
|
101
|
-
status: true,
|
|
102
|
-
output: {
|
|
103
|
-
symbol: "",
|
|
104
|
-
name: "",
|
|
105
|
-
decimals: ""
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
if (!token_mint_info.status) {
|
|
110
|
-
return {
|
|
111
|
-
status: false,
|
|
112
|
-
output: "Failed to get token decimals"
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
result.output.decimals = token_mint_info.output.decimals;
|
|
117
|
-
try {
|
|
118
|
-
const metadataAccount = metaplex
|
|
119
|
-
.nfts()
|
|
120
|
-
.pdas()
|
|
121
|
-
.metadata({ mint: mintAddress });
|
|
122
|
-
const metadataAccountInfo = await connection.getAccountInfo(metadataAccount);
|
|
123
|
-
|
|
124
|
-
if (metadataAccountInfo) {
|
|
125
|
-
const token = await metaplex.nfts().findByMint({ mintAddress: mintAddress });
|
|
126
|
-
result.output.name = token.name;
|
|
127
|
-
result.output.symbol = token.symbol;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
} catch (error) {
|
|
131
|
-
return {
|
|
132
|
-
status: false,
|
|
133
|
-
output: "Failed to get token name"
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
return result;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
export const getTokenBalanceInEvm = async (account: string, token_address: string, rpc_url: string) => {
|
|
140
|
-
const web3 = new Web3(rpc_url);
|
|
141
|
-
const erc20 = new web3.eth.Contract([
|
|
142
|
-
{
|
|
143
|
-
"constant": true,
|
|
144
|
-
"inputs": [
|
|
145
|
-
{
|
|
146
|
-
"name": "who",
|
|
147
|
-
"type": "address"
|
|
148
|
-
}
|
|
149
|
-
],
|
|
150
|
-
"name": "balanceOf",
|
|
151
|
-
"outputs": [
|
|
152
|
-
{
|
|
153
|
-
"name": "",
|
|
154
|
-
"type": "uint256"
|
|
155
|
-
}
|
|
156
|
-
],
|
|
157
|
-
"payable": false,
|
|
158
|
-
"stateMutability": "view",
|
|
159
|
-
"type": "function"
|
|
160
|
-
}
|
|
161
|
-
], token_address);
|
|
162
|
-
let balance_result = await excutePromiseFunction(erc20.methods.balanceOf(account).call.bind(erc20), []);
|
|
163
|
-
if (!balance_result.status) {
|
|
164
|
-
return {
|
|
165
|
-
status: false,
|
|
166
|
-
output: "Failed to get token balance"
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
return {
|
|
170
|
-
status: true,
|
|
171
|
-
output: balance_result.output
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
export const getTokenBalanceInSolana = async (account: string, token_address: string, rpc_url: string) => {
|
|
176
|
-
const connection = new Connection(rpc_url);
|
|
177
|
-
const tokenAccount = getAssociatedTokenAddressSync(new PublicKey(token_address), new PublicKey(account));
|
|
178
|
-
let balance_result = await excutePromiseFunction(connection.getTokenAccountBalance.bind(connection), [tokenAccount]);
|
|
179
|
-
if (!balance_result.status) {
|
|
180
|
-
if (balance_result.output.includes("could not find account")) {
|
|
181
|
-
return {
|
|
182
|
-
status: true,
|
|
183
|
-
output: "0"
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
return {
|
|
187
|
-
status: false,
|
|
188
|
-
output: "Failed to get token balance"
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
return {
|
|
192
|
-
status: true,
|
|
193
|
-
output: balance_result.output.value.amount
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
export const getCodeInEvm = async (account: string, rpc_url: string) => {
|
|
198
|
-
const web3 = new Web3(rpc_url);
|
|
199
|
-
let code_result = await excutePromiseFunction(web3.eth.getCode.bind(web3), [account]);
|
|
200
|
-
if (!code_result.status) {
|
|
201
|
-
return {
|
|
202
|
-
status: false,
|
|
203
|
-
output: "Failed to get code"
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
return {
|
|
207
|
-
status: true,
|
|
208
|
-
output: code_result.output
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
export const getTransferTokenData = async (to: string, amount: string, rpc_url: string) => {
|
|
213
|
-
const web3 = new Web3(rpc_url);
|
|
214
|
-
const transfer_token_abi_data = web3.eth.abi.encodeFunctionCall({
|
|
215
|
-
"constant": false,
|
|
216
|
-
"inputs": [
|
|
217
|
-
{
|
|
218
|
-
"name": "_to",
|
|
219
|
-
"type": "address"
|
|
220
|
-
},
|
|
221
|
-
{
|
|
222
|
-
"name": "_value",
|
|
223
|
-
"type": "uint256"
|
|
224
|
-
}
|
|
225
|
-
],
|
|
226
|
-
"name": "transfer",
|
|
227
|
-
"outputs": [],
|
|
228
|
-
"payable": false,
|
|
229
|
-
"stateMutability": "nonpayable",
|
|
230
|
-
"type": "function"
|
|
231
|
-
}, [to, amount]);
|
|
232
|
-
|
|
233
|
-
return transfer_token_abi_data;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
export const getPrioritizationFee = async (rpc_url: string) => {
|
|
237
|
-
const connection = new Connection(rpc_url);
|
|
238
|
-
let result = await excutePromiseFunction(connection.getRecentPrioritizationFees.bind(connection), []);
|
|
239
|
-
if (!result.status) {
|
|
240
|
-
return {
|
|
241
|
-
status: false,
|
|
242
|
-
output: "Failed to get recent prioritization fees"
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
let prioritization_fee_list = result.output;
|
|
247
|
-
const fees = prioritization_fee_list.map((fee: any) => fee.prioritizationFee).sort();
|
|
248
|
-
const prioritization_fee = fees.length > 0 ? Math.ceil(fees.reduce((acc: any, cur: any) => acc + cur) / fees.length) : 1000;
|
|
249
|
-
|
|
250
|
-
return {
|
|
251
|
-
status: true,
|
|
252
|
-
output: prioritization_fee
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
export const getLatestBlockhash = async (rpc_url: string) => {
|
|
257
|
-
const connection = new Connection(rpc_url);
|
|
258
|
-
let result = await excutePromiseFunction(connection.getLatestBlockhash.bind(connection), [{
|
|
259
|
-
commitment: "finalized"
|
|
260
|
-
}]);
|
|
261
|
-
if (!result.status) {
|
|
262
|
-
return {
|
|
263
|
-
status: false,
|
|
264
|
-
output: "Failed to get latest blockhash"
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
return {
|
|
268
|
-
status: true,
|
|
269
|
-
output: result.output
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
export const getAccountInfoInSolana = async (account: string, rpc_url: string) => {
|
|
274
|
-
const connection = new Connection(rpc_url);
|
|
275
|
-
let result = await excutePromiseFunction(connection.getAccountInfo.bind(connection), [
|
|
276
|
-
new PublicKey(account.toString())
|
|
277
|
-
]);
|
|
278
|
-
if (!result.status) {
|
|
279
|
-
return {
|
|
280
|
-
status: false,
|
|
281
|
-
output: "Failed to get account info"
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
return {
|
|
285
|
-
status: true,
|
|
286
|
-
output: result.output
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
export const updateBalance = async (account_address_list: string[], token_address: string, chain_id: string, rpc_url: string, is_evm: boolean) => {
|
|
291
|
-
let accountBalanceMap: any;
|
|
292
|
-
if (chain_id in chainIdAccountBalanceMap) {
|
|
293
|
-
accountBalanceMap = chainIdAccountBalanceMap[chain_id][token_address] || {};
|
|
294
|
-
} else {
|
|
295
|
-
chainIdAccountBalanceMap[chain_id] = {};
|
|
296
|
-
accountBalanceMap = {};
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
for (const account of account_address_list) {
|
|
300
|
-
if (!account) {
|
|
301
|
-
continue;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
if (!(account in accountBalanceMap)) {
|
|
305
|
-
let result: any;
|
|
306
|
-
if (token_address === "0") {
|
|
307
|
-
if (is_evm) {
|
|
308
|
-
result = await getAccountBalanceInEvm(account, rpc_url);
|
|
309
|
-
} else {
|
|
310
|
-
result = await getAccountBalanceInSolana(account, rpc_url);
|
|
311
|
-
}
|
|
312
|
-
} else {
|
|
313
|
-
if (is_evm) {
|
|
314
|
-
result = await getTokenBalanceInEvm(account, token_address, rpc_url);
|
|
315
|
-
|
|
316
|
-
} else {
|
|
317
|
-
result = await getTokenBalanceInSolana(account, token_address, rpc_url);
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
if (result.status) {
|
|
322
|
-
accountBalanceMap[account] = result.output;
|
|
323
|
-
}
|
|
324
|
-
await sleep(200);
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
chainIdAccountBalanceMap[chain_id][token_address] = accountBalanceMap;
|
|
329
|
-
|
|
330
|
-
return chainIdAccountBalanceMap;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
export const getTokenBalance = (
|
|
334
|
-
chain_id: string,
|
|
335
|
-
account_address_list: any,
|
|
336
|
-
asset_info_list: any,
|
|
337
|
-
network_info: any
|
|
338
|
-
) => {
|
|
339
|
-
let batchAccountBalanceOf: any = {};
|
|
340
|
-
|
|
341
|
-
if (!(chain_id in chainIdAccountBalanceMap)) {
|
|
342
|
-
return batchAccountBalanceOf;
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
asset_info_list.unshift({
|
|
346
|
-
address: "0",
|
|
347
|
-
name: network_info.nativeCurrency.name,
|
|
348
|
-
symbol: network_info.nativeCurrency.symbol,
|
|
349
|
-
decimals: network_info.nativeCurrency.decimals,
|
|
350
|
-
display_decimals: 4
|
|
351
|
-
});
|
|
352
|
-
let account_address_list_len = account_address_list.length;
|
|
353
|
-
for (let i = 0; i < account_address_list_len; i++) {
|
|
354
|
-
let account_address = account_address_list[i];
|
|
355
|
-
|
|
356
|
-
if (!account_address) {
|
|
357
|
-
continue;
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
for (let j = 0; j < asset_info_list.length; j++) {
|
|
361
|
-
let asset_info = asset_info_list[j];
|
|
362
|
-
let token_balance = "0";
|
|
363
|
-
if (!chainIdAccountBalanceMap[chain_id][asset_info.address]) {
|
|
364
|
-
continue;
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
if (account_address in chainIdAccountBalanceMap[chain_id][asset_info.address]) {
|
|
368
|
-
let balance = new BigNumber(chainIdAccountBalanceMap[chain_id][asset_info.address][account_address]);
|
|
369
|
-
token_balance = balance.dividedBy(10 ** asset_info.decimals).toFixed(asset_info.display_decimals || 4, BigNumber.ROUND_FLOOR);
|
|
370
|
-
}
|
|
371
|
-
if (!batchAccountBalanceOf[account_address]) {
|
|
372
|
-
batchAccountBalanceOf[account_address] = {};
|
|
373
|
-
}
|
|
374
|
-
batchAccountBalanceOf[account_address][asset_info.symbol] = token_balance;
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
return batchAccountBalanceOf;
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
export const deleteTokenBalance = (chain_id: string, account_address_list: string[], token_address_list: string[]) => {
|
|
382
|
-
for (let i = 0; i < account_address_list.length; i++) {
|
|
383
|
-
let account_address = account_address_list[i];
|
|
384
|
-
for (let j = 0; j < token_address_list.length; j++) {
|
|
385
|
-
let token_address = token_address_list[j];
|
|
386
|
-
try {
|
|
387
|
-
delete chainIdAccountBalanceMap[chain_id][token_address][account_address];
|
|
388
|
-
} catch (err) { }
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
export const batchUpdateUserTokenBalance = async (chain_id: string, account_address: string, token_address_list: string[], rpc_url: string, is_evm: boolean) => {
|
|
394
|
-
for (let i = 0; i < token_address_list.length; i++) {
|
|
395
|
-
let token_address = token_address_list[i];
|
|
396
|
-
await updateBalance([account_address], token_address, chain_id, rpc_url, is_evm);
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
export const batchHasTokenBalance = (chain_id: string, account_address_list: string[]) => {
|
|
401
|
-
let hasAccount = 0;
|
|
402
|
-
if (chain_id in chainIdAccountBalanceMap) {
|
|
403
|
-
if ("0" in chainIdAccountBalanceMap[chain_id]) {
|
|
404
|
-
for (let i = 0; i < account_address_list.length; i++) {
|
|
405
|
-
if (account_address_list[i] in chainIdAccountBalanceMap[chain_id]["0"]) {
|
|
406
|
-
hasAccount += 1;
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
if (hasAccount === 0) {
|
|
412
|
-
return false
|
|
413
|
-
}
|
|
414
|
-
return hasAccount / account_address_list.length > 0.8;
|
|
415
|
-
}
|