@pioneer-platform/mayachain-client 0.0.26 → 0.0.28

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 (3) hide show
  1. package/lib/index.js +58 -4
  2. package/package.json +3 -2
  3. package/yarn-error.log +15253 -0
package/lib/index.js CHANGED
@@ -46,6 +46,11 @@ var log = require('@pioneer-platform/loggerdog')();
46
46
  var _a = require("@pioneer-platform/pioneer-caip"), caipToNetworkId = _a.caipToNetworkId, shortListSymbolToCaip = _a.shortListSymbolToCaip, ChainToNetworkId = _a.ChainToNetworkId;
47
47
  var network = require("@pioneer-platform/maya-network");
48
48
  var _b = require('@pioneer-platform/pioneer-coins'), createMemo = _b.createMemo, parseMemo = _b.parseMemo;
49
+ var Web3 = require('web3');
50
+ var service = process.env['PARITY_ARCHIVE_NODE'];
51
+ if (!service)
52
+ throw Error("Missing PARITY_ARCHIVE_NODE in .env");
53
+ var web3 = new Web3(service);
49
54
  var networkSupport = [
50
55
  ChainToNetworkId["BTC"],
51
56
  ChainToNetworkId["MAYA"],
@@ -118,14 +123,14 @@ function quoteFromPool(sellAmount, assetPoolAmount, runePoolAmount, maxSlippage)
118
123
  }
119
124
  var get_quote = function (quote) {
120
125
  return __awaiter(this, void 0, void 0, function () {
121
- var tag, output, pools, poolIn, poolOut, BaseDecimal_1, asset, DECIMALS, BASE_UNIT, sellAmountInBaseUnits, quoteFromNode, URL_1, amountOutMin, inboundAddress, amountOutEstimated, memoInput, memo, type, chain, tx, 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, e_1;
122
127
  return __generator(this, function (_a) {
123
128
  switch (_a.label) {
124
129
  case 0:
125
130
  tag = TAG + " | get_quote | ";
126
131
  _a.label = 1;
127
132
  case 1:
128
- _a.trys.push([1, 4, , 5]);
133
+ _a.trys.push([1, 7, , 8]);
129
134
  output = {};
130
135
  if (!quote.sellAsset)
131
136
  throw new Error("missing sellAsset");
@@ -220,6 +225,53 @@ var get_quote = function (quote) {
220
225
  else {
221
226
  type = 'transfer';
222
227
  }
228
+ tx = void 0;
229
+ if (!(chain === "ETH")) return [3 /*break*/, 5];
230
+ type = 'EVM';
231
+ return [4 /*yield*/, nodeRequest('/inbound_addresses')];
232
+ case 4:
233
+ inbounds = _a.sent();
234
+ console.log("inbounds: ", inbounds);
235
+ inbound = inbounds.find(function (i) { return i.chain === 'ETH'; });
236
+ console.log("inbound: ", inbound);
237
+ tokenAddress = (quote.sellAsset.split('-')[1] || '').toLowerCase();
238
+ log.info("tokenAddress: ", tokenAddress);
239
+ depositAbi = [
240
+ {
241
+ "constant": false,
242
+ "inputs": [
243
+ { "name": "tokenAddress", "type": "address" },
244
+ { "name": "to", "type": "address" },
245
+ { "name": "amount", "type": "uint256" },
246
+ { "name": "data", "type": "string" }
247
+ ],
248
+ "name": "deposit",
249
+ "outputs": [],
250
+ "payable": false,
251
+ "stateMutability": "nonpayable",
252
+ "type": "function"
253
+ }
254
+ ];
255
+ routerContract = new web3.eth.Contract(depositAbi, inbound.router);
256
+ log.info("routerContract: ", routerContract);
257
+ quoteSellAmountInEther = web3.utils.toWei(quote.sellAmount, 'ether');
258
+ numberHex = web3.utils.toBN(quoteSellAmountInEther);
259
+ console.log("numberHex: ", numberHex);
260
+ data = routerContract.methods
261
+ .deposit(inbound.address, '0x0000000000000000000000000000000000000000', // 0 = ETH
262
+ numberHex, memo)
263
+ .encodeABI();
264
+ tx = {
265
+ type: type,
266
+ chain: ChainToNetworkId[quote.sellAsset.split(".")[0]],
267
+ txParams: {
268
+ to: "",
269
+ from: quote.senderAddress,
270
+ data: data
271
+ }
272
+ };
273
+ return [3 /*break*/, 6];
274
+ case 5:
223
275
  tx = {
224
276
  type: type,
225
277
  chain: ChainToNetworkId[quote.sellAsset.split(".")[0]],
@@ -231,15 +283,17 @@ var get_quote = function (quote) {
231
283
  memo: quoteFromNode.memo || memo
232
284
  }
233
285
  };
286
+ _a.label = 6;
287
+ case 6:
234
288
  output.txs = [
235
289
  tx
236
290
  ];
237
291
  return [2 /*return*/, output];
238
- case 4:
292
+ case 7:
239
293
  e_1 = _a.sent();
240
294
  console.error(tag, "e: ", e_1);
241
295
  throw e_1;
242
- case 5: return [2 /*return*/];
296
+ case 8: return [2 /*return*/];
243
297
  }
244
298
  });
245
299
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pioneer-platform/mayachain-client",
3
- "version": "0.0.26",
3
+ "version": "0.0.28",
4
4
  "main": "./lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "dependencies": {
@@ -11,7 +11,8 @@
11
11
  "axios": "^1.3.4",
12
12
  "dotenv": "^8.2.0",
13
13
  "rango-sdk": "^0.1.45",
14
- "uuidv4": "^6.2.13"
14
+ "uuidv4": "^6.2.13",
15
+ "web3": "1.10.3"
15
16
  },
16
17
  "scripts": {
17
18
  "npm": "npm i",