@pioneer-platform/uniswap-client 0.0.14 → 0.0.15

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 +41 -16
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -320,17 +320,38 @@ function getDefaultTransactionTtl(chainId) {
320
320
  return constants_1.DEFAULT_DEADLINE_FROM_NOW / 60;
321
321
  }
322
322
  exports.getDefaultTransactionTtl = getDefaultTransactionTtl;
323
+ var getDeadline = function (provider) { return __awaiter(void 0, void 0, void 0, function () {
324
+ var block, deadline, error_1;
325
+ return __generator(this, function (_a) {
326
+ switch (_a.label) {
327
+ case 0:
328
+ _a.trys.push([0, 2, , 3]);
329
+ return [4 /*yield*/, provider.getBlock('latest')];
330
+ case 1:
331
+ block = _a.sent();
332
+ deadline = block.timestamp + 60 * 60;
333
+ console.log("Current Block Timestamp: ".concat(block.timestamp));
334
+ console.log("Deadline (60 minutes later): ".concat(deadline));
335
+ return [2 /*return*/, deadline];
336
+ case 2:
337
+ error_1 = _a.sent();
338
+ console.error('Error fetching block or calculating deadline:', error_1);
339
+ return [2 /*return*/, null];
340
+ case 3: return [2 /*return*/];
341
+ }
342
+ });
343
+ }); };
323
344
  var buildTx = function (_a) {
324
345
  var trade = _a.trade, from = _a.from, chainId = _a.chainId, provider = _a.provider;
325
346
  return __awaiter(this, void 0, void 0, function () {
326
- var tag, BIPS_BASE, slippageTolerance, responseRouter, data, value, nonce, gas, estimatedGas, e_2, gasPrice, adjustedGasPrice, tx, e_3;
347
+ var tag, BIPS_BASE, slippageTolerance, deadline, responseRouter, data, value, nonce, gas, estimatedGas, e_2, gasPrice, adjustedGasPrice, tx, e_3;
327
348
  return __generator(this, function (_b) {
328
349
  switch (_b.label) {
329
350
  case 0:
330
351
  tag = TAG + " | buildTx | ";
331
352
  _b.label = 1;
332
353
  case 1:
333
- _b.trys.push([1, 8, , 9]);
354
+ _b.trys.push([1, 9, , 10]);
334
355
  BIPS_BASE = BigNumber.from(10000);
335
356
  slippageTolerance = new sdk_core_1.Percent(BigNumber.from(200), BIPS_BASE);
336
357
  log.info(tag, "slippageTolerance: ", slippageTolerance);
@@ -338,10 +359,14 @@ var buildTx = function (_a) {
338
359
  log.info(tag, "trade: ", trade.tradeType);
339
360
  log.info(tag, "swaps: ", trade.swaps[0]);
340
361
  log.info(tag, "routes: ", trade.routes[0]);
362
+ return [4 /*yield*/, getDeadline(provider)];
363
+ case 2:
364
+ deadline = _b.sent();
365
+ log.info(tag, "deadline: ", deadline);
341
366
  responseRouter = universal_router_sdk_1.SwapRouter.swapERC20CallParameters(trade, {
342
367
  recipient: from,
343
368
  slippageTolerance: slippageTolerance,
344
- // deadlineOrPreviousBlockhash: getDefaultTransactionTtl(chainId),
369
+ deadlineOrPreviousBlockhash: deadline,
345
370
  // inputTokenPermit: options.permit,
346
371
  // fee: options.feeOptions,
347
372
  });
@@ -349,40 +374,40 @@ var buildTx = function (_a) {
349
374
  data = responseRouter.calldata;
350
375
  value = responseRouter.value;
351
376
  return [4 /*yield*/, provider.getTransactionCount(from, "latest")];
352
- case 2:
377
+ case 3:
353
378
  nonce = _b.sent();
354
379
  gas = "0x".concat(BigInt("135120").toString(16));
355
- _b.label = 3;
356
- case 3:
357
- _b.trys.push([3, 5, , 6]);
380
+ _b.label = 4;
381
+ case 4:
382
+ _b.trys.push([4, 6, , 7]);
358
383
  return [4 /*yield*/, provider.estimateGas({
359
384
  from: from,
360
385
  to: EIP155_MAINNET_CHAINS['eip155:' + chainId].universalRouter, // Uniswap Router address
361
386
  data: data,
362
387
  value: ethers.utils.parseEther("0"), // Value for token swaps
363
388
  })];
364
- case 4:
389
+ case 5:
365
390
  estimatedGas = _b.sent();
366
391
  console.log("estimatedGas: ", estimatedGas);
367
392
  gas = "0x".concat(estimatedGas.toString(16));
368
- return [3 /*break*/, 6];
369
- case 5:
393
+ return [3 /*break*/, 7];
394
+ case 6:
370
395
  e_2 = _b.sent();
371
396
  console.error("Error in estimateGas: ", e_2);
372
397
  //@TODO get custom gas limit defaults per chain
373
398
  gas = "0x".concat(BigInt("135120").toString(16));
374
- return [3 /*break*/, 6];
375
- case 6: return [4 /*yield*/, provider.getGasPrice()];
376
- case 7:
399
+ return [3 /*break*/, 7];
400
+ case 7: return [4 /*yield*/, provider.getGasPrice()];
401
+ case 8:
377
402
  gasPrice = _b.sent();
378
403
  adjustedGasPrice = gasPrice.mul(ethers.BigNumber.from(110)).div(ethers.BigNumber.from(100));
379
404
  tx = __assign(__assign({ from: from, to: EIP155_MAINNET_CHAINS['eip155:' + chainId].universalRouter, chainId: chainId, data: data }, (value && !isZero(value) ? { value: (0, v3_sdk_1.toHex)(value) } : {})), { gas: gas, gasPrice: (0, v3_sdk_1.toHex)(adjustedGasPrice), nonce: (0, v3_sdk_1.toHex)(nonce) });
380
405
  return [2 /*return*/, tx];
381
- case 8:
406
+ case 9:
382
407
  e_3 = _b.sent();
383
408
  console.error(e_3);
384
- return [3 /*break*/, 9];
385
- case 9: return [2 /*return*/];
409
+ return [3 /*break*/, 10];
410
+ case 10: return [2 /*return*/];
386
411
  }
387
412
  });
388
413
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pioneer-platform/uniswap-client",
3
- "version": "0.0.14",
3
+ "version": "0.0.15",
4
4
  "main": "./lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "dependencies": {