@pioneer-platform/eth-network 8.1.69 → 8.1.70
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.js +112 -4
- package/package.json +1 -1
package/lib/index.js
CHANGED
@@ -361,9 +361,119 @@ var check_airdrop_claim = function (address) {
|
|
361
361
|
});
|
362
362
|
});
|
363
363
|
};
|
364
|
+
// const get_token_transfer_data = async function(toAddress: string, amount: string, contract: string) {
|
365
|
+
// const tag = TAG + " | get_token_transfer_data | ";
|
366
|
+
// try {
|
367
|
+
// const minABI = [
|
368
|
+
// // balanceOf
|
369
|
+
// {
|
370
|
+
// "constant": true,
|
371
|
+
// "inputs": [{ "name": "_owner", "type": "address" }],
|
372
|
+
// "name": "balanceOf",
|
373
|
+
// "outputs": [{ "name": "balance", "type": "uint256" }],
|
374
|
+
// "type": "function"
|
375
|
+
// },
|
376
|
+
// // decimals
|
377
|
+
// {
|
378
|
+
// "constant": true,
|
379
|
+
// "inputs": [],
|
380
|
+
// "name": "decimals",
|
381
|
+
// "outputs": [{ "name": "", "type": "uint8" }],
|
382
|
+
// "type": "function"
|
383
|
+
// }
|
384
|
+
// ];
|
385
|
+
// const newContract = new web3.eth.Contract(minABI, contract);
|
386
|
+
// const decimalPlaces = await newContract.methods.decimals().call();
|
387
|
+
//
|
388
|
+
// // Convert amount to the appropriate number of decimal places
|
389
|
+
// const amountInSmallestUnit = web3.utils.toBN(amount).mul(web3.utils.toBN(10).pow(decimalPlaces));
|
390
|
+
//
|
391
|
+
// // Convert the amount to a hexadecimal string
|
392
|
+
// const amountHex = amountInSmallestUnit.toString(16);
|
393
|
+
//
|
394
|
+
// // Pad the hexadecimal string with zeros to 64 characters
|
395
|
+
// const amountHexPadded = amountHex.padStart(64, '0');
|
396
|
+
//
|
397
|
+
// // Parse the token data
|
398
|
+
// const tokenData = web3.eth.abi.encodeFunctionCall({
|
399
|
+
// name: 'transfer',
|
400
|
+
// type: 'function',
|
401
|
+
// inputs: [
|
402
|
+
// {
|
403
|
+
// type: 'address',
|
404
|
+
// name: '_to'
|
405
|
+
// },
|
406
|
+
// {
|
407
|
+
// type: 'uint256',
|
408
|
+
// name: '_value'
|
409
|
+
// }
|
410
|
+
// ]
|
411
|
+
// }, [toAddress, amountInSmallestUnit.toString()]);
|
412
|
+
//
|
413
|
+
// return tokenData;
|
414
|
+
// } catch (e) {
|
415
|
+
// console.error(tag, e);
|
416
|
+
// }
|
417
|
+
// }
|
418
|
+
// const get_token_transfer_data = async function(toAddress: string, amount: string, contract: string) {
|
419
|
+
// const tag = TAG + " | get_token_transfer_data | ";
|
420
|
+
// try {
|
421
|
+
// const minABI = [
|
422
|
+
// // balanceOf
|
423
|
+
// {
|
424
|
+
// "constant": true,
|
425
|
+
// "inputs": [{ "name": "_owner", "type": "address" }],
|
426
|
+
// "name": "balanceOf",
|
427
|
+
// "outputs": [{ "name": "balance", "type": "uint256" }],
|
428
|
+
// "type": "function"
|
429
|
+
// },
|
430
|
+
// // decimals
|
431
|
+
// {
|
432
|
+
// "constant": true,
|
433
|
+
// "inputs": [],
|
434
|
+
// "name": "decimals",
|
435
|
+
// "outputs": [{ "name": "", "type": "uint8" }],
|
436
|
+
// "type": "function"
|
437
|
+
// }
|
438
|
+
// ];
|
439
|
+
// const newContract = new web3.eth.Contract(minABI, contract);
|
440
|
+
// const decimalPlaces = await newContract.methods.decimals().call();
|
441
|
+
//
|
442
|
+
// // Convert amount to the appropriate number of decimal places
|
443
|
+
// const amountInWei = web3.utils.toWei(amount, 'ether');
|
444
|
+
// const decimals = web3.utils.toBN(decimalPlaces);
|
445
|
+
// const amountInSmallestUnit = web3.utils.toBN(amountInWei).mul(web3.utils.toBN(10).pow(decimals));
|
446
|
+
//
|
447
|
+
// // Convert the amount to a hexadecimal string
|
448
|
+
// const amountHex = amountInSmallestUnit.toString(16);
|
449
|
+
//
|
450
|
+
// // Pad the hexadecimal string with zeros to 64 characters
|
451
|
+
// const amountHexPadded = amountHex.padStart(64, '0');
|
452
|
+
//
|
453
|
+
// // Parse the token data
|
454
|
+
// const tokenData = web3.eth.abi.encodeFunctionCall({
|
455
|
+
// name: 'transfer',
|
456
|
+
// type: 'function',
|
457
|
+
// inputs: [
|
458
|
+
// {
|
459
|
+
// type: 'address',
|
460
|
+
// name: '_to'
|
461
|
+
// },
|
462
|
+
// {
|
463
|
+
// type: 'uint256',
|
464
|
+
// name: '_value'
|
465
|
+
// }
|
466
|
+
// ]
|
467
|
+
// }, [toAddress, amountInSmallestUnit.toString()]);
|
468
|
+
//
|
469
|
+
// return tokenData;
|
470
|
+
// } catch (e) {
|
471
|
+
// console.error(tag, e);
|
472
|
+
// }
|
473
|
+
// }
|
364
474
|
var get_token_transfer_data = function (toAddress, amount, contract) {
|
365
475
|
return __awaiter(this, void 0, void 0, function () {
|
366
|
-
var tag, minABI, newContract, decimalPlaces,
|
476
|
+
var tag, minABI, newContract, decimalPlaces, amountInSmallestUnit, amountHex, amountHexPadded, tokenData, e_4;
|
367
477
|
return __generator(this, function (_a) {
|
368
478
|
switch (_a.label) {
|
369
479
|
case 0:
|
@@ -393,9 +503,7 @@ var get_token_transfer_data = function (toAddress, amount, contract) {
|
|
393
503
|
return [4 /*yield*/, newContract.methods.decimals().call()];
|
394
504
|
case 2:
|
395
505
|
decimalPlaces = _a.sent();
|
396
|
-
|
397
|
-
decimals = web3.utils.toBN(decimalPlaces);
|
398
|
-
amountInSmallestUnit = web3.utils.toBN(amountInWei).mul(web3.utils.toBN(10).pow(decimals));
|
506
|
+
amountInSmallestUnit = web3.utils.toBN(parseFloat(amount) * Math.pow(10, decimalPlaces));
|
399
507
|
amountHex = amountInSmallestUnit.toString(16);
|
400
508
|
amountHexPadded = amountHex.padStart(64, '0');
|
401
509
|
tokenData = web3.eth.abi.encodeFunctionCall({
|