@pioneer-platform/uniswap-client 0.0.20 → 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.
- package/lib/index.js +29 -26
- 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
|
-
|
|
98
|
-
|
|
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
|
-
|
|
379
|
+
inputTokenPermit: permit,
|
|
379
380
|
// fee: options.feeOptions,
|
|
380
381
|
});
|
|
381
382
|
log.info(tag, "responseRouter: ", responseRouter);
|
|
@@ -541,14 +542,14 @@ var build_permit_tx = function (_a) {
|
|
|
541
542
|
};
|
|
542
543
|
var get_quote = function (quote) {
|
|
543
544
|
return __awaiter(this, void 0, void 0, function () {
|
|
544
|
-
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,
|
|
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;
|
|
545
546
|
return __generator(this, function (_d) {
|
|
546
547
|
switch (_d.label) {
|
|
547
548
|
case 0:
|
|
548
549
|
tag = TAG + " | get_quote | ";
|
|
549
550
|
_d.label = 1;
|
|
550
551
|
case 1:
|
|
551
|
-
_d.trys.push([1,
|
|
552
|
+
_d.trys.push([1, 16, , 17]);
|
|
552
553
|
output = {};
|
|
553
554
|
if (!quote.sellAsset)
|
|
554
555
|
throw new Error("missing sellAsset");
|
|
@@ -686,29 +687,31 @@ var get_quote = function (quote) {
|
|
|
686
687
|
amountOut = trade.swaps[0].outputAmount;
|
|
687
688
|
log.info(tag, "amountOut: ", amountOut);
|
|
688
689
|
output.amountOut = amountOut.toFixed(18);
|
|
689
|
-
|
|
690
|
-
|
|
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: {
|
|
691
697
|
token: sellToken.address,
|
|
692
698
|
amount: "1000000000000000000000000",
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
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:
|
|
698
707
|
tx = _d.sent();
|
|
699
|
-
|
|
700
|
-
output.txs.push(
|
|
701
|
-
tx2 = {
|
|
708
|
+
log.info(tag, "tx: ", tx);
|
|
709
|
+
output.txs.push({
|
|
702
710
|
type: "evm",
|
|
703
711
|
description: 'swap tokens',
|
|
704
712
|
chain: inputChain,
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
};
|
|
708
|
-
output.txs.push(tx2);
|
|
709
|
-
//amountOutMin
|
|
710
|
-
// let tx = await buildTx({trade,from:quote.senderAddress, chainId:chainIdInt, provider})
|
|
711
|
-
// log.info(tag,"tx: ",tx)
|
|
713
|
+
txParams: tx
|
|
714
|
+
});
|
|
712
715
|
output.meta = {
|
|
713
716
|
quoteMode: "ERC20-ERC20"
|
|
714
717
|
};
|
|
@@ -717,11 +720,11 @@ var get_quote = function (quote) {
|
|
|
717
720
|
output.type = 'EVM';
|
|
718
721
|
output.id = uuid();
|
|
719
722
|
return [2 /*return*/, output];
|
|
720
|
-
case
|
|
723
|
+
case 16:
|
|
721
724
|
e_7 = _d.sent();
|
|
722
725
|
console.error(tag, "e: ", e_7);
|
|
723
726
|
throw e_7;
|
|
724
|
-
case
|
|
727
|
+
case 17: return [2 /*return*/];
|
|
725
728
|
}
|
|
726
729
|
});
|
|
727
730
|
});
|