wative 1.0.15 → 1.0.17
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/index.esm.js +1 -1
- package/lib/index.umd.js +1 -1
- package/package.json +1 -1
- package/src/account.ts +1 -1
- package/src/network.ts +2 -2
- package/src/tools.ts +86 -49
package/src/tools.ts
CHANGED
|
@@ -90,31 +90,38 @@ const sendEvmRawTransaction = async (chain_id: string, chain_rpc_url: string, ch
|
|
|
90
90
|
}
|
|
91
91
|
let account_balance = new BigNumber(account_balance_result.output);
|
|
92
92
|
let tx_gas_price = new BigNumber(gasPrice);
|
|
93
|
-
let
|
|
94
|
-
let total_balance = (new BigNumber(
|
|
93
|
+
let max_value = account_balance.minus(tx_gas_price.multipliedBy(21000)).toFixed(0, BigNumber.ROUND_FLOOR);
|
|
94
|
+
let total_balance = (new BigNumber(max_value)).dividedBy(1e18).toFixed(4, BigNumber.ROUND_FLOOR);
|
|
95
95
|
|
|
96
96
|
if (new BigNumber(total_balance) < new BigNumber(0)) {
|
|
97
97
|
console.log(chalk.red("Not enough balance"));
|
|
98
98
|
return
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
if (vaule_id === 0) {
|
|
108
|
-
let input_value = await inputSomething("value", numberValidator);
|
|
109
|
-
value = new BigNumber(input_value).multipliedBy(1e18).toFixed(0, BigNumber.ROUND_FLOOR);
|
|
110
|
-
} else if (vaule_id === 1) {
|
|
111
|
-
value = max_vaule;
|
|
112
|
-
}
|
|
101
|
+
value = await getTransferValue(
|
|
102
|
+
total_balance,
|
|
103
|
+
max_value,
|
|
104
|
+
chain_symbols,
|
|
105
|
+
18
|
|
106
|
+
);
|
|
113
107
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
108
|
+
// let option_select_value_list: any = [
|
|
109
|
+
// '> Input value',
|
|
110
|
+
// `> Total Balance (${total_balance} ${chain_symbols})`
|
|
111
|
+
// ]
|
|
112
|
+
// let selected_value = await selectSomething(option_select_value_list);
|
|
113
|
+
// let value_id = option_select_value_list.indexOf(selected_value);
|
|
114
|
+
// if (value_id === 0) {
|
|
115
|
+
// let input_value = await inputSomething("value", numberValidator);
|
|
116
|
+
// value = new BigNumber(input_value).multipliedBy(1e18).toFixed(0, BigNumber.ROUND_FLOOR);
|
|
117
|
+
// } else if (value_id === 1) {
|
|
118
|
+
// value = max_value;
|
|
119
|
+
// }
|
|
120
|
+
|
|
121
|
+
// if ((new BigNumber(value)).isGreaterThan(new BigNumber(max_value))) {
|
|
122
|
+
// console.log(chalk.red("Not enough balance"));
|
|
123
|
+
// return;
|
|
124
|
+
// }
|
|
118
125
|
} else {
|
|
119
126
|
data = await editorSomething("data", hexValidator);
|
|
120
127
|
value = await inputSomething("value", numberValidator);
|
|
@@ -159,12 +166,10 @@ const sendEvmRawTransaction = async (chain_id: string, chain_rpc_url: string, ch
|
|
|
159
166
|
console.log(chalk.red(signed_message_result.output));
|
|
160
167
|
return;
|
|
161
168
|
}
|
|
162
|
-
let transaction_receipt_result = await wative_core.account.sendSignedTransaction(account_address, signed_message_result.output.rawTransaction, chain_rpc_url);
|
|
163
|
-
if (!transaction_receipt_result.status) {
|
|
164
|
-
console.log(chalk.red(transaction_receipt_result.output));
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
169
|
|
|
170
|
+
console.log(chalk.green(`Transaction hash: ${signed_message_result.output.transactionHash}`));
|
|
171
|
+
|
|
172
|
+
wative_core.account.sendSignedTransaction(account_address, signed_message_result.output.rawTransaction, chain_rpc_url);
|
|
168
173
|
deleteTokenBalance(
|
|
169
174
|
chain_id,
|
|
170
175
|
[
|
|
@@ -175,7 +180,6 @@ const sendEvmRawTransaction = async (chain_id: string, chain_rpc_url: string, ch
|
|
|
175
180
|
"0"
|
|
176
181
|
]
|
|
177
182
|
);
|
|
178
|
-
console.log(chalk.green(`Transaction hash: ${transaction_receipt_result.output.transactionHash}`));
|
|
179
183
|
}
|
|
180
184
|
|
|
181
185
|
export const sendSolanaRawTransaction = async (chain_id: string, chain_rpc_url: string, chain_symbols: string, account_address: string, wative_core: typeof WativeCore) => {
|
|
@@ -197,6 +201,7 @@ export const sendSolanaRawTransaction = async (chain_id: string, chain_rpc_url:
|
|
|
197
201
|
})
|
|
198
202
|
);
|
|
199
203
|
|
|
204
|
+
transaction.feePayer = new PublicKey(account_address);
|
|
200
205
|
const simulate_result = await wative_core.account.simulateTransaction(
|
|
201
206
|
account_address,
|
|
202
207
|
chain_rpc_url,
|
|
@@ -230,30 +235,36 @@ export const sendSolanaRawTransaction = async (chain_id: string, chain_rpc_url:
|
|
|
230
235
|
}
|
|
231
236
|
|
|
232
237
|
const account_balance = new BigNumber(account_balance_result.output);
|
|
233
|
-
const
|
|
234
|
-
let total_balance = (new BigNumber(
|
|
238
|
+
const max_value = account_balance.minus(5000).minus(used_prioritization_fee);
|
|
239
|
+
let total_balance = (new BigNumber(max_value)).dividedBy(1e9).toFixed(4, BigNumber.ROUND_FLOOR);
|
|
235
240
|
if (new BigNumber(total_balance) < new BigNumber(0)) {
|
|
236
241
|
console.log(chalk.red("Not enough balance"));
|
|
237
242
|
return
|
|
238
243
|
}
|
|
239
244
|
|
|
240
|
-
let
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
let
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
245
|
+
let transfer_amount = await getTransferValue(
|
|
246
|
+
total_balance,
|
|
247
|
+
max_value.toString(),
|
|
248
|
+
chain_symbols,
|
|
249
|
+
9
|
|
250
|
+
);
|
|
251
|
+
// let option_select_value_list: any = [
|
|
252
|
+
// '> Input value',
|
|
253
|
+
// `> Total Balance (${total_balance} ${chain_symbols})`
|
|
254
|
+
// ]
|
|
255
|
+
// let selected_value = await selectSomething(option_select_value_list);
|
|
256
|
+
// let value_id = option_select_value_list.indexOf(selected_value);
|
|
257
|
+
// let transfer_amount: string = "0";
|
|
258
|
+
// if (value_id === 0) {
|
|
259
|
+
// let input_value = await inputSomething("value", numberValidator);
|
|
260
|
+
// transfer_amount = new BigNumber(input_value).multipliedBy(1e9).toFixed(0, BigNumber.ROUND_FLOOR);
|
|
261
|
+
// if ((new BigNumber(transfer_amount)).isGreaterThan(new BigNumber(max_value))) {
|
|
262
|
+
// console.log(chalk.red("Not enough balance"));
|
|
263
|
+
// return;
|
|
264
|
+
// }
|
|
265
|
+
// } else if (value_id === 1) {
|
|
266
|
+
// transfer_amount = max_value.toString();
|
|
267
|
+
// }
|
|
257
268
|
|
|
258
269
|
let transactions = new Transaction();
|
|
259
270
|
transactions.add(
|
|
@@ -272,6 +283,8 @@ export const sendSolanaRawTransaction = async (chain_id: string, chain_rpc_url:
|
|
|
272
283
|
lamports: Number(transfer_amount)
|
|
273
284
|
}));
|
|
274
285
|
|
|
286
|
+
transaction.feePayer = new PublicKey(account_address);
|
|
287
|
+
|
|
275
288
|
const signed_message_result = await wative_core.account.signTransaction(
|
|
276
289
|
account_address,
|
|
277
290
|
transactions,
|
|
@@ -301,6 +314,30 @@ export const sendSolanaRawTransaction = async (chain_id: string, chain_rpc_url:
|
|
|
301
314
|
console.log(chalk.green(`Transaction hash: ${transaction_receipt_result.output}`));
|
|
302
315
|
}
|
|
303
316
|
|
|
317
|
+
|
|
318
|
+
const getTransferValue = async (total_balance: string, max_value: string, chain_symbols: string, decimals: number): Promise<string> => {
|
|
319
|
+
let option_select_value_list: any = [
|
|
320
|
+
'> Input value',
|
|
321
|
+
`> Total Balance (${total_balance} ${chain_symbols})`
|
|
322
|
+
]
|
|
323
|
+
let selected_value = await selectSomething(option_select_value_list);
|
|
324
|
+
let value_id = option_select_value_list.indexOf(selected_value);
|
|
325
|
+
let value = "0";
|
|
326
|
+
if (value_id === 0) {
|
|
327
|
+
let input_value = await inputSomething("value", numberValidator);
|
|
328
|
+
value = new BigNumber(input_value).multipliedBy(10 ** decimals).toFixed(0, BigNumber.ROUND_FLOOR);
|
|
329
|
+
} else if (value_id === 1) {
|
|
330
|
+
value = max_value;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
if ((new BigNumber(value)).isLessThanOrEqualTo(new BigNumber(max_value))) {
|
|
334
|
+
return value;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
console.log(chalk.red("Not enough balance"));
|
|
338
|
+
return getTransferValue(total_balance, max_value, chain_symbols, decimals);
|
|
339
|
+
}
|
|
340
|
+
|
|
304
341
|
const sendEvmTokenTransaction = async (keystore_path: string, chain_rpc_url: string, chain_id: string, account_address: string, wative_core: typeof WativeCore) => {
|
|
305
342
|
const option_token_address_list = [
|
|
306
343
|
'> Input token ticker',
|
|
@@ -413,11 +450,9 @@ const sendEvmTokenTransaction = async (keystore_path: string, chain_rpc_url: str
|
|
|
413
450
|
console.log(chalk.red(signed_message_result.output));
|
|
414
451
|
return;
|
|
415
452
|
}
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
return;
|
|
420
|
-
}
|
|
453
|
+
|
|
454
|
+
console.log(chalk.green(`Transaction hash: ${signed_message_result.output.transactionHash}`));
|
|
455
|
+
wative_core.account.sendSignedTransaction(account_address, signed_message_result.output.rawTransaction, chain_rpc_url);
|
|
421
456
|
|
|
422
457
|
deleteTokenBalance(
|
|
423
458
|
chain_id,
|
|
@@ -430,7 +465,6 @@ const sendEvmTokenTransaction = async (keystore_path: string, chain_rpc_url: str
|
|
|
430
465
|
token_address
|
|
431
466
|
]
|
|
432
467
|
);
|
|
433
|
-
console.log(chalk.green(`Transaction hash: ${transaction_receipt_result.output.transactionHash}`));
|
|
434
468
|
}
|
|
435
469
|
|
|
436
470
|
const sendSolanaTokenTransaction = async (keystore_path: string, chain_rpc_url: string, chain_id: string, account_address: string, wative_core: typeof WativeCore) => {
|
|
@@ -565,6 +599,8 @@ const sendSolanaTokenTransaction = async (keystore_path: string, chain_rpc_url:
|
|
|
565
599
|
})
|
|
566
600
|
);
|
|
567
601
|
|
|
602
|
+
transaction.feePayer = new PublicKey(account_address);
|
|
603
|
+
|
|
568
604
|
const simulate_result = await wative_core.account.simulateTransaction(
|
|
569
605
|
account_address,
|
|
570
606
|
chain_rpc_url,
|
|
@@ -611,6 +647,7 @@ const sendSolanaTokenTransaction = async (keystore_path: string, chain_rpc_url:
|
|
|
611
647
|
})
|
|
612
648
|
);
|
|
613
649
|
|
|
650
|
+
transaction.feePayer = new PublicKey(account_address);
|
|
614
651
|
const signed_message_result = await wative_core.account.signTransaction(
|
|
615
652
|
account_address,
|
|
616
653
|
transactions,
|