@xchainjs/xchain-mayachain-query 2.1.10 → 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/README.md CHANGED
@@ -167,15 +167,4 @@ If you plan on using the publicly accessible endpoints provided by MAYAChain (li
167
167
  - https://midgard.mayachain.info
168
168
  - https://mayanode.mayachain.info
169
169
 
170
- ## Example
171
-
172
- ```typescript
173
- import cosmosclient from '@cosmos-client/core'
174
- import axios from 'axios'
175
- import { register9Rheader } from '@xchainjs/xchain-util'
176
-
177
- register9Rheader(axios)
178
- register9Rheader(cosmosclient.config.globalAxios)
179
- ```
180
-
181
170
  For a complete example please see this [test](https://github.com/xchainjs/xchainjs-lib/blob/master/packages/xchain-mayachain-amm/__e2e__/wallet.e2e.ts)
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
  }
@@ -239,6 +242,7 @@ const KujiraAsset = assetFromStringEx('KUJI.KUJI');
239
242
  const ArbAsset = assetFromStringEx('ARB.ETH');
240
243
  const XdrAsset = assetFromStringEx('XRD.XRD');
241
244
  const ZecAsset = assetFromStringEx('ZEC.ZEC');
245
+ const AdaAsset = assetFromStringEx('ADA.ADA');
242
246
  const BtcChain = 'BTC';
243
247
  const EthChain = 'ETH';
244
248
  const MayaChain = 'MAYA';
@@ -248,6 +252,7 @@ const KujiraChain = 'KUJI';
248
252
  const ArbChain = 'ARB';
249
253
  const XdrChain = 'XRD';
250
254
  const ZecChain = 'ZEC';
255
+ const AdaChain = 'ADA';
251
256
  const DEFAULT_MAYACHAIN_DECIMALS = 8;
252
257
  const MAYA_DECIMAL = 4;
253
258
  const CACAO_DECIMAL = 10;
@@ -545,14 +550,19 @@ class MayachainQuery {
545
550
  * @returns {QuoteSwap} A quote for the swap operation.
546
551
  */
547
552
  quoteSwap(_a) {
548
- 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, }) {
549
554
  const fromAssetString = assetToString(fromAsset);
550
555
  const toAssetString = assetToString(destinationAsset);
551
556
  // Endpoint allows 10 decimals for Cacao, 8 for the rest of assets
552
557
  const inputAmount = eqAsset(fromAsset, CacaoAsset)
553
558
  ? amount.baseAmount.amount()
554
559
  : getBaseAmountWithDiffDecimals(amount, this.getQuoteAssetDecimals(fromAsset));
555
- 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);
556
566
  // Check if the response indicates an error by examining memo and other required field
557
567
  const response = JSON.parse(JSON.stringify(swapQuote));
558
568
  if (response.error) {
@@ -635,6 +645,8 @@ class MayachainQuery {
635
645
  [ArbChain]: new AssetCryptoAmount(baseAmount(0, 18), ArbAsset),
636
646
  [XdrChain]: new AssetCryptoAmount(baseAmount(0, 18), XdrAsset),
637
647
  [ZecChain]: new AssetCryptoAmount(baseAmount(1000, 8), ZecAsset),
648
+ // 1 ADA in lovelace (6 decimals); matches MAYAChain's 1 ADA inbound minimum.
649
+ [AdaChain]: new AssetCryptoAmount(baseAmount(1000000, 6), AdaAsset),
638
650
  };
639
651
  }
640
652
  /**
@@ -983,4 +995,4 @@ class MayachainQuery {
983
995
  }
984
996
  }
985
997
 
986
- export { ArbAsset, ArbChain, BtcAsset, BtcChain, CACAO_DECIMAL, CacaoAsset, DEFAULT_MAYACHAIN_DECIMALS, DashAsset, DashChain, EthAsset, EthChain, KujiraAsset, KujiraChain, MAYA_DECIMAL, MayaAsset, MayaChain, MayachainCache, MayachainQuery, Mayanode, RuneAsset, ThorChain, XdrAsset, XdrChain, ZecAsset, ZecChain, getBaseAmountWithDiffDecimals, getCryptoAmountWithNotation, isCacaoAsset };
998
+ export { AdaAsset, AdaChain, ArbAsset, ArbChain, BtcAsset, BtcChain, CACAO_DECIMAL, CacaoAsset, DEFAULT_MAYACHAIN_DECIMALS, DashAsset, DashChain, EthAsset, EthChain, KujiraAsset, KujiraChain, MAYA_DECIMAL, MayaAsset, MayaChain, MayachainCache, MayachainQuery, Mayanode, RuneAsset, ThorChain, XdrAsset, XdrChain, ZecAsset, ZecChain, getBaseAmountWithDiffDecimals, getCryptoAmountWithNotation, isCacaoAsset };
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
  }
@@ -247,6 +250,7 @@ const KujiraAsset = xchainUtil.assetFromStringEx('KUJI.KUJI');
247
250
  const ArbAsset = xchainUtil.assetFromStringEx('ARB.ETH');
248
251
  const XdrAsset = xchainUtil.assetFromStringEx('XRD.XRD');
249
252
  const ZecAsset = xchainUtil.assetFromStringEx('ZEC.ZEC');
253
+ const AdaAsset = xchainUtil.assetFromStringEx('ADA.ADA');
250
254
  const BtcChain = 'BTC';
251
255
  const EthChain = 'ETH';
252
256
  const MayaChain = 'MAYA';
@@ -256,6 +260,7 @@ const KujiraChain = 'KUJI';
256
260
  const ArbChain = 'ARB';
257
261
  const XdrChain = 'XRD';
258
262
  const ZecChain = 'ZEC';
263
+ const AdaChain = 'ADA';
259
264
  const DEFAULT_MAYACHAIN_DECIMALS = 8;
260
265
  const MAYA_DECIMAL = 4;
261
266
  const CACAO_DECIMAL = 10;
@@ -553,14 +558,19 @@ class MayachainQuery {
553
558
  * @returns {QuoteSwap} A quote for the swap operation.
554
559
  */
555
560
  quoteSwap(_a) {
556
- 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, }) {
557
562
  const fromAssetString = xchainUtil.assetToString(fromAsset);
558
563
  const toAssetString = xchainUtil.assetToString(destinationAsset);
559
564
  // Endpoint allows 10 decimals for Cacao, 8 for the rest of assets
560
565
  const inputAmount = xchainUtil.eqAsset(fromAsset, CacaoAsset)
561
566
  ? amount.baseAmount.amount()
562
567
  : getBaseAmountWithDiffDecimals(amount, this.getQuoteAssetDecimals(fromAsset));
563
- 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);
564
574
  // Check if the response indicates an error by examining memo and other required field
565
575
  const response = JSON.parse(JSON.stringify(swapQuote));
566
576
  if (response.error) {
@@ -643,6 +653,8 @@ class MayachainQuery {
643
653
  [ArbChain]: new xchainUtil.AssetCryptoAmount(xchainUtil.baseAmount(0, 18), ArbAsset),
644
654
  [XdrChain]: new xchainUtil.AssetCryptoAmount(xchainUtil.baseAmount(0, 18), XdrAsset),
645
655
  [ZecChain]: new xchainUtil.AssetCryptoAmount(xchainUtil.baseAmount(1000, 8), ZecAsset),
656
+ // 1 ADA in lovelace (6 decimals); matches MAYAChain's 1 ADA inbound minimum.
657
+ [AdaChain]: new xchainUtil.AssetCryptoAmount(xchainUtil.baseAmount(1000000, 6), AdaAsset),
646
658
  };
647
659
  }
648
660
  /**
@@ -991,6 +1003,8 @@ class MayachainQuery {
991
1003
  }
992
1004
  }
993
1005
 
1006
+ exports.AdaAsset = AdaAsset;
1007
+ exports.AdaChain = AdaChain;
994
1008
  exports.ArbAsset = ArbAsset;
995
1009
  exports.ArbChain = ArbChain;
996
1010
  exports.BtcAsset = BtcAsset;
@@ -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
  };
@@ -9,6 +9,7 @@ export declare const KujiraAsset: Asset;
9
9
  export declare const ArbAsset: Asset;
10
10
  export declare const XdrAsset: Asset;
11
11
  export declare const ZecAsset: Asset;
12
+ export declare const AdaAsset: Asset;
12
13
  export declare const BtcChain = "BTC";
13
14
  export declare const EthChain = "ETH";
14
15
  export declare const MayaChain = "MAYA";
@@ -18,6 +19,7 @@ export declare const KujiraChain = "KUJI";
18
19
  export declare const ArbChain = "ARB";
19
20
  export declare const XdrChain = "XRD";
20
21
  export declare const ZecChain = "ZEC";
22
+ export declare const AdaChain = "ADA";
21
23
  export declare const DEFAULT_MAYACHAIN_DECIMALS = 8;
22
24
  export declare const MAYA_DECIMAL = 4;
23
25
  export declare const CACAO_DECIMAL = 10;
@@ -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.10",
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": [
@@ -33,12 +33,12 @@
33
33
  "postversion": "git push --follow-tags"
34
34
  },
35
35
  "dependencies": {
36
- "@xchainjs/xchain-client": "2.0.13",
37
- "@xchainjs/xchain-mayamidgard": "1.1.2",
38
- "@xchainjs/xchain-mayamidgard-query": "1.0.15",
39
- "@xchainjs/xchain-mayanode": "1.2.2",
36
+ "@xchainjs/xchain-client": "2.0.14",
37
+ "@xchainjs/xchain-mayamidgard": "1.1.3",
38
+ "@xchainjs/xchain-mayamidgard-query": "1.0.16",
39
+ "@xchainjs/xchain-mayanode": "1.2.3",
40
40
  "@xchainjs/xchain-util": "2.0.7",
41
- "axios": "1.15.2",
41
+ "axios": "1.16.1",
42
42
  "axios-retry": "3.2.5",
43
43
  "bignumber.js": "^11.0.0"
44
44
  },