@pioneer-platform/uniswap-client 0.0.13 → 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.
- package/lib/index.js +48 -21
- 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,
|
|
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
|
-
|
|
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
|
|
377
|
+
case 3:
|
|
353
378
|
nonce = _b.sent();
|
|
354
379
|
gas = "0x".concat(BigInt("135120").toString(16));
|
|
355
|
-
_b.label =
|
|
356
|
-
case
|
|
357
|
-
_b.trys.push([
|
|
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
|
|
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*/,
|
|
369
|
-
case
|
|
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*/,
|
|
375
|
-
case
|
|
376
|
-
case
|
|
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
|
|
406
|
+
case 9:
|
|
382
407
|
e_3 = _b.sent();
|
|
383
408
|
console.error(e_3);
|
|
384
|
-
return [3 /*break*/,
|
|
385
|
-
case
|
|
409
|
+
return [3 /*break*/, 10];
|
|
410
|
+
case 10: return [2 /*return*/];
|
|
386
411
|
}
|
|
387
412
|
});
|
|
388
413
|
});
|
|
@@ -424,9 +449,9 @@ var get_quote = function (quote) {
|
|
|
424
449
|
provider = new ethers.providers.JsonRpcProvider(providerUrl);
|
|
425
450
|
sellTokenContract = void 0, buyTokenContract = void 0;
|
|
426
451
|
if (!(quote.buyAsset.indexOf('erc20') > -1)) return [3 /*break*/, 3];
|
|
427
|
-
buyTokenAddress_1 = quote.buyAsset.split(":")[2];
|
|
452
|
+
buyTokenAddress_1 = quote.buyAsset.split(":")[2].toLowerCase();
|
|
428
453
|
log.info("buyTokenAddress: ", buyTokenAddress_1);
|
|
429
|
-
buyTokenContract = new ethers.Contract(buyTokenAddress_1, ERC20_ABI, provider);
|
|
454
|
+
buyTokenContract = new ethers.Contract(buyTokenAddress_1.toLowerCase(), ERC20_ABI, provider);
|
|
430
455
|
return [4 /*yield*/, buyTokenContract.balanceOf(quote.senderAddress)];
|
|
431
456
|
case 2:
|
|
432
457
|
balance = _d.sent();
|
|
@@ -434,7 +459,7 @@ var get_quote = function (quote) {
|
|
|
434
459
|
_d.label = 3;
|
|
435
460
|
case 3:
|
|
436
461
|
if (quote.sellAsset.indexOf('erc20') > -1) {
|
|
437
|
-
sellTokenAddress_1 = quote.sellAsset.split(":")[2];
|
|
462
|
+
sellTokenAddress_1 = quote.sellAsset.split(":")[2].toLowerCase();
|
|
438
463
|
log.info("sellTokenAddress: ", sellTokenAddress_1);
|
|
439
464
|
sellTokenContract = new ethers.Contract(sellTokenAddress_1, ERC20_ABI, provider);
|
|
440
465
|
}
|
|
@@ -464,8 +489,10 @@ var get_quote = function (quote) {
|
|
|
464
489
|
permit2Address = EIP155_MAINNET_CHAINS[inputChain].permit2;
|
|
465
490
|
if (!permit2Address)
|
|
466
491
|
throw new Error("missing permit2Address for chain: " + inputChain);
|
|
467
|
-
console.log("sellTokenContract: ", sellTokenContract
|
|
468
|
-
|
|
492
|
+
console.log("sellTokenContract: ", sellTokenContract);
|
|
493
|
+
log.info(tag, "permit2Address: ", permit2Address);
|
|
494
|
+
log.info(tag, "quote.senderAddress: ", quote.senderAddress.toLowerCase());
|
|
495
|
+
return [4 /*yield*/, sellTokenContract.allowance(quote.senderAddress.toLowerCase(), permit2Address)];
|
|
469
496
|
case 4:
|
|
470
497
|
currentAllowance = _d.sent();
|
|
471
498
|
console.log("currentAllowance: ", currentAllowance.toString());
|