@xchainjs/xchain-thorchain-amm 3.0.38 → 3.1.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
@@ -3240,7 +3240,7 @@ class ThorchainAMM {
3240
3240
  * @returns The estimated swap details.
3241
3241
  */
3242
3242
  estimateSwap(_a) {
3243
- return __awaiter(this, arguments, void 0, function* ({ fromAddress, fromAsset, amount, destinationAsset, destinationAddress, affiliateAddress = '', affiliateBps = 0, toleranceBps, liquidityToleranceBps, streamingInterval, streamingQuantity, }) {
3243
+ return __awaiter(this, arguments, void 0, function* ({ fromAddress, fromAsset, amount, destinationAsset, destinationAddress, affiliateAddress = '', affiliateBps = 0, affiliates, toleranceBps, liquidityToleranceBps, streamingInterval, streamingQuantity, }) {
3244
3244
  const errors = yield this.validateSwap({
3245
3245
  fromAddress,
3246
3246
  fromAsset,
@@ -3255,6 +3255,7 @@ class ThorchainAMM {
3255
3255
  destinationAddress,
3256
3256
  affiliateAddress,
3257
3257
  affiliateBps,
3258
+ affiliates,
3258
3259
  toleranceBps,
3259
3260
  liquidityToleranceBps,
3260
3261
  streamingInterval,
@@ -3272,7 +3273,7 @@ class ThorchainAMM {
3272
3273
  * @returns {string[]} the reasons the swap can not be done. If it is empty there are no reason to avoid the swap
3273
3274
  */
3274
3275
  validateSwap(_a) {
3275
- return __awaiter(this, arguments, void 0, function* ({ fromAsset, fromAddress, destinationAsset, destinationAddress, amount, affiliateAddress, affiliateBps, streamingInterval, streamingQuantity, }) {
3276
+ return __awaiter(this, arguments, void 0, function* ({ fromAsset, fromAddress, destinationAsset, destinationAddress, amount, affiliateAddress, affiliateBps, affiliates, streamingInterval, streamingQuantity, }) {
3276
3277
  const errors = [];
3277
3278
  if (destinationAddress &&
3278
3279
  !validateAddress(this.thorchainQuery.thorchainCache.midgardQuery.midgardCache.midgard.network, isSynthAsset(destinationAsset) || isTradeAsset(destinationAsset) || isSecuredAsset(destinationAsset)
@@ -3286,14 +3287,36 @@ class ThorchainAMM {
3286
3287
  if (isTradeAsset(fromAsset) && !isTradeAsset(destinationAsset) && !eqAsset(destinationAsset, AssetRuneNative)) {
3287
3288
  errors.push('Can not make swap from trade asset to non trade asset or non Rune asset. Use withdrawFromTrade (TRADE-) operation');
3288
3289
  }
3289
- if (affiliateAddress) {
3290
- const isThorAddress = validateAddress(this.thorchainQuery.thorchainCache.midgardQuery.midgardCache.midgard.network, THORChain, affiliateAddress);
3291
- const isThorname = !!(yield this.thorchainQuery.thorchainCache.midgardQuery.midgardCache.midgard.getTHORNameDetails(affiliateAddress));
3292
- if (!(isThorAddress || isThorname))
3290
+ // Reject mixing the singular form with the multi-affiliate array — the protocol's quote
3291
+ // endpoint reads them from the same query params, so passing both produces ambiguous wire output.
3292
+ if (affiliates && (affiliateAddress || affiliateBps !== undefined)) {
3293
+ errors.push('affiliates is mutually exclusive with affiliateAddress / affiliateBps; pass one form, not both');
3294
+ }
3295
+ if (affiliates) {
3296
+ if (affiliates.length === 0) {
3297
+ errors.push('affiliates array is empty; omit the field or include at least one entry');
3298
+ }
3299
+ // THORChain consensus caps the affiliate count at 5 per swap (MultipleAffiliatesMaxCount).
3300
+ if (affiliates.length > 5) {
3301
+ errors.push(`affiliates count ${affiliates.length} exceeds THORChain maximum of 5`);
3302
+ }
3303
+ for (const a of affiliates) {
3304
+ const valid = yield this.isThorAffiliateAddress(a.address);
3305
+ if (!valid)
3306
+ errors.push(`affiliate address ${a.address} is not a valid THOR address or THORName`);
3307
+ if (a.bps < 0 || a.bps > 1000) {
3308
+ errors.push(`affiliate bps ${a.bps} for ${a.address} out of range [0 - 1000]`);
3309
+ }
3310
+ }
3311
+ }
3312
+ else if (affiliateAddress) {
3313
+ const valid = yield this.isThorAffiliateAddress(affiliateAddress);
3314
+ if (!valid)
3293
3315
  errors.push(`affiliateAddress ${affiliateAddress} is not a valid THOR address`);
3294
3316
  }
3295
- if (affiliateBps && (affiliateBps < 0 || affiliateBps > 10000)) {
3296
- errors.push(`affiliateBps ${affiliateBps} out of range [0 - 10000]`);
3317
+ // THORChain caps single-affiliate bps at 1000 (10%); previous limit of 10000 was wider than the protocol accepts.
3318
+ if (affiliateBps !== undefined && (affiliateBps < 0 || affiliateBps > 1000)) {
3319
+ errors.push(`affiliateBps ${affiliateBps} out of range [0 - 1000]`);
3297
3320
  }
3298
3321
  if (streamingInterval && streamingInterval < 0) {
3299
3322
  errors.push(`streamingInterval ${streamingInterval} can not be lower than zero`);
@@ -3317,6 +3340,23 @@ class ThorchainAMM {
3317
3340
  return errors;
3318
3341
  });
3319
3342
  }
3343
+ /**
3344
+ * Returns true if the given identifier is either a valid THOR bech32 address or a registered THORName.
3345
+ */
3346
+ isThorAffiliateAddress(identifier) {
3347
+ return __awaiter(this, void 0, void 0, function* () {
3348
+ const network = this.thorchainQuery.thorchainCache.midgardQuery.midgardCache.midgard.network;
3349
+ if (validateAddress(network, THORChain, identifier))
3350
+ return true;
3351
+ try {
3352
+ const thorname = yield this.thorchainQuery.thorchainCache.midgardQuery.midgardCache.midgard.getTHORNameDetails(identifier);
3353
+ return !!thorname;
3354
+ }
3355
+ catch (_a) {
3356
+ return false;
3357
+ }
3358
+ });
3359
+ }
3320
3360
  /**
3321
3361
  * Conducts a swap with the given inputs. This method should be called after estimateSwap() to ensure the swap is valid.
3322
3362
  *
@@ -3325,7 +3365,7 @@ class ThorchainAMM {
3325
3365
  * @returns {SwapSubmitted} - The transaction hash, URL of BlockExplorer, and expected wait time.
3326
3366
  */
3327
3367
  doSwap(_a) {
3328
- return __awaiter(this, arguments, void 0, function* ({ fromAsset, fromAddress, amount, destinationAsset, destinationAddress, affiliateAddress, affiliateBps, toleranceBps, streamingInterval, streamingQuantity, }) {
3368
+ return __awaiter(this, arguments, void 0, function* ({ fromAsset, fromAddress, amount, destinationAsset, destinationAddress, affiliateAddress, affiliateBps, affiliates, toleranceBps, streamingInterval, streamingQuantity, }) {
3329
3369
  // Retrieve swap details from ThorchainQuery to ensure validity
3330
3370
  const txDetails = yield this.thorchainQuery.quoteSwap({
3331
3371
  fromAsset,
@@ -3335,6 +3375,7 @@ class ThorchainAMM {
3335
3375
  destinationAddress,
3336
3376
  affiliateAddress,
3337
3377
  affiliateBps,
3378
+ affiliates,
3338
3379
  toleranceBps,
3339
3380
  streamingInterval,
3340
3381
  streamingQuantity,
package/lib/index.js CHANGED
@@ -3242,7 +3242,7 @@ class ThorchainAMM {
3242
3242
  * @returns The estimated swap details.
3243
3243
  */
3244
3244
  estimateSwap(_a) {
3245
- return __awaiter(this, arguments, void 0, function* ({ fromAddress, fromAsset, amount, destinationAsset, destinationAddress, affiliateAddress = '', affiliateBps = 0, toleranceBps, liquidityToleranceBps, streamingInterval, streamingQuantity, }) {
3245
+ return __awaiter(this, arguments, void 0, function* ({ fromAddress, fromAsset, amount, destinationAsset, destinationAddress, affiliateAddress = '', affiliateBps = 0, affiliates, toleranceBps, liquidityToleranceBps, streamingInterval, streamingQuantity, }) {
3246
3246
  const errors = yield this.validateSwap({
3247
3247
  fromAddress,
3248
3248
  fromAsset,
@@ -3257,6 +3257,7 @@ class ThorchainAMM {
3257
3257
  destinationAddress,
3258
3258
  affiliateAddress,
3259
3259
  affiliateBps,
3260
+ affiliates,
3260
3261
  toleranceBps,
3261
3262
  liquidityToleranceBps,
3262
3263
  streamingInterval,
@@ -3274,7 +3275,7 @@ class ThorchainAMM {
3274
3275
  * @returns {string[]} the reasons the swap can not be done. If it is empty there are no reason to avoid the swap
3275
3276
  */
3276
3277
  validateSwap(_a) {
3277
- return __awaiter(this, arguments, void 0, function* ({ fromAsset, fromAddress, destinationAsset, destinationAddress, amount, affiliateAddress, affiliateBps, streamingInterval, streamingQuantity, }) {
3278
+ return __awaiter(this, arguments, void 0, function* ({ fromAsset, fromAddress, destinationAsset, destinationAddress, amount, affiliateAddress, affiliateBps, affiliates, streamingInterval, streamingQuantity, }) {
3278
3279
  const errors = [];
3279
3280
  if (destinationAddress &&
3280
3281
  !validateAddress(this.thorchainQuery.thorchainCache.midgardQuery.midgardCache.midgard.network, xchainUtil.isSynthAsset(destinationAsset) || xchainUtil.isTradeAsset(destinationAsset) || xchainUtil.isSecuredAsset(destinationAsset)
@@ -3288,14 +3289,36 @@ class ThorchainAMM {
3288
3289
  if (xchainUtil.isTradeAsset(fromAsset) && !xchainUtil.isTradeAsset(destinationAsset) && !xchainUtil.eqAsset(destinationAsset, xchainThorchain.AssetRuneNative)) {
3289
3290
  errors.push('Can not make swap from trade asset to non trade asset or non Rune asset. Use withdrawFromTrade (TRADE-) operation');
3290
3291
  }
3291
- if (affiliateAddress) {
3292
- const isThorAddress = validateAddress(this.thorchainQuery.thorchainCache.midgardQuery.midgardCache.midgard.network, xchainThorchain.THORChain, affiliateAddress);
3293
- const isThorname = !!(yield this.thorchainQuery.thorchainCache.midgardQuery.midgardCache.midgard.getTHORNameDetails(affiliateAddress));
3294
- if (!(isThorAddress || isThorname))
3292
+ // Reject mixing the singular form with the multi-affiliate array — the protocol's quote
3293
+ // endpoint reads them from the same query params, so passing both produces ambiguous wire output.
3294
+ if (affiliates && (affiliateAddress || affiliateBps !== undefined)) {
3295
+ errors.push('affiliates is mutually exclusive with affiliateAddress / affiliateBps; pass one form, not both');
3296
+ }
3297
+ if (affiliates) {
3298
+ if (affiliates.length === 0) {
3299
+ errors.push('affiliates array is empty; omit the field or include at least one entry');
3300
+ }
3301
+ // THORChain consensus caps the affiliate count at 5 per swap (MultipleAffiliatesMaxCount).
3302
+ if (affiliates.length > 5) {
3303
+ errors.push(`affiliates count ${affiliates.length} exceeds THORChain maximum of 5`);
3304
+ }
3305
+ for (const a of affiliates) {
3306
+ const valid = yield this.isThorAffiliateAddress(a.address);
3307
+ if (!valid)
3308
+ errors.push(`affiliate address ${a.address} is not a valid THOR address or THORName`);
3309
+ if (a.bps < 0 || a.bps > 1000) {
3310
+ errors.push(`affiliate bps ${a.bps} for ${a.address} out of range [0 - 1000]`);
3311
+ }
3312
+ }
3313
+ }
3314
+ else if (affiliateAddress) {
3315
+ const valid = yield this.isThorAffiliateAddress(affiliateAddress);
3316
+ if (!valid)
3295
3317
  errors.push(`affiliateAddress ${affiliateAddress} is not a valid THOR address`);
3296
3318
  }
3297
- if (affiliateBps && (affiliateBps < 0 || affiliateBps > 10000)) {
3298
- errors.push(`affiliateBps ${affiliateBps} out of range [0 - 10000]`);
3319
+ // THORChain caps single-affiliate bps at 1000 (10%); previous limit of 10000 was wider than the protocol accepts.
3320
+ if (affiliateBps !== undefined && (affiliateBps < 0 || affiliateBps > 1000)) {
3321
+ errors.push(`affiliateBps ${affiliateBps} out of range [0 - 1000]`);
3299
3322
  }
3300
3323
  if (streamingInterval && streamingInterval < 0) {
3301
3324
  errors.push(`streamingInterval ${streamingInterval} can not be lower than zero`);
@@ -3319,6 +3342,23 @@ class ThorchainAMM {
3319
3342
  return errors;
3320
3343
  });
3321
3344
  }
3345
+ /**
3346
+ * Returns true if the given identifier is either a valid THOR bech32 address or a registered THORName.
3347
+ */
3348
+ isThorAffiliateAddress(identifier) {
3349
+ return __awaiter(this, void 0, void 0, function* () {
3350
+ const network = this.thorchainQuery.thorchainCache.midgardQuery.midgardCache.midgard.network;
3351
+ if (validateAddress(network, xchainThorchain.THORChain, identifier))
3352
+ return true;
3353
+ try {
3354
+ const thorname = yield this.thorchainQuery.thorchainCache.midgardQuery.midgardCache.midgard.getTHORNameDetails(identifier);
3355
+ return !!thorname;
3356
+ }
3357
+ catch (_a) {
3358
+ return false;
3359
+ }
3360
+ });
3361
+ }
3322
3362
  /**
3323
3363
  * Conducts a swap with the given inputs. This method should be called after estimateSwap() to ensure the swap is valid.
3324
3364
  *
@@ -3327,7 +3367,7 @@ class ThorchainAMM {
3327
3367
  * @returns {SwapSubmitted} - The transaction hash, URL of BlockExplorer, and expected wait time.
3328
3368
  */
3329
3369
  doSwap(_a) {
3330
- return __awaiter(this, arguments, void 0, function* ({ fromAsset, fromAddress, amount, destinationAsset, destinationAddress, affiliateAddress, affiliateBps, toleranceBps, streamingInterval, streamingQuantity, }) {
3370
+ return __awaiter(this, arguments, void 0, function* ({ fromAsset, fromAddress, amount, destinationAsset, destinationAddress, affiliateAddress, affiliateBps, affiliates, toleranceBps, streamingInterval, streamingQuantity, }) {
3331
3371
  // Retrieve swap details from ThorchainQuery to ensure validity
3332
3372
  const txDetails = yield this.thorchainQuery.quoteSwap({
3333
3373
  fromAsset,
@@ -3337,6 +3377,7 @@ class ThorchainAMM {
3337
3377
  destinationAddress,
3338
3378
  affiliateAddress,
3339
3379
  affiliateBps,
3380
+ affiliates,
3340
3381
  toleranceBps,
3341
3382
  streamingInterval,
3342
3383
  streamingQuantity,
@@ -26,13 +26,17 @@ export declare class ThorchainAMM {
26
26
 
27
27
  * @returns The estimated swap details.
28
28
  */
29
- estimateSwap({ fromAddress, fromAsset, amount, destinationAsset, destinationAddress, affiliateAddress, affiliateBps, toleranceBps, liquidityToleranceBps, streamingInterval, streamingQuantity, }: QuoteSwapParams): Promise<TxDetails>;
29
+ estimateSwap({ fromAddress, fromAsset, amount, destinationAsset, destinationAddress, affiliateAddress, affiliateBps, affiliates, toleranceBps, liquidityToleranceBps, streamingInterval, streamingQuantity, }: QuoteSwapParams): Promise<TxDetails>;
30
30
  /**
31
31
  * Validate swap params
32
32
  * @param {QuoteSwapParams} quoteSwapParams Swap params
33
33
  * @returns {string[]} the reasons the swap can not be done. If it is empty there are no reason to avoid the swap
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
+ /**
37
+ * Returns true if the given identifier is either a valid THOR bech32 address or a registered THORName.
38
+ */
39
+ private isThorAffiliateAddress;
36
40
  /**
37
41
  * Conducts a swap with the given inputs. This method should be called after estimateSwap() to ensure the swap is valid.
38
42
  *
@@ -40,7 +44,7 @@ export declare class ThorchainAMM {
40
44
  * @param params - The swap parameters.
41
45
  * @returns {SwapSubmitted} - The transaction hash, URL of BlockExplorer, and expected wait time.
42
46
  */
43
- doSwap({ fromAsset, fromAddress, amount, destinationAsset, destinationAddress, affiliateAddress, affiliateBps, toleranceBps, streamingInterval, streamingQuantity, }: QuoteSwapParams): Promise<TxSubmitted>;
47
+ doSwap({ fromAsset, fromAddress, amount, destinationAsset, destinationAddress, affiliateAddress, affiliateBps, affiliates, toleranceBps, streamingInterval, streamingQuantity, }: QuoteSwapParams): Promise<TxSubmitted>;
44
48
  /**
45
49
  * Approve the Thorchain router to spend a certain amount in the asset chain.
46
50
  * @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-thorchain-amm",
3
- "version": "3.0.38",
3
+ "version": "3.1.0",
4
4
  "description": "module that exposes estimating & swappping cryptocurrency assets on thorchain",
5
5
  "keywords": [
6
6
  "THORChain",
@@ -38,24 +38,24 @@
38
38
  "dependencies": {
39
39
  "@xchainjs/xchain-avax": "2.0.18",
40
40
  "@xchainjs/xchain-base": "1.0.18",
41
- "@xchainjs/xchain-bitcoin": "2.2.5",
42
- "@xchainjs/xchain-bitcoincash": "2.2.6",
41
+ "@xchainjs/xchain-bitcoin": "2.2.6",
42
+ "@xchainjs/xchain-bitcoincash": "2.2.7",
43
43
  "@xchainjs/xchain-bsc": "2.0.19",
44
44
  "@xchainjs/xchain-client": "2.0.14",
45
45
  "@xchainjs/xchain-cosmos": "3.0.14",
46
- "@xchainjs/xchain-doge": "2.2.5",
46
+ "@xchainjs/xchain-doge": "2.2.6",
47
47
  "@xchainjs/xchain-ethereum": "2.0.19",
48
48
  "@xchainjs/xchain-evm": "2.0.18",
49
- "@xchainjs/xchain-litecoin": "2.3.2",
49
+ "@xchainjs/xchain-litecoin": "2.3.3",
50
50
  "@xchainjs/xchain-ripple": "1.0.16",
51
51
  "@xchainjs/xchain-solana": "1.1.6",
52
52
  "@xchainjs/xchain-sui": "0.1.3",
53
53
  "@xchainjs/xchain-thorchain": "3.0.18",
54
- "@xchainjs/xchain-thorchain-query": "3.0.5",
54
+ "@xchainjs/xchain-thorchain-query": "3.1.0",
55
55
  "@xchainjs/xchain-tron": "3.0.7",
56
56
  "@xchainjs/xchain-util": "2.0.7",
57
- "@xchainjs/xchain-wallet": "2.0.28",
58
- "@xchainjs/xchain-zcash": "1.3.6",
57
+ "@xchainjs/xchain-wallet": "2.0.29",
58
+ "@xchainjs/xchain-zcash": "1.3.7",
59
59
  "ethers": "^6.14.3"
60
60
  },
61
61
  "devDependencies": {