@xchainjs/xchain-thorchain-amm 0.5.1 → 0.5.3
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 +184 -0
- package/lib/index.js +184 -0
- package/lib/thorchain-amm.d.ts +27 -1
- package/lib/types.d.ts +10 -0
- package/lib/wallet.d.ts +3 -1
- package/package.json +33 -31
package/lib/index.esm.js
CHANGED
|
@@ -8,6 +8,7 @@ import { Client as Client$7 } from '@xchainjs/xchain-cosmos';
|
|
|
8
8
|
import { Client as Client$2 } from '@xchainjs/xchain-doge';
|
|
9
9
|
import { AssetETH, abi, ETH_DECIMAL, MAX_APPROVAL, Client as Client$4, ETHChain } from '@xchainjs/xchain-ethereum';
|
|
10
10
|
import { Client as Client$3 } from '@xchainjs/xchain-litecoin';
|
|
11
|
+
import { Client as Client$a, MAYAChain } from '@xchainjs/xchain-mayachain';
|
|
11
12
|
import { Client as Client$5, THORChain } from '@xchainjs/xchain-thorchain';
|
|
12
13
|
import { eqAsset, getContractAddressFromAsset, baseAmount } from '@xchainjs/xchain-util';
|
|
13
14
|
import { ethers } from 'ethers';
|
|
@@ -260,6 +261,7 @@ class Wallet {
|
|
|
260
261
|
GAIA: new Client$7(settings),
|
|
261
262
|
AVAX: new Client$8(Object.assign(Object.assign({}, defaultAvaxParams), { network: settings.network, phrase })),
|
|
262
263
|
BSC: new Client$9(Object.assign(Object.assign({}, defaultBscParams), { network: settings.network, phrase })),
|
|
264
|
+
MAYA: new Client$a(settings),
|
|
263
265
|
};
|
|
264
266
|
this.clients.BCH.setNetwork(settings.network);
|
|
265
267
|
this.clients.BCH.setPhrase(settings.phrase, 0);
|
|
@@ -438,6 +440,18 @@ class Wallet {
|
|
|
438
440
|
const hash = yield this.evmHelpers['BSC'].sendDeposit(params);
|
|
439
441
|
return { hash, url: client.getExplorerTxUrl(hash) };
|
|
440
442
|
}
|
|
443
|
+
else if (swap.input.asset.chain === MAYAChain) {
|
|
444
|
+
// add mayachain
|
|
445
|
+
const params = {
|
|
446
|
+
walletIndex: 0,
|
|
447
|
+
asset: swap.input.asset,
|
|
448
|
+
amount: swap.input.baseAmount,
|
|
449
|
+
recipient: inbound.address,
|
|
450
|
+
memo: swap.memo,
|
|
451
|
+
};
|
|
452
|
+
const hash = yield client.transfer(params);
|
|
453
|
+
return { hash, url: client.getExplorerTxUrl(hash) };
|
|
454
|
+
}
|
|
441
455
|
else {
|
|
442
456
|
const params = {
|
|
443
457
|
walletIndex: 0,
|
|
@@ -653,6 +667,120 @@ class Wallet {
|
|
|
653
667
|
}
|
|
654
668
|
});
|
|
655
669
|
}
|
|
670
|
+
loanOpen(params) {
|
|
671
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
672
|
+
const assetClient = this.clients[params.amount.asset.chain];
|
|
673
|
+
if (params.amount.asset.chain === ETHChain) {
|
|
674
|
+
const addParams = {
|
|
675
|
+
wallIndex: 0,
|
|
676
|
+
asset: params.amount.asset,
|
|
677
|
+
amount: params.amount.baseAmount,
|
|
678
|
+
feeOption: FeeOption.Fast,
|
|
679
|
+
memo: params.memo,
|
|
680
|
+
};
|
|
681
|
+
const hash = yield this.ethHelper.sendDeposit(addParams);
|
|
682
|
+
return { hash, url: assetClient.getExplorerTxUrl(hash) };
|
|
683
|
+
}
|
|
684
|
+
else if (params.amount.asset.chain === AVAXChain) {
|
|
685
|
+
const addParams = {
|
|
686
|
+
wallIndex: 0,
|
|
687
|
+
asset: params.amount.asset,
|
|
688
|
+
amount: params.amount.baseAmount,
|
|
689
|
+
feeOption: FeeOption.Fast,
|
|
690
|
+
memo: params.memo,
|
|
691
|
+
};
|
|
692
|
+
const evmHelper = new EvmHelper(this.clients.AVAX, this.thorchainQuery.thorchainCache);
|
|
693
|
+
const hash = yield evmHelper.sendDeposit(addParams);
|
|
694
|
+
return { hash, url: assetClient.getExplorerTxUrl(hash) };
|
|
695
|
+
}
|
|
696
|
+
else if (params.amount.asset.chain === BSCChain) {
|
|
697
|
+
const addParams = {
|
|
698
|
+
wallIndex: 0,
|
|
699
|
+
asset: params.amount.asset,
|
|
700
|
+
amount: params.amount.baseAmount,
|
|
701
|
+
feeOption: FeeOption.Fast,
|
|
702
|
+
memo: params.memo,
|
|
703
|
+
};
|
|
704
|
+
const evmHelper = new EvmHelper(this.clients.BSC, this.thorchainQuery.thorchainCache);
|
|
705
|
+
const hash = yield evmHelper.sendDeposit(addParams);
|
|
706
|
+
return { hash, url: assetClient.getExplorerTxUrl(hash) };
|
|
707
|
+
}
|
|
708
|
+
else {
|
|
709
|
+
const addParams = {
|
|
710
|
+
wallIndex: 0,
|
|
711
|
+
asset: params.amount.asset,
|
|
712
|
+
amount: params.amount.baseAmount,
|
|
713
|
+
recipient: params.toAddress,
|
|
714
|
+
memo: params.memo,
|
|
715
|
+
};
|
|
716
|
+
try {
|
|
717
|
+
const hash = yield assetClient.transfer(addParams);
|
|
718
|
+
return { hash, url: assetClient.getExplorerTxUrl(hash) };
|
|
719
|
+
}
|
|
720
|
+
catch (err) {
|
|
721
|
+
const hash = JSON.stringify(err);
|
|
722
|
+
return { hash, url: assetClient.getExplorerAddressUrl(assetClient.getAddress()) };
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
});
|
|
726
|
+
}
|
|
727
|
+
loanClose(params) {
|
|
728
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
729
|
+
const assetClient = this.clients[params.amount.asset.chain];
|
|
730
|
+
if (params.amount.asset.chain === ETHChain) {
|
|
731
|
+
const addParams = {
|
|
732
|
+
wallIndex: 0,
|
|
733
|
+
asset: params.amount.asset,
|
|
734
|
+
amount: params.amount.baseAmount,
|
|
735
|
+
feeOption: FeeOption.Fast,
|
|
736
|
+
memo: params.memo,
|
|
737
|
+
};
|
|
738
|
+
const hash = yield this.ethHelper.sendDeposit(addParams);
|
|
739
|
+
return { hash, url: assetClient.getExplorerTxUrl(hash) };
|
|
740
|
+
}
|
|
741
|
+
else if (params.amount.asset.chain === AVAXChain) {
|
|
742
|
+
const addParams = {
|
|
743
|
+
wallIndex: 0,
|
|
744
|
+
asset: params.amount.asset,
|
|
745
|
+
amount: params.amount.baseAmount,
|
|
746
|
+
feeOption: FeeOption.Fast,
|
|
747
|
+
memo: params.memo,
|
|
748
|
+
};
|
|
749
|
+
const evmHelper = new EvmHelper(this.clients.AVAX, this.thorchainQuery.thorchainCache);
|
|
750
|
+
const hash = yield evmHelper.sendDeposit(addParams);
|
|
751
|
+
return { hash, url: assetClient.getExplorerTxUrl(hash) };
|
|
752
|
+
}
|
|
753
|
+
else if (params.amount.asset.chain === BSCChain) {
|
|
754
|
+
const addParams = {
|
|
755
|
+
wallIndex: 0,
|
|
756
|
+
asset: params.amount.asset,
|
|
757
|
+
amount: params.amount.baseAmount,
|
|
758
|
+
feeOption: FeeOption.Fast,
|
|
759
|
+
memo: params.memo,
|
|
760
|
+
};
|
|
761
|
+
const evmHelper = new EvmHelper(this.clients.BSC, this.thorchainQuery.thorchainCache);
|
|
762
|
+
const hash = yield evmHelper.sendDeposit(addParams);
|
|
763
|
+
return { hash, url: assetClient.getExplorerTxUrl(hash) };
|
|
764
|
+
}
|
|
765
|
+
else {
|
|
766
|
+
const addParams = {
|
|
767
|
+
wallIndex: 0,
|
|
768
|
+
asset: params.amount.asset,
|
|
769
|
+
amount: params.amount.baseAmount,
|
|
770
|
+
recipient: params.toAddress,
|
|
771
|
+
memo: params.memo,
|
|
772
|
+
};
|
|
773
|
+
try {
|
|
774
|
+
const hash = yield assetClient.transfer(addParams);
|
|
775
|
+
return { hash, url: assetClient.getExplorerTxUrl(hash) };
|
|
776
|
+
}
|
|
777
|
+
catch (err) {
|
|
778
|
+
const hash = JSON.stringify(err);
|
|
779
|
+
return { hash, url: assetClient.getExplorerAddressUrl(assetClient.getAddress()) };
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
});
|
|
783
|
+
}
|
|
656
784
|
/** Function handles liquidity add for all non rune assets
|
|
657
785
|
*
|
|
658
786
|
* @param params - parameters for add liquidity
|
|
@@ -1019,6 +1147,62 @@ class ThorchainAMM {
|
|
|
1019
1147
|
return yield wallet.withdrawSavers(withdrawEstimate.dustAmount, withdrawEstimate.memo, withdrawEstimate.toAddress);
|
|
1020
1148
|
});
|
|
1021
1149
|
}
|
|
1150
|
+
/**
|
|
1151
|
+
*
|
|
1152
|
+
* @param loanOpenParams
|
|
1153
|
+
* @returns
|
|
1154
|
+
*/
|
|
1155
|
+
getLoanQuoteOpen(loanOpenParams) {
|
|
1156
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1157
|
+
return yield this.thorchainQuery.getLoanQuoteOpen(loanOpenParams);
|
|
1158
|
+
});
|
|
1159
|
+
}
|
|
1160
|
+
/**
|
|
1161
|
+
*
|
|
1162
|
+
* @param loanCloseParams
|
|
1163
|
+
* @returns
|
|
1164
|
+
*/
|
|
1165
|
+
getLoanQuoteClose(loanCloseParams) {
|
|
1166
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1167
|
+
return yield this.thorchainQuery.getLoanQuoteClose(loanCloseParams);
|
|
1168
|
+
});
|
|
1169
|
+
}
|
|
1170
|
+
/**
|
|
1171
|
+
*
|
|
1172
|
+
* @param wallet - wallet needed to execute transaction
|
|
1173
|
+
* @param loanOpenParams - params needed to open the loan
|
|
1174
|
+
* @returns - submitted tx
|
|
1175
|
+
*/
|
|
1176
|
+
addLoan(wallet, loanOpenParams) {
|
|
1177
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1178
|
+
const loanOpen = yield this.thorchainQuery.getLoanQuoteOpen(loanOpenParams);
|
|
1179
|
+
if (loanOpen.errors.length > 0)
|
|
1180
|
+
throw Error(`${loanOpen.errors}`);
|
|
1181
|
+
return yield wallet.loanOpen({
|
|
1182
|
+
memo: `${loanOpen.memo}`,
|
|
1183
|
+
amount: loanOpenParams.amount,
|
|
1184
|
+
toAddress: loanOpen.inboundAddress,
|
|
1185
|
+
});
|
|
1186
|
+
});
|
|
1187
|
+
}
|
|
1188
|
+
/**
|
|
1189
|
+
*
|
|
1190
|
+
* @param wallet - wallet to execute the transaction
|
|
1191
|
+
* @param loanCloseParams - params needed for withdrawing the loan
|
|
1192
|
+
* @returns
|
|
1193
|
+
*/
|
|
1194
|
+
withdrawLoan(wallet, loanCloseParams) {
|
|
1195
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1196
|
+
const withdrawLoan = yield this.thorchainQuery.getLoanQuoteClose(loanCloseParams);
|
|
1197
|
+
if (withdrawLoan.errors.length > 0)
|
|
1198
|
+
throw Error(`${withdrawLoan.errors}`);
|
|
1199
|
+
return yield wallet.loanClose({
|
|
1200
|
+
memo: `${withdrawLoan.memo}`,
|
|
1201
|
+
amount: loanCloseParams.amount,
|
|
1202
|
+
toAddress: withdrawLoan.inboundAddress,
|
|
1203
|
+
});
|
|
1204
|
+
});
|
|
1205
|
+
}
|
|
1022
1206
|
}
|
|
1023
1207
|
|
|
1024
1208
|
export { ThorchainAMM, Wallet };
|
package/lib/index.js
CHANGED
|
@@ -12,6 +12,7 @@ var xchainCosmos = require('@xchainjs/xchain-cosmos');
|
|
|
12
12
|
var xchainDoge = require('@xchainjs/xchain-doge');
|
|
13
13
|
var xchainEthereum = require('@xchainjs/xchain-ethereum');
|
|
14
14
|
var xchainLitecoin = require('@xchainjs/xchain-litecoin');
|
|
15
|
+
var xchainMayachain = require('@xchainjs/xchain-mayachain');
|
|
15
16
|
var xchainThorchain = require('@xchainjs/xchain-thorchain');
|
|
16
17
|
var xchainUtil = require('@xchainjs/xchain-util');
|
|
17
18
|
var ethers = require('ethers');
|
|
@@ -264,6 +265,7 @@ class Wallet {
|
|
|
264
265
|
GAIA: new xchainCosmos.Client(settings),
|
|
265
266
|
AVAX: new xchainAvax.Client(Object.assign(Object.assign({}, xchainAvax.defaultAvaxParams), { network: settings.network, phrase })),
|
|
266
267
|
BSC: new xchainBsc.Client(Object.assign(Object.assign({}, xchainBsc.defaultBscParams), { network: settings.network, phrase })),
|
|
268
|
+
MAYA: new xchainMayachain.Client(settings),
|
|
267
269
|
};
|
|
268
270
|
this.clients.BCH.setNetwork(settings.network);
|
|
269
271
|
this.clients.BCH.setPhrase(settings.phrase, 0);
|
|
@@ -442,6 +444,18 @@ class Wallet {
|
|
|
442
444
|
const hash = yield this.evmHelpers['BSC'].sendDeposit(params);
|
|
443
445
|
return { hash, url: client.getExplorerTxUrl(hash) };
|
|
444
446
|
}
|
|
447
|
+
else if (swap.input.asset.chain === xchainMayachain.MAYAChain) {
|
|
448
|
+
// add mayachain
|
|
449
|
+
const params = {
|
|
450
|
+
walletIndex: 0,
|
|
451
|
+
asset: swap.input.asset,
|
|
452
|
+
amount: swap.input.baseAmount,
|
|
453
|
+
recipient: inbound.address,
|
|
454
|
+
memo: swap.memo,
|
|
455
|
+
};
|
|
456
|
+
const hash = yield client.transfer(params);
|
|
457
|
+
return { hash, url: client.getExplorerTxUrl(hash) };
|
|
458
|
+
}
|
|
445
459
|
else {
|
|
446
460
|
const params = {
|
|
447
461
|
walletIndex: 0,
|
|
@@ -657,6 +671,120 @@ class Wallet {
|
|
|
657
671
|
}
|
|
658
672
|
});
|
|
659
673
|
}
|
|
674
|
+
loanOpen(params) {
|
|
675
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
676
|
+
const assetClient = this.clients[params.amount.asset.chain];
|
|
677
|
+
if (params.amount.asset.chain === xchainEthereum.ETHChain) {
|
|
678
|
+
const addParams = {
|
|
679
|
+
wallIndex: 0,
|
|
680
|
+
asset: params.amount.asset,
|
|
681
|
+
amount: params.amount.baseAmount,
|
|
682
|
+
feeOption: xchainClient.FeeOption.Fast,
|
|
683
|
+
memo: params.memo,
|
|
684
|
+
};
|
|
685
|
+
const hash = yield this.ethHelper.sendDeposit(addParams);
|
|
686
|
+
return { hash, url: assetClient.getExplorerTxUrl(hash) };
|
|
687
|
+
}
|
|
688
|
+
else if (params.amount.asset.chain === xchainAvax.AVAXChain) {
|
|
689
|
+
const addParams = {
|
|
690
|
+
wallIndex: 0,
|
|
691
|
+
asset: params.amount.asset,
|
|
692
|
+
amount: params.amount.baseAmount,
|
|
693
|
+
feeOption: xchainClient.FeeOption.Fast,
|
|
694
|
+
memo: params.memo,
|
|
695
|
+
};
|
|
696
|
+
const evmHelper = new EvmHelper(this.clients.AVAX, this.thorchainQuery.thorchainCache);
|
|
697
|
+
const hash = yield evmHelper.sendDeposit(addParams);
|
|
698
|
+
return { hash, url: assetClient.getExplorerTxUrl(hash) };
|
|
699
|
+
}
|
|
700
|
+
else if (params.amount.asset.chain === xchainBsc.BSCChain) {
|
|
701
|
+
const addParams = {
|
|
702
|
+
wallIndex: 0,
|
|
703
|
+
asset: params.amount.asset,
|
|
704
|
+
amount: params.amount.baseAmount,
|
|
705
|
+
feeOption: xchainClient.FeeOption.Fast,
|
|
706
|
+
memo: params.memo,
|
|
707
|
+
};
|
|
708
|
+
const evmHelper = new EvmHelper(this.clients.BSC, this.thorchainQuery.thorchainCache);
|
|
709
|
+
const hash = yield evmHelper.sendDeposit(addParams);
|
|
710
|
+
return { hash, url: assetClient.getExplorerTxUrl(hash) };
|
|
711
|
+
}
|
|
712
|
+
else {
|
|
713
|
+
const addParams = {
|
|
714
|
+
wallIndex: 0,
|
|
715
|
+
asset: params.amount.asset,
|
|
716
|
+
amount: params.amount.baseAmount,
|
|
717
|
+
recipient: params.toAddress,
|
|
718
|
+
memo: params.memo,
|
|
719
|
+
};
|
|
720
|
+
try {
|
|
721
|
+
const hash = yield assetClient.transfer(addParams);
|
|
722
|
+
return { hash, url: assetClient.getExplorerTxUrl(hash) };
|
|
723
|
+
}
|
|
724
|
+
catch (err) {
|
|
725
|
+
const hash = JSON.stringify(err);
|
|
726
|
+
return { hash, url: assetClient.getExplorerAddressUrl(assetClient.getAddress()) };
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
});
|
|
730
|
+
}
|
|
731
|
+
loanClose(params) {
|
|
732
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
733
|
+
const assetClient = this.clients[params.amount.asset.chain];
|
|
734
|
+
if (params.amount.asset.chain === xchainEthereum.ETHChain) {
|
|
735
|
+
const addParams = {
|
|
736
|
+
wallIndex: 0,
|
|
737
|
+
asset: params.amount.asset,
|
|
738
|
+
amount: params.amount.baseAmount,
|
|
739
|
+
feeOption: xchainClient.FeeOption.Fast,
|
|
740
|
+
memo: params.memo,
|
|
741
|
+
};
|
|
742
|
+
const hash = yield this.ethHelper.sendDeposit(addParams);
|
|
743
|
+
return { hash, url: assetClient.getExplorerTxUrl(hash) };
|
|
744
|
+
}
|
|
745
|
+
else if (params.amount.asset.chain === xchainAvax.AVAXChain) {
|
|
746
|
+
const addParams = {
|
|
747
|
+
wallIndex: 0,
|
|
748
|
+
asset: params.amount.asset,
|
|
749
|
+
amount: params.amount.baseAmount,
|
|
750
|
+
feeOption: xchainClient.FeeOption.Fast,
|
|
751
|
+
memo: params.memo,
|
|
752
|
+
};
|
|
753
|
+
const evmHelper = new EvmHelper(this.clients.AVAX, this.thorchainQuery.thorchainCache);
|
|
754
|
+
const hash = yield evmHelper.sendDeposit(addParams);
|
|
755
|
+
return { hash, url: assetClient.getExplorerTxUrl(hash) };
|
|
756
|
+
}
|
|
757
|
+
else if (params.amount.asset.chain === xchainBsc.BSCChain) {
|
|
758
|
+
const addParams = {
|
|
759
|
+
wallIndex: 0,
|
|
760
|
+
asset: params.amount.asset,
|
|
761
|
+
amount: params.amount.baseAmount,
|
|
762
|
+
feeOption: xchainClient.FeeOption.Fast,
|
|
763
|
+
memo: params.memo,
|
|
764
|
+
};
|
|
765
|
+
const evmHelper = new EvmHelper(this.clients.BSC, this.thorchainQuery.thorchainCache);
|
|
766
|
+
const hash = yield evmHelper.sendDeposit(addParams);
|
|
767
|
+
return { hash, url: assetClient.getExplorerTxUrl(hash) };
|
|
768
|
+
}
|
|
769
|
+
else {
|
|
770
|
+
const addParams = {
|
|
771
|
+
wallIndex: 0,
|
|
772
|
+
asset: params.amount.asset,
|
|
773
|
+
amount: params.amount.baseAmount,
|
|
774
|
+
recipient: params.toAddress,
|
|
775
|
+
memo: params.memo,
|
|
776
|
+
};
|
|
777
|
+
try {
|
|
778
|
+
const hash = yield assetClient.transfer(addParams);
|
|
779
|
+
return { hash, url: assetClient.getExplorerTxUrl(hash) };
|
|
780
|
+
}
|
|
781
|
+
catch (err) {
|
|
782
|
+
const hash = JSON.stringify(err);
|
|
783
|
+
return { hash, url: assetClient.getExplorerAddressUrl(assetClient.getAddress()) };
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
});
|
|
787
|
+
}
|
|
660
788
|
/** Function handles liquidity add for all non rune assets
|
|
661
789
|
*
|
|
662
790
|
* @param params - parameters for add liquidity
|
|
@@ -1023,6 +1151,62 @@ class ThorchainAMM {
|
|
|
1023
1151
|
return yield wallet.withdrawSavers(withdrawEstimate.dustAmount, withdrawEstimate.memo, withdrawEstimate.toAddress);
|
|
1024
1152
|
});
|
|
1025
1153
|
}
|
|
1154
|
+
/**
|
|
1155
|
+
*
|
|
1156
|
+
* @param loanOpenParams
|
|
1157
|
+
* @returns
|
|
1158
|
+
*/
|
|
1159
|
+
getLoanQuoteOpen(loanOpenParams) {
|
|
1160
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1161
|
+
return yield this.thorchainQuery.getLoanQuoteOpen(loanOpenParams);
|
|
1162
|
+
});
|
|
1163
|
+
}
|
|
1164
|
+
/**
|
|
1165
|
+
*
|
|
1166
|
+
* @param loanCloseParams
|
|
1167
|
+
* @returns
|
|
1168
|
+
*/
|
|
1169
|
+
getLoanQuoteClose(loanCloseParams) {
|
|
1170
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1171
|
+
return yield this.thorchainQuery.getLoanQuoteClose(loanCloseParams);
|
|
1172
|
+
});
|
|
1173
|
+
}
|
|
1174
|
+
/**
|
|
1175
|
+
*
|
|
1176
|
+
* @param wallet - wallet needed to execute transaction
|
|
1177
|
+
* @param loanOpenParams - params needed to open the loan
|
|
1178
|
+
* @returns - submitted tx
|
|
1179
|
+
*/
|
|
1180
|
+
addLoan(wallet, loanOpenParams) {
|
|
1181
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1182
|
+
const loanOpen = yield this.thorchainQuery.getLoanQuoteOpen(loanOpenParams);
|
|
1183
|
+
if (loanOpen.errors.length > 0)
|
|
1184
|
+
throw Error(`${loanOpen.errors}`);
|
|
1185
|
+
return yield wallet.loanOpen({
|
|
1186
|
+
memo: `${loanOpen.memo}`,
|
|
1187
|
+
amount: loanOpenParams.amount,
|
|
1188
|
+
toAddress: loanOpen.inboundAddress,
|
|
1189
|
+
});
|
|
1190
|
+
});
|
|
1191
|
+
}
|
|
1192
|
+
/**
|
|
1193
|
+
*
|
|
1194
|
+
* @param wallet - wallet to execute the transaction
|
|
1195
|
+
* @param loanCloseParams - params needed for withdrawing the loan
|
|
1196
|
+
* @returns
|
|
1197
|
+
*/
|
|
1198
|
+
withdrawLoan(wallet, loanCloseParams) {
|
|
1199
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1200
|
+
const withdrawLoan = yield this.thorchainQuery.getLoanQuoteClose(loanCloseParams);
|
|
1201
|
+
if (withdrawLoan.errors.length > 0)
|
|
1202
|
+
throw Error(`${withdrawLoan.errors}`);
|
|
1203
|
+
return yield wallet.loanClose({
|
|
1204
|
+
memo: `${withdrawLoan.memo}`,
|
|
1205
|
+
amount: loanCloseParams.amount,
|
|
1206
|
+
toAddress: withdrawLoan.inboundAddress,
|
|
1207
|
+
});
|
|
1208
|
+
});
|
|
1209
|
+
}
|
|
1026
1210
|
}
|
|
1027
1211
|
|
|
1028
1212
|
exports.ThorchainAMM = ThorchainAMM;
|
package/lib/thorchain-amm.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AddliquidityPosition, CryptoAmount, EstimateAddLP, EstimateAddSaver, EstimateWithdrawLP, EstimateWithdrawSaver, QuoteSwapParams, SaversPosition, SaversWithdraw, ThorchainQuery, TxDetails, WithdrawLiquidityPosition, getSaver } from '@xchainjs/xchain-thorchain-query';
|
|
1
|
+
import { AddliquidityPosition, CryptoAmount, EstimateAddLP, EstimateAddSaver, EstimateWithdrawLP, EstimateWithdrawSaver, LoanCloseParams, LoanCloseQuote, LoanOpenParams, LoanOpenQuote, QuoteSwapParams, SaversPosition, SaversWithdraw, ThorchainQuery, TxDetails, WithdrawLiquidityPosition, getSaver } from '@xchainjs/xchain-thorchain-query';
|
|
2
2
|
import { TxSubmitted } from './types';
|
|
3
3
|
import { Wallet } from './wallet';
|
|
4
4
|
export type AmmEstimateSwapParams = QuoteSwapParams & {
|
|
@@ -94,4 +94,30 @@ export declare class ThorchainAMM {
|
|
|
94
94
|
* @returns
|
|
95
95
|
*/
|
|
96
96
|
withdrawSaver(wallet: Wallet, withdrawParams: SaversWithdraw): Promise<TxSubmitted>;
|
|
97
|
+
/**
|
|
98
|
+
*
|
|
99
|
+
* @param loanOpenParams
|
|
100
|
+
* @returns
|
|
101
|
+
*/
|
|
102
|
+
getLoanQuoteOpen(loanOpenParams: LoanOpenParams): Promise<LoanOpenQuote>;
|
|
103
|
+
/**
|
|
104
|
+
*
|
|
105
|
+
* @param loanCloseParams
|
|
106
|
+
* @returns
|
|
107
|
+
*/
|
|
108
|
+
getLoanQuoteClose(loanCloseParams: LoanCloseParams): Promise<LoanCloseQuote>;
|
|
109
|
+
/**
|
|
110
|
+
*
|
|
111
|
+
* @param wallet - wallet needed to execute transaction
|
|
112
|
+
* @param loanOpenParams - params needed to open the loan
|
|
113
|
+
* @returns - submitted tx
|
|
114
|
+
*/
|
|
115
|
+
addLoan(wallet: Wallet, loanOpenParams: LoanOpenParams): Promise<TxSubmitted>;
|
|
116
|
+
/**
|
|
117
|
+
*
|
|
118
|
+
* @param wallet - wallet to execute the transaction
|
|
119
|
+
* @param loanCloseParams - params needed for withdrawing the loan
|
|
120
|
+
* @returns
|
|
121
|
+
*/
|
|
122
|
+
withdrawLoan(wallet: Wallet, loanCloseParams: LoanCloseParams): Promise<TxSubmitted>;
|
|
97
123
|
}
|
package/lib/types.d.ts
CHANGED
|
@@ -46,3 +46,13 @@ export type DepositParams = {
|
|
|
46
46
|
feeOption: FeeOption;
|
|
47
47
|
memo: string;
|
|
48
48
|
};
|
|
49
|
+
export type LoanOpenParams = {
|
|
50
|
+
memo: string;
|
|
51
|
+
amount: CryptoAmount;
|
|
52
|
+
toAddress: Address;
|
|
53
|
+
};
|
|
54
|
+
export type LoanCloseParams = {
|
|
55
|
+
memo: string;
|
|
56
|
+
amount: CryptoAmount;
|
|
57
|
+
toAddress: Address;
|
|
58
|
+
};
|
package/lib/wallet.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Network, XChainClient } from '@xchainjs/xchain-client';
|
|
2
2
|
import { CryptoAmount, ThorchainQuery } from '@xchainjs/xchain-thorchain-query';
|
|
3
3
|
import { Address } from '@xchainjs/xchain-util';
|
|
4
|
-
import { AddLiquidity, AllBalances, ExecuteSwap, TxSubmitted, WithdrawLiquidity } from './types';
|
|
4
|
+
import { AddLiquidity, AllBalances, ExecuteSwap, LoanCloseParams, LoanOpenParams, TxSubmitted, WithdrawLiquidity } from './types';
|
|
5
5
|
import { EvmHelper } from './utils/evm-helper';
|
|
6
6
|
export type NodeUrls = Record<Network, string>;
|
|
7
7
|
/**
|
|
@@ -80,6 +80,8 @@ export declare class Wallet {
|
|
|
80
80
|
* @returns
|
|
81
81
|
*/
|
|
82
82
|
withdrawSavers(dustAssetAmount: CryptoAmount, memo: string, toAddress: Address): Promise<TxSubmitted>;
|
|
83
|
+
loanOpen(params: LoanOpenParams): Promise<TxSubmitted>;
|
|
84
|
+
loanClose(params: LoanCloseParams): Promise<TxSubmitted>;
|
|
83
85
|
/** Function handles liquidity add for all non rune assets
|
|
84
86
|
*
|
|
85
87
|
* @param params - parameters for add liquidity
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xchainjs/xchain-thorchain-amm",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.3",
|
|
4
4
|
"description": "module that exposes estimating & swappping cryptocurrency assets on thorchain",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"THORChain",
|
|
@@ -39,24 +39,25 @@
|
|
|
39
39
|
"@binance-chain/javascript-sdk": "^4.2.0",
|
|
40
40
|
"@cosmos-client/core": "0.46.1",
|
|
41
41
|
"@psf/bitcoincashjs-lib": "^4.0.3",
|
|
42
|
-
"@xchainjs/xchain-avax": "^0.2.
|
|
43
|
-
"@xchainjs/xchain-bsc": "^0.2.
|
|
44
|
-
"@xchainjs/xchain-binance": "^5.7.
|
|
45
|
-
"@xchainjs/xchain-bitcoin": "^0.22.
|
|
46
|
-
"@xchainjs/xchain-bitcoincash": "^0.16.
|
|
47
|
-
"@xchainjs/xchain-client": "^0.14.
|
|
48
|
-
"@xchainjs/xchain-cosmos": "^0.21.
|
|
42
|
+
"@xchainjs/xchain-avax": "^0.2.2",
|
|
43
|
+
"@xchainjs/xchain-bsc": "^0.2.2",
|
|
44
|
+
"@xchainjs/xchain-binance": "^5.7.1",
|
|
45
|
+
"@xchainjs/xchain-bitcoin": "^0.22.1",
|
|
46
|
+
"@xchainjs/xchain-bitcoincash": "^0.16.1",
|
|
47
|
+
"@xchainjs/xchain-client": "^0.14.1",
|
|
48
|
+
"@xchainjs/xchain-cosmos": "^0.21.1",
|
|
49
49
|
"@xchainjs/xchain-crypto": "^0.3.0",
|
|
50
|
-
"@xchainjs/xchain-doge": "^0.6.
|
|
51
|
-
"@xchainjs/xchain-ethereum": "^0.28.
|
|
52
|
-
"@xchainjs/xchain-evm": "^0.2.
|
|
53
|
-
"@xchainjs/xchain-litecoin": "^0.12.
|
|
50
|
+
"@xchainjs/xchain-doge": "^0.6.1",
|
|
51
|
+
"@xchainjs/xchain-ethereum": "^0.28.2",
|
|
52
|
+
"@xchainjs/xchain-evm": "^0.2.2",
|
|
53
|
+
"@xchainjs/xchain-litecoin": "^0.12.1",
|
|
54
54
|
"@xchainjs/xchain-midgard": "^0.5.0",
|
|
55
|
-
"@xchainjs/xchain-
|
|
56
|
-
"@xchainjs/xchain-thorchain
|
|
57
|
-
"@xchainjs/xchain-
|
|
55
|
+
"@xchainjs/xchain-mayachain": "^0.2.1",
|
|
56
|
+
"@xchainjs/xchain-thorchain": "^0.28.1",
|
|
57
|
+
"@xchainjs/xchain-thorchain-query": "^0.4.3",
|
|
58
|
+
"@xchainjs/xchain-thornode": "^0.3.2",
|
|
58
59
|
"@xchainjs/xchain-util": "^0.13.0",
|
|
59
|
-
"@xchainjs/xchain-utxo-providers": "^0.2.
|
|
60
|
+
"@xchainjs/xchain-utxo-providers": "^0.2.1",
|
|
60
61
|
"axios": "^1.3.6",
|
|
61
62
|
"axios-retry": "^3.2.5",
|
|
62
63
|
"bchaddrjs": "^0.5.2",
|
|
@@ -74,24 +75,25 @@
|
|
|
74
75
|
"@binance-chain/javascript-sdk": "^4.2.0",
|
|
75
76
|
"@cosmos-client/core": "0.46.1",
|
|
76
77
|
"@psf/bitcoincashjs-lib": "^4.0.3",
|
|
77
|
-
"@xchainjs/xchain-avax": "^0.2.
|
|
78
|
-
"@xchainjs/xchain-bsc": "^0.2.
|
|
79
|
-
"@xchainjs/xchain-binance": "^5.7.
|
|
80
|
-
"@xchainjs/xchain-bitcoin": "^0.22.
|
|
81
|
-
"@xchainjs/xchain-bitcoincash": "^0.16.
|
|
82
|
-
"@xchainjs/xchain-client": "^0.14.
|
|
83
|
-
"@xchainjs/xchain-cosmos": "^0.21.
|
|
78
|
+
"@xchainjs/xchain-avax": "^0.2.2",
|
|
79
|
+
"@xchainjs/xchain-bsc": "^0.2.2",
|
|
80
|
+
"@xchainjs/xchain-binance": "^5.7.1",
|
|
81
|
+
"@xchainjs/xchain-bitcoin": "^0.22.1",
|
|
82
|
+
"@xchainjs/xchain-bitcoincash": "^0.16.1",
|
|
83
|
+
"@xchainjs/xchain-client": "^0.14.1",
|
|
84
|
+
"@xchainjs/xchain-cosmos": "^0.21.1",
|
|
84
85
|
"@xchainjs/xchain-crypto": "^0.3.0",
|
|
85
|
-
"@xchainjs/xchain-doge": "^0.6.
|
|
86
|
-
"@xchainjs/xchain-ethereum": "^0.28.
|
|
87
|
-
"@xchainjs/xchain-evm": "^0.2.
|
|
88
|
-
"@xchainjs/xchain-litecoin": "^0.12.
|
|
86
|
+
"@xchainjs/xchain-doge": "^0.6.1",
|
|
87
|
+
"@xchainjs/xchain-ethereum": "^0.28.2",
|
|
88
|
+
"@xchainjs/xchain-evm": "^0.2.2",
|
|
89
|
+
"@xchainjs/xchain-litecoin": "^0.12.1",
|
|
89
90
|
"@xchainjs/xchain-midgard": "^0.5.0",
|
|
90
|
-
"@xchainjs/xchain-
|
|
91
|
-
"@xchainjs/xchain-thorchain
|
|
92
|
-
"@xchainjs/xchain-
|
|
91
|
+
"@xchainjs/xchain-mayachain": "^0.2.1",
|
|
92
|
+
"@xchainjs/xchain-thorchain": "^0.28.1",
|
|
93
|
+
"@xchainjs/xchain-thorchain-query": "^0.4.3",
|
|
94
|
+
"@xchainjs/xchain-thornode": "^0.3.2",
|
|
93
95
|
"@xchainjs/xchain-util": "^0.13.0",
|
|
94
|
-
"@xchainjs/xchain-utxo-providers": "^0.2.
|
|
96
|
+
"@xchainjs/xchain-utxo-providers": "^0.2.1",
|
|
95
97
|
"axios": "^1.3.6",
|
|
96
98
|
"axios-retry": "^3.2.5",
|
|
97
99
|
"bchaddrjs": "^0.5.2",
|