@xchainjs/xchain-mayachain-amm 4.1.19 → 4.2.1

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
@@ -287,7 +287,7 @@ class MayachainAMM {
287
287
  * @returns {QuoteSwap} Quote swap result. If swap cannot be done, it returns an empty QuoteSwap with reasons.
288
288
  */
289
289
  estimateSwap(_a) {
290
- return __awaiter(this, arguments, void 0, function* ({ fromAsset, fromAddress, amount, destinationAsset, destinationAddress, affiliateAddress, affiliateBps, toleranceBps, liquidityToleranceBps, streamingInterval, streamingQuantity, }) {
290
+ return __awaiter(this, arguments, void 0, function* ({ fromAsset, fromAddress, amount, destinationAsset, destinationAddress, affiliateAddress, affiliateBps, affiliates, toleranceBps, liquidityToleranceBps, streamingInterval, streamingQuantity, }) {
291
291
  const errors = yield this.validateSwap({
292
292
  fromAsset,
293
293
  fromAddress,
@@ -296,6 +296,7 @@ class MayachainAMM {
296
296
  destinationAddress,
297
297
  affiliateAddress,
298
298
  affiliateBps,
299
+ affiliates,
299
300
  streamingInterval,
300
301
  streamingQuantity,
301
302
  });
@@ -332,6 +333,7 @@ class MayachainAMM {
332
333
  destinationAddress,
333
334
  affiliateAddress,
334
335
  affiliateBps,
336
+ affiliates,
335
337
  toleranceBps,
336
338
  liquidityToleranceBps,
337
339
  streamingInterval,
@@ -346,23 +348,48 @@ class MayachainAMM {
346
348
  * @returns {string[]} Reasons the swap cannot be executed. Empty array if the swap is valid.
347
349
  */
348
350
  validateSwap(_a) {
349
- return __awaiter(this, arguments, void 0, function* ({ fromAsset, fromAddress, destinationAsset, destinationAddress, amount, affiliateAddress, affiliateBps, streamingInterval, streamingQuantity, }) {
351
+ return __awaiter(this, arguments, void 0, function* ({ fromAsset, fromAddress, destinationAsset, destinationAddress, amount, affiliateAddress, affiliateBps, affiliates, streamingInterval, streamingQuantity, }) {
350
352
  const errors = [];
351
353
  // Validate destination address if provided
352
354
  if (destinationAddress &&
353
355
  !validateAddress(this.mayachainQuery.getNetwork(), isSynthAsset(destinationAsset) ? MAYAChain : destinationAsset.chain, destinationAddress)) {
354
356
  errors.push(`destinationAddress ${destinationAddress} is not a valid address`);
355
357
  }
356
- // Validate affiliate address if provided
357
- if (affiliateAddress) {
358
+ // Reject mixing the singular form with the multi-affiliate array the protocol's quote
359
+ // endpoint reads them from the same query params, so passing both produces ambiguous wire output.
360
+ if (affiliates && (affiliateAddress || affiliateBps !== undefined)) {
361
+ errors.push('affiliates is mutually exclusive with affiliateAddress / affiliateBps; pass one form, not both');
362
+ }
363
+ // Validate multi-affiliate array if provided
364
+ if (affiliates) {
365
+ if (affiliates.length === 0) {
366
+ errors.push('affiliates array is empty; omit the field or include at least one entry');
367
+ }
368
+ // MAYAChain consensus caps the affiliate count at 5 per swap (MultipleAffiliatesMaxCount).
369
+ if (affiliates.length > 5) {
370
+ errors.push(`affiliates count ${affiliates.length} exceeds MAYAChain maximum of 5`);
371
+ }
372
+ for (const a of affiliates) {
373
+ const isMayaAddress = validateAddress(this.mayachainQuery.getNetwork(), MAYAChain, a.address);
374
+ const isMayaName = yield this.isMAYAName(a.address);
375
+ if (!(isMayaAddress || isMayaName)) {
376
+ errors.push(`affiliate address ${a.address} is not a valid MAYA address or MAYAName`);
377
+ }
378
+ if (a.bps < 0 || a.bps > 500) {
379
+ errors.push(`affiliate bps ${a.bps} for ${a.address} out of range [0 - 500]`);
380
+ }
381
+ }
382
+ }
383
+ else if (affiliateAddress) {
384
+ // Validate single-affiliate address
358
385
  const isMayaAddress = validateAddress(this.mayachainQuery.getNetwork(), MAYAChain, affiliateAddress);
359
386
  const isMayaName = yield this.isMAYAName(affiliateAddress);
360
387
  if (!(isMayaAddress || isMayaName))
361
388
  errors.push(`affiliateAddress ${affiliateAddress} is not a valid MAYA address`);
362
389
  }
363
- // Validate affiliate basis points if provided
364
- if (affiliateBps && (affiliateBps < 0 || affiliateBps > 10000)) {
365
- errors.push(`affiliateBps ${affiliateBps} out of range [0 - 10000]`);
390
+ // MAYAChain caps single-affiliate bps at 500 (5%); previous limit of 10000 was wider than the protocol accepts.
391
+ if (affiliateBps !== undefined && (affiliateBps < 0 || affiliateBps > 500)) {
392
+ errors.push(`affiliateBps ${affiliateBps} out of range [0 - 500]`);
366
393
  }
367
394
  // Validate approval if asset is an ERC20 token and fromAddress is provided
368
395
  if (isProtocolERC20Asset(fromAsset) && fromAddress) {
@@ -400,7 +427,7 @@ class MayachainAMM {
400
427
  * @returns {TxSubmitted} Transaction hash and URL of the swap
401
428
  */
402
429
  doSwap(_a) {
403
- return __awaiter(this, arguments, void 0, function* ({ fromAsset, fromAddress, amount, destinationAsset, destinationAddress, affiliateAddress, affiliateBps, toleranceBps, liquidityToleranceBps, streamingInterval, streamingQuantity, }) {
430
+ return __awaiter(this, arguments, void 0, function* ({ fromAsset, fromAddress, amount, destinationAsset, destinationAddress, affiliateAddress, affiliateBps, affiliates, toleranceBps, liquidityToleranceBps, streamingInterval, streamingQuantity, }) {
404
431
  const quoteSwap = yield this.estimateSwap({
405
432
  fromAsset,
406
433
  fromAddress,
@@ -409,6 +436,7 @@ class MayachainAMM {
409
436
  destinationAddress,
410
437
  affiliateAddress,
411
438
  affiliateBps,
439
+ affiliates,
412
440
  toleranceBps,
413
441
  liquidityToleranceBps,
414
442
  streamingInterval,
package/lib/index.js CHANGED
@@ -289,7 +289,7 @@ class MayachainAMM {
289
289
  * @returns {QuoteSwap} Quote swap result. If swap cannot be done, it returns an empty QuoteSwap with reasons.
290
290
  */
291
291
  estimateSwap(_a) {
292
- return __awaiter(this, arguments, void 0, function* ({ fromAsset, fromAddress, amount, destinationAsset, destinationAddress, affiliateAddress, affiliateBps, toleranceBps, liquidityToleranceBps, streamingInterval, streamingQuantity, }) {
292
+ return __awaiter(this, arguments, void 0, function* ({ fromAsset, fromAddress, amount, destinationAsset, destinationAddress, affiliateAddress, affiliateBps, affiliates, toleranceBps, liquidityToleranceBps, streamingInterval, streamingQuantity, }) {
293
293
  const errors = yield this.validateSwap({
294
294
  fromAsset,
295
295
  fromAddress,
@@ -298,6 +298,7 @@ class MayachainAMM {
298
298
  destinationAddress,
299
299
  affiliateAddress,
300
300
  affiliateBps,
301
+ affiliates,
301
302
  streamingInterval,
302
303
  streamingQuantity,
303
304
  });
@@ -334,6 +335,7 @@ class MayachainAMM {
334
335
  destinationAddress,
335
336
  affiliateAddress,
336
337
  affiliateBps,
338
+ affiliates,
337
339
  toleranceBps,
338
340
  liquidityToleranceBps,
339
341
  streamingInterval,
@@ -348,23 +350,48 @@ class MayachainAMM {
348
350
  * @returns {string[]} Reasons the swap cannot be executed. Empty array if the swap is valid.
349
351
  */
350
352
  validateSwap(_a) {
351
- return __awaiter(this, arguments, void 0, function* ({ fromAsset, fromAddress, destinationAsset, destinationAddress, amount, affiliateAddress, affiliateBps, streamingInterval, streamingQuantity, }) {
353
+ return __awaiter(this, arguments, void 0, function* ({ fromAsset, fromAddress, destinationAsset, destinationAddress, amount, affiliateAddress, affiliateBps, affiliates, streamingInterval, streamingQuantity, }) {
352
354
  const errors = [];
353
355
  // Validate destination address if provided
354
356
  if (destinationAddress &&
355
357
  !validateAddress(this.mayachainQuery.getNetwork(), xchainUtil.isSynthAsset(destinationAsset) ? xchainMayachain.MAYAChain : destinationAsset.chain, destinationAddress)) {
356
358
  errors.push(`destinationAddress ${destinationAddress} is not a valid address`);
357
359
  }
358
- // Validate affiliate address if provided
359
- if (affiliateAddress) {
360
+ // Reject mixing the singular form with the multi-affiliate array the protocol's quote
361
+ // endpoint reads them from the same query params, so passing both produces ambiguous wire output.
362
+ if (affiliates && (affiliateAddress || affiliateBps !== undefined)) {
363
+ errors.push('affiliates is mutually exclusive with affiliateAddress / affiliateBps; pass one form, not both');
364
+ }
365
+ // Validate multi-affiliate array if provided
366
+ if (affiliates) {
367
+ if (affiliates.length === 0) {
368
+ errors.push('affiliates array is empty; omit the field or include at least one entry');
369
+ }
370
+ // MAYAChain consensus caps the affiliate count at 5 per swap (MultipleAffiliatesMaxCount).
371
+ if (affiliates.length > 5) {
372
+ errors.push(`affiliates count ${affiliates.length} exceeds MAYAChain maximum of 5`);
373
+ }
374
+ for (const a of affiliates) {
375
+ const isMayaAddress = validateAddress(this.mayachainQuery.getNetwork(), xchainMayachain.MAYAChain, a.address);
376
+ const isMayaName = yield this.isMAYAName(a.address);
377
+ if (!(isMayaAddress || isMayaName)) {
378
+ errors.push(`affiliate address ${a.address} is not a valid MAYA address or MAYAName`);
379
+ }
380
+ if (a.bps < 0 || a.bps > 500) {
381
+ errors.push(`affiliate bps ${a.bps} for ${a.address} out of range [0 - 500]`);
382
+ }
383
+ }
384
+ }
385
+ else if (affiliateAddress) {
386
+ // Validate single-affiliate address
360
387
  const isMayaAddress = validateAddress(this.mayachainQuery.getNetwork(), xchainMayachain.MAYAChain, affiliateAddress);
361
388
  const isMayaName = yield this.isMAYAName(affiliateAddress);
362
389
  if (!(isMayaAddress || isMayaName))
363
390
  errors.push(`affiliateAddress ${affiliateAddress} is not a valid MAYA address`);
364
391
  }
365
- // Validate affiliate basis points if provided
366
- if (affiliateBps && (affiliateBps < 0 || affiliateBps > 10000)) {
367
- errors.push(`affiliateBps ${affiliateBps} out of range [0 - 10000]`);
392
+ // MAYAChain caps single-affiliate bps at 500 (5%); previous limit of 10000 was wider than the protocol accepts.
393
+ if (affiliateBps !== undefined && (affiliateBps < 0 || affiliateBps > 500)) {
394
+ errors.push(`affiliateBps ${affiliateBps} out of range [0 - 500]`);
368
395
  }
369
396
  // Validate approval if asset is an ERC20 token and fromAddress is provided
370
397
  if (isProtocolERC20Asset(fromAsset) && fromAddress) {
@@ -402,7 +429,7 @@ class MayachainAMM {
402
429
  * @returns {TxSubmitted} Transaction hash and URL of the swap
403
430
  */
404
431
  doSwap(_a) {
405
- return __awaiter(this, arguments, void 0, function* ({ fromAsset, fromAddress, amount, destinationAsset, destinationAddress, affiliateAddress, affiliateBps, toleranceBps, liquidityToleranceBps, streamingInterval, streamingQuantity, }) {
432
+ return __awaiter(this, arguments, void 0, function* ({ fromAsset, fromAddress, amount, destinationAsset, destinationAddress, affiliateAddress, affiliateBps, affiliates, toleranceBps, liquidityToleranceBps, streamingInterval, streamingQuantity, }) {
406
433
  const quoteSwap = yield this.estimateSwap({
407
434
  fromAsset,
408
435
  fromAddress,
@@ -411,6 +438,7 @@ class MayachainAMM {
411
438
  destinationAddress,
412
439
  affiliateAddress,
413
440
  affiliateBps,
441
+ affiliates,
414
442
  toleranceBps,
415
443
  liquidityToleranceBps,
416
444
  streamingInterval,
@@ -25,20 +25,20 @@ export declare class MayachainAMM {
25
25
  * @param {QuoteSwapParams} quoteSwapParams Swap parameters.
26
26
  * @returns {QuoteSwap} Quote swap result. If swap cannot be done, it returns an empty QuoteSwap with reasons.
27
27
  */
28
- estimateSwap({ fromAsset, fromAddress, amount, destinationAsset, destinationAddress, affiliateAddress, affiliateBps, toleranceBps, liquidityToleranceBps, streamingInterval, streamingQuantity, }: QuoteSwapParams): Promise<QuoteSwap>;
28
+ estimateSwap({ fromAsset, fromAddress, amount, destinationAsset, destinationAddress, affiliateAddress, affiliateBps, affiliates, toleranceBps, liquidityToleranceBps, streamingInterval, streamingQuantity, }: QuoteSwapParams): Promise<QuoteSwap>;
29
29
  /**
30
30
  * Validate swap parameters before performing a swap operation.
31
31
  *
32
32
  * @param {QuoteSwapParams} quoteSwapParams Swap parameters.
33
33
  * @returns {string[]} Reasons the swap cannot be executed. Empty array if the swap is valid.
34
34
  */
35
- validateSwap({ fromAsset, fromAddress, destinationAsset, destinationAddress, amount, affiliateAddress, affiliateBps, streamingInterval, streamingQuantity, }: QuoteSwapParams): Promise<string[]>;
35
+ validateSwap({ fromAsset, fromAddress, destinationAsset, destinationAddress, amount, affiliateAddress, affiliateBps, affiliates, streamingInterval, streamingQuantity, }: QuoteSwapParams): Promise<string[]>;
36
36
  /**
37
37
  * Perform a swap operation between assets.
38
38
  * @param {QuoteSwapParams} quoteSwapParams Swap parameters
39
39
  * @returns {TxSubmitted} Transaction hash and URL of the swap
40
40
  */
41
- doSwap({ fromAsset, fromAddress, amount, destinationAsset, destinationAddress, affiliateAddress, affiliateBps, toleranceBps, liquidityToleranceBps, streamingInterval, streamingQuantity, }: QuoteSwapParams): Promise<TxSubmitted>;
41
+ doSwap({ fromAsset, fromAddress, amount, destinationAsset, destinationAddress, affiliateAddress, affiliateBps, affiliates, toleranceBps, liquidityToleranceBps, streamingInterval, streamingQuantity, }: QuoteSwapParams): Promise<TxSubmitted>;
42
42
  /**
43
43
  * Approve the Mayachain router to spend a certain amount in the asset chain.
44
44
  * @param {ApproveParams} approveParams Parameters for approving the router to spend
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xchainjs/xchain-mayachain-amm",
3
- "version": "4.1.19",
3
+ "version": "4.2.1",
4
4
  "description": "module that exposes estimating & swapping cryptocurrency assets on mayachain",
5
5
  "keywords": [
6
6
  "MAYAChain",
@@ -36,22 +36,22 @@
36
36
  "url": "https://github.com/xchainjs/xchainjs-lib/issues"
37
37
  },
38
38
  "dependencies": {
39
- "@xchainjs/xchain-arbitrum": "2.1.4",
40
- "@xchainjs/xchain-bitcoin": "2.2.5",
41
- "@xchainjs/xchain-cardano": "1.2.1",
42
- "@xchainjs/xchain-client": "2.0.14",
43
- "@xchainjs/xchain-crypto": "1.0.6",
44
- "@xchainjs/xchain-dash": "2.2.5",
45
- "@xchainjs/xchain-ethereum": "2.0.19",
46
- "@xchainjs/xchain-evm": "2.0.18",
47
- "@xchainjs/xchain-kujira": "2.0.14",
48
- "@xchainjs/xchain-mayachain": "4.1.5",
49
- "@xchainjs/xchain-mayachain-query": "2.1.11",
50
- "@xchainjs/xchain-radix": "2.0.15",
51
- "@xchainjs/xchain-thorchain": "3.0.18",
39
+ "@xchainjs/xchain-arbitrum": "2.1.5",
40
+ "@xchainjs/xchain-bitcoin": "2.2.7",
41
+ "@xchainjs/xchain-cardano": "1.2.2",
42
+ "@xchainjs/xchain-client": "2.0.15",
43
+ "@xchainjs/xchain-crypto": "1.0.7",
44
+ "@xchainjs/xchain-dash": "2.2.7",
45
+ "@xchainjs/xchain-ethereum": "2.0.20",
46
+ "@xchainjs/xchain-evm": "2.0.19",
47
+ "@xchainjs/xchain-kujira": "2.0.15",
48
+ "@xchainjs/xchain-mayachain": "4.1.6",
49
+ "@xchainjs/xchain-mayachain-query": "2.2.1",
50
+ "@xchainjs/xchain-radix": "2.0.16",
51
+ "@xchainjs/xchain-thorchain": "3.0.19",
52
52
  "@xchainjs/xchain-util": "2.0.7",
53
- "@xchainjs/xchain-wallet": "2.0.28",
54
- "@xchainjs/xchain-zcash": "1.3.6",
53
+ "@xchainjs/xchain-wallet": "2.0.30",
54
+ "@xchainjs/xchain-zcash": "1.3.8",
55
55
  "ethers": "^6.14.3"
56
56
  },
57
57
  "devDependencies": {