@xchainjs/xchain-thorchain-query 2.0.6 → 2.0.8
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 +97 -83
- package/lib/index.js +98 -82
- package/lib/utils/const.d.ts +2 -0
- package/package.json +5 -5
package/lib/index.esm.js
CHANGED
|
@@ -41,53 +41,57 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
41
41
|
// Default attributes for each chain
|
|
42
42
|
const DefaultChainAttributes = {
|
|
43
43
|
BCH: {
|
|
44
|
-
blockReward: 6.25,
|
|
44
|
+
blockReward: 6.25, // Block reward for Bitcoin Cash
|
|
45
45
|
avgBlockTimeInSecs: 600, // Average block time for Bitcoin Cash in seconds
|
|
46
46
|
},
|
|
47
47
|
BTC: {
|
|
48
|
-
blockReward: 6.25,
|
|
48
|
+
blockReward: 6.25, // Block reward for Bitcoin
|
|
49
49
|
avgBlockTimeInSecs: 600, // Average block time for Bitcoin in seconds
|
|
50
50
|
},
|
|
51
51
|
ETH: {
|
|
52
|
-
blockReward: 2,
|
|
52
|
+
blockReward: 2, // Block reward for Ethereum
|
|
53
53
|
avgBlockTimeInSecs: 13, // Average block time for Ethereum in seconds
|
|
54
54
|
},
|
|
55
55
|
AVAX: {
|
|
56
|
-
blockReward: 2,
|
|
56
|
+
blockReward: 2, // Block reward for Avalanche
|
|
57
57
|
avgBlockTimeInSecs: 3, // Average block time for Avalanche in seconds
|
|
58
58
|
},
|
|
59
59
|
LTC: {
|
|
60
|
-
blockReward: 12.5,
|
|
60
|
+
blockReward: 12.5, // Block reward for Litecoin
|
|
61
61
|
avgBlockTimeInSecs: 150, // Average block time for Litecoin in seconds
|
|
62
62
|
},
|
|
63
63
|
DOGE: {
|
|
64
|
-
blockReward: 10000,
|
|
64
|
+
blockReward: 10000, // Block reward for Dogecoin
|
|
65
65
|
avgBlockTimeInSecs: 60, // Average block time for Dogecoin in seconds
|
|
66
66
|
},
|
|
67
67
|
GAIA: {
|
|
68
|
-
blockReward: 0,
|
|
68
|
+
blockReward: 0, // No block reward for Gaia
|
|
69
69
|
avgBlockTimeInSecs: 6, // Average block time for Gaia in seconds
|
|
70
70
|
},
|
|
71
71
|
THOR: {
|
|
72
|
-
blockReward: 0,
|
|
72
|
+
blockReward: 0, // No block reward for THORChain
|
|
73
73
|
avgBlockTimeInSecs: 6, // Average block time for THORChain in seconds
|
|
74
74
|
},
|
|
75
75
|
BSC: {
|
|
76
|
-
blockReward: 0,
|
|
76
|
+
blockReward: 0, // No block reward for Binance Smart Chain
|
|
77
77
|
avgBlockTimeInSecs: 3, // Average block time for Binance Smart Chain in seconds
|
|
78
78
|
},
|
|
79
79
|
MAYA: {
|
|
80
|
-
blockReward: 0,
|
|
80
|
+
blockReward: 0, // No block reward for MAYAChain
|
|
81
81
|
avgBlockTimeInSecs: 6, // Average block time for MAYAChain in seconds
|
|
82
82
|
},
|
|
83
83
|
BASE: {
|
|
84
|
-
blockReward: 0,
|
|
84
|
+
blockReward: 0, // No block reward for base
|
|
85
85
|
avgBlockTimeInSecs: 2, // Average block time for Base in seconds
|
|
86
86
|
},
|
|
87
87
|
XRP: {
|
|
88
|
-
blockReward: 0,
|
|
88
|
+
blockReward: 0, // No block reward for xrp
|
|
89
89
|
avgBlockTimeInSecs: 4, // Average block time for xrp in seconds
|
|
90
90
|
},
|
|
91
|
+
SOL: {
|
|
92
|
+
blockReward: 0, // No block reward for sol
|
|
93
|
+
avgBlockTimeInSecs: 0.4, // Average block time for sol in seconds
|
|
94
|
+
},
|
|
91
95
|
};
|
|
92
96
|
|
|
93
97
|
/**
|
|
@@ -131,6 +135,7 @@ const assetUSDC = assetFromStringEx('ETH.USDC-0XA0B86991C6218B36C1D19D4A2E9EB0CE
|
|
|
131
135
|
const AssetBNB = assetFromStringEx('BSC.BNB');
|
|
132
136
|
const AssetBASE = assetFromStringEx('BASE.ETH');
|
|
133
137
|
const AssetXRP = assetFromStringEx('XRP.XRP');
|
|
138
|
+
const AssetSOL = assetFromStringEx('SOL.SOL');
|
|
134
139
|
const BNBChain = 'BNB';
|
|
135
140
|
const BTCChain = 'BTC';
|
|
136
141
|
const BCHChain = 'BCH';
|
|
@@ -144,6 +149,7 @@ const BSCChain = 'BSC';
|
|
|
144
149
|
const THORChain = 'THOR';
|
|
145
150
|
const BASEChain = 'BASE';
|
|
146
151
|
const XRPChain = 'XRP';
|
|
152
|
+
const SOLChain = 'SOL';
|
|
147
153
|
const THORCHAIN_DECIMAL = 8;
|
|
148
154
|
const isAssetRuneNative = (asset) => assetToString(asset) === assetToString(AssetRuneNative);
|
|
149
155
|
|
|
@@ -190,6 +196,8 @@ const getChainAsset = (chain) => {
|
|
|
190
196
|
return AssetBASE;
|
|
191
197
|
case XRPChain:
|
|
192
198
|
return AssetXRP;
|
|
199
|
+
case SOLChain:
|
|
200
|
+
return AssetSOL;
|
|
193
201
|
default:
|
|
194
202
|
throw Error('Unknown chain');
|
|
195
203
|
}
|
|
@@ -249,6 +257,8 @@ const calcNetworkFee = (asset, inbound) => {
|
|
|
249
257
|
return new AssetCryptoAmount(baseAmount(inbound.gasRate), AssetBASE);
|
|
250
258
|
case XRPChain:
|
|
251
259
|
return new AssetCryptoAmount(baseAmount(inbound.gasRate), AssetXRP);
|
|
260
|
+
case SOLChain:
|
|
261
|
+
return new AssetCryptoAmount(baseAmount(inbound.gasRate), AssetSOL);
|
|
252
262
|
}
|
|
253
263
|
throw new Error(`could not calculate inbound fee for ${asset.chain}`);
|
|
254
264
|
};
|
|
@@ -287,7 +297,11 @@ const calcOutboundFee = (asset, inbound) => {
|
|
|
287
297
|
case MAYAChain:
|
|
288
298
|
return new AssetCryptoAmount(baseAmount(2000000), AssetMAYA);
|
|
289
299
|
case BASEChain:
|
|
290
|
-
return new AssetCryptoAmount(baseAmount(
|
|
300
|
+
return new AssetCryptoAmount(baseAmount(inbound.outboundFee), AssetBASE);
|
|
301
|
+
case XRPChain:
|
|
302
|
+
return new AssetCryptoAmount(baseAmount(inbound.outboundFee), AssetXRP);
|
|
303
|
+
case SOLChain:
|
|
304
|
+
return new AssetCryptoAmount(baseAmount(inbound.outboundFee), AssetSOL);
|
|
291
305
|
}
|
|
292
306
|
throw new Error(`could not calculate outbound fee for ${asset.chain}`);
|
|
293
307
|
};
|
|
@@ -1242,8 +1256,8 @@ class ThorchainQuery {
|
|
|
1242
1256
|
* @param quoteSwapParams - Input parameters for the swap quote.
|
|
1243
1257
|
* @returns Transaction details including memo, address, fees, etc.
|
|
1244
1258
|
*/
|
|
1245
|
-
quoteSwap(
|
|
1246
|
-
return __awaiter(this,
|
|
1259
|
+
quoteSwap(_a) {
|
|
1260
|
+
return __awaiter(this, arguments, void 0, function* ({ fromAsset, destinationAsset, amount, destinationAddress, streamingInterval, streamingQuantity, liquidityToleranceBps, toleranceBps, affiliateBps, affiliateAddress, height, }) {
|
|
1247
1261
|
// Validates swap and pushes error if there is one
|
|
1248
1262
|
const errors = [];
|
|
1249
1263
|
const error = yield this.validateAmount(amount);
|
|
@@ -1409,7 +1423,7 @@ class ThorchainQuery {
|
|
|
1409
1423
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1410
1424
|
// Return the fees converted to the specified asset
|
|
1411
1425
|
return {
|
|
1412
|
-
asset: fees.asset,
|
|
1426
|
+
asset: fees.asset, // Shouldn't be asset?
|
|
1413
1427
|
// swapFee: await this.convert(fees.swapFee, asset),
|
|
1414
1428
|
outboundFee: yield this.convert(fees.outboundFee, asset),
|
|
1415
1429
|
affiliateFee: yield this.convert(fees.affiliateFee, asset),
|
|
@@ -1658,34 +1672,34 @@ class ThorchainQuery {
|
|
|
1658
1672
|
const assetOutbound = calcOutboundFee(params.asset, inboundDetails);
|
|
1659
1673
|
// Create an EstimateWithdrawLP object
|
|
1660
1674
|
const estimateLP = {
|
|
1661
|
-
assetAddress: memberDetail.position.asset_address,
|
|
1662
|
-
runeAddress: memberDetail.position.rune_address,
|
|
1663
|
-
slipPercent: slip.times(100),
|
|
1675
|
+
assetAddress: memberDetail.position.asset_address, // Address for the asset
|
|
1676
|
+
runeAddress: memberDetail.position.rune_address, // Address for the rune
|
|
1677
|
+
slipPercent: slip.times(100), // Slip percentage
|
|
1664
1678
|
inbound: {
|
|
1665
1679
|
minToSend: {
|
|
1666
1680
|
// Minimum amount to send
|
|
1667
|
-
rune: dustValues.rune,
|
|
1668
|
-
asset: dustValues.asset,
|
|
1681
|
+
rune: dustValues.rune, // Rune amount
|
|
1682
|
+
asset: dustValues.asset, // Asset amount
|
|
1669
1683
|
total: (yield this.convert(dustValues.asset, AssetRuneNative)).plus(dustValues.rune), // Total amount
|
|
1670
1684
|
},
|
|
1671
1685
|
fees: {
|
|
1672
1686
|
// Inbound fees
|
|
1673
|
-
rune: runeInbound,
|
|
1674
|
-
asset: assetInbound,
|
|
1687
|
+
rune: runeInbound, // Rune fees
|
|
1688
|
+
asset: assetInbound, // Asset fees
|
|
1675
1689
|
total: (yield this.convert(assetInbound, AssetRuneNative)).plus(runeInbound), // Total fees
|
|
1676
1690
|
},
|
|
1677
1691
|
},
|
|
1678
1692
|
outboundFee: {
|
|
1679
1693
|
// Outbound fees
|
|
1680
|
-
asset: assetOutbound,
|
|
1681
|
-
rune: runeOutbound,
|
|
1694
|
+
asset: assetOutbound, // Asset fees
|
|
1695
|
+
rune: runeOutbound, // Rune fees
|
|
1682
1696
|
total: (yield this.convert(assetOutbound, AssetRuneNative)).plus(runeOutbound), // Total fees
|
|
1683
1697
|
},
|
|
1684
|
-
assetAmount: poolShare.assetShare,
|
|
1685
|
-
runeAmount: poolShare.runeShare,
|
|
1686
|
-
lpGrowth: memberDetail.lpGrowth,
|
|
1687
|
-
estimatedWaitSeconds: waitTimeSeconds,
|
|
1688
|
-
impermanentLossProtection: memberDetail.impermanentLossProtection,
|
|
1698
|
+
assetAmount: poolShare.assetShare, // Asset amount
|
|
1699
|
+
runeAmount: poolShare.runeShare, // Rune amount
|
|
1700
|
+
lpGrowth: memberDetail.lpGrowth, // LP growth
|
|
1701
|
+
estimatedWaitSeconds: waitTimeSeconds, // Estimated wait time in seconds
|
|
1702
|
+
impermanentLossProtection: memberDetail.impermanentLossProtection, // Impermanent loss protection
|
|
1689
1703
|
assetPool: assetPool.thornodeDetails.asset, // Asset pool
|
|
1690
1704
|
};
|
|
1691
1705
|
return estimateLP; // Return the EstimateWithdrawLP object
|
|
@@ -1822,7 +1836,7 @@ class ThorchainQuery {
|
|
|
1822
1836
|
// Affiliate fee
|
|
1823
1837
|
new CryptoAmount(baseAmount(depositQuote.fees.affiliate), addAmount.asset), // Convert to base amount
|
|
1824
1838
|
assetDecimals),
|
|
1825
|
-
asset: feeAsset,
|
|
1839
|
+
asset: feeAsset, // Asset fee
|
|
1826
1840
|
outbound: getCryptoAmountWithNotation(
|
|
1827
1841
|
// Outbound fee
|
|
1828
1842
|
new CryptoAmount(baseAmount(depositQuote.fees.outbound), feeAsset), // Convert to base amount
|
|
@@ -1845,15 +1859,15 @@ class ThorchainQuery {
|
|
|
1845
1859
|
// Estimated deposit value
|
|
1846
1860
|
new CryptoAmount(baseAmount(depositQuote.expected_amount_deposit), addAmount.asset), // Convert to base amount
|
|
1847
1861
|
assetDecimals),
|
|
1848
|
-
fee: saverFees,
|
|
1849
|
-
expiry: new Date(depositQuote.expiry),
|
|
1850
|
-
toAddress: depositQuote.inbound_address,
|
|
1851
|
-
memo: depositQuote.memo,
|
|
1852
|
-
estimatedWaitTime: depositQuote.inbound_confirmation_seconds || 0,
|
|
1853
|
-
canAddSaver: errors.length === 0,
|
|
1854
|
-
slipBasisPoints: depositQuote.fees.slippage_bps,
|
|
1855
|
-
saverCapFilledPercent,
|
|
1856
|
-
recommendedMinAmountIn: depositQuote.recommended_min_amount_in,
|
|
1862
|
+
fee: saverFees, // Fees
|
|
1863
|
+
expiry: new Date(depositQuote.expiry), // Expiry date
|
|
1864
|
+
toAddress: depositQuote.inbound_address, // Recipient address
|
|
1865
|
+
memo: depositQuote.memo, // Memo
|
|
1866
|
+
estimatedWaitTime: depositQuote.inbound_confirmation_seconds || 0, // Estimated wait time
|
|
1867
|
+
canAddSaver: errors.length === 0, // Can add saver flag
|
|
1868
|
+
slipBasisPoints: depositQuote.fees.slippage_bps, // Slip basis points
|
|
1869
|
+
saverCapFilledPercent, // Saver filled capacity
|
|
1870
|
+
recommendedMinAmountIn: depositQuote.recommended_min_amount_in, // Recommended minimum amount in
|
|
1857
1871
|
errors, // Errors
|
|
1858
1872
|
};
|
|
1859
1873
|
return estimateAddSaver; // Return the EstimateAddSaver object
|
|
@@ -1880,27 +1894,27 @@ class ThorchainQuery {
|
|
|
1880
1894
|
errors.push(checkPositon.errors[i]);
|
|
1881
1895
|
}
|
|
1882
1896
|
return {
|
|
1883
|
-
dustAmount: new AssetCryptoAmount(baseAmount(0), getChainAsset(withdrawParams.asset.chain)),
|
|
1884
|
-
dustThreshold: new AssetCryptoAmount(baseAmount(0), getChainAsset(withdrawParams.asset.chain)),
|
|
1897
|
+
dustAmount: new AssetCryptoAmount(baseAmount(0), getChainAsset(withdrawParams.asset.chain)), // Dust amount
|
|
1898
|
+
dustThreshold: new AssetCryptoAmount(baseAmount(0), getChainAsset(withdrawParams.asset.chain)), // Dust threshold
|
|
1885
1899
|
expectedAssetAmount: new CryptoAmount(// Expected asset amount
|
|
1886
1900
|
assetToBase(assetAmount(checkPositon.redeemableValue.assetAmount.amount())), // Convert to base amount
|
|
1887
1901
|
withdrawParams.asset),
|
|
1888
1902
|
fee: {
|
|
1889
|
-
affiliate: new CryptoAmount(assetToBase(assetAmount(0)), withdrawParams.asset),
|
|
1890
|
-
asset: withdrawParams.asset,
|
|
1891
|
-
liquidity: new CryptoAmount(baseAmount(0), withdrawParams.asset),
|
|
1903
|
+
affiliate: new CryptoAmount(assetToBase(assetAmount(0)), withdrawParams.asset), // Affiliate fee
|
|
1904
|
+
asset: withdrawParams.asset, // Asset
|
|
1905
|
+
liquidity: new CryptoAmount(baseAmount(0), withdrawParams.asset), // Liquidity fee
|
|
1892
1906
|
outbound: new CryptoAmount(// Outbound fee
|
|
1893
1907
|
assetToBase(assetAmount(calcOutboundFee(withdrawParams.asset, inboundDetails[withdrawParams.asset.chain]).assetAmount.amount())), withdrawParams.asset),
|
|
1894
1908
|
totalBps: 0, // Total basis points
|
|
1895
1909
|
},
|
|
1896
|
-
expiry: new Date(0),
|
|
1897
|
-
toAddress: '',
|
|
1898
|
-
memo: '',
|
|
1899
|
-
inboundDelayBlocks: 0,
|
|
1900
|
-
inboundDelaySeconds: 0,
|
|
1901
|
-
outBoundDelayBlocks: 0,
|
|
1902
|
-
outBoundDelaySeconds: 0,
|
|
1903
|
-
slipBasisPoints: -1,
|
|
1910
|
+
expiry: new Date(0), // Expiry date
|
|
1911
|
+
toAddress: '', // Recipient address
|
|
1912
|
+
memo: '', // Memo
|
|
1913
|
+
inboundDelayBlocks: 0, // Number of blocks for inbound delay
|
|
1914
|
+
inboundDelaySeconds: 0, // Number of seconds for inbound delay
|
|
1915
|
+
outBoundDelayBlocks: 0, // Number of blocks for outbound delay
|
|
1916
|
+
outBoundDelaySeconds: 0, // Number of seconds for outbound delay
|
|
1917
|
+
slipBasisPoints: -1, // Slip basis points (negative value indicates no slip)
|
|
1904
1918
|
errors, // Errors array
|
|
1905
1919
|
};
|
|
1906
1920
|
}
|
|
@@ -2028,13 +2042,13 @@ class ThorchainQuery {
|
|
|
2028
2042
|
const saverGrowth = redeemableAssetAmount.minus(depositAmount).div(depositAmount).times(100);
|
|
2029
2043
|
// Create and populate a SaversPosition object with the calculated values
|
|
2030
2044
|
const saversPos = {
|
|
2031
|
-
depositValue: depositAmount,
|
|
2032
|
-
redeemableValue: redeemableAssetAmount,
|
|
2033
|
-
lastAddHeight: Number(savers === null || savers === void 0 ? void 0 : savers.last_add_height),
|
|
2034
|
-
percentageGrowth: saverGrowth.assetAmount.amount().toNumber(),
|
|
2035
|
-
ageInYears: saversAge,
|
|
2036
|
-
ageInDays: saversAge * 365,
|
|
2037
|
-
asset: params.asset,
|
|
2045
|
+
depositValue: depositAmount, // Current deposit value of the saver
|
|
2046
|
+
redeemableValue: redeemableAssetAmount, // Redeemable value of the saver's position
|
|
2047
|
+
lastAddHeight: Number(savers === null || savers === void 0 ? void 0 : savers.last_add_height), // Height at which the last addition was made to the pool
|
|
2048
|
+
percentageGrowth: saverGrowth.assetAmount.amount().toNumber(), // Percentage growth of the saver's position
|
|
2049
|
+
ageInYears: saversAge, // Age of the saver's position in years
|
|
2050
|
+
ageInDays: saversAge * 365, // Age of the saver's position in days
|
|
2051
|
+
asset: params.asset, // Asset of the saver's position
|
|
2038
2052
|
errors, // Array of any errors encountered during the calculation
|
|
2039
2053
|
};
|
|
2040
2054
|
// Return the SaversPosition object representing the saver's position
|
|
@@ -2084,8 +2098,8 @@ class ThorchainQuery {
|
|
|
2084
2098
|
* @param loanOpenParams - params needed for the end Point
|
|
2085
2099
|
* @returns
|
|
2086
2100
|
*/
|
|
2087
|
-
getLoanQuoteOpen(
|
|
2088
|
-
return __awaiter(this,
|
|
2101
|
+
getLoanQuoteOpen(_a) {
|
|
2102
|
+
return __awaiter(this, arguments, void 0, function* ({ asset, amount, targetAsset, destination, minOut, affiliateBps, affiliate, height, }) {
|
|
2089
2103
|
const errors = [];
|
|
2090
2104
|
const loanOpenResp = yield this.thorchainCache.thornode.getLoanQuoteOpen(`${asset.chain}.${asset.symbol}`, amount.baseAmount.amount().toNumber(), `${targetAsset.chain}.${targetAsset.symbol}`, destination, minOut, affiliateBps, affiliate, height);
|
|
2091
2105
|
const response = JSON.parse(JSON.stringify(loanOpenResp));
|
|
@@ -2156,8 +2170,8 @@ class ThorchainQuery {
|
|
|
2156
2170
|
* @param loanOpenParams - Parameters needed for the endpoint.
|
|
2157
2171
|
* @returns A Promise resolving to a LoanOpenQuote.
|
|
2158
2172
|
*/
|
|
2159
|
-
getLoanQuoteClose(
|
|
2160
|
-
return __awaiter(this,
|
|
2173
|
+
getLoanQuoteClose(_a) {
|
|
2174
|
+
return __awaiter(this, arguments, void 0, function* ({ asset, amount, loanAsset, loanOwner, minOut, height, }) {
|
|
2161
2175
|
const errors = [];
|
|
2162
2176
|
// Retrieve loan open response from ThorNode API
|
|
2163
2177
|
const loanCloseResp = yield this.thorchainCache.thornode.getLoanQuoteClose(`${asset.chain}.${asset.symbol}`, amount.baseAmount.amount().toNumber(), `${loanAsset.chain}.${loanAsset.symbol}`, loanOwner, minOut, height);
|
|
@@ -2360,8 +2374,8 @@ class ThorchainQuery {
|
|
|
2360
2374
|
* @param {Address[]} params.addresses - List of addresses
|
|
2361
2375
|
* @returns {SwapsHistory} Swap history
|
|
2362
2376
|
*/
|
|
2363
|
-
getSwapHistory(
|
|
2364
|
-
return __awaiter(this,
|
|
2377
|
+
getSwapHistory(_a) {
|
|
2378
|
+
return __awaiter(this, arguments, void 0, function* ({ addresses }) {
|
|
2365
2379
|
const actionsResume = yield this.thorchainCache.midgardQuery.midgardCache.midgard.getActions({
|
|
2366
2380
|
address: addresses.join(','),
|
|
2367
2381
|
type: 'swap',
|
|
@@ -2416,8 +2430,8 @@ class ThorchainQuery {
|
|
|
2416
2430
|
* @param {TradeAssetUnitsParams} params Get trade asset unit params
|
|
2417
2431
|
* @returns {TradeAssetUnits} Returns the total units and depth of a trade asset
|
|
2418
2432
|
*/
|
|
2419
|
-
getTradeAssetUnits(
|
|
2420
|
-
return __awaiter(this,
|
|
2433
|
+
getTradeAssetUnits(_a) {
|
|
2434
|
+
return __awaiter(this, arguments, void 0, function* ({ asset, height }) {
|
|
2421
2435
|
const { units, depth } = yield this.thorchainCache.thornode.getTradeAssetUnits(assetToString(asset), height);
|
|
2422
2436
|
const decimals = yield this.thorchainCache.midgardQuery.getDecimalForAsset(asset);
|
|
2423
2437
|
return {
|
|
@@ -2435,7 +2449,7 @@ class ThorchainQuery {
|
|
|
2435
2449
|
getTradeAssetsUnits(params) {
|
|
2436
2450
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2437
2451
|
const tradeAssetsUnits = yield this.thorchainCache.thornode.getTradeAssetsUnits(params === null || params === void 0 ? void 0 : params.height);
|
|
2438
|
-
const parseData = (
|
|
2452
|
+
const parseData = (_a) => __awaiter(this, [_a], void 0, function* ({ asset, units, depth }) {
|
|
2439
2453
|
const tradeAsset = assetFromStringEx(asset);
|
|
2440
2454
|
const decimals = yield this.thorchainCache.midgardQuery.getDecimalForAsset(tradeAsset);
|
|
2441
2455
|
return {
|
|
@@ -2452,8 +2466,8 @@ class ThorchainQuery {
|
|
|
2452
2466
|
* @param {TradeAssetsUnitsParams} params Get trade asset unit params
|
|
2453
2467
|
* @returns {TradeAssetUnits[]} Returns the total units and depth for each trade asset
|
|
2454
2468
|
*/
|
|
2455
|
-
getAddressTradeAccounts(
|
|
2456
|
-
return __awaiter(this,
|
|
2469
|
+
getAddressTradeAccounts(_a) {
|
|
2470
|
+
return __awaiter(this, arguments, void 0, function* ({ address, height, }) {
|
|
2457
2471
|
const account = yield this.thorchainCache.thornode.getTradeAssetAccount(address, height);
|
|
2458
2472
|
const parseData = (tradeAssetInfo) => __awaiter(this, void 0, void 0, function* () {
|
|
2459
2473
|
const asset = assetFromStringEx(tradeAssetInfo.asset);
|
|
@@ -2474,8 +2488,8 @@ class ThorchainQuery {
|
|
|
2474
2488
|
* @param {number} height Optional - Block height
|
|
2475
2489
|
* @returns Returns all trade accounts for an asset
|
|
2476
2490
|
*/
|
|
2477
|
-
getTradeAssetAccounts(
|
|
2478
|
-
return __awaiter(this,
|
|
2491
|
+
getTradeAssetAccounts(_a) {
|
|
2492
|
+
return __awaiter(this, arguments, void 0, function* ({ asset, height }) {
|
|
2479
2493
|
const accounts = yield this.thorchainCache.thornode.getTradeAssetAccounts(assetToString(asset), height);
|
|
2480
2494
|
const decimals = yield this.thorchainCache.midgardQuery.getDecimalForAsset(asset);
|
|
2481
2495
|
return accounts.map((account) => {
|
|
@@ -2527,8 +2541,8 @@ class ThorchainQuery {
|
|
|
2527
2541
|
* @param {RunePoolProviderParams} params Get Rune pool provider position params
|
|
2528
2542
|
* @returns {RunePoolProvider} Rune pool provider position
|
|
2529
2543
|
*/
|
|
2530
|
-
getRunePoolProvider(
|
|
2531
|
-
return __awaiter(this,
|
|
2544
|
+
getRunePoolProvider(_a) {
|
|
2545
|
+
return __awaiter(this, arguments, void 0, function* ({ address, height }) {
|
|
2532
2546
|
const position = yield this.thorchainCache.thornode.getRunePoolProvider(address, height);
|
|
2533
2547
|
return {
|
|
2534
2548
|
address: position.rune_address,
|
|
@@ -2749,8 +2763,8 @@ class TransactionStage {
|
|
|
2749
2763
|
* @param progress - Transaction progress object.
|
|
2750
2764
|
*/
|
|
2751
2765
|
checkSwapProgress(txData, progress) {
|
|
2752
|
-
var _a, _b, _c, _d;
|
|
2753
2766
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2767
|
+
var _a, _b, _c, _d;
|
|
2754
2768
|
if (progress.inboundObserved) {
|
|
2755
2769
|
// Extract memo fields
|
|
2756
2770
|
const memo = (_a = txData.tx.tx.memo) !== null && _a !== void 0 ? _a : '';
|
|
@@ -2778,7 +2792,7 @@ class TransactionStage {
|
|
|
2778
2792
|
status: swapStatus,
|
|
2779
2793
|
expectedOutBlock,
|
|
2780
2794
|
expectedOutDate,
|
|
2781
|
-
expectedAmountOut: minimumAmountOut,
|
|
2795
|
+
expectedAmountOut: minimumAmountOut, // TODO call estimateSwap()
|
|
2782
2796
|
confirmations,
|
|
2783
2797
|
minimumAmountOut,
|
|
2784
2798
|
affliateFee,
|
|
@@ -2823,8 +2837,8 @@ class TransactionStage {
|
|
|
2823
2837
|
* @returns Promise<TXProgress> - Transaction progress object.
|
|
2824
2838
|
*/
|
|
2825
2839
|
determineObserved(txData) {
|
|
2826
|
-
var _a, _b, _c, _d;
|
|
2827
2840
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2841
|
+
var _a, _b, _c, _d;
|
|
2828
2842
|
const progress = {
|
|
2829
2843
|
txType: TxType.Unknown,
|
|
2830
2844
|
};
|
|
@@ -2860,7 +2874,7 @@ class TransactionStage {
|
|
|
2860
2874
|
: yield this.blockToDate(assetIn.chain, txData);
|
|
2861
2875
|
progress.inboundObserved = {
|
|
2862
2876
|
status,
|
|
2863
|
-
date: dateObserved,
|
|
2877
|
+
date: dateObserved, // date observed?
|
|
2864
2878
|
block,
|
|
2865
2879
|
expectedConfirmationBlock: finalizeBlock,
|
|
2866
2880
|
expectedConfirmationDate,
|
|
@@ -2878,8 +2892,8 @@ class TransactionStage {
|
|
|
2878
2892
|
* @param progress - Transaction progress object.
|
|
2879
2893
|
*/
|
|
2880
2894
|
checkAddLpProgress(txData, progress) {
|
|
2881
|
-
var _a;
|
|
2882
2895
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2896
|
+
var _a;
|
|
2883
2897
|
if (progress.inboundObserved) {
|
|
2884
2898
|
// Extract memo fields
|
|
2885
2899
|
const memo = (_a = txData.tx.tx.memo) !== null && _a !== void 0 ? _a : '';
|
|
@@ -2910,8 +2924,8 @@ class TransactionStage {
|
|
|
2910
2924
|
* @param progress - Transaction progress object.
|
|
2911
2925
|
*/
|
|
2912
2926
|
checkWithdrawLpProgress(txData, progress) {
|
|
2913
|
-
var _a, _b;
|
|
2914
2927
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2928
|
+
var _a, _b;
|
|
2915
2929
|
if (progress.inboundObserved) {
|
|
2916
2930
|
// Extract memo fields
|
|
2917
2931
|
const memo = (_a = txData.tx.tx.memo) !== null && _a !== void 0 ? _a : '';
|
|
@@ -2980,8 +2994,8 @@ class TransactionStage {
|
|
|
2980
2994
|
* @param progress - Transaction progress object.
|
|
2981
2995
|
*/
|
|
2982
2996
|
checkWithdrawSaverProgress(txData, progress) {
|
|
2983
|
-
var _a;
|
|
2984
2997
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2998
|
+
var _a;
|
|
2985
2999
|
if (progress.inboundObserved) {
|
|
2986
3000
|
// Extract memo fields
|
|
2987
3001
|
const memo = (_a = txData.tx.tx.memo) !== null && _a !== void 0 ? _a : '';
|
|
@@ -3165,4 +3179,4 @@ class TransactionStage {
|
|
|
3165
3179
|
}
|
|
3166
3180
|
}
|
|
3167
3181
|
|
|
3168
|
-
export { AVAXChain, AddLpStatus, AddSaverStatus, AssetATOM, AssetAVAX, AssetBASE, AssetBCH, AssetBNB, AssetBSC, AssetBTC, AssetDOGE, AssetETH, AssetLTC, AssetMAYA, AssetRuneNative, AssetXRP, BASEChain, BCHChain, BNBChain, BSCChain, BTCChain, DOGEChain, DefaultChainAttributes, ETHChain, GAIAChain, InboundStatus, LTCChain, LiquidityPool, MAYAChain, RefundStatus, SwapStatus, THORCHAIN_DECIMAL, THORChain, ThorchainCache, ThorchainQuery, Thornode, TransactionStage, TxType, WithdrawStatus, XRPChain, assetUSDC, calcNetworkFee, getCryptoAmountWithNotation, getLiquidityProtectionData, getLiquidityUnits, getPoolShare, getSlipOnLiquidity, isAssetRuneNative };
|
|
3182
|
+
export { AVAXChain, AddLpStatus, AddSaverStatus, AssetATOM, AssetAVAX, AssetBASE, AssetBCH, AssetBNB, AssetBSC, AssetBTC, AssetDOGE, AssetETH, AssetLTC, AssetMAYA, AssetRuneNative, AssetSOL, AssetXRP, BASEChain, BCHChain, BNBChain, BSCChain, BTCChain, DOGEChain, DefaultChainAttributes, ETHChain, GAIAChain, InboundStatus, LTCChain, LiquidityPool, MAYAChain, RefundStatus, SOLChain, SwapStatus, THORCHAIN_DECIMAL, THORChain, ThorchainCache, ThorchainQuery, Thornode, TransactionStage, TxType, WithdrawStatus, XRPChain, assetUSDC, calcNetworkFee, getCryptoAmountWithNotation, getLiquidityProtectionData, getLiquidityUnits, getPoolShare, getSlipOnLiquidity, isAssetRuneNative };
|
package/lib/index.js
CHANGED
|
@@ -49,53 +49,57 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
49
49
|
// Default attributes for each chain
|
|
50
50
|
const DefaultChainAttributes = {
|
|
51
51
|
BCH: {
|
|
52
|
-
blockReward: 6.25,
|
|
52
|
+
blockReward: 6.25, // Block reward for Bitcoin Cash
|
|
53
53
|
avgBlockTimeInSecs: 600, // Average block time for Bitcoin Cash in seconds
|
|
54
54
|
},
|
|
55
55
|
BTC: {
|
|
56
|
-
blockReward: 6.25,
|
|
56
|
+
blockReward: 6.25, // Block reward for Bitcoin
|
|
57
57
|
avgBlockTimeInSecs: 600, // Average block time for Bitcoin in seconds
|
|
58
58
|
},
|
|
59
59
|
ETH: {
|
|
60
|
-
blockReward: 2,
|
|
60
|
+
blockReward: 2, // Block reward for Ethereum
|
|
61
61
|
avgBlockTimeInSecs: 13, // Average block time for Ethereum in seconds
|
|
62
62
|
},
|
|
63
63
|
AVAX: {
|
|
64
|
-
blockReward: 2,
|
|
64
|
+
blockReward: 2, // Block reward for Avalanche
|
|
65
65
|
avgBlockTimeInSecs: 3, // Average block time for Avalanche in seconds
|
|
66
66
|
},
|
|
67
67
|
LTC: {
|
|
68
|
-
blockReward: 12.5,
|
|
68
|
+
blockReward: 12.5, // Block reward for Litecoin
|
|
69
69
|
avgBlockTimeInSecs: 150, // Average block time for Litecoin in seconds
|
|
70
70
|
},
|
|
71
71
|
DOGE: {
|
|
72
|
-
blockReward: 10000,
|
|
72
|
+
blockReward: 10000, // Block reward for Dogecoin
|
|
73
73
|
avgBlockTimeInSecs: 60, // Average block time for Dogecoin in seconds
|
|
74
74
|
},
|
|
75
75
|
GAIA: {
|
|
76
|
-
blockReward: 0,
|
|
76
|
+
blockReward: 0, // No block reward for Gaia
|
|
77
77
|
avgBlockTimeInSecs: 6, // Average block time for Gaia in seconds
|
|
78
78
|
},
|
|
79
79
|
THOR: {
|
|
80
|
-
blockReward: 0,
|
|
80
|
+
blockReward: 0, // No block reward for THORChain
|
|
81
81
|
avgBlockTimeInSecs: 6, // Average block time for THORChain in seconds
|
|
82
82
|
},
|
|
83
83
|
BSC: {
|
|
84
|
-
blockReward: 0,
|
|
84
|
+
blockReward: 0, // No block reward for Binance Smart Chain
|
|
85
85
|
avgBlockTimeInSecs: 3, // Average block time for Binance Smart Chain in seconds
|
|
86
86
|
},
|
|
87
87
|
MAYA: {
|
|
88
|
-
blockReward: 0,
|
|
88
|
+
blockReward: 0, // No block reward for MAYAChain
|
|
89
89
|
avgBlockTimeInSecs: 6, // Average block time for MAYAChain in seconds
|
|
90
90
|
},
|
|
91
91
|
BASE: {
|
|
92
|
-
blockReward: 0,
|
|
92
|
+
blockReward: 0, // No block reward for base
|
|
93
93
|
avgBlockTimeInSecs: 2, // Average block time for Base in seconds
|
|
94
94
|
},
|
|
95
95
|
XRP: {
|
|
96
|
-
blockReward: 0,
|
|
96
|
+
blockReward: 0, // No block reward for xrp
|
|
97
97
|
avgBlockTimeInSecs: 4, // Average block time for xrp in seconds
|
|
98
98
|
},
|
|
99
|
+
SOL: {
|
|
100
|
+
blockReward: 0, // No block reward for sol
|
|
101
|
+
avgBlockTimeInSecs: 0.4, // Average block time for sol in seconds
|
|
102
|
+
},
|
|
99
103
|
};
|
|
100
104
|
|
|
101
105
|
/**
|
|
@@ -139,6 +143,7 @@ const assetUSDC = xchainUtil.assetFromStringEx('ETH.USDC-0XA0B86991C6218B36C1D19
|
|
|
139
143
|
const AssetBNB = xchainUtil.assetFromStringEx('BSC.BNB');
|
|
140
144
|
const AssetBASE = xchainUtil.assetFromStringEx('BASE.ETH');
|
|
141
145
|
const AssetXRP = xchainUtil.assetFromStringEx('XRP.XRP');
|
|
146
|
+
const AssetSOL = xchainUtil.assetFromStringEx('SOL.SOL');
|
|
142
147
|
const BNBChain = 'BNB';
|
|
143
148
|
const BTCChain = 'BTC';
|
|
144
149
|
const BCHChain = 'BCH';
|
|
@@ -152,6 +157,7 @@ const BSCChain = 'BSC';
|
|
|
152
157
|
const THORChain = 'THOR';
|
|
153
158
|
const BASEChain = 'BASE';
|
|
154
159
|
const XRPChain = 'XRP';
|
|
160
|
+
const SOLChain = 'SOL';
|
|
155
161
|
const THORCHAIN_DECIMAL = 8;
|
|
156
162
|
const isAssetRuneNative = (asset) => xchainUtil.assetToString(asset) === xchainUtil.assetToString(AssetRuneNative);
|
|
157
163
|
|
|
@@ -198,6 +204,8 @@ const getChainAsset = (chain) => {
|
|
|
198
204
|
return AssetBASE;
|
|
199
205
|
case XRPChain:
|
|
200
206
|
return AssetXRP;
|
|
207
|
+
case SOLChain:
|
|
208
|
+
return AssetSOL;
|
|
201
209
|
default:
|
|
202
210
|
throw Error('Unknown chain');
|
|
203
211
|
}
|
|
@@ -257,6 +265,8 @@ const calcNetworkFee = (asset, inbound) => {
|
|
|
257
265
|
return new xchainUtil.AssetCryptoAmount(xchainUtil.baseAmount(inbound.gasRate), AssetBASE);
|
|
258
266
|
case XRPChain:
|
|
259
267
|
return new xchainUtil.AssetCryptoAmount(xchainUtil.baseAmount(inbound.gasRate), AssetXRP);
|
|
268
|
+
case SOLChain:
|
|
269
|
+
return new xchainUtil.AssetCryptoAmount(xchainUtil.baseAmount(inbound.gasRate), AssetSOL);
|
|
260
270
|
}
|
|
261
271
|
throw new Error(`could not calculate inbound fee for ${asset.chain}`);
|
|
262
272
|
};
|
|
@@ -295,7 +305,11 @@ const calcOutboundFee = (asset, inbound) => {
|
|
|
295
305
|
case MAYAChain:
|
|
296
306
|
return new xchainUtil.AssetCryptoAmount(xchainUtil.baseAmount(2000000), AssetMAYA);
|
|
297
307
|
case BASEChain:
|
|
298
|
-
return new xchainUtil.AssetCryptoAmount(xchainUtil.baseAmount(
|
|
308
|
+
return new xchainUtil.AssetCryptoAmount(xchainUtil.baseAmount(inbound.outboundFee), AssetBASE);
|
|
309
|
+
case XRPChain:
|
|
310
|
+
return new xchainUtil.AssetCryptoAmount(xchainUtil.baseAmount(inbound.outboundFee), AssetXRP);
|
|
311
|
+
case SOLChain:
|
|
312
|
+
return new xchainUtil.AssetCryptoAmount(xchainUtil.baseAmount(inbound.outboundFee), AssetSOL);
|
|
299
313
|
}
|
|
300
314
|
throw new Error(`could not calculate outbound fee for ${asset.chain}`);
|
|
301
315
|
};
|
|
@@ -1250,8 +1264,8 @@ class ThorchainQuery {
|
|
|
1250
1264
|
* @param quoteSwapParams - Input parameters for the swap quote.
|
|
1251
1265
|
* @returns Transaction details including memo, address, fees, etc.
|
|
1252
1266
|
*/
|
|
1253
|
-
quoteSwap(
|
|
1254
|
-
return __awaiter(this,
|
|
1267
|
+
quoteSwap(_a) {
|
|
1268
|
+
return __awaiter(this, arguments, void 0, function* ({ fromAsset, destinationAsset, amount, destinationAddress, streamingInterval, streamingQuantity, liquidityToleranceBps, toleranceBps, affiliateBps, affiliateAddress, height, }) {
|
|
1255
1269
|
// Validates swap and pushes error if there is one
|
|
1256
1270
|
const errors = [];
|
|
1257
1271
|
const error = yield this.validateAmount(amount);
|
|
@@ -1417,7 +1431,7 @@ class ThorchainQuery {
|
|
|
1417
1431
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1418
1432
|
// Return the fees converted to the specified asset
|
|
1419
1433
|
return {
|
|
1420
|
-
asset: fees.asset,
|
|
1434
|
+
asset: fees.asset, // Shouldn't be asset?
|
|
1421
1435
|
// swapFee: await this.convert(fees.swapFee, asset),
|
|
1422
1436
|
outboundFee: yield this.convert(fees.outboundFee, asset),
|
|
1423
1437
|
affiliateFee: yield this.convert(fees.affiliateFee, asset),
|
|
@@ -1666,34 +1680,34 @@ class ThorchainQuery {
|
|
|
1666
1680
|
const assetOutbound = calcOutboundFee(params.asset, inboundDetails);
|
|
1667
1681
|
// Create an EstimateWithdrawLP object
|
|
1668
1682
|
const estimateLP = {
|
|
1669
|
-
assetAddress: memberDetail.position.asset_address,
|
|
1670
|
-
runeAddress: memberDetail.position.rune_address,
|
|
1671
|
-
slipPercent: slip.times(100),
|
|
1683
|
+
assetAddress: memberDetail.position.asset_address, // Address for the asset
|
|
1684
|
+
runeAddress: memberDetail.position.rune_address, // Address for the rune
|
|
1685
|
+
slipPercent: slip.times(100), // Slip percentage
|
|
1672
1686
|
inbound: {
|
|
1673
1687
|
minToSend: {
|
|
1674
1688
|
// Minimum amount to send
|
|
1675
|
-
rune: dustValues.rune,
|
|
1676
|
-
asset: dustValues.asset,
|
|
1689
|
+
rune: dustValues.rune, // Rune amount
|
|
1690
|
+
asset: dustValues.asset, // Asset amount
|
|
1677
1691
|
total: (yield this.convert(dustValues.asset, AssetRuneNative)).plus(dustValues.rune), // Total amount
|
|
1678
1692
|
},
|
|
1679
1693
|
fees: {
|
|
1680
1694
|
// Inbound fees
|
|
1681
|
-
rune: runeInbound,
|
|
1682
|
-
asset: assetInbound,
|
|
1695
|
+
rune: runeInbound, // Rune fees
|
|
1696
|
+
asset: assetInbound, // Asset fees
|
|
1683
1697
|
total: (yield this.convert(assetInbound, AssetRuneNative)).plus(runeInbound), // Total fees
|
|
1684
1698
|
},
|
|
1685
1699
|
},
|
|
1686
1700
|
outboundFee: {
|
|
1687
1701
|
// Outbound fees
|
|
1688
|
-
asset: assetOutbound,
|
|
1689
|
-
rune: runeOutbound,
|
|
1702
|
+
asset: assetOutbound, // Asset fees
|
|
1703
|
+
rune: runeOutbound, // Rune fees
|
|
1690
1704
|
total: (yield this.convert(assetOutbound, AssetRuneNative)).plus(runeOutbound), // Total fees
|
|
1691
1705
|
},
|
|
1692
|
-
assetAmount: poolShare.assetShare,
|
|
1693
|
-
runeAmount: poolShare.runeShare,
|
|
1694
|
-
lpGrowth: memberDetail.lpGrowth,
|
|
1695
|
-
estimatedWaitSeconds: waitTimeSeconds,
|
|
1696
|
-
impermanentLossProtection: memberDetail.impermanentLossProtection,
|
|
1706
|
+
assetAmount: poolShare.assetShare, // Asset amount
|
|
1707
|
+
runeAmount: poolShare.runeShare, // Rune amount
|
|
1708
|
+
lpGrowth: memberDetail.lpGrowth, // LP growth
|
|
1709
|
+
estimatedWaitSeconds: waitTimeSeconds, // Estimated wait time in seconds
|
|
1710
|
+
impermanentLossProtection: memberDetail.impermanentLossProtection, // Impermanent loss protection
|
|
1697
1711
|
assetPool: assetPool.thornodeDetails.asset, // Asset pool
|
|
1698
1712
|
};
|
|
1699
1713
|
return estimateLP; // Return the EstimateWithdrawLP object
|
|
@@ -1830,7 +1844,7 @@ class ThorchainQuery {
|
|
|
1830
1844
|
// Affiliate fee
|
|
1831
1845
|
new xchainUtil.CryptoAmount(xchainUtil.baseAmount(depositQuote.fees.affiliate), addAmount.asset), // Convert to base amount
|
|
1832
1846
|
assetDecimals),
|
|
1833
|
-
asset: feeAsset,
|
|
1847
|
+
asset: feeAsset, // Asset fee
|
|
1834
1848
|
outbound: getCryptoAmountWithNotation(
|
|
1835
1849
|
// Outbound fee
|
|
1836
1850
|
new xchainUtil.CryptoAmount(xchainUtil.baseAmount(depositQuote.fees.outbound), feeAsset), // Convert to base amount
|
|
@@ -1853,15 +1867,15 @@ class ThorchainQuery {
|
|
|
1853
1867
|
// Estimated deposit value
|
|
1854
1868
|
new xchainUtil.CryptoAmount(xchainUtil.baseAmount(depositQuote.expected_amount_deposit), addAmount.asset), // Convert to base amount
|
|
1855
1869
|
assetDecimals),
|
|
1856
|
-
fee: saverFees,
|
|
1857
|
-
expiry: new Date(depositQuote.expiry),
|
|
1858
|
-
toAddress: depositQuote.inbound_address,
|
|
1859
|
-
memo: depositQuote.memo,
|
|
1860
|
-
estimatedWaitTime: depositQuote.inbound_confirmation_seconds || 0,
|
|
1861
|
-
canAddSaver: errors.length === 0,
|
|
1862
|
-
slipBasisPoints: depositQuote.fees.slippage_bps,
|
|
1863
|
-
saverCapFilledPercent,
|
|
1864
|
-
recommendedMinAmountIn: depositQuote.recommended_min_amount_in,
|
|
1870
|
+
fee: saverFees, // Fees
|
|
1871
|
+
expiry: new Date(depositQuote.expiry), // Expiry date
|
|
1872
|
+
toAddress: depositQuote.inbound_address, // Recipient address
|
|
1873
|
+
memo: depositQuote.memo, // Memo
|
|
1874
|
+
estimatedWaitTime: depositQuote.inbound_confirmation_seconds || 0, // Estimated wait time
|
|
1875
|
+
canAddSaver: errors.length === 0, // Can add saver flag
|
|
1876
|
+
slipBasisPoints: depositQuote.fees.slippage_bps, // Slip basis points
|
|
1877
|
+
saverCapFilledPercent, // Saver filled capacity
|
|
1878
|
+
recommendedMinAmountIn: depositQuote.recommended_min_amount_in, // Recommended minimum amount in
|
|
1865
1879
|
errors, // Errors
|
|
1866
1880
|
};
|
|
1867
1881
|
return estimateAddSaver; // Return the EstimateAddSaver object
|
|
@@ -1888,27 +1902,27 @@ class ThorchainQuery {
|
|
|
1888
1902
|
errors.push(checkPositon.errors[i]);
|
|
1889
1903
|
}
|
|
1890
1904
|
return {
|
|
1891
|
-
dustAmount: new xchainUtil.AssetCryptoAmount(xchainUtil.baseAmount(0), getChainAsset(withdrawParams.asset.chain)),
|
|
1892
|
-
dustThreshold: new xchainUtil.AssetCryptoAmount(xchainUtil.baseAmount(0), getChainAsset(withdrawParams.asset.chain)),
|
|
1905
|
+
dustAmount: new xchainUtil.AssetCryptoAmount(xchainUtil.baseAmount(0), getChainAsset(withdrawParams.asset.chain)), // Dust amount
|
|
1906
|
+
dustThreshold: new xchainUtil.AssetCryptoAmount(xchainUtil.baseAmount(0), getChainAsset(withdrawParams.asset.chain)), // Dust threshold
|
|
1893
1907
|
expectedAssetAmount: new xchainUtil.CryptoAmount(// Expected asset amount
|
|
1894
1908
|
xchainUtil.assetToBase(xchainUtil.assetAmount(checkPositon.redeemableValue.assetAmount.amount())), // Convert to base amount
|
|
1895
1909
|
withdrawParams.asset),
|
|
1896
1910
|
fee: {
|
|
1897
|
-
affiliate: new xchainUtil.CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), withdrawParams.asset),
|
|
1898
|
-
asset: withdrawParams.asset,
|
|
1899
|
-
liquidity: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(0), withdrawParams.asset),
|
|
1911
|
+
affiliate: new xchainUtil.CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), withdrawParams.asset), // Affiliate fee
|
|
1912
|
+
asset: withdrawParams.asset, // Asset
|
|
1913
|
+
liquidity: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(0), withdrawParams.asset), // Liquidity fee
|
|
1900
1914
|
outbound: new xchainUtil.CryptoAmount(// Outbound fee
|
|
1901
1915
|
xchainUtil.assetToBase(xchainUtil.assetAmount(calcOutboundFee(withdrawParams.asset, inboundDetails[withdrawParams.asset.chain]).assetAmount.amount())), withdrawParams.asset),
|
|
1902
1916
|
totalBps: 0, // Total basis points
|
|
1903
1917
|
},
|
|
1904
|
-
expiry: new Date(0),
|
|
1905
|
-
toAddress: '',
|
|
1906
|
-
memo: '',
|
|
1907
|
-
inboundDelayBlocks: 0,
|
|
1908
|
-
inboundDelaySeconds: 0,
|
|
1909
|
-
outBoundDelayBlocks: 0,
|
|
1910
|
-
outBoundDelaySeconds: 0,
|
|
1911
|
-
slipBasisPoints: -1,
|
|
1918
|
+
expiry: new Date(0), // Expiry date
|
|
1919
|
+
toAddress: '', // Recipient address
|
|
1920
|
+
memo: '', // Memo
|
|
1921
|
+
inboundDelayBlocks: 0, // Number of blocks for inbound delay
|
|
1922
|
+
inboundDelaySeconds: 0, // Number of seconds for inbound delay
|
|
1923
|
+
outBoundDelayBlocks: 0, // Number of blocks for outbound delay
|
|
1924
|
+
outBoundDelaySeconds: 0, // Number of seconds for outbound delay
|
|
1925
|
+
slipBasisPoints: -1, // Slip basis points (negative value indicates no slip)
|
|
1912
1926
|
errors, // Errors array
|
|
1913
1927
|
};
|
|
1914
1928
|
}
|
|
@@ -2036,13 +2050,13 @@ class ThorchainQuery {
|
|
|
2036
2050
|
const saverGrowth = redeemableAssetAmount.minus(depositAmount).div(depositAmount).times(100);
|
|
2037
2051
|
// Create and populate a SaversPosition object with the calculated values
|
|
2038
2052
|
const saversPos = {
|
|
2039
|
-
depositValue: depositAmount,
|
|
2040
|
-
redeemableValue: redeemableAssetAmount,
|
|
2041
|
-
lastAddHeight: Number(savers === null || savers === void 0 ? void 0 : savers.last_add_height),
|
|
2042
|
-
percentageGrowth: saverGrowth.assetAmount.amount().toNumber(),
|
|
2043
|
-
ageInYears: saversAge,
|
|
2044
|
-
ageInDays: saversAge * 365,
|
|
2045
|
-
asset: params.asset,
|
|
2053
|
+
depositValue: depositAmount, // Current deposit value of the saver
|
|
2054
|
+
redeemableValue: redeemableAssetAmount, // Redeemable value of the saver's position
|
|
2055
|
+
lastAddHeight: Number(savers === null || savers === void 0 ? void 0 : savers.last_add_height), // Height at which the last addition was made to the pool
|
|
2056
|
+
percentageGrowth: saverGrowth.assetAmount.amount().toNumber(), // Percentage growth of the saver's position
|
|
2057
|
+
ageInYears: saversAge, // Age of the saver's position in years
|
|
2058
|
+
ageInDays: saversAge * 365, // Age of the saver's position in days
|
|
2059
|
+
asset: params.asset, // Asset of the saver's position
|
|
2046
2060
|
errors, // Array of any errors encountered during the calculation
|
|
2047
2061
|
};
|
|
2048
2062
|
// Return the SaversPosition object representing the saver's position
|
|
@@ -2092,8 +2106,8 @@ class ThorchainQuery {
|
|
|
2092
2106
|
* @param loanOpenParams - params needed for the end Point
|
|
2093
2107
|
* @returns
|
|
2094
2108
|
*/
|
|
2095
|
-
getLoanQuoteOpen(
|
|
2096
|
-
return __awaiter(this,
|
|
2109
|
+
getLoanQuoteOpen(_a) {
|
|
2110
|
+
return __awaiter(this, arguments, void 0, function* ({ asset, amount, targetAsset, destination, minOut, affiliateBps, affiliate, height, }) {
|
|
2097
2111
|
const errors = [];
|
|
2098
2112
|
const loanOpenResp = yield this.thorchainCache.thornode.getLoanQuoteOpen(`${asset.chain}.${asset.symbol}`, amount.baseAmount.amount().toNumber(), `${targetAsset.chain}.${targetAsset.symbol}`, destination, minOut, affiliateBps, affiliate, height);
|
|
2099
2113
|
const response = JSON.parse(JSON.stringify(loanOpenResp));
|
|
@@ -2164,8 +2178,8 @@ class ThorchainQuery {
|
|
|
2164
2178
|
* @param loanOpenParams - Parameters needed for the endpoint.
|
|
2165
2179
|
* @returns A Promise resolving to a LoanOpenQuote.
|
|
2166
2180
|
*/
|
|
2167
|
-
getLoanQuoteClose(
|
|
2168
|
-
return __awaiter(this,
|
|
2181
|
+
getLoanQuoteClose(_a) {
|
|
2182
|
+
return __awaiter(this, arguments, void 0, function* ({ asset, amount, loanAsset, loanOwner, minOut, height, }) {
|
|
2169
2183
|
const errors = [];
|
|
2170
2184
|
// Retrieve loan open response from ThorNode API
|
|
2171
2185
|
const loanCloseResp = yield this.thorchainCache.thornode.getLoanQuoteClose(`${asset.chain}.${asset.symbol}`, amount.baseAmount.amount().toNumber(), `${loanAsset.chain}.${loanAsset.symbol}`, loanOwner, minOut, height);
|
|
@@ -2368,8 +2382,8 @@ class ThorchainQuery {
|
|
|
2368
2382
|
* @param {Address[]} params.addresses - List of addresses
|
|
2369
2383
|
* @returns {SwapsHistory} Swap history
|
|
2370
2384
|
*/
|
|
2371
|
-
getSwapHistory(
|
|
2372
|
-
return __awaiter(this,
|
|
2385
|
+
getSwapHistory(_a) {
|
|
2386
|
+
return __awaiter(this, arguments, void 0, function* ({ addresses }) {
|
|
2373
2387
|
const actionsResume = yield this.thorchainCache.midgardQuery.midgardCache.midgard.getActions({
|
|
2374
2388
|
address: addresses.join(','),
|
|
2375
2389
|
type: 'swap',
|
|
@@ -2424,8 +2438,8 @@ class ThorchainQuery {
|
|
|
2424
2438
|
* @param {TradeAssetUnitsParams} params Get trade asset unit params
|
|
2425
2439
|
* @returns {TradeAssetUnits} Returns the total units and depth of a trade asset
|
|
2426
2440
|
*/
|
|
2427
|
-
getTradeAssetUnits(
|
|
2428
|
-
return __awaiter(this,
|
|
2441
|
+
getTradeAssetUnits(_a) {
|
|
2442
|
+
return __awaiter(this, arguments, void 0, function* ({ asset, height }) {
|
|
2429
2443
|
const { units, depth } = yield this.thorchainCache.thornode.getTradeAssetUnits(xchainUtil.assetToString(asset), height);
|
|
2430
2444
|
const decimals = yield this.thorchainCache.midgardQuery.getDecimalForAsset(asset);
|
|
2431
2445
|
return {
|
|
@@ -2443,7 +2457,7 @@ class ThorchainQuery {
|
|
|
2443
2457
|
getTradeAssetsUnits(params) {
|
|
2444
2458
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2445
2459
|
const tradeAssetsUnits = yield this.thorchainCache.thornode.getTradeAssetsUnits(params === null || params === void 0 ? void 0 : params.height);
|
|
2446
|
-
const parseData = (
|
|
2460
|
+
const parseData = (_a) => __awaiter(this, [_a], void 0, function* ({ asset, units, depth }) {
|
|
2447
2461
|
const tradeAsset = xchainUtil.assetFromStringEx(asset);
|
|
2448
2462
|
const decimals = yield this.thorchainCache.midgardQuery.getDecimalForAsset(tradeAsset);
|
|
2449
2463
|
return {
|
|
@@ -2460,8 +2474,8 @@ class ThorchainQuery {
|
|
|
2460
2474
|
* @param {TradeAssetsUnitsParams} params Get trade asset unit params
|
|
2461
2475
|
* @returns {TradeAssetUnits[]} Returns the total units and depth for each trade asset
|
|
2462
2476
|
*/
|
|
2463
|
-
getAddressTradeAccounts(
|
|
2464
|
-
return __awaiter(this,
|
|
2477
|
+
getAddressTradeAccounts(_a) {
|
|
2478
|
+
return __awaiter(this, arguments, void 0, function* ({ address, height, }) {
|
|
2465
2479
|
const account = yield this.thorchainCache.thornode.getTradeAssetAccount(address, height);
|
|
2466
2480
|
const parseData = (tradeAssetInfo) => __awaiter(this, void 0, void 0, function* () {
|
|
2467
2481
|
const asset = xchainUtil.assetFromStringEx(tradeAssetInfo.asset);
|
|
@@ -2482,8 +2496,8 @@ class ThorchainQuery {
|
|
|
2482
2496
|
* @param {number} height Optional - Block height
|
|
2483
2497
|
* @returns Returns all trade accounts for an asset
|
|
2484
2498
|
*/
|
|
2485
|
-
getTradeAssetAccounts(
|
|
2486
|
-
return __awaiter(this,
|
|
2499
|
+
getTradeAssetAccounts(_a) {
|
|
2500
|
+
return __awaiter(this, arguments, void 0, function* ({ asset, height }) {
|
|
2487
2501
|
const accounts = yield this.thorchainCache.thornode.getTradeAssetAccounts(xchainUtil.assetToString(asset), height);
|
|
2488
2502
|
const decimals = yield this.thorchainCache.midgardQuery.getDecimalForAsset(asset);
|
|
2489
2503
|
return accounts.map((account) => {
|
|
@@ -2535,8 +2549,8 @@ class ThorchainQuery {
|
|
|
2535
2549
|
* @param {RunePoolProviderParams} params Get Rune pool provider position params
|
|
2536
2550
|
* @returns {RunePoolProvider} Rune pool provider position
|
|
2537
2551
|
*/
|
|
2538
|
-
getRunePoolProvider(
|
|
2539
|
-
return __awaiter(this,
|
|
2552
|
+
getRunePoolProvider(_a) {
|
|
2553
|
+
return __awaiter(this, arguments, void 0, function* ({ address, height }) {
|
|
2540
2554
|
const position = yield this.thorchainCache.thornode.getRunePoolProvider(address, height);
|
|
2541
2555
|
return {
|
|
2542
2556
|
address: position.rune_address,
|
|
@@ -2757,8 +2771,8 @@ class TransactionStage {
|
|
|
2757
2771
|
* @param progress - Transaction progress object.
|
|
2758
2772
|
*/
|
|
2759
2773
|
checkSwapProgress(txData, progress) {
|
|
2760
|
-
var _a, _b, _c, _d;
|
|
2761
2774
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2775
|
+
var _a, _b, _c, _d;
|
|
2762
2776
|
if (progress.inboundObserved) {
|
|
2763
2777
|
// Extract memo fields
|
|
2764
2778
|
const memo = (_a = txData.tx.tx.memo) !== null && _a !== void 0 ? _a : '';
|
|
@@ -2786,7 +2800,7 @@ class TransactionStage {
|
|
|
2786
2800
|
status: swapStatus,
|
|
2787
2801
|
expectedOutBlock,
|
|
2788
2802
|
expectedOutDate,
|
|
2789
|
-
expectedAmountOut: minimumAmountOut,
|
|
2803
|
+
expectedAmountOut: minimumAmountOut, // TODO call estimateSwap()
|
|
2790
2804
|
confirmations,
|
|
2791
2805
|
minimumAmountOut,
|
|
2792
2806
|
affliateFee,
|
|
@@ -2831,8 +2845,8 @@ class TransactionStage {
|
|
|
2831
2845
|
* @returns Promise<TXProgress> - Transaction progress object.
|
|
2832
2846
|
*/
|
|
2833
2847
|
determineObserved(txData) {
|
|
2834
|
-
var _a, _b, _c, _d;
|
|
2835
2848
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2849
|
+
var _a, _b, _c, _d;
|
|
2836
2850
|
const progress = {
|
|
2837
2851
|
txType: exports.TxType.Unknown,
|
|
2838
2852
|
};
|
|
@@ -2868,7 +2882,7 @@ class TransactionStage {
|
|
|
2868
2882
|
: yield this.blockToDate(assetIn.chain, txData);
|
|
2869
2883
|
progress.inboundObserved = {
|
|
2870
2884
|
status,
|
|
2871
|
-
date: dateObserved,
|
|
2885
|
+
date: dateObserved, // date observed?
|
|
2872
2886
|
block,
|
|
2873
2887
|
expectedConfirmationBlock: finalizeBlock,
|
|
2874
2888
|
expectedConfirmationDate,
|
|
@@ -2886,8 +2900,8 @@ class TransactionStage {
|
|
|
2886
2900
|
* @param progress - Transaction progress object.
|
|
2887
2901
|
*/
|
|
2888
2902
|
checkAddLpProgress(txData, progress) {
|
|
2889
|
-
var _a;
|
|
2890
2903
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2904
|
+
var _a;
|
|
2891
2905
|
if (progress.inboundObserved) {
|
|
2892
2906
|
// Extract memo fields
|
|
2893
2907
|
const memo = (_a = txData.tx.tx.memo) !== null && _a !== void 0 ? _a : '';
|
|
@@ -2918,8 +2932,8 @@ class TransactionStage {
|
|
|
2918
2932
|
* @param progress - Transaction progress object.
|
|
2919
2933
|
*/
|
|
2920
2934
|
checkWithdrawLpProgress(txData, progress) {
|
|
2921
|
-
var _a, _b;
|
|
2922
2935
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2936
|
+
var _a, _b;
|
|
2923
2937
|
if (progress.inboundObserved) {
|
|
2924
2938
|
// Extract memo fields
|
|
2925
2939
|
const memo = (_a = txData.tx.tx.memo) !== null && _a !== void 0 ? _a : '';
|
|
@@ -2988,8 +3002,8 @@ class TransactionStage {
|
|
|
2988
3002
|
* @param progress - Transaction progress object.
|
|
2989
3003
|
*/
|
|
2990
3004
|
checkWithdrawSaverProgress(txData, progress) {
|
|
2991
|
-
var _a;
|
|
2992
3005
|
return __awaiter(this, void 0, void 0, function* () {
|
|
3006
|
+
var _a;
|
|
2993
3007
|
if (progress.inboundObserved) {
|
|
2994
3008
|
// Extract memo fields
|
|
2995
3009
|
const memo = (_a = txData.tx.tx.memo) !== null && _a !== void 0 ? _a : '';
|
|
@@ -3186,6 +3200,7 @@ exports.AssetETH = AssetETH;
|
|
|
3186
3200
|
exports.AssetLTC = AssetLTC;
|
|
3187
3201
|
exports.AssetMAYA = AssetMAYA;
|
|
3188
3202
|
exports.AssetRuneNative = AssetRuneNative;
|
|
3203
|
+
exports.AssetSOL = AssetSOL;
|
|
3189
3204
|
exports.AssetXRP = AssetXRP;
|
|
3190
3205
|
exports.BASEChain = BASEChain;
|
|
3191
3206
|
exports.BCHChain = BCHChain;
|
|
@@ -3199,6 +3214,7 @@ exports.GAIAChain = GAIAChain;
|
|
|
3199
3214
|
exports.LTCChain = LTCChain;
|
|
3200
3215
|
exports.LiquidityPool = LiquidityPool;
|
|
3201
3216
|
exports.MAYAChain = MAYAChain;
|
|
3217
|
+
exports.SOLChain = SOLChain;
|
|
3202
3218
|
exports.THORCHAIN_DECIMAL = THORCHAIN_DECIMAL;
|
|
3203
3219
|
exports.THORChain = THORChain;
|
|
3204
3220
|
exports.ThorchainCache = ThorchainCache;
|
package/lib/utils/const.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export declare const assetUSDC: TokenAsset;
|
|
|
13
13
|
export declare const AssetBNB: Asset;
|
|
14
14
|
export declare const AssetBASE: Asset;
|
|
15
15
|
export declare const AssetXRP: Asset;
|
|
16
|
+
export declare const AssetSOL: Asset;
|
|
16
17
|
export declare const BNBChain = "BNB";
|
|
17
18
|
export declare const BTCChain = "BTC";
|
|
18
19
|
export declare const BCHChain = "BCH";
|
|
@@ -26,5 +27,6 @@ export declare const BSCChain = "BSC";
|
|
|
26
27
|
export declare const THORChain = "THOR";
|
|
27
28
|
export declare const BASEChain = "BASE";
|
|
28
29
|
export declare const XRPChain = "XRP";
|
|
30
|
+
export declare const SOLChain = "SOL";
|
|
29
31
|
export declare const THORCHAIN_DECIMAL = 8;
|
|
30
32
|
export declare const isAssetRuneNative: (asset: AnyAsset) => boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xchainjs/xchain-thorchain-query",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.8",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Thorchain query module that is responsible for estimating swap calculations and add/remove liquidity for thorchain ",
|
|
6
6
|
"keywords": [
|
|
@@ -33,10 +33,10 @@
|
|
|
33
33
|
"postversion": "git push --follow-tags"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@xchainjs/xchain-client": "2.0.
|
|
37
|
-
"@xchainjs/xchain-midgard-query": "2.0.
|
|
38
|
-
"@xchainjs/xchain-thornode": "1.0.
|
|
39
|
-
"@xchainjs/xchain-util": "2.0.
|
|
36
|
+
"@xchainjs/xchain-client": "2.0.6",
|
|
37
|
+
"@xchainjs/xchain-midgard-query": "2.0.6",
|
|
38
|
+
"@xchainjs/xchain-thornode": "1.0.5",
|
|
39
|
+
"@xchainjs/xchain-util": "2.0.4",
|
|
40
40
|
"axios": "1.8.4",
|
|
41
41
|
"axios-retry": "3.2.5",
|
|
42
42
|
"bignumber.js": "^9.0.0"
|