@xchainjs/xchain-thorchain-amm 0.3.20 → 0.3.22
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 +86 -38
- package/lib/index.js +84 -36
- package/lib/thorchain-amm.d.ts +6 -2
- package/lib/types.d.ts +8 -2
- package/lib/wallet.d.ts +6 -10
- package/package.json +16 -16
package/lib/index.esm.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Client as Client$8, defaultAvaxParams, AVAXChain } from '@xchainjs/xchain-avax';
|
|
1
|
+
import { Client as Client$8, defaultAvaxParams, AVAXChain, AssetAVAX } from '@xchainjs/xchain-avax';
|
|
2
2
|
import { Client as Client$6 } from '@xchainjs/xchain-binance';
|
|
3
3
|
import { Client as Client$1 } from '@xchainjs/xchain-bitcoin';
|
|
4
4
|
import { Client } from '@xchainjs/xchain-bitcoincash';
|
|
5
|
-
import { Client as Client$9, defaultBscParams, BSCChain } from '@xchainjs/xchain-bsc';
|
|
5
|
+
import { Client as Client$9, defaultBscParams, BSCChain, AssetBSC } from '@xchainjs/xchain-bsc';
|
|
6
6
|
import { FeeOption } from '@xchainjs/xchain-client';
|
|
7
7
|
import { Client as Client$7 } from '@xchainjs/xchain-cosmos';
|
|
8
8
|
import { Client as Client$2 } from '@xchainjs/xchain-doge';
|
|
@@ -97,7 +97,7 @@ class EthHelper {
|
|
|
97
97
|
expiry,
|
|
98
98
|
];
|
|
99
99
|
const routerContract = new ethers.Contract(inboundAsgard.router, abi.router);
|
|
100
|
-
const gasLimit = '
|
|
100
|
+
const gasLimit = '160000';
|
|
101
101
|
const unsignedTx = yield routerContract.populateTransaction.depositWithExpiry(...depositParams, {
|
|
102
102
|
from: address,
|
|
103
103
|
value: 0,
|
|
@@ -196,7 +196,7 @@ class EvmHelper {
|
|
|
196
196
|
expiry,
|
|
197
197
|
];
|
|
198
198
|
const routerContract = new ethers.Contract(inboundAsgard.router, abi$1.router);
|
|
199
|
-
const gasLimit = '
|
|
199
|
+
const gasLimit = '160000';
|
|
200
200
|
const unsignedTx = yield routerContract.populateTransaction.depositWithExpiry(...depositParams, {
|
|
201
201
|
from: address,
|
|
202
202
|
value: 0,
|
|
@@ -270,6 +270,11 @@ class Wallet {
|
|
|
270
270
|
this.clients.LTC.setNetwork(settings.network);
|
|
271
271
|
this.clients.LTC.setPhrase(settings.phrase, 0);
|
|
272
272
|
this.ethHelper = new EthHelper(this.clients.ETH, this.thorchainQuery.thorchainCache);
|
|
273
|
+
this.evmHelpers = {
|
|
274
|
+
// ETH: new EvmHelper(this.clients.ETH, this.thorchainQuery.thorchainCache),
|
|
275
|
+
BSC: new EvmHelper(this.clients.BSC, this.thorchainQuery.thorchainCache),
|
|
276
|
+
AVAX: new EvmHelper(this.clients.AVAX, this.thorchainQuery.thorchainCache),
|
|
277
|
+
};
|
|
273
278
|
}
|
|
274
279
|
/**
|
|
275
280
|
* Fetch balances for all wallets
|
|
@@ -278,18 +283,17 @@ class Wallet {
|
|
|
278
283
|
*/
|
|
279
284
|
getAllBalances() {
|
|
280
285
|
return __awaiter(this, void 0, void 0, function* () {
|
|
281
|
-
const
|
|
282
|
-
const
|
|
283
|
-
const
|
|
284
|
-
const address = entry[1].getAddress(0);
|
|
286
|
+
const allBalances = [];
|
|
287
|
+
for (const [chain, client] of Object.entries(this.clients)) {
|
|
288
|
+
const address = client.getAddress(0);
|
|
285
289
|
try {
|
|
286
|
-
const balances = yield
|
|
287
|
-
|
|
290
|
+
const balances = yield client.getBalance(address);
|
|
291
|
+
allBalances.push({ chain, address, balances });
|
|
288
292
|
}
|
|
289
293
|
catch (err) {
|
|
290
|
-
|
|
294
|
+
allBalances.push({ chain, address, balances: err.message });
|
|
291
295
|
}
|
|
292
|
-
}
|
|
296
|
+
}
|
|
293
297
|
return allBalances;
|
|
294
298
|
});
|
|
295
299
|
}
|
|
@@ -302,7 +306,7 @@ class Wallet {
|
|
|
302
306
|
*/
|
|
303
307
|
executeSwap(swap) {
|
|
304
308
|
return __awaiter(this, void 0, void 0, function* () {
|
|
305
|
-
this.validateSwap(swap);
|
|
309
|
+
yield this.validateSwap(swap);
|
|
306
310
|
if (swap.input.asset.chain === THORChain || swap.input.asset.synth) {
|
|
307
311
|
return yield this.swapRuneTo(swap);
|
|
308
312
|
}
|
|
@@ -316,25 +320,54 @@ class Wallet {
|
|
|
316
320
|
* @param swap - swap parameters
|
|
317
321
|
*/
|
|
318
322
|
validateSwap(swap) {
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
const
|
|
329
|
-
if (
|
|
330
|
-
const
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
323
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
324
|
+
const errors = [];
|
|
325
|
+
const isThorchainDestinationAsset = swap.destinationAsset.synth || swap.destinationAsset.chain === THORChain;
|
|
326
|
+
const chain = isThorchainDestinationAsset ? THORChain : swap.destinationAsset.chain;
|
|
327
|
+
// check address
|
|
328
|
+
if (!this.clients[chain].validateAddress(swap.destinationAddress)) {
|
|
329
|
+
errors.push(`destinationAddress ${swap.destinationAddress} is not a valid address`);
|
|
330
|
+
}
|
|
331
|
+
// Affiliate address should be THORName or THORAddress
|
|
332
|
+
const checkAffiliateAddress = swap.memo.split(':');
|
|
333
|
+
if (checkAffiliateAddress.length > 4) {
|
|
334
|
+
const affiliateAddress = checkAffiliateAddress[4];
|
|
335
|
+
if (affiliateAddress.length > 0) {
|
|
336
|
+
const isValidThorchainAddress = this.clients[THORChain].validateAddress(affiliateAddress);
|
|
337
|
+
const isValidThorname = this.isThorname(affiliateAddress);
|
|
338
|
+
if (!(isValidThorchainAddress || isValidThorname))
|
|
339
|
+
errors.push(`affiliateAddress ${affiliateAddress} is not a valid THOR address`);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
if (swap.input.asset.chain === ETHChain) {
|
|
343
|
+
if (eqAsset(swap.input.asset, AssetETH) !== true) {
|
|
344
|
+
const isApprovedResult = yield this.ethHelper.isTCRouterApprovedToSpend(swap.input.asset, swap.input.baseAmount, swap.walletIndex);
|
|
345
|
+
console.log(isApprovedResult);
|
|
346
|
+
if (!isApprovedResult) {
|
|
347
|
+
errors.push('TC router has not been approved to spend this amount');
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
else if (swap.input.asset.chain === AVAXChain) {
|
|
352
|
+
if (eqAsset(swap.input.asset, AssetAVAX) !== true) {
|
|
353
|
+
const isApprovedResult = yield this.evmHelpers[`AVAX`].isTCRouterApprovedToSpend(swap.input.asset, swap.input.baseAmount, swap.walletIndex);
|
|
354
|
+
console.log(isApprovedResult);
|
|
355
|
+
if (!isApprovedResult) {
|
|
356
|
+
errors.push('TC router has not been approved to spend this amount');
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
else if (swap.input.asset.chain === BSCChain) {
|
|
361
|
+
if (eqAsset(swap.input.asset, AssetBSC) !== true) {
|
|
362
|
+
const isApprovedResult = yield this.evmHelpers[`BSC`].isTCRouterApprovedToSpend(swap.input.asset, swap.input.baseAmount, swap.walletIndex);
|
|
363
|
+
console.log(isApprovedResult);
|
|
364
|
+
if (!isApprovedResult) {
|
|
365
|
+
errors.push('TC router has not been approved to spend this amount');
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
return errors;
|
|
370
|
+
});
|
|
338
371
|
}
|
|
339
372
|
isThorname(name) {
|
|
340
373
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -390,8 +423,7 @@ class Wallet {
|
|
|
390
423
|
feeOption: swap.feeOption || FeeOption.Fast,
|
|
391
424
|
memo: swap.memo,
|
|
392
425
|
};
|
|
393
|
-
const
|
|
394
|
-
const hash = yield evmHelper.sendDeposit(params);
|
|
426
|
+
const hash = yield this.evmHelpers['AVAX'].sendDeposit(params);
|
|
395
427
|
return { hash, url: client.getExplorerTxUrl(hash), waitTimeSeconds };
|
|
396
428
|
}
|
|
397
429
|
else if (swap.input.asset.chain === BSCChain) {
|
|
@@ -402,8 +434,7 @@ class Wallet {
|
|
|
402
434
|
feeOption: swap.feeOption || FeeOption.Fast,
|
|
403
435
|
memo: swap.memo,
|
|
404
436
|
};
|
|
405
|
-
const
|
|
406
|
-
const hash = yield evmHelper.sendDeposit(params);
|
|
437
|
+
const hash = yield this.evmHelpers['BSC'].sendDeposit(params);
|
|
407
438
|
return { hash, url: client.getExplorerTxUrl(hash), waitTimeSeconds };
|
|
408
439
|
}
|
|
409
440
|
else {
|
|
@@ -814,9 +845,21 @@ class ThorchainAMM {
|
|
|
814
845
|
|
|
815
846
|
* @returns The SwapEstimate
|
|
816
847
|
*/
|
|
817
|
-
estimateSwap({ input, destinationAsset, destinationAddress, affiliateAddress = '', interfaceID = `555`, affiliateFeeBasisPoints = 0, slipLimit, }) {
|
|
848
|
+
estimateSwap({ input, destinationAsset, destinationAddress, affiliateAddress = '', interfaceID = `555`, affiliateFeeBasisPoints = 0, slipLimit, wallet, walletIndex, }) {
|
|
818
849
|
return __awaiter(this, void 0, void 0, function* () {
|
|
819
|
-
|
|
850
|
+
let errors = [];
|
|
851
|
+
if (wallet) {
|
|
852
|
+
const params = {
|
|
853
|
+
input,
|
|
854
|
+
destinationAsset,
|
|
855
|
+
destinationAddress,
|
|
856
|
+
memo: '',
|
|
857
|
+
waitTimeSeconds: 100,
|
|
858
|
+
walletIndex,
|
|
859
|
+
};
|
|
860
|
+
errors = yield wallet.validateSwap(params);
|
|
861
|
+
}
|
|
862
|
+
const estimate = yield this.thorchainQuery.estimateSwap({
|
|
820
863
|
input,
|
|
821
864
|
destinationAsset,
|
|
822
865
|
destinationAddress,
|
|
@@ -825,6 +868,9 @@ class ThorchainAMM {
|
|
|
825
868
|
affiliateFeeBasisPoints,
|
|
826
869
|
slipLimit,
|
|
827
870
|
});
|
|
871
|
+
estimate.txEstimate.errors.push(...errors);
|
|
872
|
+
estimate.txEstimate.canSwap = errors.length == 0;
|
|
873
|
+
return estimate;
|
|
828
874
|
});
|
|
829
875
|
}
|
|
830
876
|
/**
|
|
@@ -847,6 +893,8 @@ class ThorchainAMM {
|
|
|
847
893
|
destinationAddress: params.destinationAddress,
|
|
848
894
|
memo: txDetails.memo,
|
|
849
895
|
waitTimeSeconds: txDetails.txEstimate.waitTimeSeconds,
|
|
896
|
+
walletIndex: params.walletIndex,
|
|
897
|
+
feeOption: params.feeOption,
|
|
850
898
|
});
|
|
851
899
|
});
|
|
852
900
|
}
|
package/lib/index.js
CHANGED
|
@@ -101,7 +101,7 @@ class EthHelper {
|
|
|
101
101
|
expiry,
|
|
102
102
|
];
|
|
103
103
|
const routerContract = new ethers.ethers.Contract(inboundAsgard.router, xchainEthereum.abi.router);
|
|
104
|
-
const gasLimit = '
|
|
104
|
+
const gasLimit = '160000';
|
|
105
105
|
const unsignedTx = yield routerContract.populateTransaction.depositWithExpiry(...depositParams, {
|
|
106
106
|
from: address,
|
|
107
107
|
value: 0,
|
|
@@ -200,7 +200,7 @@ class EvmHelper {
|
|
|
200
200
|
expiry,
|
|
201
201
|
];
|
|
202
202
|
const routerContract = new ethers.ethers.Contract(inboundAsgard.router, xchainEvm.abi.router);
|
|
203
|
-
const gasLimit = '
|
|
203
|
+
const gasLimit = '160000';
|
|
204
204
|
const unsignedTx = yield routerContract.populateTransaction.depositWithExpiry(...depositParams, {
|
|
205
205
|
from: address,
|
|
206
206
|
value: 0,
|
|
@@ -274,6 +274,11 @@ class Wallet {
|
|
|
274
274
|
this.clients.LTC.setNetwork(settings.network);
|
|
275
275
|
this.clients.LTC.setPhrase(settings.phrase, 0);
|
|
276
276
|
this.ethHelper = new EthHelper(this.clients.ETH, this.thorchainQuery.thorchainCache);
|
|
277
|
+
this.evmHelpers = {
|
|
278
|
+
// ETH: new EvmHelper(this.clients.ETH, this.thorchainQuery.thorchainCache),
|
|
279
|
+
BSC: new EvmHelper(this.clients.BSC, this.thorchainQuery.thorchainCache),
|
|
280
|
+
AVAX: new EvmHelper(this.clients.AVAX, this.thorchainQuery.thorchainCache),
|
|
281
|
+
};
|
|
277
282
|
}
|
|
278
283
|
/**
|
|
279
284
|
* Fetch balances for all wallets
|
|
@@ -282,18 +287,17 @@ class Wallet {
|
|
|
282
287
|
*/
|
|
283
288
|
getAllBalances() {
|
|
284
289
|
return __awaiter(this, void 0, void 0, function* () {
|
|
285
|
-
const
|
|
286
|
-
const
|
|
287
|
-
const
|
|
288
|
-
const address = entry[1].getAddress(0);
|
|
290
|
+
const allBalances = [];
|
|
291
|
+
for (const [chain, client] of Object.entries(this.clients)) {
|
|
292
|
+
const address = client.getAddress(0);
|
|
289
293
|
try {
|
|
290
|
-
const balances = yield
|
|
291
|
-
|
|
294
|
+
const balances = yield client.getBalance(address);
|
|
295
|
+
allBalances.push({ chain, address, balances });
|
|
292
296
|
}
|
|
293
297
|
catch (err) {
|
|
294
|
-
|
|
298
|
+
allBalances.push({ chain, address, balances: err.message });
|
|
295
299
|
}
|
|
296
|
-
}
|
|
300
|
+
}
|
|
297
301
|
return allBalances;
|
|
298
302
|
});
|
|
299
303
|
}
|
|
@@ -306,7 +310,7 @@ class Wallet {
|
|
|
306
310
|
*/
|
|
307
311
|
executeSwap(swap) {
|
|
308
312
|
return __awaiter(this, void 0, void 0, function* () {
|
|
309
|
-
this.validateSwap(swap);
|
|
313
|
+
yield this.validateSwap(swap);
|
|
310
314
|
if (swap.input.asset.chain === xchainThorchain.THORChain || swap.input.asset.synth) {
|
|
311
315
|
return yield this.swapRuneTo(swap);
|
|
312
316
|
}
|
|
@@ -320,25 +324,54 @@ class Wallet {
|
|
|
320
324
|
* @param swap - swap parameters
|
|
321
325
|
*/
|
|
322
326
|
validateSwap(swap) {
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
const
|
|
333
|
-
if (
|
|
334
|
-
const
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
327
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
328
|
+
const errors = [];
|
|
329
|
+
const isThorchainDestinationAsset = swap.destinationAsset.synth || swap.destinationAsset.chain === xchainThorchain.THORChain;
|
|
330
|
+
const chain = isThorchainDestinationAsset ? xchainThorchain.THORChain : swap.destinationAsset.chain;
|
|
331
|
+
// check address
|
|
332
|
+
if (!this.clients[chain].validateAddress(swap.destinationAddress)) {
|
|
333
|
+
errors.push(`destinationAddress ${swap.destinationAddress} is not a valid address`);
|
|
334
|
+
}
|
|
335
|
+
// Affiliate address should be THORName or THORAddress
|
|
336
|
+
const checkAffiliateAddress = swap.memo.split(':');
|
|
337
|
+
if (checkAffiliateAddress.length > 4) {
|
|
338
|
+
const affiliateAddress = checkAffiliateAddress[4];
|
|
339
|
+
if (affiliateAddress.length > 0) {
|
|
340
|
+
const isValidThorchainAddress = this.clients[xchainThorchain.THORChain].validateAddress(affiliateAddress);
|
|
341
|
+
const isValidThorname = this.isThorname(affiliateAddress);
|
|
342
|
+
if (!(isValidThorchainAddress || isValidThorname))
|
|
343
|
+
errors.push(`affiliateAddress ${affiliateAddress} is not a valid THOR address`);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
if (swap.input.asset.chain === xchainEthereum.ETHChain) {
|
|
347
|
+
if (xchainUtil.eqAsset(swap.input.asset, xchainEthereum.AssetETH) !== true) {
|
|
348
|
+
const isApprovedResult = yield this.ethHelper.isTCRouterApprovedToSpend(swap.input.asset, swap.input.baseAmount, swap.walletIndex);
|
|
349
|
+
console.log(isApprovedResult);
|
|
350
|
+
if (!isApprovedResult) {
|
|
351
|
+
errors.push('TC router has not been approved to spend this amount');
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
else if (swap.input.asset.chain === xchainAvax.AVAXChain) {
|
|
356
|
+
if (xchainUtil.eqAsset(swap.input.asset, xchainAvax.AssetAVAX) !== true) {
|
|
357
|
+
const isApprovedResult = yield this.evmHelpers[`AVAX`].isTCRouterApprovedToSpend(swap.input.asset, swap.input.baseAmount, swap.walletIndex);
|
|
358
|
+
console.log(isApprovedResult);
|
|
359
|
+
if (!isApprovedResult) {
|
|
360
|
+
errors.push('TC router has not been approved to spend this amount');
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
else if (swap.input.asset.chain === xchainBsc.BSCChain) {
|
|
365
|
+
if (xchainUtil.eqAsset(swap.input.asset, xchainBsc.AssetBSC) !== true) {
|
|
366
|
+
const isApprovedResult = yield this.evmHelpers[`BSC`].isTCRouterApprovedToSpend(swap.input.asset, swap.input.baseAmount, swap.walletIndex);
|
|
367
|
+
console.log(isApprovedResult);
|
|
368
|
+
if (!isApprovedResult) {
|
|
369
|
+
errors.push('TC router has not been approved to spend this amount');
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
return errors;
|
|
374
|
+
});
|
|
342
375
|
}
|
|
343
376
|
isThorname(name) {
|
|
344
377
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -394,8 +427,7 @@ class Wallet {
|
|
|
394
427
|
feeOption: swap.feeOption || xchainClient.FeeOption.Fast,
|
|
395
428
|
memo: swap.memo,
|
|
396
429
|
};
|
|
397
|
-
const
|
|
398
|
-
const hash = yield evmHelper.sendDeposit(params);
|
|
430
|
+
const hash = yield this.evmHelpers['AVAX'].sendDeposit(params);
|
|
399
431
|
return { hash, url: client.getExplorerTxUrl(hash), waitTimeSeconds };
|
|
400
432
|
}
|
|
401
433
|
else if (swap.input.asset.chain === xchainBsc.BSCChain) {
|
|
@@ -406,8 +438,7 @@ class Wallet {
|
|
|
406
438
|
feeOption: swap.feeOption || xchainClient.FeeOption.Fast,
|
|
407
439
|
memo: swap.memo,
|
|
408
440
|
};
|
|
409
|
-
const
|
|
410
|
-
const hash = yield evmHelper.sendDeposit(params);
|
|
441
|
+
const hash = yield this.evmHelpers['BSC'].sendDeposit(params);
|
|
411
442
|
return { hash, url: client.getExplorerTxUrl(hash), waitTimeSeconds };
|
|
412
443
|
}
|
|
413
444
|
else {
|
|
@@ -818,9 +849,21 @@ class ThorchainAMM {
|
|
|
818
849
|
|
|
819
850
|
* @returns The SwapEstimate
|
|
820
851
|
*/
|
|
821
|
-
estimateSwap({ input, destinationAsset, destinationAddress, affiliateAddress = '', interfaceID = `555`, affiliateFeeBasisPoints = 0, slipLimit, }) {
|
|
852
|
+
estimateSwap({ input, destinationAsset, destinationAddress, affiliateAddress = '', interfaceID = `555`, affiliateFeeBasisPoints = 0, slipLimit, wallet, walletIndex, }) {
|
|
822
853
|
return __awaiter(this, void 0, void 0, function* () {
|
|
823
|
-
|
|
854
|
+
let errors = [];
|
|
855
|
+
if (wallet) {
|
|
856
|
+
const params = {
|
|
857
|
+
input,
|
|
858
|
+
destinationAsset,
|
|
859
|
+
destinationAddress,
|
|
860
|
+
memo: '',
|
|
861
|
+
waitTimeSeconds: 100,
|
|
862
|
+
walletIndex,
|
|
863
|
+
};
|
|
864
|
+
errors = yield wallet.validateSwap(params);
|
|
865
|
+
}
|
|
866
|
+
const estimate = yield this.thorchainQuery.estimateSwap({
|
|
824
867
|
input,
|
|
825
868
|
destinationAsset,
|
|
826
869
|
destinationAddress,
|
|
@@ -829,6 +872,9 @@ class ThorchainAMM {
|
|
|
829
872
|
affiliateFeeBasisPoints,
|
|
830
873
|
slipLimit,
|
|
831
874
|
});
|
|
875
|
+
estimate.txEstimate.errors.push(...errors);
|
|
876
|
+
estimate.txEstimate.canSwap = errors.length == 0;
|
|
877
|
+
return estimate;
|
|
832
878
|
});
|
|
833
879
|
}
|
|
834
880
|
/**
|
|
@@ -851,6 +897,8 @@ class ThorchainAMM {
|
|
|
851
897
|
destinationAddress: params.destinationAddress,
|
|
852
898
|
memo: txDetails.memo,
|
|
853
899
|
waitTimeSeconds: txDetails.txEstimate.waitTimeSeconds,
|
|
900
|
+
walletIndex: params.walletIndex,
|
|
901
|
+
feeOption: params.feeOption,
|
|
854
902
|
});
|
|
855
903
|
});
|
|
856
904
|
}
|
package/lib/thorchain-amm.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { AddliquidityPosition, CryptoAmount, EstimateAddLP, EstimateSwapParams, EstimateWithdrawLP, SaversWithdraw, ThorchainQuery, TxDetails, WithdrawLiquidityPosition } from '@xchainjs/xchain-thorchain-query';
|
|
2
2
|
import { TxSubmitted } from './types';
|
|
3
3
|
import { Wallet } from './wallet';
|
|
4
|
+
export declare type AmmEstimateSwapParams = EstimateSwapParams & {
|
|
5
|
+
wallet: Wallet;
|
|
6
|
+
walletIndex: number;
|
|
7
|
+
};
|
|
4
8
|
/**
|
|
5
9
|
* THORChain Class for interacting with THORChain.
|
|
6
10
|
* Recommended main class to use for swapping with THORChain
|
|
@@ -23,7 +27,7 @@ export declare class ThorchainAMM {
|
|
|
23
27
|
|
|
24
28
|
* @returns The SwapEstimate
|
|
25
29
|
*/
|
|
26
|
-
estimateSwap({ input, destinationAsset, destinationAddress, affiliateAddress, interfaceID, affiliateFeeBasisPoints, slipLimit, }:
|
|
30
|
+
estimateSwap({ input, destinationAsset, destinationAddress, affiliateAddress, interfaceID, affiliateFeeBasisPoints, slipLimit, wallet, walletIndex, }: AmmEstimateSwapParams): Promise<TxDetails>;
|
|
27
31
|
/**
|
|
28
32
|
* Conducts a swap with the given inputs. Should be called after estimateSwap() to ensure the swap is valid
|
|
29
33
|
*
|
|
@@ -31,7 +35,7 @@ export declare class ThorchainAMM {
|
|
|
31
35
|
* @param params - swap params
|
|
32
36
|
* @returns {SwapSubmitted} - Tx Hash, URL of BlockExplorer and expected wait time.
|
|
33
37
|
*/
|
|
34
|
-
doSwap(wallet: Wallet, params:
|
|
38
|
+
doSwap(wallet: Wallet, params: AmmEstimateSwapParams): Promise<TxSubmitted>;
|
|
35
39
|
/**
|
|
36
40
|
* Wraps estimate from thorchain query
|
|
37
41
|
* @param params - estimate add liquidity
|
package/lib/types.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import { FeeOption } from '@xchainjs/xchain-client';
|
|
1
|
+
import { Balance, FeeOption } from '@xchainjs/xchain-client';
|
|
2
2
|
import { CryptoAmount, LiquidityPool } from '@xchainjs/xchain-thorchain-query';
|
|
3
|
-
import { Address, Asset, BaseAmount } from '@xchainjs/xchain-util';
|
|
3
|
+
import { Address, Asset, BaseAmount, Chain } from '@xchainjs/xchain-util';
|
|
4
|
+
export declare type AllBalances = {
|
|
5
|
+
chain: Chain;
|
|
6
|
+
address: string;
|
|
7
|
+
balances: Balance[] | string;
|
|
8
|
+
};
|
|
4
9
|
export declare type ExecuteSwap = {
|
|
5
10
|
input: CryptoAmount;
|
|
6
11
|
destinationAsset: Asset;
|
|
@@ -8,6 +13,7 @@ export declare type ExecuteSwap = {
|
|
|
8
13
|
memo: string;
|
|
9
14
|
feeOption?: FeeOption;
|
|
10
15
|
waitTimeSeconds: number;
|
|
16
|
+
walletIndex: number;
|
|
11
17
|
};
|
|
12
18
|
export declare type TxSubmitted = {
|
|
13
19
|
hash: string;
|
package/lib/wallet.d.ts
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Network, XChainClient } from '@xchainjs/xchain-client';
|
|
2
2
|
import { CryptoAmount, ThorchainQuery } from '@xchainjs/xchain-thorchain-query';
|
|
3
|
-
import { Address
|
|
4
|
-
import { AddLiquidity, ExecuteSwap, TxSubmitted, WithdrawLiquidity } from './types';
|
|
5
|
-
|
|
6
|
-
chain: Chain;
|
|
7
|
-
address: string;
|
|
8
|
-
balances: Balance[] | string;
|
|
9
|
-
};
|
|
3
|
+
import { Address } from '@xchainjs/xchain-util';
|
|
4
|
+
import { AddLiquidity, AllBalances, ExecuteSwap, TxSubmitted, WithdrawLiquidity } from './types';
|
|
5
|
+
import { EvmHelper } from './utils/evm-helper';
|
|
10
6
|
export declare type NodeUrls = Record<Network, string>;
|
|
11
7
|
/**
|
|
12
8
|
* Wallet Class for managing all xchain-* wallets with a mnemonic seed.
|
|
@@ -15,6 +11,7 @@ export declare class Wallet {
|
|
|
15
11
|
private thorchainQuery;
|
|
16
12
|
clients: Record<string, XChainClient>;
|
|
17
13
|
private ethHelper;
|
|
14
|
+
evmHelpers: Record<string, EvmHelper>;
|
|
18
15
|
/**
|
|
19
16
|
* Contructor to create a Wallet
|
|
20
17
|
*
|
|
@@ -41,7 +38,7 @@ export declare class Wallet {
|
|
|
41
38
|
*
|
|
42
39
|
* @param swap - swap parameters
|
|
43
40
|
*/
|
|
44
|
-
|
|
41
|
+
validateSwap(swap: ExecuteSwap): Promise<string[]>;
|
|
45
42
|
private isThorname;
|
|
46
43
|
/** Function handles all swaps from Rune to asset
|
|
47
44
|
*
|
|
@@ -118,4 +115,3 @@ export declare class Wallet {
|
|
|
118
115
|
*/
|
|
119
116
|
private withdrawRuneLP;
|
|
120
117
|
}
|
|
121
|
-
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xchainjs/xchain-thorchain-amm",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.22",
|
|
4
4
|
"description": "module that exposes estimating & swappping cryptocurrency assets on thorchain",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"THORChain",
|
|
@@ -39,22 +39,22 @@
|
|
|
39
39
|
"@binance-chain/javascript-sdk": "^4.2.0",
|
|
40
40
|
"@cosmos-client/core": "0.46.1",
|
|
41
41
|
"@psf/bitcoincashjs-lib": "^4.0.2",
|
|
42
|
-
"@xchainjs/xchain-avax": "^0.1.
|
|
43
|
-
"@xchainjs/xchain-bsc": "^0.1.
|
|
44
|
-
"@xchainjs/xchain-binance": "^5.6.
|
|
45
|
-
"@xchainjs/xchain-bitcoin": "^0.21.
|
|
46
|
-
"@xchainjs/xchain-bitcoincash": "^0.15.
|
|
47
|
-
"@xchainjs/xchain-client": "^0.13.
|
|
48
|
-
"@xchainjs/xchain-cosmos": "^0.20.
|
|
42
|
+
"@xchainjs/xchain-avax": "^0.1.6",
|
|
43
|
+
"@xchainjs/xchain-bsc": "^0.1.3",
|
|
44
|
+
"@xchainjs/xchain-binance": "^5.6.8",
|
|
45
|
+
"@xchainjs/xchain-bitcoin": "^0.21.3",
|
|
46
|
+
"@xchainjs/xchain-bitcoincash": "^0.15.10",
|
|
47
|
+
"@xchainjs/xchain-client": "^0.13.7",
|
|
48
|
+
"@xchainjs/xchain-cosmos": "^0.20.9",
|
|
49
49
|
"@xchainjs/xchain-crypto": "^0.2.6",
|
|
50
|
-
"@xchainjs/xchain-doge": "^0.5.
|
|
51
|
-
"@xchainjs/xchain-ethereum": "^0.27.
|
|
52
|
-
"@xchainjs/xchain-evm": "^0.1.
|
|
53
|
-
"@xchainjs/xchain-litecoin": "^0.11.
|
|
50
|
+
"@xchainjs/xchain-doge": "^0.5.12",
|
|
51
|
+
"@xchainjs/xchain-ethereum": "^0.27.8",
|
|
52
|
+
"@xchainjs/xchain-evm": "^0.1.5",
|
|
53
|
+
"@xchainjs/xchain-litecoin": "^0.11.3",
|
|
54
54
|
"@xchainjs/xchain-midgard": "0.4.3",
|
|
55
55
|
"@xchainjs/xchain-thorchain": "^0.27.9",
|
|
56
|
-
"@xchainjs/xchain-thorchain-query": "^0.2.
|
|
57
|
-
"@xchainjs/xchain-thornode": "^0.2.
|
|
56
|
+
"@xchainjs/xchain-thorchain-query": "^0.2.2",
|
|
57
|
+
"@xchainjs/xchain-thornode": "^0.2.2",
|
|
58
58
|
"@xchainjs/xchain-util": "^0.12.0",
|
|
59
59
|
"@xchainjs/xchain-utxo-providers": "^0.1.1",
|
|
60
60
|
"axios": "^0.25.0",
|
|
@@ -88,8 +88,8 @@
|
|
|
88
88
|
"@xchainjs/xchain-litecoin": "^0.11.1",
|
|
89
89
|
"@xchainjs/xchain-midgard": "0.4.3",
|
|
90
90
|
"@xchainjs/xchain-thorchain": "^0.27.9",
|
|
91
|
-
"@xchainjs/xchain-thorchain-query": "^0.2.
|
|
92
|
-
"@xchainjs/xchain-thornode": "^0.2.
|
|
91
|
+
"@xchainjs/xchain-thorchain-query": "^0.2.2",
|
|
92
|
+
"@xchainjs/xchain-thornode": "^0.2.2",
|
|
93
93
|
"@xchainjs/xchain-util": "^0.12.0",
|
|
94
94
|
"@xchainjs/xchain-utxo-providers": "^0.1.1",
|
|
95
95
|
"axios": "^0.25.0",
|