@xchainjs/xchain-mayachain-amm 4.1.18 → 4.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 +49 -13
- package/lib/index.js +49 -13
- package/lib/mayachain-action.d.ts +2 -0
- package/lib/mayachain-amm.d.ts +3 -3
- package/package.json +16 -16
package/lib/index.esm.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AssetAETH, ARBChain, Client as Client$1, defaultArbParams } from '@xchainjs/xchain-arbitrum';
|
|
2
|
+
import { ADAChain, Client, defaultAdaParams } from '@xchainjs/xchain-cardano';
|
|
2
3
|
import { ZECChain, Client as Client$2, defaultZECParams } from '@xchainjs/xchain-zcash';
|
|
3
4
|
import { BTCChain, Client as Client$9, defaultBTCParams } from '@xchainjs/xchain-bitcoin';
|
|
4
5
|
import { Network, Protocol } from '@xchainjs/xchain-client';
|
|
@@ -12,7 +13,6 @@ import { RadixChain, Client as Client$3, AssetXRD, generateAddressParam, generat
|
|
|
12
13
|
import { AssetRuneNative, THORChain, Client as Client$5 } from '@xchainjs/xchain-thorchain';
|
|
13
14
|
import { eqAsset, isSynthAsset, getContractAddressFromAsset, baseAmount, isTradeAsset, CryptoAmount, assetToString, AssetCryptoAmount, AssetType } from '@xchainjs/xchain-util';
|
|
14
15
|
import { Wallet } from '@xchainjs/xchain-wallet';
|
|
15
|
-
import { ADAChain, Client, defaultAdaParams } from '@xchainjs/xchain-cardano';
|
|
16
16
|
import { getAddress, ZeroAddress, Contract } from 'ethers';
|
|
17
17
|
|
|
18
18
|
/******************************************************************************
|
|
@@ -128,12 +128,13 @@ class MayachainAction {
|
|
|
128
128
|
});
|
|
129
129
|
}
|
|
130
130
|
static makeProtocolAction(_a) {
|
|
131
|
-
return __awaiter(this, arguments, void 0, function* ({ wallet, assetAmount, memo }) {
|
|
131
|
+
return __awaiter(this, arguments, void 0, function* ({ wallet, assetAmount, memo, walletIndex, }) {
|
|
132
132
|
const hash = yield wallet.deposit({
|
|
133
133
|
chain: MAYAChain,
|
|
134
134
|
asset: assetAmount.asset,
|
|
135
135
|
amount: assetAmount.baseAmount,
|
|
136
136
|
memo,
|
|
137
|
+
walletIndex,
|
|
137
138
|
});
|
|
138
139
|
return {
|
|
139
140
|
hash,
|
|
@@ -142,15 +143,18 @@ class MayachainAction {
|
|
|
142
143
|
});
|
|
143
144
|
}
|
|
144
145
|
static makeNonProtocolAction(_a) {
|
|
145
|
-
return __awaiter(this, arguments, void 0, function* ({ wallet, assetAmount, recipient, memo, }) {
|
|
146
|
+
return __awaiter(this, arguments, void 0, function* ({ wallet, assetAmount, recipient, memo, walletIndex, }) {
|
|
146
147
|
// Non EVM actions and non Radix action
|
|
147
148
|
if (!isProtocolEVMChain(assetAmount.asset.chain) && !eqAsset(assetAmount.asset, AssetXRD)) {
|
|
148
|
-
|
|
149
|
+
// BFT/Cosmos chains and Cardano derive their fee internally (Cardano from on-chain
|
|
150
|
+
// protocol params) and do not accept a caller-supplied per-byte feeRate, unlike UTXO chains.
|
|
151
|
+
if (isProtocolBFTChain(assetAmount.asset.chain) || assetAmount.asset.chain === ADAChain) {
|
|
149
152
|
const hash = yield wallet.transfer({
|
|
150
153
|
asset: assetAmount.asset,
|
|
151
154
|
amount: assetAmount.baseAmount,
|
|
152
155
|
recipient,
|
|
153
156
|
memo,
|
|
157
|
+
walletIndex,
|
|
154
158
|
});
|
|
155
159
|
return {
|
|
156
160
|
hash,
|
|
@@ -164,6 +168,7 @@ class MayachainAction {
|
|
|
164
168
|
recipient,
|
|
165
169
|
memo,
|
|
166
170
|
feeRate: feeRates.fast,
|
|
171
|
+
walletIndex,
|
|
167
172
|
});
|
|
168
173
|
return {
|
|
169
174
|
hash,
|
|
@@ -191,6 +196,7 @@ class MayachainAction {
|
|
|
191
196
|
generateStringParam(memo),
|
|
192
197
|
],
|
|
193
198
|
},
|
|
199
|
+
walletIndex,
|
|
194
200
|
});
|
|
195
201
|
return {
|
|
196
202
|
hash,
|
|
@@ -223,7 +229,8 @@ class MayachainAction {
|
|
|
223
229
|
isMemoEncoded: true,
|
|
224
230
|
};
|
|
225
231
|
const gasLimit = yield wallet.estimateGasLimit(tx);
|
|
226
|
-
const hash = yield wallet.transfer(Object.assign(Object.assign({}, tx), { gasLimit
|
|
232
|
+
const hash = yield wallet.transfer(Object.assign(Object.assign({}, tx), { gasLimit,
|
|
233
|
+
walletIndex }));
|
|
227
234
|
return {
|
|
228
235
|
hash,
|
|
229
236
|
url: yield wallet.getExplorerTxUrl(assetAmount.asset.chain, hash),
|
|
@@ -268,6 +275,7 @@ class MayachainAMM {
|
|
|
268
275
|
MAYA: new Client$4({ network: Network.Mainnet }),
|
|
269
276
|
XRD: new Client$3({ network: Network.Mainnet }),
|
|
270
277
|
ZEC: new Client$2(Object.assign(Object.assign({}, defaultZECParams), { network: Network.Mainnet })),
|
|
278
|
+
ADA: new Client(Object.assign(Object.assign({}, defaultAdaParams), { network: Network.Mainnet })),
|
|
271
279
|
})) {
|
|
272
280
|
this.mayachainQuery = mayachainQuery;
|
|
273
281
|
this.wallet = wallet;
|
|
@@ -279,7 +287,7 @@ class MayachainAMM {
|
|
|
279
287
|
* @returns {QuoteSwap} Quote swap result. If swap cannot be done, it returns an empty QuoteSwap with reasons.
|
|
280
288
|
*/
|
|
281
289
|
estimateSwap(_a) {
|
|
282
|
-
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, }) {
|
|
283
291
|
const errors = yield this.validateSwap({
|
|
284
292
|
fromAsset,
|
|
285
293
|
fromAddress,
|
|
@@ -288,6 +296,7 @@ class MayachainAMM {
|
|
|
288
296
|
destinationAddress,
|
|
289
297
|
affiliateAddress,
|
|
290
298
|
affiliateBps,
|
|
299
|
+
affiliates,
|
|
291
300
|
streamingInterval,
|
|
292
301
|
streamingQuantity,
|
|
293
302
|
});
|
|
@@ -324,6 +333,7 @@ class MayachainAMM {
|
|
|
324
333
|
destinationAddress,
|
|
325
334
|
affiliateAddress,
|
|
326
335
|
affiliateBps,
|
|
336
|
+
affiliates,
|
|
327
337
|
toleranceBps,
|
|
328
338
|
liquidityToleranceBps,
|
|
329
339
|
streamingInterval,
|
|
@@ -338,23 +348,48 @@ class MayachainAMM {
|
|
|
338
348
|
* @returns {string[]} Reasons the swap cannot be executed. Empty array if the swap is valid.
|
|
339
349
|
*/
|
|
340
350
|
validateSwap(_a) {
|
|
341
|
-
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, }) {
|
|
342
352
|
const errors = [];
|
|
343
353
|
// Validate destination address if provided
|
|
344
354
|
if (destinationAddress &&
|
|
345
355
|
!validateAddress(this.mayachainQuery.getNetwork(), isSynthAsset(destinationAsset) ? MAYAChain : destinationAsset.chain, destinationAddress)) {
|
|
346
356
|
errors.push(`destinationAddress ${destinationAddress} is not a valid address`);
|
|
347
357
|
}
|
|
348
|
-
//
|
|
349
|
-
|
|
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
|
|
350
385
|
const isMayaAddress = validateAddress(this.mayachainQuery.getNetwork(), MAYAChain, affiliateAddress);
|
|
351
386
|
const isMayaName = yield this.isMAYAName(affiliateAddress);
|
|
352
387
|
if (!(isMayaAddress || isMayaName))
|
|
353
388
|
errors.push(`affiliateAddress ${affiliateAddress} is not a valid MAYA address`);
|
|
354
389
|
}
|
|
355
|
-
//
|
|
356
|
-
if (affiliateBps && (affiliateBps < 0 || affiliateBps >
|
|
357
|
-
errors.push(`affiliateBps ${affiliateBps} out of range [0 -
|
|
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]`);
|
|
358
393
|
}
|
|
359
394
|
// Validate approval if asset is an ERC20 token and fromAddress is provided
|
|
360
395
|
if (isProtocolERC20Asset(fromAsset) && fromAddress) {
|
|
@@ -392,7 +427,7 @@ class MayachainAMM {
|
|
|
392
427
|
* @returns {TxSubmitted} Transaction hash and URL of the swap
|
|
393
428
|
*/
|
|
394
429
|
doSwap(_a) {
|
|
395
|
-
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, }) {
|
|
396
431
|
const quoteSwap = yield this.estimateSwap({
|
|
397
432
|
fromAsset,
|
|
398
433
|
fromAddress,
|
|
@@ -401,6 +436,7 @@ class MayachainAMM {
|
|
|
401
436
|
destinationAddress,
|
|
402
437
|
affiliateAddress,
|
|
403
438
|
affiliateBps,
|
|
439
|
+
affiliates,
|
|
404
440
|
toleranceBps,
|
|
405
441
|
liquidityToleranceBps,
|
|
406
442
|
streamingInterval,
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var xchainArbitrum = require('@xchainjs/xchain-arbitrum');
|
|
4
|
+
var xchainCardano = require('@xchainjs/xchain-cardano');
|
|
4
5
|
var xchainZcash = require('@xchainjs/xchain-zcash');
|
|
5
6
|
var xchainBitcoin = require('@xchainjs/xchain-bitcoin');
|
|
6
7
|
var xchainClient = require('@xchainjs/xchain-client');
|
|
@@ -14,7 +15,6 @@ var xchainRadix = require('@xchainjs/xchain-radix');
|
|
|
14
15
|
var xchainThorchain = require('@xchainjs/xchain-thorchain');
|
|
15
16
|
var xchainUtil = require('@xchainjs/xchain-util');
|
|
16
17
|
var xchainWallet = require('@xchainjs/xchain-wallet');
|
|
17
|
-
var xchainCardano = require('@xchainjs/xchain-cardano');
|
|
18
18
|
var ethers = require('ethers');
|
|
19
19
|
|
|
20
20
|
/******************************************************************************
|
|
@@ -130,12 +130,13 @@ class MayachainAction {
|
|
|
130
130
|
});
|
|
131
131
|
}
|
|
132
132
|
static makeProtocolAction(_a) {
|
|
133
|
-
return __awaiter(this, arguments, void 0, function* ({ wallet, assetAmount, memo }) {
|
|
133
|
+
return __awaiter(this, arguments, void 0, function* ({ wallet, assetAmount, memo, walletIndex, }) {
|
|
134
134
|
const hash = yield wallet.deposit({
|
|
135
135
|
chain: xchainMayachain.MAYAChain,
|
|
136
136
|
asset: assetAmount.asset,
|
|
137
137
|
amount: assetAmount.baseAmount,
|
|
138
138
|
memo,
|
|
139
|
+
walletIndex,
|
|
139
140
|
});
|
|
140
141
|
return {
|
|
141
142
|
hash,
|
|
@@ -144,15 +145,18 @@ class MayachainAction {
|
|
|
144
145
|
});
|
|
145
146
|
}
|
|
146
147
|
static makeNonProtocolAction(_a) {
|
|
147
|
-
return __awaiter(this, arguments, void 0, function* ({ wallet, assetAmount, recipient, memo, }) {
|
|
148
|
+
return __awaiter(this, arguments, void 0, function* ({ wallet, assetAmount, recipient, memo, walletIndex, }) {
|
|
148
149
|
// Non EVM actions and non Radix action
|
|
149
150
|
if (!isProtocolEVMChain(assetAmount.asset.chain) && !xchainUtil.eqAsset(assetAmount.asset, xchainRadix.AssetXRD)) {
|
|
150
|
-
|
|
151
|
+
// BFT/Cosmos chains and Cardano derive their fee internally (Cardano from on-chain
|
|
152
|
+
// protocol params) and do not accept a caller-supplied per-byte feeRate, unlike UTXO chains.
|
|
153
|
+
if (isProtocolBFTChain(assetAmount.asset.chain) || assetAmount.asset.chain === xchainCardano.ADAChain) {
|
|
151
154
|
const hash = yield wallet.transfer({
|
|
152
155
|
asset: assetAmount.asset,
|
|
153
156
|
amount: assetAmount.baseAmount,
|
|
154
157
|
recipient,
|
|
155
158
|
memo,
|
|
159
|
+
walletIndex,
|
|
156
160
|
});
|
|
157
161
|
return {
|
|
158
162
|
hash,
|
|
@@ -166,6 +170,7 @@ class MayachainAction {
|
|
|
166
170
|
recipient,
|
|
167
171
|
memo,
|
|
168
172
|
feeRate: feeRates.fast,
|
|
173
|
+
walletIndex,
|
|
169
174
|
});
|
|
170
175
|
return {
|
|
171
176
|
hash,
|
|
@@ -193,6 +198,7 @@ class MayachainAction {
|
|
|
193
198
|
xchainRadix.generateStringParam(memo),
|
|
194
199
|
],
|
|
195
200
|
},
|
|
201
|
+
walletIndex,
|
|
196
202
|
});
|
|
197
203
|
return {
|
|
198
204
|
hash,
|
|
@@ -225,7 +231,8 @@ class MayachainAction {
|
|
|
225
231
|
isMemoEncoded: true,
|
|
226
232
|
};
|
|
227
233
|
const gasLimit = yield wallet.estimateGasLimit(tx);
|
|
228
|
-
const hash = yield wallet.transfer(Object.assign(Object.assign({}, tx), { gasLimit
|
|
234
|
+
const hash = yield wallet.transfer(Object.assign(Object.assign({}, tx), { gasLimit,
|
|
235
|
+
walletIndex }));
|
|
229
236
|
return {
|
|
230
237
|
hash,
|
|
231
238
|
url: yield wallet.getExplorerTxUrl(assetAmount.asset.chain, hash),
|
|
@@ -270,6 +277,7 @@ class MayachainAMM {
|
|
|
270
277
|
MAYA: new xchainMayachain.Client({ network: xchainClient.Network.Mainnet }),
|
|
271
278
|
XRD: new xchainRadix.Client({ network: xchainClient.Network.Mainnet }),
|
|
272
279
|
ZEC: new xchainZcash.Client(Object.assign(Object.assign({}, xchainZcash.defaultZECParams), { network: xchainClient.Network.Mainnet })),
|
|
280
|
+
ADA: new xchainCardano.Client(Object.assign(Object.assign({}, xchainCardano.defaultAdaParams), { network: xchainClient.Network.Mainnet })),
|
|
273
281
|
})) {
|
|
274
282
|
this.mayachainQuery = mayachainQuery;
|
|
275
283
|
this.wallet = wallet;
|
|
@@ -281,7 +289,7 @@ class MayachainAMM {
|
|
|
281
289
|
* @returns {QuoteSwap} Quote swap result. If swap cannot be done, it returns an empty QuoteSwap with reasons.
|
|
282
290
|
*/
|
|
283
291
|
estimateSwap(_a) {
|
|
284
|
-
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, }) {
|
|
285
293
|
const errors = yield this.validateSwap({
|
|
286
294
|
fromAsset,
|
|
287
295
|
fromAddress,
|
|
@@ -290,6 +298,7 @@ class MayachainAMM {
|
|
|
290
298
|
destinationAddress,
|
|
291
299
|
affiliateAddress,
|
|
292
300
|
affiliateBps,
|
|
301
|
+
affiliates,
|
|
293
302
|
streamingInterval,
|
|
294
303
|
streamingQuantity,
|
|
295
304
|
});
|
|
@@ -326,6 +335,7 @@ class MayachainAMM {
|
|
|
326
335
|
destinationAddress,
|
|
327
336
|
affiliateAddress,
|
|
328
337
|
affiliateBps,
|
|
338
|
+
affiliates,
|
|
329
339
|
toleranceBps,
|
|
330
340
|
liquidityToleranceBps,
|
|
331
341
|
streamingInterval,
|
|
@@ -340,23 +350,48 @@ class MayachainAMM {
|
|
|
340
350
|
* @returns {string[]} Reasons the swap cannot be executed. Empty array if the swap is valid.
|
|
341
351
|
*/
|
|
342
352
|
validateSwap(_a) {
|
|
343
|
-
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, }) {
|
|
344
354
|
const errors = [];
|
|
345
355
|
// Validate destination address if provided
|
|
346
356
|
if (destinationAddress &&
|
|
347
357
|
!validateAddress(this.mayachainQuery.getNetwork(), xchainUtil.isSynthAsset(destinationAsset) ? xchainMayachain.MAYAChain : destinationAsset.chain, destinationAddress)) {
|
|
348
358
|
errors.push(`destinationAddress ${destinationAddress} is not a valid address`);
|
|
349
359
|
}
|
|
350
|
-
//
|
|
351
|
-
|
|
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
|
|
352
387
|
const isMayaAddress = validateAddress(this.mayachainQuery.getNetwork(), xchainMayachain.MAYAChain, affiliateAddress);
|
|
353
388
|
const isMayaName = yield this.isMAYAName(affiliateAddress);
|
|
354
389
|
if (!(isMayaAddress || isMayaName))
|
|
355
390
|
errors.push(`affiliateAddress ${affiliateAddress} is not a valid MAYA address`);
|
|
356
391
|
}
|
|
357
|
-
//
|
|
358
|
-
if (affiliateBps && (affiliateBps < 0 || affiliateBps >
|
|
359
|
-
errors.push(`affiliateBps ${affiliateBps} out of range [0 -
|
|
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]`);
|
|
360
395
|
}
|
|
361
396
|
// Validate approval if asset is an ERC20 token and fromAddress is provided
|
|
362
397
|
if (isProtocolERC20Asset(fromAsset) && fromAddress) {
|
|
@@ -394,7 +429,7 @@ class MayachainAMM {
|
|
|
394
429
|
* @returns {TxSubmitted} Transaction hash and URL of the swap
|
|
395
430
|
*/
|
|
396
431
|
doSwap(_a) {
|
|
397
|
-
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, }) {
|
|
398
433
|
const quoteSwap = yield this.estimateSwap({
|
|
399
434
|
fromAsset,
|
|
400
435
|
fromAddress,
|
|
@@ -403,6 +438,7 @@ class MayachainAMM {
|
|
|
403
438
|
destinationAddress,
|
|
404
439
|
affiliateAddress,
|
|
405
440
|
affiliateBps,
|
|
441
|
+
affiliates,
|
|
406
442
|
toleranceBps,
|
|
407
443
|
liquidityToleranceBps,
|
|
408
444
|
streamingInterval,
|
|
@@ -7,11 +7,13 @@ export type NonProtocolActionParams = {
|
|
|
7
7
|
assetAmount: CryptoAmount<Asset | TokenAsset>;
|
|
8
8
|
recipient: Address;
|
|
9
9
|
memo: string;
|
|
10
|
+
walletIndex?: number;
|
|
10
11
|
};
|
|
11
12
|
export type ProtocolActionParams = {
|
|
12
13
|
wallet: Wallet;
|
|
13
14
|
assetAmount: CryptoAmount<CompatibleAsset>;
|
|
14
15
|
memo: string;
|
|
16
|
+
walletIndex?: number;
|
|
15
17
|
};
|
|
16
18
|
export type ActionParams = ProtocolActionParams | NonProtocolActionParams;
|
|
17
19
|
export declare class MayachainAction {
|
package/lib/mayachain-amm.d.ts
CHANGED
|
@@ -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.
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"description": "module that exposes estimating & swapping cryptocurrency assets on mayachain",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MAYAChain",
|
|
@@ -36,27 +36,27 @@
|
|
|
36
36
|
"url": "https://github.com/xchainjs/xchainjs-lib/issues"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@xchainjs/xchain-arbitrum": "2.1.
|
|
40
|
-
"@xchainjs/xchain-bitcoin": "2.2.
|
|
41
|
-
"@xchainjs/xchain-cardano": "1.2.
|
|
42
|
-
"@xchainjs/xchain-client": "2.0.
|
|
39
|
+
"@xchainjs/xchain-arbitrum": "2.1.4",
|
|
40
|
+
"@xchainjs/xchain-bitcoin": "2.2.6",
|
|
41
|
+
"@xchainjs/xchain-cardano": "1.2.1",
|
|
42
|
+
"@xchainjs/xchain-client": "2.0.14",
|
|
43
43
|
"@xchainjs/xchain-crypto": "1.0.6",
|
|
44
|
-
"@xchainjs/xchain-dash": "2.2.
|
|
45
|
-
"@xchainjs/xchain-ethereum": "2.0.
|
|
46
|
-
"@xchainjs/xchain-evm": "2.0.
|
|
47
|
-
"@xchainjs/xchain-kujira": "2.0.
|
|
48
|
-
"@xchainjs/xchain-mayachain": "4.1.
|
|
49
|
-
"@xchainjs/xchain-mayachain-query": "2.
|
|
50
|
-
"@xchainjs/xchain-radix": "2.0.
|
|
51
|
-
"@xchainjs/xchain-thorchain": "3.0.
|
|
44
|
+
"@xchainjs/xchain-dash": "2.2.6",
|
|
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.2.0",
|
|
50
|
+
"@xchainjs/xchain-radix": "2.0.15",
|
|
51
|
+
"@xchainjs/xchain-thorchain": "3.0.18",
|
|
52
52
|
"@xchainjs/xchain-util": "2.0.7",
|
|
53
|
-
"@xchainjs/xchain-wallet": "2.0.
|
|
54
|
-
"@xchainjs/xchain-zcash": "1.3.
|
|
53
|
+
"@xchainjs/xchain-wallet": "2.0.29",
|
|
54
|
+
"@xchainjs/xchain-zcash": "1.3.7",
|
|
55
55
|
"ethers": "^6.14.3"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@ledgerhq/hw-transport-node-hid": "^6.28.6",
|
|
59
|
-
"axios": "1.
|
|
59
|
+
"axios": "1.16.1",
|
|
60
60
|
"axios-mock-adapter": "^2.1.0"
|
|
61
61
|
},
|
|
62
62
|
"publishConfig": {
|