@xchainjs/xchain-mayachain-query 2.1.2 → 2.1.3

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
@@ -81,13 +81,12 @@ class Mayanode {
81
81
  * @param height - block height
82
82
  * @returns quotes swap object response
83
83
  */
84
- getSwapQuote(fromAsset, toAsset, amount, destinationAddress, streamingInterval, streamingQuantity, toleranceBps, affiliateBps, affiliate, height) {
84
+ getSwapQuote(fromAsset, toAsset, amount, destinationAddress, streamingInterval, streamingQuantity, liquidityToleranceBps, toleranceBps, affiliateBps, affiliate, height) {
85
85
  return __awaiter(this, void 0, void 0, function* () {
86
86
  for (const api of this.quoteApis) {
87
87
  try {
88
- return (yield api.quoteswap(height, fromAsset, toAsset, amount, destinationAddress, undefined, // refundAddress
89
- streamingInterval, streamingQuantity, toleranceBps, undefined, // liquidityToleranceBps
90
- affiliateBps === null || affiliateBps === void 0 ? void 0 : affiliateBps.toString(), affiliate)).data;
88
+ return (yield api.quoteswap(height, fromAsset, toAsset, amount, destinationAddress, undefined, //refund address
89
+ streamingInterval, streamingQuantity, toleranceBps, liquidityToleranceBps, affiliateBps === null || affiliateBps === void 0 ? void 0 : affiliateBps.toString(), affiliate)).data;
91
90
  }
92
91
  catch (_e) { }
93
92
  }
@@ -543,14 +542,15 @@ class MayachainQuery {
543
542
  * @returns {QuoteSwap} A quote for the swap operation.
544
543
  */
545
544
  quoteSwap(_a) {
546
- return __awaiter(this, arguments, void 0, function* ({ fromAsset, destinationAsset, amount, destinationAddress, toleranceBps, affiliateBps, affiliateAddress, height, streamingInterval, streamingQuantity, }) {
545
+ return __awaiter(this, arguments, void 0, function* ({ fromAsset, destinationAsset, amount, destinationAddress, liquidityToleranceBps, toleranceBps, affiliateBps, affiliateAddress, height, streamingInterval, streamingQuantity, }) {
547
546
  const fromAssetString = assetToString(fromAsset);
548
547
  const toAssetString = assetToString(destinationAsset);
549
548
  // Endpoint allows 10 decimals for Cacao, 8 for the rest of assets
550
- const inputAmount = fromAssetString === assetToString(CacaoAsset)
549
+ const inputAmount = eqAsset(fromAsset, CacaoAsset)
551
550
  ? amount.baseAmount.amount()
552
- : getBaseAmountWithDiffDecimals(amount, 8);
553
- const swapQuote = yield this.mayachainCache.mayanode.getSwapQuote(fromAssetString, toAssetString, inputAmount.toNumber(), destinationAddress, streamingInterval, streamingQuantity, toleranceBps, affiliateBps, affiliateAddress, height);
551
+ : getBaseAmountWithDiffDecimals(amount, this.getQuoteAssetDecimals(fromAsset));
552
+ const swapQuote = yield this.mayachainCache.mayanode.getSwapQuote(fromAssetString, toAssetString, inputAmount.toNumber(), destinationAddress, streamingInterval, streamingQuantity, liquidityToleranceBps, toleranceBps, affiliateBps, affiliateAddress, height);
553
+ // Check if the response indicates an error by examining memo and other required field
554
554
  const response = JSON.parse(JSON.stringify(swapQuote));
555
555
  if (response.error) {
556
556
  return {
@@ -582,23 +582,22 @@ class MayachainQuery {
582
582
  }
583
583
  const feeAsset = assetFromStringEx(swapQuote.fees.asset);
584
584
  const errors = [];
585
- if (swapQuote.memo === undefined)
585
+ if (swapQuote.memo === undefined || swapQuote.memo === '')
586
586
  errors.push(`Error parsing swap quote: Memo is ${swapQuote.memo}`);
587
- const isFeeAssetCacao = swapQuote.fees.asset === assetToString(CacaoAsset);
588
587
  return {
589
588
  toAddress: swapQuote.inbound_address || '',
590
589
  memo: swapQuote.memo || '',
591
- expectedAmount: new CryptoAmount(baseAmount(swapQuote.expected_amount_out, toAssetString === assetToString(CacaoAsset) ? 10 : 8), destinationAsset),
590
+ expectedAmount: new CryptoAmount(baseAmount(swapQuote.expected_amount_out, this.getQuoteAssetDecimals(destinationAsset)), destinationAsset),
592
591
  dustThreshold: this.getChainDustValue(fromAsset.chain),
593
592
  fees: {
594
593
  asset: feeAsset,
595
- affiliateFee: new CryptoAmount(baseAmount(swapQuote.fees.affiliate, isFeeAssetCacao ? 10 : 8), feeAsset),
596
- outboundFee: new CryptoAmount(baseAmount(swapQuote.fees.outbound, isFeeAssetCacao ? 10 : 8), feeAsset),
597
- liquidityFee: new CryptoAmount(baseAmount(swapQuote.fees.liquidity, isFeeAssetCacao ? 10 : 8), feeAsset),
598
- totalFee: new CryptoAmount(baseAmount(swapQuote.fees.total, isFeeAssetCacao ? 10 : 8), feeAsset),
594
+ affiliateFee: new CryptoAmount(baseAmount(swapQuote.fees.affiliate, this.getQuoteAssetDecimals(feeAsset)), feeAsset),
595
+ outboundFee: new CryptoAmount(baseAmount(swapQuote.fees.outbound, this.getQuoteAssetDecimals(feeAsset)), feeAsset),
596
+ liquidityFee: new CryptoAmount(baseAmount(swapQuote.fees.liquidity, this.getQuoteAssetDecimals(feeAsset)), feeAsset),
597
+ totalFee: new CryptoAmount(baseAmount(swapQuote.fees.total, this.getQuoteAssetDecimals(feeAsset)), feeAsset),
599
598
  },
600
599
  expiry: swapQuote.expiry,
601
- recommendedMinAmountIn: new CryptoAmount(baseAmount(swapQuote.recommended_min_amount_in || '0', eqAsset(fromAsset, CacaoAsset) ? 10 : 8), fromAsset),
600
+ recommendedMinAmountIn: new CryptoAmount(baseAmount(swapQuote.recommended_min_amount_in || '0', this.getQuoteAssetDecimals(fromAsset)), fromAsset),
602
601
  router: swapQuote.router,
603
602
  recommendedGasRate: swapQuote.recommended_gas_rate,
604
603
  gasRateUnits: swapQuote.gas_rate_units,
@@ -965,6 +964,14 @@ class MayachainQuery {
965
964
  });
966
965
  });
967
966
  }
967
+ /**
968
+ * Get the hardcoded decimal precision for quote calculations
969
+ * @param asset The asset to get decimals for
970
+ * @returns 10 for Cacao, 8 for other assets (used in quote calculations)
971
+ */
972
+ getQuoteAssetDecimals(asset) {
973
+ return eqAsset(asset, CacaoAsset) ? 10 : 8;
974
+ }
968
975
  }
969
976
 
970
977
  export { ArbAsset, ArbChain, BtcAsset, BtcChain, CacaoAsset, DEFAULT_MAYACHAIN_DECIMALS, DashAsset, DashChain, EthAsset, EthChain, KujiraAsset, KujiraChain, MayaChain, MayachainCache, MayachainQuery, Mayanode, RuneAsset, ThorChain, XdrAsset, XdrChain, ZecAsset, ZecChain, getBaseAmountWithDiffDecimals, getCryptoAmountWithNotation, isCacaoAsset };
package/lib/index.js CHANGED
@@ -89,13 +89,12 @@ class Mayanode {
89
89
  * @param height - block height
90
90
  * @returns quotes swap object response
91
91
  */
92
- getSwapQuote(fromAsset, toAsset, amount, destinationAddress, streamingInterval, streamingQuantity, toleranceBps, affiliateBps, affiliate, height) {
92
+ getSwapQuote(fromAsset, toAsset, amount, destinationAddress, streamingInterval, streamingQuantity, liquidityToleranceBps, toleranceBps, affiliateBps, affiliate, height) {
93
93
  return __awaiter(this, void 0, void 0, function* () {
94
94
  for (const api of this.quoteApis) {
95
95
  try {
96
- return (yield api.quoteswap(height, fromAsset, toAsset, amount, destinationAddress, undefined, // refundAddress
97
- streamingInterval, streamingQuantity, toleranceBps, undefined, // liquidityToleranceBps
98
- affiliateBps === null || affiliateBps === void 0 ? void 0 : affiliateBps.toString(), affiliate)).data;
96
+ return (yield api.quoteswap(height, fromAsset, toAsset, amount, destinationAddress, undefined, //refund address
97
+ streamingInterval, streamingQuantity, toleranceBps, liquidityToleranceBps, affiliateBps === null || affiliateBps === void 0 ? void 0 : affiliateBps.toString(), affiliate)).data;
99
98
  }
100
99
  catch (_e) { }
101
100
  }
@@ -551,14 +550,15 @@ class MayachainQuery {
551
550
  * @returns {QuoteSwap} A quote for the swap operation.
552
551
  */
553
552
  quoteSwap(_a) {
554
- return __awaiter(this, arguments, void 0, function* ({ fromAsset, destinationAsset, amount, destinationAddress, toleranceBps, affiliateBps, affiliateAddress, height, streamingInterval, streamingQuantity, }) {
553
+ return __awaiter(this, arguments, void 0, function* ({ fromAsset, destinationAsset, amount, destinationAddress, liquidityToleranceBps, toleranceBps, affiliateBps, affiliateAddress, height, streamingInterval, streamingQuantity, }) {
555
554
  const fromAssetString = xchainUtil.assetToString(fromAsset);
556
555
  const toAssetString = xchainUtil.assetToString(destinationAsset);
557
556
  // Endpoint allows 10 decimals for Cacao, 8 for the rest of assets
558
- const inputAmount = fromAssetString === xchainUtil.assetToString(CacaoAsset)
557
+ const inputAmount = xchainUtil.eqAsset(fromAsset, CacaoAsset)
559
558
  ? amount.baseAmount.amount()
560
- : getBaseAmountWithDiffDecimals(amount, 8);
561
- const swapQuote = yield this.mayachainCache.mayanode.getSwapQuote(fromAssetString, toAssetString, inputAmount.toNumber(), destinationAddress, streamingInterval, streamingQuantity, toleranceBps, affiliateBps, affiliateAddress, height);
559
+ : getBaseAmountWithDiffDecimals(amount, this.getQuoteAssetDecimals(fromAsset));
560
+ const swapQuote = yield this.mayachainCache.mayanode.getSwapQuote(fromAssetString, toAssetString, inputAmount.toNumber(), destinationAddress, streamingInterval, streamingQuantity, liquidityToleranceBps, toleranceBps, affiliateBps, affiliateAddress, height);
561
+ // Check if the response indicates an error by examining memo and other required field
562
562
  const response = JSON.parse(JSON.stringify(swapQuote));
563
563
  if (response.error) {
564
564
  return {
@@ -590,23 +590,22 @@ class MayachainQuery {
590
590
  }
591
591
  const feeAsset = xchainUtil.assetFromStringEx(swapQuote.fees.asset);
592
592
  const errors = [];
593
- if (swapQuote.memo === undefined)
593
+ if (swapQuote.memo === undefined || swapQuote.memo === '')
594
594
  errors.push(`Error parsing swap quote: Memo is ${swapQuote.memo}`);
595
- const isFeeAssetCacao = swapQuote.fees.asset === xchainUtil.assetToString(CacaoAsset);
596
595
  return {
597
596
  toAddress: swapQuote.inbound_address || '',
598
597
  memo: swapQuote.memo || '',
599
- expectedAmount: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(swapQuote.expected_amount_out, toAssetString === xchainUtil.assetToString(CacaoAsset) ? 10 : 8), destinationAsset),
598
+ expectedAmount: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(swapQuote.expected_amount_out, this.getQuoteAssetDecimals(destinationAsset)), destinationAsset),
600
599
  dustThreshold: this.getChainDustValue(fromAsset.chain),
601
600
  fees: {
602
601
  asset: feeAsset,
603
- affiliateFee: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(swapQuote.fees.affiliate, isFeeAssetCacao ? 10 : 8), feeAsset),
604
- outboundFee: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(swapQuote.fees.outbound, isFeeAssetCacao ? 10 : 8), feeAsset),
605
- liquidityFee: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(swapQuote.fees.liquidity, isFeeAssetCacao ? 10 : 8), feeAsset),
606
- totalFee: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(swapQuote.fees.total, isFeeAssetCacao ? 10 : 8), feeAsset),
602
+ affiliateFee: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(swapQuote.fees.affiliate, this.getQuoteAssetDecimals(feeAsset)), feeAsset),
603
+ outboundFee: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(swapQuote.fees.outbound, this.getQuoteAssetDecimals(feeAsset)), feeAsset),
604
+ liquidityFee: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(swapQuote.fees.liquidity, this.getQuoteAssetDecimals(feeAsset)), feeAsset),
605
+ totalFee: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(swapQuote.fees.total, this.getQuoteAssetDecimals(feeAsset)), feeAsset),
607
606
  },
608
607
  expiry: swapQuote.expiry,
609
- recommendedMinAmountIn: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(swapQuote.recommended_min_amount_in || '0', xchainUtil.eqAsset(fromAsset, CacaoAsset) ? 10 : 8), fromAsset),
608
+ recommendedMinAmountIn: new xchainUtil.CryptoAmount(xchainUtil.baseAmount(swapQuote.recommended_min_amount_in || '0', this.getQuoteAssetDecimals(fromAsset)), fromAsset),
610
609
  router: swapQuote.router,
611
610
  recommendedGasRate: swapQuote.recommended_gas_rate,
612
611
  gasRateUnits: swapQuote.gas_rate_units,
@@ -973,6 +972,14 @@ class MayachainQuery {
973
972
  });
974
973
  });
975
974
  }
975
+ /**
976
+ * Get the hardcoded decimal precision for quote calculations
977
+ * @param asset The asset to get decimals for
978
+ * @returns 10 for Cacao, 8 for other assets (used in quote calculations)
979
+ */
980
+ getQuoteAssetDecimals(asset) {
981
+ return xchainUtil.eqAsset(asset, CacaoAsset) ? 10 : 8;
982
+ }
976
983
  }
977
984
 
978
985
  exports.ArbAsset = ArbAsset;
@@ -32,7 +32,7 @@ export declare class MayachainQuery {
32
32
  * @param {QuoteSwapParams} quoteSwapParams - Parameters for the quote swap operation.
33
33
  * @returns {QuoteSwap} A quote for the swap operation.
34
34
  */
35
- quoteSwap({ fromAsset, destinationAsset, amount, destinationAddress, toleranceBps, affiliateBps, affiliateAddress, height, streamingInterval, streamingQuantity, }: QuoteSwapParams): Promise<QuoteSwap>;
35
+ quoteSwap({ fromAsset, destinationAsset, amount, destinationAddress, liquidityToleranceBps, toleranceBps, affiliateBps, affiliateAddress, height, streamingInterval, streamingQuantity, }: QuoteSwapParams): Promise<QuoteSwap>;
36
36
  /**
37
37
  * Return mayachain supported chains dust amounts
38
38
  * @returns a map where chain is the key and dust amount cryptoAmount as value
@@ -122,4 +122,10 @@ export declare class MayachainQuery {
122
122
  * @returns {TradeAssetAccounts} All trade accounts for the asset
123
123
  */
124
124
  getTradeAssetAccounts({ asset, height }: TradeAssetAccountsParams): Promise<TradeAssetAccounts>;
125
+ /**
126
+ * Get the hardcoded decimal precision for quote calculations
127
+ * @param asset The asset to get decimals for
128
+ * @returns 10 for Cacao, 8 for other assets (used in quote calculations)
129
+ */
130
+ private getQuoteAssetDecimals;
125
131
  }
package/lib/types.d.ts CHANGED
@@ -79,6 +79,7 @@ export type QuoteSwapParams = {
79
79
  fromAddress?: string;
80
80
  destinationAddress?: string;
81
81
  height?: number;
82
+ liquidityToleranceBps?: number;
82
83
  toleranceBps?: number;
83
84
  affiliateBps?: number;
84
85
  affiliateAddress?: string;
@@ -31,7 +31,7 @@ export declare class Mayanode {
31
31
  * @param height - block height
32
32
  * @returns quotes swap object response
33
33
  */
34
- getSwapQuote(fromAsset: string, toAsset: string, amount: number, destinationAddress?: string, streamingInterval?: number, streamingQuantity?: number, toleranceBps?: number, affiliateBps?: number, affiliate?: string, height?: number): Promise<QuoteSwapResponse>;
34
+ getSwapQuote(fromAsset: string, toAsset: string, amount: number, destinationAddress?: string, streamingInterval?: number, streamingQuantity?: number, liquidityToleranceBps?: number, toleranceBps?: number, affiliateBps?: number, affiliate?: string, height?: number): Promise<QuoteSwapResponse>;
35
35
  /**
36
36
  * Get current active mimir configuration.
37
37
  * @returns mimir configuration
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xchainjs/xchain-mayachain-query",
3
- "version": "2.1.2",
3
+ "version": "2.1.3",
4
4
  "license": "MIT",
5
5
  "description": "Mayachain query module that is responsible for estimating swap calculations and add/remove liquidity for thorchain",
6
6
  "keywords": [