@xchainjs/xchain-thorchain-query 2.0.15 → 3.0.0
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 +13 -479
- package/lib/index.js +13 -479
- package/lib/thorchain-query.d.ts +8 -22
- package/lib/utils/thornode.d.ts +1 -45
- package/package.json +5 -5
package/lib/index.esm.js
CHANGED
|
@@ -729,49 +729,6 @@ class Thornode {
|
|
|
729
729
|
throw new Error(`THORNode not responding`);
|
|
730
730
|
});
|
|
731
731
|
}
|
|
732
|
-
/**
|
|
733
|
-
*
|
|
734
|
-
* @param asset - asset to add to savers
|
|
735
|
-
* @param amount - amount to deposit
|
|
736
|
-
* @param height - block height
|
|
737
|
-
* @returns quotes deposit object response
|
|
738
|
-
*/
|
|
739
|
-
getSaversDepositQuote(asset, amount, height) {
|
|
740
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
741
|
-
for (const api of this.quoteApi) {
|
|
742
|
-
try {
|
|
743
|
-
const resp = (yield api.quotesaverdeposit(height, asset, amount)).data;
|
|
744
|
-
return resp;
|
|
745
|
-
}
|
|
746
|
-
catch (_e) {
|
|
747
|
-
//console.error(_e)
|
|
748
|
-
}
|
|
749
|
-
}
|
|
750
|
-
throw new Error(`THORNode not responding`);
|
|
751
|
-
});
|
|
752
|
-
}
|
|
753
|
-
/**
|
|
754
|
-
*
|
|
755
|
-
* @param asset - asset to withdraw
|
|
756
|
-
* @param address - savers address
|
|
757
|
-
* @param height - block height
|
|
758
|
-
* @param withdrawBps - withddraw percent
|
|
759
|
-
* @returns quotes withdraw object response
|
|
760
|
-
*/
|
|
761
|
-
getSaversWithdrawQuote(withdrawParams) {
|
|
762
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
763
|
-
for (const api of this.quoteApi) {
|
|
764
|
-
try {
|
|
765
|
-
const resp = yield api.quotesaverwithdraw(withdrawParams.height, `${withdrawParams.asset.chain}.${withdrawParams.asset.symbol}`, withdrawParams.address, withdrawParams.withdrawBps);
|
|
766
|
-
return resp.data;
|
|
767
|
-
}
|
|
768
|
-
catch (_e) {
|
|
769
|
-
//console.error(_e)
|
|
770
|
-
}
|
|
771
|
-
}
|
|
772
|
-
throw new Error(`THORNode not responding`);
|
|
773
|
-
});
|
|
774
|
-
}
|
|
775
732
|
/**
|
|
776
733
|
*
|
|
777
734
|
* @param fromAsset - input asset
|
|
@@ -798,58 +755,6 @@ class Thornode {
|
|
|
798
755
|
throw new Error(`THORNode not responding`);
|
|
799
756
|
});
|
|
800
757
|
}
|
|
801
|
-
/**
|
|
802
|
-
*
|
|
803
|
-
* @param height
|
|
804
|
-
* @param asset
|
|
805
|
-
* @param amount
|
|
806
|
-
* @param targetAsset
|
|
807
|
-
* @param destination
|
|
808
|
-
* @param minOut
|
|
809
|
-
* @param affiliateBps
|
|
810
|
-
* @param affiliate
|
|
811
|
-
* @returns
|
|
812
|
-
*/
|
|
813
|
-
getLoanQuoteOpen(asset, amount, targetAsset, destination, minOut, affiliateBps, affiliate, height) {
|
|
814
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
815
|
-
for (const api of this.quoteApi) {
|
|
816
|
-
try {
|
|
817
|
-
const resp = (yield api.quoteloanopen(height, asset, amount, targetAsset, destination, minOut, affiliateBps, affiliate)).data;
|
|
818
|
-
return resp;
|
|
819
|
-
}
|
|
820
|
-
catch (_e) {
|
|
821
|
-
//console.log(_e)
|
|
822
|
-
}
|
|
823
|
-
}
|
|
824
|
-
throw new Error(`THORNode is not responding`);
|
|
825
|
-
});
|
|
826
|
-
}
|
|
827
|
-
/**
|
|
828
|
-
*
|
|
829
|
-
* @param height
|
|
830
|
-
* @param asset
|
|
831
|
-
* @param amount
|
|
832
|
-
* @param targetAsset
|
|
833
|
-
* @param destination
|
|
834
|
-
* @param minOut
|
|
835
|
-
* @param affiliateBps
|
|
836
|
-
* @param affiliate
|
|
837
|
-
* @returns
|
|
838
|
-
*/
|
|
839
|
-
getLoanQuoteClose(asset, amount, loanAsset, loanOwner, minOut, height) {
|
|
840
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
841
|
-
for (const api of this.quoteApi) {
|
|
842
|
-
try {
|
|
843
|
-
const resp = (yield api.quoteloanclose(height, asset, amount, loanAsset, loanOwner, minOut)).data;
|
|
844
|
-
return resp;
|
|
845
|
-
}
|
|
846
|
-
catch (_e) {
|
|
847
|
-
// console.log(_e)
|
|
848
|
-
}
|
|
849
|
-
}
|
|
850
|
-
throw new Error(`THORNode is not responding`);
|
|
851
|
-
});
|
|
852
|
-
}
|
|
853
758
|
getThornameDetails(thorname, height) {
|
|
854
759
|
return __awaiter(this, void 0, void 0, function* () {
|
|
855
760
|
for (const api of this.thornamesApi) {
|
|
@@ -1792,224 +1697,20 @@ class ThorchainQuery {
|
|
|
1792
1697
|
});
|
|
1793
1698
|
}
|
|
1794
1699
|
// Savers Queries
|
|
1795
|
-
// Derrived from https://dev.thorchain.org/thorchain-dev/connection-guide/savers-guide
|
|
1796
1700
|
/**
|
|
1797
|
-
*
|
|
1798
|
-
* @param addAmount - The amount to be added to the saver
|
|
1799
|
-
* @returns - Object of type EstimateAddSaver
|
|
1701
|
+
* @deprecated Saver quote endpoints were removed from THORNode API in v3.15.0
|
|
1800
1702
|
*/
|
|
1801
|
-
estimateAddSaver(
|
|
1703
|
+
estimateAddSaver(_addAmount) {
|
|
1802
1704
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1803
|
-
|
|
1804
|
-
// Check for errors before sending quote
|
|
1805
|
-
errors = yield this.getAddSaversEstimateErrors(addAmount);
|
|
1806
|
-
// Request parameter amount should always be in 1e8
|
|
1807
|
-
// Adjust decimals if chain decimals != 8
|
|
1808
|
-
const newAddAmount = addAmount.baseAmount.decimal != 8 ? getBaseAmountWithDiffDecimals(addAmount, 8) : addAmount.baseAmount.amount();
|
|
1809
|
-
// Fetch quote
|
|
1810
|
-
const depositQuote = yield this.thorchainCache.thornode.getSaversDepositQuote(assetToString(addAmount.asset), // Convert asset to string
|
|
1811
|
-
newAddAmount.toNumber());
|
|
1812
|
-
// Error handling
|
|
1813
|
-
const response = JSON.parse(JSON.stringify(depositQuote));
|
|
1814
|
-
if (response.error)
|
|
1815
|
-
errors.push(`Thornode request quote failed: ${response.error}`); // Push error to array if exists
|
|
1816
|
-
// The recommended minimum inbound amount for this transaction type & inbound asset.
|
|
1817
|
-
// Sending less than this amount could result in failed refunds
|
|
1818
|
-
if (depositQuote.recommended_min_amount_in &&
|
|
1819
|
-
addAmount.baseAmount.amount().toNumber() < Number(depositQuote.recommended_min_amount_in))
|
|
1820
|
-
errors.push(`Error amount in: ${addAmount.baseAmount.amount().toNumber()} is less than recommended Min Amount: ${depositQuote.recommended_min_amount_in}`);
|
|
1821
|
-
// Return errors if there is any
|
|
1822
|
-
if (errors.length > 0) {
|
|
1823
|
-
// Return an object with default values and errors
|
|
1824
|
-
return {
|
|
1825
|
-
assetAmount: addAmount,
|
|
1826
|
-
estimatedDepositValue: new CryptoAmount(baseAmount(0), addAmount.asset),
|
|
1827
|
-
fee: {
|
|
1828
|
-
affiliate: new CryptoAmount(baseAmount(0), addAmount.asset),
|
|
1829
|
-
asset: addAmount.asset,
|
|
1830
|
-
outbound: new CryptoAmount(baseAmount(0), addAmount.asset),
|
|
1831
|
-
liquidity: new CryptoAmount(baseAmount(0), addAmount.asset),
|
|
1832
|
-
totalBps: depositQuote.fees.total_bps || 0,
|
|
1833
|
-
},
|
|
1834
|
-
expiry: new Date(0),
|
|
1835
|
-
toAddress: '',
|
|
1836
|
-
memo: '',
|
|
1837
|
-
saverCapFilledPercent: -1,
|
|
1838
|
-
estimatedWaitTime: -1,
|
|
1839
|
-
slipBasisPoints: -1,
|
|
1840
|
-
recommendedMinAmountIn: depositQuote.recommended_min_amount_in,
|
|
1841
|
-
canAddSaver: false,
|
|
1842
|
-
errors, // Errors
|
|
1843
|
-
};
|
|
1844
|
-
}
|
|
1845
|
-
// Get pool details
|
|
1846
|
-
const pool = (yield this.thorchainCache.getPoolForAsset(addAmount.asset)).thornodeDetails;
|
|
1847
|
-
// Get asset decimals
|
|
1848
|
-
const assetDecimals = yield this.thorchainCache.midgardQuery.getDecimalForAsset(addAmount.asset);
|
|
1849
|
-
// Get fee asset decimals
|
|
1850
|
-
const feeAssetDecimals = yield this.thorchainCache.midgardQuery.getDecimalForAsset(addAmount.asset);
|
|
1851
|
-
// Organize fees
|
|
1852
|
-
const feeAsset = assetFromStringEx(depositQuote.fees.asset);
|
|
1853
|
-
const saverFees = {
|
|
1854
|
-
affiliate: getCryptoAmountWithNotation(
|
|
1855
|
-
// Affiliate fee
|
|
1856
|
-
new CryptoAmount(baseAmount(depositQuote.fees.affiliate), addAmount.asset), // Convert to base amount
|
|
1857
|
-
assetDecimals),
|
|
1858
|
-
asset: feeAsset, // Asset fee
|
|
1859
|
-
outbound: getCryptoAmountWithNotation(
|
|
1860
|
-
// Outbound fee
|
|
1861
|
-
new CryptoAmount(baseAmount(depositQuote.fees.outbound), feeAsset), // Convert to base amount
|
|
1862
|
-
feeAssetDecimals),
|
|
1863
|
-
liquidity: getCryptoAmountWithNotation(
|
|
1864
|
-
// Liquidity fee
|
|
1865
|
-
new CryptoAmount(baseAmount(depositQuote.fees.liquidity), feeAsset), // Convert to base amount
|
|
1866
|
-
feeAssetDecimals),
|
|
1867
|
-
totalBps: depositQuote.fees.total_bps || 0, // Total basis points
|
|
1868
|
-
};
|
|
1869
|
-
// Define saver filled capacity
|
|
1870
|
-
const saverCapFilledPercent = (Number(pool.synth_supply) / Number(pool.balance_asset)) * 100;
|
|
1871
|
-
// Return object
|
|
1872
|
-
const estimateAddSaver = {
|
|
1873
|
-
assetAmount: getCryptoAmountWithNotation(
|
|
1874
|
-
// Asset amount
|
|
1875
|
-
new CryptoAmount(baseAmount(depositQuote.expected_amount_out), addAmount.asset), // Convert to base amount
|
|
1876
|
-
assetDecimals),
|
|
1877
|
-
estimatedDepositValue: getCryptoAmountWithNotation(
|
|
1878
|
-
// Estimated deposit value
|
|
1879
|
-
new CryptoAmount(baseAmount(depositQuote.expected_amount_deposit), addAmount.asset), // Convert to base amount
|
|
1880
|
-
assetDecimals),
|
|
1881
|
-
fee: saverFees, // Fees
|
|
1882
|
-
expiry: new Date(depositQuote.expiry), // Expiry date
|
|
1883
|
-
toAddress: depositQuote.inbound_address, // Recipient address
|
|
1884
|
-
memo: depositQuote.memo, // Memo
|
|
1885
|
-
estimatedWaitTime: depositQuote.inbound_confirmation_seconds || 0, // Estimated wait time
|
|
1886
|
-
canAddSaver: errors.length === 0, // Can add saver flag
|
|
1887
|
-
slipBasisPoints: depositQuote.fees.slippage_bps, // Slip basis points
|
|
1888
|
-
saverCapFilledPercent, // Saver filled capacity
|
|
1889
|
-
recommendedMinAmountIn: depositQuote.recommended_min_amount_in, // Recommended minimum amount in
|
|
1890
|
-
errors, // Errors
|
|
1891
|
-
};
|
|
1892
|
-
return estimateAddSaver; // Return the EstimateAddSaver object
|
|
1705
|
+
throw new Error('Saver deposit quotes are no longer available. THORNode removed the /quote/saver/deposit endpoint in API v3.15.0.');
|
|
1893
1706
|
});
|
|
1894
1707
|
}
|
|
1895
1708
|
/**
|
|
1896
|
-
*
|
|
1897
|
-
* @param withdrawParams - Withdrawal parameters including height, asset, address, and withdrawal basis points
|
|
1898
|
-
* @returns - Object of type EstimateWithdrawSaver
|
|
1709
|
+
* @deprecated Saver quote endpoints were removed from THORNode API in v3.15.0
|
|
1899
1710
|
*/
|
|
1900
|
-
estimateWithdrawSaver(
|
|
1711
|
+
estimateWithdrawSaver(_withdrawParams) {
|
|
1901
1712
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1902
|
-
|
|
1903
|
-
// Return error if asset in is incorrect
|
|
1904
|
-
if (isAssetRuneNative(withdrawParams.asset) || isSynthAsset(withdrawParams.asset))
|
|
1905
|
-
errors.push(`Native Rune and synth assets are not supported only L1's`);
|
|
1906
|
-
// Get inbound details
|
|
1907
|
-
const inboundDetails = yield this.thorchainCache.getInboundDetails();
|
|
1908
|
-
// Check if there is a position before calling withdraw quote
|
|
1909
|
-
const checkPositon = yield this.getSaverPosition(withdrawParams);
|
|
1910
|
-
// If there are errors in the position, return those errors
|
|
1911
|
-
if (checkPositon.errors.length > 0) {
|
|
1912
|
-
for (let i = 0; i < checkPositon.errors.length; i++) {
|
|
1913
|
-
errors.push(checkPositon.errors[i]);
|
|
1914
|
-
}
|
|
1915
|
-
return {
|
|
1916
|
-
dustAmount: new AssetCryptoAmount(baseAmount(0), getChainAsset(withdrawParams.asset.chain)), // Dust amount
|
|
1917
|
-
dustThreshold: new AssetCryptoAmount(baseAmount(0), getChainAsset(withdrawParams.asset.chain)), // Dust threshold
|
|
1918
|
-
expectedAssetAmount: new CryptoAmount(// Expected asset amount
|
|
1919
|
-
assetToBase(assetAmount(checkPositon.redeemableValue.assetAmount.amount())), // Convert to base amount
|
|
1920
|
-
withdrawParams.asset),
|
|
1921
|
-
fee: {
|
|
1922
|
-
affiliate: new CryptoAmount(assetToBase(assetAmount(0)), withdrawParams.asset), // Affiliate fee
|
|
1923
|
-
asset: withdrawParams.asset, // Asset
|
|
1924
|
-
liquidity: new CryptoAmount(baseAmount(0), withdrawParams.asset), // Liquidity fee
|
|
1925
|
-
outbound: new CryptoAmount(// Outbound fee
|
|
1926
|
-
assetToBase(assetAmount(calcOutboundFee(withdrawParams.asset, inboundDetails[withdrawParams.asset.chain]).assetAmount.amount())), withdrawParams.asset),
|
|
1927
|
-
totalBps: 0, // Total basis points
|
|
1928
|
-
},
|
|
1929
|
-
expiry: new Date(0), // Expiry date
|
|
1930
|
-
toAddress: '', // Recipient address
|
|
1931
|
-
memo: '', // Memo
|
|
1932
|
-
inboundDelayBlocks: 0, // Number of blocks for inbound delay
|
|
1933
|
-
inboundDelaySeconds: 0, // Number of seconds for inbound delay
|
|
1934
|
-
outBoundDelayBlocks: 0, // Number of blocks for outbound delay
|
|
1935
|
-
outBoundDelaySeconds: 0, // Number of seconds for outbound delay
|
|
1936
|
-
slipBasisPoints: -1, // Slip basis points (negative value indicates no slip)
|
|
1937
|
-
errors, // Errors array
|
|
1938
|
-
};
|
|
1939
|
-
}
|
|
1940
|
-
// Request withdraw quote
|
|
1941
|
-
const withdrawQuote = yield this.thorchainCache.thornode.getSaversWithdrawQuote(withdrawParams);
|
|
1942
|
-
// error handling
|
|
1943
|
-
const response = JSON.parse(JSON.stringify(withdrawQuote));
|
|
1944
|
-
if (response.error)
|
|
1945
|
-
errors.push(`Thornode request quote failed: ${response.error}`);
|
|
1946
|
-
if (errors.length > 0) {
|
|
1947
|
-
// Return default values and errors if there are any errors
|
|
1948
|
-
return {
|
|
1949
|
-
dustAmount: new AssetCryptoAmount(baseAmount(0), getChainAsset(withdrawParams.asset.chain)),
|
|
1950
|
-
dustThreshold: new AssetCryptoAmount(baseAmount(0), getChainAsset(withdrawParams.asset.chain)),
|
|
1951
|
-
expectedAssetAmount: new CryptoAmount(assetToBase(assetAmount(0)), withdrawParams.asset),
|
|
1952
|
-
fee: {
|
|
1953
|
-
affiliate: new CryptoAmount(baseAmount(0), withdrawParams.asset),
|
|
1954
|
-
asset: withdrawParams.asset,
|
|
1955
|
-
liquidity: new CryptoAmount(baseAmount(0), withdrawParams.asset),
|
|
1956
|
-
outbound: new CryptoAmount(baseAmount(0), withdrawParams.asset),
|
|
1957
|
-
totalBps: 0,
|
|
1958
|
-
},
|
|
1959
|
-
expiry: new Date(0),
|
|
1960
|
-
toAddress: '',
|
|
1961
|
-
memo: '',
|
|
1962
|
-
inboundDelayBlocks: 0,
|
|
1963
|
-
inboundDelaySeconds: 0,
|
|
1964
|
-
outBoundDelayBlocks: 0,
|
|
1965
|
-
outBoundDelaySeconds: 0,
|
|
1966
|
-
slipBasisPoints: -1,
|
|
1967
|
-
errors,
|
|
1968
|
-
};
|
|
1969
|
-
}
|
|
1970
|
-
// Extract the withdraw asset and chain asset from the withdraw quote
|
|
1971
|
-
const withdrawAsset = assetFromStringEx(withdrawQuote.fees.asset);
|
|
1972
|
-
const chainAsset = getChainAsset(withdrawParams.asset.chain);
|
|
1973
|
-
// Get the decimals for the withdraw asset and chain asset
|
|
1974
|
-
const withdrawAssetDecimals = yield this.thorchainCache.midgardQuery.getDecimalForAsset(withdrawAsset);
|
|
1975
|
-
const chainAssetDecimals = yield this.thorchainCache.midgardQuery.getDecimalForAsset(chainAsset);
|
|
1976
|
-
// Create an EstimateWithdrawSaver object with the necessary data
|
|
1977
|
-
const estimateWithdrawSaver = {
|
|
1978
|
-
// Format the dust amount with appropriate notation and decimals
|
|
1979
|
-
dustAmount: getCryptoAmountWithNotation(new AssetCryptoAmount(baseAmount(withdrawQuote.dust_amount), chainAsset), chainAssetDecimals),
|
|
1980
|
-
// Format the dust threshold with appropriate notation and decimals
|
|
1981
|
-
dustThreshold: getCryptoAmountWithNotation(new AssetCryptoAmount(baseAmount(withdrawQuote.dust_threshold), chainAsset), chainAssetDecimals),
|
|
1982
|
-
// Format the expected asset amount with appropriate notation and decimals
|
|
1983
|
-
expectedAssetAmount: getCryptoAmountWithNotation(new CryptoAmount(baseAmount(withdrawQuote.expected_amount_out), withdrawParams.asset), withdrawAssetDecimals),
|
|
1984
|
-
// Format the withdrawal fees with appropriate notation and decimals
|
|
1985
|
-
fee: {
|
|
1986
|
-
affiliate: getCryptoAmountWithNotation(new CryptoAmount(baseAmount(withdrawQuote.fees.affiliate), withdrawAsset), withdrawAssetDecimals),
|
|
1987
|
-
asset: withdrawAsset,
|
|
1988
|
-
liquidity: getCryptoAmountWithNotation(new CryptoAmount(baseAmount(withdrawQuote.fees.liquidity), withdrawAsset), withdrawAssetDecimals),
|
|
1989
|
-
outbound: getCryptoAmountWithNotation(new CryptoAmount(baseAmount(withdrawQuote.fees.outbound), withdrawAsset), withdrawAssetDecimals),
|
|
1990
|
-
totalBps: withdrawQuote.fees.total_bps || 0,
|
|
1991
|
-
},
|
|
1992
|
-
// Set the expiry date
|
|
1993
|
-
expiry: new Date(withdrawQuote.expiry),
|
|
1994
|
-
// Set the recipient address
|
|
1995
|
-
toAddress: withdrawQuote.inbound_address,
|
|
1996
|
-
// Set the memo
|
|
1997
|
-
memo: withdrawQuote.memo,
|
|
1998
|
-
// Set the inbound delay blocks
|
|
1999
|
-
inboundDelayBlocks: withdrawQuote.inbound_confirmation_blocks || 0,
|
|
2000
|
-
// Set the inbound delay seconds
|
|
2001
|
-
inboundDelaySeconds: withdrawQuote.inbound_confirmation_seconds || 0,
|
|
2002
|
-
// Set the outbound delay blocks
|
|
2003
|
-
outBoundDelayBlocks: withdrawQuote.outbound_delay_blocks || 0,
|
|
2004
|
-
// Set the outbound delay seconds
|
|
2005
|
-
outBoundDelaySeconds: withdrawQuote.outbound_delay_seconds || 0,
|
|
2006
|
-
// Set the slip basis points
|
|
2007
|
-
slipBasisPoints: withdrawQuote.fees.slippage_bps,
|
|
2008
|
-
// Set the errors
|
|
2009
|
-
errors,
|
|
2010
|
-
};
|
|
2011
|
-
// Return the withdrawal estimation object
|
|
2012
|
-
return estimateWithdrawSaver;
|
|
1713
|
+
throw new Error('Saver withdraw quotes are no longer available. THORNode removed the /quote/saver/withdraw endpoint in API v3.15.0.');
|
|
2013
1714
|
});
|
|
2014
1715
|
}
|
|
2015
1716
|
/**
|
|
@@ -2075,185 +1776,19 @@ class ThorchainQuery {
|
|
|
2075
1776
|
});
|
|
2076
1777
|
}
|
|
2077
1778
|
/**
|
|
2078
|
-
*
|
|
2079
|
-
* @param addAmount - Amount of funds to be added to the saver's pool.
|
|
2080
|
-
* @returns An array of strings representing any errors encountered during the estimation process.
|
|
1779
|
+
* @deprecated Loan endpoints were removed from THORNode API in v3.15.0
|
|
2081
1780
|
*/
|
|
2082
|
-
|
|
1781
|
+
getLoanQuoteOpen(_params) {
|
|
2083
1782
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2084
|
-
|
|
2085
|
-
// Retrieve all pools
|
|
2086
|
-
const pools = yield this.thorchainCache.getPools();
|
|
2087
|
-
// Filter out saver's pools with non-zero depth
|
|
2088
|
-
const saversPools = Object.values(pools).filter((i) => i.thornodeDetails.savers_depth !== '0');
|
|
2089
|
-
// Retrieve inbound details
|
|
2090
|
-
const inboundDetails = yield this.thorchainCache.getInboundDetails();
|
|
2091
|
-
// Find the saver's pool corresponding to the provided asset
|
|
2092
|
-
const saverPool = saversPools.find((i) => assetToString(i.asset) === assetToString(addAmount.asset));
|
|
2093
|
-
// Check if a saver's pool exists for the provided asset
|
|
2094
|
-
if (!saverPool)
|
|
2095
|
-
errors.push(` ${assetToString(addAmount.asset)} does not have a saver's pool`);
|
|
2096
|
-
// Check if the chain for the provided asset is halted
|
|
2097
|
-
if (inboundDetails[addAmount.asset.chain].haltedChain)
|
|
2098
|
-
errors.push(`${addAmount.asset.chain} is halted, cannot add`);
|
|
2099
|
-
// Get details of the pool for the provided asset
|
|
2100
|
-
const pool = (yield this.thorchainCache.getPoolForAsset(addAmount.asset)).thornodeDetails;
|
|
2101
|
-
// Check if the pool for the provided asset is available
|
|
2102
|
-
if (pool.status.toLowerCase() !== 'available')
|
|
2103
|
-
errors.push(`Pool is not available for this asset ${assetToString(addAmount.asset)}`);
|
|
2104
|
-
// Calculate inbound fee for the provided asset
|
|
2105
|
-
const inboundFee = new CryptoAmount(baseAmount(inboundDetails[addAmount.asset.chain].gasRate), addAmount.asset);
|
|
2106
|
-
// Convert inbound fee to the same asset as the addAmount to ensure consistency in calculations
|
|
2107
|
-
const inboundFeeInAddAmountAsset = (yield this.convert(inboundFee, addAmount.asset));
|
|
2108
|
-
// Check if the addAmount covers the inbound fees
|
|
2109
|
-
if (addAmount.lte(inboundFeeInAddAmountAsset))
|
|
2110
|
-
errors.push(`Add amount does not cover fees`);
|
|
2111
|
-
// Return array of errors encountered during estimation
|
|
2112
|
-
return errors;
|
|
2113
|
-
});
|
|
2114
|
-
}
|
|
2115
|
-
/**
|
|
2116
|
-
*
|
|
2117
|
-
* @param loanOpenParams - params needed for the end Point
|
|
2118
|
-
* @returns
|
|
2119
|
-
*/
|
|
2120
|
-
getLoanQuoteOpen(_a) {
|
|
2121
|
-
return __awaiter(this, arguments, void 0, function* ({ asset, amount, targetAsset, destination, minOut, affiliateBps, affiliate, height, }) {
|
|
2122
|
-
const errors = [];
|
|
2123
|
-
const loanOpenResp = yield this.thorchainCache.thornode.getLoanQuoteOpen(`${asset.chain}.${asset.symbol}`, amount.baseAmount.amount().toNumber(), `${targetAsset.chain}.${targetAsset.symbol}`, destination, minOut, affiliateBps, affiliate, height);
|
|
2124
|
-
const response = JSON.parse(JSON.stringify(loanOpenResp));
|
|
2125
|
-
if (response.error)
|
|
2126
|
-
errors.push(`Thornode request quote failed: ${response.error}`);
|
|
2127
|
-
if (loanOpenResp.recommended_min_amount_in &&
|
|
2128
|
-
amount.baseAmount.amount().toNumber() < Number(loanOpenResp.recommended_min_amount_in))
|
|
2129
|
-
errors.push(`Error amount in: ${amount.baseAmount.amount().toNumber()} is less than reccommended Min Amount: ${loanOpenResp.recommended_min_amount_in}`);
|
|
2130
|
-
if (errors.length > 0) {
|
|
2131
|
-
return {
|
|
2132
|
-
inboundAddress: '',
|
|
2133
|
-
expectedWaitTime: {
|
|
2134
|
-
outboundDelayBlocks: undefined,
|
|
2135
|
-
outbondDelaySeconds: undefined,
|
|
2136
|
-
},
|
|
2137
|
-
fees: {
|
|
2138
|
-
asset: '',
|
|
2139
|
-
liquidity: undefined,
|
|
2140
|
-
outbound: undefined,
|
|
2141
|
-
total_bps: undefined,
|
|
2142
|
-
},
|
|
2143
|
-
slippageBps: undefined,
|
|
2144
|
-
router: undefined,
|
|
2145
|
-
expiry: 0,
|
|
2146
|
-
warning: '',
|
|
2147
|
-
notes: '',
|
|
2148
|
-
dustThreshold: undefined,
|
|
2149
|
-
recommendedMinAmountIn: loanOpenResp.recommended_min_amount_in,
|
|
2150
|
-
memo: undefined,
|
|
2151
|
-
expectedAmountOut: '',
|
|
2152
|
-
expectedCollateralizationRatio: '',
|
|
2153
|
-
expectedCollateralDeposited: '',
|
|
2154
|
-
expectedDebtIssued: '',
|
|
2155
|
-
errors: errors,
|
|
2156
|
-
};
|
|
2157
|
-
}
|
|
2158
|
-
const loanOpenQuote = {
|
|
2159
|
-
inboundAddress: loanOpenResp.inbound_address,
|
|
2160
|
-
expectedWaitTime: {
|
|
2161
|
-
outboundDelayBlocks: loanOpenResp.outbound_delay_blocks,
|
|
2162
|
-
outbondDelaySeconds: loanOpenResp.outbound_delay_seconds,
|
|
2163
|
-
},
|
|
2164
|
-
fees: {
|
|
2165
|
-
asset: loanOpenResp.fees.asset,
|
|
2166
|
-
liquidity: loanOpenResp.fees.liquidity,
|
|
2167
|
-
outbound: loanOpenResp.fees.outbound,
|
|
2168
|
-
total_bps: loanOpenResp.fees.total_bps,
|
|
2169
|
-
},
|
|
2170
|
-
slippageBps: loanOpenResp.fees.slippage_bps,
|
|
2171
|
-
router: loanOpenResp.router,
|
|
2172
|
-
expiry: loanOpenResp.expiry,
|
|
2173
|
-
warning: loanOpenResp.warning,
|
|
2174
|
-
notes: loanOpenResp.notes,
|
|
2175
|
-
dustThreshold: loanOpenResp.dust_threshold,
|
|
2176
|
-
recommendedMinAmountIn: loanOpenResp.recommended_min_amount_in,
|
|
2177
|
-
memo: loanOpenResp.memo,
|
|
2178
|
-
expectedAmountOut: loanOpenResp.expected_amount_out,
|
|
2179
|
-
expectedCollateralizationRatio: loanOpenResp.expected_collateralization_ratio,
|
|
2180
|
-
expectedCollateralDeposited: loanOpenResp.expected_collateral_deposited,
|
|
2181
|
-
expectedDebtIssued: loanOpenResp.expected_debt_issued,
|
|
2182
|
-
errors: errors,
|
|
2183
|
-
};
|
|
2184
|
-
return loanOpenQuote;
|
|
1783
|
+
throw new Error('Loan quotes are no longer available. THORNode removed the /quote/loan/open endpoint in API v3.15.0.');
|
|
2185
1784
|
});
|
|
2186
1785
|
}
|
|
2187
1786
|
/**
|
|
2188
|
-
*
|
|
2189
|
-
* @param loanOpenParams - Parameters needed for the endpoint.
|
|
2190
|
-
* @returns A Promise resolving to a LoanOpenQuote.
|
|
1787
|
+
* @deprecated Loan endpoints were removed from THORNode API in v3.15.0
|
|
2191
1788
|
*/
|
|
2192
|
-
getLoanQuoteClose(
|
|
2193
|
-
return __awaiter(this,
|
|
2194
|
-
|
|
2195
|
-
// Retrieve loan open response from ThorNode API
|
|
2196
|
-
const loanCloseResp = yield this.thorchainCache.thornode.getLoanQuoteClose(`${asset.chain}.${asset.symbol}`, amount.baseAmount.amount().toNumber(), `${loanAsset.chain}.${loanAsset.symbol}`, loanOwner, minOut, height);
|
|
2197
|
-
// Parse loan open response
|
|
2198
|
-
const response = JSON.parse(JSON.stringify(loanCloseResp));
|
|
2199
|
-
// Check for errors in response
|
|
2200
|
-
if (response.error)
|
|
2201
|
-
errors.push(`Thornode request quote failed: ${response.error}`);
|
|
2202
|
-
// If errors exist, return an object with error details
|
|
2203
|
-
if (errors.length > 0) {
|
|
2204
|
-
return {
|
|
2205
|
-
inboundAddress: '',
|
|
2206
|
-
expectedWaitTime: {
|
|
2207
|
-
outboundDelayBlocks: undefined,
|
|
2208
|
-
outbondDelaySeconds: undefined,
|
|
2209
|
-
},
|
|
2210
|
-
fees: {
|
|
2211
|
-
asset: '',
|
|
2212
|
-
liquidity: undefined,
|
|
2213
|
-
outbound: undefined,
|
|
2214
|
-
total_bps: undefined,
|
|
2215
|
-
},
|
|
2216
|
-
slippageBps: undefined,
|
|
2217
|
-
router: undefined,
|
|
2218
|
-
expiry: 0,
|
|
2219
|
-
warning: '',
|
|
2220
|
-
notes: '',
|
|
2221
|
-
dustThreshold: undefined,
|
|
2222
|
-
recommendedMinAmountIn: loanCloseResp.recommended_min_amount_in,
|
|
2223
|
-
memo: undefined,
|
|
2224
|
-
expectedAmountOut: '',
|
|
2225
|
-
expectedCollateralWithdrawn: '',
|
|
2226
|
-
expectedDebtRepaid: '',
|
|
2227
|
-
errors: errors,
|
|
2228
|
-
};
|
|
2229
|
-
}
|
|
2230
|
-
// Construct loan open quote object
|
|
2231
|
-
const loanCloseQuote = {
|
|
2232
|
-
inboundAddress: loanCloseResp.inbound_address,
|
|
2233
|
-
expectedWaitTime: {
|
|
2234
|
-
outboundDelayBlocks: loanCloseResp.outbound_delay_blocks,
|
|
2235
|
-
outbondDelaySeconds: loanCloseResp.outbound_delay_seconds,
|
|
2236
|
-
},
|
|
2237
|
-
fees: {
|
|
2238
|
-
asset: loanCloseResp.fees.asset,
|
|
2239
|
-
liquidity: loanCloseResp.fees.liquidity,
|
|
2240
|
-
outbound: loanCloseResp.fees.outbound,
|
|
2241
|
-
total_bps: loanCloseResp.fees.total_bps,
|
|
2242
|
-
},
|
|
2243
|
-
slippageBps: loanCloseResp.fees.slippage_bps,
|
|
2244
|
-
router: loanCloseResp.router,
|
|
2245
|
-
expiry: loanCloseResp.expiry,
|
|
2246
|
-
warning: loanCloseResp.warning,
|
|
2247
|
-
notes: loanCloseResp.notes,
|
|
2248
|
-
dustThreshold: loanCloseResp.dust_threshold,
|
|
2249
|
-
recommendedMinAmountIn: loanCloseResp.recommended_min_amount_in,
|
|
2250
|
-
memo: loanCloseResp.memo,
|
|
2251
|
-
expectedAmountOut: loanCloseResp.expected_amount_out,
|
|
2252
|
-
expectedCollateralWithdrawn: loanCloseResp.expected_collateral_withdrawn,
|
|
2253
|
-
expectedDebtRepaid: loanCloseResp.expected_debt_repaid,
|
|
2254
|
-
errors: errors,
|
|
2255
|
-
};
|
|
2256
|
-
return loanCloseQuote;
|
|
1789
|
+
getLoanQuoteClose(_params) {
|
|
1790
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1791
|
+
throw new Error('Loan quotes are no longer available. THORNode removed the /quote/loan/close endpoint in API v3.15.0.');
|
|
2257
1792
|
});
|
|
2258
1793
|
}
|
|
2259
1794
|
/**
|
|
@@ -3073,7 +2608,6 @@ class TransactionStage {
|
|
|
3073
2608
|
const asset = assetFromStringEx(txData.tx.tx.coins[0].asset);
|
|
3074
2609
|
const toAddress = `${txData.tx.tx.to_address}`;
|
|
3075
2610
|
const currentHeight = lastBlockObj.find((obj) => obj.chain === asset.chain);
|
|
3076
|
-
console.log(currentHeight);
|
|
3077
2611
|
// Extract relevant block heights and calculate estimated wait time
|
|
3078
2612
|
const outboundBlock = Number(`${currentHeight === null || currentHeight === void 0 ? void 0 : currentHeight.last_observed_in}`);
|
|
3079
2613
|
const finalisedHeight = Number(txData.finalised_height);
|
package/lib/index.js
CHANGED
|
@@ -737,49 +737,6 @@ class Thornode {
|
|
|
737
737
|
throw new Error(`THORNode not responding`);
|
|
738
738
|
});
|
|
739
739
|
}
|
|
740
|
-
/**
|
|
741
|
-
*
|
|
742
|
-
* @param asset - asset to add to savers
|
|
743
|
-
* @param amount - amount to deposit
|
|
744
|
-
* @param height - block height
|
|
745
|
-
* @returns quotes deposit object response
|
|
746
|
-
*/
|
|
747
|
-
getSaversDepositQuote(asset, amount, height) {
|
|
748
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
749
|
-
for (const api of this.quoteApi) {
|
|
750
|
-
try {
|
|
751
|
-
const resp = (yield api.quotesaverdeposit(height, asset, amount)).data;
|
|
752
|
-
return resp;
|
|
753
|
-
}
|
|
754
|
-
catch (_e) {
|
|
755
|
-
//console.error(_e)
|
|
756
|
-
}
|
|
757
|
-
}
|
|
758
|
-
throw new Error(`THORNode not responding`);
|
|
759
|
-
});
|
|
760
|
-
}
|
|
761
|
-
/**
|
|
762
|
-
*
|
|
763
|
-
* @param asset - asset to withdraw
|
|
764
|
-
* @param address - savers address
|
|
765
|
-
* @param height - block height
|
|
766
|
-
* @param withdrawBps - withddraw percent
|
|
767
|
-
* @returns quotes withdraw object response
|
|
768
|
-
*/
|
|
769
|
-
getSaversWithdrawQuote(withdrawParams) {
|
|
770
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
771
|
-
for (const api of this.quoteApi) {
|
|
772
|
-
try {
|
|
773
|
-
const resp = yield api.quotesaverwithdraw(withdrawParams.height, `${withdrawParams.asset.chain}.${withdrawParams.asset.symbol}`, withdrawParams.address, withdrawParams.withdrawBps);
|
|
774
|
-
return resp.data;
|
|
775
|
-
}
|
|
776
|
-
catch (_e) {
|
|
777
|
-
//console.error(_e)
|
|
778
|
-
}
|
|
779
|
-
}
|
|
780
|
-
throw new Error(`THORNode not responding`);
|
|
781
|
-
});
|
|
782
|
-
}
|
|
783
740
|
/**
|
|
784
741
|
*
|
|
785
742
|
* @param fromAsset - input asset
|
|
@@ -806,58 +763,6 @@ class Thornode {
|
|
|
806
763
|
throw new Error(`THORNode not responding`);
|
|
807
764
|
});
|
|
808
765
|
}
|
|
809
|
-
/**
|
|
810
|
-
*
|
|
811
|
-
* @param height
|
|
812
|
-
* @param asset
|
|
813
|
-
* @param amount
|
|
814
|
-
* @param targetAsset
|
|
815
|
-
* @param destination
|
|
816
|
-
* @param minOut
|
|
817
|
-
* @param affiliateBps
|
|
818
|
-
* @param affiliate
|
|
819
|
-
* @returns
|
|
820
|
-
*/
|
|
821
|
-
getLoanQuoteOpen(asset, amount, targetAsset, destination, minOut, affiliateBps, affiliate, height) {
|
|
822
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
823
|
-
for (const api of this.quoteApi) {
|
|
824
|
-
try {
|
|
825
|
-
const resp = (yield api.quoteloanopen(height, asset, amount, targetAsset, destination, minOut, affiliateBps, affiliate)).data;
|
|
826
|
-
return resp;
|
|
827
|
-
}
|
|
828
|
-
catch (_e) {
|
|
829
|
-
//console.log(_e)
|
|
830
|
-
}
|
|
831
|
-
}
|
|
832
|
-
throw new Error(`THORNode is not responding`);
|
|
833
|
-
});
|
|
834
|
-
}
|
|
835
|
-
/**
|
|
836
|
-
*
|
|
837
|
-
* @param height
|
|
838
|
-
* @param asset
|
|
839
|
-
* @param amount
|
|
840
|
-
* @param targetAsset
|
|
841
|
-
* @param destination
|
|
842
|
-
* @param minOut
|
|
843
|
-
* @param affiliateBps
|
|
844
|
-
* @param affiliate
|
|
845
|
-
* @returns
|
|
846
|
-
*/
|
|
847
|
-
getLoanQuoteClose(asset, amount, loanAsset, loanOwner, minOut, height) {
|
|
848
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
849
|
-
for (const api of this.quoteApi) {
|
|
850
|
-
try {
|
|
851
|
-
const resp = (yield api.quoteloanclose(height, asset, amount, loanAsset, loanOwner, minOut)).data;
|
|
852
|
-
return resp;
|
|
853
|
-
}
|
|
854
|
-
catch (_e) {
|
|
855
|
-
// console.log(_e)
|
|
856
|
-
}
|
|
857
|
-
}
|
|
858
|
-
throw new Error(`THORNode is not responding`);
|
|
859
|
-
});
|
|
860
|
-
}
|
|
861
766
|
getThornameDetails(thorname, height) {
|
|
862
767
|
return __awaiter(this, void 0, void 0, function* () {
|
|
863
768
|
for (const api of this.thornamesApi) {
|
|
@@ -1800,224 +1705,20 @@ class ThorchainQuery {
|
|
|
1800
1705
|
});
|
|
1801
1706
|
}
|
|
1802
1707
|
// Savers Queries
|
|
1803
|
-
// Derrived from https://dev.thorchain.org/thorchain-dev/connection-guide/savers-guide
|
|
1804
1708
|
/**
|
|
1805
|
-
*
|
|
1806
|
-
* @param addAmount - The amount to be added to the saver
|
|
1807
|
-
* @returns - Object of type EstimateAddSaver
|
|
1709
|
+
* @deprecated Saver quote endpoints were removed from THORNode API in v3.15.0
|
|
1808
1710
|
*/
|
|
1809
|
-
estimateAddSaver(
|
|
1711
|
+
estimateAddSaver(_addAmount) {
|
|
1810
1712
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1811
|
-
|
|
1812
|
-
// Check for errors before sending quote
|
|
1813
|
-
errors = yield this.getAddSaversEstimateErrors(addAmount);
|
|
1814
|
-
// Request parameter amount should always be in 1e8
|
|
1815
|
-
// Adjust decimals if chain decimals != 8
|
|
1816
|
-
const newAddAmount = addAmount.baseAmount.decimal != 8 ? getBaseAmountWithDiffDecimals(addAmount, 8) : addAmount.baseAmount.amount();
|
|
1817
|
-
// Fetch quote
|
|
1818
|
-
const depositQuote = yield this.thorchainCache.thornode.getSaversDepositQuote(xchainUtil.assetToString(addAmount.asset), // Convert asset to string
|
|
1819
|
-
newAddAmount.toNumber());
|
|
1820
|
-
// Error handling
|
|
1821
|
-
const response = JSON.parse(JSON.stringify(depositQuote));
|
|
1822
|
-
if (response.error)
|
|
1823
|
-
errors.push(`Thornode request quote failed: ${response.error}`); // Push error to array if exists
|
|
1824
|
-
// The recommended minimum inbound amount for this transaction type & inbound asset.
|
|
1825
|
-
// Sending less than this amount could result in failed refunds
|
|
1826
|
-
if (depositQuote.recommended_min_amount_in &&
|
|
1827
|
-
addAmount.baseAmount.amount().toNumber() < Number(depositQuote.recommended_min_amount_in))
|
|
1828
|
-
errors.push(`Error amount in: ${addAmount.baseAmount.amount().toNumber()} is less than recommended Min Amount: ${depositQuote.recommended_min_amount_in}`);
|
|
1829
|
-
// Return errors if there is any
|
|
1830
|
-
if (errors.length > 0) {
|
|
1831
|
-
// Return an object with default values and errors
|
|
1832
|
-
return {
|
|
1833
|
-
assetAmount: addAmount,
|
|
1834
|
-
estimatedDepositValue: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(0), addAmount.asset),
|
|
1835
|
-
fee: {
|
|
1836
|
-
affiliate: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(0), addAmount.asset),
|
|
1837
|
-
asset: addAmount.asset,
|
|
1838
|
-
outbound: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(0), addAmount.asset),
|
|
1839
|
-
liquidity: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(0), addAmount.asset),
|
|
1840
|
-
totalBps: depositQuote.fees.total_bps || 0,
|
|
1841
|
-
},
|
|
1842
|
-
expiry: new Date(0),
|
|
1843
|
-
toAddress: '',
|
|
1844
|
-
memo: '',
|
|
1845
|
-
saverCapFilledPercent: -1,
|
|
1846
|
-
estimatedWaitTime: -1,
|
|
1847
|
-
slipBasisPoints: -1,
|
|
1848
|
-
recommendedMinAmountIn: depositQuote.recommended_min_amount_in,
|
|
1849
|
-
canAddSaver: false,
|
|
1850
|
-
errors, // Errors
|
|
1851
|
-
};
|
|
1852
|
-
}
|
|
1853
|
-
// Get pool details
|
|
1854
|
-
const pool = (yield this.thorchainCache.getPoolForAsset(addAmount.asset)).thornodeDetails;
|
|
1855
|
-
// Get asset decimals
|
|
1856
|
-
const assetDecimals = yield this.thorchainCache.midgardQuery.getDecimalForAsset(addAmount.asset);
|
|
1857
|
-
// Get fee asset decimals
|
|
1858
|
-
const feeAssetDecimals = yield this.thorchainCache.midgardQuery.getDecimalForAsset(addAmount.asset);
|
|
1859
|
-
// Organize fees
|
|
1860
|
-
const feeAsset = xchainUtil.assetFromStringEx(depositQuote.fees.asset);
|
|
1861
|
-
const saverFees = {
|
|
1862
|
-
affiliate: getCryptoAmountWithNotation(
|
|
1863
|
-
// Affiliate fee
|
|
1864
|
-
new xchainUtil.CryptoAmount(xchainUtil.baseAmount(depositQuote.fees.affiliate), addAmount.asset), // Convert to base amount
|
|
1865
|
-
assetDecimals),
|
|
1866
|
-
asset: feeAsset, // Asset fee
|
|
1867
|
-
outbound: getCryptoAmountWithNotation(
|
|
1868
|
-
// Outbound fee
|
|
1869
|
-
new xchainUtil.CryptoAmount(xchainUtil.baseAmount(depositQuote.fees.outbound), feeAsset), // Convert to base amount
|
|
1870
|
-
feeAssetDecimals),
|
|
1871
|
-
liquidity: getCryptoAmountWithNotation(
|
|
1872
|
-
// Liquidity fee
|
|
1873
|
-
new xchainUtil.CryptoAmount(xchainUtil.baseAmount(depositQuote.fees.liquidity), feeAsset), // Convert to base amount
|
|
1874
|
-
feeAssetDecimals),
|
|
1875
|
-
totalBps: depositQuote.fees.total_bps || 0, // Total basis points
|
|
1876
|
-
};
|
|
1877
|
-
// Define saver filled capacity
|
|
1878
|
-
const saverCapFilledPercent = (Number(pool.synth_supply) / Number(pool.balance_asset)) * 100;
|
|
1879
|
-
// Return object
|
|
1880
|
-
const estimateAddSaver = {
|
|
1881
|
-
assetAmount: getCryptoAmountWithNotation(
|
|
1882
|
-
// Asset amount
|
|
1883
|
-
new xchainUtil.CryptoAmount(xchainUtil.baseAmount(depositQuote.expected_amount_out), addAmount.asset), // Convert to base amount
|
|
1884
|
-
assetDecimals),
|
|
1885
|
-
estimatedDepositValue: getCryptoAmountWithNotation(
|
|
1886
|
-
// Estimated deposit value
|
|
1887
|
-
new xchainUtil.CryptoAmount(xchainUtil.baseAmount(depositQuote.expected_amount_deposit), addAmount.asset), // Convert to base amount
|
|
1888
|
-
assetDecimals),
|
|
1889
|
-
fee: saverFees, // Fees
|
|
1890
|
-
expiry: new Date(depositQuote.expiry), // Expiry date
|
|
1891
|
-
toAddress: depositQuote.inbound_address, // Recipient address
|
|
1892
|
-
memo: depositQuote.memo, // Memo
|
|
1893
|
-
estimatedWaitTime: depositQuote.inbound_confirmation_seconds || 0, // Estimated wait time
|
|
1894
|
-
canAddSaver: errors.length === 0, // Can add saver flag
|
|
1895
|
-
slipBasisPoints: depositQuote.fees.slippage_bps, // Slip basis points
|
|
1896
|
-
saverCapFilledPercent, // Saver filled capacity
|
|
1897
|
-
recommendedMinAmountIn: depositQuote.recommended_min_amount_in, // Recommended minimum amount in
|
|
1898
|
-
errors, // Errors
|
|
1899
|
-
};
|
|
1900
|
-
return estimateAddSaver; // Return the EstimateAddSaver object
|
|
1713
|
+
throw new Error('Saver deposit quotes are no longer available. THORNode removed the /quote/saver/deposit endpoint in API v3.15.0.');
|
|
1901
1714
|
});
|
|
1902
1715
|
}
|
|
1903
1716
|
/**
|
|
1904
|
-
*
|
|
1905
|
-
* @param withdrawParams - Withdrawal parameters including height, asset, address, and withdrawal basis points
|
|
1906
|
-
* @returns - Object of type EstimateWithdrawSaver
|
|
1717
|
+
* @deprecated Saver quote endpoints were removed from THORNode API in v3.15.0
|
|
1907
1718
|
*/
|
|
1908
|
-
estimateWithdrawSaver(
|
|
1719
|
+
estimateWithdrawSaver(_withdrawParams) {
|
|
1909
1720
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1910
|
-
|
|
1911
|
-
// Return error if asset in is incorrect
|
|
1912
|
-
if (isAssetRuneNative(withdrawParams.asset) || xchainUtil.isSynthAsset(withdrawParams.asset))
|
|
1913
|
-
errors.push(`Native Rune and synth assets are not supported only L1's`);
|
|
1914
|
-
// Get inbound details
|
|
1915
|
-
const inboundDetails = yield this.thorchainCache.getInboundDetails();
|
|
1916
|
-
// Check if there is a position before calling withdraw quote
|
|
1917
|
-
const checkPositon = yield this.getSaverPosition(withdrawParams);
|
|
1918
|
-
// If there are errors in the position, return those errors
|
|
1919
|
-
if (checkPositon.errors.length > 0) {
|
|
1920
|
-
for (let i = 0; i < checkPositon.errors.length; i++) {
|
|
1921
|
-
errors.push(checkPositon.errors[i]);
|
|
1922
|
-
}
|
|
1923
|
-
return {
|
|
1924
|
-
dustAmount: new xchainUtil.AssetCryptoAmount(xchainUtil.baseAmount(0), getChainAsset(withdrawParams.asset.chain)), // Dust amount
|
|
1925
|
-
dustThreshold: new xchainUtil.AssetCryptoAmount(xchainUtil.baseAmount(0), getChainAsset(withdrawParams.asset.chain)), // Dust threshold
|
|
1926
|
-
expectedAssetAmount: new xchainUtil.CryptoAmount(// Expected asset amount
|
|
1927
|
-
xchainUtil.assetToBase(xchainUtil.assetAmount(checkPositon.redeemableValue.assetAmount.amount())), // Convert to base amount
|
|
1928
|
-
withdrawParams.asset),
|
|
1929
|
-
fee: {
|
|
1930
|
-
affiliate: new xchainUtil.CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), withdrawParams.asset), // Affiliate fee
|
|
1931
|
-
asset: withdrawParams.asset, // Asset
|
|
1932
|
-
liquidity: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(0), withdrawParams.asset), // Liquidity fee
|
|
1933
|
-
outbound: new xchainUtil.CryptoAmount(// Outbound fee
|
|
1934
|
-
xchainUtil.assetToBase(xchainUtil.assetAmount(calcOutboundFee(withdrawParams.asset, inboundDetails[withdrawParams.asset.chain]).assetAmount.amount())), withdrawParams.asset),
|
|
1935
|
-
totalBps: 0, // Total basis points
|
|
1936
|
-
},
|
|
1937
|
-
expiry: new Date(0), // Expiry date
|
|
1938
|
-
toAddress: '', // Recipient address
|
|
1939
|
-
memo: '', // Memo
|
|
1940
|
-
inboundDelayBlocks: 0, // Number of blocks for inbound delay
|
|
1941
|
-
inboundDelaySeconds: 0, // Number of seconds for inbound delay
|
|
1942
|
-
outBoundDelayBlocks: 0, // Number of blocks for outbound delay
|
|
1943
|
-
outBoundDelaySeconds: 0, // Number of seconds for outbound delay
|
|
1944
|
-
slipBasisPoints: -1, // Slip basis points (negative value indicates no slip)
|
|
1945
|
-
errors, // Errors array
|
|
1946
|
-
};
|
|
1947
|
-
}
|
|
1948
|
-
// Request withdraw quote
|
|
1949
|
-
const withdrawQuote = yield this.thorchainCache.thornode.getSaversWithdrawQuote(withdrawParams);
|
|
1950
|
-
// error handling
|
|
1951
|
-
const response = JSON.parse(JSON.stringify(withdrawQuote));
|
|
1952
|
-
if (response.error)
|
|
1953
|
-
errors.push(`Thornode request quote failed: ${response.error}`);
|
|
1954
|
-
if (errors.length > 0) {
|
|
1955
|
-
// Return default values and errors if there are any errors
|
|
1956
|
-
return {
|
|
1957
|
-
dustAmount: new xchainUtil.AssetCryptoAmount(xchainUtil.baseAmount(0), getChainAsset(withdrawParams.asset.chain)),
|
|
1958
|
-
dustThreshold: new xchainUtil.AssetCryptoAmount(xchainUtil.baseAmount(0), getChainAsset(withdrawParams.asset.chain)),
|
|
1959
|
-
expectedAssetAmount: new xchainUtil.CryptoAmount(xchainUtil.assetToBase(xchainUtil.assetAmount(0)), withdrawParams.asset),
|
|
1960
|
-
fee: {
|
|
1961
|
-
affiliate: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(0), withdrawParams.asset),
|
|
1962
|
-
asset: withdrawParams.asset,
|
|
1963
|
-
liquidity: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(0), withdrawParams.asset),
|
|
1964
|
-
outbound: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(0), withdrawParams.asset),
|
|
1965
|
-
totalBps: 0,
|
|
1966
|
-
},
|
|
1967
|
-
expiry: new Date(0),
|
|
1968
|
-
toAddress: '',
|
|
1969
|
-
memo: '',
|
|
1970
|
-
inboundDelayBlocks: 0,
|
|
1971
|
-
inboundDelaySeconds: 0,
|
|
1972
|
-
outBoundDelayBlocks: 0,
|
|
1973
|
-
outBoundDelaySeconds: 0,
|
|
1974
|
-
slipBasisPoints: -1,
|
|
1975
|
-
errors,
|
|
1976
|
-
};
|
|
1977
|
-
}
|
|
1978
|
-
// Extract the withdraw asset and chain asset from the withdraw quote
|
|
1979
|
-
const withdrawAsset = xchainUtil.assetFromStringEx(withdrawQuote.fees.asset);
|
|
1980
|
-
const chainAsset = getChainAsset(withdrawParams.asset.chain);
|
|
1981
|
-
// Get the decimals for the withdraw asset and chain asset
|
|
1982
|
-
const withdrawAssetDecimals = yield this.thorchainCache.midgardQuery.getDecimalForAsset(withdrawAsset);
|
|
1983
|
-
const chainAssetDecimals = yield this.thorchainCache.midgardQuery.getDecimalForAsset(chainAsset);
|
|
1984
|
-
// Create an EstimateWithdrawSaver object with the necessary data
|
|
1985
|
-
const estimateWithdrawSaver = {
|
|
1986
|
-
// Format the dust amount with appropriate notation and decimals
|
|
1987
|
-
dustAmount: getCryptoAmountWithNotation(new xchainUtil.AssetCryptoAmount(xchainUtil.baseAmount(withdrawQuote.dust_amount), chainAsset), chainAssetDecimals),
|
|
1988
|
-
// Format the dust threshold with appropriate notation and decimals
|
|
1989
|
-
dustThreshold: getCryptoAmountWithNotation(new xchainUtil.AssetCryptoAmount(xchainUtil.baseAmount(withdrawQuote.dust_threshold), chainAsset), chainAssetDecimals),
|
|
1990
|
-
// Format the expected asset amount with appropriate notation and decimals
|
|
1991
|
-
expectedAssetAmount: getCryptoAmountWithNotation(new xchainUtil.CryptoAmount(xchainUtil.baseAmount(withdrawQuote.expected_amount_out), withdrawParams.asset), withdrawAssetDecimals),
|
|
1992
|
-
// Format the withdrawal fees with appropriate notation and decimals
|
|
1993
|
-
fee: {
|
|
1994
|
-
affiliate: getCryptoAmountWithNotation(new xchainUtil.CryptoAmount(xchainUtil.baseAmount(withdrawQuote.fees.affiliate), withdrawAsset), withdrawAssetDecimals),
|
|
1995
|
-
asset: withdrawAsset,
|
|
1996
|
-
liquidity: getCryptoAmountWithNotation(new xchainUtil.CryptoAmount(xchainUtil.baseAmount(withdrawQuote.fees.liquidity), withdrawAsset), withdrawAssetDecimals),
|
|
1997
|
-
outbound: getCryptoAmountWithNotation(new xchainUtil.CryptoAmount(xchainUtil.baseAmount(withdrawQuote.fees.outbound), withdrawAsset), withdrawAssetDecimals),
|
|
1998
|
-
totalBps: withdrawQuote.fees.total_bps || 0,
|
|
1999
|
-
},
|
|
2000
|
-
// Set the expiry date
|
|
2001
|
-
expiry: new Date(withdrawQuote.expiry),
|
|
2002
|
-
// Set the recipient address
|
|
2003
|
-
toAddress: withdrawQuote.inbound_address,
|
|
2004
|
-
// Set the memo
|
|
2005
|
-
memo: withdrawQuote.memo,
|
|
2006
|
-
// Set the inbound delay blocks
|
|
2007
|
-
inboundDelayBlocks: withdrawQuote.inbound_confirmation_blocks || 0,
|
|
2008
|
-
// Set the inbound delay seconds
|
|
2009
|
-
inboundDelaySeconds: withdrawQuote.inbound_confirmation_seconds || 0,
|
|
2010
|
-
// Set the outbound delay blocks
|
|
2011
|
-
outBoundDelayBlocks: withdrawQuote.outbound_delay_blocks || 0,
|
|
2012
|
-
// Set the outbound delay seconds
|
|
2013
|
-
outBoundDelaySeconds: withdrawQuote.outbound_delay_seconds || 0,
|
|
2014
|
-
// Set the slip basis points
|
|
2015
|
-
slipBasisPoints: withdrawQuote.fees.slippage_bps,
|
|
2016
|
-
// Set the errors
|
|
2017
|
-
errors,
|
|
2018
|
-
};
|
|
2019
|
-
// Return the withdrawal estimation object
|
|
2020
|
-
return estimateWithdrawSaver;
|
|
1721
|
+
throw new Error('Saver withdraw quotes are no longer available. THORNode removed the /quote/saver/withdraw endpoint in API v3.15.0.');
|
|
2021
1722
|
});
|
|
2022
1723
|
}
|
|
2023
1724
|
/**
|
|
@@ -2083,185 +1784,19 @@ class ThorchainQuery {
|
|
|
2083
1784
|
});
|
|
2084
1785
|
}
|
|
2085
1786
|
/**
|
|
2086
|
-
*
|
|
2087
|
-
* @param addAmount - Amount of funds to be added to the saver's pool.
|
|
2088
|
-
* @returns An array of strings representing any errors encountered during the estimation process.
|
|
1787
|
+
* @deprecated Loan endpoints were removed from THORNode API in v3.15.0
|
|
2089
1788
|
*/
|
|
2090
|
-
|
|
1789
|
+
getLoanQuoteOpen(_params) {
|
|
2091
1790
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2092
|
-
|
|
2093
|
-
// Retrieve all pools
|
|
2094
|
-
const pools = yield this.thorchainCache.getPools();
|
|
2095
|
-
// Filter out saver's pools with non-zero depth
|
|
2096
|
-
const saversPools = Object.values(pools).filter((i) => i.thornodeDetails.savers_depth !== '0');
|
|
2097
|
-
// Retrieve inbound details
|
|
2098
|
-
const inboundDetails = yield this.thorchainCache.getInboundDetails();
|
|
2099
|
-
// Find the saver's pool corresponding to the provided asset
|
|
2100
|
-
const saverPool = saversPools.find((i) => xchainUtil.assetToString(i.asset) === xchainUtil.assetToString(addAmount.asset));
|
|
2101
|
-
// Check if a saver's pool exists for the provided asset
|
|
2102
|
-
if (!saverPool)
|
|
2103
|
-
errors.push(` ${xchainUtil.assetToString(addAmount.asset)} does not have a saver's pool`);
|
|
2104
|
-
// Check if the chain for the provided asset is halted
|
|
2105
|
-
if (inboundDetails[addAmount.asset.chain].haltedChain)
|
|
2106
|
-
errors.push(`${addAmount.asset.chain} is halted, cannot add`);
|
|
2107
|
-
// Get details of the pool for the provided asset
|
|
2108
|
-
const pool = (yield this.thorchainCache.getPoolForAsset(addAmount.asset)).thornodeDetails;
|
|
2109
|
-
// Check if the pool for the provided asset is available
|
|
2110
|
-
if (pool.status.toLowerCase() !== 'available')
|
|
2111
|
-
errors.push(`Pool is not available for this asset ${xchainUtil.assetToString(addAmount.asset)}`);
|
|
2112
|
-
// Calculate inbound fee for the provided asset
|
|
2113
|
-
const inboundFee = new xchainUtil.CryptoAmount(xchainUtil.baseAmount(inboundDetails[addAmount.asset.chain].gasRate), addAmount.asset);
|
|
2114
|
-
// Convert inbound fee to the same asset as the addAmount to ensure consistency in calculations
|
|
2115
|
-
const inboundFeeInAddAmountAsset = (yield this.convert(inboundFee, addAmount.asset));
|
|
2116
|
-
// Check if the addAmount covers the inbound fees
|
|
2117
|
-
if (addAmount.lte(inboundFeeInAddAmountAsset))
|
|
2118
|
-
errors.push(`Add amount does not cover fees`);
|
|
2119
|
-
// Return array of errors encountered during estimation
|
|
2120
|
-
return errors;
|
|
2121
|
-
});
|
|
2122
|
-
}
|
|
2123
|
-
/**
|
|
2124
|
-
*
|
|
2125
|
-
* @param loanOpenParams - params needed for the end Point
|
|
2126
|
-
* @returns
|
|
2127
|
-
*/
|
|
2128
|
-
getLoanQuoteOpen(_a) {
|
|
2129
|
-
return __awaiter(this, arguments, void 0, function* ({ asset, amount, targetAsset, destination, minOut, affiliateBps, affiliate, height, }) {
|
|
2130
|
-
const errors = [];
|
|
2131
|
-
const loanOpenResp = yield this.thorchainCache.thornode.getLoanQuoteOpen(`${asset.chain}.${asset.symbol}`, amount.baseAmount.amount().toNumber(), `${targetAsset.chain}.${targetAsset.symbol}`, destination, minOut, affiliateBps, affiliate, height);
|
|
2132
|
-
const response = JSON.parse(JSON.stringify(loanOpenResp));
|
|
2133
|
-
if (response.error)
|
|
2134
|
-
errors.push(`Thornode request quote failed: ${response.error}`);
|
|
2135
|
-
if (loanOpenResp.recommended_min_amount_in &&
|
|
2136
|
-
amount.baseAmount.amount().toNumber() < Number(loanOpenResp.recommended_min_amount_in))
|
|
2137
|
-
errors.push(`Error amount in: ${amount.baseAmount.amount().toNumber()} is less than reccommended Min Amount: ${loanOpenResp.recommended_min_amount_in}`);
|
|
2138
|
-
if (errors.length > 0) {
|
|
2139
|
-
return {
|
|
2140
|
-
inboundAddress: '',
|
|
2141
|
-
expectedWaitTime: {
|
|
2142
|
-
outboundDelayBlocks: undefined,
|
|
2143
|
-
outbondDelaySeconds: undefined,
|
|
2144
|
-
},
|
|
2145
|
-
fees: {
|
|
2146
|
-
asset: '',
|
|
2147
|
-
liquidity: undefined,
|
|
2148
|
-
outbound: undefined,
|
|
2149
|
-
total_bps: undefined,
|
|
2150
|
-
},
|
|
2151
|
-
slippageBps: undefined,
|
|
2152
|
-
router: undefined,
|
|
2153
|
-
expiry: 0,
|
|
2154
|
-
warning: '',
|
|
2155
|
-
notes: '',
|
|
2156
|
-
dustThreshold: undefined,
|
|
2157
|
-
recommendedMinAmountIn: loanOpenResp.recommended_min_amount_in,
|
|
2158
|
-
memo: undefined,
|
|
2159
|
-
expectedAmountOut: '',
|
|
2160
|
-
expectedCollateralizationRatio: '',
|
|
2161
|
-
expectedCollateralDeposited: '',
|
|
2162
|
-
expectedDebtIssued: '',
|
|
2163
|
-
errors: errors,
|
|
2164
|
-
};
|
|
2165
|
-
}
|
|
2166
|
-
const loanOpenQuote = {
|
|
2167
|
-
inboundAddress: loanOpenResp.inbound_address,
|
|
2168
|
-
expectedWaitTime: {
|
|
2169
|
-
outboundDelayBlocks: loanOpenResp.outbound_delay_blocks,
|
|
2170
|
-
outbondDelaySeconds: loanOpenResp.outbound_delay_seconds,
|
|
2171
|
-
},
|
|
2172
|
-
fees: {
|
|
2173
|
-
asset: loanOpenResp.fees.asset,
|
|
2174
|
-
liquidity: loanOpenResp.fees.liquidity,
|
|
2175
|
-
outbound: loanOpenResp.fees.outbound,
|
|
2176
|
-
total_bps: loanOpenResp.fees.total_bps,
|
|
2177
|
-
},
|
|
2178
|
-
slippageBps: loanOpenResp.fees.slippage_bps,
|
|
2179
|
-
router: loanOpenResp.router,
|
|
2180
|
-
expiry: loanOpenResp.expiry,
|
|
2181
|
-
warning: loanOpenResp.warning,
|
|
2182
|
-
notes: loanOpenResp.notes,
|
|
2183
|
-
dustThreshold: loanOpenResp.dust_threshold,
|
|
2184
|
-
recommendedMinAmountIn: loanOpenResp.recommended_min_amount_in,
|
|
2185
|
-
memo: loanOpenResp.memo,
|
|
2186
|
-
expectedAmountOut: loanOpenResp.expected_amount_out,
|
|
2187
|
-
expectedCollateralizationRatio: loanOpenResp.expected_collateralization_ratio,
|
|
2188
|
-
expectedCollateralDeposited: loanOpenResp.expected_collateral_deposited,
|
|
2189
|
-
expectedDebtIssued: loanOpenResp.expected_debt_issued,
|
|
2190
|
-
errors: errors,
|
|
2191
|
-
};
|
|
2192
|
-
return loanOpenQuote;
|
|
1791
|
+
throw new Error('Loan quotes are no longer available. THORNode removed the /quote/loan/open endpoint in API v3.15.0.');
|
|
2193
1792
|
});
|
|
2194
1793
|
}
|
|
2195
1794
|
/**
|
|
2196
|
-
*
|
|
2197
|
-
* @param loanOpenParams - Parameters needed for the endpoint.
|
|
2198
|
-
* @returns A Promise resolving to a LoanOpenQuote.
|
|
1795
|
+
* @deprecated Loan endpoints were removed from THORNode API in v3.15.0
|
|
2199
1796
|
*/
|
|
2200
|
-
getLoanQuoteClose(
|
|
2201
|
-
return __awaiter(this,
|
|
2202
|
-
|
|
2203
|
-
// Retrieve loan open response from ThorNode API
|
|
2204
|
-
const loanCloseResp = yield this.thorchainCache.thornode.getLoanQuoteClose(`${asset.chain}.${asset.symbol}`, amount.baseAmount.amount().toNumber(), `${loanAsset.chain}.${loanAsset.symbol}`, loanOwner, minOut, height);
|
|
2205
|
-
// Parse loan open response
|
|
2206
|
-
const response = JSON.parse(JSON.stringify(loanCloseResp));
|
|
2207
|
-
// Check for errors in response
|
|
2208
|
-
if (response.error)
|
|
2209
|
-
errors.push(`Thornode request quote failed: ${response.error}`);
|
|
2210
|
-
// If errors exist, return an object with error details
|
|
2211
|
-
if (errors.length > 0) {
|
|
2212
|
-
return {
|
|
2213
|
-
inboundAddress: '',
|
|
2214
|
-
expectedWaitTime: {
|
|
2215
|
-
outboundDelayBlocks: undefined,
|
|
2216
|
-
outbondDelaySeconds: undefined,
|
|
2217
|
-
},
|
|
2218
|
-
fees: {
|
|
2219
|
-
asset: '',
|
|
2220
|
-
liquidity: undefined,
|
|
2221
|
-
outbound: undefined,
|
|
2222
|
-
total_bps: undefined,
|
|
2223
|
-
},
|
|
2224
|
-
slippageBps: undefined,
|
|
2225
|
-
router: undefined,
|
|
2226
|
-
expiry: 0,
|
|
2227
|
-
warning: '',
|
|
2228
|
-
notes: '',
|
|
2229
|
-
dustThreshold: undefined,
|
|
2230
|
-
recommendedMinAmountIn: loanCloseResp.recommended_min_amount_in,
|
|
2231
|
-
memo: undefined,
|
|
2232
|
-
expectedAmountOut: '',
|
|
2233
|
-
expectedCollateralWithdrawn: '',
|
|
2234
|
-
expectedDebtRepaid: '',
|
|
2235
|
-
errors: errors,
|
|
2236
|
-
};
|
|
2237
|
-
}
|
|
2238
|
-
// Construct loan open quote object
|
|
2239
|
-
const loanCloseQuote = {
|
|
2240
|
-
inboundAddress: loanCloseResp.inbound_address,
|
|
2241
|
-
expectedWaitTime: {
|
|
2242
|
-
outboundDelayBlocks: loanCloseResp.outbound_delay_blocks,
|
|
2243
|
-
outbondDelaySeconds: loanCloseResp.outbound_delay_seconds,
|
|
2244
|
-
},
|
|
2245
|
-
fees: {
|
|
2246
|
-
asset: loanCloseResp.fees.asset,
|
|
2247
|
-
liquidity: loanCloseResp.fees.liquidity,
|
|
2248
|
-
outbound: loanCloseResp.fees.outbound,
|
|
2249
|
-
total_bps: loanCloseResp.fees.total_bps,
|
|
2250
|
-
},
|
|
2251
|
-
slippageBps: loanCloseResp.fees.slippage_bps,
|
|
2252
|
-
router: loanCloseResp.router,
|
|
2253
|
-
expiry: loanCloseResp.expiry,
|
|
2254
|
-
warning: loanCloseResp.warning,
|
|
2255
|
-
notes: loanCloseResp.notes,
|
|
2256
|
-
dustThreshold: loanCloseResp.dust_threshold,
|
|
2257
|
-
recommendedMinAmountIn: loanCloseResp.recommended_min_amount_in,
|
|
2258
|
-
memo: loanCloseResp.memo,
|
|
2259
|
-
expectedAmountOut: loanCloseResp.expected_amount_out,
|
|
2260
|
-
expectedCollateralWithdrawn: loanCloseResp.expected_collateral_withdrawn,
|
|
2261
|
-
expectedDebtRepaid: loanCloseResp.expected_debt_repaid,
|
|
2262
|
-
errors: errors,
|
|
2263
|
-
};
|
|
2264
|
-
return loanCloseQuote;
|
|
1797
|
+
getLoanQuoteClose(_params) {
|
|
1798
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1799
|
+
throw new Error('Loan quotes are no longer available. THORNode removed the /quote/loan/close endpoint in API v3.15.0.');
|
|
2265
1800
|
});
|
|
2266
1801
|
}
|
|
2267
1802
|
/**
|
|
@@ -3081,7 +2616,6 @@ class TransactionStage {
|
|
|
3081
2616
|
const asset = xchainUtil.assetFromStringEx(txData.tx.tx.coins[0].asset);
|
|
3082
2617
|
const toAddress = `${txData.tx.tx.to_address}`;
|
|
3083
2618
|
const currentHeight = lastBlockObj.find((obj) => obj.chain === asset.chain);
|
|
3084
|
-
console.log(currentHeight);
|
|
3085
2619
|
// Extract relevant block heights and calculate estimated wait time
|
|
3086
2620
|
const outboundBlock = Number(`${currentHeight === null || currentHeight === void 0 ? void 0 : currentHeight.last_observed_in}`);
|
|
3087
2621
|
const finalisedHeight = Number(txData.finalised_height);
|
package/lib/thorchain-query.d.ts
CHANGED
|
@@ -94,17 +94,13 @@ export declare class ThorchainQuery {
|
|
|
94
94
|
*/
|
|
95
95
|
private getDustValues;
|
|
96
96
|
/**
|
|
97
|
-
*
|
|
98
|
-
* @param addAmount - The amount to be added to the saver
|
|
99
|
-
* @returns - Object of type EstimateAddSaver
|
|
97
|
+
* @deprecated Saver quote endpoints were removed from THORNode API in v3.15.0
|
|
100
98
|
*/
|
|
101
|
-
estimateAddSaver(
|
|
99
|
+
estimateAddSaver(_addAmount: CryptoAmount<Asset | TokenAsset>): Promise<EstimateAddSaver>;
|
|
102
100
|
/**
|
|
103
|
-
*
|
|
104
|
-
* @param withdrawParams - Withdrawal parameters including height, asset, address, and withdrawal basis points
|
|
105
|
-
* @returns - Object of type EstimateWithdrawSaver
|
|
101
|
+
* @deprecated Saver quote endpoints were removed from THORNode API in v3.15.0
|
|
106
102
|
*/
|
|
107
|
-
estimateWithdrawSaver(
|
|
103
|
+
estimateWithdrawSaver(_withdrawParams: SaversWithdraw): Promise<EstimateWithdrawSaver>;
|
|
108
104
|
/**
|
|
109
105
|
* Retrieve the position of a saver given the asset, address, and height.
|
|
110
106
|
* @param params - Object containing the asset, address, and height.
|
|
@@ -112,23 +108,13 @@ export declare class ThorchainQuery {
|
|
|
112
108
|
*/
|
|
113
109
|
getSaverPosition(params: getSaver): Promise<SaversPosition>;
|
|
114
110
|
/**
|
|
115
|
-
*
|
|
116
|
-
* @param addAmount - Amount of funds to be added to the saver's pool.
|
|
117
|
-
* @returns An array of strings representing any errors encountered during the estimation process.
|
|
111
|
+
* @deprecated Loan endpoints were removed from THORNode API in v3.15.0
|
|
118
112
|
*/
|
|
119
|
-
|
|
113
|
+
getLoanQuoteOpen(_params: LoanOpenParams): Promise<LoanOpenQuote>;
|
|
120
114
|
/**
|
|
121
|
-
*
|
|
122
|
-
* @param loanOpenParams - params needed for the end Point
|
|
123
|
-
* @returns
|
|
124
|
-
*/
|
|
125
|
-
getLoanQuoteOpen({ asset, amount, targetAsset, destination, minOut, affiliateBps, affiliate, height, }: LoanOpenParams): Promise<LoanOpenQuote>;
|
|
126
|
-
/**
|
|
127
|
-
* Get a quote for opening a loan.
|
|
128
|
-
* @param loanOpenParams - Parameters needed for the endpoint.
|
|
129
|
-
* @returns A Promise resolving to a LoanOpenQuote.
|
|
115
|
+
* @deprecated Loan endpoints were removed from THORNode API in v3.15.0
|
|
130
116
|
*/
|
|
131
|
-
getLoanQuoteClose(
|
|
117
|
+
getLoanQuoteClose(_params: LoanCloseParams): Promise<LoanCloseQuote>;
|
|
132
118
|
/**
|
|
133
119
|
* Retrieve details for a THORName.
|
|
134
120
|
* @param thorname - The THORName to get details for.
|
package/lib/utils/thornode.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Network } from '@xchainjs/xchain-client';
|
|
2
|
-
import { InboundAddress, LastBlock, LiquidityProviderSummary, MimirResponse, Pool, QueueResponse,
|
|
2
|
+
import { InboundAddress, LastBlock, LiquidityProviderSummary, MimirResponse, Pool, QueueResponse, QuoteSwapResponse, RUNEPoolResponse, RUNEProvider, RUNEProvidersResponse, Saver, SaversResponse, Thorname, TradeAccountsResponse, TradeUnitResponse, TradeUnitsResponse, TxDetailsResponse, TxOutItem, TxResponse } from '@xchainjs/xchain-thornode';
|
|
3
3
|
import { Address } from '@xchainjs/xchain-util';
|
|
4
|
-
import { SaversWithdraw } from '../types';
|
|
5
4
|
export type ThornodeConfig = {
|
|
6
5
|
apiRetries: number;
|
|
7
6
|
thornodeBaseUrls: string[];
|
|
@@ -118,23 +117,6 @@ export declare class Thornode {
|
|
|
118
117
|
* @returns - Liquidity Provider Object
|
|
119
118
|
*/
|
|
120
119
|
getSaver(asset: string, address: string, height?: number): Promise<Saver>;
|
|
121
|
-
/**
|
|
122
|
-
*
|
|
123
|
-
* @param asset - asset to add to savers
|
|
124
|
-
* @param amount - amount to deposit
|
|
125
|
-
* @param height - block height
|
|
126
|
-
* @returns quotes deposit object response
|
|
127
|
-
*/
|
|
128
|
-
getSaversDepositQuote(asset: string, amount: number, height?: number): Promise<QuoteSaverDepositResponse>;
|
|
129
|
-
/**
|
|
130
|
-
*
|
|
131
|
-
* @param asset - asset to withdraw
|
|
132
|
-
* @param address - savers address
|
|
133
|
-
* @param height - block height
|
|
134
|
-
* @param withdrawBps - withddraw percent
|
|
135
|
-
* @returns quotes withdraw object response
|
|
136
|
-
*/
|
|
137
|
-
getSaversWithdrawQuote(withdrawParams: SaversWithdraw): Promise<QuoteSaverWithdrawResponse>;
|
|
138
120
|
/**
|
|
139
121
|
*
|
|
140
122
|
* @param fromAsset - input asset
|
|
@@ -148,32 +130,6 @@ export declare class Thornode {
|
|
|
148
130
|
* @returns quotes swap object response
|
|
149
131
|
*/
|
|
150
132
|
getSwapQuote(fromAsset: string, toAsset: string, amount: number, destinationAddress?: string, streamingInterval?: number, streamingQuantity?: number, toleranceBps?: number, liquidityToleranceBps?: number, affiliateBps?: number, affiliate?: string, height?: number, refundAddress?: string): Promise<QuoteSwapResponse>;
|
|
151
|
-
/**
|
|
152
|
-
*
|
|
153
|
-
* @param height
|
|
154
|
-
* @param asset
|
|
155
|
-
* @param amount
|
|
156
|
-
* @param targetAsset
|
|
157
|
-
* @param destination
|
|
158
|
-
* @param minOut
|
|
159
|
-
* @param affiliateBps
|
|
160
|
-
* @param affiliate
|
|
161
|
-
* @returns
|
|
162
|
-
*/
|
|
163
|
-
getLoanQuoteOpen(asset: string, amount: number, targetAsset: string, destination: string, minOut?: string, affiliateBps?: number, affiliate?: string, height?: number): Promise<QuoteLoanOpenResponse>;
|
|
164
|
-
/**
|
|
165
|
-
*
|
|
166
|
-
* @param height
|
|
167
|
-
* @param asset
|
|
168
|
-
* @param amount
|
|
169
|
-
* @param targetAsset
|
|
170
|
-
* @param destination
|
|
171
|
-
* @param minOut
|
|
172
|
-
* @param affiliateBps
|
|
173
|
-
* @param affiliate
|
|
174
|
-
* @returns
|
|
175
|
-
*/
|
|
176
|
-
getLoanQuoteClose(asset: string, amount: number, loanAsset: string, loanOwner: string, minOut?: string, height?: number): Promise<QuoteLoanCloseResponse>;
|
|
177
133
|
getThornameDetails(thorname: string, height?: number): Promise<Thorname>;
|
|
178
134
|
getTradeAssetUnits(asset: string, height?: number): Promise<TradeUnitResponse>;
|
|
179
135
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xchainjs/xchain-thorchain-query",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
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,11 +33,11 @@
|
|
|
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
|
|
36
|
+
"@xchainjs/xchain-client": "2.0.10",
|
|
37
|
+
"@xchainjs/xchain-midgard-query": "2.0.12",
|
|
38
|
+
"@xchainjs/xchain-thornode": "1.1.0",
|
|
39
39
|
"@xchainjs/xchain-util": "2.0.5",
|
|
40
|
-
"axios": "1.
|
|
40
|
+
"axios": "1.13.5",
|
|
41
41
|
"axios-retry": "3.2.5",
|
|
42
42
|
"bignumber.js": "^9.1.2"
|
|
43
43
|
},
|