@pioneer-platform/uniswap-client 0.0.6 → 0.0.8

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 +58 -24
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -310,33 +310,63 @@ var isZero = function isZero(hexNumberString) {
310
310
  return hexNumberString === '0' || /^0x0*$/.test(hexNumberString);
311
311
  };
312
312
  var buildTx = function (_a) {
313
- var trade = _a.trade, from = _a.from, chainId = _a.chainId;
313
+ var trade = _a.trade, from = _a.from, chainId = _a.chainId, provider = _a.provider;
314
314
  return __awaiter(this, void 0, void 0, function () {
315
- var BIPS_BASE, slippageTolerance, _b, data, value, tx;
315
+ var BIPS_BASE, slippageTolerance, _b, data, value, nonce, gas, estimatedGas, e_2, gasPrice, adjustedGasPrice, tx, e_3;
316
316
  return __generator(this, function (_c) {
317
- try {
318
- BIPS_BASE = BigNumber.from(10000);
319
- slippageTolerance = new sdk_core_1.Percent(BigNumber.from(200), BIPS_BASE);
320
- _b = router_sdk_1.SwapRouter.swapCallParameters(trade, {
321
- slippageTolerance: slippageTolerance,
322
- // slippageTolerance: new Percent(JSBI.BigInt(200), BIPS_BASE),
323
- // deadlineOrPreviousBlockhash: options.deadline?.toString(),
324
- // inputTokenPermit: options.permit,
325
- // fee: options.feeOptions,
326
- }), data = _b.calldata, value = _b.value;
327
- tx = __assign({ from: from, to: (0, universal_router_sdk_1.UNIVERSAL_ROUTER_ADDRESS)(chainId), data: data }, (value && !isZero(value) ? { value: (0, v3_sdk_1.toHex)(value) } : {}));
328
- return [2 /*return*/, tx];
329
- }
330
- catch (e) {
331
- console.error(e);
317
+ switch (_c.label) {
318
+ case 0:
319
+ _c.trys.push([0, 7, , 8]);
320
+ BIPS_BASE = BigNumber.from(10000);
321
+ slippageTolerance = new sdk_core_1.Percent(BigNumber.from(200), BIPS_BASE);
322
+ _b = router_sdk_1.SwapRouter.swapCallParameters(trade, {
323
+ slippageTolerance: slippageTolerance,
324
+ // slippageTolerance: new Percent(JSBI.BigInt(200), BIPS_BASE),
325
+ // deadlineOrPreviousBlockhash: options.deadline?.toString(),
326
+ // inputTokenPermit: options.permit,
327
+ // fee: options.feeOptions,
328
+ }), data = _b.calldata, value = _b.value;
329
+ return [4 /*yield*/, provider.getTransactionCount(from, "latest")];
330
+ case 1:
331
+ nonce = _c.sent();
332
+ gas = "0x".concat(BigInt("135120").toString(16));
333
+ _c.label = 2;
334
+ case 2:
335
+ _c.trys.push([2, 4, , 5]);
336
+ return [4 /*yield*/, provider.estimateGas({
337
+ from: from,
338
+ to: (0, universal_router_sdk_1.UNIVERSAL_ROUTER_ADDRESS)(chainId), // Uniswap Router address
339
+ data: data,
340
+ value: ethers.utils.parseEther("0"), // Value for token swaps
341
+ })];
342
+ case 3:
343
+ estimatedGas = _c.sent();
344
+ console.log("estimatedGas: ", estimatedGas);
345
+ gas = "0x".concat(estimatedGas.toString(16));
346
+ return [3 /*break*/, 5];
347
+ case 4:
348
+ e_2 = _c.sent();
349
+ //@TODO get custom gas limit defaults per chain
350
+ gas = "0x".concat(BigInt("135120").toString(16));
351
+ return [3 /*break*/, 5];
352
+ case 5: return [4 /*yield*/, provider.getGasPrice()];
353
+ case 6:
354
+ gasPrice = _c.sent();
355
+ adjustedGasPrice = gasPrice.mul(ethers.BigNumber.from(110)).div(ethers.BigNumber.from(100));
356
+ tx = __assign(__assign({ from: from, to: (0, universal_router_sdk_1.UNIVERSAL_ROUTER_ADDRESS)(chainId), 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) });
357
+ return [2 /*return*/, tx];
358
+ case 7:
359
+ e_3 = _c.sent();
360
+ console.error(e_3);
361
+ return [3 /*break*/, 8];
362
+ case 8: return [2 /*return*/];
332
363
  }
333
- return [2 /*return*/];
334
364
  });
335
365
  });
336
366
  };
337
367
  var get_quote = function (quote) {
338
368
  return __awaiter(this, void 0, void 0, function () {
339
- var tag, output, slippageTolerance, recipient, inputChain, outputChain, providerUrl, provider, sellTokenContract, buyTokenContract, buyTokenAddress_1, balance, sellTokenAddress_1, permit2, router, planner, sellAmountBigNumber, path, permit2Address, currentAllowance, _a, sellTokenAddress, buyTokenAddress, sellTokenDecimals, _b, buyTokenDecimals, _c, amountInBigNumber, chainIdInt, sellToken, buyToken, route, trade, amountOut, tx, e_2;
369
+ var tag, output, slippageTolerance, recipient, inputChain, outputChain, providerUrl, provider, sellTokenContract, buyTokenContract, buyTokenAddress_1, balance, sellTokenAddress_1, permit2, router, planner, sellAmountBigNumber, path, permit2Address, currentAllowance, _a, sellTokenAddress, buyTokenAddress, sellTokenDecimals, _b, buyTokenDecimals, _c, amountInBigNumber, chainIdInt, sellToken, buyToken, route, trade, amountOut, tx, e_4;
340
370
  return __generator(this, function (_d) {
341
371
  switch (_d.label) {
342
372
  case 0:
@@ -471,7 +501,7 @@ var get_quote = function (quote) {
471
501
  amountOut = trade.swaps[0].outputAmount;
472
502
  log.info(tag, "amountOut: ", amountOut);
473
503
  output.amountOut = amountOut.toFixed(18);
474
- return [4 /*yield*/, buildTx({ trade: trade, from: quote.senderAddress, chainId: chainIdInt })];
504
+ return [4 /*yield*/, buildTx({ trade: trade, from: quote.senderAddress, chainId: chainIdInt, provider: provider })];
475
505
  case 13:
476
506
  tx = _d.sent();
477
507
  log.info(tag, "tx: ", tx);
@@ -482,12 +512,16 @@ var get_quote = function (quote) {
482
512
  output.complete = true;
483
513
  output.type = 'EVM';
484
514
  output.id = uuid();
485
- output.txs = [tx];
515
+ output.txs = [{
516
+ type: "evm",
517
+ chain: inputChain,
518
+ txParams: tx
519
+ }];
486
520
  return [2 /*return*/, output];
487
521
  case 14:
488
- e_2 = _d.sent();
489
- console.error(tag, "e: ", e_2);
490
- throw e_2;
522
+ e_4 = _d.sent();
523
+ console.error(tag, "e: ", e_4);
524
+ throw e_4;
491
525
  case 15: return [2 /*return*/];
492
526
  }
493
527
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pioneer-platform/uniswap-client",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "main": "./lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "dependencies": {