@xchainjs/xchain-thorchain-amm 0.3.1 → 0.3.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/README.md +5 -0
- package/lib/index.esm.js +89 -70
- package/lib/index.js +88 -69
- package/lib/thorchain-amm.d.ts +15 -3
- package/lib/types.d.ts +2 -19
- package/lib/wallet.d.ts +28 -14
- package/package.json +18 -19
package/README.md
CHANGED
|
@@ -54,6 +54,11 @@ Following peer dependencies have to be installed into your project. These are no
|
|
|
54
54
|
[How thorchain-amm works](http://docs.xchainjs.org/xchain-thorchain-amm/how-it-works.html)\
|
|
55
55
|
[How to use thorchain-amm](http://docs.xchainjs.org/xchain-thorchain-amm/how-to-use.html)
|
|
56
56
|
|
|
57
|
+
For live examples
|
|
58
|
+
[Do Swap](https://replit.com/@thorchain/doSwap-Single)
|
|
59
|
+
[Add Liquidity](https://replit.com/@thorchain/addLiquidity)
|
|
60
|
+
[Withdraw liquidity](https://replit.com/@thorchain/removeLiquidity)
|
|
61
|
+
|
|
57
62
|
##
|
|
58
63
|
|
|
59
64
|
tsconfig compiler options
|
package/lib/index.esm.js
CHANGED
|
@@ -8,10 +8,10 @@ import { Client as Client$2 } from '@xchainjs/xchain-doge';
|
|
|
8
8
|
import { MAX_APPROVAL, ETH_DECIMAL, Client as Client$3 } from '@xchainjs/xchain-ethereum';
|
|
9
9
|
import { Client as Client$5 } from '@xchainjs/xchain-litecoin';
|
|
10
10
|
import { Client as Client$4 } from '@xchainjs/xchain-thorchain';
|
|
11
|
-
import { eqAsset, AssetETH, getContractAddressFromAsset, baseAmount, Chain
|
|
11
|
+
import { eqAsset, AssetETH, getContractAddressFromAsset, baseAmount, Chain } from '@xchainjs/xchain-util';
|
|
12
12
|
import { ethers } from 'ethers';
|
|
13
13
|
import { MAX_APPROVAL as MAX_APPROVAL$1 } from '@xchainjs/xchain-evm';
|
|
14
|
-
import {
|
|
14
|
+
import { ThorchainQuery } from '@xchainjs/xchain-thorchain-query';
|
|
15
15
|
|
|
16
16
|
/*! *****************************************************************************
|
|
17
17
|
Copyright (c) Microsoft Corporation.
|
|
@@ -676,24 +676,10 @@ class Wallet {
|
|
|
676
676
|
}
|
|
677
677
|
});
|
|
678
678
|
}
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
// create the full memo
|
|
684
|
-
let memo = `=:${assetToString(swap.destinationAsset)}`;
|
|
685
|
-
if (swap.affiliateAddress != '' || swap.affiliateFee == undefined) {
|
|
686
|
-
memo = memo.concat(`:${swap.destinationAddress}:${lim}:${swap.affiliateAddress}:${swap.affiliateFee.amount().toFixed()}`);
|
|
687
|
-
}
|
|
688
|
-
else {
|
|
689
|
-
memo = memo.concat(`:${swap.destinationAddress}:${lim}`);
|
|
690
|
-
}
|
|
691
|
-
// If memo length is too long for BTC, trim it
|
|
692
|
-
if (eqAsset(swap.input.asset, AssetBTC) && memo.length > 80) {
|
|
693
|
-
memo = `=:${assetToString(swap.destinationAsset)}:${swap.destinationAddress}`;
|
|
694
|
-
}
|
|
695
|
-
return memo;
|
|
696
|
-
}
|
|
679
|
+
/** Validate swap object
|
|
680
|
+
*
|
|
681
|
+
* @param swap - swap parameters
|
|
682
|
+
*/
|
|
697
683
|
validateSwap(swap) {
|
|
698
684
|
const errors = [];
|
|
699
685
|
const isThorchainDestinationAsset = swap.destinationAsset.synth || swap.destinationAsset.chain === Chain.THORChain;
|
|
@@ -701,11 +687,31 @@ class Wallet {
|
|
|
701
687
|
if (!this.clients[chain].validateAddress(swap.destinationAddress)) {
|
|
702
688
|
errors.push(`destinationAddress ${swap.destinationAddress} is not a valid address`);
|
|
703
689
|
}
|
|
704
|
-
|
|
705
|
-
|
|
690
|
+
// Affiliate address should be THORName or THORAddress
|
|
691
|
+
const checkAffiliateAddress = swap.memo.split(':');
|
|
692
|
+
if (checkAffiliateAddress.length > 4) {
|
|
693
|
+
const affiliateAddress = checkAffiliateAddress[4];
|
|
694
|
+
if (affiliateAddress.length > 0) {
|
|
695
|
+
const isValidThorchainAddress = this.clients[Chain.THORChain].validateAddress(affiliateAddress);
|
|
696
|
+
const isValidThorname = this.isThorname(affiliateAddress);
|
|
697
|
+
if (!(isValidThorchainAddress || isValidThorname))
|
|
698
|
+
errors.push(`affiliateAddress ${affiliateAddress} is not a valid THOR address`);
|
|
699
|
+
}
|
|
700
|
+
}
|
|
706
701
|
if (errors.length > 0)
|
|
707
702
|
throw Error(errors.join('\n'));
|
|
708
703
|
}
|
|
704
|
+
isThorname(name) {
|
|
705
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
706
|
+
const thornameDetails = yield this.thorchainQuery.thorchainCache.midgard.getTHORNameDetails(name);
|
|
707
|
+
return thornameDetails !== undefined;
|
|
708
|
+
});
|
|
709
|
+
}
|
|
710
|
+
/** Function handles all swaps from Rune to asset
|
|
711
|
+
*
|
|
712
|
+
* @param swap - swap parameters
|
|
713
|
+
* @returns - tx submitted object
|
|
714
|
+
*/
|
|
709
715
|
swapRuneTo(swap) {
|
|
710
716
|
return __awaiter(this, void 0, void 0, function* () {
|
|
711
717
|
const thorClient = this.clients.THOR;
|
|
@@ -713,11 +719,16 @@ class Wallet {
|
|
|
713
719
|
const hash = yield thorClient.deposit({
|
|
714
720
|
amount: swap.input.baseAmount,
|
|
715
721
|
asset: swap.input.asset,
|
|
716
|
-
memo:
|
|
722
|
+
memo: swap.memo,
|
|
717
723
|
});
|
|
718
724
|
return { hash, url: this.clients.THOR.getExplorerTxUrl(hash), waitTimeSeconds };
|
|
719
725
|
});
|
|
720
726
|
}
|
|
727
|
+
/** Function handles all swaps from Non Rune
|
|
728
|
+
*
|
|
729
|
+
* @param swap - swap object
|
|
730
|
+
* @returns - TxSubmitted object
|
|
731
|
+
*/
|
|
721
732
|
swapNonRune(swap) {
|
|
722
733
|
return __awaiter(this, void 0, void 0, function* () {
|
|
723
734
|
const client = this.clients[swap.input.asset.chain];
|
|
@@ -731,7 +742,7 @@ class Wallet {
|
|
|
731
742
|
asset: swap.input.asset,
|
|
732
743
|
amount: swap.input.baseAmount,
|
|
733
744
|
feeOption: swap.feeOption || FeeOption.Fast,
|
|
734
|
-
memo:
|
|
745
|
+
memo: swap.memo,
|
|
735
746
|
};
|
|
736
747
|
const hash = yield this.ethHelper.sendDeposit(params);
|
|
737
748
|
return { hash, url: client.getExplorerTxUrl(hash), waitTimeSeconds };
|
|
@@ -742,7 +753,7 @@ class Wallet {
|
|
|
742
753
|
asset: swap.input.asset,
|
|
743
754
|
amount: swap.input.baseAmount,
|
|
744
755
|
feeOption: swap.feeOption || FeeOption.Fast,
|
|
745
|
-
memo:
|
|
756
|
+
memo: swap.memo,
|
|
746
757
|
};
|
|
747
758
|
const evmHelper = new EvmHelper(this.clients.AVAX, this.thorchainQuery.thorchainCache);
|
|
748
759
|
const hash = yield evmHelper.sendDeposit(params);
|
|
@@ -754,15 +765,15 @@ class Wallet {
|
|
|
754
765
|
asset: swap.input.asset,
|
|
755
766
|
amount: swap.input.baseAmount,
|
|
756
767
|
recipient: inbound.address,
|
|
757
|
-
memo:
|
|
768
|
+
memo: swap.memo,
|
|
758
769
|
};
|
|
759
770
|
const hash = yield client.transfer(params);
|
|
760
771
|
return { hash, url: client.getExplorerTxUrl(hash), waitTimeSeconds };
|
|
761
772
|
}
|
|
762
773
|
});
|
|
763
774
|
}
|
|
764
|
-
/**
|
|
765
|
-
*
|
|
775
|
+
/** Function handles liquidity Add
|
|
776
|
+
* BASED OFF https://dev.thorchain.or›g/thorchain-dev/network/memos
|
|
766
777
|
* @param params input parameters needed to add liquidity
|
|
767
778
|
* @returns transaction details submitted
|
|
768
779
|
*/
|
|
@@ -799,12 +810,12 @@ class Wallet {
|
|
|
799
810
|
}
|
|
800
811
|
});
|
|
801
812
|
}
|
|
802
|
-
/**
|
|
813
|
+
/** Function handles liquidity Withdraw
|
|
803
814
|
*
|
|
804
815
|
* @param params - parameters required for liquidity position
|
|
805
816
|
* @returns object with tx response, url and wait time in seconds
|
|
806
817
|
*/
|
|
807
|
-
|
|
818
|
+
withdrawLiquidity(params) {
|
|
808
819
|
return __awaiter(this, void 0, void 0, function* () {
|
|
809
820
|
const assetClient = this.clients[params.assetFee.asset.chain];
|
|
810
821
|
const inboundAsgard = (yield this.thorchainQuery.thorchainCache.getInboundDetails())[params.assetFee.asset.chain]
|
|
@@ -816,26 +827,26 @@ class Wallet {
|
|
|
816
827
|
const txSubmitted = [];
|
|
817
828
|
if (params.assetAddress && params.runeAddress) {
|
|
818
829
|
constructedMemo = `-:${params.assetPool}:${basisPoints}`;
|
|
819
|
-
txSubmitted.push(yield this.
|
|
830
|
+
txSubmitted.push(yield this.withdrawAssetLP(params, constructedMemo, assetClient, waitTimeSeconds, inboundAsgard));
|
|
820
831
|
constructedMemo = `-:${params.assetPool}:${basisPoints}`;
|
|
821
|
-
txSubmitted.push(yield this.
|
|
832
|
+
txSubmitted.push(yield this.withdrawRuneLP(params, constructedMemo, thorchainClient, waitTimeSeconds));
|
|
822
833
|
return txSubmitted;
|
|
823
834
|
}
|
|
824
835
|
else if (params.assetAddress && !params.runeAddress) {
|
|
825
836
|
// asymmetrical asset only
|
|
826
837
|
constructedMemo = `-:${params.assetPool}:${basisPoints}`;
|
|
827
|
-
txSubmitted.push(yield this.
|
|
838
|
+
txSubmitted.push(yield this.withdrawAssetLP(params, constructedMemo, assetClient, waitTimeSeconds, inboundAsgard));
|
|
828
839
|
return txSubmitted;
|
|
829
840
|
}
|
|
830
841
|
else {
|
|
831
842
|
// asymmetrical rune only
|
|
832
843
|
constructedMemo = `-:${params.assetPool}:${basisPoints}`;
|
|
833
|
-
txSubmitted.push(yield this.
|
|
844
|
+
txSubmitted.push(yield this.withdrawRuneLP(params, constructedMemo, thorchainClient, waitTimeSeconds));
|
|
834
845
|
return txSubmitted;
|
|
835
846
|
}
|
|
836
847
|
});
|
|
837
848
|
}
|
|
838
|
-
/**
|
|
849
|
+
/** Function handles liquidity add for all non rune assets
|
|
839
850
|
*
|
|
840
851
|
* @param params - parameters for add liquidity
|
|
841
852
|
* @param constructedMemo - memo needed for thorchain
|
|
@@ -888,31 +899,31 @@ class Wallet {
|
|
|
888
899
|
}
|
|
889
900
|
});
|
|
890
901
|
}
|
|
891
|
-
/**
|
|
902
|
+
/** Function handles liquidity Withdraw for Non rune assets
|
|
892
903
|
*
|
|
893
|
-
* @param params - parameters for
|
|
904
|
+
* @param params - parameters for withdraw liquidity
|
|
894
905
|
* @param constructedMemo - memo needed for thorchain execution
|
|
895
906
|
* @param assetClient - asset client to call transfer
|
|
896
907
|
* @param waitTimeSeconds - return back estimated wait
|
|
897
908
|
* @param inboundAsgard - destination address
|
|
898
909
|
* @returns - tx object
|
|
899
910
|
*/
|
|
900
|
-
|
|
911
|
+
withdrawAssetLP(params, constructedMemo, assetClient, waitTimeSeconds, inboundAsgard) {
|
|
901
912
|
return __awaiter(this, void 0, void 0, function* () {
|
|
902
913
|
if (params.assetFee.asset.chain === Chain.Ethereum) {
|
|
903
|
-
const
|
|
914
|
+
const withdrawParams = {
|
|
904
915
|
wallIndex: 0,
|
|
905
916
|
asset: params.assetFee.asset,
|
|
906
917
|
amount: params.assetFee.baseAmount,
|
|
907
918
|
feeOption: FeeOption.Fast,
|
|
908
919
|
memo: constructedMemo,
|
|
909
920
|
};
|
|
910
|
-
// console.log(
|
|
911
|
-
const hash = yield this.ethHelper.sendDeposit(
|
|
921
|
+
// console.log(withdrawParams.amount.amount().toNumber())
|
|
922
|
+
const hash = yield this.ethHelper.sendDeposit(withdrawParams);
|
|
912
923
|
return { hash, url: assetClient.getExplorerTxUrl(hash), waitTimeSeconds };
|
|
913
924
|
}
|
|
914
925
|
else if (params.assetFee.asset.chain === Chain.Avalanche) {
|
|
915
|
-
const
|
|
926
|
+
const withdrawParams = {
|
|
916
927
|
wallIndex: 0,
|
|
917
928
|
asset: params.assetFee.asset,
|
|
918
929
|
amount: params.assetFee.baseAmount,
|
|
@@ -920,11 +931,11 @@ class Wallet {
|
|
|
920
931
|
memo: constructedMemo,
|
|
921
932
|
};
|
|
922
933
|
const evmHelper = new EvmHelper(this.clients.AVAX, this.thorchainQuery.thorchainCache);
|
|
923
|
-
const hash = yield evmHelper.sendDeposit(
|
|
934
|
+
const hash = yield evmHelper.sendDeposit(withdrawParams);
|
|
924
935
|
return { hash, url: assetClient.getExplorerTxUrl(hash), waitTimeSeconds };
|
|
925
936
|
}
|
|
926
937
|
else {
|
|
927
|
-
const
|
|
938
|
+
const withdrawParams = {
|
|
928
939
|
wallIndex: 0,
|
|
929
940
|
asset: params.assetFee.asset,
|
|
930
941
|
amount: params.assetFee.baseAmount,
|
|
@@ -932,7 +943,7 @@ class Wallet {
|
|
|
932
943
|
memo: constructedMemo,
|
|
933
944
|
};
|
|
934
945
|
try {
|
|
935
|
-
const hash = yield assetClient.transfer(
|
|
946
|
+
const hash = yield assetClient.transfer(withdrawParams);
|
|
936
947
|
return { hash, url: assetClient.getExplorerTxUrl(hash), waitTimeSeconds };
|
|
937
948
|
}
|
|
938
949
|
catch (err) {
|
|
@@ -942,7 +953,7 @@ class Wallet {
|
|
|
942
953
|
}
|
|
943
954
|
});
|
|
944
955
|
}
|
|
945
|
-
/**
|
|
956
|
+
/** Function handles liquidity Add for Rune only
|
|
946
957
|
*
|
|
947
958
|
* @param params - deposit parameters
|
|
948
959
|
* @param memo - memo needed to withdraw lp
|
|
@@ -956,18 +967,17 @@ class Wallet {
|
|
|
956
967
|
amount: params.rune.baseAmount,
|
|
957
968
|
memo: memo,
|
|
958
969
|
};
|
|
959
|
-
// console.log(addParams)
|
|
960
970
|
const hash = yield thorClient.deposit(addParams);
|
|
961
971
|
return { hash, url: thorchainClient.getExplorerTxUrl(hash), waitTimeSeconds };
|
|
962
972
|
});
|
|
963
973
|
}
|
|
964
|
-
/**
|
|
974
|
+
/** Function handles liquidity Withdraw for Rune only
|
|
965
975
|
*
|
|
966
|
-
* @param params -
|
|
976
|
+
* @param params - withdraw parameters
|
|
967
977
|
* @param memo - memo needed to withdraw lp
|
|
968
978
|
* @returns - tx object
|
|
969
979
|
*/
|
|
970
|
-
|
|
980
|
+
withdrawRuneLP(params, memo, thorchainClient, waitTimeSeconds) {
|
|
971
981
|
return __awaiter(this, void 0, void 0, function* () {
|
|
972
982
|
const thorClient = this.clients.THOR;
|
|
973
983
|
const addParams = {
|
|
@@ -975,14 +985,13 @@ class Wallet {
|
|
|
975
985
|
amount: params.runeFee.baseAmount,
|
|
976
986
|
memo: memo,
|
|
977
987
|
};
|
|
978
|
-
// console.log(addParams)
|
|
979
988
|
const hash = yield thorClient.deposit(addParams);
|
|
980
989
|
return { hash, url: thorchainClient.getExplorerTxUrl(hash), waitTimeSeconds };
|
|
981
990
|
});
|
|
982
991
|
}
|
|
983
992
|
}
|
|
984
993
|
|
|
985
|
-
const
|
|
994
|
+
const defaultQuery = new ThorchainQuery();
|
|
986
995
|
/**
|
|
987
996
|
* THORChain Class for interacting with THORChain.
|
|
988
997
|
* Recommended main class to use for swapping with THORChain
|
|
@@ -995,7 +1004,7 @@ class ThorchainAMM {
|
|
|
995
1004
|
* @param thorchainQuery - an instance of the ThorchainQuery
|
|
996
1005
|
* @returns ThorchainAMM
|
|
997
1006
|
*/
|
|
998
|
-
constructor(thorchainQuery) {
|
|
1007
|
+
constructor(thorchainQuery = defaultQuery) {
|
|
999
1008
|
this.thorchainQuery = thorchainQuery;
|
|
1000
1009
|
}
|
|
1001
1010
|
/**
|
|
@@ -1026,32 +1035,40 @@ class ThorchainAMM {
|
|
|
1026
1035
|
*/
|
|
1027
1036
|
doSwap(wallet, params) {
|
|
1028
1037
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1029
|
-
//
|
|
1038
|
+
// Thorchain-query call satisfies the data needed for executeSwap to be called.
|
|
1030
1039
|
const txDetails = yield this.thorchainQuery.estimateSwap(params);
|
|
1031
1040
|
if (!txDetails.txEstimate.canSwap) {
|
|
1032
1041
|
throw Error(txDetails.txEstimate.errors.join('\n'));
|
|
1033
1042
|
}
|
|
1034
|
-
// remove any affiliateFee. netInput * affiliateFee (%age) of the destination asset type
|
|
1035
|
-
const affiliateFee = params.input.baseAmount.times(params.affiliateFeePercent || 0);
|
|
1036
|
-
// Work out LIM from the slip percentage
|
|
1037
|
-
let limPercentage = BN_1;
|
|
1038
|
-
if (params.slipLimit) {
|
|
1039
|
-
limPercentage = BN_1.minus(params.slipLimit || 1);
|
|
1040
|
-
} // else allowed slip is 100%
|
|
1041
|
-
const limAssetAmount = txDetails.txEstimate.netOutput.times(limPercentage);
|
|
1042
|
-
const waitTimeSeconds = txDetails.txEstimate.waitTimeSeconds;
|
|
1043
1043
|
return yield wallet.executeSwap({
|
|
1044
1044
|
input: params.input,
|
|
1045
1045
|
destinationAsset: params.destinationAsset,
|
|
1046
|
-
limit: limAssetAmount.baseAmount,
|
|
1047
1046
|
destinationAddress: params.destinationAddress,
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
interfaceID: params.interfaceID || 999,
|
|
1051
|
-
waitTimeSeconds,
|
|
1047
|
+
memo: txDetails.memo,
|
|
1048
|
+
waitTimeSeconds: txDetails.txEstimate.waitTimeSeconds,
|
|
1052
1049
|
});
|
|
1053
1050
|
});
|
|
1054
1051
|
}
|
|
1052
|
+
/**
|
|
1053
|
+
* Wraps estimate from thorchain query
|
|
1054
|
+
* @param params - estimate add liquidity
|
|
1055
|
+
* @returns - Estimate add lp object
|
|
1056
|
+
*/
|
|
1057
|
+
estimateAddLiquidity(params) {
|
|
1058
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1059
|
+
return this.thorchainQuery.estimateAddLP(params);
|
|
1060
|
+
});
|
|
1061
|
+
}
|
|
1062
|
+
/**
|
|
1063
|
+
* Wraps estimate withdraw from thorchain query
|
|
1064
|
+
* @param params - estimate withdraw liquidity
|
|
1065
|
+
* @returns - Estimate withdraw lp object
|
|
1066
|
+
*/
|
|
1067
|
+
estimateWithdrawLiquidity(params) {
|
|
1068
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1069
|
+
return this.thorchainQuery.estimateWithdrawLP(params);
|
|
1070
|
+
});
|
|
1071
|
+
}
|
|
1055
1072
|
/**
|
|
1056
1073
|
*
|
|
1057
1074
|
* @param wallet - wallet class
|
|
@@ -1062,6 +1079,8 @@ class ThorchainAMM {
|
|
|
1062
1079
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1063
1080
|
// Check amounts are greater than fees and use return estimated wait
|
|
1064
1081
|
const checkLPAdd = yield this.thorchainQuery.estimateAddLP(params);
|
|
1082
|
+
if (!checkLPAdd.canAdd)
|
|
1083
|
+
throw Error(`${checkLPAdd.errors}`);
|
|
1065
1084
|
return wallet.addLiquidity({
|
|
1066
1085
|
asset: params.asset,
|
|
1067
1086
|
rune: params.rune,
|
|
@@ -1076,11 +1095,11 @@ class ThorchainAMM {
|
|
|
1076
1095
|
* @param wallet - wallet needed to perform tx
|
|
1077
1096
|
* @return
|
|
1078
1097
|
*/
|
|
1079
|
-
|
|
1098
|
+
withdrawLiquidityPosition(wallet, params) {
|
|
1080
1099
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1081
1100
|
// Caution Dust Limits: BTC,BCH,LTC chains 10k sats; DOGE 1m Sats; ETH 0 wei; THOR 0 RUNE.
|
|
1082
1101
|
const withdrawParams = yield this.thorchainQuery.estimateWithdrawLP(params);
|
|
1083
|
-
return wallet.
|
|
1102
|
+
return wallet.withdrawLiquidity({
|
|
1084
1103
|
assetFee: withdrawParams.transactionFee.assetFee,
|
|
1085
1104
|
runeFee: withdrawParams.transactionFee.runeFee,
|
|
1086
1105
|
waitTimeSeconds: withdrawParams.estimatedWaitSeconds,
|
package/lib/index.js
CHANGED
|
@@ -15,7 +15,7 @@ var xchainThorchain = require('@xchainjs/xchain-thorchain');
|
|
|
15
15
|
var xchainUtil = require('@xchainjs/xchain-util');
|
|
16
16
|
var ethers = require('ethers');
|
|
17
17
|
var xchainEvm = require('@xchainjs/xchain-evm');
|
|
18
|
-
var
|
|
18
|
+
var xchainThorchainQuery = require('@xchainjs/xchain-thorchain-query');
|
|
19
19
|
|
|
20
20
|
/*! *****************************************************************************
|
|
21
21
|
Copyright (c) Microsoft Corporation.
|
|
@@ -680,24 +680,10 @@ class Wallet {
|
|
|
680
680
|
}
|
|
681
681
|
});
|
|
682
682
|
}
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
// create the full memo
|
|
688
|
-
let memo = `=:${xchainUtil.assetToString(swap.destinationAsset)}`;
|
|
689
|
-
if (swap.affiliateAddress != '' || swap.affiliateFee == undefined) {
|
|
690
|
-
memo = memo.concat(`:${swap.destinationAddress}:${lim}:${swap.affiliateAddress}:${swap.affiliateFee.amount().toFixed()}`);
|
|
691
|
-
}
|
|
692
|
-
else {
|
|
693
|
-
memo = memo.concat(`:${swap.destinationAddress}:${lim}`);
|
|
694
|
-
}
|
|
695
|
-
// If memo length is too long for BTC, trim it
|
|
696
|
-
if (xchainUtil.eqAsset(swap.input.asset, xchainUtil.AssetBTC) && memo.length > 80) {
|
|
697
|
-
memo = `=:${xchainUtil.assetToString(swap.destinationAsset)}:${swap.destinationAddress}`;
|
|
698
|
-
}
|
|
699
|
-
return memo;
|
|
700
|
-
}
|
|
683
|
+
/** Validate swap object
|
|
684
|
+
*
|
|
685
|
+
* @param swap - swap parameters
|
|
686
|
+
*/
|
|
701
687
|
validateSwap(swap) {
|
|
702
688
|
const errors = [];
|
|
703
689
|
const isThorchainDestinationAsset = swap.destinationAsset.synth || swap.destinationAsset.chain === xchainUtil.Chain.THORChain;
|
|
@@ -705,11 +691,31 @@ class Wallet {
|
|
|
705
691
|
if (!this.clients[chain].validateAddress(swap.destinationAddress)) {
|
|
706
692
|
errors.push(`destinationAddress ${swap.destinationAddress} is not a valid address`);
|
|
707
693
|
}
|
|
708
|
-
|
|
709
|
-
|
|
694
|
+
// Affiliate address should be THORName or THORAddress
|
|
695
|
+
const checkAffiliateAddress = swap.memo.split(':');
|
|
696
|
+
if (checkAffiliateAddress.length > 4) {
|
|
697
|
+
const affiliateAddress = checkAffiliateAddress[4];
|
|
698
|
+
if (affiliateAddress.length > 0) {
|
|
699
|
+
const isValidThorchainAddress = this.clients[xchainUtil.Chain.THORChain].validateAddress(affiliateAddress);
|
|
700
|
+
const isValidThorname = this.isThorname(affiliateAddress);
|
|
701
|
+
if (!(isValidThorchainAddress || isValidThorname))
|
|
702
|
+
errors.push(`affiliateAddress ${affiliateAddress} is not a valid THOR address`);
|
|
703
|
+
}
|
|
704
|
+
}
|
|
710
705
|
if (errors.length > 0)
|
|
711
706
|
throw Error(errors.join('\n'));
|
|
712
707
|
}
|
|
708
|
+
isThorname(name) {
|
|
709
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
710
|
+
const thornameDetails = yield this.thorchainQuery.thorchainCache.midgard.getTHORNameDetails(name);
|
|
711
|
+
return thornameDetails !== undefined;
|
|
712
|
+
});
|
|
713
|
+
}
|
|
714
|
+
/** Function handles all swaps from Rune to asset
|
|
715
|
+
*
|
|
716
|
+
* @param swap - swap parameters
|
|
717
|
+
* @returns - tx submitted object
|
|
718
|
+
*/
|
|
713
719
|
swapRuneTo(swap) {
|
|
714
720
|
return __awaiter(this, void 0, void 0, function* () {
|
|
715
721
|
const thorClient = this.clients.THOR;
|
|
@@ -717,11 +723,16 @@ class Wallet {
|
|
|
717
723
|
const hash = yield thorClient.deposit({
|
|
718
724
|
amount: swap.input.baseAmount,
|
|
719
725
|
asset: swap.input.asset,
|
|
720
|
-
memo:
|
|
726
|
+
memo: swap.memo,
|
|
721
727
|
});
|
|
722
728
|
return { hash, url: this.clients.THOR.getExplorerTxUrl(hash), waitTimeSeconds };
|
|
723
729
|
});
|
|
724
730
|
}
|
|
731
|
+
/** Function handles all swaps from Non Rune
|
|
732
|
+
*
|
|
733
|
+
* @param swap - swap object
|
|
734
|
+
* @returns - TxSubmitted object
|
|
735
|
+
*/
|
|
725
736
|
swapNonRune(swap) {
|
|
726
737
|
return __awaiter(this, void 0, void 0, function* () {
|
|
727
738
|
const client = this.clients[swap.input.asset.chain];
|
|
@@ -735,7 +746,7 @@ class Wallet {
|
|
|
735
746
|
asset: swap.input.asset,
|
|
736
747
|
amount: swap.input.baseAmount,
|
|
737
748
|
feeOption: swap.feeOption || xchainClient.FeeOption.Fast,
|
|
738
|
-
memo:
|
|
749
|
+
memo: swap.memo,
|
|
739
750
|
};
|
|
740
751
|
const hash = yield this.ethHelper.sendDeposit(params);
|
|
741
752
|
return { hash, url: client.getExplorerTxUrl(hash), waitTimeSeconds };
|
|
@@ -746,7 +757,7 @@ class Wallet {
|
|
|
746
757
|
asset: swap.input.asset,
|
|
747
758
|
amount: swap.input.baseAmount,
|
|
748
759
|
feeOption: swap.feeOption || xchainClient.FeeOption.Fast,
|
|
749
|
-
memo:
|
|
760
|
+
memo: swap.memo,
|
|
750
761
|
};
|
|
751
762
|
const evmHelper = new EvmHelper(this.clients.AVAX, this.thorchainQuery.thorchainCache);
|
|
752
763
|
const hash = yield evmHelper.sendDeposit(params);
|
|
@@ -758,15 +769,15 @@ class Wallet {
|
|
|
758
769
|
asset: swap.input.asset,
|
|
759
770
|
amount: swap.input.baseAmount,
|
|
760
771
|
recipient: inbound.address,
|
|
761
|
-
memo:
|
|
772
|
+
memo: swap.memo,
|
|
762
773
|
};
|
|
763
774
|
const hash = yield client.transfer(params);
|
|
764
775
|
return { hash, url: client.getExplorerTxUrl(hash), waitTimeSeconds };
|
|
765
776
|
}
|
|
766
777
|
});
|
|
767
778
|
}
|
|
768
|
-
/**
|
|
769
|
-
*
|
|
779
|
+
/** Function handles liquidity Add
|
|
780
|
+
* BASED OFF https://dev.thorchain.or›g/thorchain-dev/network/memos
|
|
770
781
|
* @param params input parameters needed to add liquidity
|
|
771
782
|
* @returns transaction details submitted
|
|
772
783
|
*/
|
|
@@ -803,12 +814,12 @@ class Wallet {
|
|
|
803
814
|
}
|
|
804
815
|
});
|
|
805
816
|
}
|
|
806
|
-
/**
|
|
817
|
+
/** Function handles liquidity Withdraw
|
|
807
818
|
*
|
|
808
819
|
* @param params - parameters required for liquidity position
|
|
809
820
|
* @returns object with tx response, url and wait time in seconds
|
|
810
821
|
*/
|
|
811
|
-
|
|
822
|
+
withdrawLiquidity(params) {
|
|
812
823
|
return __awaiter(this, void 0, void 0, function* () {
|
|
813
824
|
const assetClient = this.clients[params.assetFee.asset.chain];
|
|
814
825
|
const inboundAsgard = (yield this.thorchainQuery.thorchainCache.getInboundDetails())[params.assetFee.asset.chain]
|
|
@@ -820,26 +831,26 @@ class Wallet {
|
|
|
820
831
|
const txSubmitted = [];
|
|
821
832
|
if (params.assetAddress && params.runeAddress) {
|
|
822
833
|
constructedMemo = `-:${params.assetPool}:${basisPoints}`;
|
|
823
|
-
txSubmitted.push(yield this.
|
|
834
|
+
txSubmitted.push(yield this.withdrawAssetLP(params, constructedMemo, assetClient, waitTimeSeconds, inboundAsgard));
|
|
824
835
|
constructedMemo = `-:${params.assetPool}:${basisPoints}`;
|
|
825
|
-
txSubmitted.push(yield this.
|
|
836
|
+
txSubmitted.push(yield this.withdrawRuneLP(params, constructedMemo, thorchainClient, waitTimeSeconds));
|
|
826
837
|
return txSubmitted;
|
|
827
838
|
}
|
|
828
839
|
else if (params.assetAddress && !params.runeAddress) {
|
|
829
840
|
// asymmetrical asset only
|
|
830
841
|
constructedMemo = `-:${params.assetPool}:${basisPoints}`;
|
|
831
|
-
txSubmitted.push(yield this.
|
|
842
|
+
txSubmitted.push(yield this.withdrawAssetLP(params, constructedMemo, assetClient, waitTimeSeconds, inboundAsgard));
|
|
832
843
|
return txSubmitted;
|
|
833
844
|
}
|
|
834
845
|
else {
|
|
835
846
|
// asymmetrical rune only
|
|
836
847
|
constructedMemo = `-:${params.assetPool}:${basisPoints}`;
|
|
837
|
-
txSubmitted.push(yield this.
|
|
848
|
+
txSubmitted.push(yield this.withdrawRuneLP(params, constructedMemo, thorchainClient, waitTimeSeconds));
|
|
838
849
|
return txSubmitted;
|
|
839
850
|
}
|
|
840
851
|
});
|
|
841
852
|
}
|
|
842
|
-
/**
|
|
853
|
+
/** Function handles liquidity add for all non rune assets
|
|
843
854
|
*
|
|
844
855
|
* @param params - parameters for add liquidity
|
|
845
856
|
* @param constructedMemo - memo needed for thorchain
|
|
@@ -892,31 +903,31 @@ class Wallet {
|
|
|
892
903
|
}
|
|
893
904
|
});
|
|
894
905
|
}
|
|
895
|
-
/**
|
|
906
|
+
/** Function handles liquidity Withdraw for Non rune assets
|
|
896
907
|
*
|
|
897
|
-
* @param params - parameters for
|
|
908
|
+
* @param params - parameters for withdraw liquidity
|
|
898
909
|
* @param constructedMemo - memo needed for thorchain execution
|
|
899
910
|
* @param assetClient - asset client to call transfer
|
|
900
911
|
* @param waitTimeSeconds - return back estimated wait
|
|
901
912
|
* @param inboundAsgard - destination address
|
|
902
913
|
* @returns - tx object
|
|
903
914
|
*/
|
|
904
|
-
|
|
915
|
+
withdrawAssetLP(params, constructedMemo, assetClient, waitTimeSeconds, inboundAsgard) {
|
|
905
916
|
return __awaiter(this, void 0, void 0, function* () {
|
|
906
917
|
if (params.assetFee.asset.chain === xchainUtil.Chain.Ethereum) {
|
|
907
|
-
const
|
|
918
|
+
const withdrawParams = {
|
|
908
919
|
wallIndex: 0,
|
|
909
920
|
asset: params.assetFee.asset,
|
|
910
921
|
amount: params.assetFee.baseAmount,
|
|
911
922
|
feeOption: xchainClient.FeeOption.Fast,
|
|
912
923
|
memo: constructedMemo,
|
|
913
924
|
};
|
|
914
|
-
// console.log(
|
|
915
|
-
const hash = yield this.ethHelper.sendDeposit(
|
|
925
|
+
// console.log(withdrawParams.amount.amount().toNumber())
|
|
926
|
+
const hash = yield this.ethHelper.sendDeposit(withdrawParams);
|
|
916
927
|
return { hash, url: assetClient.getExplorerTxUrl(hash), waitTimeSeconds };
|
|
917
928
|
}
|
|
918
929
|
else if (params.assetFee.asset.chain === xchainUtil.Chain.Avalanche) {
|
|
919
|
-
const
|
|
930
|
+
const withdrawParams = {
|
|
920
931
|
wallIndex: 0,
|
|
921
932
|
asset: params.assetFee.asset,
|
|
922
933
|
amount: params.assetFee.baseAmount,
|
|
@@ -924,11 +935,11 @@ class Wallet {
|
|
|
924
935
|
memo: constructedMemo,
|
|
925
936
|
};
|
|
926
937
|
const evmHelper = new EvmHelper(this.clients.AVAX, this.thorchainQuery.thorchainCache);
|
|
927
|
-
const hash = yield evmHelper.sendDeposit(
|
|
938
|
+
const hash = yield evmHelper.sendDeposit(withdrawParams);
|
|
928
939
|
return { hash, url: assetClient.getExplorerTxUrl(hash), waitTimeSeconds };
|
|
929
940
|
}
|
|
930
941
|
else {
|
|
931
|
-
const
|
|
942
|
+
const withdrawParams = {
|
|
932
943
|
wallIndex: 0,
|
|
933
944
|
asset: params.assetFee.asset,
|
|
934
945
|
amount: params.assetFee.baseAmount,
|
|
@@ -936,7 +947,7 @@ class Wallet {
|
|
|
936
947
|
memo: constructedMemo,
|
|
937
948
|
};
|
|
938
949
|
try {
|
|
939
|
-
const hash = yield assetClient.transfer(
|
|
950
|
+
const hash = yield assetClient.transfer(withdrawParams);
|
|
940
951
|
return { hash, url: assetClient.getExplorerTxUrl(hash), waitTimeSeconds };
|
|
941
952
|
}
|
|
942
953
|
catch (err) {
|
|
@@ -946,7 +957,7 @@ class Wallet {
|
|
|
946
957
|
}
|
|
947
958
|
});
|
|
948
959
|
}
|
|
949
|
-
/**
|
|
960
|
+
/** Function handles liquidity Add for Rune only
|
|
950
961
|
*
|
|
951
962
|
* @param params - deposit parameters
|
|
952
963
|
* @param memo - memo needed to withdraw lp
|
|
@@ -960,18 +971,17 @@ class Wallet {
|
|
|
960
971
|
amount: params.rune.baseAmount,
|
|
961
972
|
memo: memo,
|
|
962
973
|
};
|
|
963
|
-
// console.log(addParams)
|
|
964
974
|
const hash = yield thorClient.deposit(addParams);
|
|
965
975
|
return { hash, url: thorchainClient.getExplorerTxUrl(hash), waitTimeSeconds };
|
|
966
976
|
});
|
|
967
977
|
}
|
|
968
|
-
/**
|
|
978
|
+
/** Function handles liquidity Withdraw for Rune only
|
|
969
979
|
*
|
|
970
|
-
* @param params -
|
|
980
|
+
* @param params - withdraw parameters
|
|
971
981
|
* @param memo - memo needed to withdraw lp
|
|
972
982
|
* @returns - tx object
|
|
973
983
|
*/
|
|
974
|
-
|
|
984
|
+
withdrawRuneLP(params, memo, thorchainClient, waitTimeSeconds) {
|
|
975
985
|
return __awaiter(this, void 0, void 0, function* () {
|
|
976
986
|
const thorClient = this.clients.THOR;
|
|
977
987
|
const addParams = {
|
|
@@ -979,14 +989,13 @@ class Wallet {
|
|
|
979
989
|
amount: params.runeFee.baseAmount,
|
|
980
990
|
memo: memo,
|
|
981
991
|
};
|
|
982
|
-
// console.log(addParams)
|
|
983
992
|
const hash = yield thorClient.deposit(addParams);
|
|
984
993
|
return { hash, url: thorchainClient.getExplorerTxUrl(hash), waitTimeSeconds };
|
|
985
994
|
});
|
|
986
995
|
}
|
|
987
996
|
}
|
|
988
997
|
|
|
989
|
-
const
|
|
998
|
+
const defaultQuery = new xchainThorchainQuery.ThorchainQuery();
|
|
990
999
|
/**
|
|
991
1000
|
* THORChain Class for interacting with THORChain.
|
|
992
1001
|
* Recommended main class to use for swapping with THORChain
|
|
@@ -999,7 +1008,7 @@ class ThorchainAMM {
|
|
|
999
1008
|
* @param thorchainQuery - an instance of the ThorchainQuery
|
|
1000
1009
|
* @returns ThorchainAMM
|
|
1001
1010
|
*/
|
|
1002
|
-
constructor(thorchainQuery) {
|
|
1011
|
+
constructor(thorchainQuery = defaultQuery) {
|
|
1003
1012
|
this.thorchainQuery = thorchainQuery;
|
|
1004
1013
|
}
|
|
1005
1014
|
/**
|
|
@@ -1030,32 +1039,40 @@ class ThorchainAMM {
|
|
|
1030
1039
|
*/
|
|
1031
1040
|
doSwap(wallet, params) {
|
|
1032
1041
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1033
|
-
//
|
|
1042
|
+
// Thorchain-query call satisfies the data needed for executeSwap to be called.
|
|
1034
1043
|
const txDetails = yield this.thorchainQuery.estimateSwap(params);
|
|
1035
1044
|
if (!txDetails.txEstimate.canSwap) {
|
|
1036
1045
|
throw Error(txDetails.txEstimate.errors.join('\n'));
|
|
1037
1046
|
}
|
|
1038
|
-
// remove any affiliateFee. netInput * affiliateFee (%age) of the destination asset type
|
|
1039
|
-
const affiliateFee = params.input.baseAmount.times(params.affiliateFeePercent || 0);
|
|
1040
|
-
// Work out LIM from the slip percentage
|
|
1041
|
-
let limPercentage = BN_1;
|
|
1042
|
-
if (params.slipLimit) {
|
|
1043
|
-
limPercentage = BN_1.minus(params.slipLimit || 1);
|
|
1044
|
-
} // else allowed slip is 100%
|
|
1045
|
-
const limAssetAmount = txDetails.txEstimate.netOutput.times(limPercentage);
|
|
1046
|
-
const waitTimeSeconds = txDetails.txEstimate.waitTimeSeconds;
|
|
1047
1047
|
return yield wallet.executeSwap({
|
|
1048
1048
|
input: params.input,
|
|
1049
1049
|
destinationAsset: params.destinationAsset,
|
|
1050
|
-
limit: limAssetAmount.baseAmount,
|
|
1051
1050
|
destinationAddress: params.destinationAddress,
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
interfaceID: params.interfaceID || 999,
|
|
1055
|
-
waitTimeSeconds,
|
|
1051
|
+
memo: txDetails.memo,
|
|
1052
|
+
waitTimeSeconds: txDetails.txEstimate.waitTimeSeconds,
|
|
1056
1053
|
});
|
|
1057
1054
|
});
|
|
1058
1055
|
}
|
|
1056
|
+
/**
|
|
1057
|
+
* Wraps estimate from thorchain query
|
|
1058
|
+
* @param params - estimate add liquidity
|
|
1059
|
+
* @returns - Estimate add lp object
|
|
1060
|
+
*/
|
|
1061
|
+
estimateAddLiquidity(params) {
|
|
1062
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1063
|
+
return this.thorchainQuery.estimateAddLP(params);
|
|
1064
|
+
});
|
|
1065
|
+
}
|
|
1066
|
+
/**
|
|
1067
|
+
* Wraps estimate withdraw from thorchain query
|
|
1068
|
+
* @param params - estimate withdraw liquidity
|
|
1069
|
+
* @returns - Estimate withdraw lp object
|
|
1070
|
+
*/
|
|
1071
|
+
estimateWithdrawLiquidity(params) {
|
|
1072
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1073
|
+
return this.thorchainQuery.estimateWithdrawLP(params);
|
|
1074
|
+
});
|
|
1075
|
+
}
|
|
1059
1076
|
/**
|
|
1060
1077
|
*
|
|
1061
1078
|
* @param wallet - wallet class
|
|
@@ -1066,6 +1083,8 @@ class ThorchainAMM {
|
|
|
1066
1083
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1067
1084
|
// Check amounts are greater than fees and use return estimated wait
|
|
1068
1085
|
const checkLPAdd = yield this.thorchainQuery.estimateAddLP(params);
|
|
1086
|
+
if (!checkLPAdd.canAdd)
|
|
1087
|
+
throw Error(`${checkLPAdd.errors}`);
|
|
1069
1088
|
return wallet.addLiquidity({
|
|
1070
1089
|
asset: params.asset,
|
|
1071
1090
|
rune: params.rune,
|
|
@@ -1080,11 +1099,11 @@ class ThorchainAMM {
|
|
|
1080
1099
|
* @param wallet - wallet needed to perform tx
|
|
1081
1100
|
* @return
|
|
1082
1101
|
*/
|
|
1083
|
-
|
|
1102
|
+
withdrawLiquidityPosition(wallet, params) {
|
|
1084
1103
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1085
1104
|
// Caution Dust Limits: BTC,BCH,LTC chains 10k sats; DOGE 1m Sats; ETH 0 wei; THOR 0 RUNE.
|
|
1086
1105
|
const withdrawParams = yield this.thorchainQuery.estimateWithdrawLP(params);
|
|
1087
|
-
return wallet.
|
|
1106
|
+
return wallet.withdrawLiquidity({
|
|
1088
1107
|
assetFee: withdrawParams.transactionFee.assetFee,
|
|
1089
1108
|
runeFee: withdrawParams.transactionFee.runeFee,
|
|
1090
1109
|
waitTimeSeconds: withdrawParams.estimatedWaitSeconds,
|
package/lib/thorchain-amm.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AddliquidityPosition, EstimateSwapParams,
|
|
1
|
+
import { AddliquidityPosition, EstimateAddLP, EstimateSwapParams, EstimateWithdrawLP, ThorchainQuery, TxDetails, WithdrawLiquidityPosition } from '@xchainjs/xchain-thorchain-query';
|
|
2
2
|
import { TxSubmitted } from './types';
|
|
3
3
|
import { Wallet } from './wallet';
|
|
4
4
|
/**
|
|
@@ -14,7 +14,7 @@ export declare class ThorchainAMM {
|
|
|
14
14
|
* @param thorchainQuery - an instance of the ThorchainQuery
|
|
15
15
|
* @returns ThorchainAMM
|
|
16
16
|
*/
|
|
17
|
-
constructor(thorchainQuery
|
|
17
|
+
constructor(thorchainQuery?: ThorchainQuery);
|
|
18
18
|
/**
|
|
19
19
|
* Provides a swap estimate for the given swap detail. Will check the params for errors before trying to get the estimate.
|
|
20
20
|
* Uses current pool data, works out inbound and outboud fee, affiliate fees and works out the expected wait time for the swap (in and out)
|
|
@@ -32,6 +32,18 @@ export declare class ThorchainAMM {
|
|
|
32
32
|
* @returns {SwapSubmitted} - Tx Hash, URL of BlockExplorer and expected wait time.
|
|
33
33
|
*/
|
|
34
34
|
doSwap(wallet: Wallet, params: EstimateSwapParams): Promise<TxSubmitted>;
|
|
35
|
+
/**
|
|
36
|
+
* Wraps estimate from thorchain query
|
|
37
|
+
* @param params - estimate add liquidity
|
|
38
|
+
* @returns - Estimate add lp object
|
|
39
|
+
*/
|
|
40
|
+
estimateAddLiquidity(params: AddliquidityPosition): Promise<EstimateAddLP>;
|
|
41
|
+
/**
|
|
42
|
+
* Wraps estimate withdraw from thorchain query
|
|
43
|
+
* @param params - estimate withdraw liquidity
|
|
44
|
+
* @returns - Estimate withdraw lp object
|
|
45
|
+
*/
|
|
46
|
+
estimateWithdrawLiquidity(params: WithdrawLiquidityPosition): Promise<EstimateWithdrawLP>;
|
|
35
47
|
/**
|
|
36
48
|
*
|
|
37
49
|
* @param wallet - wallet class
|
|
@@ -45,5 +57,5 @@ export declare class ThorchainAMM {
|
|
|
45
57
|
* @param wallet - wallet needed to perform tx
|
|
46
58
|
* @return
|
|
47
59
|
*/
|
|
48
|
-
|
|
60
|
+
withdrawLiquidityPosition(wallet: Wallet, params: WithdrawLiquidityPosition): Promise<TxSubmitted[]>;
|
|
49
61
|
}
|
package/lib/types.d.ts
CHANGED
|
@@ -1,20 +1,12 @@
|
|
|
1
1
|
import { FeeOption } from '@xchainjs/xchain-client';
|
|
2
2
|
import { CryptoAmount, LiquidityPool } from '@xchainjs/xchain-thorchain-query';
|
|
3
3
|
import { Address, Asset, BaseAmount } from '@xchainjs/xchain-util';
|
|
4
|
-
import { BigNumber } from 'bignumber.js';
|
|
5
|
-
export declare type MidgardConfig = {
|
|
6
|
-
apiRetries: number;
|
|
7
|
-
midgardBaseUrls: string[];
|
|
8
|
-
};
|
|
9
4
|
export declare type ExecuteSwap = {
|
|
10
5
|
input: CryptoAmount;
|
|
11
6
|
destinationAsset: Asset;
|
|
12
|
-
limit: BaseAmount;
|
|
13
7
|
destinationAddress: Address;
|
|
14
|
-
|
|
15
|
-
affiliateFee: BaseAmount;
|
|
8
|
+
memo: string;
|
|
16
9
|
feeOption?: FeeOption;
|
|
17
|
-
interfaceID: number;
|
|
18
10
|
waitTimeSeconds: number;
|
|
19
11
|
};
|
|
20
12
|
export declare type TxSubmitted = {
|
|
@@ -34,7 +26,7 @@ export declare type AddLiquidity = {
|
|
|
34
26
|
waitTimeSeconds: number;
|
|
35
27
|
assetPool: string;
|
|
36
28
|
};
|
|
37
|
-
export declare type
|
|
29
|
+
export declare type WithdrawLiquidity = {
|
|
38
30
|
assetFee: CryptoAmount;
|
|
39
31
|
runeFee: CryptoAmount;
|
|
40
32
|
waitTimeSeconds: number;
|
|
@@ -50,12 +42,3 @@ export declare type DepositParams = {
|
|
|
50
42
|
feeOption: FeeOption;
|
|
51
43
|
memo: string;
|
|
52
44
|
};
|
|
53
|
-
export declare type SwapOutput = {
|
|
54
|
-
output: CryptoAmount;
|
|
55
|
-
swapFee: CryptoAmount;
|
|
56
|
-
slip: BigNumber;
|
|
57
|
-
};
|
|
58
|
-
export declare type UnitData = {
|
|
59
|
-
liquidityUnits: BigNumber;
|
|
60
|
-
totalUnits: BigNumber;
|
|
61
|
-
};
|
package/lib/wallet.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Balance, XChainClient } from '@xchainjs/xchain-client';
|
|
2
2
|
import { ThorchainQuery } from '@xchainjs/xchain-thorchain-query';
|
|
3
3
|
import { Chain } from '@xchainjs/xchain-util';
|
|
4
|
-
import { AddLiquidity, ExecuteSwap,
|
|
4
|
+
import { AddLiquidity, ExecuteSwap, TxSubmitted, WithdrawLiquidity } from './types';
|
|
5
5
|
declare type AllBalances = {
|
|
6
6
|
chain: Chain;
|
|
7
7
|
address: string;
|
|
@@ -36,23 +36,37 @@ export declare class Wallet {
|
|
|
36
36
|
* @see ThorchainAMM.doSwap()
|
|
37
37
|
*/
|
|
38
38
|
executeSwap(swap: ExecuteSwap): Promise<TxSubmitted>;
|
|
39
|
-
|
|
39
|
+
/** Validate swap object
|
|
40
|
+
*
|
|
41
|
+
* @param swap - swap parameters
|
|
42
|
+
*/
|
|
40
43
|
private validateSwap;
|
|
44
|
+
private isThorname;
|
|
45
|
+
/** Function handles all swaps from Rune to asset
|
|
46
|
+
*
|
|
47
|
+
* @param swap - swap parameters
|
|
48
|
+
* @returns - tx submitted object
|
|
49
|
+
*/
|
|
41
50
|
private swapRuneTo;
|
|
42
|
-
|
|
43
|
-
/** BASED OFF https://dev.thorchain.or›g/thorchain-dev/network/memos
|
|
51
|
+
/** Function handles all swaps from Non Rune
|
|
44
52
|
*
|
|
53
|
+
* @param swap - swap object
|
|
54
|
+
* @returns - TxSubmitted object
|
|
55
|
+
*/
|
|
56
|
+
private swapNonRune;
|
|
57
|
+
/** Function handles liquidity Add
|
|
58
|
+
* BASED OFF https://dev.thorchain.or›g/thorchain-dev/network/memos
|
|
45
59
|
* @param params input parameters needed to add liquidity
|
|
46
60
|
* @returns transaction details submitted
|
|
47
61
|
*/
|
|
48
62
|
addLiquidity(params: AddLiquidity): Promise<TxSubmitted[]>;
|
|
49
|
-
/**
|
|
63
|
+
/** Function handles liquidity Withdraw
|
|
50
64
|
*
|
|
51
65
|
* @param params - parameters required for liquidity position
|
|
52
66
|
* @returns object with tx response, url and wait time in seconds
|
|
53
67
|
*/
|
|
54
|
-
|
|
55
|
-
/**
|
|
68
|
+
withdrawLiquidity(params: WithdrawLiquidity): Promise<TxSubmitted[]>;
|
|
69
|
+
/** Function handles liquidity add for all non rune assets
|
|
56
70
|
*
|
|
57
71
|
* @param params - parameters for add liquidity
|
|
58
72
|
* @param constructedMemo - memo needed for thorchain
|
|
@@ -62,29 +76,29 @@ export declare class Wallet {
|
|
|
62
76
|
* @returns - tx object
|
|
63
77
|
*/
|
|
64
78
|
private addAssetLP;
|
|
65
|
-
/**
|
|
79
|
+
/** Function handles liquidity Withdraw for Non rune assets
|
|
66
80
|
*
|
|
67
|
-
* @param params - parameters for
|
|
81
|
+
* @param params - parameters for withdraw liquidity
|
|
68
82
|
* @param constructedMemo - memo needed for thorchain execution
|
|
69
83
|
* @param assetClient - asset client to call transfer
|
|
70
84
|
* @param waitTimeSeconds - return back estimated wait
|
|
71
85
|
* @param inboundAsgard - destination address
|
|
72
86
|
* @returns - tx object
|
|
73
87
|
*/
|
|
74
|
-
private
|
|
75
|
-
/**
|
|
88
|
+
private withdrawAssetLP;
|
|
89
|
+
/** Function handles liquidity Add for Rune only
|
|
76
90
|
*
|
|
77
91
|
* @param params - deposit parameters
|
|
78
92
|
* @param memo - memo needed to withdraw lp
|
|
79
93
|
* @returns - tx object
|
|
80
94
|
*/
|
|
81
95
|
private addRuneLP;
|
|
82
|
-
/**
|
|
96
|
+
/** Function handles liquidity Withdraw for Rune only
|
|
83
97
|
*
|
|
84
|
-
* @param params -
|
|
98
|
+
* @param params - withdraw parameters
|
|
85
99
|
* @param memo - memo needed to withdraw lp
|
|
86
100
|
* @returns - tx object
|
|
87
101
|
*/
|
|
88
|
-
private
|
|
102
|
+
private withdrawRuneLP;
|
|
89
103
|
}
|
|
90
104
|
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.3",
|
|
4
4
|
"description": "module that exposes estimating & swappping cryptocurrency assets on thorchain",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"THORChain",
|
|
@@ -48,13 +48,13 @@
|
|
|
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
|
-
"@xchainjs/xchain-evm": "^0.1.0
|
|
52
|
-
"@xchainjs/xchain-avax": "^0.1.0
|
|
51
|
+
"@xchainjs/xchain-evm": "^0.1.0",
|
|
52
|
+
"@xchainjs/xchain-avax": "^0.1.0",
|
|
53
53
|
"@xchainjs/xchain-litecoin": "^0.10.3",
|
|
54
|
-
"@xchainjs/xchain-midgard": "0.
|
|
54
|
+
"@xchainjs/xchain-midgard": "0.2.0",
|
|
55
55
|
"@xchainjs/xchain-thorchain": "^0.27.0",
|
|
56
|
-
"@xchainjs/xchain-thorchain-query": "^0.1.
|
|
57
|
-
"@xchainjs/xchain-thornode": "^0.1.
|
|
56
|
+
"@xchainjs/xchain-thorchain-query": "^0.1.4",
|
|
57
|
+
"@xchainjs/xchain-thornode": "^0.1.1",
|
|
58
58
|
"@xchainjs/xchain-util": "^0.11.0",
|
|
59
59
|
"axios": "^0.25.0",
|
|
60
60
|
"axios-retry": "^3.2.5",
|
|
@@ -73,22 +73,21 @@
|
|
|
73
73
|
"@binance-chain/javascript-sdk": "^4.2.0",
|
|
74
74
|
"@cosmos-client/core": "0.45.13",
|
|
75
75
|
"@psf/bitcoincashjs-lib": "^4.0.2",
|
|
76
|
-
"@
|
|
77
|
-
"@xchainjs/xchain-
|
|
78
|
-
"@xchainjs/xchain-
|
|
79
|
-
"@xchainjs/xchain-bitcoincash": "^0.15.0",
|
|
76
|
+
"@xchainjs/xchain-binance": "^5.6.4",
|
|
77
|
+
"@xchainjs/xchain-bitcoin": "^0.20.4",
|
|
78
|
+
"@xchainjs/xchain-bitcoincash": "^0.15.3",
|
|
80
79
|
"@xchainjs/xchain-client": "^0.13.2",
|
|
81
|
-
"@xchainjs/xchain-cosmos": "^0.20.
|
|
80
|
+
"@xchainjs/xchain-cosmos": "^0.20.3",
|
|
82
81
|
"@xchainjs/xchain-crypto": "^0.2.6",
|
|
83
|
-
"@xchainjs/xchain-doge": "^0.5.
|
|
84
|
-
"@xchainjs/xchain-ethereum": "^0.27.
|
|
85
|
-
"@xchainjs/xchain-evm": "^0.1.0
|
|
86
|
-
"@xchainjs/xchain-avax": "^0.1.0
|
|
87
|
-
"@xchainjs/xchain-litecoin": "^0.10.
|
|
88
|
-
"@xchainjs/xchain-midgard": "0.
|
|
82
|
+
"@xchainjs/xchain-doge": "^0.5.4",
|
|
83
|
+
"@xchainjs/xchain-ethereum": "^0.27.3",
|
|
84
|
+
"@xchainjs/xchain-evm": "^0.1.0",
|
|
85
|
+
"@xchainjs/xchain-avax": "^0.1.0",
|
|
86
|
+
"@xchainjs/xchain-litecoin": "^0.10.4",
|
|
87
|
+
"@xchainjs/xchain-midgard": "0.2.0",
|
|
89
88
|
"@xchainjs/xchain-thornode": "^0.1.0",
|
|
90
|
-
"@xchainjs/xchain-thorchain": "^0.
|
|
91
|
-
"@xchainjs/xchain-thorchain-query": "^0.1.
|
|
89
|
+
"@xchainjs/xchain-thorchain": "^0.27.1",
|
|
90
|
+
"@xchainjs/xchain-thorchain-query": "^0.1.2",
|
|
92
91
|
"@xchainjs/xchain-util": "^0.11.0",
|
|
93
92
|
"axios": "^0.25.0",
|
|
94
93
|
"axios-retry": "^3.2.5",
|