wative 1.2.8 → 1.2.10
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 +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/assets.ts
DELETED
|
@@ -1,399 +0,0 @@
|
|
|
1
|
-
const chalk = require('chalk');
|
|
2
|
-
import * as path from "path";
|
|
3
|
-
import * as fs from 'fs';
|
|
4
|
-
import { BigNumber } from 'bignumber.js';
|
|
5
|
-
import { getChainType, isEvmAddress, isSolanaAddress } from "./chain";
|
|
6
|
-
import { getNetworkInfoByName, getNetworkTypeByName, getShowTokenList } from "./network";
|
|
7
|
-
import { chainAddressValidator, checkFileExistence, inputSomething, numberValidator, selectSomething } from "./utils";
|
|
8
|
-
import { deleteTokenBalance, getTokenBalance, getTokenBalanceInEvm, getTokenBalanceInSolana, getTokenInfoInEvm, getTokenInfoInSolana, updateBalance, batchUpdateUserTokenBalance } from './web3';
|
|
9
|
-
import inquirer from "inquirer";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
// symbol; name; address; decimals
|
|
13
|
-
export const getAssetList = async (
|
|
14
|
-
keystore_path: string,
|
|
15
|
-
chain_id: string
|
|
16
|
-
) => {
|
|
17
|
-
let json_data_path = path.join(keystore_path, `assets.json`);
|
|
18
|
-
|
|
19
|
-
if (!checkFileExistence(json_data_path)) {
|
|
20
|
-
return [];
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const json_string = fs.readFileSync(json_data_path).toString();
|
|
24
|
-
const assets_mapping = JSON.parse(json_string);
|
|
25
|
-
if (chain_id in assets_mapping) {
|
|
26
|
-
return assets_mapping[chain_id];
|
|
27
|
-
}
|
|
28
|
-
return [];
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export const getAssetListByTokenName = async (
|
|
32
|
-
keystore_path: string,
|
|
33
|
-
chain_id: string,
|
|
34
|
-
token_name: string
|
|
35
|
-
) => {
|
|
36
|
-
const asset_list = await getAssetList(keystore_path, chain_id);
|
|
37
|
-
let token_address_list: any = [];
|
|
38
|
-
for (let i = 0; i < asset_list.length; i++) {
|
|
39
|
-
if (asset_list[i].symbol.toLocaleLowerCase() === token_name.toLocaleLowerCase()) {
|
|
40
|
-
token_address_list.push(asset_list[i]);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return token_address_list;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export const showAssetsDetail = async (
|
|
47
|
-
keystore_path: string,
|
|
48
|
-
default_network: string,
|
|
49
|
-
account_address: string
|
|
50
|
-
) => {
|
|
51
|
-
const network_info = getNetworkInfoByName(keystore_path, default_network);
|
|
52
|
-
const network_type = getChainType(network_info.chainId.toString());
|
|
53
|
-
const asset_list = await getAssetList(keystore_path, network_info.chainId.toString());
|
|
54
|
-
if (!asset_list) {
|
|
55
|
-
console.log(chalk.red("No asset found"));
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const token_balance = await batchGetTokenBalance(
|
|
60
|
-
account_address,
|
|
61
|
-
asset_list,
|
|
62
|
-
network_info.rpcUrl,
|
|
63
|
-
network_type,
|
|
64
|
-
network_info.chainId.toString()
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
let asset_id = 1;
|
|
68
|
-
for (let i = 0; i < token_balance.length; i++) {
|
|
69
|
-
if (token_balance[i].balance === "0" || token_balance[i].balance === "0.0000") {
|
|
70
|
-
continue;
|
|
71
|
-
}
|
|
72
|
-
console.log(
|
|
73
|
-
chalk.green(
|
|
74
|
-
`${asset_id}. ${token_balance[i].symbol} Balance: ${token_balance[i].balance}`
|
|
75
|
-
)
|
|
76
|
-
)
|
|
77
|
-
asset_id += 1;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (asset_id === 1) {
|
|
81
|
-
console.log(chalk.red("No asset found"));
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export const updateTokenBalanceOption = async (
|
|
86
|
-
keystore_path: string,
|
|
87
|
-
default_network: string,
|
|
88
|
-
account_address: string
|
|
89
|
-
) => {
|
|
90
|
-
const network_info = getNetworkInfoByName(keystore_path, default_network);
|
|
91
|
-
let asset_info_list = await getAssetList(keystore_path, network_info.chainId.toString());
|
|
92
|
-
let token_list_addrs = asset_info_list.map((item: any) => item.address);
|
|
93
|
-
token_list_addrs.push("0");
|
|
94
|
-
deleteTokenBalance(network_info.chainId.toString(), [account_address], token_list_addrs);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export const saveAsset = async (
|
|
98
|
-
keystore_path: string,
|
|
99
|
-
chain_id: string,
|
|
100
|
-
asset_address: string,
|
|
101
|
-
symbol: string,
|
|
102
|
-
name: string,
|
|
103
|
-
decimals: number,
|
|
104
|
-
display_decimals: number
|
|
105
|
-
) => {
|
|
106
|
-
let json_data_path = path.join(keystore_path, `assets.json`);
|
|
107
|
-
let assets_mapping: any = {};
|
|
108
|
-
if (checkFileExistence(json_data_path)) {
|
|
109
|
-
const json_string = fs.readFileSync(json_data_path).toString();
|
|
110
|
-
assets_mapping = JSON.parse(json_string);
|
|
111
|
-
}
|
|
112
|
-
if (assets_mapping[chain_id] === undefined) {
|
|
113
|
-
assets_mapping[chain_id] = [];
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
for (let i = 0; i < assets_mapping[chain_id].length; i++) {
|
|
117
|
-
if (
|
|
118
|
-
assets_mapping[chain_id][i].address.toLocaleLowerCase() === asset_address.toLocaleLowerCase() ||
|
|
119
|
-
assets_mapping[chain_id][i].symbol.toLocaleLowerCase() === symbol.toLocaleLowerCase()
|
|
120
|
-
) {
|
|
121
|
-
assets_mapping[chain_id][i] = {
|
|
122
|
-
address: asset_address,
|
|
123
|
-
symbol,
|
|
124
|
-
name,
|
|
125
|
-
decimals,
|
|
126
|
-
display_decimals
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
fs.writeFileSync(json_data_path, JSON.stringify(assets_mapping, null, 4));
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
assets_mapping[chain_id].push({
|
|
135
|
-
address: asset_address,
|
|
136
|
-
symbol,
|
|
137
|
-
name,
|
|
138
|
-
decimals,
|
|
139
|
-
display_decimals
|
|
140
|
-
});
|
|
141
|
-
fs.writeFileSync(json_data_path, JSON.stringify(assets_mapping, null, 4));
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
export const addToken = async (
|
|
145
|
-
keystore_path: string,
|
|
146
|
-
) => {
|
|
147
|
-
const network_path = path.resolve(keystore_path, 'network.json');
|
|
148
|
-
const networks = JSON.parse(fs.readFileSync(network_path, 'utf8'));
|
|
149
|
-
|
|
150
|
-
let options: any = [];
|
|
151
|
-
let network_list = networks.networks;
|
|
152
|
-
for (let i = 0; i < network_list.length; i++) {
|
|
153
|
-
options.push(`${i + 1}. ${network_list[i].name}`);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
let selected_option = await selectSomething(options);
|
|
157
|
-
let network_name = selected_option.split(".")[1].trim();
|
|
158
|
-
const network_type = getNetworkTypeByName(keystore_path, network_name);
|
|
159
|
-
const network_info = getNetworkInfoByName(keystore_path, network_name);
|
|
160
|
-
|
|
161
|
-
const token_address = await inputSomething("Enter contract address", chainAddressValidator);
|
|
162
|
-
|
|
163
|
-
let token_info_result: any;
|
|
164
|
-
if (network_type === "evm") {
|
|
165
|
-
if (!isEvmAddress(token_address)) {
|
|
166
|
-
console.log(chalk.red("evm address format error"));
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
169
|
-
token_info_result = await getTokenInfoInEvm(token_address, network_info.rpcUrl);
|
|
170
|
-
} else {
|
|
171
|
-
if (!isSolanaAddress(token_address)) {
|
|
172
|
-
console.log(chalk.red("solana address format error"));
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
token_info_result = await getTokenInfoInSolana(token_address, network_info.rpcUrl);
|
|
176
|
-
}
|
|
177
|
-
if (!token_info_result.status) {
|
|
178
|
-
console.log(chalk.red(token_info_result.output));
|
|
179
|
-
return;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
if (!token_info_result.output.name) {
|
|
183
|
-
token_info_result.output.name = await inputSomething("Please input token name");
|
|
184
|
-
}
|
|
185
|
-
if (!token_info_result.output.symbol) {
|
|
186
|
-
token_info_result.output.symbol = await inputSomething("Please input token symbol");
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
console.log(
|
|
190
|
-
chalk.green(`Token ${token_info_result.output.symbol}(${token_info_result.output.name}) loaded successfully.`)
|
|
191
|
-
);
|
|
192
|
-
|
|
193
|
-
let display_decimals = await inputSomething("Enter decimals for display", numberValidator);
|
|
194
|
-
display_decimals = parseInt(display_decimals);
|
|
195
|
-
await saveAsset(
|
|
196
|
-
keystore_path,
|
|
197
|
-
network_info.chainId.toString(),
|
|
198
|
-
token_address,
|
|
199
|
-
token_info_result.output.symbol,
|
|
200
|
-
token_info_result.output.name,
|
|
201
|
-
token_info_result.output.decimals,
|
|
202
|
-
display_decimals
|
|
203
|
-
);
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
export const addAsset = async (
|
|
207
|
-
keystore_path: string,
|
|
208
|
-
default_network: string
|
|
209
|
-
) => {
|
|
210
|
-
const network_type = getNetworkTypeByName(keystore_path, default_network);
|
|
211
|
-
const network_info = getNetworkInfoByName(keystore_path, default_network);
|
|
212
|
-
|
|
213
|
-
const token_address = await inputSomething("Enter contract address", chainAddressValidator);
|
|
214
|
-
|
|
215
|
-
let token_info_result: any;
|
|
216
|
-
if (network_type === "evm") {
|
|
217
|
-
if (!isEvmAddress(token_address)) {
|
|
218
|
-
console.log(chalk.red("evm address format error"));
|
|
219
|
-
return;
|
|
220
|
-
}
|
|
221
|
-
token_info_result = await getTokenInfoInEvm(token_address, network_info.rpcUrl);
|
|
222
|
-
} else {
|
|
223
|
-
if (!isSolanaAddress(token_address)) {
|
|
224
|
-
console.log(chalk.red("solana address format error"));
|
|
225
|
-
return;
|
|
226
|
-
}
|
|
227
|
-
token_info_result = await getTokenInfoInSolana(token_address, network_info.rpcUrl);
|
|
228
|
-
}
|
|
229
|
-
if (!token_info_result.status) {
|
|
230
|
-
console.log(chalk.red(token_info_result.output));
|
|
231
|
-
return;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
if (!token_info_result.output.name) {
|
|
235
|
-
token_info_result.output.name = await inputSomething("Please input token name");
|
|
236
|
-
}
|
|
237
|
-
if (!token_info_result.output.symbol) {
|
|
238
|
-
token_info_result.output.symbol = await inputSomething("Please input token symbol");
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
console.log(
|
|
242
|
-
chalk.green(`Token ${token_info_result.output.symbol}(${token_info_result.output.name}) loaded successfully.`)
|
|
243
|
-
);
|
|
244
|
-
|
|
245
|
-
let display_decimals = await inputSomething("Enter decimals for display", numberValidator);
|
|
246
|
-
display_decimals = parseInt(display_decimals);
|
|
247
|
-
await saveAsset(
|
|
248
|
-
keystore_path,
|
|
249
|
-
network_info.chainId.toString(),
|
|
250
|
-
token_address,
|
|
251
|
-
token_info_result.output.symbol,
|
|
252
|
-
token_info_result.output.name,
|
|
253
|
-
token_info_result.output.decimals,
|
|
254
|
-
display_decimals
|
|
255
|
-
);
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
export const showAssets = async (
|
|
259
|
-
keystore_path: string,
|
|
260
|
-
account_address: string,
|
|
261
|
-
default_network: string
|
|
262
|
-
) => {
|
|
263
|
-
const options_assets_list = [
|
|
264
|
-
'> Show Assets',
|
|
265
|
-
'> Add Asset',
|
|
266
|
-
new inquirer.Separator('----------------------------------'),
|
|
267
|
-
'> Back'
|
|
268
|
-
];
|
|
269
|
-
|
|
270
|
-
const selected_option = await selectSomething(options_assets_list);
|
|
271
|
-
switch (selected_option) {
|
|
272
|
-
case '> Show Assets': {
|
|
273
|
-
await showAssetsDetail(keystore_path, default_network, account_address);
|
|
274
|
-
break;
|
|
275
|
-
}
|
|
276
|
-
case '> Add Asset': {
|
|
277
|
-
await addAsset(keystore_path, default_network);
|
|
278
|
-
break;
|
|
279
|
-
}
|
|
280
|
-
case '> Back': {
|
|
281
|
-
return;
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
await showAssets(keystore_path, account_address, default_network);
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
export const batchGetTokenBalance = async (
|
|
289
|
-
account_address: string,
|
|
290
|
-
asset_info_list: any,
|
|
291
|
-
rpc_url: string,
|
|
292
|
-
chain_type: string,
|
|
293
|
-
chain_id: string
|
|
294
|
-
) => {
|
|
295
|
-
let asset_list_len = asset_info_list.length;
|
|
296
|
-
let promise_list: any = [];
|
|
297
|
-
for (let i = 0; i < asset_list_len; i++) {
|
|
298
|
-
let asset_info = asset_info_list[i];
|
|
299
|
-
if (chain_type === "evm") {
|
|
300
|
-
promise_list.push(getTokenBalanceInEvm(account_address, asset_info.address, rpc_url));
|
|
301
|
-
} else if (chain_type === "solana") {
|
|
302
|
-
promise_list.push(getTokenBalanceInSolana(account_address, asset_info.address, rpc_url));
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
let result = await Promise.all(promise_list);
|
|
307
|
-
let asset_balance_info_list: any = [];
|
|
308
|
-
for (let i = 0; i < asset_list_len; i++) {
|
|
309
|
-
let asset_info = asset_info_list[i];
|
|
310
|
-
let decimals = asset_info.decimals;
|
|
311
|
-
if (!result[i].status) {
|
|
312
|
-
console.log(
|
|
313
|
-
chalk.red(result[i].output)
|
|
314
|
-
)
|
|
315
|
-
return null;
|
|
316
|
-
}
|
|
317
|
-
let balance = new BigNumber(result[i].output);
|
|
318
|
-
let asset_balance = balance.dividedBy(Math.pow(10, decimals)).toFixed(4, BigNumber.ROUND_FLOOR);
|
|
319
|
-
|
|
320
|
-
asset_balance_info_list.push({
|
|
321
|
-
address: asset_info.address,
|
|
322
|
-
symbol: asset_info.symbol,
|
|
323
|
-
balance: asset_balance
|
|
324
|
-
});
|
|
325
|
-
deleteTokenBalance(
|
|
326
|
-
chain_id,
|
|
327
|
-
[
|
|
328
|
-
account_address
|
|
329
|
-
],
|
|
330
|
-
[
|
|
331
|
-
asset_info.address
|
|
332
|
-
]
|
|
333
|
-
);
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
deleteTokenBalance(
|
|
337
|
-
chain_id,
|
|
338
|
-
[
|
|
339
|
-
account_address
|
|
340
|
-
],
|
|
341
|
-
[
|
|
342
|
-
"0"
|
|
343
|
-
]
|
|
344
|
-
);
|
|
345
|
-
return asset_balance_info_list;
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
export const getBatchAccountBalance = async (
|
|
349
|
-
keystore_path: string,
|
|
350
|
-
account_address_list: string[],
|
|
351
|
-
asset_info_list: any,
|
|
352
|
-
rpc_url: string,
|
|
353
|
-
network_name: string,
|
|
354
|
-
show_gas_token: boolean,
|
|
355
|
-
show_extended_token: boolean,
|
|
356
|
-
) => {
|
|
357
|
-
let asset_info_list_len = asset_info_list.length;
|
|
358
|
-
|
|
359
|
-
let network_info = getNetworkInfoByName(keystore_path, network_name);
|
|
360
|
-
let chain_type = getChainType(network_info.chainId.toString());
|
|
361
|
-
let is_evm = chain_type === "evm";
|
|
362
|
-
if (show_gas_token) {
|
|
363
|
-
await updateBalance(
|
|
364
|
-
account_address_list,
|
|
365
|
-
"0",
|
|
366
|
-
network_info.chainId.toString(),
|
|
367
|
-
rpc_url,
|
|
368
|
-
is_evm
|
|
369
|
-
);
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
if (show_extended_token) {
|
|
373
|
-
let showTokenList = getShowTokenList(keystore_path, network_name);
|
|
374
|
-
|
|
375
|
-
for (let i = 0; i < asset_info_list_len; i++) {
|
|
376
|
-
let asset_info = asset_info_list[i];
|
|
377
|
-
let token_address = asset_info.address;
|
|
378
|
-
if (!showTokenList.includes(token_address)) {
|
|
379
|
-
continue;
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
await updateBalance(
|
|
383
|
-
account_address_list,
|
|
384
|
-
token_address,
|
|
385
|
-
network_info.chainId.toString(),
|
|
386
|
-
rpc_url,
|
|
387
|
-
is_evm
|
|
388
|
-
);
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
let batchAccountBalanceOf: any = getTokenBalance(
|
|
392
|
-
network_info.chainId.toString(),
|
|
393
|
-
account_address_list,
|
|
394
|
-
asset_info_list,
|
|
395
|
-
network_info
|
|
396
|
-
);
|
|
397
|
-
|
|
398
|
-
return batchAccountBalanceOf;
|
|
399
|
-
}
|
package/src/chain.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
// 901: mainnet 902: testnet 903: devnet
|
|
2
|
-
export const SOLANA_CHAIN_IDS = ["901", "902", "903"];
|
|
3
|
-
|
|
4
|
-
export const getNativeTokenDecimals = (chain_id: string) => {
|
|
5
|
-
if (SOLANA_CHAIN_IDS.includes(chain_id)) {
|
|
6
|
-
return 9;
|
|
7
|
-
} else {
|
|
8
|
-
return 18;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export const getChainType = (chain_id: string) => {
|
|
13
|
-
if (SOLANA_CHAIN_IDS.includes(chain_id)) {
|
|
14
|
-
return "solana";
|
|
15
|
-
} else {
|
|
16
|
-
return "evm";
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export const isSolanaAddress = (account_address: string) => {
|
|
21
|
-
let is_solana_address = /^[A-HJ-NP-Za-km-z1-9]*$/.test(account_address);
|
|
22
|
-
return is_solana_address;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export const isEvmAddress = (account_address: string) => {
|
|
26
|
-
let is_evm_address = account_address.startsWith("0x") && account_address.length === 42;
|
|
27
|
-
return is_evm_address;
|
|
28
|
-
}
|