@xchainjs/xchain-thorchain-query 0.7.17 → 1.0.1
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 +381 -84
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +379 -82
- package/lib/index.js.map +1 -1
- package/lib/liquidity-pool.d.ts +2 -2
- package/lib/thorchain-cache.d.ts +5 -4
- package/lib/thorchain-checktx.d.ts +2 -2
- package/lib/thorchain-query.d.ts +41 -8
- package/lib/types.d.ts +304 -48
- package/lib/utils/const.d.ts +3 -3
- package/lib/utils/thornode.d.ts +47 -1
- package/lib/utils/utils.d.ts +6 -6
- package/package.json +6 -6
package/lib/index.esm.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { assetFromString, baseAmount, assetFromStringEx, assetToString, CryptoAmount, eqAsset, CachedValue, assetToBase, assetAmount } from '@xchainjs/xchain-util';
|
|
1
|
+
import { assetFromString, baseAmount, assetFromStringEx, assetToString, CryptoAmount, isSynthAsset, AssetCryptoAmount, eqAsset, CachedValue, isTradeAsset, assetToBase, assetAmount } from '@xchainjs/xchain-util';
|
|
2
2
|
import { BigNumber } from 'bignumber.js';
|
|
3
3
|
import { MidgardQuery } from '@xchainjs/xchain-midgard-query';
|
|
4
4
|
import { Network } from '@xchainjs/xchain-client';
|
|
5
|
-
import { TransactionsApi, Configuration, QueueApi, NetworkApi, PoolsApi, LiquidityProvidersApi, SaversApi, QuoteApi, MimirApi, ThornamesApi } from '@xchainjs/xchain-thornode';
|
|
5
|
+
import { TransactionsApi, Configuration, QueueApi, NetworkApi, PoolsApi, LiquidityProvidersApi, SaversApi, QuoteApi, MimirApi, ThornamesApi, TradeUnitApi, TradeUnitsApi, TradeAccountApi, TradeAccountsApi, RUNEPoolApi } from '@xchainjs/xchain-thornode';
|
|
6
6
|
import axios from 'axios';
|
|
7
7
|
import axiosRetry from 'axios-retry';
|
|
8
8
|
|
|
@@ -188,49 +188,48 @@ const getChainAsset = (chain) => {
|
|
|
188
188
|
*/
|
|
189
189
|
const calcNetworkFee = (asset, inbound) => {
|
|
190
190
|
// synths are always 0.02R fee
|
|
191
|
-
if (asset
|
|
192
|
-
return new
|
|
191
|
+
if (isSynthAsset(asset))
|
|
192
|
+
return new AssetCryptoAmount(baseAmount(2000000), AssetRuneNative);
|
|
193
193
|
// if you are swapping a non-gas asset on a multiAsset chain (ex. ERC-20 on ETH), the
|
|
194
194
|
// gas fees will be paid in a diff asset than the one you are swapping
|
|
195
195
|
switch (asset.chain) {
|
|
196
196
|
case BTCChain:
|
|
197
|
-
return new
|
|
197
|
+
return new AssetCryptoAmount(baseAmount(inbound.gasRate.multipliedBy(inbound.outboundTxSize)), AssetBTC);
|
|
198
198
|
case BCHChain:
|
|
199
|
-
return new
|
|
199
|
+
return new AssetCryptoAmount(baseAmount(inbound.gasRate.multipliedBy(inbound.outboundTxSize)), AssetBCH);
|
|
200
200
|
case LTCChain:
|
|
201
|
-
return new
|
|
201
|
+
return new AssetCryptoAmount(baseAmount(inbound.gasRate.multipliedBy(inbound.outboundTxSize)), AssetLTC);
|
|
202
202
|
case DOGEChain:
|
|
203
203
|
// NOTE: UTXO chains estimate fees with a 250 byte size
|
|
204
|
-
return new
|
|
204
|
+
return new AssetCryptoAmount(baseAmount(inbound.gasRate.multipliedBy(inbound.outboundTxSize)), AssetDOGE);
|
|
205
205
|
case BNBChain:
|
|
206
|
-
|
|
207
|
-
return new CryptoAmount(baseAmount(inbound.gasRate), AssetBNB);
|
|
206
|
+
return new AssetCryptoAmount(baseAmount(inbound.gasRate), AssetBNB);
|
|
208
207
|
case ETHChain:
|
|
209
208
|
const gasRateinETHGwei = inbound.gasRate;
|
|
210
209
|
const gasRateinETHWei = baseAmount(gasRateinETHGwei.multipliedBy(Math.pow(10, 9)), 18);
|
|
211
210
|
if (eqAsset(asset, AssetETH)) {
|
|
212
|
-
return new
|
|
211
|
+
return new AssetCryptoAmount(gasRateinETHWei.times(21000), AssetETH);
|
|
213
212
|
}
|
|
214
213
|
else {
|
|
215
|
-
return new
|
|
214
|
+
return new AssetCryptoAmount(gasRateinETHWei.times(70000), AssetETH);
|
|
216
215
|
}
|
|
217
216
|
case AVAXChain:
|
|
218
217
|
const gasRateinAVAXGwei = inbound.gasRate;
|
|
219
218
|
const gasRateinAVAXWei = baseAmount(gasRateinAVAXGwei.multipliedBy(Math.pow(10, 9)), 18);
|
|
220
219
|
if (eqAsset(asset, AssetAVAX)) {
|
|
221
|
-
return new
|
|
220
|
+
return new AssetCryptoAmount(gasRateinAVAXWei.times(21000), AssetAVAX);
|
|
222
221
|
}
|
|
223
222
|
else {
|
|
224
|
-
return new
|
|
223
|
+
return new AssetCryptoAmount(gasRateinAVAXWei.times(70000), AssetAVAX);
|
|
225
224
|
}
|
|
226
225
|
case GAIAChain:
|
|
227
|
-
return new
|
|
226
|
+
return new AssetCryptoAmount(baseAmount(inbound.gasRate), AssetATOM);
|
|
228
227
|
case THORChain:
|
|
229
|
-
return new
|
|
228
|
+
return new AssetCryptoAmount(baseAmount(2000000), AssetRuneNative);
|
|
230
229
|
case BSCChain:
|
|
231
|
-
return new
|
|
230
|
+
return new AssetCryptoAmount(baseAmount(inbound.gasRate), AssetBSC);
|
|
232
231
|
case MAYAChain:
|
|
233
|
-
return new
|
|
232
|
+
return new AssetCryptoAmount(baseAmount(inbound.gasRate), AssetMAYA);
|
|
234
233
|
}
|
|
235
234
|
throw new Error(`could not calculate inbound fee for ${asset.chain}`);
|
|
236
235
|
};
|
|
@@ -244,33 +243,33 @@ const calcNetworkFee = (asset, inbound) => {
|
|
|
244
243
|
* @returns
|
|
245
244
|
*/
|
|
246
245
|
const calcOutboundFee = (asset, inbound) => {
|
|
247
|
-
if (asset
|
|
248
|
-
return new
|
|
246
|
+
if (isSynthAsset(asset))
|
|
247
|
+
return new AssetCryptoAmount(baseAmount(2000000), AssetRuneNative);
|
|
249
248
|
switch (asset.chain) {
|
|
250
249
|
case BTCChain:
|
|
251
|
-
return new
|
|
250
|
+
return new AssetCryptoAmount(baseAmount(inbound.outboundFee), AssetBTC);
|
|
252
251
|
case BCHChain:
|
|
253
|
-
return new
|
|
252
|
+
return new AssetCryptoAmount(baseAmount(inbound.outboundFee), AssetBCH);
|
|
254
253
|
case LTCChain:
|
|
255
|
-
return new
|
|
254
|
+
return new AssetCryptoAmount(baseAmount(inbound.outboundFee), AssetLTC);
|
|
256
255
|
case DOGEChain:
|
|
257
256
|
// NOTE: UTXO chains estimate fees with a 250 byte size
|
|
258
|
-
return new
|
|
257
|
+
return new AssetCryptoAmount(baseAmount(inbound.outboundFee), AssetDOGE);
|
|
259
258
|
case BNBChain:
|
|
260
259
|
//flat fee
|
|
261
|
-
return new
|
|
260
|
+
return new AssetCryptoAmount(baseAmount(inbound.outboundFee), AssetBNB);
|
|
262
261
|
case ETHChain:
|
|
263
|
-
return new
|
|
262
|
+
return new AssetCryptoAmount(baseAmount(inbound.outboundFee.multipliedBy(Math.pow(10, 9)), 18), AssetETH);
|
|
264
263
|
case AVAXChain:
|
|
265
|
-
return new
|
|
264
|
+
return new AssetCryptoAmount(baseAmount(inbound.outboundFee.multipliedBy(Math.pow(10, 9)), 18), AssetAVAX);
|
|
266
265
|
case GAIAChain:
|
|
267
|
-
return new
|
|
266
|
+
return new AssetCryptoAmount(baseAmount(inbound.outboundFee), AssetATOM);
|
|
268
267
|
case BSCChain:
|
|
269
|
-
return new
|
|
268
|
+
return new AssetCryptoAmount(baseAmount(inbound.outboundFee), AssetBSC);
|
|
270
269
|
case THORChain:
|
|
271
|
-
return new
|
|
270
|
+
return new AssetCryptoAmount(baseAmount(2000000), AssetRuneNative);
|
|
272
271
|
case MAYAChain:
|
|
273
|
-
return new
|
|
272
|
+
return new AssetCryptoAmount(baseAmount(2000000), AssetMAYA);
|
|
274
273
|
}
|
|
275
274
|
throw new Error(`could not calculate outbound fee for ${asset.chain}`);
|
|
276
275
|
};
|
|
@@ -394,6 +393,11 @@ class Thornode {
|
|
|
394
393
|
this.quoteApi = this.config.thornodeBaseUrls.map((url) => new QuoteApi(new Configuration({ basePath: url })));
|
|
395
394
|
this.mimirApi = this.config.thornodeBaseUrls.map((url) => new MimirApi(new Configuration({ basePath: url })));
|
|
396
395
|
this.thornamesApi = this.config.thornodeBaseUrls.map((url) => new ThornamesApi(new Configuration({ basePath: url })));
|
|
396
|
+
this.tradeUnitApi = this.config.thornodeBaseUrls.map((url) => new TradeUnitApi(new Configuration({ basePath: url })));
|
|
397
|
+
this.tradeUnitsApi = this.config.thornodeBaseUrls.map((url) => new TradeUnitsApi(new Configuration({ basePath: url })));
|
|
398
|
+
this.tradeAccountApi = this.config.thornodeBaseUrls.map((url) => new TradeAccountApi(new Configuration({ basePath: url })));
|
|
399
|
+
this.tradeAccountsApi = this.config.thornodeBaseUrls.map((url) => new TradeAccountsApi(new Configuration({ basePath: url })));
|
|
400
|
+
this.runePoolApi = this.config.thornodeBaseUrls.map((url) => new RUNEPoolApi(new Configuration({ basePath: url })));
|
|
397
401
|
}
|
|
398
402
|
/**
|
|
399
403
|
* Returns the oubound transactions held by THORChain due to outbound delay
|
|
@@ -814,6 +818,129 @@ class Thornode {
|
|
|
814
818
|
throw new Error(`THORNode is not responding`);
|
|
815
819
|
});
|
|
816
820
|
}
|
|
821
|
+
/*
|
|
822
|
+
* Returns the total units and depth of a trade asset
|
|
823
|
+
* @param {string} asset Trade asset
|
|
824
|
+
* @param {number} height Optional - Block height
|
|
825
|
+
* @returns Returns the total units and depth of a trade asset
|
|
826
|
+
*/
|
|
827
|
+
getTradeAssetUnits(asset, height) {
|
|
828
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
829
|
+
for (const api of this.tradeUnitApi) {
|
|
830
|
+
try {
|
|
831
|
+
const resp = (yield api.tradeUnit(asset, height)).data;
|
|
832
|
+
return resp;
|
|
833
|
+
}
|
|
834
|
+
catch (e) { }
|
|
835
|
+
}
|
|
836
|
+
throw new Error(`THORNode is not responding. Can not get asset trade units`);
|
|
837
|
+
});
|
|
838
|
+
}
|
|
839
|
+
/**
|
|
840
|
+
* Returns the total units and depth for each trade asset
|
|
841
|
+
* @param {number} height Block height
|
|
842
|
+
* @returns Returns the total units and depth for each trade asset
|
|
843
|
+
*/
|
|
844
|
+
getTradeAssetsUnits(height) {
|
|
845
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
846
|
+
for (const api of this.tradeUnitsApi) {
|
|
847
|
+
try {
|
|
848
|
+
const resp = (yield api.tradeUnits(height)).data;
|
|
849
|
+
return resp;
|
|
850
|
+
}
|
|
851
|
+
catch (e) { }
|
|
852
|
+
}
|
|
853
|
+
throw new Error(`THORNode is not responding. Can not get trade units`);
|
|
854
|
+
});
|
|
855
|
+
}
|
|
856
|
+
/**
|
|
857
|
+
* Returns the units and depth of a trade account address
|
|
858
|
+
* @param {Address} address Thorchain address
|
|
859
|
+
* @param {number} height Optional - Block height
|
|
860
|
+
* @returns Returns the units and depth of a trade account
|
|
861
|
+
*/
|
|
862
|
+
getTradeAssetAccount(address, height) {
|
|
863
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
864
|
+
for (const api of this.tradeAccountApi) {
|
|
865
|
+
try {
|
|
866
|
+
const resp = (yield api.tradeAccount(address, height)).data;
|
|
867
|
+
return resp;
|
|
868
|
+
}
|
|
869
|
+
catch (e) { }
|
|
870
|
+
}
|
|
871
|
+
throw new Error(`THORNode is not responding. Can not get trade asset account`);
|
|
872
|
+
});
|
|
873
|
+
}
|
|
874
|
+
/**
|
|
875
|
+
* Returns all trade accounts for an asset
|
|
876
|
+
* @param {Address} address Thorchain address
|
|
877
|
+
* @param {number} height Optional - Block height
|
|
878
|
+
* @returns Returns all trade accounts for an asset
|
|
879
|
+
*/
|
|
880
|
+
getTradeAssetAccounts(asset, height) {
|
|
881
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
882
|
+
for (const api of this.tradeAccountsApi) {
|
|
883
|
+
try {
|
|
884
|
+
const resp = (yield api.tradeAccounts(asset, height)).data;
|
|
885
|
+
return resp;
|
|
886
|
+
}
|
|
887
|
+
catch (e) { }
|
|
888
|
+
}
|
|
889
|
+
throw new Error(`THORNode is not responding. Can not get trade asset accounts`);
|
|
890
|
+
});
|
|
891
|
+
}
|
|
892
|
+
/**
|
|
893
|
+
* Get rune pool information
|
|
894
|
+
* @param {number} height block height
|
|
895
|
+
* @returns {RUNEPoolResponse} the pool information for the RUNE pool.
|
|
896
|
+
*/
|
|
897
|
+
getRunePool(height) {
|
|
898
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
899
|
+
for (const api of this.runePoolApi) {
|
|
900
|
+
try {
|
|
901
|
+
const resp = (yield api.runePool(height)).data;
|
|
902
|
+
return resp;
|
|
903
|
+
}
|
|
904
|
+
catch (e) { }
|
|
905
|
+
}
|
|
906
|
+
throw new Error(`THORNode is not responding. Can not get Rune pool`);
|
|
907
|
+
});
|
|
908
|
+
}
|
|
909
|
+
/**
|
|
910
|
+
* Get Rune pool provider information
|
|
911
|
+
* @param {string} address of which return the info
|
|
912
|
+
* @param {number} height block height
|
|
913
|
+
* @returns {RUNEProvider} the RUNE Provider information for an address.
|
|
914
|
+
*/
|
|
915
|
+
getRunePoolProvider(address, height) {
|
|
916
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
917
|
+
for (const api of this.runePoolApi) {
|
|
918
|
+
try {
|
|
919
|
+
const resp = (yield api.runeProvider(address, height)).data;
|
|
920
|
+
return resp;
|
|
921
|
+
}
|
|
922
|
+
catch (e) { }
|
|
923
|
+
}
|
|
924
|
+
throw new Error(`THORNode is not responding. Can not get Rune pool provider info`);
|
|
925
|
+
});
|
|
926
|
+
}
|
|
927
|
+
/**
|
|
928
|
+
* Get all Rune pool providers information
|
|
929
|
+
* @param {number} height block height
|
|
930
|
+
* @returns {RUNEProvidersResponse} all Rune Providers.
|
|
931
|
+
*/
|
|
932
|
+
getRunePoolProviders(height) {
|
|
933
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
934
|
+
for (const api of this.runePoolApi) {
|
|
935
|
+
try {
|
|
936
|
+
const resp = (yield api.runeProviders(height)).data;
|
|
937
|
+
return resp;
|
|
938
|
+
}
|
|
939
|
+
catch (e) { }
|
|
940
|
+
}
|
|
941
|
+
throw new Error(`THORNode is not responding. Can not get all Rune providers info`);
|
|
942
|
+
});
|
|
943
|
+
}
|
|
817
944
|
}
|
|
818
945
|
|
|
819
946
|
// Constants
|
|
@@ -856,18 +983,22 @@ class ThorchainCache {
|
|
|
856
983
|
}
|
|
857
984
|
else if (isAssetRuneNative(from)) {
|
|
858
985
|
// Runes per Asset
|
|
859
|
-
const
|
|
986
|
+
const poolToAsset = isSynthAsset(to) || isTradeAsset(to) ? yield this.getAnalogAsset(to) : to;
|
|
987
|
+
const lpTo = yield this.getPoolForAsset(poolToAsset);
|
|
860
988
|
exchangeRate = lpTo.assetToRuneRatio;
|
|
861
989
|
}
|
|
862
990
|
else if (isAssetRuneNative(to)) {
|
|
863
991
|
// Asset per rune
|
|
864
|
-
const
|
|
992
|
+
const poolFromAsset = isSynthAsset(from) || isTradeAsset(from) ? yield this.getAnalogAsset(from) : from;
|
|
993
|
+
const lpFrom = yield this.getPoolForAsset(poolFromAsset);
|
|
865
994
|
exchangeRate = lpFrom.runeToAssetRatio;
|
|
866
995
|
}
|
|
867
996
|
else {
|
|
868
997
|
// AssetA per AssetB
|
|
869
|
-
const
|
|
870
|
-
const
|
|
998
|
+
const poolFromAsset = isSynthAsset(from) || isTradeAsset(from) ? yield this.getAnalogAsset(from) : from;
|
|
999
|
+
const poolToAsset = isSynthAsset(to) || isTradeAsset(to) ? yield this.getAnalogAsset(to) : to;
|
|
1000
|
+
const lpFrom = yield this.getPoolForAsset(poolFromAsset);
|
|
1001
|
+
const lpTo = yield this.getPoolForAsset(poolToAsset);
|
|
871
1002
|
// from/R * R/to = from/to
|
|
872
1003
|
exchangeRate = lpFrom.runeToAssetRatio.times(lpTo.assetToRuneRatio);
|
|
873
1004
|
}
|
|
@@ -1057,6 +1188,17 @@ class ThorchainCache {
|
|
|
1057
1188
|
}
|
|
1058
1189
|
});
|
|
1059
1190
|
}
|
|
1191
|
+
getAnalogAsset(asset) {
|
|
1192
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1193
|
+
const pools = yield this.getPools();
|
|
1194
|
+
const analogAssetPool = Object.values(pools).find((pool) => {
|
|
1195
|
+
return (pool.asset.chain === asset.chain && pool.asset.ticker === asset.ticker && pool.asset.symbol === asset.symbol);
|
|
1196
|
+
});
|
|
1197
|
+
if (!analogAssetPool)
|
|
1198
|
+
throw Error(`Can not find analog asset pool for ${assetToString(asset)}`);
|
|
1199
|
+
return analogAssetPool.asset;
|
|
1200
|
+
});
|
|
1201
|
+
}
|
|
1060
1202
|
}
|
|
1061
1203
|
|
|
1062
1204
|
const defaultCache = new ThorchainCache();
|
|
@@ -1110,13 +1252,13 @@ class ThorchainQuery {
|
|
|
1110
1252
|
return {
|
|
1111
1253
|
memo: ``,
|
|
1112
1254
|
toAddress: ``,
|
|
1113
|
-
dustThreshold: new
|
|
1255
|
+
dustThreshold: new AssetCryptoAmount(baseAmount(0), AssetRuneNative),
|
|
1114
1256
|
expiry: new Date(),
|
|
1115
1257
|
txEstimate: {
|
|
1116
1258
|
totalFees: {
|
|
1117
1259
|
asset: destinationAsset,
|
|
1118
|
-
affiliateFee: new
|
|
1119
|
-
outboundFee: new
|
|
1260
|
+
affiliateFee: new AssetCryptoAmount(baseAmount(0), AssetRuneNative),
|
|
1261
|
+
outboundFee: new AssetCryptoAmount(baseAmount(0), AssetRuneNative),
|
|
1120
1262
|
},
|
|
1121
1263
|
slipBasisPoints: 0,
|
|
1122
1264
|
netOutput: new CryptoAmount(baseAmount(0), destinationAsset),
|
|
@@ -1124,7 +1266,7 @@ class ThorchainQuery {
|
|
|
1124
1266
|
inboundConfirmationSeconds: 0,
|
|
1125
1267
|
canSwap: false,
|
|
1126
1268
|
errors,
|
|
1127
|
-
netOutputStreaming: new
|
|
1269
|
+
netOutputStreaming: new AssetCryptoAmount(baseAmount(0), AssetRuneNative),
|
|
1128
1270
|
maxStreamingQuantity: 0,
|
|
1129
1271
|
outboundDelayBlocks: 0,
|
|
1130
1272
|
streamingSlipBasisPoints: 0,
|
|
@@ -1153,19 +1295,19 @@ class ThorchainQuery {
|
|
|
1153
1295
|
expiry: new Date(swapQuote.expiry * 1000),
|
|
1154
1296
|
txEstimate: {
|
|
1155
1297
|
totalFees: {
|
|
1156
|
-
asset:
|
|
1298
|
+
asset: destinationAsset,
|
|
1157
1299
|
affiliateFee: getCryptoAmountWithNotation(new CryptoAmount(baseAmount(swapQuote.fees.affiliate), feeAsset), feeAssetDecimals),
|
|
1158
1300
|
outboundFee: getCryptoAmountWithNotation(new CryptoAmount(baseAmount(swapQuote.fees.outbound), feeAsset), feeAssetDecimals),
|
|
1159
1301
|
},
|
|
1160
|
-
slipBasisPoints: swapQuote.slippage_bps,
|
|
1302
|
+
slipBasisPoints: swapQuote.fees.slippage_bps,
|
|
1161
1303
|
netOutput: getCryptoAmountWithNotation(new CryptoAmount(baseAmount(swapQuote.expected_amount_out), destinationAsset), destinationAssetDecimals),
|
|
1162
|
-
netOutputStreaming: getCryptoAmountWithNotation(new CryptoAmount(baseAmount(swapQuote.
|
|
1304
|
+
netOutputStreaming: getCryptoAmountWithNotation(new CryptoAmount(baseAmount(swapQuote.expected_amount_out), destinationAsset), destinationAssetDecimals),
|
|
1163
1305
|
outboundDelaySeconds: swapQuote.outbound_delay_seconds,
|
|
1164
1306
|
inboundConfirmationSeconds: swapQuote.inbound_confirmation_seconds,
|
|
1165
1307
|
recommendedMinAmountIn: swapQuote.recommended_min_amount_in,
|
|
1166
1308
|
maxStreamingQuantity: swapQuote.max_streaming_quantity ? swapQuote.max_streaming_quantity : 0,
|
|
1167
1309
|
outboundDelayBlocks: swapQuote.outbound_delay_blocks,
|
|
1168
|
-
streamingSlipBasisPoints: swapQuote.
|
|
1310
|
+
streamingSlipBasisPoints: swapQuote.fees.slippage_bps,
|
|
1169
1311
|
streamingSwapBlocks: swapQuote.streaming_swap_blocks ? swapQuote.streaming_swap_blocks : 0,
|
|
1170
1312
|
streamingSwapSeconds: swapQuote.streaming_swap_seconds ? swapQuote.streaming_swap_seconds : 0,
|
|
1171
1313
|
totalSwapSeconds: swapQuote.total_swap_seconds ? swapQuote.total_swap_seconds : 0,
|
|
@@ -1202,16 +1344,16 @@ class ThorchainQuery {
|
|
|
1202
1344
|
// Retrieve network values
|
|
1203
1345
|
const networkValues = yield this.thorchainCache.getNetworkValues();
|
|
1204
1346
|
// Create CryptoAmounts for minimum transaction out volume threshold and maximum transaction out offset
|
|
1205
|
-
const minTxOutVolumeThreshold = new
|
|
1347
|
+
const minTxOutVolumeThreshold = new AssetCryptoAmount(baseAmount(networkValues['MINTXOUTVOLUMETHRESHOLD']), AssetRuneNative);
|
|
1206
1348
|
const maxTxOutOffset = networkValues['MAXTXOUTOFFSET'];
|
|
1207
1349
|
// Get the delay rate for outbound transactions
|
|
1208
|
-
let txOutDelayRate = new
|
|
1350
|
+
let txOutDelayRate = new AssetCryptoAmount(baseAmount(networkValues['TXOUTDELAYRATE']), AssetRuneNative).assetAmount
|
|
1209
1351
|
.amount()
|
|
1210
1352
|
.toNumber();
|
|
1211
1353
|
// Get the outbound queue
|
|
1212
1354
|
const getQueue = yield this.thorchainCache.thornode.getQueue();
|
|
1213
1355
|
// Create a CryptoAmount for the scheduled outbound value
|
|
1214
|
-
const outboundValue = new
|
|
1356
|
+
const outboundValue = new AssetCryptoAmount(baseAmount(getQueue.scheduled_outbound_value), AssetRuneNative);
|
|
1215
1357
|
// Get the average block time for THORChain
|
|
1216
1358
|
const thorChainblocktime = this.chainAttributes[THORChain].avgBlockTimeInSecs; // blocks required to confirm tx
|
|
1217
1359
|
// Convert the outbound amount to its value in RUNE
|
|
@@ -1284,7 +1426,7 @@ class ThorchainQuery {
|
|
|
1284
1426
|
if (isAssetRuneNative(inbound.asset) ||
|
|
1285
1427
|
inbound.asset.chain == BNBChain ||
|
|
1286
1428
|
inbound.asset.chain == GAIAChain ||
|
|
1287
|
-
inbound.asset
|
|
1429
|
+
isSynthAsset(inbound.asset)) {
|
|
1288
1430
|
// Return the average block time for THORChain
|
|
1289
1431
|
return this.chainAttributes[THORChain].avgBlockTimeInSecs;
|
|
1290
1432
|
}
|
|
@@ -1309,8 +1451,9 @@ class ThorchainQuery {
|
|
|
1309
1451
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1310
1452
|
const errors = [];
|
|
1311
1453
|
// Check if either of the assets are synths or if the rune is not THOR.RUNE
|
|
1312
|
-
if (params.asset.asset
|
|
1454
|
+
if (isSynthAsset(params.asset.asset) || isSynthAsset(params.rune.asset)) {
|
|
1313
1455
|
errors.push('you cannot add liquidity with a synth');
|
|
1456
|
+
}
|
|
1314
1457
|
if (!isAssetRuneNative(params.rune.asset))
|
|
1315
1458
|
errors.push('params.rune must be THOR.RUNE');
|
|
1316
1459
|
// Get the pool for the asset
|
|
@@ -1332,7 +1475,7 @@ class ThorchainQuery {
|
|
|
1332
1475
|
const waitTimeSeconds = assetWaitTimeSeconds > runeWaitTimeSeconds ? assetWaitTimeSeconds : runeWaitTimeSeconds;
|
|
1333
1476
|
// Calculate inbound fees
|
|
1334
1477
|
let assetInboundFee = new CryptoAmount(baseAmount(0), params.asset.asset);
|
|
1335
|
-
let runeInboundFee = new
|
|
1478
|
+
let runeInboundFee = new AssetCryptoAmount(baseAmount(0), AssetRuneNative);
|
|
1336
1479
|
if (!params.asset.assetAmount.eq(0)) {
|
|
1337
1480
|
assetInboundFee = calcNetworkFee(params.asset.asset, inboundDetails[params.asset.asset.chain]);
|
|
1338
1481
|
if (assetInboundFee.assetAmount.amount().times(3).gt(params.asset.assetAmount.amount()))
|
|
@@ -1461,7 +1604,7 @@ class ThorchainQuery {
|
|
|
1461
1604
|
// Check liquidity position for the provided asset
|
|
1462
1605
|
const memberDetail = yield this.checkLiquidityPosition(params.asset, assetOrRuneAddress);
|
|
1463
1606
|
// Get dust values
|
|
1464
|
-
const dustValues = yield this.getDustValues(params.asset); // returns asset and rune dust values
|
|
1607
|
+
const dustValues = yield this.getDustValues(getChainAsset(params.asset.chain)); // returns asset and rune dust values
|
|
1465
1608
|
// Get asset pool
|
|
1466
1609
|
const assetPool = yield this.thorchainCache.getPoolForAsset(params.asset);
|
|
1467
1610
|
// Calculate pool share
|
|
@@ -1544,58 +1687,58 @@ class ThorchainQuery {
|
|
|
1544
1687
|
switch (asset.chain) {
|
|
1545
1688
|
case 'BNB':
|
|
1546
1689
|
return {
|
|
1547
|
-
asset: new
|
|
1548
|
-
rune: new
|
|
1690
|
+
asset: new AssetCryptoAmount(assetToBase(assetAmount(0.000001, assetDecimals)), AssetBNB),
|
|
1691
|
+
rune: new AssetCryptoAmount(assetToBase(assetAmount(0)), AssetRuneNative),
|
|
1549
1692
|
};
|
|
1550
1693
|
case 'BTC':
|
|
1551
1694
|
case `BCH`:
|
|
1552
1695
|
case `LTC`:
|
|
1553
1696
|
// Dust value: 10k sats
|
|
1554
1697
|
return {
|
|
1555
|
-
asset: new
|
|
1556
|
-
rune: new
|
|
1698
|
+
asset: new AssetCryptoAmount(assetToBase(assetAmount(0.0001, assetDecimals)), asset),
|
|
1699
|
+
rune: new AssetCryptoAmount(assetToBase(assetAmount(0)), AssetRuneNative),
|
|
1557
1700
|
};
|
|
1558
1701
|
case 'ETH':
|
|
1559
1702
|
// Dust value: 0 wei
|
|
1560
1703
|
return {
|
|
1561
|
-
asset: new
|
|
1562
|
-
rune: new
|
|
1704
|
+
asset: new AssetCryptoAmount(assetToBase(assetAmount(0, assetDecimals)), asset),
|
|
1705
|
+
rune: new AssetCryptoAmount(assetToBase(assetAmount(0)), AssetRuneNative),
|
|
1563
1706
|
};
|
|
1564
1707
|
case 'THOR':
|
|
1565
1708
|
// Dust value: 0 Rune
|
|
1566
1709
|
return {
|
|
1567
|
-
asset: new
|
|
1568
|
-
rune: new
|
|
1710
|
+
asset: new AssetCryptoAmount(assetToBase(assetAmount(0, assetDecimals)), asset),
|
|
1711
|
+
rune: new AssetCryptoAmount(assetToBase(assetAmount(0)), AssetRuneNative),
|
|
1569
1712
|
};
|
|
1570
1713
|
case 'GAIA':
|
|
1571
1714
|
// Dust value: 0 GAIA
|
|
1572
1715
|
return {
|
|
1573
|
-
asset: new
|
|
1574
|
-
rune: new
|
|
1716
|
+
asset: new AssetCryptoAmount(assetToBase(assetAmount(0, assetDecimals)), asset),
|
|
1717
|
+
rune: new AssetCryptoAmount(assetToBase(assetAmount(0)), AssetRuneNative),
|
|
1575
1718
|
};
|
|
1576
1719
|
case 'DOGE':
|
|
1577
1720
|
// Dust value: 1 million sats
|
|
1578
1721
|
return {
|
|
1579
|
-
asset: new
|
|
1580
|
-
rune: new
|
|
1722
|
+
asset: new AssetCryptoAmount(assetToBase(assetAmount(0.01, assetDecimals)), asset),
|
|
1723
|
+
rune: new AssetCryptoAmount(assetToBase(assetAmount(0)), AssetRuneNative),
|
|
1581
1724
|
};
|
|
1582
1725
|
case 'AVAX':
|
|
1583
1726
|
// Dust value: 0 AVAX
|
|
1584
1727
|
return {
|
|
1585
|
-
asset: new
|
|
1586
|
-
rune: new
|
|
1728
|
+
asset: new AssetCryptoAmount(assetToBase(assetAmount(0, assetDecimals)), asset),
|
|
1729
|
+
rune: new AssetCryptoAmount(assetToBase(assetAmount(0)), AssetRuneNative),
|
|
1587
1730
|
};
|
|
1588
1731
|
case 'BSC':
|
|
1589
1732
|
// Dust value: 0 BSC
|
|
1590
1733
|
return {
|
|
1591
|
-
asset: new
|
|
1592
|
-
rune: new
|
|
1734
|
+
asset: new AssetCryptoAmount(assetToBase(assetAmount(0, assetDecimals)), asset),
|
|
1735
|
+
rune: new AssetCryptoAmount(assetToBase(assetAmount(0)), AssetRuneNative),
|
|
1593
1736
|
};
|
|
1594
1737
|
case 'MAYA':
|
|
1595
1738
|
// Dust value: 0 MAYA
|
|
1596
1739
|
return {
|
|
1597
|
-
asset: new
|
|
1598
|
-
rune: new
|
|
1740
|
+
asset: new AssetCryptoAmount(assetToBase(assetAmount(0, assetDecimals)), asset),
|
|
1741
|
+
rune: new AssetCryptoAmount(assetToBase(assetAmount(0)), AssetRuneNative),
|
|
1599
1742
|
};
|
|
1600
1743
|
default:
|
|
1601
1744
|
throw Error('Unknown chain'); // Throw error for unknown chain
|
|
@@ -1660,19 +1803,20 @@ class ThorchainQuery {
|
|
|
1660
1803
|
// Get fee asset decimals
|
|
1661
1804
|
const feeAssetDecimals = yield this.thorchainCache.midgardQuery.getDecimalForAsset(addAmount.asset);
|
|
1662
1805
|
// Organize fees
|
|
1806
|
+
const feeAsset = assetFromStringEx(depositQuote.fees.asset);
|
|
1663
1807
|
const saverFees = {
|
|
1664
1808
|
affiliate: getCryptoAmountWithNotation(
|
|
1665
1809
|
// Affiliate fee
|
|
1666
1810
|
new CryptoAmount(baseAmount(depositQuote.fees.affiliate), addAmount.asset), // Convert to base amount
|
|
1667
1811
|
assetDecimals),
|
|
1668
|
-
asset:
|
|
1812
|
+
asset: feeAsset,
|
|
1669
1813
|
outbound: getCryptoAmountWithNotation(
|
|
1670
1814
|
// Outbound fee
|
|
1671
|
-
new CryptoAmount(baseAmount(depositQuote.fees.outbound),
|
|
1815
|
+
new CryptoAmount(baseAmount(depositQuote.fees.outbound), feeAsset), // Convert to base amount
|
|
1672
1816
|
feeAssetDecimals),
|
|
1673
1817
|
liquidity: getCryptoAmountWithNotation(
|
|
1674
1818
|
// Liquidity fee
|
|
1675
|
-
new CryptoAmount(baseAmount(depositQuote.fees.liquidity),
|
|
1819
|
+
new CryptoAmount(baseAmount(depositQuote.fees.liquidity), feeAsset), // Convert to base amount
|
|
1676
1820
|
feeAssetDecimals),
|
|
1677
1821
|
totalBps: depositQuote.fees.total_bps || 0, // Total basis points
|
|
1678
1822
|
};
|
|
@@ -1694,7 +1838,7 @@ class ThorchainQuery {
|
|
|
1694
1838
|
memo: depositQuote.memo,
|
|
1695
1839
|
estimatedWaitTime: depositQuote.inbound_confirmation_seconds || 0,
|
|
1696
1840
|
canAddSaver: errors.length === 0,
|
|
1697
|
-
slipBasisPoints: depositQuote.slippage_bps,
|
|
1841
|
+
slipBasisPoints: depositQuote.fees.slippage_bps,
|
|
1698
1842
|
saverCapFilledPercent,
|
|
1699
1843
|
recommendedMinAmountIn: depositQuote.recommended_min_amount_in,
|
|
1700
1844
|
errors, // Errors
|
|
@@ -1711,7 +1855,7 @@ class ThorchainQuery {
|
|
|
1711
1855
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1712
1856
|
const errors = []; // Initialize errors array
|
|
1713
1857
|
// Return error if asset in is incorrect
|
|
1714
|
-
if (isAssetRuneNative(withdrawParams.asset) || withdrawParams.asset
|
|
1858
|
+
if (isAssetRuneNative(withdrawParams.asset) || isSynthAsset(withdrawParams.asset))
|
|
1715
1859
|
errors.push(`Native Rune and synth assets are not supported only L1's`);
|
|
1716
1860
|
// Get inbound details
|
|
1717
1861
|
const inboundDetails = yield this.thorchainCache.getInboundDetails();
|
|
@@ -1723,8 +1867,8 @@ class ThorchainQuery {
|
|
|
1723
1867
|
errors.push(checkPositon.errors[i]);
|
|
1724
1868
|
}
|
|
1725
1869
|
return {
|
|
1726
|
-
dustAmount: new
|
|
1727
|
-
dustThreshold: new
|
|
1870
|
+
dustAmount: new AssetCryptoAmount(baseAmount(0), getChainAsset(withdrawParams.asset.chain)),
|
|
1871
|
+
dustThreshold: new AssetCryptoAmount(baseAmount(0), getChainAsset(withdrawParams.asset.chain)),
|
|
1728
1872
|
expectedAssetAmount: new CryptoAmount(// Expected asset amount
|
|
1729
1873
|
assetToBase(assetAmount(checkPositon.redeemableValue.assetAmount.amount())), // Convert to base amount
|
|
1730
1874
|
withdrawParams.asset),
|
|
@@ -1756,8 +1900,8 @@ class ThorchainQuery {
|
|
|
1756
1900
|
if (errors.length > 0) {
|
|
1757
1901
|
// Return default values and errors if there are any errors
|
|
1758
1902
|
return {
|
|
1759
|
-
dustAmount: new
|
|
1760
|
-
dustThreshold: new
|
|
1903
|
+
dustAmount: new AssetCryptoAmount(baseAmount(0), getChainAsset(withdrawParams.asset.chain)),
|
|
1904
|
+
dustThreshold: new AssetCryptoAmount(baseAmount(0), getChainAsset(withdrawParams.asset.chain)),
|
|
1761
1905
|
expectedAssetAmount: new CryptoAmount(assetToBase(assetAmount(0)), withdrawParams.asset),
|
|
1762
1906
|
fee: {
|
|
1763
1907
|
affiliate: new CryptoAmount(baseAmount(0), withdrawParams.asset),
|
|
@@ -1786,9 +1930,9 @@ class ThorchainQuery {
|
|
|
1786
1930
|
// Create an EstimateWithdrawSaver object with the necessary data
|
|
1787
1931
|
const estimateWithdrawSaver = {
|
|
1788
1932
|
// Format the dust amount with appropriate notation and decimals
|
|
1789
|
-
dustAmount: getCryptoAmountWithNotation(new
|
|
1933
|
+
dustAmount: getCryptoAmountWithNotation(new AssetCryptoAmount(baseAmount(withdrawQuote.dust_amount), chainAsset), chainAssetDecimals),
|
|
1790
1934
|
// Format the dust threshold with appropriate notation and decimals
|
|
1791
|
-
dustThreshold: getCryptoAmountWithNotation(new
|
|
1935
|
+
dustThreshold: getCryptoAmountWithNotation(new AssetCryptoAmount(baseAmount(withdrawQuote.dust_threshold), chainAsset), chainAssetDecimals),
|
|
1792
1936
|
// Format the expected asset amount with appropriate notation and decimals
|
|
1793
1937
|
expectedAssetAmount: getCryptoAmountWithNotation(new CryptoAmount(baseAmount(withdrawQuote.expected_amount_out), withdrawParams.asset), withdrawAssetDecimals),
|
|
1794
1938
|
// Format the withdrawal fees with appropriate notation and decimals
|
|
@@ -1814,7 +1958,7 @@ class ThorchainQuery {
|
|
|
1814
1958
|
// Set the outbound delay seconds
|
|
1815
1959
|
outBoundDelaySeconds: withdrawQuote.outbound_delay_seconds || 0,
|
|
1816
1960
|
// Set the slip basis points
|
|
1817
|
-
slipBasisPoints: withdrawQuote.slippage_bps,
|
|
1961
|
+
slipBasisPoints: withdrawQuote.fees.slippage_bps,
|
|
1818
1962
|
// Set the errors
|
|
1819
1963
|
errors,
|
|
1820
1964
|
};
|
|
@@ -1914,7 +2058,7 @@ class ThorchainQuery {
|
|
|
1914
2058
|
// Calculate inbound fee for the provided asset
|
|
1915
2059
|
const inboundFee = new CryptoAmount(baseAmount(inboundDetails[addAmount.asset.chain].gasRate), addAmount.asset);
|
|
1916
2060
|
// Convert inbound fee to the same asset as the addAmount to ensure consistency in calculations
|
|
1917
|
-
const inboundFeeInAddAmountAsset = yield this.convert(inboundFee, addAmount.asset);
|
|
2061
|
+
const inboundFeeInAddAmountAsset = (yield this.convert(inboundFee, addAmount.asset));
|
|
1918
2062
|
// Check if the addAmount covers the inbound fees
|
|
1919
2063
|
if (addAmount.lte(inboundFeeInAddAmountAsset))
|
|
1920
2064
|
errors.push(`Add amount does not cover fees`);
|
|
@@ -1977,7 +2121,7 @@ class ThorchainQuery {
|
|
|
1977
2121
|
outbound: loanOpenResp.fees.outbound,
|
|
1978
2122
|
total_bps: loanOpenResp.fees.total_bps,
|
|
1979
2123
|
},
|
|
1980
|
-
slippageBps: loanOpenResp.slippage_bps,
|
|
2124
|
+
slippageBps: loanOpenResp.fees.slippage_bps,
|
|
1981
2125
|
router: loanOpenResp.router,
|
|
1982
2126
|
expiry: loanOpenResp.expiry,
|
|
1983
2127
|
warning: loanOpenResp.warning,
|
|
@@ -2050,7 +2194,7 @@ class ThorchainQuery {
|
|
|
2050
2194
|
outbound: loanCloseResp.fees.outbound,
|
|
2051
2195
|
total_bps: loanCloseResp.fees.total_bps,
|
|
2052
2196
|
},
|
|
2053
|
-
slippageBps: loanCloseResp.slippage_bps,
|
|
2197
|
+
slippageBps: loanCloseResp.fees.slippage_bps,
|
|
2054
2198
|
router: loanCloseResp.router,
|
|
2055
2199
|
expiry: loanCloseResp.expiry,
|
|
2056
2200
|
warning: loanCloseResp.warning,
|
|
@@ -2244,6 +2388,159 @@ class ThorchainQuery {
|
|
|
2244
2388
|
};
|
|
2245
2389
|
});
|
|
2246
2390
|
}
|
|
2391
|
+
/*
|
|
2392
|
+
* Returns the total units and depth of a trade asset
|
|
2393
|
+
* @param {TradeAssetUnitsParams} params Get trade asset unit params
|
|
2394
|
+
* @returns {TradeAssetUnits} Returns the total units and depth of a trade asset
|
|
2395
|
+
*/
|
|
2396
|
+
getTradeAssetUnits({ asset, height }) {
|
|
2397
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2398
|
+
const { units, depth } = yield this.thorchainCache.thornode.getTradeAssetUnits(assetToString(asset), height);
|
|
2399
|
+
const decimals = yield this.thorchainCache.midgardQuery.getDecimalForAsset(asset);
|
|
2400
|
+
return {
|
|
2401
|
+
asset,
|
|
2402
|
+
units: new CryptoAmount(baseAmount(units, decimals), asset),
|
|
2403
|
+
depth: new CryptoAmount(baseAmount(depth, decimals), asset),
|
|
2404
|
+
};
|
|
2405
|
+
});
|
|
2406
|
+
}
|
|
2407
|
+
/*
|
|
2408
|
+
* Returns the total units and depth for each trade asset
|
|
2409
|
+
* @param {TradeAssetsUnitsParams} params Get trade asset unit params
|
|
2410
|
+
* @returns {TradeAssetUnits[]} Returns the total units and depth for each trade asset
|
|
2411
|
+
*/
|
|
2412
|
+
getTradeAssetsUnits(params) {
|
|
2413
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2414
|
+
const tradeAssetsUnits = yield this.thorchainCache.thornode.getTradeAssetsUnits(params === null || params === void 0 ? void 0 : params.height);
|
|
2415
|
+
const parseData = ({ asset, units, depth }) => __awaiter(this, void 0, void 0, function* () {
|
|
2416
|
+
const tradeAsset = assetFromStringEx(asset);
|
|
2417
|
+
const decimals = yield this.thorchainCache.midgardQuery.getDecimalForAsset(tradeAsset);
|
|
2418
|
+
return {
|
|
2419
|
+
asset: tradeAsset,
|
|
2420
|
+
units: new CryptoAmount(baseAmount(units, decimals), tradeAsset),
|
|
2421
|
+
depth: new CryptoAmount(baseAmount(depth, decimals), tradeAsset),
|
|
2422
|
+
};
|
|
2423
|
+
});
|
|
2424
|
+
return Promise.all(tradeAssetsUnits.map(parseData));
|
|
2425
|
+
});
|
|
2426
|
+
}
|
|
2427
|
+
/**
|
|
2428
|
+
* Returns the units and depth of a trade account address
|
|
2429
|
+
* @param {TradeAssetsUnitsParams} params Get trade asset unit params
|
|
2430
|
+
* @returns {TradeAssetUnits[]} Returns the total units and depth for each trade asset
|
|
2431
|
+
*/
|
|
2432
|
+
getAddressTradeAccounts({ address, height, }) {
|
|
2433
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2434
|
+
const account = yield this.thorchainCache.thornode.getTradeAssetAccount(address, height);
|
|
2435
|
+
const parseData = (tradeAssetInfo) => __awaiter(this, void 0, void 0, function* () {
|
|
2436
|
+
const asset = assetFromStringEx(tradeAssetInfo.asset);
|
|
2437
|
+
return {
|
|
2438
|
+
asset,
|
|
2439
|
+
address,
|
|
2440
|
+
balance: new CryptoAmount(baseAmount(tradeAssetInfo.units), asset),
|
|
2441
|
+
lastAddHeight: tradeAssetInfo.last_add_height ? +tradeAssetInfo.last_add_height : undefined,
|
|
2442
|
+
lastWithdrawHeight: tradeAssetInfo.last_withdraw_height ? +tradeAssetInfo.last_withdraw_height : undefined,
|
|
2443
|
+
};
|
|
2444
|
+
});
|
|
2445
|
+
return Promise.all(account.map(parseData));
|
|
2446
|
+
});
|
|
2447
|
+
}
|
|
2448
|
+
/**
|
|
2449
|
+
* Returns all trade accounts for a trade asset
|
|
2450
|
+
* @param {TradeAssetAccountsParams} params Get Trade asset accounts params
|
|
2451
|
+
* @param {number} height Optional - Block height
|
|
2452
|
+
* @returns Returns all trade accounts for an asset
|
|
2453
|
+
*/
|
|
2454
|
+
getTradeAssetAccounts({ asset, height }) {
|
|
2455
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2456
|
+
const accounts = yield this.thorchainCache.thornode.getTradeAssetAccounts(assetToString(asset), height);
|
|
2457
|
+
const decimals = yield this.thorchainCache.midgardQuery.getDecimalForAsset(asset);
|
|
2458
|
+
return accounts.map((account) => {
|
|
2459
|
+
return {
|
|
2460
|
+
address: account.owner,
|
|
2461
|
+
asset,
|
|
2462
|
+
balance: new CryptoAmount(baseAmount(account.units, decimals), asset),
|
|
2463
|
+
lastAddHeight: account.last_add_height ? +account.last_add_height : undefined,
|
|
2464
|
+
lastWithdrawHeight: account.last_withdraw_height ? +account.last_withdraw_height : undefined,
|
|
2465
|
+
};
|
|
2466
|
+
});
|
|
2467
|
+
});
|
|
2468
|
+
}
|
|
2469
|
+
/**
|
|
2470
|
+
* Get Rune pool
|
|
2471
|
+
* @param {GetRunePoolParmas} params Get Rune pool params
|
|
2472
|
+
* @returns {RunePool} Rune pool information
|
|
2473
|
+
*/
|
|
2474
|
+
getRunePool(params) {
|
|
2475
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2476
|
+
const pool = yield this.thorchainCache.thornode.getRunePool(params === null || params === void 0 ? void 0 : params.height);
|
|
2477
|
+
return {
|
|
2478
|
+
pol: {
|
|
2479
|
+
runeDeposited: new AssetCryptoAmount(baseAmount(pool.pol.rune_deposited, THORCHAIN_DECIMAL), AssetRuneNative),
|
|
2480
|
+
runeWithdrawn: new AssetCryptoAmount(baseAmount(pool.pol.rune_withdrawn, THORCHAIN_DECIMAL), AssetRuneNative),
|
|
2481
|
+
value: new AssetCryptoAmount(baseAmount(pool.pol.value, THORCHAIN_DECIMAL), AssetRuneNative),
|
|
2482
|
+
pnl: new AssetCryptoAmount(baseAmount(pool.pol.pnl, THORCHAIN_DECIMAL), AssetRuneNative),
|
|
2483
|
+
currentRuneDeposited: new AssetCryptoAmount(baseAmount(pool.pol.current_deposit, THORCHAIN_DECIMAL), AssetRuneNative),
|
|
2484
|
+
},
|
|
2485
|
+
providers: {
|
|
2486
|
+
units: pool.providers.units,
|
|
2487
|
+
pendingUnits: pool.providers.pending_units,
|
|
2488
|
+
pendingRune: new AssetCryptoAmount(baseAmount(pool.providers.pending_rune, THORCHAIN_DECIMAL), AssetRuneNative),
|
|
2489
|
+
value: new AssetCryptoAmount(baseAmount(pool.providers.value, THORCHAIN_DECIMAL), AssetRuneNative),
|
|
2490
|
+
pnl: new AssetCryptoAmount(baseAmount(pool.providers.pnl, THORCHAIN_DECIMAL), AssetRuneNative),
|
|
2491
|
+
currentRuneDeposited: new AssetCryptoAmount(baseAmount(pool.providers.current_deposit, THORCHAIN_DECIMAL), AssetRuneNative),
|
|
2492
|
+
},
|
|
2493
|
+
reserve: {
|
|
2494
|
+
units: pool.reserve.units,
|
|
2495
|
+
value: new AssetCryptoAmount(baseAmount(pool.reserve.value, THORCHAIN_DECIMAL), AssetRuneNative),
|
|
2496
|
+
pnl: new AssetCryptoAmount(baseAmount(pool.reserve.pnl, THORCHAIN_DECIMAL), AssetRuneNative),
|
|
2497
|
+
currentRuneDeposited: new AssetCryptoAmount(baseAmount(pool.reserve.current_deposit, THORCHAIN_DECIMAL), AssetRuneNative),
|
|
2498
|
+
},
|
|
2499
|
+
};
|
|
2500
|
+
});
|
|
2501
|
+
}
|
|
2502
|
+
/**
|
|
2503
|
+
* Get Rune pool provider position
|
|
2504
|
+
* @param {RunePoolProviderParams} params Get Rune pool provider position params
|
|
2505
|
+
* @returns {RunePoolProvider} Rune pool provider position
|
|
2506
|
+
*/
|
|
2507
|
+
getRunePoolProvider({ address, height }) {
|
|
2508
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2509
|
+
const position = yield this.thorchainCache.thornode.getRunePoolProvider(address, height);
|
|
2510
|
+
return {
|
|
2511
|
+
address: position.rune_address,
|
|
2512
|
+
units: position.units,
|
|
2513
|
+
value: new AssetCryptoAmount(baseAmount(position.value), AssetRuneNative),
|
|
2514
|
+
pnl: new AssetCryptoAmount(baseAmount(position.pnl), AssetRuneNative),
|
|
2515
|
+
depositAmount: new AssetCryptoAmount(baseAmount(position.deposit_amount), AssetRuneNative),
|
|
2516
|
+
withdrawAmount: new AssetCryptoAmount(baseAmount(position.withdraw_amount), AssetRuneNative),
|
|
2517
|
+
lastDepositHeight: position.last_deposit_height,
|
|
2518
|
+
lastWithdrawHeight: position.last_withdraw_height,
|
|
2519
|
+
};
|
|
2520
|
+
});
|
|
2521
|
+
}
|
|
2522
|
+
/**
|
|
2523
|
+
* Get all Rune pool providers position
|
|
2524
|
+
* @param {RunePoolProvidersParams} params Get Rune pool provider position params
|
|
2525
|
+
* @returns {RunePoolProvider[]} All Rune pool providers position
|
|
2526
|
+
*/
|
|
2527
|
+
getRunePoolProviders(params) {
|
|
2528
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2529
|
+
const positions = yield this.thorchainCache.thornode.getRunePoolProviders(params === null || params === void 0 ? void 0 : params.height);
|
|
2530
|
+
return positions.map((position) => {
|
|
2531
|
+
return {
|
|
2532
|
+
address: position.rune_address,
|
|
2533
|
+
units: position.units,
|
|
2534
|
+
value: new AssetCryptoAmount(baseAmount(position.value), AssetRuneNative),
|
|
2535
|
+
pnl: new AssetCryptoAmount(baseAmount(position.pnl), AssetRuneNative),
|
|
2536
|
+
depositAmount: new AssetCryptoAmount(baseAmount(position.deposit_amount), AssetRuneNative),
|
|
2537
|
+
withdrawAmount: new AssetCryptoAmount(baseAmount(position.withdraw_amount), AssetRuneNative),
|
|
2538
|
+
lastDepositHeight: position.last_deposit_height,
|
|
2539
|
+
lastWithdrawHeight: position.last_withdraw_height,
|
|
2540
|
+
};
|
|
2541
|
+
});
|
|
2542
|
+
});
|
|
2543
|
+
}
|
|
2247
2544
|
}
|
|
2248
2545
|
|
|
2249
2546
|
/**
|
|
@@ -2786,7 +3083,7 @@ class TransactionStage {
|
|
|
2786
3083
|
const lastBlockObj = yield this.thorchainCache.thornode.getLastBlock();
|
|
2787
3084
|
const currentHeight = lastBlockObj.find((obj) => obj.chain == asset.chain);
|
|
2788
3085
|
let blockHeight;
|
|
2789
|
-
if (asset.chain === THORChain || asset
|
|
3086
|
+
if (asset.chain === THORChain || isSynthAsset(asset)) {
|
|
2790
3087
|
const currentHeight = lastBlockObj.find((obj) => obj);
|
|
2791
3088
|
blockHeight = Number(`${currentHeight === null || currentHeight === void 0 ? void 0 : currentHeight.thorchain}`);
|
|
2792
3089
|
}
|