@xchainjs/xchain-thorchain-query 0.6.4 → 0.6.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.esm.js +74 -30
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +74 -30
- package/lib/index.js.map +1 -1
- package/lib/thorchain-query.d.ts +6 -0
- package/lib/types.d.ts +2 -0
- package/package.json +4 -4
package/lib/index.esm.js
CHANGED
|
@@ -890,11 +890,8 @@ class Thornode {
|
|
|
890
890
|
try {
|
|
891
891
|
const resp = (yield api.thorname(thorname, height)).data;
|
|
892
892
|
return resp;
|
|
893
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
894
|
-
}
|
|
895
|
-
catch (e) {
|
|
896
|
-
if (e.response.status == 404) ;
|
|
897
893
|
}
|
|
894
|
+
catch (e) { }
|
|
898
895
|
}
|
|
899
896
|
throw new Error(`THORNode is not responding`);
|
|
900
897
|
});
|
|
@@ -1164,6 +1161,11 @@ class ThorchainQuery {
|
|
|
1164
1161
|
quoteSwap({ fromAsset, destinationAsset, amount, destinationAddress, streamingInterval, streamingQuantity, fromAddress, toleranceBps, affiliateBps, affiliateAddress, height, }) {
|
|
1165
1162
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1166
1163
|
const errors = [];
|
|
1164
|
+
const validAssetDecimals = yield this.isValidAssetDecimals(fromAsset, amount);
|
|
1165
|
+
// validates swap, and pushes error if there is one
|
|
1166
|
+
if (validAssetDecimals) {
|
|
1167
|
+
errors.push(`${validAssetDecimals}`);
|
|
1168
|
+
}
|
|
1167
1169
|
const fromAssetString = assetToString(fromAsset);
|
|
1168
1170
|
const toAssetString = assetToString(destinationAsset);
|
|
1169
1171
|
const inputAmount = getBaseAmountWithDiffDecimals(amount, 8);
|
|
@@ -1242,6 +1244,27 @@ class ThorchainQuery {
|
|
|
1242
1244
|
return txDetails;
|
|
1243
1245
|
});
|
|
1244
1246
|
}
|
|
1247
|
+
/**
|
|
1248
|
+
*
|
|
1249
|
+
* @param params - quote swap params
|
|
1250
|
+
* @returns boolean
|
|
1251
|
+
*/
|
|
1252
|
+
isValidAssetDecimals(fromAsset, inputAmount) {
|
|
1253
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1254
|
+
if (isAssetRuneNative(fromAsset) || fromAsset.synth) {
|
|
1255
|
+
if (inputAmount.baseAmount.decimal !== 8) {
|
|
1256
|
+
return `input asset ${assetToString(fromAsset)} must have decimals of 8`;
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
else {
|
|
1260
|
+
const nativeDecimals = yield this.thorchainCache.midgardQuery.getDecimalForAsset(fromAsset);
|
|
1261
|
+
if (nativeDecimals && nativeDecimals !== -1 && inputAmount.baseAmount.decimal !== nativeDecimals) {
|
|
1262
|
+
return `input asset ${assetToString(fromAsset)} must have decimals of ${nativeDecimals}`;
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
return undefined; // Explicitly return undefined if no conditions are met
|
|
1266
|
+
});
|
|
1267
|
+
}
|
|
1245
1268
|
/**
|
|
1246
1269
|
* Works out how long an outbound Tx will be held by THORChain before sending.
|
|
1247
1270
|
*
|
|
@@ -1731,6 +1754,8 @@ class ThorchainQuery {
|
|
|
1731
1754
|
expiry: new Date(0),
|
|
1732
1755
|
toAddress: '',
|
|
1733
1756
|
memo: '',
|
|
1757
|
+
inboundDelayBlocks: 0,
|
|
1758
|
+
inboundDelaySeconds: 0,
|
|
1734
1759
|
outBoundDelayBlocks: 0,
|
|
1735
1760
|
outBoundDelaySeconds: 0,
|
|
1736
1761
|
slipBasisPoints: -1,
|
|
@@ -1758,6 +1783,8 @@ class ThorchainQuery {
|
|
|
1758
1783
|
expiry: new Date(0),
|
|
1759
1784
|
toAddress: '',
|
|
1760
1785
|
memo: '',
|
|
1786
|
+
inboundDelayBlocks: 0,
|
|
1787
|
+
inboundDelaySeconds: 0,
|
|
1761
1788
|
outBoundDelayBlocks: 0,
|
|
1762
1789
|
outBoundDelaySeconds: 0,
|
|
1763
1790
|
slipBasisPoints: -1,
|
|
@@ -1779,8 +1806,10 @@ class ThorchainQuery {
|
|
|
1779
1806
|
expiry: new Date(withdrawQuote.expiry),
|
|
1780
1807
|
toAddress: withdrawQuote.inbound_address,
|
|
1781
1808
|
memo: withdrawQuote.memo,
|
|
1782
|
-
|
|
1783
|
-
|
|
1809
|
+
inboundDelayBlocks: withdrawQuote.inbound_confirmation_blocks || 0,
|
|
1810
|
+
inboundDelaySeconds: withdrawQuote.inbound_confirmation_seconds || 0,
|
|
1811
|
+
outBoundDelayBlocks: withdrawQuote.outbound_delay_blocks || 0,
|
|
1812
|
+
outBoundDelaySeconds: withdrawQuote.outbound_delay_seconds || 0,
|
|
1784
1813
|
slipBasisPoints: withdrawQuote.slippage_bps,
|
|
1785
1814
|
errors,
|
|
1786
1815
|
};
|
|
@@ -1797,7 +1826,8 @@ class ThorchainQuery {
|
|
|
1797
1826
|
const errors = [];
|
|
1798
1827
|
const inboundDetails = yield this.thorchainCache.getInboundDetails();
|
|
1799
1828
|
const blockData = (yield this.thorchainCache.thornode.getLastBlock()).find((item) => item.chain === params.asset.chain);
|
|
1800
|
-
|
|
1829
|
+
// address comparison is done after conversion to lower case
|
|
1830
|
+
const savers = (yield this.thorchainCache.thornode.getSavers(`${params.asset.chain}.${params.asset.symbol}`)).find((item) => item.asset_address.toLowerCase() === params.address.toLowerCase());
|
|
1801
1831
|
const pool = (yield this.thorchainCache.getPoolForAsset(params.asset)).thornodeDetails;
|
|
1802
1832
|
if (!savers)
|
|
1803
1833
|
errors.push(`Could not find position for ${params.address}`);
|
|
@@ -2000,11 +2030,38 @@ class ThorchainQuery {
|
|
|
2000
2030
|
getThornameDetails(thorname, height) {
|
|
2001
2031
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2002
2032
|
const errors = [];
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2033
|
+
try {
|
|
2034
|
+
const thornameResp = yield this.thorchainCache.thornode.getThornameDetails(thorname, height);
|
|
2035
|
+
const response = JSON.parse(JSON.stringify(thornameResp));
|
|
2036
|
+
if (response.error)
|
|
2037
|
+
errors.push(`Thornode request quote failed: ${response.error}`);
|
|
2038
|
+
if (errors.length > 0) {
|
|
2039
|
+
const errorResp = {
|
|
2040
|
+
name: '',
|
|
2041
|
+
expireBlockHeight: 0,
|
|
2042
|
+
owner: '',
|
|
2043
|
+
preferredAsset: '',
|
|
2044
|
+
affiliateCollectorRune: '',
|
|
2045
|
+
aliases: [],
|
|
2046
|
+
error: errors,
|
|
2047
|
+
};
|
|
2048
|
+
return errorResp;
|
|
2049
|
+
}
|
|
2050
|
+
const thornameAliases = thornameResp.aliases.map((alias) => ({
|
|
2051
|
+
chain: alias.chain,
|
|
2052
|
+
address: alias.address,
|
|
2053
|
+
}));
|
|
2054
|
+
const thornameDetails = {
|
|
2055
|
+
name: thornameResp.name || '',
|
|
2056
|
+
expireBlockHeight: thornameResp.expire_block_height || 0,
|
|
2057
|
+
owner: thornameResp.owner || '',
|
|
2058
|
+
preferredAsset: thornameResp.preferred_asset || '',
|
|
2059
|
+
affiliateCollectorRune: thornameResp.affiliate_collector_rune || '',
|
|
2060
|
+
aliases: thornameAliases || [],
|
|
2061
|
+
};
|
|
2062
|
+
return thornameDetails;
|
|
2063
|
+
}
|
|
2064
|
+
catch (e) {
|
|
2008
2065
|
const errorResp = {
|
|
2009
2066
|
name: '',
|
|
2010
2067
|
expireBlockHeight: 0,
|
|
@@ -2016,19 +2073,6 @@ class ThorchainQuery {
|
|
|
2016
2073
|
};
|
|
2017
2074
|
return errorResp;
|
|
2018
2075
|
}
|
|
2019
|
-
const thornameAliases = thornameResp.aliases.map((alias) => ({
|
|
2020
|
-
chain: alias.chain,
|
|
2021
|
-
address: alias.address,
|
|
2022
|
-
}));
|
|
2023
|
-
const thornameDetails = {
|
|
2024
|
-
name: thornameResp.name || '',
|
|
2025
|
-
expireBlockHeight: thornameResp.expire_block_height || 0,
|
|
2026
|
-
owner: thornameResp.owner || '',
|
|
2027
|
-
preferredAsset: thornameResp.preferred_asset || '',
|
|
2028
|
-
affiliateCollectorRune: thornameResp.affiliate_collector_rune || '',
|
|
2029
|
-
aliases: thornameAliases || [],
|
|
2030
|
-
};
|
|
2031
|
-
return thornameDetails;
|
|
2032
2076
|
});
|
|
2033
2077
|
}
|
|
2034
2078
|
/**
|
|
@@ -2045,14 +2089,14 @@ class ThorchainQuery {
|
|
|
2045
2089
|
estimateThorname(params) {
|
|
2046
2090
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2047
2091
|
// CHECK IF ALREADY EXISTS
|
|
2048
|
-
const thornameDetails =
|
|
2049
|
-
if (thornameDetails && !params.isUpdate) {
|
|
2092
|
+
const thornameDetails = yield this.getThornameDetails(params.thorname);
|
|
2093
|
+
if (thornameDetails.owner !== '' && !params.isUpdate) {
|
|
2050
2094
|
throw Error('Thorname already registered');
|
|
2051
2095
|
}
|
|
2052
2096
|
const blockData = yield this.thorchainCache.thornode.getLastBlock();
|
|
2053
2097
|
const currentThorchainHeight = blockData[0].thorchain;
|
|
2054
2098
|
const currentHeightForExpirity = params.isUpdate
|
|
2055
|
-
? thornameDetails === null || thornameDetails === void 0 ? void 0 : thornameDetails.
|
|
2099
|
+
? thornameDetails === null || thornameDetails === void 0 ? void 0 : thornameDetails.expireBlockHeight
|
|
2056
2100
|
: currentThorchainHeight;
|
|
2057
2101
|
// DEFAULT EXPIRITY
|
|
2058
2102
|
let numberOfBlocksToAddToExpirity = params.isUpdate ? 0 : 5259600; // One year by default
|
|
@@ -2063,8 +2107,8 @@ class ThorchainQuery {
|
|
|
2063
2107
|
const numberOfSecondsToExpire = expirityTimestamp - currentTimestamp;
|
|
2064
2108
|
const numberOfBlocks = Math.round(numberOfSecondsToExpire / 6);
|
|
2065
2109
|
const newHeightExpirity = currentThorchainHeight + numberOfBlocks;
|
|
2066
|
-
numberOfBlocksToAddToExpirity = (thornameDetails === null || thornameDetails === void 0 ? void 0 : thornameDetails.
|
|
2067
|
-
? newHeightExpirity - (thornameDetails === null || thornameDetails === void 0 ? void 0 : thornameDetails.
|
|
2110
|
+
numberOfBlocksToAddToExpirity = (thornameDetails === null || thornameDetails === void 0 ? void 0 : thornameDetails.expireBlockHeight)
|
|
2111
|
+
? newHeightExpirity - (thornameDetails === null || thornameDetails === void 0 ? void 0 : thornameDetails.expireBlockHeight)
|
|
2068
2112
|
: numberOfBlocks;
|
|
2069
2113
|
}
|
|
2070
2114
|
// COMPUTE VALUE
|