@xchainjs/xchain-mayachain-query 2.1.11 → 2.2.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 CHANGED
@@ -81,12 +81,15 @@ 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, liquidityToleranceBps, toleranceBps, affiliateBps, affiliate, height) {
84
+ getSwapQuote(fromAsset, toAsset, amount, destinationAddress, streamingInterval, streamingQuantity, liquidityToleranceBps, toleranceBps,
85
+ // `string` is accepted to carry the slash-delimited per-affiliate form (e.g. "10/20/30")
86
+ // used when multiple affiliates are passed. Single-affiliate callers pass a number as before.
87
+ affiliateBps, affiliate, height) {
85
88
  return __awaiter(this, void 0, void 0, function* () {
86
89
  for (const api of this.quoteApis) {
87
90
  try {
88
91
  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;
92
+ streamingInterval, streamingQuantity, toleranceBps, liquidityToleranceBps, typeof affiliateBps === 'number' ? affiliateBps.toString() : affiliateBps, affiliate)).data;
90
93
  }
91
94
  catch (_e) { }
92
95
  }
@@ -547,14 +550,19 @@ class MayachainQuery {
547
550
  * @returns {QuoteSwap} A quote for the swap operation.
548
551
  */
549
552
  quoteSwap(_a) {
550
- return __awaiter(this, arguments, void 0, function* ({ fromAsset, destinationAsset, amount, destinationAddress, liquidityToleranceBps, toleranceBps, affiliateBps, affiliateAddress, height, streamingInterval, streamingQuantity, }) {
553
+ return __awaiter(this, arguments, void 0, function* ({ fromAsset, destinationAsset, amount, destinationAddress, liquidityToleranceBps, toleranceBps, affiliateBps, affiliateAddress, affiliates, height, streamingInterval, streamingQuantity, }) {
551
554
  const fromAssetString = assetToString(fromAsset);
552
555
  const toAssetString = assetToString(destinationAsset);
553
556
  // Endpoint allows 10 decimals for Cacao, 8 for the rest of assets
554
557
  const inputAmount = eqAsset(fromAsset, CacaoAsset)
555
558
  ? amount.baseAmount.amount()
556
559
  : getBaseAmountWithDiffDecimals(amount, this.getQuoteAssetDecimals(fromAsset));
557
- const swapQuote = yield this.mayachainCache.mayanode.getSwapQuote(fromAssetString, toAssetString, inputAmount.toNumber(), destinationAddress, streamingInterval, streamingQuantity, liquidityToleranceBps, toleranceBps, affiliateBps, affiliateAddress, height);
560
+ // If the caller passed a multi-affiliate array, collapse it into the slash-delimited
561
+ // form the protocol's /quote/swap endpoint accepts. The endpoint requires per-affiliate bps
562
+ // (it does not auto-expand a single shared bps), so both fields are joined in parallel.
563
+ const quoteAffiliateAddress = affiliates ? affiliates.map((a) => a.address).join('/') : affiliateAddress;
564
+ const quoteAffiliateBps = affiliates ? affiliates.map((a) => a.bps).join('/') : affiliateBps;
565
+ const swapQuote = yield this.mayachainCache.mayanode.getSwapQuote(fromAssetString, toAssetString, inputAmount.toNumber(), destinationAddress, streamingInterval, streamingQuantity, liquidityToleranceBps, toleranceBps, quoteAffiliateBps, quoteAffiliateAddress, height);
558
566
  // Check if the response indicates an error by examining memo and other required field
559
567
  const response = JSON.parse(JSON.stringify(swapQuote));
560
568
  if (response.error) {
package/lib/index.js CHANGED
@@ -89,12 +89,15 @@ 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, liquidityToleranceBps, toleranceBps, affiliateBps, affiliate, height) {
92
+ getSwapQuote(fromAsset, toAsset, amount, destinationAddress, streamingInterval, streamingQuantity, liquidityToleranceBps, toleranceBps,
93
+ // `string` is accepted to carry the slash-delimited per-affiliate form (e.g. "10/20/30")
94
+ // used when multiple affiliates are passed. Single-affiliate callers pass a number as before.
95
+ affiliateBps, affiliate, height) {
93
96
  return __awaiter(this, void 0, void 0, function* () {
94
97
  for (const api of this.quoteApis) {
95
98
  try {
96
99
  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;
100
+ streamingInterval, streamingQuantity, toleranceBps, liquidityToleranceBps, typeof affiliateBps === 'number' ? affiliateBps.toString() : affiliateBps, affiliate)).data;
98
101
  }
99
102
  catch (_e) { }
100
103
  }
@@ -555,14 +558,19 @@ class MayachainQuery {
555
558
  * @returns {QuoteSwap} A quote for the swap operation.
556
559
  */
557
560
  quoteSwap(_a) {
558
- return __awaiter(this, arguments, void 0, function* ({ fromAsset, destinationAsset, amount, destinationAddress, liquidityToleranceBps, toleranceBps, affiliateBps, affiliateAddress, height, streamingInterval, streamingQuantity, }) {
561
+ return __awaiter(this, arguments, void 0, function* ({ fromAsset, destinationAsset, amount, destinationAddress, liquidityToleranceBps, toleranceBps, affiliateBps, affiliateAddress, affiliates, height, streamingInterval, streamingQuantity, }) {
559
562
  const fromAssetString = xchainUtil.assetToString(fromAsset);
560
563
  const toAssetString = xchainUtil.assetToString(destinationAsset);
561
564
  // Endpoint allows 10 decimals for Cacao, 8 for the rest of assets
562
565
  const inputAmount = xchainUtil.eqAsset(fromAsset, CacaoAsset)
563
566
  ? amount.baseAmount.amount()
564
567
  : getBaseAmountWithDiffDecimals(amount, this.getQuoteAssetDecimals(fromAsset));
565
- const swapQuote = yield this.mayachainCache.mayanode.getSwapQuote(fromAssetString, toAssetString, inputAmount.toNumber(), destinationAddress, streamingInterval, streamingQuantity, liquidityToleranceBps, toleranceBps, affiliateBps, affiliateAddress, height);
568
+ // If the caller passed a multi-affiliate array, collapse it into the slash-delimited
569
+ // form the protocol's /quote/swap endpoint accepts. The endpoint requires per-affiliate bps
570
+ // (it does not auto-expand a single shared bps), so both fields are joined in parallel.
571
+ const quoteAffiliateAddress = affiliates ? affiliates.map((a) => a.address).join('/') : affiliateAddress;
572
+ const quoteAffiliateBps = affiliates ? affiliates.map((a) => a.bps).join('/') : affiliateBps;
573
+ const swapQuote = yield this.mayachainCache.mayanode.getSwapQuote(fromAssetString, toAssetString, inputAmount.toNumber(), destinationAddress, streamingInterval, streamingQuantity, liquidityToleranceBps, toleranceBps, quoteAffiliateBps, quoteAffiliateAddress, height);
566
574
  // Check if the response indicates an error by examining memo and other required field
567
575
  const response = JSON.parse(JSON.stringify(swapQuote));
568
576
  if (response.error) {
@@ -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, liquidityToleranceBps, toleranceBps, affiliateBps, affiliateAddress, height, streamingInterval, streamingQuantity, }: QuoteSwapParams): Promise<QuoteSwap>;
35
+ quoteSwap({ fromAsset, destinationAsset, amount, destinationAddress, liquidityToleranceBps, toleranceBps, affiliateBps, affiliateAddress, affiliates, 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
package/lib/types.d.ts CHANGED
@@ -69,6 +69,13 @@ export type QuoteSwap = {
69
69
  errors: string[];
70
70
  warning: string;
71
71
  };
72
+ /**
73
+ * A single affiliate entry. Used by the multi-affiliate `affiliates` field on QuoteSwapParams.
74
+ */
75
+ export type Affiliate = {
76
+ address: string;
77
+ bps: number;
78
+ };
72
79
  /**
73
80
  * Represents parameters for quoting a swap operation.
74
81
  */
@@ -83,6 +90,7 @@ export type QuoteSwapParams = {
83
90
  toleranceBps?: number;
84
91
  affiliateBps?: number;
85
92
  affiliateAddress?: string;
93
+ affiliates?: Affiliate[];
86
94
  streamingInterval?: number;
87
95
  streamingQuantity?: number;
88
96
  };
@@ -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, liquidityToleranceBps?: 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 | string, 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.11",
3
+ "version": "2.2.0",
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": [