@xchainjs/xchain-thorchain-query 0.1.5 → 0.1.6
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.esm.js +64 -34
- package/lib/index.js +64 -34
- package/lib/types.d.ts +14 -6
- package/package.json +1 -1
package/lib/index.esm.js
CHANGED
|
@@ -221,7 +221,7 @@ class Midgard {
|
|
|
221
221
|
return data;
|
|
222
222
|
}
|
|
223
223
|
catch (e) {
|
|
224
|
-
console.error(e)
|
|
224
|
+
//console.error(e)
|
|
225
225
|
}
|
|
226
226
|
}
|
|
227
227
|
throw new Error('Midgard not responding');
|
|
@@ -238,10 +238,10 @@ class Midgard {
|
|
|
238
238
|
return (yield api.getPools()).data;
|
|
239
239
|
}
|
|
240
240
|
catch (e) {
|
|
241
|
-
console.error(e)
|
|
241
|
+
//console.error(e)
|
|
242
242
|
}
|
|
243
243
|
}
|
|
244
|
-
throw Error(`Midgard not responding`);
|
|
244
|
+
throw new Error(`Midgard not responding`);
|
|
245
245
|
});
|
|
246
246
|
}
|
|
247
247
|
/**
|
|
@@ -257,7 +257,7 @@ class Midgard {
|
|
|
257
257
|
return data.int_64_values;
|
|
258
258
|
}
|
|
259
259
|
catch (e) {
|
|
260
|
-
console.error(e)
|
|
260
|
+
//console.error(e)
|
|
261
261
|
}
|
|
262
262
|
}
|
|
263
263
|
throw new Error('Midgard not responding');
|
|
@@ -277,7 +277,7 @@ class Midgard {
|
|
|
277
277
|
return value;
|
|
278
278
|
}
|
|
279
279
|
catch (e) {
|
|
280
|
-
console.error(e)
|
|
280
|
+
//console.error(e)
|
|
281
281
|
}
|
|
282
282
|
}
|
|
283
283
|
throw new Error('Midgard not responding');
|
|
@@ -318,7 +318,7 @@ class Midgard {
|
|
|
318
318
|
return +data.scannerHeight;
|
|
319
319
|
}
|
|
320
320
|
catch (e) {
|
|
321
|
-
console.error(e)
|
|
321
|
+
//console.error(e)
|
|
322
322
|
}
|
|
323
323
|
}
|
|
324
324
|
throw Error(`Midgard not responding`);
|
|
@@ -337,7 +337,7 @@ class Midgard {
|
|
|
337
337
|
return actions;
|
|
338
338
|
}
|
|
339
339
|
catch (e) {
|
|
340
|
-
console.error(e)
|
|
340
|
+
//console.error(e)
|
|
341
341
|
}
|
|
342
342
|
}
|
|
343
343
|
throw Error(`Midgard not responding`);
|
|
@@ -356,7 +356,7 @@ class Midgard {
|
|
|
356
356
|
return memberDetail;
|
|
357
357
|
}
|
|
358
358
|
catch (e) {
|
|
359
|
-
console.error(e)
|
|
359
|
+
//console.error(e)
|
|
360
360
|
}
|
|
361
361
|
}
|
|
362
362
|
throw Error(`Midgard not responding`);
|
|
@@ -375,7 +375,7 @@ class Midgard {
|
|
|
375
375
|
return poolDetail;
|
|
376
376
|
}
|
|
377
377
|
catch (e) {
|
|
378
|
-
console.error(e)
|
|
378
|
+
//console.error(e)
|
|
379
379
|
}
|
|
380
380
|
}
|
|
381
381
|
throw Error(`Midgard not responding`);
|
|
@@ -402,7 +402,7 @@ class Midgard {
|
|
|
402
402
|
// if (resp.status == 404) {
|
|
403
403
|
// return undefined
|
|
404
404
|
// }
|
|
405
|
-
console.error(e)
|
|
405
|
+
//console.error(e)
|
|
406
406
|
}
|
|
407
407
|
}
|
|
408
408
|
throw Error(`Midgard not responding`);
|
|
@@ -724,7 +724,7 @@ class Thornode {
|
|
|
724
724
|
return queueScheduled.data;
|
|
725
725
|
}
|
|
726
726
|
catch (e) {
|
|
727
|
-
console.error(e)
|
|
727
|
+
//console.error(e)
|
|
728
728
|
throw new Error(`THORNode not responding`);
|
|
729
729
|
}
|
|
730
730
|
}
|
|
@@ -767,7 +767,7 @@ class Thornode {
|
|
|
767
767
|
return lastBlock.data;
|
|
768
768
|
}
|
|
769
769
|
catch (e) {
|
|
770
|
-
console.error(e)
|
|
770
|
+
//console.error(e)
|
|
771
771
|
}
|
|
772
772
|
}
|
|
773
773
|
throw new Error(`THORNode not responding`);
|
|
@@ -781,12 +781,11 @@ class Thornode {
|
|
|
781
781
|
return __awaiter(this, void 0, void 0, function* () {
|
|
782
782
|
for (const api of this.poolsApi) {
|
|
783
783
|
try {
|
|
784
|
-
// console.log(console.log(JSON.stringify(api, null, 2)))
|
|
785
784
|
const pools = yield api.pools();
|
|
786
785
|
return pools.data;
|
|
787
786
|
}
|
|
788
787
|
catch (e) {
|
|
789
|
-
console.error(e)
|
|
788
|
+
//console.error(e)
|
|
790
789
|
}
|
|
791
790
|
}
|
|
792
791
|
throw new Error(`THORNode not responding`);
|
|
@@ -807,7 +806,7 @@ class Thornode {
|
|
|
807
806
|
return lps.find((lp) => lp.asset_address === address || lp.rune_address === address);
|
|
808
807
|
}
|
|
809
808
|
catch (e) {
|
|
810
|
-
console.error(e)
|
|
809
|
+
//console.error(e)
|
|
811
810
|
}
|
|
812
811
|
}
|
|
813
812
|
throw new Error(`THORNode not responding`);
|
|
@@ -828,7 +827,7 @@ class Thornode {
|
|
|
828
827
|
return resp;
|
|
829
828
|
}
|
|
830
829
|
catch (e) {
|
|
831
|
-
console.error(e)
|
|
830
|
+
//console.error(e)
|
|
832
831
|
}
|
|
833
832
|
}
|
|
834
833
|
throw new Error(`THORNode not responding`);
|
|
@@ -1284,11 +1283,13 @@ const getLiquidityProtectionData = (depositValue, poolShare, block) => {
|
|
|
1284
1283
|
const currentHeight = block.current;
|
|
1285
1284
|
const heightLastAdded = block.lastAdded || 0; //default to zero if undefined
|
|
1286
1285
|
const blocksforfullprotection = block.fullProtection;
|
|
1287
|
-
const
|
|
1286
|
+
const fractionOfFullILPProtection = (currentHeight - heightLastAdded) / blocksforfullprotection;
|
|
1287
|
+
const protectionProgress = Math.min(fractionOfFullILPProtection, 1); // percentage of entitlement, max 100%
|
|
1288
1288
|
const result = coverage.times(protectionProgress); // impermanent loss protection result
|
|
1289
|
+
const maxILP = result.lt(0) ? new BigNumber(0) : result; // max negative ILP to 0
|
|
1289
1290
|
const ILProtection = {
|
|
1290
|
-
ILProtection: new CryptoAmount(baseAmount$1(
|
|
1291
|
-
totalDays: (
|
|
1291
|
+
ILProtection: new CryptoAmount(baseAmount$1(maxILP), AssetRuneNative$1),
|
|
1292
|
+
totalDays: (fractionOfFullILPProtection * 100).toFixed(2),
|
|
1292
1293
|
};
|
|
1293
1294
|
return ILProtection;
|
|
1294
1295
|
};
|
|
@@ -1760,10 +1761,12 @@ class ThorchainQuery {
|
|
|
1760
1761
|
poolShare: poolShare,
|
|
1761
1762
|
lpUnits: baseAmount(lpUnits),
|
|
1762
1763
|
runeToAssetRatio: assetPool.runeToAssetRatio,
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1764
|
+
inbound: {
|
|
1765
|
+
fees: {
|
|
1766
|
+
asset: assetInboundFee,
|
|
1767
|
+
rune: runeInboundFee,
|
|
1768
|
+
total: totalFees,
|
|
1769
|
+
},
|
|
1767
1770
|
},
|
|
1768
1771
|
estimatedWaitSeconds: waitTimeSeconds,
|
|
1769
1772
|
errors,
|
|
@@ -1809,11 +1812,20 @@ class ThorchainQuery {
|
|
|
1809
1812
|
rune: baseAmount(liquidityProvider.rune_deposit_value),
|
|
1810
1813
|
};
|
|
1811
1814
|
const poolShare = getPoolShare(unitData, poolAsset);
|
|
1812
|
-
//
|
|
1813
|
-
//
|
|
1815
|
+
// Liquidity Unit Value Index = sprt(assetdepth * runeDepth) / Poolunits
|
|
1816
|
+
// Using this formula we can work out an individual position to find LUVI and then the growth rate
|
|
1817
|
+
const depositLuvi = Math.sqrt(currentLP.asset.times(currentLP.rune).div(unitData.liquidityUnits).amount().toNumber());
|
|
1818
|
+
const redeemLuvi = Math.sqrt(poolShare.assetShare.baseAmount
|
|
1819
|
+
.times(poolShare.runeShare.baseAmount)
|
|
1820
|
+
.div(unitData.liquidityUnits)
|
|
1821
|
+
.amount()
|
|
1822
|
+
.toNumber());
|
|
1823
|
+
const lpGrowth = redeemLuvi - depositLuvi;
|
|
1824
|
+
const currentLpGrowth = lpGrowth > 0 ? lpGrowth / depositLuvi : 0;
|
|
1814
1825
|
const impermanentLossProtection = getLiquidityProtectionData(currentLP, poolShare, block);
|
|
1815
1826
|
const lpPosition = {
|
|
1816
1827
|
poolShare,
|
|
1828
|
+
lpGrowth: `${(currentLpGrowth * 100).toFixed(2)} %`,
|
|
1817
1829
|
position: liquidityProvider,
|
|
1818
1830
|
impermanentLossProtection: impermanentLossProtection,
|
|
1819
1831
|
};
|
|
@@ -1851,8 +1863,6 @@ class ThorchainQuery {
|
|
|
1851
1863
|
liquidityUnits: new BigNumber(memberDetail.position.units),
|
|
1852
1864
|
totalUnits: new BigNumber(assetPool.pool.liquidityUnits),
|
|
1853
1865
|
}, assetPool);
|
|
1854
|
-
// calculate total fees
|
|
1855
|
-
const totalFees = (yield this.convert(dustValues.asset, AssetRuneNative)).plus(dustValues.rune);
|
|
1856
1866
|
// get slip on liquidity removal
|
|
1857
1867
|
const slip = getSlipOnLiquidity({
|
|
1858
1868
|
asset: poolShare.assetShare,
|
|
@@ -1862,26 +1872,46 @@ class ThorchainQuery {
|
|
|
1862
1872
|
const waitTimeSecondsForAsset = yield this.confCounting(poolShare.assetShare.div(params.percentage / 100));
|
|
1863
1873
|
const waitTimeSecondsForRune = yield this.confCounting(poolShare.runeShare.div(params.percentage / 100));
|
|
1864
1874
|
let waitTimeSeconds = 0;
|
|
1865
|
-
if (
|
|
1866
|
-
waitTimeSeconds =
|
|
1875
|
+
if (memberDetail.position.asset_address && memberDetail.position.rune_address) {
|
|
1876
|
+
waitTimeSeconds =
|
|
1877
|
+
waitTimeSecondsForAsset > waitTimeSecondsForRune ? waitTimeSecondsForAsset : waitTimeSecondsForRune;
|
|
1867
1878
|
}
|
|
1868
|
-
else if (
|
|
1879
|
+
else if (memberDetail.position.asset_address) {
|
|
1869
1880
|
waitTimeSeconds = waitTimeSecondsForAsset;
|
|
1870
1881
|
}
|
|
1871
1882
|
else {
|
|
1872
1883
|
waitTimeSeconds = waitTimeSecondsForRune;
|
|
1873
1884
|
}
|
|
1885
|
+
const allInboundDetails = yield this.thorchainCache.getInboundDetails();
|
|
1886
|
+
const inboundDetails = allInboundDetails[params.asset.chain];
|
|
1887
|
+
const runeInbound = calcNetworkFee(AssetRuneNative, inboundDetails);
|
|
1888
|
+
const assetInbound = calcNetworkFee(params.asset, inboundDetails);
|
|
1889
|
+
const runeOutbound = calcOutboundFee(AssetRuneNative, inboundDetails);
|
|
1890
|
+
const assetOutbound = calcOutboundFee(params.asset, inboundDetails);
|
|
1874
1891
|
const estimateLP = {
|
|
1875
1892
|
assetAddress: memberDetail.position.asset_address,
|
|
1876
1893
|
runeAddress: memberDetail.position.rune_address,
|
|
1877
1894
|
slipPercent: slip.times(100),
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1895
|
+
inbound: {
|
|
1896
|
+
minToSend: {
|
|
1897
|
+
rune: dustValues.rune,
|
|
1898
|
+
asset: dustValues.asset,
|
|
1899
|
+
total: (yield this.convert(dustValues.asset, AssetRuneNative)).plus(dustValues.rune),
|
|
1900
|
+
},
|
|
1901
|
+
fees: {
|
|
1902
|
+
rune: runeInbound,
|
|
1903
|
+
asset: assetInbound,
|
|
1904
|
+
total: (yield this.convert(assetInbound, AssetRuneNative)).plus(runeInbound),
|
|
1905
|
+
},
|
|
1906
|
+
},
|
|
1907
|
+
outboundFee: {
|
|
1908
|
+
asset: assetOutbound,
|
|
1909
|
+
rune: runeOutbound,
|
|
1910
|
+
total: (yield this.convert(assetOutbound, AssetRuneNative)).plus(runeOutbound),
|
|
1882
1911
|
},
|
|
1883
1912
|
assetAmount: poolShare.assetShare,
|
|
1884
1913
|
runeAmount: poolShare.runeShare,
|
|
1914
|
+
lpGrowth: memberDetail.lpGrowth,
|
|
1885
1915
|
estimatedWaitSeconds: waitTimeSeconds,
|
|
1886
1916
|
impermanentLossProtection: memberDetail.impermanentLossProtection,
|
|
1887
1917
|
assetPool: assetPool.pool.asset,
|
package/lib/index.js
CHANGED
|
@@ -230,7 +230,7 @@ class Midgard {
|
|
|
230
230
|
return data;
|
|
231
231
|
}
|
|
232
232
|
catch (e) {
|
|
233
|
-
console.error(e)
|
|
233
|
+
//console.error(e)
|
|
234
234
|
}
|
|
235
235
|
}
|
|
236
236
|
throw new Error('Midgard not responding');
|
|
@@ -247,10 +247,10 @@ class Midgard {
|
|
|
247
247
|
return (yield api.getPools()).data;
|
|
248
248
|
}
|
|
249
249
|
catch (e) {
|
|
250
|
-
console.error(e)
|
|
250
|
+
//console.error(e)
|
|
251
251
|
}
|
|
252
252
|
}
|
|
253
|
-
throw Error(`Midgard not responding`);
|
|
253
|
+
throw new Error(`Midgard not responding`);
|
|
254
254
|
});
|
|
255
255
|
}
|
|
256
256
|
/**
|
|
@@ -266,7 +266,7 @@ class Midgard {
|
|
|
266
266
|
return data.int_64_values;
|
|
267
267
|
}
|
|
268
268
|
catch (e) {
|
|
269
|
-
console.error(e)
|
|
269
|
+
//console.error(e)
|
|
270
270
|
}
|
|
271
271
|
}
|
|
272
272
|
throw new Error('Midgard not responding');
|
|
@@ -286,7 +286,7 @@ class Midgard {
|
|
|
286
286
|
return value;
|
|
287
287
|
}
|
|
288
288
|
catch (e) {
|
|
289
|
-
console.error(e)
|
|
289
|
+
//console.error(e)
|
|
290
290
|
}
|
|
291
291
|
}
|
|
292
292
|
throw new Error('Midgard not responding');
|
|
@@ -327,7 +327,7 @@ class Midgard {
|
|
|
327
327
|
return +data.scannerHeight;
|
|
328
328
|
}
|
|
329
329
|
catch (e) {
|
|
330
|
-
console.error(e)
|
|
330
|
+
//console.error(e)
|
|
331
331
|
}
|
|
332
332
|
}
|
|
333
333
|
throw Error(`Midgard not responding`);
|
|
@@ -346,7 +346,7 @@ class Midgard {
|
|
|
346
346
|
return actions;
|
|
347
347
|
}
|
|
348
348
|
catch (e) {
|
|
349
|
-
console.error(e)
|
|
349
|
+
//console.error(e)
|
|
350
350
|
}
|
|
351
351
|
}
|
|
352
352
|
throw Error(`Midgard not responding`);
|
|
@@ -365,7 +365,7 @@ class Midgard {
|
|
|
365
365
|
return memberDetail;
|
|
366
366
|
}
|
|
367
367
|
catch (e) {
|
|
368
|
-
console.error(e)
|
|
368
|
+
//console.error(e)
|
|
369
369
|
}
|
|
370
370
|
}
|
|
371
371
|
throw Error(`Midgard not responding`);
|
|
@@ -384,7 +384,7 @@ class Midgard {
|
|
|
384
384
|
return poolDetail;
|
|
385
385
|
}
|
|
386
386
|
catch (e) {
|
|
387
|
-
console.error(e)
|
|
387
|
+
//console.error(e)
|
|
388
388
|
}
|
|
389
389
|
}
|
|
390
390
|
throw Error(`Midgard not responding`);
|
|
@@ -411,7 +411,7 @@ class Midgard {
|
|
|
411
411
|
// if (resp.status == 404) {
|
|
412
412
|
// return undefined
|
|
413
413
|
// }
|
|
414
|
-
console.error(e)
|
|
414
|
+
//console.error(e)
|
|
415
415
|
}
|
|
416
416
|
}
|
|
417
417
|
throw Error(`Midgard not responding`);
|
|
@@ -733,7 +733,7 @@ class Thornode {
|
|
|
733
733
|
return queueScheduled.data;
|
|
734
734
|
}
|
|
735
735
|
catch (e) {
|
|
736
|
-
console.error(e)
|
|
736
|
+
//console.error(e)
|
|
737
737
|
throw new Error(`THORNode not responding`);
|
|
738
738
|
}
|
|
739
739
|
}
|
|
@@ -776,7 +776,7 @@ class Thornode {
|
|
|
776
776
|
return lastBlock.data;
|
|
777
777
|
}
|
|
778
778
|
catch (e) {
|
|
779
|
-
console.error(e)
|
|
779
|
+
//console.error(e)
|
|
780
780
|
}
|
|
781
781
|
}
|
|
782
782
|
throw new Error(`THORNode not responding`);
|
|
@@ -790,12 +790,11 @@ class Thornode {
|
|
|
790
790
|
return __awaiter(this, void 0, void 0, function* () {
|
|
791
791
|
for (const api of this.poolsApi) {
|
|
792
792
|
try {
|
|
793
|
-
// console.log(console.log(JSON.stringify(api, null, 2)))
|
|
794
793
|
const pools = yield api.pools();
|
|
795
794
|
return pools.data;
|
|
796
795
|
}
|
|
797
796
|
catch (e) {
|
|
798
|
-
console.error(e)
|
|
797
|
+
//console.error(e)
|
|
799
798
|
}
|
|
800
799
|
}
|
|
801
800
|
throw new Error(`THORNode not responding`);
|
|
@@ -816,7 +815,7 @@ class Thornode {
|
|
|
816
815
|
return lps.find((lp) => lp.asset_address === address || lp.rune_address === address);
|
|
817
816
|
}
|
|
818
817
|
catch (e) {
|
|
819
|
-
console.error(e)
|
|
818
|
+
//console.error(e)
|
|
820
819
|
}
|
|
821
820
|
}
|
|
822
821
|
throw new Error(`THORNode not responding`);
|
|
@@ -837,7 +836,7 @@ class Thornode {
|
|
|
837
836
|
return resp;
|
|
838
837
|
}
|
|
839
838
|
catch (e) {
|
|
840
|
-
console.error(e)
|
|
839
|
+
//console.error(e)
|
|
841
840
|
}
|
|
842
841
|
}
|
|
843
842
|
throw new Error(`THORNode not responding`);
|
|
@@ -1293,11 +1292,13 @@ const getLiquidityProtectionData = (depositValue, poolShare, block) => {
|
|
|
1293
1292
|
const currentHeight = block.current;
|
|
1294
1293
|
const heightLastAdded = block.lastAdded || 0; //default to zero if undefined
|
|
1295
1294
|
const blocksforfullprotection = block.fullProtection;
|
|
1296
|
-
const
|
|
1295
|
+
const fractionOfFullILPProtection = (currentHeight - heightLastAdded) / blocksforfullprotection;
|
|
1296
|
+
const protectionProgress = Math.min(fractionOfFullILPProtection, 1); // percentage of entitlement, max 100%
|
|
1297
1297
|
const result = coverage.times(protectionProgress); // impermanent loss protection result
|
|
1298
|
+
const maxILP = result.lt(0) ? new bignumber_js.BigNumber(0) : result; // max negative ILP to 0
|
|
1298
1299
|
const ILProtection = {
|
|
1299
|
-
ILProtection: new CryptoAmount(lib.baseAmount(
|
|
1300
|
-
totalDays: (
|
|
1300
|
+
ILProtection: new CryptoAmount(lib.baseAmount(maxILP), lib.AssetRuneNative),
|
|
1301
|
+
totalDays: (fractionOfFullILPProtection * 100).toFixed(2),
|
|
1301
1302
|
};
|
|
1302
1303
|
return ILProtection;
|
|
1303
1304
|
};
|
|
@@ -1769,10 +1770,12 @@ class ThorchainQuery {
|
|
|
1769
1770
|
poolShare: poolShare,
|
|
1770
1771
|
lpUnits: xchainUtil.baseAmount(lpUnits),
|
|
1771
1772
|
runeToAssetRatio: assetPool.runeToAssetRatio,
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1773
|
+
inbound: {
|
|
1774
|
+
fees: {
|
|
1775
|
+
asset: assetInboundFee,
|
|
1776
|
+
rune: runeInboundFee,
|
|
1777
|
+
total: totalFees,
|
|
1778
|
+
},
|
|
1776
1779
|
},
|
|
1777
1780
|
estimatedWaitSeconds: waitTimeSeconds,
|
|
1778
1781
|
errors,
|
|
@@ -1818,11 +1821,20 @@ class ThorchainQuery {
|
|
|
1818
1821
|
rune: xchainUtil.baseAmount(liquidityProvider.rune_deposit_value),
|
|
1819
1822
|
};
|
|
1820
1823
|
const poolShare = getPoolShare(unitData, poolAsset);
|
|
1821
|
-
//
|
|
1822
|
-
//
|
|
1824
|
+
// Liquidity Unit Value Index = sprt(assetdepth * runeDepth) / Poolunits
|
|
1825
|
+
// Using this formula we can work out an individual position to find LUVI and then the growth rate
|
|
1826
|
+
const depositLuvi = Math.sqrt(currentLP.asset.times(currentLP.rune).div(unitData.liquidityUnits).amount().toNumber());
|
|
1827
|
+
const redeemLuvi = Math.sqrt(poolShare.assetShare.baseAmount
|
|
1828
|
+
.times(poolShare.runeShare.baseAmount)
|
|
1829
|
+
.div(unitData.liquidityUnits)
|
|
1830
|
+
.amount()
|
|
1831
|
+
.toNumber());
|
|
1832
|
+
const lpGrowth = redeemLuvi - depositLuvi;
|
|
1833
|
+
const currentLpGrowth = lpGrowth > 0 ? lpGrowth / depositLuvi : 0;
|
|
1823
1834
|
const impermanentLossProtection = getLiquidityProtectionData(currentLP, poolShare, block);
|
|
1824
1835
|
const lpPosition = {
|
|
1825
1836
|
poolShare,
|
|
1837
|
+
lpGrowth: `${(currentLpGrowth * 100).toFixed(2)} %`,
|
|
1826
1838
|
position: liquidityProvider,
|
|
1827
1839
|
impermanentLossProtection: impermanentLossProtection,
|
|
1828
1840
|
};
|
|
@@ -1860,8 +1872,6 @@ class ThorchainQuery {
|
|
|
1860
1872
|
liquidityUnits: new bignumber_js.BigNumber(memberDetail.position.units),
|
|
1861
1873
|
totalUnits: new bignumber_js.BigNumber(assetPool.pool.liquidityUnits),
|
|
1862
1874
|
}, assetPool);
|
|
1863
|
-
// calculate total fees
|
|
1864
|
-
const totalFees = (yield this.convert(dustValues.asset, xchainUtil.AssetRuneNative)).plus(dustValues.rune);
|
|
1865
1875
|
// get slip on liquidity removal
|
|
1866
1876
|
const slip = getSlipOnLiquidity({
|
|
1867
1877
|
asset: poolShare.assetShare,
|
|
@@ -1871,26 +1881,46 @@ class ThorchainQuery {
|
|
|
1871
1881
|
const waitTimeSecondsForAsset = yield this.confCounting(poolShare.assetShare.div(params.percentage / 100));
|
|
1872
1882
|
const waitTimeSecondsForRune = yield this.confCounting(poolShare.runeShare.div(params.percentage / 100));
|
|
1873
1883
|
let waitTimeSeconds = 0;
|
|
1874
|
-
if (
|
|
1875
|
-
waitTimeSeconds =
|
|
1884
|
+
if (memberDetail.position.asset_address && memberDetail.position.rune_address) {
|
|
1885
|
+
waitTimeSeconds =
|
|
1886
|
+
waitTimeSecondsForAsset > waitTimeSecondsForRune ? waitTimeSecondsForAsset : waitTimeSecondsForRune;
|
|
1876
1887
|
}
|
|
1877
|
-
else if (
|
|
1888
|
+
else if (memberDetail.position.asset_address) {
|
|
1878
1889
|
waitTimeSeconds = waitTimeSecondsForAsset;
|
|
1879
1890
|
}
|
|
1880
1891
|
else {
|
|
1881
1892
|
waitTimeSeconds = waitTimeSecondsForRune;
|
|
1882
1893
|
}
|
|
1894
|
+
const allInboundDetails = yield this.thorchainCache.getInboundDetails();
|
|
1895
|
+
const inboundDetails = allInboundDetails[params.asset.chain];
|
|
1896
|
+
const runeInbound = calcNetworkFee(xchainUtil.AssetRuneNative, inboundDetails);
|
|
1897
|
+
const assetInbound = calcNetworkFee(params.asset, inboundDetails);
|
|
1898
|
+
const runeOutbound = calcOutboundFee(xchainUtil.AssetRuneNative, inboundDetails);
|
|
1899
|
+
const assetOutbound = calcOutboundFee(params.asset, inboundDetails);
|
|
1883
1900
|
const estimateLP = {
|
|
1884
1901
|
assetAddress: memberDetail.position.asset_address,
|
|
1885
1902
|
runeAddress: memberDetail.position.rune_address,
|
|
1886
1903
|
slipPercent: slip.times(100),
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1904
|
+
inbound: {
|
|
1905
|
+
minToSend: {
|
|
1906
|
+
rune: dustValues.rune,
|
|
1907
|
+
asset: dustValues.asset,
|
|
1908
|
+
total: (yield this.convert(dustValues.asset, xchainUtil.AssetRuneNative)).plus(dustValues.rune),
|
|
1909
|
+
},
|
|
1910
|
+
fees: {
|
|
1911
|
+
rune: runeInbound,
|
|
1912
|
+
asset: assetInbound,
|
|
1913
|
+
total: (yield this.convert(assetInbound, xchainUtil.AssetRuneNative)).plus(runeInbound),
|
|
1914
|
+
},
|
|
1915
|
+
},
|
|
1916
|
+
outboundFee: {
|
|
1917
|
+
asset: assetOutbound,
|
|
1918
|
+
rune: runeOutbound,
|
|
1919
|
+
total: (yield this.convert(assetOutbound, xchainUtil.AssetRuneNative)).plus(runeOutbound),
|
|
1891
1920
|
},
|
|
1892
1921
|
assetAmount: poolShare.assetShare,
|
|
1893
1922
|
runeAmount: poolShare.runeShare,
|
|
1923
|
+
lpGrowth: memberDetail.lpGrowth,
|
|
1894
1924
|
estimatedWaitSeconds: waitTimeSeconds,
|
|
1895
1925
|
impermanentLossProtection: memberDetail.impermanentLossProtection,
|
|
1896
1926
|
assetPool: assetPool.pool.asset,
|
package/lib/types.d.ts
CHANGED
|
@@ -123,7 +123,9 @@ export declare type EstimateAddLP = {
|
|
|
123
123
|
slipPercent: BigNumber;
|
|
124
124
|
poolShare: PoolShareDetail;
|
|
125
125
|
lpUnits: BaseAmount;
|
|
126
|
-
|
|
126
|
+
inbound: {
|
|
127
|
+
fees: LPAmounts;
|
|
128
|
+
};
|
|
127
129
|
runeToAssetRatio: BigNumber;
|
|
128
130
|
estimatedWaitSeconds: number;
|
|
129
131
|
errors: string[];
|
|
@@ -133,17 +135,22 @@ export declare type EstimateWithdrawLP = {
|
|
|
133
135
|
assetAddress?: string;
|
|
134
136
|
runeAddress?: string;
|
|
135
137
|
slipPercent: BigNumber;
|
|
136
|
-
|
|
138
|
+
inbound: {
|
|
139
|
+
minToSend: LPAmounts;
|
|
140
|
+
fees: LPAmounts;
|
|
141
|
+
};
|
|
142
|
+
outboundFee: LPAmounts;
|
|
137
143
|
assetAmount: CryptoAmount;
|
|
138
144
|
runeAmount: CryptoAmount;
|
|
145
|
+
lpGrowth: string;
|
|
139
146
|
impermanentLossProtection: ILProtectionData;
|
|
140
147
|
estimatedWaitSeconds: number;
|
|
141
148
|
assetPool: string;
|
|
142
149
|
};
|
|
143
|
-
export declare type
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
150
|
+
export declare type LPAmounts = {
|
|
151
|
+
rune: CryptoAmount;
|
|
152
|
+
asset: CryptoAmount;
|
|
153
|
+
total: CryptoAmount;
|
|
147
154
|
};
|
|
148
155
|
export declare type DustValues = {
|
|
149
156
|
asset: CryptoAmount;
|
|
@@ -162,6 +169,7 @@ export declare type WithdrawLiquidityPosition = {
|
|
|
162
169
|
export declare type LiquidityPosition = {
|
|
163
170
|
poolShare: PoolShareDetail;
|
|
164
171
|
position: LiquidityProvider;
|
|
172
|
+
lpGrowth: string;
|
|
165
173
|
impermanentLossProtection: ILProtectionData;
|
|
166
174
|
};
|
|
167
175
|
export declare type PoolRatios = {
|
package/package.json
CHANGED