@pioneer-platform/osmosis-network 8.1.33 → 8.1.36

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 +378 -118
  2. package/package.json +2 -1
package/lib/index.js CHANGED
@@ -79,6 +79,7 @@ https://github.com/osmosis-labs/osmosis-frontend/tree/master/src/stores/osmosis/
79
79
  */
80
80
  var pjson = require("../package.json");
81
81
  var TAG = " | " + pjson.name.replace("@pioneer-platform/", "") + " | ";
82
+ var lodash_1 = require("lodash");
82
83
  require("dotenv").config({ path: '../../../.env' });
83
84
  var Axios = require('axios');
84
85
  var https = require('https');
@@ -134,6 +135,9 @@ module.exports = {
134
135
  getPools: function () {
135
136
  return get_pools();
136
137
  },
138
+ getPool: function (pair) {
139
+ return get_pool(pair);
140
+ },
137
141
  getValidators: function () {
138
142
  return get_validators();
139
143
  },
@@ -152,11 +156,29 @@ module.exports = {
152
156
  getBlock: function (block) {
153
157
  return get_block(block);
154
158
  },
159
+ getEpochProvisions: function () {
160
+ return get_epoch_provisions();
161
+ },
155
162
  getTransaction: function (txid) {
156
163
  return get_transaction(txid);
157
164
  },
158
- getStakingTxs: function (address) {
159
- return get_staking_txs(address);
165
+ getMintParams: function () {
166
+ return get_mint_params();
167
+ },
168
+ getSupply: function (denom) {
169
+ return get_total_supply(denom);
170
+ },
171
+ getPoolInfo: function () {
172
+ return get_pool_info();
173
+ },
174
+ getDistrobution: function () {
175
+ return get_distrobution_params();
176
+ },
177
+ getAPR: function () {
178
+ return get_APR();
179
+ },
180
+ getEpochs: function () {
181
+ return get_epochs();
160
182
  },
161
183
  transaction: function (txid) {
162
184
  return get_transaction(txid);
@@ -168,9 +190,215 @@ module.exports = {
168
190
  /**********************************
169
191
  // Lib
170
192
  //**********************************/
193
+ var get_APR = function () {
194
+ return __awaiter(this, void 0, void 0, function () {
195
+ var tag, mintParams, distributionProportions, getEpochs, epochProvisionInfo, durationSeconds, epochProvision, poolInfo, bondedToken, mintingEpochProvision, yearMintingProvision, totalSupply, ratio, inflation, apr, e_1;
196
+ return __generator(this, function (_a) {
197
+ switch (_a.label) {
198
+ case 0:
199
+ tag = TAG + " | get_APR | ";
200
+ _a.label = 1;
201
+ case 1:
202
+ _a.trys.push([1, 6, , 7]);
203
+ return [4 /*yield*/, get_mint_params()];
204
+ case 2:
205
+ mintParams = _a.sent();
206
+ log.info(tag, "mintParams:", mintParams);
207
+ distributionProportions = mintParams.params.distribution_proportions.staking;
208
+ log.info(tag, "distributionProportions:", distributionProportions);
209
+ return [4 /*yield*/, get_epochs()];
210
+ case 3:
211
+ getEpochs = _a.sent();
212
+ log.info(tag, "getEpochs:", getEpochs);
213
+ epochProvisionInfo = getEpochs.epochs.filter(function (e) { return e.identifier === 'day'; });
214
+ epochProvisionInfo = epochProvisionInfo[0];
215
+ log.info(tag, "epochProvisionInfo:", epochProvisionInfo);
216
+ durationSeconds = epochProvisionInfo.duration.replace("s", "");
217
+ log.info(tag, "durationSeconds:", durationSeconds);
218
+ return [4 /*yield*/, get_epoch_provisions()
219
+ //get bonded tokens
220
+ ];
221
+ case 4:
222
+ epochProvision = _a.sent();
223
+ return [4 /*yield*/, get_pool_info()];
224
+ case 5:
225
+ poolInfo = _a.sent();
226
+ bondedToken = poolInfo.pool.bonded_tokens;
227
+ log.info(tag, "bondedToken:", bondedToken);
228
+ // mintingEpochProvision = epochProvision * distributionProportions
229
+ log.info(tag, "epochProvision:", epochProvision);
230
+ log.info(tag, "distributionProportions:", distributionProportions);
231
+ mintingEpochProvision = epochProvision * distributionProportions;
232
+ log.info(tag, "mintingEpochProvision:", mintingEpochProvision);
233
+ yearMintingProvision = mintingEpochProvision * ((365 * 24 * 3600) / durationSeconds);
234
+ log.info(tag, "yearMintingProvision:", yearMintingProvision);
235
+ totalSupply = 1000000000;
236
+ // //let totalSupply = await get_total_supply('uosmo')
237
+ // log.info(tag,"totalSupply:",totalSupply)
238
+ // totalSupply = totalSupply.result.amount
239
+ // log.info(tag,"totalSupply:",totalSupply)
240
+ if (!totalSupply)
241
+ throw Error("unable to calc APR: missing totalSupply");
242
+ if (!epochProvision)
243
+ throw Error("unable to calc APR: missing epochProvision");
244
+ ratio = bondedToken / totalSupply;
245
+ log.info(tag, "ratio:", ratio);
246
+ inflation = yearMintingProvision / totalSupply;
247
+ log.info(tag, "inflation:", inflation);
248
+ apr = inflation / ratio;
249
+ log.info(tag, "apr:", apr);
250
+ apr = apr * 100;
251
+ return [2 /*return*/, apr];
252
+ case 6:
253
+ e_1 = _a.sent();
254
+ throw e_1;
255
+ case 7: return [2 /*return*/];
256
+ }
257
+ });
258
+ });
259
+ };
260
+ var get_distrobution_params = function () {
261
+ return __awaiter(this, void 0, void 0, function () {
262
+ var tag, output, txInfo, e_2;
263
+ return __generator(this, function (_a) {
264
+ switch (_a.label) {
265
+ case 0:
266
+ tag = TAG + " | get_distrobution_params | ";
267
+ output = {};
268
+ _a.label = 1;
269
+ case 1:
270
+ _a.trys.push([1, 3, , 4]);
271
+ return [4 /*yield*/, axios({ method: 'GET', url: URL_OSMO_LCD + '/cosmos/distribution/v1beta1/params' })];
272
+ case 2:
273
+ txInfo = _a.sent();
274
+ return [2 /*return*/, txInfo.data];
275
+ case 3:
276
+ e_2 = _a.sent();
277
+ throw e_2;
278
+ case 4: return [2 /*return*/];
279
+ }
280
+ });
281
+ });
282
+ };
283
+ var get_pool_info = function () {
284
+ return __awaiter(this, void 0, void 0, function () {
285
+ var tag, output, txInfo, e_3;
286
+ return __generator(this, function (_a) {
287
+ switch (_a.label) {
288
+ case 0:
289
+ tag = TAG + " | get_pool_info | ";
290
+ output = {};
291
+ _a.label = 1;
292
+ case 1:
293
+ _a.trys.push([1, 3, , 4]);
294
+ return [4 /*yield*/, axios({ method: 'GET', url: URL_OSMO_LCD + '/cosmos/staking/v1beta1/pool' })];
295
+ case 2:
296
+ txInfo = _a.sent();
297
+ return [2 /*return*/, txInfo.data];
298
+ case 3:
299
+ e_3 = _a.sent();
300
+ throw e_3;
301
+ case 4: return [2 /*return*/];
302
+ }
303
+ });
304
+ });
305
+ };
306
+ var get_epoch_provisions = function () {
307
+ return __awaiter(this, void 0, void 0, function () {
308
+ var tag, output, txInfo, e_4;
309
+ return __generator(this, function (_a) {
310
+ switch (_a.label) {
311
+ case 0:
312
+ tag = TAG + " | get_total_supply | ";
313
+ output = {};
314
+ _a.label = 1;
315
+ case 1:
316
+ _a.trys.push([1, 3, , 4]);
317
+ return [4 /*yield*/, axios({ method: 'GET', url: URL_OSMO_LCD + '/osmosis/mint/v1beta1/epoch_provisions' })];
318
+ case 2:
319
+ txInfo = _a.sent();
320
+ return [2 /*return*/, txInfo.data.epoch_provisions];
321
+ case 3:
322
+ e_4 = _a.sent();
323
+ throw e_4;
324
+ case 4: return [2 /*return*/];
325
+ }
326
+ });
327
+ });
328
+ };
329
+ var get_total_supply = function (denom) {
330
+ return __awaiter(this, void 0, void 0, function () {
331
+ var tag, output, txInfo, e_5;
332
+ return __generator(this, function (_a) {
333
+ switch (_a.label) {
334
+ case 0:
335
+ tag = TAG + " | get_total_supply | ";
336
+ output = {};
337
+ _a.label = 1;
338
+ case 1:
339
+ _a.trys.push([1, 3, , 4]);
340
+ log.info(tag, "url: ", URL_OSMO_LCD + '/bank/total/' + denom);
341
+ return [4 /*yield*/, axios({ method: 'GET', url: URL_OSMO_LCD + '/bank/total/' + denom })];
342
+ case 2:
343
+ txInfo = _a.sent();
344
+ return [2 /*return*/, txInfo.data];
345
+ case 3:
346
+ e_5 = _a.sent();
347
+ throw e_5;
348
+ case 4: return [2 /*return*/];
349
+ }
350
+ });
351
+ });
352
+ };
353
+ var get_mint_params = function () {
354
+ return __awaiter(this, void 0, void 0, function () {
355
+ var tag, output, txInfo, e_6;
356
+ return __generator(this, function (_a) {
357
+ switch (_a.label) {
358
+ case 0:
359
+ tag = TAG + " | get_mint_params | ";
360
+ output = {};
361
+ _a.label = 1;
362
+ case 1:
363
+ _a.trys.push([1, 3, , 4]);
364
+ return [4 /*yield*/, axios({ method: 'GET', url: URL_OSMO_LCD + '/osmosis/mint/v1beta1/params' })];
365
+ case 2:
366
+ txInfo = _a.sent();
367
+ return [2 /*return*/, txInfo.data];
368
+ case 3:
369
+ e_6 = _a.sent();
370
+ throw e_6;
371
+ case 4: return [2 /*return*/];
372
+ }
373
+ });
374
+ });
375
+ };
376
+ var get_epochs = function () {
377
+ return __awaiter(this, void 0, void 0, function () {
378
+ var tag, output, txInfo, e_7;
379
+ return __generator(this, function (_a) {
380
+ switch (_a.label) {
381
+ case 0:
382
+ tag = TAG + " | get_epochs | ";
383
+ output = {};
384
+ _a.label = 1;
385
+ case 1:
386
+ _a.trys.push([1, 3, , 4]);
387
+ return [4 /*yield*/, axios({ method: 'GET', url: URL_OSMO_LCD + "/osmosis/epochs/v1beta1/epochs" })];
388
+ case 2:
389
+ txInfo = _a.sent();
390
+ return [2 /*return*/, txInfo.data];
391
+ case 3:
392
+ e_7 = _a.sent();
393
+ throw e_7;
394
+ case 4: return [2 /*return*/];
395
+ }
396
+ });
397
+ });
398
+ };
171
399
  var get_voucher_info = function (voucher) {
172
400
  return __awaiter(this, void 0, void 0, function () {
173
- var tag, url, txInfo, e_1;
401
+ var tag, url, txInfo, e_8;
174
402
  return __generator(this, function (_a) {
175
403
  switch (_a.label) {
176
404
  case 0:
@@ -183,11 +411,11 @@ var get_voucher_info = function (voucher) {
183
411
  return [4 /*yield*/, axios({ method: 'GET', url: url })];
184
412
  case 2:
185
413
  txInfo = _a.sent();
186
- log.debug(tag, "txInfo: ", txInfo.data);
414
+ log.info(tag, "txInfo: ", txInfo.data);
187
415
  return [2 /*return*/, txInfo.data];
188
416
  case 3:
189
- e_1 = _a.sent();
190
- throw e_1;
417
+ e_8 = _a.sent();
418
+ throw e_8;
191
419
  case 4: return [2 /*return*/];
192
420
  }
193
421
  });
@@ -195,7 +423,7 @@ var get_voucher_info = function (voucher) {
195
423
  };
196
424
  var get_block = function (height) {
197
425
  return __awaiter(this, void 0, void 0, function () {
198
- var tag, output, txInfo, e_2;
426
+ var tag, output, txInfo, e_9;
199
427
  return __generator(this, function (_a) {
200
428
  switch (_a.label) {
201
429
  case 0:
@@ -227,9 +455,9 @@ var get_block = function (height) {
227
455
  log.debug(tag, "txInfo: ", txInfo.data.block.data.txs);
228
456
  return [2 /*return*/, txInfo.data];
229
457
  case 3:
230
- e_2 = _a.sent();
458
+ e_9 = _a.sent();
231
459
  //TODO dont shh error fix em
232
- throw e_2;
460
+ throw e_9;
233
461
  case 4: return [2 /*return*/];
234
462
  }
235
463
  });
@@ -237,7 +465,7 @@ var get_block = function (height) {
237
465
  };
238
466
  var get_staking_txs = function (address) {
239
467
  return __awaiter(this, void 0, void 0, function () {
240
- var tag, output, txInfo, e_3;
468
+ var tag, output, txInfo, e_10;
241
469
  return __generator(this, function (_a) {
242
470
  switch (_a.label) {
243
471
  case 0:
@@ -252,8 +480,8 @@ var get_staking_txs = function (address) {
252
480
  log.debug(tag, "txInfo: ", txInfo.data);
253
481
  return [2 /*return*/, txInfo.data];
254
482
  case 3:
255
- e_3 = _a.sent();
256
- throw e_3;
483
+ e_10 = _a.sent();
484
+ throw e_10;
257
485
  case 4: return [2 /*return*/];
258
486
  }
259
487
  });
@@ -261,7 +489,7 @@ var get_staking_txs = function (address) {
261
489
  };
262
490
  var get_rewards = function (address) {
263
491
  return __awaiter(this, void 0, void 0, function () {
264
- var tag, output, resp, output_1, e_4;
492
+ var tag, output, resp, output_1, e_11;
265
493
  return __generator(this, function (_a) {
266
494
  switch (_a.label) {
267
495
  case 0:
@@ -277,8 +505,8 @@ var get_rewards = function (address) {
277
505
  output_1 = resp.data;
278
506
  return [2 /*return*/, output_1];
279
507
  case 3:
280
- e_4 = _a.sent();
281
- throw e_4;
508
+ e_11 = _a.sent();
509
+ throw e_11;
282
510
  case 4: return [2 /*return*/];
283
511
  }
284
512
  });
@@ -287,7 +515,7 @@ var get_rewards = function (address) {
287
515
  //
288
516
  var get_block_height = function () {
289
517
  return __awaiter(this, void 0, void 0, function () {
290
- var tag, output, resp, height, e_5;
518
+ var tag, output, resp, height, e_12;
291
519
  return __generator(this, function (_a) {
292
520
  switch (_a.label) {
293
521
  case 0:
@@ -303,32 +531,55 @@ var get_block_height = function () {
303
531
  height = resp.data.block.header.height;
304
532
  return [2 /*return*/, parseInt(height)];
305
533
  case 3:
306
- e_5 = _a.sent();
307
- throw e_5;
534
+ e_12 = _a.sent();
535
+ throw e_12;
308
536
  case 4: return [2 /*return*/];
309
537
  }
310
538
  });
311
539
  });
312
540
  };
313
- var get_pool = function (poolId) {
541
+ //get pools
542
+ var get_pool = function (pair) {
314
543
  return __awaiter(this, void 0, void 0, function () {
315
- var tag, output, poolInfo, e_6;
544
+ var tag, output, assets, poolInfo, sellAssetDenom_1, buyAssetDenom_1, foundPool, e_13;
316
545
  return __generator(this, function (_a) {
317
546
  switch (_a.label) {
318
547
  case 0:
319
- tag = TAG + " | get_pools | ";
548
+ tag = TAG + " | get_pool | ";
320
549
  output = {};
321
550
  _a.label = 1;
322
551
  case 1:
323
552
  _a.trys.push([1, 3, , 4]);
324
- return [4 /*yield*/, axios({ method: 'GET', url: URL_OSMO_LCD + '/osmosis/gamm/v1beta1/pool/' + poolId })];
553
+ if (pair.indexOf("_") === -1)
554
+ throw Error("Pair needs to use _ example (ATOM_OSMO)");
555
+ assets = pair.split("_");
556
+ if (assets[0] === 'ATOM')
557
+ assets[0] = "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2";
558
+ if (assets[1] === 'ATOM')
559
+ assets[1] = "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2";
560
+ if (assets[0] === 'OSMO')
561
+ assets[0] = "uosmo";
562
+ if (assets[1] === 'OSMO')
563
+ assets[1] = "uosmo";
564
+ return [4 /*yield*/, axios({ method: 'GET', url: URL_OSMO_LCD + '/osmosis/gamm/v1beta1/pools' })
565
+ // log.debug(tag,"poolInfo: ",poolInfo.data)
566
+ ];
325
567
  case 2:
326
568
  poolInfo = _a.sent();
327
- log.debug(tag, "poolInfo: ", poolInfo.data);
328
- return [2 /*return*/, poolInfo.data];
569
+ sellAssetDenom_1 = assets[0];
570
+ buyAssetDenom_1 = assets[1];
571
+ foundPool = lodash_1.find(poolInfo.data.pools, function (pool) {
572
+ var token0Denom = pool.poolAssets[0].token.denom;
573
+ var token1Denom = pool.poolAssets[1].token.denom;
574
+ return ((token0Denom === sellAssetDenom_1 && token1Denom === buyAssetDenom_1) ||
575
+ (token0Denom === buyAssetDenom_1 && token1Denom === sellAssetDenom_1));
576
+ });
577
+ if (!foundPool)
578
+ throw new Error('Couldnt find pool');
579
+ return [2 /*return*/, foundPool];
329
580
  case 3:
330
- e_6 = _a.sent();
331
- throw e_6;
581
+ e_13 = _a.sent();
582
+ throw e_13;
332
583
  case 4: return [2 /*return*/];
333
584
  }
334
585
  });
@@ -337,7 +588,7 @@ var get_pool = function (poolId) {
337
588
  //get pools
338
589
  var get_pools = function () {
339
590
  return __awaiter(this, void 0, void 0, function () {
340
- var tag, output, poolInfo, e_7;
591
+ var tag, output, poolInfo, e_14;
341
592
  return __generator(this, function (_a) {
342
593
  switch (_a.label) {
343
594
  case 0:
@@ -356,8 +607,8 @@ var get_pools = function () {
356
607
  // log.debug(tag,"txInfo: ",poolInfo.data)
357
608
  return [2 /*return*/, poolInfo.data];
358
609
  case 3:
359
- e_7 = _a.sent();
360
- throw e_7;
610
+ e_14 = _a.sent();
611
+ throw e_14;
361
612
  case 4: return [2 /*return*/];
362
613
  }
363
614
  });
@@ -365,7 +616,7 @@ var get_pools = function () {
365
616
  };
366
617
  var get_delegations_by_address = function (address) {
367
618
  return __awaiter(this, void 0, void 0, function () {
368
- var tag, output, resp, output_2, e_8;
619
+ var tag, output, resp, output_2, e_15;
369
620
  return __generator(this, function (_a) {
370
621
  switch (_a.label) {
371
622
  case 0:
@@ -381,8 +632,8 @@ var get_delegations_by_address = function (address) {
381
632
  output_2 = resp.data.result;
382
633
  return [2 /*return*/, output_2];
383
634
  case 3:
384
- e_8 = _a.sent();
385
- throw e_8;
635
+ e_15 = _a.sent();
636
+ throw e_15;
386
637
  case 4: return [2 /*return*/];
387
638
  }
388
639
  });
@@ -390,7 +641,7 @@ var get_delegations_by_address = function (address) {
390
641
  };
391
642
  var get_delegations = function (address, valAddress) {
392
643
  return __awaiter(this, void 0, void 0, function () {
393
- var tag, output, txInfo, e_9;
644
+ var tag, output, txInfo, e_16;
394
645
  return __generator(this, function (_a) {
395
646
  switch (_a.label) {
396
647
  case 0:
@@ -409,8 +660,8 @@ var get_delegations = function (address, valAddress) {
409
660
  // log.debug(tag,"txInfo: ",txInfo.data)
410
661
  return [2 /*return*/, txInfo.data];
411
662
  case 3:
412
- e_9 = _a.sent();
413
- throw e_9;
663
+ e_16 = _a.sent();
664
+ throw e_16;
414
665
  case 4: return [2 /*return*/];
415
666
  }
416
667
  });
@@ -418,7 +669,7 @@ var get_delegations = function (address, valAddress) {
418
669
  };
419
670
  var get_validators = function () {
420
671
  return __awaiter(this, void 0, void 0, function () {
421
- var tag, output, txInfo, validators, e_10;
672
+ var tag, output, txInfo, validators, e_17;
422
673
  return __generator(this, function (_a) {
423
674
  switch (_a.label) {
424
675
  case 0:
@@ -442,8 +693,8 @@ var get_validators = function () {
442
693
  validators.reverse();
443
694
  return [2 /*return*/, validators];
444
695
  case 3:
445
- e_10 = _a.sent();
446
- throw e_10;
696
+ e_17 = _a.sent();
697
+ throw e_17;
447
698
  case 4: return [2 /*return*/];
448
699
  }
449
700
  });
@@ -451,7 +702,7 @@ var get_validators = function () {
451
702
  };
452
703
  var get_transaction = function (txid) {
453
704
  return __awaiter(this, void 0, void 0, function () {
454
- var tag, txInfo, e_11;
705
+ var tag, txInfo, e_18;
455
706
  return __generator(this, function (_a) {
456
707
  switch (_a.label) {
457
708
  case 0:
@@ -465,9 +716,9 @@ var get_transaction = function (txid) {
465
716
  log.debug(tag, "txInfo: ", txInfo.data);
466
717
  return [2 /*return*/, txInfo.data];
467
718
  case 3:
468
- e_11 = _a.sent();
719
+ e_18 = _a.sent();
469
720
  //if not found
470
- throw Error(e_11);
721
+ throw Error(e_18);
471
722
  case 4: return [2 /*return*/];
472
723
  }
473
724
  });
@@ -475,7 +726,7 @@ var get_transaction = function (txid) {
475
726
  };
476
727
  var broadcast_transaction = function (tx) {
477
728
  return __awaiter(this, void 0, void 0, function () {
478
- var tag, output, txBytesBase64, urlRemote, result2, logSend, e_12, e_13;
729
+ var tag, output, payload, urlRemote, result2, logSend, e_19, e_20;
479
730
  return __generator(this, function (_a) {
480
731
  switch (_a.label) {
481
732
  case 0:
@@ -489,19 +740,24 @@ var broadcast_transaction = function (tx) {
489
740
  _a.label = 2;
490
741
  case 2:
491
742
  _a.trys.push([2, 4, , 5]);
492
- txBytesBase64 = Buffer.from(tx, 'binary').toString('base64');
493
- urlRemote = URL_OSMO_LCD + '/txs';
743
+ payload = {
744
+ "tx_bytes": tx,
745
+ "mode": "BROADCAST_MODE_SYNC"
746
+ };
747
+ urlRemote = URL_OSMO_LCD + '/cosmos/tx/v1beta1/txs';
494
748
  log.debug(tag, "urlRemote: ", urlRemote);
495
749
  return [4 /*yield*/, axios({
496
750
  url: urlRemote,
497
751
  method: 'POST',
498
- data: tx,
752
+ data: payload,
499
753
  })];
500
754
  case 3:
501
755
  result2 = _a.sent();
502
- log.debug(tag, '** Broadcast ** REMOTE: result: ', result2.data);
503
- if (result2.data.txhash)
504
- output.txid = result2.data.txhash;
756
+ log.info(tag, '** Broadcast ** REMOTE: result: ', result2.data);
757
+ if (result2.data.tx_response.txhash) {
758
+ output.txid = result2.data.tx_response.txhash;
759
+ output.success = true;
760
+ }
505
761
  //verify success
506
762
  if (result2.data.raw_log) {
507
763
  logSend = result2.data.raw_log;
@@ -513,16 +769,16 @@ var broadcast_transaction = function (tx) {
513
769
  output.raw = result2.data;
514
770
  return [3 /*break*/, 5];
515
771
  case 4:
516
- e_12 = _a.sent();
772
+ e_19 = _a.sent();
517
773
  //log.error(tag,"failed second broadcast e: ",e.response)
518
- log.error(tag, e_12);
519
- log.error(tag, e_12.response);
520
- log.error(tag, e_12.response.data);
521
- log.error(tag, e_12.response.data.error);
522
- log.error(tag, e_12.response.data.error.indexOf('RPC error -32603 - Internal error: Tx already exists in cache'));
774
+ log.error(tag, e_19);
775
+ log.error(tag, e_19.response);
776
+ log.error(tag, e_19.response.data);
777
+ log.error(tag, e_19.response.data.error);
778
+ log.error(tag, e_19.response.data.error.indexOf('RPC error -32603 - Internal error: Tx already exists in cache'));
523
779
  //throw e
524
780
  output.success = false;
525
- output.error = e_12.response.data.error;
781
+ output.error = e_19.response.data.error;
526
782
  return [3 /*break*/, 5];
527
783
  case 5:
528
784
  if (output.txid) {
@@ -530,8 +786,8 @@ var broadcast_transaction = function (tx) {
530
786
  }
531
787
  return [2 /*return*/, output];
532
788
  case 6:
533
- e_13 = _a.sent();
534
- console.error(tag, "throw error: ", e_13);
789
+ e_20 = _a.sent();
790
+ console.error(tag, "throw error: ", e_20);
535
791
  return [2 /*return*/, output];
536
792
  case 7: return [2 /*return*/];
537
793
  }
@@ -540,7 +796,7 @@ var broadcast_transaction = function (tx) {
540
796
  };
541
797
  var get_account_info = function (address) {
542
798
  return __awaiter(this, void 0, void 0, function () {
543
- var tag, txInfo, e_14;
799
+ var tag, txInfo, e_21;
544
800
  return __generator(this, function (_a) {
545
801
  switch (_a.label) {
546
802
  case 0:
@@ -556,9 +812,9 @@ var get_account_info = function (address) {
556
812
  log.debug(tag, "txInfo: ", txInfo.data);
557
813
  return [2 /*return*/, txInfo.data];
558
814
  case 3:
559
- e_14 = _a.sent();
560
- log.error(tag, "e: ", e_14);
561
- throw e_14;
815
+ e_21 = _a.sent();
816
+ log.error(tag, "e: ", e_21);
817
+ throw e_21;
562
818
  case 4: return [2 /*return*/];
563
819
  }
564
820
  });
@@ -642,7 +898,7 @@ var normalize_tx = function (tx, address) {
642
898
  };
643
899
  var get_txs_at_height = function (height) {
644
900
  return __awaiter(this, void 0, void 0, function () {
645
- var tag, output, url, resultSends, sends, e_15;
901
+ var tag, output, url, resultSends, sends, e_22;
646
902
  return __generator(this, function (_a) {
647
903
  switch (_a.label) {
648
904
  case 0:
@@ -651,7 +907,9 @@ var get_txs_at_height = function (height) {
651
907
  case 1:
652
908
  _a.trys.push([1, 3, , 4]);
653
909
  output = [];
654
- url = URL_OSMO_LCD + '/txs?tx.height=' + height;
910
+ url = URL_OSMO_LCD + '/cosmos/tx/v1beta1/txs?events=tx.height=%27' + height + '%27';
911
+ // let url = URL_OSMO_LCD+ '/txs?block.height='+height
912
+ // let url = URL_OSMO_LCD+ '/txs?tx.height='+height
655
913
  //tx.height=
656
914
  //?tx.height=1891147&page=1
657
915
  log.debug(tag, "url: ", url);
@@ -665,9 +923,9 @@ var get_txs_at_height = function (height) {
665
923
  //log.debug('sends: ', sends)
666
924
  return [2 /*return*/, sends];
667
925
  case 3:
668
- e_15 = _a.sent();
669
- log.error(tag, "e: ", e_15);
670
- throw e_15;
926
+ e_22 = _a.sent();
927
+ log.error(tag, "e: ", e_22);
928
+ throw e_22;
671
929
  case 4: return [2 /*return*/];
672
930
  }
673
931
  });
@@ -675,16 +933,17 @@ var get_txs_at_height = function (height) {
675
933
  };
676
934
  var get_txs_by_address = function (address) {
677
935
  return __awaiter(this, void 0, void 0, function () {
678
- var tag, output, url, resultSends, sends, i, tx, resultRecieves, receives, i, tx, e_16;
936
+ var tag, output, url, resultSends, sends, i, tx, e_23;
679
937
  return __generator(this, function (_a) {
680
938
  switch (_a.label) {
681
939
  case 0:
682
940
  tag = TAG + " | get_txs_by_address | ";
683
941
  _a.label = 1;
684
942
  case 1:
685
- _a.trys.push([1, 4, , 5]);
943
+ _a.trys.push([1, 3, , 4]);
686
944
  output = [];
687
- url = URL_OSMO_LCD + '/txs?message.sender=' + address;
945
+ url = URL_OSMO_LCD + '/cosmos/tx/v1beta1/txs?events=transfer.sender=%27' + address + '%27';
946
+ //let url = URL_OSMO_LCD+ '/txs?message.sender='+address
688
947
  log.debug(tag, "url: ", url);
689
948
  return [4 /*yield*/, axios({
690
949
  url: url,
@@ -702,29 +961,30 @@ var get_txs_by_address = function (address) {
702
961
  }
703
962
  }
704
963
  //receives
705
- url = URL_OSMO_LCD + '/txs?transfer.recipient=' + address;
706
- return [4 /*yield*/, axios({
707
- url: url,
708
- method: 'GET'
709
- })];
710
- case 3:
711
- resultRecieves = _a.sent();
712
- receives = resultRecieves.data;
713
- //log.debug('receives: ', receives)
714
- if (receives.txs) {
715
- for (i = 0; i < receives.txs.length; i++) {
716
- tx = receives.txs[i];
717
- //normalize
718
- tx = normalize_tx(tx, address);
719
- output.push(tx);
720
- }
721
- }
964
+ //url = URL_OSMO_LCD+ '/txs?transfer.recipient='+address
965
+ //
966
+ // url = URL_OSMO_LCD+ '/cosmos/tx/v1beta1/txs?events=transfer.recipient=%27'+address+'%27'
967
+ // //console.log("URL_OSMO_LCD: ",url)
968
+ // let resultRecieves = await axios({
969
+ // url: url,
970
+ // method: 'GET'
971
+ // })
972
+ // let receives = resultRecieves.data
973
+ // //log.debug('receives: ', JSON.stringify(receives.tx_responses))
974
+ // if(receives.tx_responses){
975
+ // for(let i = 0; i < receives.txs.length; i++ ){
976
+ // let tx = receives.txs[i]
977
+ // //normalize
978
+ // // tx = normalize_tx(tx,address)
979
+ // output.push(tx)
980
+ // }
981
+ // }
722
982
  return [2 /*return*/, output];
723
- case 4:
724
- e_16 = _a.sent();
725
- log.error(tag, "e: ", e_16);
726
- throw e_16;
727
- case 5: return [2 /*return*/];
983
+ case 3:
984
+ e_23 = _a.sent();
985
+ log.error(tag, "e: ", e_23);
986
+ throw e_23;
987
+ case 4: return [2 /*return*/];
728
988
  }
729
989
  });
730
990
  });
@@ -732,7 +992,7 @@ var get_txs_by_address = function (address) {
732
992
  var get_balances = function (address) {
733
993
  var _a;
734
994
  return __awaiter(this, void 0, void 0, function () {
735
- var tag, output, accountInfo, i, entry, balance, voucher, voucherInfo, balance, poolInfo, totalShares, poolAssets, assetAtom, assetOsmo, totalAtom, totalOsmo, yourLpTokens, yourLpPercent, yourAtomInPool, yourOsmoInPool, balance, e_17, e_18;
995
+ var tag, output, accountInfo, i, entry, balance, voucher, voucherInfo, balance, poolInfo, totalShares, poolAssets, assetAtom, assetOsmo, totalAtom, totalOsmo, yourLpTokens, yourLpPercent, yourAtomInPool, yourOsmoInPool, balance, e_24, e_25;
736
996
  return __generator(this, function (_b) {
737
997
  switch (_b.label) {
738
998
  case 0:
@@ -778,7 +1038,7 @@ var get_balances = function (address) {
778
1038
  asset: 'ATOM',
779
1039
  denom: voucherInfo.denom_trace.base_denom,
780
1040
  channel: voucherInfo.denom_trace.path,
781
- balance: entry.amount
1041
+ balance: entry.amount / 1000000
782
1042
  };
783
1043
  output.push(balance);
784
1044
  }
@@ -793,27 +1053,27 @@ var get_balances = function (address) {
793
1053
  case 7:
794
1054
  poolInfo = _b.sent();
795
1055
  poolInfo = poolInfo.pools[0];
796
- log.info(tag, "poolInfo: ", poolInfo);
1056
+ log.debug(tag, "poolInfo: ", poolInfo);
797
1057
  totalShares = poolInfo.totalShares.amount / 1000000000000000000;
798
- log.info(tag, "totalShares: ", totalShares);
1058
+ log.debug(tag, "totalShares: ", totalShares);
799
1059
  poolAssets = poolInfo.poolAssets;
800
- log.info(tag, "poolAssets: ", poolAssets);
1060
+ log.debug(tag, "poolAssets: ", poolAssets);
801
1061
  assetAtom = poolAssets[0];
802
- log.info(tag, "assetAtom: ", assetAtom);
1062
+ log.debug(tag, "assetAtom: ", assetAtom);
803
1063
  assetOsmo = poolAssets[1];
804
- log.info(tag, "assetOsmo: ", assetOsmo);
1064
+ log.debug(tag, "assetOsmo: ", assetOsmo);
805
1065
  totalAtom = assetAtom.token.amount / 10000000;
806
- log.info(tag, "totalAtom: ", totalAtom);
1066
+ log.debug(tag, "totalAtom: ", totalAtom);
807
1067
  totalOsmo = assetOsmo.token.amount / 1000000;
808
- log.info(tag, "totalOsmo: ", totalOsmo);
1068
+ log.debug(tag, "totalOsmo: ", totalOsmo);
809
1069
  yourLpTokens = entry.amount / 1000000000000000000;
810
- log.info(tag, "yourLpTokens: ", yourLpTokens);
1070
+ log.debug(tag, "yourLpTokens: ", yourLpTokens);
811
1071
  yourLpPercent = yourLpTokens / totalShares;
812
- log.info(tag, "yourLpPercent: ", yourLpPercent);
1072
+ log.debug(tag, "yourLpPercent: ", yourLpPercent);
813
1073
  yourAtomInPool = totalAtom * yourLpPercent;
814
- log.info(tag, "yourAtomInPool: ", yourAtomInPool);
1074
+ log.debug(tag, "yourAtomInPool: ", yourAtomInPool);
815
1075
  yourOsmoInPool = totalOsmo * yourLpPercent;
816
- log.info(tag, "yourOsmoInPool: ", yourOsmoInPool);
1076
+ log.debug(tag, "yourOsmoInPool: ", yourOsmoInPool);
817
1077
  balance = {
818
1078
  type: 'lptoken',
819
1079
  lp: true,
@@ -831,13 +1091,13 @@ var get_balances = function (address) {
831
1091
  return [3 /*break*/, 4];
832
1092
  case 9: return [3 /*break*/, 11];
833
1093
  case 10:
834
- e_17 = _b.sent();
1094
+ e_24 = _b.sent();
835
1095
  return [3 /*break*/, 11];
836
1096
  case 11: return [2 /*return*/, output];
837
1097
  case 12:
838
- e_18 = _b.sent();
839
- log.error(tag, "e: ", e_18);
840
- throw e_18;
1098
+ e_25 = _b.sent();
1099
+ log.error(tag, "e: ", e_25);
1100
+ throw e_25;
841
1101
  case 13: return [2 /*return*/];
842
1102
  }
843
1103
  });
@@ -846,7 +1106,7 @@ var get_balances = function (address) {
846
1106
  var get_balance = function (address) {
847
1107
  var _a;
848
1108
  return __awaiter(this, void 0, void 0, function () {
849
- var tag, output, accountInfo, i, entry, e_19, e_20;
1109
+ var tag, output, accountInfo, i, entry, e_26, e_27;
850
1110
  return __generator(this, function (_b) {
851
1111
  switch (_b.label) {
852
1112
  case 0:
@@ -862,7 +1122,7 @@ var get_balance = function (address) {
862
1122
  return [4 /*yield*/, axios({ method: 'GET', url: URL_OSMO_LCD + '/bank/balances/' + address })];
863
1123
  case 3:
864
1124
  accountInfo = _b.sent();
865
- log.info(tag, "accountInfo: ", accountInfo.data);
1125
+ log.debug(tag, "accountInfo: ", accountInfo.data);
866
1126
  //
867
1127
  if ((_a = accountInfo.data) === null || _a === void 0 ? void 0 : _a.result) {
868
1128
  for (i = 0; i < accountInfo.data.result.length; i++) {
@@ -875,13 +1135,13 @@ var get_balance = function (address) {
875
1135
  output = output / BASE_OSMO;
876
1136
  return [3 /*break*/, 5];
877
1137
  case 4:
878
- e_19 = _b.sent();
1138
+ e_26 = _b.sent();
879
1139
  return [3 /*break*/, 5];
880
1140
  case 5: return [2 /*return*/, output];
881
1141
  case 6:
882
- e_20 = _b.sent();
883
- log.error(tag, "e: ", e_20);
884
- throw e_20;
1142
+ e_27 = _b.sent();
1143
+ log.error(tag, "e: ", e_27);
1144
+ throw e_27;
885
1145
  case 7: return [2 /*return*/];
886
1146
  }
887
1147
  });
@@ -889,7 +1149,7 @@ var get_balance = function (address) {
889
1149
  };
890
1150
  var get_node_info_verbose = function () {
891
1151
  return __awaiter(this, void 0, void 0, function () {
892
- var tag, output, syncInfo, nodeInfo, e_21;
1152
+ var tag, output, syncInfo, nodeInfo, e_28;
893
1153
  return __generator(this, function (_a) {
894
1154
  switch (_a.label) {
895
1155
  case 0:
@@ -914,9 +1174,9 @@ var get_node_info_verbose = function () {
914
1174
  //output.height = lastBlock.data.block.header.height
915
1175
  return [2 /*return*/, output];
916
1176
  case 4:
917
- e_21 = _a.sent();
918
- log.error(tag, "e: ", e_21);
919
- throw e_21;
1177
+ e_28 = _a.sent();
1178
+ log.error(tag, "e: ", e_28);
1179
+ throw e_28;
920
1180
  case 5: return [2 /*return*/];
921
1181
  }
922
1182
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pioneer-platform/osmosis-network",
3
- "version": "8.1.33",
3
+ "version": "8.1.36",
4
4
  "main": "./lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "scripts": {
@@ -11,6 +11,7 @@
11
11
  "refresh": "rm -rf ./node_modules ./package-lock.json && npm install"
12
12
  },
13
13
  "dependencies": {
14
+ "@keplr-wallet/unit": "^0.10.2",
14
15
  "@pioneer-platform/loggerdog": "^8.1.17",
15
16
  "@tendermint/amino-js": "^0.6.2",
16
17
  "bech32": "^1.1.4",