@xchainjs/xchain-thorchain-amm 0.3.7 → 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 +130 -0
- package/lib/index.js +130 -0
- package/lib/thorchain-amm.d.ts +15 -1
- package/lib/wallet.d.ts +18 -2
- package/package.json +4 -4
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
|
|
@@ -1093,6 +1197,32 @@ class ThorchainAMM {
|
|
|
1093
1197
|
});
|
|
1094
1198
|
});
|
|
1095
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
|
+
}
|
|
1096
1226
|
}
|
|
1097
1227
|
|
|
1098
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
|
|
@@ -1097,6 +1201,32 @@ class ThorchainAMM {
|
|
|
1097
1201
|
});
|
|
1098
1202
|
});
|
|
1099
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
|
+
}
|
|
1100
1230
|
}
|
|
1101
1231
|
|
|
1102
1232
|
exports.ThorchainAMM = ThorchainAMM;
|
package/lib/thorchain-amm.d.ts
CHANGED
|
@@ -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.
|
|
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.
|
|
54
|
+
"@xchainjs/xchain-midgard": "0.3.0",
|
|
55
55
|
"@xchainjs/xchain-thorchain": "^0.27.2",
|
|
56
|
-
"@xchainjs/xchain-thorchain-query": "^0.1.
|
|
57
|
-
"@xchainjs/xchain-thornode": "^0.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",
|