@pioneer-platform/uniswap-client 0.0.19 → 0.0.21

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 +54 -34
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -94,9 +94,9 @@ module.exports = {
94
94
  return get_quote(quote);
95
95
  },
96
96
  // //buildSwapTx
97
- // buildApprovalTx: function (approval:any) {
98
- // return build_approval_tx(approval);
99
- // },
97
+ buildSwapTx: function (quote, permitSig) {
98
+ return buildSwapTx(quote);
99
+ },
100
100
  // buildApprovalTx: function (approval:any) {
101
101
  // return build_approval_tx(approval);
102
102
  // }
@@ -350,7 +350,7 @@ var getDeadline = function (provider) { return __awaiter(void 0, void 0, void 0,
350
350
  });
351
351
  }); };
352
352
  var buildSwapTx = function (_a) {
353
- var trade = _a.trade, from = _a.from, chainId = _a.chainId, provider = _a.provider;
353
+ var trade = _a.trade, permit = _a.permit, from = _a.from, chainId = _a.chainId, provider = _a.provider;
354
354
  return __awaiter(this, void 0, void 0, function () {
355
355
  var tag, BIPS_BASE, slippageTolerance, deadline, responseRouter, data, value, nonce, gas, estimatedGas, e_2, gasPrice, adjustedGasPrice, tx, e_3;
356
356
  return __generator(this, function (_b) {
@@ -371,11 +371,12 @@ var buildSwapTx = function (_a) {
371
371
  case 2:
372
372
  deadline = _b.sent();
373
373
  log.info(tag, "deadline: ", deadline);
374
+ permit.signature = "0x3e1d72164c5656b61bb438fd0527cf317451d334e54468ab58dfd54eb12cae6f3aafdff7d8f7952e6935a463a7920c1a16298694a976496d40918d718260cc781b";
374
375
  responseRouter = universal_router_sdk_1.SwapRouter.swapERC20CallParameters(trade, {
375
376
  recipient: from,
376
377
  slippageTolerance: slippageTolerance,
377
378
  deadlineOrPreviousBlockhash: deadline,
378
- // inputTokenPermit: options.permit,
379
+ inputTokenPermit: permit,
379
380
  // fee: options.feeOptions,
380
381
  });
381
382
  log.info(tag, "responseRouter: ", responseRouter);
@@ -482,11 +483,11 @@ function toDeadline(expiration) {
482
483
  var build_permit_tx = function (_a) {
483
484
  var from = _a.from, token = _a.token, amount = _a.amount, chainId = _a.chainId;
484
485
  return __awaiter(this, void 0, void 0, function () {
485
- var PERMIT_EXPIRATION, PERMIT_SIG_EXPIRATION, providerUrl, provider, nonce, permit, _b, domain, types, values, tx, e_6;
486
- return __generator(this, function (_c) {
487
- switch (_c.label) {
486
+ var PERMIT_EXPIRATION, PERMIT_SIG_EXPIRATION, providerUrl, provider, nonce, permit, fullResponse, domain, types, values, typedData, tx, e_6;
487
+ return __generator(this, function (_b) {
488
+ switch (_b.label) {
488
489
  case 0:
489
- _c.trys.push([0, 2, , 3]);
490
+ _b.trys.push([0, 2, , 3]);
490
491
  PERMIT_EXPIRATION = 2592000000;
491
492
  PERMIT_SIG_EXPIRATION = 1800000;
492
493
  providerUrl = EIP155_MAINNET_CHAINS['eip155:' + chainId].rpc;
@@ -496,7 +497,7 @@ var build_permit_tx = function (_a) {
496
497
  provider = new ethers.providers.JsonRpcProvider(providerUrl);
497
498
  return [4 /*yield*/, provider.getTransactionCount(from, "latest")];
498
499
  case 1:
499
- nonce = _c.sent();
500
+ nonce = _b.sent();
500
501
  permit = {
501
502
  details: {
502
503
  token: token,
@@ -507,14 +508,31 @@ var build_permit_tx = function (_a) {
507
508
  spender: from,
508
509
  sigDeadline: toDeadline(PERMIT_SIG_EXPIRATION),
509
510
  };
510
- _b = permit2_sdk_1.AllowanceTransfer.getPermitData(permit, permit2_sdk_1.PERMIT2_ADDRESS, chainId), domain = _b.domain, types = _b.types, values = _b.values;
511
+ fullResponse = permit2_sdk_1.AllowanceTransfer.getPermitData(permit, permit2_sdk_1.PERMIT2_ADDRESS, chainId);
512
+ log.info("fullResponse: ", fullResponse);
513
+ domain = fullResponse.domain, types = fullResponse.types, values = fullResponse.values;
514
+ // Ensure 'EIP712Domain' is included in the types definitions
515
+ // If it's not already present or not recognized for some reason, define it explicitly
516
+ if (!types['EIP712Domain']) {
517
+ types['EIP712Domain'] = [
518
+ { name: "name", type: "string" },
519
+ { name: "chainId", type: "uint256" },
520
+ { name: "verifyingContract", type: "address" },
521
+ ];
522
+ }
523
+ typedData = {
524
+ domain: domain,
525
+ types: types,
526
+ message: values, // Use 'values' as the 'message' for EIP712 signing
527
+ primaryType: "PermitSingle" // Assuming 'PermitSingle' as the primaryType based on your types definition
528
+ };
511
529
  tx = {
512
530
  type: 'signTypedData',
513
- txParams: { domain: domain, types: types, values: values }
531
+ txParams: typedData // Ensuring txParams contains the correctly formatted EIP-712 data
514
532
  };
515
533
  return [2 /*return*/, tx];
516
534
  case 2:
517
- e_6 = _c.sent();
535
+ e_6 = _b.sent();
518
536
  console.error(e_6);
519
537
  return [3 /*break*/, 3];
520
538
  case 3: return [2 /*return*/];
@@ -524,14 +542,14 @@ var build_permit_tx = function (_a) {
524
542
  };
525
543
  var get_quote = function (quote) {
526
544
  return __awaiter(this, void 0, void 0, function () {
527
- var tag, output, slippageTolerance, recipient, inputChain, outputChain, providerUrl, chainIdInt, provider, sellTokenContract, buyTokenContract, buyTokenAddress_1, balance, sellTokenAddress_1, permit2, router, planner, sellAmountBigNumber, path, permit2Address, currentAllowance, allowanceTx, formattedAllowanceTx, _a, sellTokenAddress, buyTokenAddress, sellTokenDecimals, _b, buyTokenDecimals, _c, amountInBigNumber, sellToken, buyToken, route, trade, amountOut, tx, tx2, e_7;
545
+ var tag, output, slippageTolerance, recipient, inputChain, outputChain, providerUrl, chainIdInt, provider, sellTokenContract, buyTokenContract, buyTokenAddress_1, balance, sellTokenAddress_1, permit2, router, planner, sellAmountBigNumber, path, permit2Address, currentAllowance, allowanceTx, formattedAllowanceTx, _a, sellTokenAddress, buyTokenAddress, sellTokenDecimals, _b, buyTokenDecimals, _c, amountInBigNumber, sellToken, buyToken, route, trade, amountOut, PERMIT_EXPIRATION, PERMIT_SIG_EXPIRATION, nonce, permit, tx, e_7;
528
546
  return __generator(this, function (_d) {
529
547
  switch (_d.label) {
530
548
  case 0:
531
549
  tag = TAG + " | get_quote | ";
532
550
  _d.label = 1;
533
551
  case 1:
534
- _d.trys.push([1, 15, , 16]);
552
+ _d.trys.push([1, 16, , 17]);
535
553
  output = {};
536
554
  if (!quote.sellAsset)
537
555
  throw new Error("missing sellAsset");
@@ -669,29 +687,31 @@ var get_quote = function (quote) {
669
687
  amountOut = trade.swaps[0].outputAmount;
670
688
  log.info(tag, "amountOut: ", amountOut);
671
689
  output.amountOut = amountOut.toFixed(18);
672
- return [4 /*yield*/, build_permit_tx({
673
- from: quote.senderAddress,
690
+ PERMIT_EXPIRATION = 2592000000;
691
+ PERMIT_SIG_EXPIRATION = 1800000;
692
+ return [4 /*yield*/, provider.getTransactionCount(quote.senderAddress, "latest")];
693
+ case 14:
694
+ nonce = _d.sent();
695
+ permit = {
696
+ details: {
674
697
  token: sellToken.address,
675
698
  amount: "1000000000000000000000000",
676
- chainId: chainIdInt
677
- })
678
- //
679
- ];
680
- case 14:
699
+ expiration: toDeadline(PERMIT_EXPIRATION),
700
+ nonce: nonce,
701
+ },
702
+ spender: quote.senderAddress,
703
+ sigDeadline: toDeadline(PERMIT_SIG_EXPIRATION),
704
+ };
705
+ return [4 /*yield*/, buildSwapTx({ trade: trade, permit: permit, from: quote.senderAddress, chainId: chainIdInt, provider: provider })];
706
+ case 15:
681
707
  tx = _d.sent();
682
- //
683
- output.txs.push(tx);
684
- tx2 = {
708
+ log.info(tag, "tx: ", tx);
709
+ output.txs.push({
685
710
  type: "evm",
686
711
  description: 'swap tokens',
687
712
  chain: inputChain,
688
- inputs: ['permit2sig'],
689
- txParams: {}
690
- };
691
- output.txs.push(tx2);
692
- //amountOutMin
693
- // let tx = await buildTx({trade,from:quote.senderAddress, chainId:chainIdInt, provider})
694
- // log.info(tag,"tx: ",tx)
713
+ txParams: tx
714
+ });
695
715
  output.meta = {
696
716
  quoteMode: "ERC20-ERC20"
697
717
  };
@@ -700,11 +720,11 @@ var get_quote = function (quote) {
700
720
  output.type = 'EVM';
701
721
  output.id = uuid();
702
722
  return [2 /*return*/, output];
703
- case 15:
723
+ case 16:
704
724
  e_7 = _d.sent();
705
725
  console.error(tag, "e: ", e_7);
706
726
  throw e_7;
707
- case 16: return [2 /*return*/];
727
+ case 17: return [2 /*return*/];
708
728
  }
709
729
  });
710
730
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pioneer-platform/uniswap-client",
3
- "version": "0.0.19",
3
+ "version": "0.0.21",
4
4
  "main": "./lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "dependencies": {