@xchainjs/xchain-thorchain-amm 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/lib/index.esm.js +133 -48
- package/lib/index.js +122 -37
- package/lib/types.d.ts +11 -8
- package/lib/wallet.d.ts +19 -2
- package/package.json +8 -10
package/README.md
CHANGED
|
@@ -28,11 +28,11 @@ Following peer dependencies have to be installed into your project. These are no
|
|
|
28
28
|
"@xchainjs/xchain-ethereum": "^0.27.0",
|
|
29
29
|
"@xchainjs/xchain-evm": "^0.1.0-alpha2",
|
|
30
30
|
"@xchainjs/xchain-avax": "^0.1.0-alpha3",
|
|
31
|
-
"@xchainjs/xchain-litecoin": "^0.10.
|
|
31
|
+
"@xchainjs/xchain-litecoin": "^0.10.3",
|
|
32
32
|
"@xchainjs/xchain-midgard": "^0.1.0",
|
|
33
33
|
"@xchainjs/xchain-terra": "^0.3.0",
|
|
34
34
|
"@xchainjs/xchain-thorchain": "^0.26.0",
|
|
35
|
-
"@xchainjs/xchain-thorchain-query": "^0.1.
|
|
35
|
+
"@xchainjs/xchain-thorchain-query": "^0.1.2",
|
|
36
36
|
"@xchainjs/xchain-thornode": "^0.1.0",
|
|
37
37
|
"@xchainjs/xchain-util": "^0.9.0",
|
|
38
38
|
"axios": "^0.27.2",
|
package/lib/index.esm.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import { Client as Client$
|
|
2
|
-
import { Client as Client$
|
|
1
|
+
import { Client as Client$8, defaultAvaxParams } from '@xchainjs/xchain-avax';
|
|
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
5
|
import { Network, FeeOption } from '@xchainjs/xchain-client';
|
|
6
|
-
import { Client as Client$
|
|
6
|
+
import { Client as Client$7 } from '@xchainjs/xchain-cosmos';
|
|
7
7
|
import { Client as Client$2 } from '@xchainjs/xchain-doge';
|
|
8
|
-
import { MAX_APPROVAL, ETH_DECIMAL, Client as Client$
|
|
9
|
-
import { Client as Client$
|
|
10
|
-
import { Client as Client$
|
|
11
|
-
import { Client as Client$5 } from '@xchainjs/xchain-thorchain';
|
|
8
|
+
import { MAX_APPROVAL, ETH_DECIMAL, Client as Client$3 } from '@xchainjs/xchain-ethereum';
|
|
9
|
+
import { Client as Client$5 } from '@xchainjs/xchain-litecoin';
|
|
10
|
+
import { Client as Client$4 } from '@xchainjs/xchain-thorchain';
|
|
12
11
|
import { eqAsset, AssetETH, getContractAddressFromAsset, baseAmount, Chain, assetToString, AssetBTC } from '@xchainjs/xchain-util';
|
|
13
12
|
import { ethers } from 'ethers';
|
|
14
13
|
import { MAX_APPROVAL as MAX_APPROVAL$1 } from '@xchainjs/xchain-evm';
|
|
@@ -594,7 +593,21 @@ class EvmHelper {
|
|
|
594
593
|
const chainIds = {
|
|
595
594
|
[Network.Mainnet]: 'thorchain-mainnet-v1',
|
|
596
595
|
[Network.Stagenet]: 'chain-id-stagenet',
|
|
597
|
-
[Network.Testnet]: '
|
|
596
|
+
[Network.Testnet]: 'deprecated',
|
|
597
|
+
};
|
|
598
|
+
const clientUrl = {
|
|
599
|
+
[Network.Stagenet]: {
|
|
600
|
+
node: 'https://stagenet-thornode.ninerealms.com',
|
|
601
|
+
rpc: 'https://stagenet-rpc.ninerealms.com',
|
|
602
|
+
},
|
|
603
|
+
[Network.Mainnet]: {
|
|
604
|
+
node: 'https://thornode.ninerealms.com',
|
|
605
|
+
rpc: 'https://rpc.ninerealms.com',
|
|
606
|
+
},
|
|
607
|
+
[Network.Testnet]: {
|
|
608
|
+
node: 'deprecated',
|
|
609
|
+
rpc: 'deprecated',
|
|
610
|
+
},
|
|
598
611
|
};
|
|
599
612
|
/**
|
|
600
613
|
* Wallet Class for managing all xchain-* wallets with a mnemonic seed.
|
|
@@ -614,13 +627,12 @@ class Wallet {
|
|
|
614
627
|
BCH: new Client(settings),
|
|
615
628
|
BTC: new Client$1(settings),
|
|
616
629
|
DOGE: new Client$2(settings),
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
AVAX: new Client$9(Object.assign(Object.assign({}, defaultAvaxParams), { network: settings.network, phrase })),
|
|
630
|
+
ETH: new Client$3(settings),
|
|
631
|
+
THOR: new Client$4(Object.assign(Object.assign({}, settings), { chainIds, clientUrl })),
|
|
632
|
+
LTC: new Client$5(settings),
|
|
633
|
+
BNB: new Client$6(settings),
|
|
634
|
+
GAIA: new Client$7(settings),
|
|
635
|
+
AVAX: new Client$8(Object.assign(Object.assign({}, defaultAvaxParams), { network: settings.network, phrase })),
|
|
624
636
|
};
|
|
625
637
|
this.ethHelper = new EthHelper(this.clients.ETH, this.thorchainQuery.thorchainCache);
|
|
626
638
|
}
|
|
@@ -767,22 +779,22 @@ class Wallet {
|
|
|
767
779
|
const txSubmitted = [];
|
|
768
780
|
// symmetrical add
|
|
769
781
|
if (params.asset.assetAmount.gt(0) && params.rune.assetAmount.gt(0)) {
|
|
770
|
-
constructedMemo = `+:${params.
|
|
771
|
-
txSubmitted.push(yield this.
|
|
772
|
-
constructedMemo = `+:${params.
|
|
773
|
-
txSubmitted.push(yield this.
|
|
782
|
+
constructedMemo = `+:${params.assetPool}:${addressRune}`;
|
|
783
|
+
txSubmitted.push(yield this.addAssetLP(params, constructedMemo, assetClient, waitTimeSeconds, inboundAsgard));
|
|
784
|
+
constructedMemo = `+:${params.assetPool}:${addressAsset}`;
|
|
785
|
+
txSubmitted.push(yield this.addRuneLP(params, constructedMemo, thorchainClient, waitTimeSeconds));
|
|
774
786
|
return txSubmitted;
|
|
775
787
|
}
|
|
776
788
|
else if (params.asset.assetAmount.gt(0) && params.rune.assetAmount.eq(0)) {
|
|
777
789
|
// asymmetrical asset only
|
|
778
|
-
constructedMemo = `+:${params.
|
|
779
|
-
txSubmitted.push(yield this.
|
|
790
|
+
constructedMemo = `+:${params.assetPool}`;
|
|
791
|
+
txSubmitted.push(yield this.addAssetLP(params, constructedMemo, assetClient, waitTimeSeconds, inboundAsgard));
|
|
780
792
|
return txSubmitted;
|
|
781
793
|
}
|
|
782
794
|
else {
|
|
783
795
|
// asymmetrical rune only
|
|
784
|
-
constructedMemo = `+:${params.
|
|
785
|
-
txSubmitted.push(yield this.
|
|
796
|
+
constructedMemo = `+:${params.assetPool}`;
|
|
797
|
+
txSubmitted.push(yield this.addRuneLP(params, constructedMemo, thorchainClient, waitTimeSeconds));
|
|
786
798
|
return txSubmitted;
|
|
787
799
|
}
|
|
788
800
|
});
|
|
@@ -794,33 +806,31 @@ class Wallet {
|
|
|
794
806
|
*/
|
|
795
807
|
removeLiquidity(params) {
|
|
796
808
|
return __awaiter(this, void 0, void 0, function* () {
|
|
797
|
-
const assetClient = this.clients[params.
|
|
798
|
-
const inboundAsgard = (yield this.thorchainQuery.thorchainCache.getInboundDetails())[params.
|
|
799
|
-
|
|
800
|
-
throw new Error('Vault address is not defined');
|
|
801
|
-
}
|
|
809
|
+
const assetClient = this.clients[params.assetFee.asset.chain];
|
|
810
|
+
const inboundAsgard = (yield this.thorchainQuery.thorchainCache.getInboundDetails())[params.assetFee.asset.chain]
|
|
811
|
+
.address;
|
|
802
812
|
const waitTimeSeconds = params.waitTimeSeconds;
|
|
803
|
-
const thorchainClient = this.clients[params.
|
|
813
|
+
const thorchainClient = this.clients[params.runeFee.asset.chain];
|
|
804
814
|
const basisPoints = (params.percentage * 100).toFixed(); // convert to basis points
|
|
805
815
|
let constructedMemo = '';
|
|
806
816
|
const txSubmitted = [];
|
|
807
|
-
if (params.
|
|
808
|
-
constructedMemo = `-:${params.
|
|
809
|
-
txSubmitted.push(yield this.
|
|
810
|
-
constructedMemo = `-:${params.
|
|
811
|
-
txSubmitted.push(yield this.
|
|
817
|
+
if (params.assetAddress && params.runeAddress) {
|
|
818
|
+
constructedMemo = `-:${params.assetPool}:${basisPoints}`;
|
|
819
|
+
txSubmitted.push(yield this.removeAssetLP(params, constructedMemo, assetClient, waitTimeSeconds, inboundAsgard));
|
|
820
|
+
constructedMemo = `-:${params.assetPool}:${basisPoints}`;
|
|
821
|
+
txSubmitted.push(yield this.removeRuneLP(params, constructedMemo, thorchainClient, waitTimeSeconds));
|
|
812
822
|
return txSubmitted;
|
|
813
823
|
}
|
|
814
|
-
else if (params.
|
|
824
|
+
else if (params.assetAddress && !params.runeAddress) {
|
|
815
825
|
// asymmetrical asset only
|
|
816
|
-
constructedMemo = `-:${params.
|
|
817
|
-
txSubmitted.push(yield this.
|
|
826
|
+
constructedMemo = `-:${params.assetPool}:${basisPoints}`;
|
|
827
|
+
txSubmitted.push(yield this.removeAssetLP(params, constructedMemo, assetClient, waitTimeSeconds, inboundAsgard));
|
|
818
828
|
return txSubmitted;
|
|
819
829
|
}
|
|
820
830
|
else {
|
|
821
831
|
// asymmetrical rune only
|
|
822
|
-
constructedMemo = `-:${params.
|
|
823
|
-
txSubmitted.push(yield this.
|
|
832
|
+
constructedMemo = `-:${params.assetPool}:${basisPoints}`;
|
|
833
|
+
txSubmitted.push(yield this.removeRuneLP(params, constructedMemo, thorchainClient, waitTimeSeconds));
|
|
824
834
|
return txSubmitted;
|
|
825
835
|
}
|
|
826
836
|
});
|
|
@@ -834,7 +844,7 @@ class Wallet {
|
|
|
834
844
|
* @param inboundAsgard - inbound Asgard address for the LP
|
|
835
845
|
* @returns - tx object
|
|
836
846
|
*/
|
|
837
|
-
|
|
847
|
+
addAssetLP(params, constructedMemo, assetClient, waitTimeSeconds, inboundAsgard) {
|
|
838
848
|
return __awaiter(this, void 0, void 0, function* () {
|
|
839
849
|
if (params.asset.asset.chain === Chain.Ethereum) {
|
|
840
850
|
const addParams = {
|
|
@@ -844,7 +854,6 @@ class Wallet {
|
|
|
844
854
|
feeOption: FeeOption.Fast,
|
|
845
855
|
memo: constructedMemo,
|
|
846
856
|
};
|
|
847
|
-
console.log(addParams.amount.amount().toNumber());
|
|
848
857
|
const hash = yield this.ethHelper.sendDeposit(addParams);
|
|
849
858
|
return { hash, url: assetClient.getExplorerTxUrl(hash), waitTimeSeconds };
|
|
850
859
|
}
|
|
@@ -869,7 +878,6 @@ class Wallet {
|
|
|
869
878
|
memo: constructedMemo,
|
|
870
879
|
};
|
|
871
880
|
try {
|
|
872
|
-
console.log(addParams);
|
|
873
881
|
const hash = yield assetClient.transfer(addParams);
|
|
874
882
|
return { hash, url: assetClient.getExplorerTxUrl(hash), waitTimeSeconds };
|
|
875
883
|
}
|
|
@@ -880,13 +888,67 @@ class Wallet {
|
|
|
880
888
|
}
|
|
881
889
|
});
|
|
882
890
|
}
|
|
891
|
+
/**
|
|
892
|
+
*
|
|
893
|
+
* @param params - parameters for remove liquidity
|
|
894
|
+
* @param constructedMemo - memo needed for thorchain execution
|
|
895
|
+
* @param assetClient - asset client to call transfer
|
|
896
|
+
* @param waitTimeSeconds - return back estimated wait
|
|
897
|
+
* @param inboundAsgard - destination address
|
|
898
|
+
* @returns - tx object
|
|
899
|
+
*/
|
|
900
|
+
removeAssetLP(params, constructedMemo, assetClient, waitTimeSeconds, inboundAsgard) {
|
|
901
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
902
|
+
if (params.assetFee.asset.chain === Chain.Ethereum) {
|
|
903
|
+
const removeParams = {
|
|
904
|
+
wallIndex: 0,
|
|
905
|
+
asset: params.assetFee.asset,
|
|
906
|
+
amount: params.assetFee.baseAmount,
|
|
907
|
+
feeOption: FeeOption.Fast,
|
|
908
|
+
memo: constructedMemo,
|
|
909
|
+
};
|
|
910
|
+
// console.log(removeParams.amount.amount().toNumber())
|
|
911
|
+
const hash = yield this.ethHelper.sendDeposit(removeParams);
|
|
912
|
+
return { hash, url: assetClient.getExplorerTxUrl(hash), waitTimeSeconds };
|
|
913
|
+
}
|
|
914
|
+
else if (params.assetFee.asset.chain === Chain.Avalanche) {
|
|
915
|
+
const removeParams = {
|
|
916
|
+
wallIndex: 0,
|
|
917
|
+
asset: params.assetFee.asset,
|
|
918
|
+
amount: params.assetFee.baseAmount,
|
|
919
|
+
feeOption: FeeOption.Fast,
|
|
920
|
+
memo: constructedMemo,
|
|
921
|
+
};
|
|
922
|
+
const evmHelper = new EvmHelper(this.clients.AVAX, this.thorchainQuery.thorchainCache);
|
|
923
|
+
const hash = yield evmHelper.sendDeposit(removeParams);
|
|
924
|
+
return { hash, url: assetClient.getExplorerTxUrl(hash), waitTimeSeconds };
|
|
925
|
+
}
|
|
926
|
+
else {
|
|
927
|
+
const removeParams = {
|
|
928
|
+
wallIndex: 0,
|
|
929
|
+
asset: params.assetFee.asset,
|
|
930
|
+
amount: params.assetFee.baseAmount,
|
|
931
|
+
recipient: inboundAsgard,
|
|
932
|
+
memo: constructedMemo,
|
|
933
|
+
};
|
|
934
|
+
try {
|
|
935
|
+
const hash = yield assetClient.transfer(removeParams);
|
|
936
|
+
return { hash, url: assetClient.getExplorerTxUrl(hash), waitTimeSeconds };
|
|
937
|
+
}
|
|
938
|
+
catch (err) {
|
|
939
|
+
const hash = JSON.stringify(err);
|
|
940
|
+
return { hash, url: assetClient.getExplorerAddressUrl(assetClient.getAddress()), waitTimeSeconds };
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
});
|
|
944
|
+
}
|
|
883
945
|
/**
|
|
884
946
|
*
|
|
885
947
|
* @param params - deposit parameters
|
|
886
948
|
* @param memo - memo needed to withdraw lp
|
|
887
949
|
* @returns - tx object
|
|
888
950
|
*/
|
|
889
|
-
|
|
951
|
+
addRuneLP(params, memo, thorchainClient, waitTimeSeconds) {
|
|
890
952
|
return __awaiter(this, void 0, void 0, function* () {
|
|
891
953
|
const thorClient = this.clients.THOR;
|
|
892
954
|
const addParams = {
|
|
@@ -894,7 +956,26 @@ class Wallet {
|
|
|
894
956
|
amount: params.rune.baseAmount,
|
|
895
957
|
memo: memo,
|
|
896
958
|
};
|
|
897
|
-
console.log(addParams)
|
|
959
|
+
// console.log(addParams)
|
|
960
|
+
const hash = yield thorClient.deposit(addParams);
|
|
961
|
+
return { hash, url: thorchainClient.getExplorerTxUrl(hash), waitTimeSeconds };
|
|
962
|
+
});
|
|
963
|
+
}
|
|
964
|
+
/**
|
|
965
|
+
*
|
|
966
|
+
* @param params - remove parameters
|
|
967
|
+
* @param memo - memo needed to withdraw lp
|
|
968
|
+
* @returns - tx object
|
|
969
|
+
*/
|
|
970
|
+
removeRuneLP(params, memo, thorchainClient, waitTimeSeconds) {
|
|
971
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
972
|
+
const thorClient = this.clients.THOR;
|
|
973
|
+
const addParams = {
|
|
974
|
+
asset: params.runeFee.asset,
|
|
975
|
+
amount: params.runeFee.baseAmount,
|
|
976
|
+
memo: memo,
|
|
977
|
+
};
|
|
978
|
+
// console.log(addParams)
|
|
898
979
|
const hash = yield thorClient.deposit(addParams);
|
|
899
980
|
return { hash, url: thorchainClient.getExplorerTxUrl(hash), waitTimeSeconds };
|
|
900
981
|
});
|
|
@@ -985,6 +1066,7 @@ class ThorchainAMM {
|
|
|
985
1066
|
asset: params.asset,
|
|
986
1067
|
rune: params.rune,
|
|
987
1068
|
waitTimeSeconds: checkLPAdd.estimatedWaitSeconds,
|
|
1069
|
+
assetPool: checkLPAdd.assetPool,
|
|
988
1070
|
});
|
|
989
1071
|
});
|
|
990
1072
|
}
|
|
@@ -997,12 +1079,15 @@ class ThorchainAMM {
|
|
|
997
1079
|
removeLiquidityPosition(wallet, params) {
|
|
998
1080
|
return __awaiter(this, void 0, void 0, function* () {
|
|
999
1081
|
// Caution Dust Limits: BTC,BCH,LTC chains 10k sats; DOGE 1m Sats; ETH 0 wei; THOR 0 RUNE.
|
|
1000
|
-
const
|
|
1082
|
+
const withdrawParams = yield this.thorchainQuery.estimateWithdrawLP(params);
|
|
1001
1083
|
return wallet.removeLiquidity({
|
|
1002
|
-
|
|
1003
|
-
|
|
1084
|
+
assetFee: withdrawParams.transactionFee.assetFee,
|
|
1085
|
+
runeFee: withdrawParams.transactionFee.runeFee,
|
|
1086
|
+
waitTimeSeconds: withdrawParams.estimatedWaitSeconds,
|
|
1004
1087
|
percentage: params.percentage,
|
|
1005
|
-
|
|
1088
|
+
assetPool: withdrawParams.assetPool,
|
|
1089
|
+
assetAddress: withdrawParams.assetAddress,
|
|
1090
|
+
runeAddress: withdrawParams.runeAddress,
|
|
1006
1091
|
});
|
|
1007
1092
|
});
|
|
1008
1093
|
}
|
package/lib/index.js
CHANGED
|
@@ -11,7 +11,6 @@ var xchainCosmos = require('@xchainjs/xchain-cosmos');
|
|
|
11
11
|
var xchainDoge = require('@xchainjs/xchain-doge');
|
|
12
12
|
var xchainEthereum = require('@xchainjs/xchain-ethereum');
|
|
13
13
|
var xchainLitecoin = require('@xchainjs/xchain-litecoin');
|
|
14
|
-
var xchainTerra = require('@xchainjs/xchain-terra');
|
|
15
14
|
var xchainThorchain = require('@xchainjs/xchain-thorchain');
|
|
16
15
|
var xchainUtil = require('@xchainjs/xchain-util');
|
|
17
16
|
var ethers = require('ethers');
|
|
@@ -598,7 +597,21 @@ class EvmHelper {
|
|
|
598
597
|
const chainIds = {
|
|
599
598
|
[xchainClient.Network.Mainnet]: 'thorchain-mainnet-v1',
|
|
600
599
|
[xchainClient.Network.Stagenet]: 'chain-id-stagenet',
|
|
601
|
-
[xchainClient.Network.Testnet]: '
|
|
600
|
+
[xchainClient.Network.Testnet]: 'deprecated',
|
|
601
|
+
};
|
|
602
|
+
const clientUrl = {
|
|
603
|
+
[xchainClient.Network.Stagenet]: {
|
|
604
|
+
node: 'https://stagenet-thornode.ninerealms.com',
|
|
605
|
+
rpc: 'https://stagenet-rpc.ninerealms.com',
|
|
606
|
+
},
|
|
607
|
+
[xchainClient.Network.Mainnet]: {
|
|
608
|
+
node: 'https://thornode.ninerealms.com',
|
|
609
|
+
rpc: 'https://rpc.ninerealms.com',
|
|
610
|
+
},
|
|
611
|
+
[xchainClient.Network.Testnet]: {
|
|
612
|
+
node: 'deprecated',
|
|
613
|
+
rpc: 'deprecated',
|
|
614
|
+
},
|
|
602
615
|
};
|
|
603
616
|
/**
|
|
604
617
|
* Wallet Class for managing all xchain-* wallets with a mnemonic seed.
|
|
@@ -618,9 +631,8 @@ class Wallet {
|
|
|
618
631
|
BCH: new xchainBitcoincash.Client(settings),
|
|
619
632
|
BTC: new xchainBitcoin.Client(settings),
|
|
620
633
|
DOGE: new xchainDoge.Client(settings),
|
|
621
|
-
TERRA: new xchainTerra.Client(settings),
|
|
622
634
|
ETH: new xchainEthereum.Client(settings),
|
|
623
|
-
THOR: new xchainThorchain.Client(Object.assign(Object.assign({}, settings), { chainIds })),
|
|
635
|
+
THOR: new xchainThorchain.Client(Object.assign(Object.assign({}, settings), { chainIds, clientUrl })),
|
|
624
636
|
LTC: new xchainLitecoin.Client(settings),
|
|
625
637
|
BNB: new xchainBinance.Client(settings),
|
|
626
638
|
GAIA: new xchainCosmos.Client(settings),
|
|
@@ -771,22 +783,22 @@ class Wallet {
|
|
|
771
783
|
const txSubmitted = [];
|
|
772
784
|
// symmetrical add
|
|
773
785
|
if (params.asset.assetAmount.gt(0) && params.rune.assetAmount.gt(0)) {
|
|
774
|
-
constructedMemo = `+:${params.
|
|
775
|
-
txSubmitted.push(yield this.
|
|
776
|
-
constructedMemo = `+:${params.
|
|
777
|
-
txSubmitted.push(yield this.
|
|
786
|
+
constructedMemo = `+:${params.assetPool}:${addressRune}`;
|
|
787
|
+
txSubmitted.push(yield this.addAssetLP(params, constructedMemo, assetClient, waitTimeSeconds, inboundAsgard));
|
|
788
|
+
constructedMemo = `+:${params.assetPool}:${addressAsset}`;
|
|
789
|
+
txSubmitted.push(yield this.addRuneLP(params, constructedMemo, thorchainClient, waitTimeSeconds));
|
|
778
790
|
return txSubmitted;
|
|
779
791
|
}
|
|
780
792
|
else if (params.asset.assetAmount.gt(0) && params.rune.assetAmount.eq(0)) {
|
|
781
793
|
// asymmetrical asset only
|
|
782
|
-
constructedMemo = `+:${params.
|
|
783
|
-
txSubmitted.push(yield this.
|
|
794
|
+
constructedMemo = `+:${params.assetPool}`;
|
|
795
|
+
txSubmitted.push(yield this.addAssetLP(params, constructedMemo, assetClient, waitTimeSeconds, inboundAsgard));
|
|
784
796
|
return txSubmitted;
|
|
785
797
|
}
|
|
786
798
|
else {
|
|
787
799
|
// asymmetrical rune only
|
|
788
|
-
constructedMemo = `+:${params.
|
|
789
|
-
txSubmitted.push(yield this.
|
|
800
|
+
constructedMemo = `+:${params.assetPool}`;
|
|
801
|
+
txSubmitted.push(yield this.addRuneLP(params, constructedMemo, thorchainClient, waitTimeSeconds));
|
|
790
802
|
return txSubmitted;
|
|
791
803
|
}
|
|
792
804
|
});
|
|
@@ -798,33 +810,31 @@ class Wallet {
|
|
|
798
810
|
*/
|
|
799
811
|
removeLiquidity(params) {
|
|
800
812
|
return __awaiter(this, void 0, void 0, function* () {
|
|
801
|
-
const assetClient = this.clients[params.
|
|
802
|
-
const inboundAsgard = (yield this.thorchainQuery.thorchainCache.getInboundDetails())[params.
|
|
803
|
-
|
|
804
|
-
throw new Error('Vault address is not defined');
|
|
805
|
-
}
|
|
813
|
+
const assetClient = this.clients[params.assetFee.asset.chain];
|
|
814
|
+
const inboundAsgard = (yield this.thorchainQuery.thorchainCache.getInboundDetails())[params.assetFee.asset.chain]
|
|
815
|
+
.address;
|
|
806
816
|
const waitTimeSeconds = params.waitTimeSeconds;
|
|
807
|
-
const thorchainClient = this.clients[params.
|
|
817
|
+
const thorchainClient = this.clients[params.runeFee.asset.chain];
|
|
808
818
|
const basisPoints = (params.percentage * 100).toFixed(); // convert to basis points
|
|
809
819
|
let constructedMemo = '';
|
|
810
820
|
const txSubmitted = [];
|
|
811
|
-
if (params.
|
|
812
|
-
constructedMemo = `-:${params.
|
|
813
|
-
txSubmitted.push(yield this.
|
|
814
|
-
constructedMemo = `-:${params.
|
|
815
|
-
txSubmitted.push(yield this.
|
|
821
|
+
if (params.assetAddress && params.runeAddress) {
|
|
822
|
+
constructedMemo = `-:${params.assetPool}:${basisPoints}`;
|
|
823
|
+
txSubmitted.push(yield this.removeAssetLP(params, constructedMemo, assetClient, waitTimeSeconds, inboundAsgard));
|
|
824
|
+
constructedMemo = `-:${params.assetPool}:${basisPoints}`;
|
|
825
|
+
txSubmitted.push(yield this.removeRuneLP(params, constructedMemo, thorchainClient, waitTimeSeconds));
|
|
816
826
|
return txSubmitted;
|
|
817
827
|
}
|
|
818
|
-
else if (params.
|
|
828
|
+
else if (params.assetAddress && !params.runeAddress) {
|
|
819
829
|
// asymmetrical asset only
|
|
820
|
-
constructedMemo = `-:${params.
|
|
821
|
-
txSubmitted.push(yield this.
|
|
830
|
+
constructedMemo = `-:${params.assetPool}:${basisPoints}`;
|
|
831
|
+
txSubmitted.push(yield this.removeAssetLP(params, constructedMemo, assetClient, waitTimeSeconds, inboundAsgard));
|
|
822
832
|
return txSubmitted;
|
|
823
833
|
}
|
|
824
834
|
else {
|
|
825
835
|
// asymmetrical rune only
|
|
826
|
-
constructedMemo = `-:${params.
|
|
827
|
-
txSubmitted.push(yield this.
|
|
836
|
+
constructedMemo = `-:${params.assetPool}:${basisPoints}`;
|
|
837
|
+
txSubmitted.push(yield this.removeRuneLP(params, constructedMemo, thorchainClient, waitTimeSeconds));
|
|
828
838
|
return txSubmitted;
|
|
829
839
|
}
|
|
830
840
|
});
|
|
@@ -838,7 +848,7 @@ class Wallet {
|
|
|
838
848
|
* @param inboundAsgard - inbound Asgard address for the LP
|
|
839
849
|
* @returns - tx object
|
|
840
850
|
*/
|
|
841
|
-
|
|
851
|
+
addAssetLP(params, constructedMemo, assetClient, waitTimeSeconds, inboundAsgard) {
|
|
842
852
|
return __awaiter(this, void 0, void 0, function* () {
|
|
843
853
|
if (params.asset.asset.chain === xchainUtil.Chain.Ethereum) {
|
|
844
854
|
const addParams = {
|
|
@@ -848,7 +858,6 @@ class Wallet {
|
|
|
848
858
|
feeOption: xchainClient.FeeOption.Fast,
|
|
849
859
|
memo: constructedMemo,
|
|
850
860
|
};
|
|
851
|
-
console.log(addParams.amount.amount().toNumber());
|
|
852
861
|
const hash = yield this.ethHelper.sendDeposit(addParams);
|
|
853
862
|
return { hash, url: assetClient.getExplorerTxUrl(hash), waitTimeSeconds };
|
|
854
863
|
}
|
|
@@ -873,7 +882,6 @@ class Wallet {
|
|
|
873
882
|
memo: constructedMemo,
|
|
874
883
|
};
|
|
875
884
|
try {
|
|
876
|
-
console.log(addParams);
|
|
877
885
|
const hash = yield assetClient.transfer(addParams);
|
|
878
886
|
return { hash, url: assetClient.getExplorerTxUrl(hash), waitTimeSeconds };
|
|
879
887
|
}
|
|
@@ -884,13 +892,67 @@ class Wallet {
|
|
|
884
892
|
}
|
|
885
893
|
});
|
|
886
894
|
}
|
|
895
|
+
/**
|
|
896
|
+
*
|
|
897
|
+
* @param params - parameters for remove liquidity
|
|
898
|
+
* @param constructedMemo - memo needed for thorchain execution
|
|
899
|
+
* @param assetClient - asset client to call transfer
|
|
900
|
+
* @param waitTimeSeconds - return back estimated wait
|
|
901
|
+
* @param inboundAsgard - destination address
|
|
902
|
+
* @returns - tx object
|
|
903
|
+
*/
|
|
904
|
+
removeAssetLP(params, constructedMemo, assetClient, waitTimeSeconds, inboundAsgard) {
|
|
905
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
906
|
+
if (params.assetFee.asset.chain === xchainUtil.Chain.Ethereum) {
|
|
907
|
+
const removeParams = {
|
|
908
|
+
wallIndex: 0,
|
|
909
|
+
asset: params.assetFee.asset,
|
|
910
|
+
amount: params.assetFee.baseAmount,
|
|
911
|
+
feeOption: xchainClient.FeeOption.Fast,
|
|
912
|
+
memo: constructedMemo,
|
|
913
|
+
};
|
|
914
|
+
// console.log(removeParams.amount.amount().toNumber())
|
|
915
|
+
const hash = yield this.ethHelper.sendDeposit(removeParams);
|
|
916
|
+
return { hash, url: assetClient.getExplorerTxUrl(hash), waitTimeSeconds };
|
|
917
|
+
}
|
|
918
|
+
else if (params.assetFee.asset.chain === xchainUtil.Chain.Avalanche) {
|
|
919
|
+
const removeParams = {
|
|
920
|
+
wallIndex: 0,
|
|
921
|
+
asset: params.assetFee.asset,
|
|
922
|
+
amount: params.assetFee.baseAmount,
|
|
923
|
+
feeOption: xchainClient.FeeOption.Fast,
|
|
924
|
+
memo: constructedMemo,
|
|
925
|
+
};
|
|
926
|
+
const evmHelper = new EvmHelper(this.clients.AVAX, this.thorchainQuery.thorchainCache);
|
|
927
|
+
const hash = yield evmHelper.sendDeposit(removeParams);
|
|
928
|
+
return { hash, url: assetClient.getExplorerTxUrl(hash), waitTimeSeconds };
|
|
929
|
+
}
|
|
930
|
+
else {
|
|
931
|
+
const removeParams = {
|
|
932
|
+
wallIndex: 0,
|
|
933
|
+
asset: params.assetFee.asset,
|
|
934
|
+
amount: params.assetFee.baseAmount,
|
|
935
|
+
recipient: inboundAsgard,
|
|
936
|
+
memo: constructedMemo,
|
|
937
|
+
};
|
|
938
|
+
try {
|
|
939
|
+
const hash = yield assetClient.transfer(removeParams);
|
|
940
|
+
return { hash, url: assetClient.getExplorerTxUrl(hash), waitTimeSeconds };
|
|
941
|
+
}
|
|
942
|
+
catch (err) {
|
|
943
|
+
const hash = JSON.stringify(err);
|
|
944
|
+
return { hash, url: assetClient.getExplorerAddressUrl(assetClient.getAddress()), waitTimeSeconds };
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
});
|
|
948
|
+
}
|
|
887
949
|
/**
|
|
888
950
|
*
|
|
889
951
|
* @param params - deposit parameters
|
|
890
952
|
* @param memo - memo needed to withdraw lp
|
|
891
953
|
* @returns - tx object
|
|
892
954
|
*/
|
|
893
|
-
|
|
955
|
+
addRuneLP(params, memo, thorchainClient, waitTimeSeconds) {
|
|
894
956
|
return __awaiter(this, void 0, void 0, function* () {
|
|
895
957
|
const thorClient = this.clients.THOR;
|
|
896
958
|
const addParams = {
|
|
@@ -898,7 +960,26 @@ class Wallet {
|
|
|
898
960
|
amount: params.rune.baseAmount,
|
|
899
961
|
memo: memo,
|
|
900
962
|
};
|
|
901
|
-
console.log(addParams)
|
|
963
|
+
// console.log(addParams)
|
|
964
|
+
const hash = yield thorClient.deposit(addParams);
|
|
965
|
+
return { hash, url: thorchainClient.getExplorerTxUrl(hash), waitTimeSeconds };
|
|
966
|
+
});
|
|
967
|
+
}
|
|
968
|
+
/**
|
|
969
|
+
*
|
|
970
|
+
* @param params - remove parameters
|
|
971
|
+
* @param memo - memo needed to withdraw lp
|
|
972
|
+
* @returns - tx object
|
|
973
|
+
*/
|
|
974
|
+
removeRuneLP(params, memo, thorchainClient, waitTimeSeconds) {
|
|
975
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
976
|
+
const thorClient = this.clients.THOR;
|
|
977
|
+
const addParams = {
|
|
978
|
+
asset: params.runeFee.asset,
|
|
979
|
+
amount: params.runeFee.baseAmount,
|
|
980
|
+
memo: memo,
|
|
981
|
+
};
|
|
982
|
+
// console.log(addParams)
|
|
902
983
|
const hash = yield thorClient.deposit(addParams);
|
|
903
984
|
return { hash, url: thorchainClient.getExplorerTxUrl(hash), waitTimeSeconds };
|
|
904
985
|
});
|
|
@@ -989,6 +1070,7 @@ class ThorchainAMM {
|
|
|
989
1070
|
asset: params.asset,
|
|
990
1071
|
rune: params.rune,
|
|
991
1072
|
waitTimeSeconds: checkLPAdd.estimatedWaitSeconds,
|
|
1073
|
+
assetPool: checkLPAdd.assetPool,
|
|
992
1074
|
});
|
|
993
1075
|
});
|
|
994
1076
|
}
|
|
@@ -1001,12 +1083,15 @@ class ThorchainAMM {
|
|
|
1001
1083
|
removeLiquidityPosition(wallet, params) {
|
|
1002
1084
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1003
1085
|
// Caution Dust Limits: BTC,BCH,LTC chains 10k sats; DOGE 1m Sats; ETH 0 wei; THOR 0 RUNE.
|
|
1004
|
-
const
|
|
1086
|
+
const withdrawParams = yield this.thorchainQuery.estimateWithdrawLP(params);
|
|
1005
1087
|
return wallet.removeLiquidity({
|
|
1006
|
-
|
|
1007
|
-
|
|
1088
|
+
assetFee: withdrawParams.transactionFee.assetFee,
|
|
1089
|
+
runeFee: withdrawParams.transactionFee.runeFee,
|
|
1090
|
+
waitTimeSeconds: withdrawParams.estimatedWaitSeconds,
|
|
1008
1091
|
percentage: params.percentage,
|
|
1009
|
-
|
|
1092
|
+
assetPool: withdrawParams.assetPool,
|
|
1093
|
+
assetAddress: withdrawParams.assetAddress,
|
|
1094
|
+
runeAddress: withdrawParams.runeAddress,
|
|
1010
1095
|
});
|
|
1011
1096
|
});
|
|
1012
1097
|
}
|
package/lib/types.d.ts
CHANGED
|
@@ -22,23 +22,26 @@ export declare type TxSubmitted = {
|
|
|
22
22
|
url: string;
|
|
23
23
|
waitTimeSeconds: number;
|
|
24
24
|
};
|
|
25
|
-
export declare type AddLiquidity = {
|
|
26
|
-
asset: CryptoAmount;
|
|
27
|
-
rune: CryptoAmount;
|
|
28
|
-
waitTimeSeconds: number;
|
|
29
|
-
};
|
|
30
25
|
export declare type LiquidityPosition = {
|
|
31
26
|
assetPool: LiquidityPool;
|
|
32
27
|
assetAmount: CryptoAmount;
|
|
33
28
|
runeAmount: CryptoAmount;
|
|
34
29
|
impermanentLossProtection: number;
|
|
35
30
|
};
|
|
36
|
-
export declare type
|
|
31
|
+
export declare type AddLiquidity = {
|
|
37
32
|
asset: CryptoAmount;
|
|
38
33
|
rune: CryptoAmount;
|
|
39
|
-
percentage: number;
|
|
40
34
|
waitTimeSeconds: number;
|
|
41
|
-
|
|
35
|
+
assetPool: string;
|
|
36
|
+
};
|
|
37
|
+
export declare type RemoveLiquidity = {
|
|
38
|
+
assetFee: CryptoAmount;
|
|
39
|
+
runeFee: CryptoAmount;
|
|
40
|
+
waitTimeSeconds: number;
|
|
41
|
+
percentage: number;
|
|
42
|
+
assetPool: string;
|
|
43
|
+
assetAddress?: string;
|
|
44
|
+
runeAddress?: string;
|
|
42
45
|
};
|
|
43
46
|
export declare type DepositParams = {
|
|
44
47
|
walletIndex?: number;
|
package/lib/wallet.d.ts
CHANGED
|
@@ -61,13 +61,30 @@ export declare class Wallet {
|
|
|
61
61
|
* @param inboundAsgard - inbound Asgard address for the LP
|
|
62
62
|
* @returns - tx object
|
|
63
63
|
*/
|
|
64
|
-
private
|
|
64
|
+
private addAssetLP;
|
|
65
|
+
/**
|
|
66
|
+
*
|
|
67
|
+
* @param params - parameters for remove liquidity
|
|
68
|
+
* @param constructedMemo - memo needed for thorchain execution
|
|
69
|
+
* @param assetClient - asset client to call transfer
|
|
70
|
+
* @param waitTimeSeconds - return back estimated wait
|
|
71
|
+
* @param inboundAsgard - destination address
|
|
72
|
+
* @returns - tx object
|
|
73
|
+
*/
|
|
74
|
+
private removeAssetLP;
|
|
65
75
|
/**
|
|
66
76
|
*
|
|
67
77
|
* @param params - deposit parameters
|
|
68
78
|
* @param memo - memo needed to withdraw lp
|
|
69
79
|
* @returns - tx object
|
|
70
80
|
*/
|
|
71
|
-
private
|
|
81
|
+
private addRuneLP;
|
|
82
|
+
/**
|
|
83
|
+
*
|
|
84
|
+
* @param params - remove parameters
|
|
85
|
+
* @param memo - memo needed to withdraw lp
|
|
86
|
+
* @returns - tx object
|
|
87
|
+
*/
|
|
88
|
+
private removeRuneLP;
|
|
72
89
|
}
|
|
73
90
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xchainjs/xchain-thorchain-amm",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "module that exposes estimating & swappping cryptocurrency assets on thorchain",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"THORChain",
|
|
@@ -43,20 +43,19 @@
|
|
|
43
43
|
"@xchainjs/xchain-binance": "^5.6.0",
|
|
44
44
|
"@xchainjs/xchain-bitcoin": "^0.20.0",
|
|
45
45
|
"@xchainjs/xchain-bitcoincash": "^0.15.0",
|
|
46
|
-
"@xchainjs/xchain-client": "^0.13.
|
|
46
|
+
"@xchainjs/xchain-client": "^0.13.2",
|
|
47
47
|
"@xchainjs/xchain-cosmos": "^0.20.0",
|
|
48
48
|
"@xchainjs/xchain-crypto": "^0.2.6",
|
|
49
49
|
"@xchainjs/xchain-doge": "^0.5.0",
|
|
50
50
|
"@xchainjs/xchain-ethereum": "^0.27.0",
|
|
51
51
|
"@xchainjs/xchain-evm": "^0.1.0-alpha2",
|
|
52
52
|
"@xchainjs/xchain-avax": "^0.1.0-alpha3",
|
|
53
|
-
"@xchainjs/xchain-litecoin": "^0.10.
|
|
53
|
+
"@xchainjs/xchain-litecoin": "^0.10.3",
|
|
54
54
|
"@xchainjs/xchain-midgard": "0.1.0",
|
|
55
|
-
"@xchainjs/xchain-
|
|
56
|
-
"@xchainjs/xchain-thorchain": "^0.
|
|
57
|
-
"@xchainjs/xchain-thorchain-query": "^0.1.0",
|
|
55
|
+
"@xchainjs/xchain-thorchain": "^0.27.0",
|
|
56
|
+
"@xchainjs/xchain-thorchain-query": "^0.1.2",
|
|
58
57
|
"@xchainjs/xchain-thornode": "^0.1.0",
|
|
59
|
-
"@xchainjs/xchain-util": "^0.
|
|
58
|
+
"@xchainjs/xchain-util": "^0.11.0",
|
|
60
59
|
"axios": "^0.25.0",
|
|
61
60
|
"axios-retry": "^3.2.5",
|
|
62
61
|
"bchaddrjs": "^0.5.2",
|
|
@@ -78,7 +77,7 @@
|
|
|
78
77
|
"@xchainjs/xchain-binance": "^5.6.0",
|
|
79
78
|
"@xchainjs/xchain-bitcoin": "^0.20.0",
|
|
80
79
|
"@xchainjs/xchain-bitcoincash": "^0.15.0",
|
|
81
|
-
"@xchainjs/xchain-client": "^0.13.
|
|
80
|
+
"@xchainjs/xchain-client": "^0.13.2",
|
|
82
81
|
"@xchainjs/xchain-cosmos": "^0.20.0",
|
|
83
82
|
"@xchainjs/xchain-crypto": "^0.2.6",
|
|
84
83
|
"@xchainjs/xchain-doge": "^0.5.0",
|
|
@@ -88,10 +87,9 @@
|
|
|
88
87
|
"@xchainjs/xchain-litecoin": "^0.10.0",
|
|
89
88
|
"@xchainjs/xchain-midgard": "0.1.0",
|
|
90
89
|
"@xchainjs/xchain-thornode": "^0.1.0",
|
|
91
|
-
"@xchainjs/xchain-terra": "^0.3.0",
|
|
92
90
|
"@xchainjs/xchain-thorchain": "^0.26.0",
|
|
93
91
|
"@xchainjs/xchain-thorchain-query": "^0.1.0",
|
|
94
|
-
"@xchainjs/xchain-util": "^0.
|
|
92
|
+
"@xchainjs/xchain-util": "^0.11.0",
|
|
95
93
|
"axios": "^0.25.0",
|
|
96
94
|
"axios-retry": "^3.2.5",
|
|
97
95
|
"bchaddrjs": "^0.5.2",
|