@pioneer-platform/uniswap-client 0.0.7 → 0.0.9
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 +60 -24
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -169,6 +169,7 @@ var EIP155_MAINNET_CHAINS = {
|
|
|
169
169
|
logo: '/chain-logos/eip155-1.png',
|
|
170
170
|
rgb: '99, 125, 234',
|
|
171
171
|
permit2: universal_router_sdk_1.PERMIT2_ADDRESS,
|
|
172
|
+
universalRouter: universal_router_sdk_1.UNIVERSAL_ROUTER_ADDRESS,
|
|
172
173
|
rpc: 'https://eth.llamarpc.com',
|
|
173
174
|
namespace: 'eip155'
|
|
174
175
|
},
|
|
@@ -211,6 +212,7 @@ var EIP155_MAINNET_CHAINS = {
|
|
|
211
212
|
logo: '/chain-logos/base.png',
|
|
212
213
|
rgb: '242, 242, 242',
|
|
213
214
|
permit2: BASE_CONTRACTS.Permit2,
|
|
215
|
+
universalRouter: BASE_CONTRACTS.UniversalRouter,
|
|
214
216
|
rpc: 'https://mainnet.base.org',
|
|
215
217
|
namespace: 'eip155'
|
|
216
218
|
}
|
|
@@ -310,33 +312,63 @@ var isZero = function isZero(hexNumberString) {
|
|
|
310
312
|
return hexNumberString === '0' || /^0x0*$/.test(hexNumberString);
|
|
311
313
|
};
|
|
312
314
|
var buildTx = function (_a) {
|
|
313
|
-
var trade = _a.trade, from = _a.from, chainId = _a.chainId;
|
|
315
|
+
var trade = _a.trade, from = _a.from, chainId = _a.chainId, provider = _a.provider;
|
|
314
316
|
return __awaiter(this, void 0, void 0, function () {
|
|
315
|
-
var BIPS_BASE, slippageTolerance, _b, data, value, tx;
|
|
317
|
+
var BIPS_BASE, slippageTolerance, _b, data, value, nonce, gas, estimatedGas, e_2, gasPrice, adjustedGasPrice, tx, e_3;
|
|
316
318
|
return __generator(this, function (_c) {
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
slippageTolerance
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
319
|
+
switch (_c.label) {
|
|
320
|
+
case 0:
|
|
321
|
+
_c.trys.push([0, 7, , 8]);
|
|
322
|
+
BIPS_BASE = BigNumber.from(10000);
|
|
323
|
+
slippageTolerance = new sdk_core_1.Percent(BigNumber.from(200), BIPS_BASE);
|
|
324
|
+
_b = router_sdk_1.SwapRouter.swapCallParameters(trade, {
|
|
325
|
+
slippageTolerance: slippageTolerance,
|
|
326
|
+
// slippageTolerance: new Percent(JSBI.BigInt(200), BIPS_BASE),
|
|
327
|
+
// deadlineOrPreviousBlockhash: options.deadline?.toString(),
|
|
328
|
+
// inputTokenPermit: options.permit,
|
|
329
|
+
// fee: options.feeOptions,
|
|
330
|
+
}), data = _b.calldata, value = _b.value;
|
|
331
|
+
return [4 /*yield*/, provider.getTransactionCount(from, "latest")];
|
|
332
|
+
case 1:
|
|
333
|
+
nonce = _c.sent();
|
|
334
|
+
gas = "0x".concat(BigInt("135120").toString(16));
|
|
335
|
+
_c.label = 2;
|
|
336
|
+
case 2:
|
|
337
|
+
_c.trys.push([2, 4, , 5]);
|
|
338
|
+
return [4 /*yield*/, provider.estimateGas({
|
|
339
|
+
from: from,
|
|
340
|
+
to: (0, universal_router_sdk_1.UNIVERSAL_ROUTER_ADDRESS)(chainId), // Uniswap Router address
|
|
341
|
+
data: data,
|
|
342
|
+
value: ethers.utils.parseEther("0"), // Value for token swaps
|
|
343
|
+
})];
|
|
344
|
+
case 3:
|
|
345
|
+
estimatedGas = _c.sent();
|
|
346
|
+
console.log("estimatedGas: ", estimatedGas);
|
|
347
|
+
gas = "0x".concat(estimatedGas.toString(16));
|
|
348
|
+
return [3 /*break*/, 5];
|
|
349
|
+
case 4:
|
|
350
|
+
e_2 = _c.sent();
|
|
351
|
+
//@TODO get custom gas limit defaults per chain
|
|
352
|
+
gas = "0x".concat(BigInt("135120").toString(16));
|
|
353
|
+
return [3 /*break*/, 5];
|
|
354
|
+
case 5: return [4 /*yield*/, provider.getGasPrice()];
|
|
355
|
+
case 6:
|
|
356
|
+
gasPrice = _c.sent();
|
|
357
|
+
adjustedGasPrice = gasPrice.mul(ethers.BigNumber.from(110)).div(ethers.BigNumber.from(100));
|
|
358
|
+
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) });
|
|
359
|
+
return [2 /*return*/, tx];
|
|
360
|
+
case 7:
|
|
361
|
+
e_3 = _c.sent();
|
|
362
|
+
console.error(e_3);
|
|
363
|
+
return [3 /*break*/, 8];
|
|
364
|
+
case 8: return [2 /*return*/];
|
|
332
365
|
}
|
|
333
|
-
return [2 /*return*/];
|
|
334
366
|
});
|
|
335
367
|
});
|
|
336
368
|
};
|
|
337
369
|
var get_quote = function (quote) {
|
|
338
370
|
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,
|
|
371
|
+
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
372
|
return __generator(this, function (_d) {
|
|
341
373
|
switch (_d.label) {
|
|
342
374
|
case 0:
|
|
@@ -471,7 +503,7 @@ var get_quote = function (quote) {
|
|
|
471
503
|
amountOut = trade.swaps[0].outputAmount;
|
|
472
504
|
log.info(tag, "amountOut: ", amountOut);
|
|
473
505
|
output.amountOut = amountOut.toFixed(18);
|
|
474
|
-
return [4 /*yield*/, buildTx({ trade: trade, from: quote.senderAddress, chainId: chainIdInt })];
|
|
506
|
+
return [4 /*yield*/, buildTx({ trade: trade, from: quote.senderAddress, chainId: chainIdInt, provider: provider })];
|
|
475
507
|
case 13:
|
|
476
508
|
tx = _d.sent();
|
|
477
509
|
log.info(tag, "tx: ", tx);
|
|
@@ -482,12 +514,16 @@ var get_quote = function (quote) {
|
|
|
482
514
|
output.complete = true;
|
|
483
515
|
output.type = 'EVM';
|
|
484
516
|
output.id = uuid();
|
|
485
|
-
output.txs = [
|
|
517
|
+
output.txs = [{
|
|
518
|
+
type: "evm",
|
|
519
|
+
chain: inputChain,
|
|
520
|
+
txParams: tx
|
|
521
|
+
}];
|
|
486
522
|
return [2 /*return*/, output];
|
|
487
523
|
case 14:
|
|
488
|
-
|
|
489
|
-
console.error(tag, "e: ",
|
|
490
|
-
throw
|
|
524
|
+
e_4 = _d.sent();
|
|
525
|
+
console.error(tag, "e: ", e_4);
|
|
526
|
+
throw e_4;
|
|
491
527
|
case 15: return [2 /*return*/];
|
|
492
528
|
}
|
|
493
529
|
});
|