@pioneer-platform/eth-network 8.1.67 → 8.1.69

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 +89 -25
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -361,17 +361,16 @@ var check_airdrop_claim = function (address) {
361
361
  });
362
362
  });
363
363
  };
364
- //get_token_transfer_data
365
364
  var get_token_transfer_data = function (toAddress, amount, contract) {
366
365
  return __awaiter(this, void 0, void 0, function () {
367
- var tag, minABI, newContract, decimals, value, tokenData, e_4;
366
+ var tag, minABI, newContract, decimalPlaces, amountInWei, decimals, amountInSmallestUnit, amountHex, amountHexPadded, tokenData, e_4;
368
367
  return __generator(this, function (_a) {
369
368
  switch (_a.label) {
370
369
  case 0:
371
370
  tag = TAG + " | get_token_transfer_data | ";
372
371
  _a.label = 1;
373
372
  case 1:
374
- _a.trys.push([1, 4, , 5]);
373
+ _a.trys.push([1, 3, , 4]);
375
374
  minABI = [
376
375
  // balanceOf
377
376
  {
@@ -393,35 +392,100 @@ var get_token_transfer_data = function (toAddress, amount, contract) {
393
392
  newContract = new web3.eth.Contract(minABI, contract);
394
393
  return [4 /*yield*/, newContract.methods.decimals().call()];
395
394
  case 2:
396
- decimals = _a.sent();
397
- value = new BigNumber(amount).times(new BigNumber(10).pow(decimals)).toFixed();
398
- log.info(tag, "value: ", value);
399
- return [4 /*yield*/, web3.eth.abi.encodeFunctionCall({
400
- name: 'transfer',
401
- type: 'function',
402
- inputs: [
403
- {
404
- type: 'address',
405
- name: '_to'
406
- },
407
- {
408
- type: 'uint256',
409
- name: '_value'
410
- }
411
- ]
412
- }, [toAddress, value])];
413
- case 3:
414
- tokenData = _a.sent();
395
+ decimalPlaces = _a.sent();
396
+ amountInWei = web3.utils.toWei(amount, 'ether');
397
+ decimals = web3.utils.toBN(decimalPlaces);
398
+ amountInSmallestUnit = web3.utils.toBN(amountInWei).mul(web3.utils.toBN(10).pow(decimals));
399
+ amountHex = amountInSmallestUnit.toString(16);
400
+ amountHexPadded = amountHex.padStart(64, '0');
401
+ tokenData = web3.eth.abi.encodeFunctionCall({
402
+ name: 'transfer',
403
+ type: 'function',
404
+ inputs: [
405
+ {
406
+ type: 'address',
407
+ name: '_to'
408
+ },
409
+ {
410
+ type: 'uint256',
411
+ name: '_value'
412
+ }
413
+ ]
414
+ }, [toAddress, amountInSmallestUnit.toString()]);
415
415
  return [2 /*return*/, tokenData];
416
- case 4:
416
+ case 3:
417
417
  e_4 = _a.sent();
418
418
  console.error(tag, e_4);
419
- return [3 /*break*/, 5];
420
- case 5: return [2 /*return*/];
419
+ return [3 /*break*/, 4];
420
+ case 4: return [2 /*return*/];
421
421
  }
422
422
  });
423
423
  });
424
424
  };
425
+ // //get_token_transfer_data
426
+ // const get_token_transfer_data = async function(toAddress:string, amount:string, contract:string){
427
+ // let tag = TAG + " | get_token_transfer_data | "
428
+ // try{
429
+ //
430
+ // let minABI = [
431
+ // // balanceOf
432
+ // {
433
+ // "constant": true,
434
+ // "inputs": [{ "name": "_owner", "type": "address" }],
435
+ // "name": "balanceOf",
436
+ // "outputs": [{ "name": "balance", "type": "uint256" }],
437
+ // "type": "function"
438
+ // },
439
+ // // decimals
440
+ // {
441
+ // "constant": true,
442
+ // "inputs": [],
443
+ // "name": "decimals",
444
+ // "outputs": [{ "name": "", "type": "uint8" }],
445
+ // "type": "function"
446
+ // }
447
+ // ];
448
+ // const newContract = new web3.eth.Contract(minABI, contract);
449
+ // const decimalPlaces = await newContract.methods.decimals().call();
450
+ // //
451
+ // // // @ts-ignore
452
+ // // let value = parseInt(amount/Math.pow(10, decimals))
453
+ // // //const adjustedValue = value.mul(web3.utils.toBN(10).pow(web3.utils.toBN(decimals)));
454
+ // //
455
+ // // log.info(tag, "adjustedValue: ", value.toString());
456
+ //
457
+ // // Calculate the amount in the token's smallest unit
458
+ // const amountInWei = web3.utils.toWei(amount, 'ether');
459
+ // const decimals = web3.utils.toBN(decimalPlaces);
460
+ // const amountInSmallestUnit = web3.utils.toBN(amountInWei).mul(web3.utils.toBN(10).pow(decimals));
461
+ //
462
+ // // Convert the amount to a hexadecimal string
463
+ // const amountHex = amountInSmallestUnit.toString(16);
464
+ //
465
+ // // Pad the hexadecimal string with zeros to 64 characters
466
+ // const amountHexPadded = amountHex.padStart(64, '0');
467
+ //
468
+ // //parse to prescision?
469
+ // let tokenData = await web3.eth.abi.encodeFunctionCall({
470
+ // name: 'transfer',
471
+ // type: 'function',
472
+ // inputs: [
473
+ // {
474
+ // type: 'address',
475
+ // name: '_to'
476
+ // },
477
+ // {
478
+ // type: 'uint256',
479
+ // name: '_value'
480
+ // }
481
+ // ]
482
+ // }, [toAddress, amountInSmallestUnit]);
483
+ //
484
+ // return tokenData
485
+ // }catch(e){
486
+ // console.error(tag,e)
487
+ // }
488
+ // }
425
489
  var get_symbol_from_contract = function (address) {
426
490
  return __awaiter(this, void 0, void 0, function () {
427
491
  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.67",
3
+ "version": "8.1.69",
4
4
  "main": "./lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "scripts": {