@xchainjs/xchain-thorchain-query 0.1.17 → 0.1.19
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 +90 -13
- package/lib/index.js +88 -12
- package/lib/liquidity-pool.d.ts +3 -1
- package/lib/thorchain-checktx.d.ts +18 -0
- package/lib/utils/thornode.d.ts +7 -2
- package/package.json +23 -23
package/lib/index.esm.js
CHANGED
|
@@ -177,8 +177,9 @@ class CryptoAmount {
|
|
|
177
177
|
* Represent a Liquidity Pool in Thorchain
|
|
178
178
|
*/
|
|
179
179
|
class LiquidityPool {
|
|
180
|
-
constructor(pool) {
|
|
180
|
+
constructor(pool, thornodeDetails) {
|
|
181
181
|
this.pool = pool;
|
|
182
|
+
this.thornodeDetails = thornodeDetails;
|
|
182
183
|
const asset = assetFromString(this.pool.asset);
|
|
183
184
|
if (!asset)
|
|
184
185
|
throw new Error(`could not parse ${this.pool.asset}`);
|
|
@@ -517,8 +518,6 @@ const calcNetworkFee = (asset, inbound) => {
|
|
|
517
518
|
return new CryptoAmount(baseAmount(2000000), AssetRuneNative);
|
|
518
519
|
// if you are swapping a non-gas asset on a multiAsset chain (ex. ERC-20 on ETH), the
|
|
519
520
|
// gas fees will be paid in a diff asset than the one you are swapping
|
|
520
|
-
else if (!isNativeChainAsset(asset))
|
|
521
|
-
return new CryptoAmount(baseAmount(0), AssetRuneNative);
|
|
522
521
|
switch (asset.chain) {
|
|
523
522
|
case BTCChain:
|
|
524
523
|
return new CryptoAmount(baseAmount(inbound.gasRate.multipliedBy(inbound.outboundTxSize)), AssetBTC);
|
|
@@ -751,7 +750,7 @@ class Thornode {
|
|
|
751
750
|
}
|
|
752
751
|
/**
|
|
753
752
|
*
|
|
754
|
-
* @returns - thorchain
|
|
753
|
+
* @returns - thorchain pools
|
|
755
754
|
*/
|
|
756
755
|
getPools() {
|
|
757
756
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -767,6 +766,24 @@ class Thornode {
|
|
|
767
766
|
throw new Error(`THORNode not responding`);
|
|
768
767
|
});
|
|
769
768
|
}
|
|
769
|
+
/**
|
|
770
|
+
*
|
|
771
|
+
* @returns - thorchain pool
|
|
772
|
+
*/
|
|
773
|
+
getPool(asset) {
|
|
774
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
775
|
+
for (const api of this.poolsApi) {
|
|
776
|
+
try {
|
|
777
|
+
const pools = yield api.pool(asset);
|
|
778
|
+
return pools.data;
|
|
779
|
+
}
|
|
780
|
+
catch (e) {
|
|
781
|
+
//console.error(e)
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
throw new Error(`THORNode not responding`);
|
|
785
|
+
});
|
|
786
|
+
}
|
|
770
787
|
/**
|
|
771
788
|
*
|
|
772
789
|
* @returns Thorchain constants
|
|
@@ -945,11 +962,11 @@ class Thornode {
|
|
|
945
962
|
* @param height - block height
|
|
946
963
|
* @returns quotes swap object response
|
|
947
964
|
*/
|
|
948
|
-
getSwapQuote(fromAsset, toAsset, amount, destination, toleranceBps, affiliateBps, affiliate, height) {
|
|
965
|
+
getSwapQuote(fromAsset, toAsset, amount, destination, fromAddress, toleranceBps, affiliateBps, affiliate, height) {
|
|
949
966
|
return __awaiter(this, void 0, void 0, function* () {
|
|
950
967
|
for (const api of this.quoteApi) {
|
|
951
968
|
try {
|
|
952
|
-
const resp = (yield api.quoteswap(height, fromAsset, toAsset, amount, destination, toleranceBps, affiliateBps, affiliate)).data;
|
|
969
|
+
const resp = (yield api.quoteswap(height, fromAsset, toAsset, amount, destination, fromAddress, toleranceBps, affiliateBps, affiliate)).data;
|
|
953
970
|
return resp;
|
|
954
971
|
}
|
|
955
972
|
catch (e) {
|
|
@@ -1090,14 +1107,14 @@ class ThorchainCache {
|
|
|
1090
1107
|
*/
|
|
1091
1108
|
refereshPoolCache() {
|
|
1092
1109
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1093
|
-
|
|
1094
|
-
const midgardPools = yield this.midgard.getPools();
|
|
1110
|
+
const [thornodePools, midgardPools] = yield Promise.all([this.thornode.getPools(), this.midgard.getPools()]);
|
|
1095
1111
|
const poolMap = {};
|
|
1096
1112
|
if (midgardPools) {
|
|
1097
1113
|
for (const pool of midgardPools) {
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1114
|
+
const thornodePool = thornodePools.find((p) => p.asset === pool.asset);
|
|
1115
|
+
if (!thornodePool)
|
|
1116
|
+
throw Error(`Could not find thornode pool ${pool.asset}`);
|
|
1117
|
+
const lp = new LiquidityPool(pool, thornodePool);
|
|
1101
1118
|
poolMap[`${lp.asset.chain}.${lp.asset.ticker}`] = lp;
|
|
1102
1119
|
}
|
|
1103
1120
|
this.poolCache = {
|
|
@@ -1704,6 +1721,18 @@ class ThorchainQuery {
|
|
|
1704
1721
|
const destPool = yield this.thorchainCache.getPoolForAsset(destAsset);
|
|
1705
1722
|
if (!destPool.isAvailable())
|
|
1706
1723
|
errors.push(`destinationAsset ${destAsset.ticker} does not have a valid liquidity pool`);
|
|
1724
|
+
// check synth info on thornode pools
|
|
1725
|
+
try {
|
|
1726
|
+
const pools = yield this.thorchainCache.thornode.getPools();
|
|
1727
|
+
const destinationAssetPool = pools.find((pool) => pool.asset === `${destAsset.chain}.${destAsset.symbol}`);
|
|
1728
|
+
if (destinationAssetPool)
|
|
1729
|
+
if (destinationAssetPool.synth_mint_paused && destAsset.synth) {
|
|
1730
|
+
errors.push(`Synth supply is over cap on destinationAsset ${destAsset.ticker}, synth minting is paused`);
|
|
1731
|
+
}
|
|
1732
|
+
}
|
|
1733
|
+
catch (error) {
|
|
1734
|
+
errors.push(`Error: ${error} destination pool was not found for asset ${destAsset}`);
|
|
1735
|
+
}
|
|
1707
1736
|
}
|
|
1708
1737
|
if (sourceInboundDetails.haltedChain)
|
|
1709
1738
|
errors.push(`source chain is halted`);
|
|
@@ -2272,6 +2301,7 @@ var TxType;
|
|
|
2272
2301
|
TxType["WithdrawLP"] = "WithdrawLP";
|
|
2273
2302
|
TxType["AddSaver"] = "AddSaver";
|
|
2274
2303
|
TxType["WithdrawSaver"] = "WithdrawSaver";
|
|
2304
|
+
TxType["Refund"] = "Refund";
|
|
2275
2305
|
TxType["Other"] = "Other";
|
|
2276
2306
|
TxType["Unknown"] = "Unknown";
|
|
2277
2307
|
})(TxType || (TxType = {}));
|
|
@@ -2301,6 +2331,12 @@ var WithdrawStatus;
|
|
|
2301
2331
|
WithdrawStatus["Incomplete"] = "Incomplete";
|
|
2302
2332
|
WithdrawStatus["Complete_Refunded"] = "Complete_Refunded";
|
|
2303
2333
|
})(WithdrawStatus || (WithdrawStatus = {}));
|
|
2334
|
+
var RefundStatus;
|
|
2335
|
+
(function (RefundStatus) {
|
|
2336
|
+
RefundStatus["Complete"] = "Complete";
|
|
2337
|
+
RefundStatus["Incomplete"] = "Incomplete";
|
|
2338
|
+
RefundStatus["Complete_Refunded"] = "Complete_Refunded";
|
|
2339
|
+
})(RefundStatus || (RefundStatus = {}));
|
|
2304
2340
|
var AddSaverStatus;
|
|
2305
2341
|
(function (AddSaverStatus) {
|
|
2306
2342
|
AddSaverStatus["Complete"] = "Complete";
|
|
@@ -2345,6 +2381,9 @@ class TransactionStage {
|
|
|
2345
2381
|
case TxType.WithdrawSaver:
|
|
2346
2382
|
yield this.checkWithdrawSaverProgress(txData, progress);
|
|
2347
2383
|
break;
|
|
2384
|
+
case TxType.Refund:
|
|
2385
|
+
yield this.checkRefund(txData, progress);
|
|
2386
|
+
break;
|
|
2348
2387
|
case TxType.Other:
|
|
2349
2388
|
break;
|
|
2350
2389
|
}
|
|
@@ -2431,7 +2470,9 @@ class TransactionStage {
|
|
|
2431
2470
|
progress.txType = TxType.WithdrawSaver;
|
|
2432
2471
|
if (operation.match(/withdraw|wd|-/gi) && parts[1].match(/[.]/))
|
|
2433
2472
|
progress.txType = TxType.WithdrawLP;
|
|
2434
|
-
if (operation.match(/
|
|
2473
|
+
if (operation.match(/refund/gi))
|
|
2474
|
+
progress.txType = TxType.Refund;
|
|
2475
|
+
if (operation.match(/out/gi))
|
|
2435
2476
|
progress.txType = TxType.Other;
|
|
2436
2477
|
const amount = yield this.getCryptoAmount(inboundAmount, assetIn);
|
|
2437
2478
|
// find a date for when it should be competed
|
|
@@ -2562,6 +2603,42 @@ class TransactionStage {
|
|
|
2562
2603
|
}
|
|
2563
2604
|
});
|
|
2564
2605
|
}
|
|
2606
|
+
checkRefund(txData, progress) {
|
|
2607
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2608
|
+
if (progress.inboundObserved) {
|
|
2609
|
+
const lastBlockObj = yield this.thorchainCache.thornode.getLastBlock();
|
|
2610
|
+
// find the date in which the asset should be seen in the wallet
|
|
2611
|
+
const outboundHeight = txData.tx.status === 'done' ? txData.finalised_height : Number(`${txData.outbound_height}`);
|
|
2612
|
+
const expectedConfirmationDate = yield this.blockToDate(THORChain, txData, outboundHeight); // always pass in thorchain
|
|
2613
|
+
const amount = txData.tx.tx.coins[0].amount;
|
|
2614
|
+
const asset = assetFromStringEx(txData.tx.tx.coins[0].asset);
|
|
2615
|
+
const toAddress = `${txData.tx.tx.to_address}`;
|
|
2616
|
+
const currentHeight = lastBlockObj.find((obj) => obj.chain === asset.chain);
|
|
2617
|
+
console.log(currentHeight);
|
|
2618
|
+
const outboundBlock = Number(`${currentHeight === null || currentHeight === void 0 ? void 0 : currentHeight.last_observed_in}`);
|
|
2619
|
+
const finalisedHeight = Number(txData.finalised_height);
|
|
2620
|
+
const currentTCHeight = Number(`${currentHeight === null || currentHeight === void 0 ? void 0 : currentHeight.thorchain}`);
|
|
2621
|
+
const estimatedWaitTime = outboundBlock > currentTCHeight
|
|
2622
|
+
? (outboundBlock - currentTCHeight) * this.chainAttributes[THORChain].avgBlockTimeInSecs +
|
|
2623
|
+
this.chainAttributes[asset.chain].avgBlockTimeInSecs
|
|
2624
|
+
: 0;
|
|
2625
|
+
// if the TC has process the block that the outbound tx was assigned to then its completed.
|
|
2626
|
+
const status = txData.tx.status === 'done' ? RefundStatus.Complete : RefundStatus.Incomplete;
|
|
2627
|
+
const refundAmount = yield this.getCryptoAmount(amount, asset);
|
|
2628
|
+
const refundInfo = {
|
|
2629
|
+
status,
|
|
2630
|
+
refundAmount,
|
|
2631
|
+
toAddress,
|
|
2632
|
+
expectedConfirmationDate,
|
|
2633
|
+
thorchainHeight: currentTCHeight,
|
|
2634
|
+
finalisedHeight,
|
|
2635
|
+
outboundBlock,
|
|
2636
|
+
estimatedWaitTime,
|
|
2637
|
+
};
|
|
2638
|
+
progress.refundInfo = refundInfo;
|
|
2639
|
+
}
|
|
2640
|
+
});
|
|
2641
|
+
}
|
|
2565
2642
|
parseAddLpMemo(memo) {
|
|
2566
2643
|
//ADD:POOL:PAIREDADDR:AFFILIATE:FEE
|
|
2567
2644
|
const parts = memo.split(`:`);
|
|
@@ -2651,4 +2728,4 @@ class TransactionStage {
|
|
|
2651
2728
|
}
|
|
2652
2729
|
}
|
|
2653
2730
|
|
|
2654
|
-
export { AddLpStatus, AddSaverStatus, CryptoAmount, InboundStatus, LiquidityPool, Midgard, SwapStatus, ThorchainCache, ThorchainQuery, Thornode, TransactionStage, TxType, WithdrawStatus, calcNetworkFee, getDoubleSwap, getLiquidityProtectionData, getLiquidityUnits, getPoolShare, getSingleSwap, getSlipOnLiquidity };
|
|
2731
|
+
export { AddLpStatus, AddSaverStatus, CryptoAmount, InboundStatus, LiquidityPool, Midgard, RefundStatus, SwapStatus, ThorchainCache, ThorchainQuery, Thornode, TransactionStage, TxType, WithdrawStatus, calcNetworkFee, getDoubleSwap, getLiquidityProtectionData, getLiquidityUnits, getPoolShare, getSingleSwap, getSlipOnLiquidity };
|
package/lib/index.js
CHANGED
|
@@ -186,8 +186,9 @@ class CryptoAmount {
|
|
|
186
186
|
* Represent a Liquidity Pool in Thorchain
|
|
187
187
|
*/
|
|
188
188
|
class LiquidityPool {
|
|
189
|
-
constructor(pool) {
|
|
189
|
+
constructor(pool, thornodeDetails) {
|
|
190
190
|
this.pool = pool;
|
|
191
|
+
this.thornodeDetails = thornodeDetails;
|
|
191
192
|
const asset = xchainUtil.assetFromString(this.pool.asset);
|
|
192
193
|
if (!asset)
|
|
193
194
|
throw new Error(`could not parse ${this.pool.asset}`);
|
|
@@ -526,8 +527,6 @@ const calcNetworkFee = (asset, inbound) => {
|
|
|
526
527
|
return new CryptoAmount(xchainUtil.baseAmount(2000000), xchainThorchain.AssetRuneNative);
|
|
527
528
|
// if you are swapping a non-gas asset on a multiAsset chain (ex. ERC-20 on ETH), the
|
|
528
529
|
// gas fees will be paid in a diff asset than the one you are swapping
|
|
529
|
-
else if (!isNativeChainAsset(asset))
|
|
530
|
-
return new CryptoAmount(xchainUtil.baseAmount(0), xchainThorchain.AssetRuneNative);
|
|
531
530
|
switch (asset.chain) {
|
|
532
531
|
case xchainBitcoin.BTCChain:
|
|
533
532
|
return new CryptoAmount(xchainUtil.baseAmount(inbound.gasRate.multipliedBy(inbound.outboundTxSize)), xchainBitcoin.AssetBTC);
|
|
@@ -760,7 +759,7 @@ class Thornode {
|
|
|
760
759
|
}
|
|
761
760
|
/**
|
|
762
761
|
*
|
|
763
|
-
* @returns - thorchain
|
|
762
|
+
* @returns - thorchain pools
|
|
764
763
|
*/
|
|
765
764
|
getPools() {
|
|
766
765
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -776,6 +775,24 @@ class Thornode {
|
|
|
776
775
|
throw new Error(`THORNode not responding`);
|
|
777
776
|
});
|
|
778
777
|
}
|
|
778
|
+
/**
|
|
779
|
+
*
|
|
780
|
+
* @returns - thorchain pool
|
|
781
|
+
*/
|
|
782
|
+
getPool(asset) {
|
|
783
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
784
|
+
for (const api of this.poolsApi) {
|
|
785
|
+
try {
|
|
786
|
+
const pools = yield api.pool(asset);
|
|
787
|
+
return pools.data;
|
|
788
|
+
}
|
|
789
|
+
catch (e) {
|
|
790
|
+
//console.error(e)
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
throw new Error(`THORNode not responding`);
|
|
794
|
+
});
|
|
795
|
+
}
|
|
779
796
|
/**
|
|
780
797
|
*
|
|
781
798
|
* @returns Thorchain constants
|
|
@@ -954,11 +971,11 @@ class Thornode {
|
|
|
954
971
|
* @param height - block height
|
|
955
972
|
* @returns quotes swap object response
|
|
956
973
|
*/
|
|
957
|
-
getSwapQuote(fromAsset, toAsset, amount, destination, toleranceBps, affiliateBps, affiliate, height) {
|
|
974
|
+
getSwapQuote(fromAsset, toAsset, amount, destination, fromAddress, toleranceBps, affiliateBps, affiliate, height) {
|
|
958
975
|
return __awaiter(this, void 0, void 0, function* () {
|
|
959
976
|
for (const api of this.quoteApi) {
|
|
960
977
|
try {
|
|
961
|
-
const resp = (yield api.quoteswap(height, fromAsset, toAsset, amount, destination, toleranceBps, affiliateBps, affiliate)).data;
|
|
978
|
+
const resp = (yield api.quoteswap(height, fromAsset, toAsset, amount, destination, fromAddress, toleranceBps, affiliateBps, affiliate)).data;
|
|
962
979
|
return resp;
|
|
963
980
|
}
|
|
964
981
|
catch (e) {
|
|
@@ -1099,14 +1116,14 @@ class ThorchainCache {
|
|
|
1099
1116
|
*/
|
|
1100
1117
|
refereshPoolCache() {
|
|
1101
1118
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1102
|
-
|
|
1103
|
-
const midgardPools = yield this.midgard.getPools();
|
|
1119
|
+
const [thornodePools, midgardPools] = yield Promise.all([this.thornode.getPools(), this.midgard.getPools()]);
|
|
1104
1120
|
const poolMap = {};
|
|
1105
1121
|
if (midgardPools) {
|
|
1106
1122
|
for (const pool of midgardPools) {
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1123
|
+
const thornodePool = thornodePools.find((p) => p.asset === pool.asset);
|
|
1124
|
+
if (!thornodePool)
|
|
1125
|
+
throw Error(`Could not find thornode pool ${pool.asset}`);
|
|
1126
|
+
const lp = new LiquidityPool(pool, thornodePool);
|
|
1110
1127
|
poolMap[`${lp.asset.chain}.${lp.asset.ticker}`] = lp;
|
|
1111
1128
|
}
|
|
1112
1129
|
this.poolCache = {
|
|
@@ -1713,6 +1730,18 @@ class ThorchainQuery {
|
|
|
1713
1730
|
const destPool = yield this.thorchainCache.getPoolForAsset(destAsset);
|
|
1714
1731
|
if (!destPool.isAvailable())
|
|
1715
1732
|
errors.push(`destinationAsset ${destAsset.ticker} does not have a valid liquidity pool`);
|
|
1733
|
+
// check synth info on thornode pools
|
|
1734
|
+
try {
|
|
1735
|
+
const pools = yield this.thorchainCache.thornode.getPools();
|
|
1736
|
+
const destinationAssetPool = pools.find((pool) => pool.asset === `${destAsset.chain}.${destAsset.symbol}`);
|
|
1737
|
+
if (destinationAssetPool)
|
|
1738
|
+
if (destinationAssetPool.synth_mint_paused && destAsset.synth) {
|
|
1739
|
+
errors.push(`Synth supply is over cap on destinationAsset ${destAsset.ticker}, synth minting is paused`);
|
|
1740
|
+
}
|
|
1741
|
+
}
|
|
1742
|
+
catch (error) {
|
|
1743
|
+
errors.push(`Error: ${error} destination pool was not found for asset ${destAsset}`);
|
|
1744
|
+
}
|
|
1716
1745
|
}
|
|
1717
1746
|
if (sourceInboundDetails.haltedChain)
|
|
1718
1747
|
errors.push(`source chain is halted`);
|
|
@@ -2280,6 +2309,7 @@ class ThorchainQuery {
|
|
|
2280
2309
|
TxType["WithdrawLP"] = "WithdrawLP";
|
|
2281
2310
|
TxType["AddSaver"] = "AddSaver";
|
|
2282
2311
|
TxType["WithdrawSaver"] = "WithdrawSaver";
|
|
2312
|
+
TxType["Refund"] = "Refund";
|
|
2283
2313
|
TxType["Other"] = "Other";
|
|
2284
2314
|
TxType["Unknown"] = "Unknown";
|
|
2285
2315
|
})(exports.TxType || (exports.TxType = {}));
|
|
@@ -2305,6 +2335,11 @@ class ThorchainQuery {
|
|
|
2305
2335
|
WithdrawStatus["Incomplete"] = "Incomplete";
|
|
2306
2336
|
WithdrawStatus["Complete_Refunded"] = "Complete_Refunded";
|
|
2307
2337
|
})(exports.WithdrawStatus || (exports.WithdrawStatus = {}));
|
|
2338
|
+
(function (RefundStatus) {
|
|
2339
|
+
RefundStatus["Complete"] = "Complete";
|
|
2340
|
+
RefundStatus["Incomplete"] = "Incomplete";
|
|
2341
|
+
RefundStatus["Complete_Refunded"] = "Complete_Refunded";
|
|
2342
|
+
})(exports.RefundStatus || (exports.RefundStatus = {}));
|
|
2308
2343
|
(function (AddSaverStatus) {
|
|
2309
2344
|
AddSaverStatus["Complete"] = "Complete";
|
|
2310
2345
|
AddSaverStatus["Complete_Refunded"] = "Complete_Refunded";
|
|
@@ -2348,6 +2383,9 @@ class TransactionStage {
|
|
|
2348
2383
|
case exports.TxType.WithdrawSaver:
|
|
2349
2384
|
yield this.checkWithdrawSaverProgress(txData, progress);
|
|
2350
2385
|
break;
|
|
2386
|
+
case exports.TxType.Refund:
|
|
2387
|
+
yield this.checkRefund(txData, progress);
|
|
2388
|
+
break;
|
|
2351
2389
|
case exports.TxType.Other:
|
|
2352
2390
|
break;
|
|
2353
2391
|
}
|
|
@@ -2434,7 +2472,9 @@ class TransactionStage {
|
|
|
2434
2472
|
progress.txType = exports.TxType.WithdrawSaver;
|
|
2435
2473
|
if (operation.match(/withdraw|wd|-/gi) && parts[1].match(/[.]/))
|
|
2436
2474
|
progress.txType = exports.TxType.WithdrawLP;
|
|
2437
|
-
if (operation.match(/
|
|
2475
|
+
if (operation.match(/refund/gi))
|
|
2476
|
+
progress.txType = exports.TxType.Refund;
|
|
2477
|
+
if (operation.match(/out/gi))
|
|
2438
2478
|
progress.txType = exports.TxType.Other;
|
|
2439
2479
|
const amount = yield this.getCryptoAmount(inboundAmount, assetIn);
|
|
2440
2480
|
// find a date for when it should be competed
|
|
@@ -2565,6 +2605,42 @@ class TransactionStage {
|
|
|
2565
2605
|
}
|
|
2566
2606
|
});
|
|
2567
2607
|
}
|
|
2608
|
+
checkRefund(txData, progress) {
|
|
2609
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2610
|
+
if (progress.inboundObserved) {
|
|
2611
|
+
const lastBlockObj = yield this.thorchainCache.thornode.getLastBlock();
|
|
2612
|
+
// find the date in which the asset should be seen in the wallet
|
|
2613
|
+
const outboundHeight = txData.tx.status === 'done' ? txData.finalised_height : Number(`${txData.outbound_height}`);
|
|
2614
|
+
const expectedConfirmationDate = yield this.blockToDate(xchainThorchain.THORChain, txData, outboundHeight); // always pass in thorchain
|
|
2615
|
+
const amount = txData.tx.tx.coins[0].amount;
|
|
2616
|
+
const asset = xchainUtil.assetFromStringEx(txData.tx.tx.coins[0].asset);
|
|
2617
|
+
const toAddress = `${txData.tx.tx.to_address}`;
|
|
2618
|
+
const currentHeight = lastBlockObj.find((obj) => obj.chain === asset.chain);
|
|
2619
|
+
console.log(currentHeight);
|
|
2620
|
+
const outboundBlock = Number(`${currentHeight === null || currentHeight === void 0 ? void 0 : currentHeight.last_observed_in}`);
|
|
2621
|
+
const finalisedHeight = Number(txData.finalised_height);
|
|
2622
|
+
const currentTCHeight = Number(`${currentHeight === null || currentHeight === void 0 ? void 0 : currentHeight.thorchain}`);
|
|
2623
|
+
const estimatedWaitTime = outboundBlock > currentTCHeight
|
|
2624
|
+
? (outboundBlock - currentTCHeight) * this.chainAttributes[xchainThorchain.THORChain].avgBlockTimeInSecs +
|
|
2625
|
+
this.chainAttributes[asset.chain].avgBlockTimeInSecs
|
|
2626
|
+
: 0;
|
|
2627
|
+
// if the TC has process the block that the outbound tx was assigned to then its completed.
|
|
2628
|
+
const status = txData.tx.status === 'done' ? exports.RefundStatus.Complete : exports.RefundStatus.Incomplete;
|
|
2629
|
+
const refundAmount = yield this.getCryptoAmount(amount, asset);
|
|
2630
|
+
const refundInfo = {
|
|
2631
|
+
status,
|
|
2632
|
+
refundAmount,
|
|
2633
|
+
toAddress,
|
|
2634
|
+
expectedConfirmationDate,
|
|
2635
|
+
thorchainHeight: currentTCHeight,
|
|
2636
|
+
finalisedHeight,
|
|
2637
|
+
outboundBlock,
|
|
2638
|
+
estimatedWaitTime,
|
|
2639
|
+
};
|
|
2640
|
+
progress.refundInfo = refundInfo;
|
|
2641
|
+
}
|
|
2642
|
+
});
|
|
2643
|
+
}
|
|
2568
2644
|
parseAddLpMemo(memo) {
|
|
2569
2645
|
//ADD:POOL:PAIREDADDR:AFFILIATE:FEE
|
|
2570
2646
|
const parts = memo.split(`:`);
|
package/lib/liquidity-pool.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { PoolDetail } from '@xchainjs/xchain-midgard/lib';
|
|
2
|
+
import { Pool } from '@xchainjs/xchain-thornode/lib';
|
|
2
3
|
import { Asset, BaseAmount } from '@xchainjs/xchain-util';
|
|
3
4
|
import { BigNumber } from 'bignumber.js';
|
|
4
5
|
/**
|
|
@@ -6,12 +7,13 @@ import { BigNumber } from 'bignumber.js';
|
|
|
6
7
|
*/
|
|
7
8
|
export declare class LiquidityPool {
|
|
8
9
|
readonly pool: PoolDetail;
|
|
10
|
+
readonly thornodeDetails: Pool;
|
|
9
11
|
readonly assetBalance: BaseAmount;
|
|
10
12
|
readonly runeBalance: BaseAmount;
|
|
11
13
|
readonly asset: Asset;
|
|
12
14
|
readonly assetString: string;
|
|
13
15
|
readonly runeToAssetRatio: BigNumber;
|
|
14
16
|
readonly assetToRuneRatio: BigNumber;
|
|
15
|
-
constructor(pool: PoolDetail);
|
|
17
|
+
constructor(pool: PoolDetail, thornodeDetails: Pool);
|
|
16
18
|
isAvailable(): boolean;
|
|
17
19
|
}
|
|
@@ -9,6 +9,7 @@ export declare enum TxType {
|
|
|
9
9
|
WithdrawLP = "WithdrawLP",
|
|
10
10
|
AddSaver = "AddSaver",
|
|
11
11
|
WithdrawSaver = "WithdrawSaver",
|
|
12
|
+
Refund = "Refund",
|
|
12
13
|
Other = "Other",
|
|
13
14
|
Unknown = "Unknown"
|
|
14
15
|
}
|
|
@@ -34,6 +35,11 @@ export declare enum WithdrawStatus {
|
|
|
34
35
|
Incomplete = "Incomplete",
|
|
35
36
|
Complete_Refunded = "Complete_Refunded"
|
|
36
37
|
}
|
|
38
|
+
export declare enum RefundStatus {
|
|
39
|
+
Complete = "Complete",
|
|
40
|
+
Incomplete = "Incomplete",
|
|
41
|
+
Complete_Refunded = "Complete_Refunded"
|
|
42
|
+
}
|
|
37
43
|
export declare enum AddSaverStatus {
|
|
38
44
|
Complete = "Complete",
|
|
39
45
|
Complete_Refunded = "Complete_Refunded",
|
|
@@ -76,6 +82,16 @@ export declare type WithdrawInfo = {
|
|
|
76
82
|
outboundHeight: number;
|
|
77
83
|
estimatedWaitTime: number;
|
|
78
84
|
};
|
|
85
|
+
export declare type RefundInfo = {
|
|
86
|
+
status: RefundStatus;
|
|
87
|
+
refundAmount: CryptoAmount;
|
|
88
|
+
toAddress: string;
|
|
89
|
+
expectedConfirmationDate: Date;
|
|
90
|
+
finalisedHeight: number;
|
|
91
|
+
thorchainHeight: number;
|
|
92
|
+
outboundBlock: number;
|
|
93
|
+
estimatedWaitTime: number;
|
|
94
|
+
};
|
|
79
95
|
export declare type AddSaverInfo = {
|
|
80
96
|
status: AddSaverStatus;
|
|
81
97
|
assetTx?: InboundTx;
|
|
@@ -99,6 +115,7 @@ export declare type TXProgress = {
|
|
|
99
115
|
addSaverInfo?: AddSaverInfo;
|
|
100
116
|
withdrawLpInfo?: WithdrawInfo;
|
|
101
117
|
withdrawSaverInfo?: WithdrawSaverInfo;
|
|
118
|
+
refundInfo?: RefundInfo;
|
|
102
119
|
};
|
|
103
120
|
export declare class TransactionStage {
|
|
104
121
|
readonly thorchainCache: ThorchainCache;
|
|
@@ -113,6 +130,7 @@ export declare class TransactionStage {
|
|
|
113
130
|
private checkWithdrawLpProgress;
|
|
114
131
|
private checkAddSaverProgress;
|
|
115
132
|
private checkWithdrawSaverProgress;
|
|
133
|
+
private checkRefund;
|
|
116
134
|
private parseAddLpMemo;
|
|
117
135
|
private parseWithdrawLpMemo;
|
|
118
136
|
/**
|
package/lib/utils/thornode.d.ts
CHANGED
|
@@ -61,9 +61,14 @@ export declare class Thornode {
|
|
|
61
61
|
getLastBlock(height?: number): Promise<LastBlock[]>;
|
|
62
62
|
/**
|
|
63
63
|
*
|
|
64
|
-
* @returns - thorchain
|
|
64
|
+
* @returns - thorchain pools
|
|
65
65
|
*/
|
|
66
66
|
getPools(): Promise<Pool[]>;
|
|
67
|
+
/**
|
|
68
|
+
*
|
|
69
|
+
* @returns - thorchain pool
|
|
70
|
+
*/
|
|
71
|
+
getPool(asset: string): Promise<Pool>;
|
|
67
72
|
/**
|
|
68
73
|
*
|
|
69
74
|
* @returns Thorchain constants
|
|
@@ -135,5 +140,5 @@ export declare class Thornode {
|
|
|
135
140
|
* @param height - block height
|
|
136
141
|
* @returns quotes swap object response
|
|
137
142
|
*/
|
|
138
|
-
getSwapQuote(fromAsset: string, toAsset: string, amount: number, destination: string, toleranceBps: number, affiliateBps: number, affiliate: string, height?: number): Promise<QuoteSwapResponse>;
|
|
143
|
+
getSwapQuote(fromAsset: string, toAsset: string, amount: number, destination: string, fromAddress: string, toleranceBps: number, affiliateBps: number, affiliate: string, height?: number): Promise<QuoteSwapResponse>;
|
|
139
144
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xchainjs/xchain-thorchain-query",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.19",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Thorchain query module that is resposible for estimating swap calculations and add/remove liquidity for thorchain ",
|
|
6
6
|
"keywords": [
|
|
@@ -33,18 +33,18 @@
|
|
|
33
33
|
"postversion": "git push --follow-tags"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@xchainjs/xchain-avax": "^0.1.
|
|
37
|
-
"@xchainjs/xchain-binance": "^5.6.
|
|
38
|
-
"@xchainjs/xchain-bitcoin": "^0.20.
|
|
39
|
-
"@xchainjs/xchain-bitcoincash": "^0.15.
|
|
36
|
+
"@xchainjs/xchain-avax": "^0.1.4",
|
|
37
|
+
"@xchainjs/xchain-binance": "^5.6.7",
|
|
38
|
+
"@xchainjs/xchain-bitcoin": "^0.20.9",
|
|
39
|
+
"@xchainjs/xchain-bitcoincash": "^0.15.7",
|
|
40
40
|
"@xchainjs/xchain-client": "^0.13.5",
|
|
41
|
-
"@xchainjs/xchain-cosmos": "^0.20.
|
|
42
|
-
"@xchainjs/xchain-doge": "^0.5.
|
|
43
|
-
"@xchainjs/xchain-ethereum": "^0.27.
|
|
44
|
-
"@xchainjs/xchain-litecoin": "^0.10.
|
|
45
|
-
"@xchainjs/xchain-midgard": "^0.4.
|
|
46
|
-
"@xchainjs/xchain-thorchain": "^0.27.
|
|
47
|
-
"@xchainjs/xchain-thornode": "^0.2.
|
|
41
|
+
"@xchainjs/xchain-cosmos": "^0.20.8",
|
|
42
|
+
"@xchainjs/xchain-doge": "^0.5.8",
|
|
43
|
+
"@xchainjs/xchain-ethereum": "^0.27.7",
|
|
44
|
+
"@xchainjs/xchain-litecoin": "^0.10.10",
|
|
45
|
+
"@xchainjs/xchain-midgard": "^0.4.3",
|
|
46
|
+
"@xchainjs/xchain-thorchain": "^0.27.9",
|
|
47
|
+
"@xchainjs/xchain-thornode": "^0.2.1",
|
|
48
48
|
"@xchainjs/xchain-util": "^0.12.0",
|
|
49
49
|
"axios": "^0.25.0",
|
|
50
50
|
"axios-retry": "^3.2.5",
|
|
@@ -52,18 +52,18 @@
|
|
|
52
52
|
"rimraf": "~3.0.2"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
|
-
"@xchainjs/xchain-avax": "^0.1.
|
|
56
|
-
"@xchainjs/xchain-binance": "^5.6.
|
|
57
|
-
"@xchainjs/xchain-
|
|
58
|
-
"@xchainjs/xchain-
|
|
59
|
-
"@xchainjs/xchain-doge": "^0.5.6",
|
|
60
|
-
"@xchainjs/xchain-ethereum": "^0.27.6",
|
|
61
|
-
"@xchainjs/xchain-bitcoin": "^0.20.7",
|
|
62
|
-
"@xchainjs/xchain-litecoin": "^0.10.8",
|
|
55
|
+
"@xchainjs/xchain-avax": "^0.1.4",
|
|
56
|
+
"@xchainjs/xchain-binance": "^5.6.7",
|
|
57
|
+
"@xchainjs/xchain-bitcoin": "^0.20.9",
|
|
58
|
+
"@xchainjs/xchain-bitcoincash": "^0.15.7",
|
|
63
59
|
"@xchainjs/xchain-client": "^0.13.5",
|
|
64
|
-
"@xchainjs/xchain-
|
|
65
|
-
"@xchainjs/xchain-
|
|
66
|
-
"@xchainjs/xchain-
|
|
60
|
+
"@xchainjs/xchain-cosmos": "^0.20.8",
|
|
61
|
+
"@xchainjs/xchain-doge": "^0.5.8",
|
|
62
|
+
"@xchainjs/xchain-ethereum": "^0.27.7",
|
|
63
|
+
"@xchainjs/xchain-litecoin": "^0.10.10",
|
|
64
|
+
"@xchainjs/xchain-midgard": "^0.4.3",
|
|
65
|
+
"@xchainjs/xchain-thorchain": "^0.27.9",
|
|
66
|
+
"@xchainjs/xchain-thornode": "^0.2.1",
|
|
67
67
|
"@xchainjs/xchain-util": "^0.12.0",
|
|
68
68
|
"axios": "^0.25.0",
|
|
69
69
|
"axios-retry": "^3.2.5",
|