@pioneer-platform/mayachain-client 0.0.31 → 0.0.33

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 +24 -17
  2. 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, gasLimit, block, baseFeePerGas, gasPrice, maxPriorityFeePerGas, maxFeePerGas, feeData, nonce, 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, numberBN, numberHex, data, gasLimit, block, baseFeePerGas, gasPrice, maxPriorityFeePerGas, maxFeePerGas, feeData, 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, 11, , 12]);
133
+ _a.trys.push([1, 10, , 11]);
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*/, 9];
229
+ if (!(chain === "ETH")) return [3 /*break*/, 8];
230
230
  type = 'EVM';
231
231
  return [4 /*yield*/, nodeRequest('/inbound_addresses')];
232
232
  case 4:
@@ -255,7 +255,8 @@ var get_quote = function (quote) {
255
255
  routerContract = new web3.eth.Contract(depositAbi, inbound.router);
256
256
  log.info("routerContract: ", routerContract);
257
257
  quoteSellAmountInEther = web3.utils.toWei(quote.sellAmount, 'ether');
258
- numberHex = web3.utils.toBN(quoteSellAmountInEther);
258
+ numberBN = web3.utils.toBN(quoteSellAmountInEther);
259
+ numberHex = '0x' + numberBN.toString(16);
259
260
  console.log("numberHex: ", numberHex);
260
261
  data = routerContract.methods
261
262
  .deposit(inbound.address, '0x0000000000000000000000000000000000000000', // 0 = ETH
@@ -269,6 +270,7 @@ var get_quote = function (quote) {
269
270
  })];
270
271
  case 5:
271
272
  gasLimit = _a.sent();
273
+ gasLimit = gasLimit + gasLimit * 0.2;
272
274
  log.info(tag, 'gasLimit: ', gasLimit);
273
275
  return [4 /*yield*/, web3.eth.getBlock("latest")];
274
276
  case 6:
@@ -286,10 +288,15 @@ var get_quote = function (quote) {
286
288
  maxFeePerGas: maxFeePerGas // EIP-1559 calculation
287
289
  };
288
290
  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);
291
+ // Calculate a 20% buffer and add it to the gasLimit
292
+ // const buffer = gasLimit.mul(20).div(100); // 20% buffer
293
+ // gasLimit = gasLimit.add(buffer);
294
+ // //if gas limit is < 21000 then set to 21000
295
+ // if (gasLimit.lt(ethers.BigNumber.from('36000'))) {
296
+ // gasLimit = ethers.BigNumber.from('36000');
297
+ // }
298
+ // const nonce = await web3.eth.getTransactionCount(quote.senderAddress, 'latest'); // 'latest' can be replaced with the desired block number
299
+ // console.log("nonce: ",nonce)
293
300
  tx = {
294
301
  type: type,
295
302
  chain: ChainToNetworkId[quote.sellAsset.split(".")[0]],
@@ -297,15 +304,15 @@ var get_quote = function (quote) {
297
304
  to: inbound.router,
298
305
  from: quote.senderAddress,
299
306
  data: data,
300
- value: quoteSellAmountInEther,
301
- "gasLimit": gasLimit,
307
+ value: numberHex,
308
+ "gasLimit": Web3.utils.toHex(gasLimit),
302
309
  "maxPriorityFeePerGas": maxPriorityFeePerGas,
303
310
  "maxFeePerGas": maxFeePerGas,
304
- "nonce": nonce
311
+ "nonce": null
305
312
  }
306
313
  };
307
- return [3 /*break*/, 10];
308
- case 9:
314
+ return [3 /*break*/, 9];
315
+ case 8:
309
316
  tx = {
310
317
  type: type,
311
318
  chain: ChainToNetworkId[quote.sellAsset.split(".")[0]],
@@ -317,17 +324,17 @@ var get_quote = function (quote) {
317
324
  memo: quoteFromNode.memo || memo
318
325
  }
319
326
  };
320
- _a.label = 10;
321
- case 10:
327
+ _a.label = 9;
328
+ case 9:
322
329
  output.txs = [
323
330
  tx
324
331
  ];
325
332
  return [2 /*return*/, output];
326
- case 11:
333
+ case 10:
327
334
  e_1 = _a.sent();
328
335
  console.error(tag, "e: ", e_1);
329
336
  throw e_1;
330
- case 12: return [2 /*return*/];
337
+ case 11: return [2 /*return*/];
331
338
  }
332
339
  });
333
340
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pioneer-platform/mayachain-client",
3
- "version": "0.0.31",
3
+ "version": "0.0.33",
4
4
  "main": "./lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "dependencies": {