@pioneer-platform/mayachain-client 0.0.29 → 0.0.30
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 +45 -11
- package/package.json +1 -1
package/lib/index.js
CHANGED
@@ -123,14 +123,14 @@ function quoteFromPool(sellAmount, assetPoolAmount, runePoolAmount, maxSlippage)
|
|
123
123
|
}
|
124
124
|
var get_quote = function (quote) {
|
125
125
|
return __awaiter(this, void 0, void 0, function () {
|
126
|
-
var tag, output, pools, poolIn, poolOut, BaseDecimal_1, asset, DECIMALS, BASE_UNIT, sellAmountInBaseUnits, quoteFromNode, URL_1, amountOutMin, inboundAddress, amountOutEstimated, memoInput, memo, type, chain, tx, inbounds, inbound, tokenAddress, depositAbi, routerContract, quoteSellAmountInEther, numberHex, data, e_1;
|
126
|
+
var tag, output, pools, poolIn, poolOut, BaseDecimal_1, asset, DECIMALS, BASE_UNIT, sellAmountInBaseUnits, quoteFromNode, URL_1, amountOutMin, inboundAddress, amountOutEstimated, memoInput, memo, type, chain, tx, inbounds, inbound, tokenAddress, depositAbi, routerContract, quoteSellAmountInEther, numberHex, data, gasLimit, block, baseFeePerGas, gasPrice, maxPriorityFeePerGas, maxFeePerGas, feeData, nonce, e_1;
|
127
127
|
return __generator(this, function (_a) {
|
128
128
|
switch (_a.label) {
|
129
129
|
case 0:
|
130
130
|
tag = TAG + " | get_quote | ";
|
131
131
|
_a.label = 1;
|
132
132
|
case 1:
|
133
|
-
_a.trys.push([1,
|
133
|
+
_a.trys.push([1, 11, , 12]);
|
134
134
|
output = {};
|
135
135
|
if (!quote.sellAsset)
|
136
136
|
throw new Error("missing sellAsset");
|
@@ -226,7 +226,7 @@ var get_quote = function (quote) {
|
|
226
226
|
type = 'transfer';
|
227
227
|
}
|
228
228
|
tx = void 0;
|
229
|
-
if (!(chain === "ETH")) return [3 /*break*/,
|
229
|
+
if (!(chain === "ETH")) return [3 /*break*/, 9];
|
230
230
|
type = 'EVM';
|
231
231
|
return [4 /*yield*/, nodeRequest('/inbound_addresses')];
|
232
232
|
case 4:
|
@@ -261,17 +261,51 @@ var get_quote = function (quote) {
|
|
261
261
|
.deposit(inbound.address, '0x0000000000000000000000000000000000000000', // 0 = ETH
|
262
262
|
numberHex, memo)
|
263
263
|
.encodeABI();
|
264
|
+
return [4 /*yield*/, web3.eth.estimateGas({
|
265
|
+
from: quote.senderAddress,
|
266
|
+
to: inbound.router,
|
267
|
+
value: 0,
|
268
|
+
data: data,
|
269
|
+
})];
|
270
|
+
case 5:
|
271
|
+
gasLimit = _a.sent();
|
272
|
+
log.info(tag, 'gasLimit: ', gasLimit);
|
273
|
+
return [4 /*yield*/, web3.eth.getBlock("latest")];
|
274
|
+
case 6:
|
275
|
+
block = _a.sent();
|
276
|
+
baseFeePerGas = block.baseFeePerGas;
|
277
|
+
return [4 /*yield*/, web3.eth.getGasPrice()];
|
278
|
+
case 7:
|
279
|
+
gasPrice = _a.sent();
|
280
|
+
maxPriorityFeePerGas = baseFeePerGas ? web3.utils.toBN(baseFeePerGas).div(web3.utils.toBN(2)).toString() : '0';
|
281
|
+
maxFeePerGas = baseFeePerGas ? web3.utils.toBN(baseFeePerGas).mul(web3.utils.toBN(2)).toString() : gasPrice;
|
282
|
+
feeData = {
|
283
|
+
gasPrice: gasPrice, // Legacy networks
|
284
|
+
baseFeePerGas: baseFeePerGas, // EIP-1559 networks
|
285
|
+
maxPriorityFeePerGas: maxPriorityFeePerGas, // EIP-1559 calculation
|
286
|
+
maxFeePerGas: maxFeePerGas // EIP-1559 calculation
|
287
|
+
};
|
288
|
+
console.log("feeData: ", feeData);
|
289
|
+
return [4 /*yield*/, web3.eth.getTransactionCount(quote.senderAddress, 'latest')];
|
290
|
+
case 8:
|
291
|
+
nonce = _a.sent();
|
292
|
+
console.log("nonce: ", nonce);
|
264
293
|
tx = {
|
265
294
|
type: type,
|
266
295
|
chain: ChainToNetworkId[quote.sellAsset.split(".")[0]],
|
267
296
|
txParams: {
|
268
|
-
to:
|
297
|
+
to: inbound.router,
|
269
298
|
from: quote.senderAddress,
|
270
|
-
data: data
|
299
|
+
data: data,
|
300
|
+
value: quoteSellAmountInEther,
|
301
|
+
"gasLimit": gasLimit,
|
302
|
+
"maxPriorityFeePerGas": maxPriorityFeePerGas,
|
303
|
+
"maxFeePerGas": maxFeePerGas,
|
304
|
+
"nonce": nonce
|
271
305
|
}
|
272
306
|
};
|
273
|
-
return [3 /*break*/,
|
274
|
-
case
|
307
|
+
return [3 /*break*/, 10];
|
308
|
+
case 9:
|
275
309
|
tx = {
|
276
310
|
type: type,
|
277
311
|
chain: ChainToNetworkId[quote.sellAsset.split(".")[0]],
|
@@ -283,17 +317,17 @@ var get_quote = function (quote) {
|
|
283
317
|
memo: quoteFromNode.memo || memo
|
284
318
|
}
|
285
319
|
};
|
286
|
-
_a.label =
|
287
|
-
case
|
320
|
+
_a.label = 10;
|
321
|
+
case 10:
|
288
322
|
output.txs = [
|
289
323
|
tx
|
290
324
|
];
|
291
325
|
return [2 /*return*/, output];
|
292
|
-
case
|
326
|
+
case 11:
|
293
327
|
e_1 = _a.sent();
|
294
328
|
console.error(tag, "e: ", e_1);
|
295
329
|
throw e_1;
|
296
|
-
case
|
330
|
+
case 12: return [2 /*return*/];
|
297
331
|
}
|
298
332
|
});
|
299
333
|
});
|