@pioneer-platform/mayachain-client 0.0.13 → 0.0.16

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 +22 -6
  2. package/package.json +2 -2
package/lib/index.js CHANGED
@@ -117,14 +117,14 @@ function quoteFromPool(sellAmount, assetPoolAmount, runePoolAmount, maxSlippage)
117
117
  }
118
118
  var get_quote = function (quote) {
119
119
  return __awaiter(this, void 0, void 0, function () {
120
- var tag, output, pools, memoInput, memo, tx, e_1;
120
+ var tag, output, pools, poolIn, poolOut, BASE_UNIT, DECIMALS, sellAmountInBaseUnits, quoteFromNode, amountOutMin, inboundAddress, amountOutEstimated, memoInput, memo, tx, e_1;
121
121
  return __generator(this, function (_a) {
122
122
  switch (_a.label) {
123
123
  case 0:
124
124
  tag = TAG + " | get_quote | ";
125
125
  _a.label = 1;
126
126
  case 1:
127
- _a.trys.push([1, 3, , 4]);
127
+ _a.trys.push([1, 4, , 5]);
128
128
  output = {};
129
129
  if (!quote.sellAsset)
130
130
  throw new Error("missing sellAsset");
@@ -144,11 +144,27 @@ var get_quote = function (quote) {
144
144
  if (!pools)
145
145
  throw Error("Unable to get pools from network!");
146
146
  log.info(tag, "pools: ", pools);
147
+ poolIn = pools.find(function (p) { return p.asset == quote.sellAsset; });
148
+ log.info(tag, "poolIn: ", poolIn);
149
+ poolOut = pools.find(function (p) { return p.asset == quote.buyAsset; });
147
150
  output.meta = {
148
- quoteMode: "MAYA-OUT"
151
+ quoteMode: "MAYA_SUPPORTED_TO_MAYA_SUPPORTED"
149
152
  };
150
153
  output.steps = 1;
151
154
  output.complete = true;
155
+ output.id = uuid();
156
+ BASE_UNIT = 1e6;
157
+ DECIMALS = 6;
158
+ sellAmountInBaseUnits = parseFloat(quote.sellAmount) * BASE_UNIT;
159
+ quoteFromNode = void 0;
160
+ return [4 /*yield*/, nodeRequest("/quote/swap?from_asset=".concat(quote.sellAsset, "&to_asset=").concat(quote.buyAsset, "&amount=").concat(sellAmountInBaseUnits, "&destination=").concat(quote.recipientAddress))];
161
+ case 3:
162
+ quoteFromNode = _a.sent();
163
+ log.info("quoteFromNode: ", quoteFromNode);
164
+ amountOutMin = quoteFromNode.amount_out_min;
165
+ inboundAddress = quoteFromNode.inbound_address;
166
+ amountOutEstimated = (parseInt(quoteFromNode.expected_amount_out) / BASE_UNIT).toFixed(DECIMALS);
167
+ output.amountOut = amountOutEstimated;
152
168
  memoInput = {
153
169
  type: 'SWAP',
154
170
  asset: quote.buyAsset,
@@ -169,7 +185,7 @@ var get_quote = function (quote) {
169
185
  chain: quote.sellAsset.split(".")[0],
170
186
  txParams: {
171
187
  senderAddress: quote.senderAddress,
172
- recipientAddress: quote.recipientAddress,
188
+ recipientAddress: quote.inboundAddress,
173
189
  amount: quote.sellAmount,
174
190
  token: quote.sellAsset.split(".")[1],
175
191
  memo: memo
@@ -179,11 +195,11 @@ var get_quote = function (quote) {
179
195
  tx
180
196
  ];
181
197
  return [2 /*return*/, output];
182
- case 3:
198
+ case 4:
183
199
  e_1 = _a.sent();
184
200
  console.error(tag, "e: ", e_1);
185
201
  throw e_1;
186
- case 4: return [2 /*return*/];
202
+ case 5: return [2 /*return*/];
187
203
  }
188
204
  });
189
205
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pioneer-platform/mayachain-client",
3
- "version": "0.0.13",
3
+ "version": "0.0.16",
4
4
  "main": "./lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "dependencies": {
@@ -30,5 +30,5 @@
30
30
  "ts-jest": "^29.0.5",
31
31
  "typescript": "^5.0.2"
32
32
  },
33
- "gitHead": "4c12b840606a82a8dabf03389e9c32c44d1efda6"
33
+ "gitHead": "c1e40e843e4fdc57c436fd16e36c2773cee756e4"
34
34
  }