@xchainjs/xchain-thorchain-query 0.6.8 → 0.6.10

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 CHANGED
@@ -1160,12 +1160,11 @@ class ThorchainQuery {
1160
1160
  */
1161
1161
  quoteSwap({ fromAsset, destinationAsset, amount, destinationAddress, streamingInterval, streamingQuantity, fromAddress, toleranceBps, affiliateBps, affiliateAddress, height, }) {
1162
1162
  return __awaiter(this, void 0, void 0, function* () {
1163
- const errors = [];
1164
- const validAssetDecimals = yield this.isValidAssetDecimals(fromAsset, amount);
1165
1163
  // validates swap, and pushes error if there is one
1166
- if (validAssetDecimals) {
1167
- errors.push(`${validAssetDecimals}`);
1168
- }
1164
+ const errors = [];
1165
+ const error = yield this.validateAmount(amount);
1166
+ if (error)
1167
+ errors.push(error.message);
1169
1168
  const fromAssetString = assetToString(fromAsset);
1170
1169
  const toAssetString = assetToString(destinationAsset);
1171
1170
  const inputAmount = getBaseAmountWithDiffDecimals(amount, 8);
@@ -1245,24 +1244,15 @@ class ThorchainQuery {
1245
1244
  });
1246
1245
  }
1247
1246
  /**
1248
- *
1249
- * @param params - quote swap params
1250
- * @returns boolean
1247
+ * Validate a cryptoAmount is well formed
1248
+ * @param {CryptoAmount} cryptoAmount - CryptoAmount to validate
1249
+ * @returns {void | Error} Error if the cryptoAmount is not well formed
1251
1250
  */
1252
- isValidAssetDecimals(fromAsset, inputAmount) {
1251
+ validateAmount(cryptoAmount) {
1253
1252
  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
1253
+ const assetDecimals = yield this.thorchainCache.midgardQuery.getDecimalForAsset(cryptoAmount.asset);
1254
+ if (cryptoAmount.baseAmount.decimal !== assetDecimals)
1255
+ return new Error(`Invalid number of decimals: ${assetToString(cryptoAmount.asset)} must have ${assetDecimals} decimals`);
1266
1256
  });
1267
1257
  }
1268
1258
  /**
@@ -2116,7 +2106,7 @@ class ThorchainQuery {
2116
2106
  const oneTimeFee = params.isUpdate ? baseAmount(0) : baseAmount(constantsDetails['TNSRegisterFee']);
2117
2107
  const totalFeePerBlock = baseAmount(constantsDetails['TNSFeePerBlock']).times(numberOfBlocksToAddToExpirity > 0 ? numberOfBlocksToAddToExpirity : 0);
2118
2108
  const totalCost = new CryptoAmount(oneTimeFee.plus(totalFeePerBlock), AssetRuneNative);
2119
- const thornameMemo = `~:${params.thorname}:${params.chain}:${params.chainAddress}:${params.owner ? params.owner : ''}:${params.preferredAsset ? assetToString(params.preferredAsset) : ''}:${params.isUpdate ? '' : currentHeightForExpirity + numberOfBlocksToAddToExpirity}`;
2109
+ const thornameMemo = `~:${params.thorname}:${params.chain}:${params.chainAddress}:${params.owner ? params.owner : ''}:${params.preferredAsset ? assetToString(params.preferredAsset) : ''}:${params.isUpdate ? '' : currentHeightForExpirity + numberOfBlocksToAddToExpirity}`.replace(/^:+|:+$/g, '');
2120
2110
  return {
2121
2111
  memo: thornameMemo,
2122
2112
  value: totalCost,