@xchainjs/xchain-thorchain-amm 0.3.6 → 0.3.8

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 CHANGED
@@ -827,6 +827,110 @@ class Wallet {
827
827
  }
828
828
  });
829
829
  }
830
+ /**
831
+ *
832
+ * @param assetAmount - amount to add
833
+ * @param memo - memo required
834
+ * @param waitTimeSeconds - expected wait for the transaction to be processed
835
+ * @returns
836
+ */
837
+ addSavers(assetAmount, memo, toAddress, waitTimeSeconds) {
838
+ return __awaiter(this, void 0, void 0, function* () {
839
+ const assetClient = this.clients[assetAmount.asset.chain];
840
+ if (assetAmount.asset.chain === Chain.Ethereum) {
841
+ const addParams = {
842
+ wallIndex: 0,
843
+ asset: assetAmount.asset,
844
+ amount: assetAmount.baseAmount,
845
+ feeOption: FeeOption.Fast,
846
+ memo: memo,
847
+ };
848
+ const hash = yield this.ethHelper.sendDeposit(addParams);
849
+ return { hash, url: assetClient.getExplorerTxUrl(hash), waitTimeSeconds };
850
+ }
851
+ else if (assetAmount.asset.chain === Chain.Avalanche) {
852
+ const addParams = {
853
+ wallIndex: 0,
854
+ asset: assetAmount.asset,
855
+ amount: assetAmount.baseAmount,
856
+ feeOption: FeeOption.Fast,
857
+ memo: memo,
858
+ };
859
+ const evmHelper = new EvmHelper(this.clients.AVAX, this.thorchainQuery.thorchainCache);
860
+ const hash = yield evmHelper.sendDeposit(addParams);
861
+ return { hash, url: assetClient.getExplorerTxUrl(hash), waitTimeSeconds };
862
+ }
863
+ else {
864
+ const addParams = {
865
+ wallIndex: 0,
866
+ asset: assetAmount.asset,
867
+ amount: assetAmount.baseAmount,
868
+ recipient: toAddress,
869
+ memo: memo,
870
+ };
871
+ try {
872
+ const hash = yield assetClient.transfer(addParams);
873
+ return { hash, url: assetClient.getExplorerTxUrl(hash), waitTimeSeconds };
874
+ }
875
+ catch (err) {
876
+ const hash = JSON.stringify(err);
877
+ return { hash, url: assetClient.getExplorerAddressUrl(assetClient.getAddress()), waitTimeSeconds };
878
+ }
879
+ }
880
+ });
881
+ }
882
+ /**
883
+ *
884
+ * @param assetAmount - amount to withdraw
885
+ * @param memo - memo required
886
+ * @param waitTimeSeconds - expected wait for the transaction to be processed
887
+ * @returns
888
+ */
889
+ withdrawSavers(dustAssetAmount, memo, toAddress, waitTimeSeconds) {
890
+ return __awaiter(this, void 0, void 0, function* () {
891
+ const assetClient = this.clients[dustAssetAmount.asset.chain];
892
+ if (dustAssetAmount.asset.chain === Chain.Ethereum) {
893
+ const addParams = {
894
+ wallIndex: 0,
895
+ asset: dustAssetAmount.asset,
896
+ amount: dustAssetAmount.baseAmount,
897
+ feeOption: FeeOption.Fast,
898
+ memo: memo,
899
+ };
900
+ const hash = yield this.ethHelper.sendDeposit(addParams);
901
+ return { hash, url: assetClient.getExplorerTxUrl(hash), waitTimeSeconds };
902
+ }
903
+ else if (dustAssetAmount.asset.chain === Chain.Avalanche) {
904
+ const addParams = {
905
+ wallIndex: 0,
906
+ asset: dustAssetAmount.asset,
907
+ amount: dustAssetAmount.baseAmount,
908
+ feeOption: FeeOption.Fast,
909
+ memo: memo,
910
+ };
911
+ const evmHelper = new EvmHelper(this.clients.AVAX, this.thorchainQuery.thorchainCache);
912
+ const hash = yield evmHelper.sendDeposit(addParams);
913
+ return { hash, url: assetClient.getExplorerTxUrl(hash), waitTimeSeconds };
914
+ }
915
+ else {
916
+ const addParams = {
917
+ wallIndex: 0,
918
+ asset: dustAssetAmount.asset,
919
+ amount: dustAssetAmount.baseAmount,
920
+ recipient: toAddress,
921
+ memo: memo,
922
+ };
923
+ try {
924
+ const hash = yield assetClient.transfer(addParams);
925
+ return { hash, url: assetClient.getExplorerTxUrl(hash), waitTimeSeconds };
926
+ }
927
+ catch (err) {
928
+ const hash = JSON.stringify(err);
929
+ return { hash, url: assetClient.getExplorerAddressUrl(assetClient.getAddress()), waitTimeSeconds };
930
+ }
931
+ }
932
+ });
933
+ }
830
934
  /** Function handles liquidity add for all non rune assets
831
935
  *
832
936
  * @param params - parameters for add liquidity
@@ -997,14 +1101,16 @@ class ThorchainAMM {
997
1101
  * @returns The SwapEstimate
998
1102
  */
999
1103
  estimateSwap({ input, destinationAsset, destinationAddress, affiliateAddress = '', interfaceID = `555`, affiliateFeeBasisPoints = 0, slipLimit, }) {
1000
- return this.thorchainQuery.estimateSwap({
1001
- input,
1002
- destinationAsset,
1003
- destinationAddress,
1004
- affiliateAddress,
1005
- interfaceID,
1006
- affiliateFeeBasisPoints,
1007
- slipLimit,
1104
+ return __awaiter(this, void 0, void 0, function* () {
1105
+ return yield this.thorchainQuery.estimateSwap({
1106
+ input,
1107
+ destinationAsset,
1108
+ destinationAddress,
1109
+ affiliateAddress,
1110
+ interfaceID,
1111
+ affiliateFeeBasisPoints,
1112
+ slipLimit,
1113
+ });
1008
1114
  });
1009
1115
  }
1010
1116
  /**
@@ -1037,7 +1143,7 @@ class ThorchainAMM {
1037
1143
  */
1038
1144
  estimateAddLiquidity(params) {
1039
1145
  return __awaiter(this, void 0, void 0, function* () {
1040
- return this.thorchainQuery.estimateAddLP(params);
1146
+ return yield this.thorchainQuery.estimateAddLP(params);
1041
1147
  });
1042
1148
  }
1043
1149
  /**
@@ -1047,7 +1153,7 @@ class ThorchainAMM {
1047
1153
  */
1048
1154
  estimateWithdrawLiquidity(params) {
1049
1155
  return __awaiter(this, void 0, void 0, function* () {
1050
- return this.thorchainQuery.estimateWithdrawLP(params);
1156
+ return yield this.thorchainQuery.estimateWithdrawLP(params);
1051
1157
  });
1052
1158
  }
1053
1159
  /**
@@ -1062,7 +1168,7 @@ class ThorchainAMM {
1062
1168
  const checkLPAdd = yield this.thorchainQuery.estimateAddLP(params);
1063
1169
  if (!checkLPAdd.canAdd)
1064
1170
  throw Error(`${checkLPAdd.errors}`);
1065
- return wallet.addLiquidity({
1171
+ return yield wallet.addLiquidity({
1066
1172
  asset: params.asset,
1067
1173
  rune: params.rune,
1068
1174
  waitTimeSeconds: checkLPAdd.estimatedWaitSeconds,
@@ -1080,7 +1186,7 @@ class ThorchainAMM {
1080
1186
  return __awaiter(this, void 0, void 0, function* () {
1081
1187
  // Caution Dust Limits: BTC,BCH,LTC chains 10k sats; DOGE 1m Sats; ETH 0 wei; THOR 0 RUNE.
1082
1188
  const withdrawParams = yield this.thorchainQuery.estimateWithdrawLP(params);
1083
- return wallet.withdrawLiquidity({
1189
+ return yield wallet.withdrawLiquidity({
1084
1190
  assetFee: withdrawParams.inbound.fees.asset,
1085
1191
  runeFee: withdrawParams.inbound.fees.rune,
1086
1192
  waitTimeSeconds: withdrawParams.estimatedWaitSeconds,
@@ -1091,6 +1197,32 @@ class ThorchainAMM {
1091
1197
  });
1092
1198
  });
1093
1199
  }
1200
+ /**
1201
+ *
1202
+ * @param wallet - wallet needed to execute tx
1203
+ * @param addAssetAmount - asset amount being added to savers
1204
+ * @returns - submitted tx
1205
+ */
1206
+ addSaver(wallet, addAssetAmount) {
1207
+ return __awaiter(this, void 0, void 0, function* () {
1208
+ const addEstimate = yield this.thorchainQuery.estimateAddSaver(addAssetAmount);
1209
+ if (!addEstimate.canAddSaver)
1210
+ throw Error(`Cannot add to savers`);
1211
+ return yield wallet.addSavers(addEstimate.assetAmount, addEstimate.memo, addEstimate.toAddress, addEstimate.estimatedWaitTime);
1212
+ });
1213
+ }
1214
+ /**
1215
+ *
1216
+ * @param wallet - wallet to execute the transaction
1217
+ * @param withdrawParams - params needed for withdraw
1218
+ * @returns
1219
+ */
1220
+ withdrawSaver(wallet, withdrawParams) {
1221
+ return __awaiter(this, void 0, void 0, function* () {
1222
+ const withdrawEstimate = yield this.thorchainQuery.estimateWithdrawSaver(withdrawParams);
1223
+ return yield wallet.withdrawSavers(withdrawEstimate.dustAmount, withdrawEstimate.memo, withdrawEstimate.toAddress, withdrawEstimate.estimatedWaitTime);
1224
+ });
1225
+ }
1094
1226
  }
1095
1227
 
1096
1228
  export { ThorchainAMM, Wallet };
package/lib/index.js CHANGED
@@ -831,6 +831,110 @@ class Wallet {
831
831
  }
832
832
  });
833
833
  }
834
+ /**
835
+ *
836
+ * @param assetAmount - amount to add
837
+ * @param memo - memo required
838
+ * @param waitTimeSeconds - expected wait for the transaction to be processed
839
+ * @returns
840
+ */
841
+ addSavers(assetAmount, memo, toAddress, waitTimeSeconds) {
842
+ return __awaiter(this, void 0, void 0, function* () {
843
+ const assetClient = this.clients[assetAmount.asset.chain];
844
+ if (assetAmount.asset.chain === xchainUtil.Chain.Ethereum) {
845
+ const addParams = {
846
+ wallIndex: 0,
847
+ asset: assetAmount.asset,
848
+ amount: assetAmount.baseAmount,
849
+ feeOption: xchainClient.FeeOption.Fast,
850
+ memo: memo,
851
+ };
852
+ const hash = yield this.ethHelper.sendDeposit(addParams);
853
+ return { hash, url: assetClient.getExplorerTxUrl(hash), waitTimeSeconds };
854
+ }
855
+ else if (assetAmount.asset.chain === xchainUtil.Chain.Avalanche) {
856
+ const addParams = {
857
+ wallIndex: 0,
858
+ asset: assetAmount.asset,
859
+ amount: assetAmount.baseAmount,
860
+ feeOption: xchainClient.FeeOption.Fast,
861
+ memo: memo,
862
+ };
863
+ const evmHelper = new EvmHelper(this.clients.AVAX, this.thorchainQuery.thorchainCache);
864
+ const hash = yield evmHelper.sendDeposit(addParams);
865
+ return { hash, url: assetClient.getExplorerTxUrl(hash), waitTimeSeconds };
866
+ }
867
+ else {
868
+ const addParams = {
869
+ wallIndex: 0,
870
+ asset: assetAmount.asset,
871
+ amount: assetAmount.baseAmount,
872
+ recipient: toAddress,
873
+ memo: memo,
874
+ };
875
+ try {
876
+ const hash = yield assetClient.transfer(addParams);
877
+ return { hash, url: assetClient.getExplorerTxUrl(hash), waitTimeSeconds };
878
+ }
879
+ catch (err) {
880
+ const hash = JSON.stringify(err);
881
+ return { hash, url: assetClient.getExplorerAddressUrl(assetClient.getAddress()), waitTimeSeconds };
882
+ }
883
+ }
884
+ });
885
+ }
886
+ /**
887
+ *
888
+ * @param assetAmount - amount to withdraw
889
+ * @param memo - memo required
890
+ * @param waitTimeSeconds - expected wait for the transaction to be processed
891
+ * @returns
892
+ */
893
+ withdrawSavers(dustAssetAmount, memo, toAddress, waitTimeSeconds) {
894
+ return __awaiter(this, void 0, void 0, function* () {
895
+ const assetClient = this.clients[dustAssetAmount.asset.chain];
896
+ if (dustAssetAmount.asset.chain === xchainUtil.Chain.Ethereum) {
897
+ const addParams = {
898
+ wallIndex: 0,
899
+ asset: dustAssetAmount.asset,
900
+ amount: dustAssetAmount.baseAmount,
901
+ feeOption: xchainClient.FeeOption.Fast,
902
+ memo: memo,
903
+ };
904
+ const hash = yield this.ethHelper.sendDeposit(addParams);
905
+ return { hash, url: assetClient.getExplorerTxUrl(hash), waitTimeSeconds };
906
+ }
907
+ else if (dustAssetAmount.asset.chain === xchainUtil.Chain.Avalanche) {
908
+ const addParams = {
909
+ wallIndex: 0,
910
+ asset: dustAssetAmount.asset,
911
+ amount: dustAssetAmount.baseAmount,
912
+ feeOption: xchainClient.FeeOption.Fast,
913
+ memo: memo,
914
+ };
915
+ const evmHelper = new EvmHelper(this.clients.AVAX, this.thorchainQuery.thorchainCache);
916
+ const hash = yield evmHelper.sendDeposit(addParams);
917
+ return { hash, url: assetClient.getExplorerTxUrl(hash), waitTimeSeconds };
918
+ }
919
+ else {
920
+ const addParams = {
921
+ wallIndex: 0,
922
+ asset: dustAssetAmount.asset,
923
+ amount: dustAssetAmount.baseAmount,
924
+ recipient: toAddress,
925
+ memo: memo,
926
+ };
927
+ try {
928
+ const hash = yield assetClient.transfer(addParams);
929
+ return { hash, url: assetClient.getExplorerTxUrl(hash), waitTimeSeconds };
930
+ }
931
+ catch (err) {
932
+ const hash = JSON.stringify(err);
933
+ return { hash, url: assetClient.getExplorerAddressUrl(assetClient.getAddress()), waitTimeSeconds };
934
+ }
935
+ }
936
+ });
937
+ }
834
938
  /** Function handles liquidity add for all non rune assets
835
939
  *
836
940
  * @param params - parameters for add liquidity
@@ -1001,14 +1105,16 @@ class ThorchainAMM {
1001
1105
  * @returns The SwapEstimate
1002
1106
  */
1003
1107
  estimateSwap({ input, destinationAsset, destinationAddress, affiliateAddress = '', interfaceID = `555`, affiliateFeeBasisPoints = 0, slipLimit, }) {
1004
- return this.thorchainQuery.estimateSwap({
1005
- input,
1006
- destinationAsset,
1007
- destinationAddress,
1008
- affiliateAddress,
1009
- interfaceID,
1010
- affiliateFeeBasisPoints,
1011
- slipLimit,
1108
+ return __awaiter(this, void 0, void 0, function* () {
1109
+ return yield this.thorchainQuery.estimateSwap({
1110
+ input,
1111
+ destinationAsset,
1112
+ destinationAddress,
1113
+ affiliateAddress,
1114
+ interfaceID,
1115
+ affiliateFeeBasisPoints,
1116
+ slipLimit,
1117
+ });
1012
1118
  });
1013
1119
  }
1014
1120
  /**
@@ -1041,7 +1147,7 @@ class ThorchainAMM {
1041
1147
  */
1042
1148
  estimateAddLiquidity(params) {
1043
1149
  return __awaiter(this, void 0, void 0, function* () {
1044
- return this.thorchainQuery.estimateAddLP(params);
1150
+ return yield this.thorchainQuery.estimateAddLP(params);
1045
1151
  });
1046
1152
  }
1047
1153
  /**
@@ -1051,7 +1157,7 @@ class ThorchainAMM {
1051
1157
  */
1052
1158
  estimateWithdrawLiquidity(params) {
1053
1159
  return __awaiter(this, void 0, void 0, function* () {
1054
- return this.thorchainQuery.estimateWithdrawLP(params);
1160
+ return yield this.thorchainQuery.estimateWithdrawLP(params);
1055
1161
  });
1056
1162
  }
1057
1163
  /**
@@ -1066,7 +1172,7 @@ class ThorchainAMM {
1066
1172
  const checkLPAdd = yield this.thorchainQuery.estimateAddLP(params);
1067
1173
  if (!checkLPAdd.canAdd)
1068
1174
  throw Error(`${checkLPAdd.errors}`);
1069
- return wallet.addLiquidity({
1175
+ return yield wallet.addLiquidity({
1070
1176
  asset: params.asset,
1071
1177
  rune: params.rune,
1072
1178
  waitTimeSeconds: checkLPAdd.estimatedWaitSeconds,
@@ -1084,7 +1190,7 @@ class ThorchainAMM {
1084
1190
  return __awaiter(this, void 0, void 0, function* () {
1085
1191
  // Caution Dust Limits: BTC,BCH,LTC chains 10k sats; DOGE 1m Sats; ETH 0 wei; THOR 0 RUNE.
1086
1192
  const withdrawParams = yield this.thorchainQuery.estimateWithdrawLP(params);
1087
- return wallet.withdrawLiquidity({
1193
+ return yield wallet.withdrawLiquidity({
1088
1194
  assetFee: withdrawParams.inbound.fees.asset,
1089
1195
  runeFee: withdrawParams.inbound.fees.rune,
1090
1196
  waitTimeSeconds: withdrawParams.estimatedWaitSeconds,
@@ -1095,6 +1201,32 @@ class ThorchainAMM {
1095
1201
  });
1096
1202
  });
1097
1203
  }
1204
+ /**
1205
+ *
1206
+ * @param wallet - wallet needed to execute tx
1207
+ * @param addAssetAmount - asset amount being added to savers
1208
+ * @returns - submitted tx
1209
+ */
1210
+ addSaver(wallet, addAssetAmount) {
1211
+ return __awaiter(this, void 0, void 0, function* () {
1212
+ const addEstimate = yield this.thorchainQuery.estimateAddSaver(addAssetAmount);
1213
+ if (!addEstimate.canAddSaver)
1214
+ throw Error(`Cannot add to savers`);
1215
+ return yield wallet.addSavers(addEstimate.assetAmount, addEstimate.memo, addEstimate.toAddress, addEstimate.estimatedWaitTime);
1216
+ });
1217
+ }
1218
+ /**
1219
+ *
1220
+ * @param wallet - wallet to execute the transaction
1221
+ * @param withdrawParams - params needed for withdraw
1222
+ * @returns
1223
+ */
1224
+ withdrawSaver(wallet, withdrawParams) {
1225
+ return __awaiter(this, void 0, void 0, function* () {
1226
+ const withdrawEstimate = yield this.thorchainQuery.estimateWithdrawSaver(withdrawParams);
1227
+ return yield wallet.withdrawSavers(withdrawEstimate.dustAmount, withdrawEstimate.memo, withdrawEstimate.toAddress, withdrawEstimate.estimatedWaitTime);
1228
+ });
1229
+ }
1098
1230
  }
1099
1231
 
1100
1232
  exports.ThorchainAMM = ThorchainAMM;
@@ -1,4 +1,4 @@
1
- import { AddliquidityPosition, EstimateAddLP, EstimateSwapParams, EstimateWithdrawLP, ThorchainQuery, TxDetails, WithdrawLiquidityPosition } from '@xchainjs/xchain-thorchain-query';
1
+ import { AddliquidityPosition, CryptoAmount, EstimateAddLP, EstimateSwapParams, EstimateWithdrawLP, SaversWithdraw, ThorchainQuery, TxDetails, WithdrawLiquidityPosition } from '@xchainjs/xchain-thorchain-query';
2
2
  import { TxSubmitted } from './types';
3
3
  import { Wallet } from './wallet';
4
4
  /**
@@ -58,4 +58,18 @@ export declare class ThorchainAMM {
58
58
  * @return
59
59
  */
60
60
  withdrawLiquidityPosition(wallet: Wallet, params: WithdrawLiquidityPosition): Promise<TxSubmitted[]>;
61
+ /**
62
+ *
63
+ * @param wallet - wallet needed to execute tx
64
+ * @param addAssetAmount - asset amount being added to savers
65
+ * @returns - submitted tx
66
+ */
67
+ addSaver(wallet: Wallet, addAssetAmount: CryptoAmount): Promise<TxSubmitted>;
68
+ /**
69
+ *
70
+ * @param wallet - wallet to execute the transaction
71
+ * @param withdrawParams - params needed for withdraw
72
+ * @returns
73
+ */
74
+ withdrawSaver(wallet: Wallet, withdrawParams: SaversWithdraw): Promise<TxSubmitted>;
61
75
  }
package/lib/wallet.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Balance, XChainClient } from '@xchainjs/xchain-client';
2
- import { ThorchainQuery } from '@xchainjs/xchain-thorchain-query';
3
- import { Chain } from '@xchainjs/xchain-util';
2
+ import { CryptoAmount, ThorchainQuery } from '@xchainjs/xchain-thorchain-query';
3
+ import { Address, Chain } from '@xchainjs/xchain-util';
4
4
  import { AddLiquidity, ExecuteSwap, TxSubmitted, WithdrawLiquidity } from './types';
5
5
  declare type AllBalances = {
6
6
  chain: Chain;
@@ -66,6 +66,22 @@ export declare class Wallet {
66
66
  * @returns object with tx response, url and wait time in seconds
67
67
  */
68
68
  withdrawLiquidity(params: WithdrawLiquidity): Promise<TxSubmitted[]>;
69
+ /**
70
+ *
71
+ * @param assetAmount - amount to add
72
+ * @param memo - memo required
73
+ * @param waitTimeSeconds - expected wait for the transaction to be processed
74
+ * @returns
75
+ */
76
+ addSavers(assetAmount: CryptoAmount, memo: string, toAddress: Address, waitTimeSeconds: number): Promise<TxSubmitted>;
77
+ /**
78
+ *
79
+ * @param assetAmount - amount to withdraw
80
+ * @param memo - memo required
81
+ * @param waitTimeSeconds - expected wait for the transaction to be processed
82
+ * @returns
83
+ */
84
+ withdrawSavers(dustAssetAmount: CryptoAmount, memo: string, toAddress: Address, waitTimeSeconds: number): Promise<TxSubmitted>;
69
85
  /** Function handles liquidity add for all non rune assets
70
86
  *
71
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.3.6",
3
+ "version": "0.3.8",
4
4
  "description": "module that exposes estimating & swappping cryptocurrency assets on thorchain",
5
5
  "keywords": [
6
6
  "THORChain",
@@ -51,10 +51,10 @@
51
51
  "@xchainjs/xchain-evm": "^0.1.0",
52
52
  "@xchainjs/xchain-avax": "^0.1.0",
53
53
  "@xchainjs/xchain-litecoin": "^0.10.5",
54
- "@xchainjs/xchain-midgard": "0.2.0",
54
+ "@xchainjs/xchain-midgard": "0.3.0",
55
55
  "@xchainjs/xchain-thorchain": "^0.27.2",
56
- "@xchainjs/xchain-thorchain-query": "^0.1.6",
57
- "@xchainjs/xchain-thornode": "^0.1.1",
56
+ "@xchainjs/xchain-thorchain-query": "^0.1.8",
57
+ "@xchainjs/xchain-thornode": "^0.1.2",
58
58
  "@xchainjs/xchain-util": "^0.11.0",
59
59
  "axios": "^0.25.0",
60
60
  "axios-retry": "^3.2.5",