@pioneer-platform/eth-network 8.1.68 → 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.
Files changed (2) hide show
  1. package/lib/index.js +197 -26
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -361,17 +361,126 @@ var check_airdrop_claim = function (address) {
361
361
  });
362
362
  });
363
363
  };
364
- //get_token_transfer_data
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
+ // }
365
474
  var get_token_transfer_data = function (toAddress, amount, contract) {
366
475
  return __awaiter(this, void 0, void 0, function () {
367
- var tag, minABI, newContract, decimals, value, tokenData, e_4;
476
+ var tag, minABI, newContract, decimalPlaces, amountInSmallestUnit, amountHex, amountHexPadded, tokenData, e_4;
368
477
  return __generator(this, function (_a) {
369
478
  switch (_a.label) {
370
479
  case 0:
371
480
  tag = TAG + " | get_token_transfer_data | ";
372
481
  _a.label = 1;
373
482
  case 1:
374
- _a.trys.push([1, 4, , 5]);
483
+ _a.trys.push([1, 3, , 4]);
375
484
  minABI = [
376
485
  // balanceOf
377
486
  {
@@ -393,36 +502,98 @@ var get_token_transfer_data = function (toAddress, amount, contract) {
393
502
  newContract = new web3.eth.Contract(minABI, contract);
394
503
  return [4 /*yield*/, newContract.methods.decimals().call()];
395
504
  case 2:
396
- decimals = _a.sent();
397
- value = web3.utils.toBN(amount).mul(web3.utils.toBN(10).pow(web3.utils.toBN(decimals)));
398
- log.info(tag, "value: ", value.toString());
399
- log.info(tag, "value: ", value);
400
- return [4 /*yield*/, web3.eth.abi.encodeFunctionCall({
401
- name: 'transfer',
402
- type: 'function',
403
- inputs: [
404
- {
405
- type: 'address',
406
- name: '_to'
407
- },
408
- {
409
- type: 'uint256',
410
- name: '_value'
411
- }
412
- ]
413
- }, [toAddress, value])];
414
- case 3:
415
- tokenData = _a.sent();
505
+ decimalPlaces = _a.sent();
506
+ amountInSmallestUnit = web3.utils.toBN(parseFloat(amount) * Math.pow(10, decimalPlaces));
507
+ amountHex = amountInSmallestUnit.toString(16);
508
+ amountHexPadded = amountHex.padStart(64, '0');
509
+ tokenData = web3.eth.abi.encodeFunctionCall({
510
+ name: 'transfer',
511
+ type: 'function',
512
+ inputs: [
513
+ {
514
+ type: 'address',
515
+ name: '_to'
516
+ },
517
+ {
518
+ type: 'uint256',
519
+ name: '_value'
520
+ }
521
+ ]
522
+ }, [toAddress, amountInSmallestUnit.toString()]);
416
523
  return [2 /*return*/, tokenData];
417
- case 4:
524
+ case 3:
418
525
  e_4 = _a.sent();
419
526
  console.error(tag, e_4);
420
- return [3 /*break*/, 5];
421
- case 5: return [2 /*return*/];
527
+ return [3 /*break*/, 4];
528
+ case 4: return [2 /*return*/];
422
529
  }
423
530
  });
424
531
  });
425
532
  };
533
+ // //get_token_transfer_data
534
+ // const get_token_transfer_data = async function(toAddress:string, amount:string, contract:string){
535
+ // let tag = TAG + " | get_token_transfer_data | "
536
+ // try{
537
+ //
538
+ // let minABI = [
539
+ // // balanceOf
540
+ // {
541
+ // "constant": true,
542
+ // "inputs": [{ "name": "_owner", "type": "address" }],
543
+ // "name": "balanceOf",
544
+ // "outputs": [{ "name": "balance", "type": "uint256" }],
545
+ // "type": "function"
546
+ // },
547
+ // // decimals
548
+ // {
549
+ // "constant": true,
550
+ // "inputs": [],
551
+ // "name": "decimals",
552
+ // "outputs": [{ "name": "", "type": "uint8" }],
553
+ // "type": "function"
554
+ // }
555
+ // ];
556
+ // const newContract = new web3.eth.Contract(minABI, contract);
557
+ // const decimalPlaces = await newContract.methods.decimals().call();
558
+ // //
559
+ // // // @ts-ignore
560
+ // // let value = parseInt(amount/Math.pow(10, decimals))
561
+ // // //const adjustedValue = value.mul(web3.utils.toBN(10).pow(web3.utils.toBN(decimals)));
562
+ // //
563
+ // // log.info(tag, "adjustedValue: ", value.toString());
564
+ //
565
+ // // Calculate the amount in the token's smallest unit
566
+ // const amountInWei = web3.utils.toWei(amount, 'ether');
567
+ // const decimals = web3.utils.toBN(decimalPlaces);
568
+ // const amountInSmallestUnit = web3.utils.toBN(amountInWei).mul(web3.utils.toBN(10).pow(decimals));
569
+ //
570
+ // // Convert the amount to a hexadecimal string
571
+ // const amountHex = amountInSmallestUnit.toString(16);
572
+ //
573
+ // // Pad the hexadecimal string with zeros to 64 characters
574
+ // const amountHexPadded = amountHex.padStart(64, '0');
575
+ //
576
+ // //parse to prescision?
577
+ // let tokenData = await web3.eth.abi.encodeFunctionCall({
578
+ // name: 'transfer',
579
+ // type: 'function',
580
+ // inputs: [
581
+ // {
582
+ // type: 'address',
583
+ // name: '_to'
584
+ // },
585
+ // {
586
+ // type: 'uint256',
587
+ // name: '_value'
588
+ // }
589
+ // ]
590
+ // }, [toAddress, amountInSmallestUnit]);
591
+ //
592
+ // return tokenData
593
+ // }catch(e){
594
+ // console.error(tag,e)
595
+ // }
596
+ // }
426
597
  var get_symbol_from_contract = function (address) {
427
598
  return __awaiter(this, void 0, void 0, function () {
428
599
  var tag, contract, tokenName, e_5;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pioneer-platform/eth-network",
3
- "version": "8.1.68",
3
+ "version": "8.1.70",
4
4
  "main": "./lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "scripts": {