@defisaver/automation-sdk 3.1.3 → 3.1.4-dev-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/cjs/automation/private/StrategiesAutomation.d.ts +2 -2
- package/cjs/automation/public/Strategies.test.d.ts +1 -0
- package/cjs/automation/public/Strategies.test.js +61 -0
- package/cjs/constants/index.js +35 -15
- package/cjs/services/strategiesService.js +68 -3
- package/cjs/services/strategySubService.d.ts +6 -2
- package/cjs/services/strategySubService.js +25 -3
- package/cjs/services/strategySubService.test.js +2 -2
- package/cjs/services/subDataService.d.ts +21 -2
- package/cjs/services/subDataService.js +56 -2
- package/cjs/services/subDataService.test.js +3 -3
- package/cjs/services/triggerService.d.ts +17 -0
- package/cjs/services/triggerService.js +33 -1
- package/cjs/services/utils.d.ts +6 -1
- package/cjs/services/utils.js +52 -1
- package/cjs/types/enums.d.ts +40 -11
- package/cjs/types/enums.js +37 -4
- package/cjs/types/index.d.ts +12 -3
- package/esm/automation/private/StrategiesAutomation.d.ts +2 -2
- package/esm/automation/public/Strategies.test.d.ts +1 -0
- package/esm/automation/public/Strategies.test.js +56 -0
- package/esm/constants/index.js +35 -15
- package/esm/services/strategiesService.js +69 -4
- package/esm/services/strategySubService.d.ts +6 -2
- package/esm/services/strategySubService.js +26 -4
- package/esm/services/strategySubService.test.js +2 -2
- package/esm/services/subDataService.d.ts +21 -2
- package/esm/services/subDataService.js +56 -2
- package/esm/services/subDataService.test.js +4 -4
- package/esm/services/triggerService.d.ts +17 -0
- package/esm/services/triggerService.js +32 -0
- package/esm/services/utils.d.ts +6 -1
- package/esm/services/utils.js +50 -1
- package/esm/types/enums.d.ts +40 -11
- package/esm/types/enums.js +36 -3
- package/esm/types/index.d.ts +12 -3
- package/package.json +1 -1
- package/src/automation/private/StrategiesAutomation.ts +2 -2
- package/src/automation/public/Strategies.test.ts +49 -0
- package/src/constants/index.ts +47 -16
- package/src/services/strategiesService.ts +89 -4
- package/src/services/strategySubService.test.ts +2 -2
- package/src/services/strategySubService.ts +52 -3
- package/src/services/subDataService.test.ts +4 -4
- package/src/services/subDataService.ts +85 -4
- package/src/services/triggerService.ts +53 -0
- package/src/services/utils.ts +60 -1
- package/src/types/enums.ts +36 -3
- package/src/types/index.ts +14 -2
package/cjs/services/utils.js
CHANGED
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.getPositionId = exports.getRatioStateInfoForAaveCloseStrategy = exports.requireAddresses = exports.requireAddress = exports.isEmptyBytes = exports.isRatioStateUnder = exports.isRatioStateOver = exports.weiToRatioPercentage = exports.ratioPercentageToWei = exports.encodeSubId = exports.compareSubHashes = exports.wethToEthByAddress = exports.wethToEth = exports.ethToWeth = exports.addToObjectIf = exports.addToArrayIf = exports.isAddress = exports.compareAddresses = exports.isUndefined = exports.isDefined = void 0;
|
|
29
|
+
exports.getStopLossAndTakeProfitTypeByCloseStrategyType = exports.getCloseStrategyType = exports.getPositionId = exports.getRatioStateInfoForAaveCloseStrategy = exports.requireAddresses = exports.requireAddress = exports.isEmptyBytes = exports.isRatioStateUnder = exports.isRatioStateOver = exports.weiToRatioPercentage = exports.ratioPercentageToWei = exports.encodeSubId = exports.compareSubHashes = exports.wethToEthByAddress = exports.wethToEth = exports.ethToWeth = exports.addToObjectIf = exports.addToArrayIf = exports.isAddress = exports.compareAddresses = exports.isUndefined = exports.isDefined = void 0;
|
|
30
30
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
31
31
|
const web3Utils = __importStar(require("web3-utils"));
|
|
32
32
|
const web3_eth_abi_1 = __importDefault(require("web3-eth-abi"));
|
|
@@ -129,3 +129,54 @@ function getPositionId(...args) {
|
|
|
129
129
|
return args.map(arg => arg.toString().toLowerCase().split(' ').join('_')).join('-');
|
|
130
130
|
}
|
|
131
131
|
exports.getPositionId = getPositionId;
|
|
132
|
+
function getCloseStrategyType(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType) {
|
|
133
|
+
const isStopLoss = stopLossPrice > 0;
|
|
134
|
+
const isTakeProfit = takeProfitPrice > 0;
|
|
135
|
+
if (!isStopLoss && !isTakeProfit) {
|
|
136
|
+
throw new Error('CloseOnPrice: At least one price must be defined');
|
|
137
|
+
}
|
|
138
|
+
if (isStopLoss && isTakeProfit) {
|
|
139
|
+
if (stopLossType === enums_1.CloseToAssetType.COLLATERAL && takeProfitType === enums_1.CloseToAssetType.COLLATERAL) {
|
|
140
|
+
return enums_1.CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_COLLATERAL;
|
|
141
|
+
}
|
|
142
|
+
if (stopLossType === enums_1.CloseToAssetType.COLLATERAL) {
|
|
143
|
+
return enums_1.CloseStrategyType.TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL;
|
|
144
|
+
}
|
|
145
|
+
if (takeProfitType === enums_1.CloseToAssetType.COLLATERAL) {
|
|
146
|
+
return enums_1.CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT;
|
|
147
|
+
}
|
|
148
|
+
return enums_1.CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT;
|
|
149
|
+
}
|
|
150
|
+
if (isStopLoss) {
|
|
151
|
+
return stopLossType === enums_1.CloseToAssetType.COLLATERAL
|
|
152
|
+
? enums_1.CloseStrategyType.STOP_LOSS_IN_COLLATERAL
|
|
153
|
+
: enums_1.CloseStrategyType.STOP_LOSS_IN_DEBT;
|
|
154
|
+
}
|
|
155
|
+
return takeProfitType === enums_1.CloseToAssetType.COLLATERAL
|
|
156
|
+
? enums_1.CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL
|
|
157
|
+
: enums_1.CloseStrategyType.TAKE_PROFIT_IN_DEBT;
|
|
158
|
+
}
|
|
159
|
+
exports.getCloseStrategyType = getCloseStrategyType;
|
|
160
|
+
function getStopLossAndTakeProfitTypeByCloseStrategyType(closeStrategyType) {
|
|
161
|
+
switch (closeStrategyType) {
|
|
162
|
+
case enums_1.CloseStrategyType.STOP_LOSS_IN_COLLATERAL:
|
|
163
|
+
return { stopLossType: enums_1.CloseToAssetType.COLLATERAL, takeProfitType: undefined };
|
|
164
|
+
case enums_1.CloseStrategyType.STOP_LOSS_IN_DEBT:
|
|
165
|
+
return { stopLossType: enums_1.CloseToAssetType.DEBT, takeProfitType: undefined };
|
|
166
|
+
case enums_1.CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL:
|
|
167
|
+
return { stopLossType: undefined, takeProfitType: enums_1.CloseToAssetType.COLLATERAL };
|
|
168
|
+
case enums_1.CloseStrategyType.TAKE_PROFIT_IN_DEBT:
|
|
169
|
+
return { stopLossType: undefined, takeProfitType: enums_1.CloseToAssetType.DEBT };
|
|
170
|
+
case enums_1.CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT:
|
|
171
|
+
return { stopLossType: enums_1.CloseToAssetType.DEBT, takeProfitType: enums_1.CloseToAssetType.COLLATERAL };
|
|
172
|
+
case enums_1.CloseStrategyType.TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL:
|
|
173
|
+
return { stopLossType: enums_1.CloseToAssetType.COLLATERAL, takeProfitType: enums_1.CloseToAssetType.DEBT };
|
|
174
|
+
case enums_1.CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT:
|
|
175
|
+
return { stopLossType: enums_1.CloseToAssetType.DEBT, takeProfitType: enums_1.CloseToAssetType.DEBT };
|
|
176
|
+
case enums_1.CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_COLLATERAL:
|
|
177
|
+
return { stopLossType: enums_1.CloseToAssetType.COLLATERAL, takeProfitType: enums_1.CloseToAssetType.COLLATERAL };
|
|
178
|
+
default:
|
|
179
|
+
throw new Error('CloseStrategyType not supported');
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
exports.getStopLossAndTakeProfitTypeByCloseStrategyType = getStopLossAndTakeProfitTypeByCloseStrategyType;
|
package/cjs/types/enums.d.ts
CHANGED
|
@@ -17,6 +17,28 @@ export declare enum BundleProtocols {
|
|
|
17
17
|
Yearn = "yearn",
|
|
18
18
|
Rari = "rari"
|
|
19
19
|
}
|
|
20
|
+
export declare enum CollActionType {
|
|
21
|
+
SUPPLY = 0,
|
|
22
|
+
WITHDRAW = 1
|
|
23
|
+
}
|
|
24
|
+
export declare enum DebtActionType {
|
|
25
|
+
PAYBACK = 0,
|
|
26
|
+
BORROW = 1
|
|
27
|
+
}
|
|
28
|
+
export declare enum CloseStrategyType {
|
|
29
|
+
TAKE_PROFIT_IN_COLLATERAL = 0,
|
|
30
|
+
STOP_LOSS_IN_COLLATERAL = 1,
|
|
31
|
+
TAKE_PROFIT_IN_DEBT = 2,
|
|
32
|
+
STOP_LOSS_IN_DEBT = 3,
|
|
33
|
+
TAKE_PROFIT_AND_STOP_LOSS_IN_COLLATERAL = 4,
|
|
34
|
+
TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT = 5,
|
|
35
|
+
TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT = 6,
|
|
36
|
+
TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL = 7
|
|
37
|
+
}
|
|
38
|
+
export declare enum CloseToAssetType {
|
|
39
|
+
COLLATERAL = 0,
|
|
40
|
+
DEBT = 1
|
|
41
|
+
}
|
|
20
42
|
/**
|
|
21
43
|
* @dev Follow the naming convention:
|
|
22
44
|
* - Enum name consists of two parts, name and version
|
|
@@ -28,6 +50,7 @@ export declare namespace ProtocolIdentifiers {
|
|
|
28
50
|
enum StrategiesAutomation {
|
|
29
51
|
MakerDAO = "MakerDAO",
|
|
30
52
|
Liquity = "Liquity",
|
|
53
|
+
LiquityV2 = "Liquity__V2",
|
|
31
54
|
ChickenBonds = "Chicken Bonds",
|
|
32
55
|
CompoundV2 = "Compound__V2",
|
|
33
56
|
CompoundV3 = "Compound__V3",
|
|
@@ -60,13 +83,11 @@ export declare namespace Strategies {
|
|
|
60
83
|
LIQUITY_DSR_PAYBACK = 69,
|
|
61
84
|
LIQUITY_DSR_SUPPLY = 70,
|
|
62
85
|
LIQUITY_DEBT_IN_FRONT_REPAY = 75,
|
|
63
|
-
CURVEUSD_PAYBACK = 92
|
|
64
|
-
AAVE_V3_OPEN_ORDER_FROM_DEBT = 96
|
|
86
|
+
CURVEUSD_PAYBACK = 92
|
|
65
87
|
}
|
|
66
88
|
enum OptimismIds {
|
|
67
89
|
EXCHANGE_DCA = 8,
|
|
68
|
-
EXCHANGE_LIMIT_ORDER = 9
|
|
69
|
-
AAVE_V3_OPEN_ORDER_FROM_DEBT = 12
|
|
90
|
+
EXCHANGE_LIMIT_ORDER = 9
|
|
70
91
|
}
|
|
71
92
|
enum BaseIds {
|
|
72
93
|
EXCHANGE_DCA = 8,
|
|
@@ -74,8 +95,7 @@ export declare namespace Strategies {
|
|
|
74
95
|
}
|
|
75
96
|
enum ArbitrumIds {
|
|
76
97
|
EXCHANGE_DCA = 8,
|
|
77
|
-
EXCHANGE_LIMIT_ORDER = 9
|
|
78
|
-
AAVE_V3_OPEN_ORDER_FROM_DEBT = 16
|
|
98
|
+
EXCHANGE_LIMIT_ORDER = 9
|
|
79
99
|
}
|
|
80
100
|
enum Identifiers {
|
|
81
101
|
SavingsLiqProtection = "smart-savings-liquidation-protection",
|
|
@@ -91,6 +111,7 @@ export declare namespace Strategies {
|
|
|
91
111
|
CloseToCollateralWithGasPrice = "close-to-collateral-with-gas-price",
|
|
92
112
|
CloseOnPriceToDebt = "close-on-price-to-debt",
|
|
93
113
|
CloseOnPriceToColl = "close-on-price-to-collateral",
|
|
114
|
+
CloseOnPrice = "close-on-price",
|
|
94
115
|
TrailingStopToColl = "trailing-stop-to-collateral",
|
|
95
116
|
TrailingStopToDebt = "trailing-stop-to-debt",
|
|
96
117
|
Rebond = "rebond",
|
|
@@ -100,7 +121,8 @@ export declare namespace Strategies {
|
|
|
100
121
|
LimitOrder = "limit-order",
|
|
101
122
|
DebtInFrontRepay = "debt-in-front-repay",
|
|
102
123
|
OpenOrderFromCollateral = "open-order-from-collateral",
|
|
103
|
-
OpenOrderFromDebt = "open-order-from-debt"
|
|
124
|
+
OpenOrderFromDebt = "open-order-from-debt",
|
|
125
|
+
RepayOnPrice = "repay-on-price"
|
|
104
126
|
}
|
|
105
127
|
enum IdOverrides {
|
|
106
128
|
TakeProfit = "take-profit",
|
|
@@ -152,14 +174,19 @@ export declare namespace Bundles {
|
|
|
152
174
|
MORPHO_BLUE_BOOST = 33,
|
|
153
175
|
MORPHO_BLUE_EOA_REPAY = 34,
|
|
154
176
|
MORPHO_BLUE_EOA_BOOST = 35,
|
|
155
|
-
AAVE_V3_OPEN_ORDER_FROM_COLLATERAL = 36
|
|
177
|
+
AAVE_V3_OPEN_ORDER_FROM_COLLATERAL = 36,
|
|
178
|
+
AAVE_V3_REPAY_ON_PRICE = 37,
|
|
179
|
+
LIQUITY_V2_REPAY = 38,
|
|
180
|
+
LIQUITY_V2_BOOST = 39,
|
|
181
|
+
LIQUITY_V2_CLOSE = 40
|
|
156
182
|
}
|
|
157
183
|
enum OptimismIds {
|
|
158
184
|
AAVE_V3_REPAY = 0,
|
|
159
185
|
AAVE_V3_BOOST = 1,
|
|
160
186
|
AAVE_V3_CLOSE_TO_DEBT = 2,
|
|
161
187
|
AAVE_V3_CLOSE_TO_COLLATERAL = 3,
|
|
162
|
-
AAVE_V3_OPEN_ORDER_FROM_COLLATERAL = 4
|
|
188
|
+
AAVE_V3_OPEN_ORDER_FROM_COLLATERAL = 4,
|
|
189
|
+
AAVE_V3_REPAY_ON_PRICE = 5
|
|
163
190
|
}
|
|
164
191
|
enum BaseIds {
|
|
165
192
|
AAVE_V3_REPAY = 0,
|
|
@@ -170,7 +197,8 @@ export declare namespace Bundles {
|
|
|
170
197
|
COMP_V3_SW_BOOST_BUNDLE = 5,
|
|
171
198
|
MORPHO_BLUE_REPAY = 8,
|
|
172
199
|
MORPHO_BLUE_BOOST = 9,
|
|
173
|
-
AAVE_V3_OPEN_ORDER_FROM_COLLATERAL = 10
|
|
200
|
+
AAVE_V3_OPEN_ORDER_FROM_COLLATERAL = 10,
|
|
201
|
+
AAVE_V3_REPAY_ON_PRICE = 11
|
|
174
202
|
}
|
|
175
203
|
enum ArbitrumIds {
|
|
176
204
|
AAVE_V3_REPAY = 0,
|
|
@@ -179,6 +207,7 @@ export declare namespace Bundles {
|
|
|
179
207
|
AAVE_V3_CLOSE_TO_COLLATERAL = 3,
|
|
180
208
|
COMP_V3_SW_REPAY_BUNDLE = 4,
|
|
181
209
|
COMP_V3_SW_BOOST_BUNDLE = 5,
|
|
182
|
-
AAVE_V3_OPEN_ORDER_FROM_COLLATERAL = 6
|
|
210
|
+
AAVE_V3_OPEN_ORDER_FROM_COLLATERAL = 6,
|
|
211
|
+
AAVE_V3_REPAY_ON_PRICE = 7
|
|
183
212
|
}
|
|
184
213
|
}
|
package/cjs/types/enums.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Bundles = exports.Strategies = exports.ProtocolIdentifiers = exports.BundleProtocols = exports.OrderType = exports.RatioState = exports.ChainId = void 0;
|
|
3
|
+
exports.Bundles = exports.Strategies = exports.ProtocolIdentifiers = exports.CloseToAssetType = exports.CloseStrategyType = exports.DebtActionType = exports.CollActionType = exports.BundleProtocols = exports.OrderType = exports.RatioState = exports.ChainId = void 0;
|
|
4
4
|
var ChainId;
|
|
5
5
|
(function (ChainId) {
|
|
6
6
|
ChainId[ChainId["Ethereum"] = 1] = "Ethereum";
|
|
@@ -24,6 +24,32 @@ var BundleProtocols;
|
|
|
24
24
|
BundleProtocols["Yearn"] = "yearn";
|
|
25
25
|
BundleProtocols["Rari"] = "rari";
|
|
26
26
|
})(BundleProtocols = exports.BundleProtocols || (exports.BundleProtocols = {}));
|
|
27
|
+
var CollActionType;
|
|
28
|
+
(function (CollActionType) {
|
|
29
|
+
CollActionType[CollActionType["SUPPLY"] = 0] = "SUPPLY";
|
|
30
|
+
CollActionType[CollActionType["WITHDRAW"] = 1] = "WITHDRAW";
|
|
31
|
+
})(CollActionType = exports.CollActionType || (exports.CollActionType = {}));
|
|
32
|
+
var DebtActionType;
|
|
33
|
+
(function (DebtActionType) {
|
|
34
|
+
DebtActionType[DebtActionType["PAYBACK"] = 0] = "PAYBACK";
|
|
35
|
+
DebtActionType[DebtActionType["BORROW"] = 1] = "BORROW";
|
|
36
|
+
})(DebtActionType = exports.DebtActionType || (exports.DebtActionType = {}));
|
|
37
|
+
var CloseStrategyType;
|
|
38
|
+
(function (CloseStrategyType) {
|
|
39
|
+
CloseStrategyType[CloseStrategyType["TAKE_PROFIT_IN_COLLATERAL"] = 0] = "TAKE_PROFIT_IN_COLLATERAL";
|
|
40
|
+
CloseStrategyType[CloseStrategyType["STOP_LOSS_IN_COLLATERAL"] = 1] = "STOP_LOSS_IN_COLLATERAL";
|
|
41
|
+
CloseStrategyType[CloseStrategyType["TAKE_PROFIT_IN_DEBT"] = 2] = "TAKE_PROFIT_IN_DEBT";
|
|
42
|
+
CloseStrategyType[CloseStrategyType["STOP_LOSS_IN_DEBT"] = 3] = "STOP_LOSS_IN_DEBT";
|
|
43
|
+
CloseStrategyType[CloseStrategyType["TAKE_PROFIT_AND_STOP_LOSS_IN_COLLATERAL"] = 4] = "TAKE_PROFIT_AND_STOP_LOSS_IN_COLLATERAL";
|
|
44
|
+
CloseStrategyType[CloseStrategyType["TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT"] = 5] = "TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT";
|
|
45
|
+
CloseStrategyType[CloseStrategyType["TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT"] = 6] = "TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT";
|
|
46
|
+
CloseStrategyType[CloseStrategyType["TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL"] = 7] = "TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL";
|
|
47
|
+
})(CloseStrategyType = exports.CloseStrategyType || (exports.CloseStrategyType = {}));
|
|
48
|
+
var CloseToAssetType;
|
|
49
|
+
(function (CloseToAssetType) {
|
|
50
|
+
CloseToAssetType[CloseToAssetType["COLLATERAL"] = 0] = "COLLATERAL";
|
|
51
|
+
CloseToAssetType[CloseToAssetType["DEBT"] = 1] = "DEBT";
|
|
52
|
+
})(CloseToAssetType = exports.CloseToAssetType || (exports.CloseToAssetType = {}));
|
|
27
53
|
/**
|
|
28
54
|
* @dev Follow the naming convention:
|
|
29
55
|
* - Enum name consists of two parts, name and version
|
|
@@ -37,6 +63,7 @@ var ProtocolIdentifiers;
|
|
|
37
63
|
(function (StrategiesAutomation) {
|
|
38
64
|
StrategiesAutomation["MakerDAO"] = "MakerDAO";
|
|
39
65
|
StrategiesAutomation["Liquity"] = "Liquity";
|
|
66
|
+
StrategiesAutomation["LiquityV2"] = "Liquity__V2";
|
|
40
67
|
StrategiesAutomation["ChickenBonds"] = "Chicken Bonds";
|
|
41
68
|
StrategiesAutomation["CompoundV2"] = "Compound__V2";
|
|
42
69
|
StrategiesAutomation["CompoundV3"] = "Compound__V3";
|
|
@@ -73,13 +100,11 @@ var Strategies;
|
|
|
73
100
|
MainnetIds[MainnetIds["LIQUITY_DSR_SUPPLY"] = 70] = "LIQUITY_DSR_SUPPLY";
|
|
74
101
|
MainnetIds[MainnetIds["LIQUITY_DEBT_IN_FRONT_REPAY"] = 75] = "LIQUITY_DEBT_IN_FRONT_REPAY";
|
|
75
102
|
MainnetIds[MainnetIds["CURVEUSD_PAYBACK"] = 92] = "CURVEUSD_PAYBACK";
|
|
76
|
-
MainnetIds[MainnetIds["AAVE_V3_OPEN_ORDER_FROM_DEBT"] = 96] = "AAVE_V3_OPEN_ORDER_FROM_DEBT";
|
|
77
103
|
})(MainnetIds = Strategies.MainnetIds || (Strategies.MainnetIds = {}));
|
|
78
104
|
let OptimismIds;
|
|
79
105
|
(function (OptimismIds) {
|
|
80
106
|
OptimismIds[OptimismIds["EXCHANGE_DCA"] = 8] = "EXCHANGE_DCA";
|
|
81
107
|
OptimismIds[OptimismIds["EXCHANGE_LIMIT_ORDER"] = 9] = "EXCHANGE_LIMIT_ORDER";
|
|
82
|
-
OptimismIds[OptimismIds["AAVE_V3_OPEN_ORDER_FROM_DEBT"] = 12] = "AAVE_V3_OPEN_ORDER_FROM_DEBT";
|
|
83
108
|
})(OptimismIds = Strategies.OptimismIds || (Strategies.OptimismIds = {}));
|
|
84
109
|
let BaseIds;
|
|
85
110
|
(function (BaseIds) {
|
|
@@ -90,7 +115,6 @@ var Strategies;
|
|
|
90
115
|
(function (ArbitrumIds) {
|
|
91
116
|
ArbitrumIds[ArbitrumIds["EXCHANGE_DCA"] = 8] = "EXCHANGE_DCA";
|
|
92
117
|
ArbitrumIds[ArbitrumIds["EXCHANGE_LIMIT_ORDER"] = 9] = "EXCHANGE_LIMIT_ORDER";
|
|
93
|
-
ArbitrumIds[ArbitrumIds["AAVE_V3_OPEN_ORDER_FROM_DEBT"] = 16] = "AAVE_V3_OPEN_ORDER_FROM_DEBT";
|
|
94
118
|
})(ArbitrumIds = Strategies.ArbitrumIds || (Strategies.ArbitrumIds = {}));
|
|
95
119
|
let Identifiers;
|
|
96
120
|
(function (Identifiers) {
|
|
@@ -107,6 +131,7 @@ var Strategies;
|
|
|
107
131
|
Identifiers["CloseToCollateralWithGasPrice"] = "close-to-collateral-with-gas-price";
|
|
108
132
|
Identifiers["CloseOnPriceToDebt"] = "close-on-price-to-debt";
|
|
109
133
|
Identifiers["CloseOnPriceToColl"] = "close-on-price-to-collateral";
|
|
134
|
+
Identifiers["CloseOnPrice"] = "close-on-price";
|
|
110
135
|
Identifiers["TrailingStopToColl"] = "trailing-stop-to-collateral";
|
|
111
136
|
Identifiers["TrailingStopToDebt"] = "trailing-stop-to-debt";
|
|
112
137
|
Identifiers["Rebond"] = "rebond";
|
|
@@ -117,6 +142,7 @@ var Strategies;
|
|
|
117
142
|
Identifiers["DebtInFrontRepay"] = "debt-in-front-repay";
|
|
118
143
|
Identifiers["OpenOrderFromCollateral"] = "open-order-from-collateral";
|
|
119
144
|
Identifiers["OpenOrderFromDebt"] = "open-order-from-debt";
|
|
145
|
+
Identifiers["RepayOnPrice"] = "repay-on-price";
|
|
120
146
|
})(Identifiers = Strategies.Identifiers || (Strategies.Identifiers = {}));
|
|
121
147
|
let IdOverrides;
|
|
122
148
|
(function (IdOverrides) {
|
|
@@ -172,6 +198,10 @@ var Bundles;
|
|
|
172
198
|
MainnetIds[MainnetIds["MORPHO_BLUE_EOA_REPAY"] = 34] = "MORPHO_BLUE_EOA_REPAY";
|
|
173
199
|
MainnetIds[MainnetIds["MORPHO_BLUE_EOA_BOOST"] = 35] = "MORPHO_BLUE_EOA_BOOST";
|
|
174
200
|
MainnetIds[MainnetIds["AAVE_V3_OPEN_ORDER_FROM_COLLATERAL"] = 36] = "AAVE_V3_OPEN_ORDER_FROM_COLLATERAL";
|
|
201
|
+
MainnetIds[MainnetIds["AAVE_V3_REPAY_ON_PRICE"] = 37] = "AAVE_V3_REPAY_ON_PRICE";
|
|
202
|
+
MainnetIds[MainnetIds["LIQUITY_V2_REPAY"] = 38] = "LIQUITY_V2_REPAY";
|
|
203
|
+
MainnetIds[MainnetIds["LIQUITY_V2_BOOST"] = 39] = "LIQUITY_V2_BOOST";
|
|
204
|
+
MainnetIds[MainnetIds["LIQUITY_V2_CLOSE"] = 40] = "LIQUITY_V2_CLOSE";
|
|
175
205
|
})(MainnetIds = Bundles.MainnetIds || (Bundles.MainnetIds = {}));
|
|
176
206
|
let OptimismIds;
|
|
177
207
|
(function (OptimismIds) {
|
|
@@ -180,6 +210,7 @@ var Bundles;
|
|
|
180
210
|
OptimismIds[OptimismIds["AAVE_V3_CLOSE_TO_DEBT"] = 2] = "AAVE_V3_CLOSE_TO_DEBT";
|
|
181
211
|
OptimismIds[OptimismIds["AAVE_V3_CLOSE_TO_COLLATERAL"] = 3] = "AAVE_V3_CLOSE_TO_COLLATERAL";
|
|
182
212
|
OptimismIds[OptimismIds["AAVE_V3_OPEN_ORDER_FROM_COLLATERAL"] = 4] = "AAVE_V3_OPEN_ORDER_FROM_COLLATERAL";
|
|
213
|
+
OptimismIds[OptimismIds["AAVE_V3_REPAY_ON_PRICE"] = 5] = "AAVE_V3_REPAY_ON_PRICE";
|
|
183
214
|
})(OptimismIds = Bundles.OptimismIds || (Bundles.OptimismIds = {}));
|
|
184
215
|
let BaseIds;
|
|
185
216
|
(function (BaseIds) {
|
|
@@ -192,6 +223,7 @@ var Bundles;
|
|
|
192
223
|
BaseIds[BaseIds["MORPHO_BLUE_REPAY"] = 8] = "MORPHO_BLUE_REPAY";
|
|
193
224
|
BaseIds[BaseIds["MORPHO_BLUE_BOOST"] = 9] = "MORPHO_BLUE_BOOST";
|
|
194
225
|
BaseIds[BaseIds["AAVE_V3_OPEN_ORDER_FROM_COLLATERAL"] = 10] = "AAVE_V3_OPEN_ORDER_FROM_COLLATERAL";
|
|
226
|
+
BaseIds[BaseIds["AAVE_V3_REPAY_ON_PRICE"] = 11] = "AAVE_V3_REPAY_ON_PRICE";
|
|
195
227
|
})(BaseIds = Bundles.BaseIds || (Bundles.BaseIds = {}));
|
|
196
228
|
let ArbitrumIds;
|
|
197
229
|
(function (ArbitrumIds) {
|
|
@@ -202,5 +234,6 @@ var Bundles;
|
|
|
202
234
|
ArbitrumIds[ArbitrumIds["COMP_V3_SW_REPAY_BUNDLE"] = 4] = "COMP_V3_SW_REPAY_BUNDLE";
|
|
203
235
|
ArbitrumIds[ArbitrumIds["COMP_V3_SW_BOOST_BUNDLE"] = 5] = "COMP_V3_SW_BOOST_BUNDLE";
|
|
204
236
|
ArbitrumIds[ArbitrumIds["AAVE_V3_OPEN_ORDER_FROM_COLLATERAL"] = 6] = "AAVE_V3_OPEN_ORDER_FROM_COLLATERAL";
|
|
237
|
+
ArbitrumIds[ArbitrumIds["AAVE_V3_REPAY_ON_PRICE"] = 7] = "AAVE_V3_REPAY_ON_PRICE";
|
|
205
238
|
})(ArbitrumIds = Bundles.ArbitrumIds || (Bundles.ArbitrumIds = {}));
|
|
206
239
|
})(Bundles = exports.Bundles || (exports.Bundles = {}));
|
package/cjs/types/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type Web3 from 'web3';
|
|
|
2
2
|
import type { AbiItem } from 'web3-utils';
|
|
3
3
|
import type { BaseContract, BlockType } from './contracts/generated/types';
|
|
4
4
|
import type { Subscribe, StrategyModel } from './contracts/generated/SubStorage';
|
|
5
|
-
import type { ChainId, Strategies, Bundles, ProtocolIdentifiers, RatioState } from './enums';
|
|
5
|
+
import type { ChainId, Strategies, Bundles, ProtocolIdentifiers, RatioState, CloseToAssetType } from './enums';
|
|
6
6
|
export type PlaceholderType = any;
|
|
7
7
|
export type EthereumAddress = string;
|
|
8
8
|
export type BlockNumber = BlockType;
|
|
@@ -69,7 +69,7 @@ export declare namespace Interfaces {
|
|
|
69
69
|
}
|
|
70
70
|
interface Automation {
|
|
71
71
|
provider: Web3;
|
|
72
|
-
providerFork
|
|
72
|
+
providerFork?: Web3;
|
|
73
73
|
}
|
|
74
74
|
interface LegacyAutomation<T extends BaseContract> {
|
|
75
75
|
provider: Web3;
|
|
@@ -134,6 +134,15 @@ export declare namespace Position {
|
|
|
134
134
|
maximumGasPrice: string;
|
|
135
135
|
ratioState: RatioState;
|
|
136
136
|
}
|
|
137
|
+
interface CloseOnPriceLiquityV2 extends Base {
|
|
138
|
+
market: EthereumAddress;
|
|
139
|
+
troveId: string;
|
|
140
|
+
stopLossPrice: string;
|
|
141
|
+
takeProfitPrice: string;
|
|
142
|
+
closeToAssetAddr: EthereumAddress;
|
|
143
|
+
stopLossType: CloseToAssetType | undefined;
|
|
144
|
+
takeProfitType: CloseToAssetType | undefined;
|
|
145
|
+
}
|
|
137
146
|
interface TrailingStop extends Base {
|
|
138
147
|
roundId: number;
|
|
139
148
|
triggerPercentage: number;
|
|
@@ -148,7 +157,7 @@ export declare namespace Position {
|
|
|
148
157
|
subHashRepay?: string;
|
|
149
158
|
}
|
|
150
159
|
}
|
|
151
|
-
type SpecificAny = Specific.CloseOnPrice | Specific.TrailingStop | Specific.RatioProtection | Specific.CloseOnPriceAave | Specific.BoostOnPriceAave | Specific.CloseOnPriceWithMaximumGasPriceAave | Specific.DebtInFrontRepay | Specific.LeverageManagementCrvUSD;
|
|
160
|
+
type SpecificAny = Specific.CloseOnPrice | Specific.TrailingStop | Specific.RatioProtection | Specific.CloseOnPriceAave | Specific.BoostOnPriceAave | Specific.CloseOnPriceWithMaximumGasPriceAave | Specific.DebtInFrontRepay | Specific.LeverageManagementCrvUSD | Specific.CloseOnPriceLiquityV2;
|
|
152
161
|
interface Automated {
|
|
153
162
|
chainId: ChainId;
|
|
154
163
|
positionId: string;
|
|
@@ -6,12 +6,12 @@ import type { ChainId } from '../../types/enums';
|
|
|
6
6
|
import Automation from './Automation';
|
|
7
7
|
interface IStrategiesAutomation extends Interfaces.Automation {
|
|
8
8
|
chainId: ChainId;
|
|
9
|
-
providerFork
|
|
9
|
+
providerFork?: Web3;
|
|
10
10
|
}
|
|
11
11
|
export default class StrategiesAutomation extends Automation {
|
|
12
12
|
protected chainId: ChainId;
|
|
13
13
|
protected web3: Web3;
|
|
14
|
-
protected web3Fork
|
|
14
|
+
protected web3Fork?: Web3;
|
|
15
15
|
protected subStorageContract: Contract.WithMeta<SubStorage>;
|
|
16
16
|
protected subStorageContractFork: Contract.WithMeta<SubStorage> | null;
|
|
17
17
|
constructor(args: IStrategiesAutomation);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '../../configuration';
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import Web3 from 'web3';
|
|
11
|
+
import '../../configuration';
|
|
12
|
+
import EthereumStrategies from './EthereumStrategies';
|
|
13
|
+
import ArbitrumStrategies from './ArbitrumStrategies';
|
|
14
|
+
import OptimismStrategies from './OptimismStrategies';
|
|
15
|
+
import BaseStrategies from './BaseStrategies';
|
|
16
|
+
require('dotenv').config({ path: '.env' });
|
|
17
|
+
const Web3_1 = new Web3(process.env.RPC_1);
|
|
18
|
+
const Web3_42161 = new Web3(process.env.RPC_42161);
|
|
19
|
+
const Web3_10 = new Web3(process.env.RPC_10);
|
|
20
|
+
const Web3_8453 = new Web3(process.env.RPC_8453);
|
|
21
|
+
describe('Feature: StrategiesAutomation.ts', () => {
|
|
22
|
+
describe('Fetching subscriptions', () => {
|
|
23
|
+
it('can fetch subscriptions on Mainnet', function () {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
this.timeout(120000);
|
|
26
|
+
const ethStrategies = new EthereumStrategies({ provider: Web3_1 });
|
|
27
|
+
const subs = yield ethStrategies.getSubscriptions({ mergeSubs: true });
|
|
28
|
+
console.log(subs.length);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
it('can fetch subscriptions on Arbitrum', function () {
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
this.timeout(120000);
|
|
34
|
+
const arbiStrategies = new ArbitrumStrategies({ provider: Web3_42161 });
|
|
35
|
+
const subs = yield arbiStrategies.getSubscriptions({ mergeSubs: true });
|
|
36
|
+
console.log(subs.length);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
it('can fetch subscriptions on Optimism', function () {
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
this.timeout(120000);
|
|
42
|
+
const optimismStrategies = new OptimismStrategies({ provider: Web3_10 });
|
|
43
|
+
const subs = yield optimismStrategies.getSubscriptions({ mergeSubs: true });
|
|
44
|
+
console.log(subs.length);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
it('can fetch subscriptions on Base', function () {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
this.timeout(120000);
|
|
50
|
+
const baseStrategies = new BaseStrategies({ provider: Web3_8453 });
|
|
51
|
+
const subs = yield baseStrategies.getSubscriptions({ mergeSubs: true });
|
|
52
|
+
console.log(subs.length);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
});
|
package/esm/constants/index.js
CHANGED
|
@@ -90,11 +90,6 @@ export const MAINNET_STRATEGIES_INFO = {
|
|
|
90
90
|
strategyId: Strategies.Identifiers.Payback,
|
|
91
91
|
protocol: PROTOCOLS.CrvUSD,
|
|
92
92
|
},
|
|
93
|
-
[Strategies.MainnetIds.AAVE_V3_OPEN_ORDER_FROM_DEBT]: {
|
|
94
|
-
strategyOrBundleId: Strategies.MainnetIds.AAVE_V3_OPEN_ORDER_FROM_DEBT,
|
|
95
|
-
strategyId: Strategies.Identifiers.OpenOrderFromDebt,
|
|
96
|
-
protocol: PROTOCOLS.AaveV3,
|
|
97
|
-
},
|
|
98
93
|
};
|
|
99
94
|
export const OPTIMISM_STRATEGIES_INFO = {
|
|
100
95
|
[Strategies.OptimismIds.EXCHANGE_DCA]: {
|
|
@@ -107,11 +102,6 @@ export const OPTIMISM_STRATEGIES_INFO = {
|
|
|
107
102
|
strategyId: Strategies.Identifiers.LimitOrder,
|
|
108
103
|
protocol: PROTOCOLS.Exchange,
|
|
109
104
|
},
|
|
110
|
-
[Strategies.OptimismIds.AAVE_V3_OPEN_ORDER_FROM_DEBT]: {
|
|
111
|
-
strategyOrBundleId: Strategies.OptimismIds.AAVE_V3_OPEN_ORDER_FROM_DEBT,
|
|
112
|
-
strategyId: Strategies.Identifiers.OpenOrderFromDebt,
|
|
113
|
-
protocol: PROTOCOLS.AaveV3,
|
|
114
|
-
},
|
|
115
105
|
};
|
|
116
106
|
export const BASE_STRATEGIES_INFO = {
|
|
117
107
|
[Strategies.BaseIds.EXCHANGE_DCA]: {
|
|
@@ -136,11 +126,6 @@ export const ARBITRUM_STRATEGIES_INFO = {
|
|
|
136
126
|
strategyId: Strategies.Identifiers.LimitOrder,
|
|
137
127
|
protocol: PROTOCOLS.Exchange,
|
|
138
128
|
},
|
|
139
|
-
[Strategies.ArbitrumIds.AAVE_V3_OPEN_ORDER_FROM_DEBT]: {
|
|
140
|
-
strategyOrBundleId: Strategies.ArbitrumIds.AAVE_V3_OPEN_ORDER_FROM_DEBT,
|
|
141
|
-
strategyId: Strategies.Identifiers.OpenOrderFromDebt,
|
|
142
|
-
protocol: PROTOCOLS.AaveV3,
|
|
143
|
-
},
|
|
144
129
|
};
|
|
145
130
|
export const STRATEGIES_INFO = {
|
|
146
131
|
[ChainId.Ethereum]: MAINNET_STRATEGIES_INFO,
|
|
@@ -357,6 +342,26 @@ export const MAINNET_BUNDLES_INFO = {
|
|
|
357
342
|
strategyId: Strategies.Identifiers.OpenOrderFromCollateral,
|
|
358
343
|
protocol: PROTOCOLS.AaveV3,
|
|
359
344
|
},
|
|
345
|
+
[Bundles.MainnetIds.AAVE_V3_REPAY_ON_PRICE]: {
|
|
346
|
+
strategyOrBundleId: Bundles.MainnetIds.AAVE_V3_REPAY_ON_PRICE,
|
|
347
|
+
strategyId: Strategies.Identifiers.RepayOnPrice,
|
|
348
|
+
protocol: PROTOCOLS.AaveV3,
|
|
349
|
+
},
|
|
350
|
+
[Bundles.MainnetIds.LIQUITY_V2_REPAY]: {
|
|
351
|
+
strategyOrBundleId: Bundles.MainnetIds.LIQUITY_V2_REPAY,
|
|
352
|
+
strategyId: Strategies.Identifiers.Repay,
|
|
353
|
+
protocol: PROTOCOLS.LiquityV2,
|
|
354
|
+
},
|
|
355
|
+
[Bundles.MainnetIds.LIQUITY_V2_BOOST]: {
|
|
356
|
+
strategyOrBundleId: Bundles.MainnetIds.LIQUITY_V2_BOOST,
|
|
357
|
+
strategyId: Strategies.Identifiers.Boost,
|
|
358
|
+
protocol: PROTOCOLS.LiquityV2,
|
|
359
|
+
},
|
|
360
|
+
[Bundles.MainnetIds.LIQUITY_V2_CLOSE]: {
|
|
361
|
+
strategyOrBundleId: Bundles.MainnetIds.LIQUITY_V2_CLOSE,
|
|
362
|
+
strategyId: Strategies.Identifiers.CloseOnPrice,
|
|
363
|
+
protocol: PROTOCOLS.LiquityV2,
|
|
364
|
+
},
|
|
360
365
|
};
|
|
361
366
|
export const OPTIMISM_BUNDLES_INFO = {
|
|
362
367
|
[Bundles.OptimismIds.AAVE_V3_REPAY]: {
|
|
@@ -384,6 +389,11 @@ export const OPTIMISM_BUNDLES_INFO = {
|
|
|
384
389
|
strategyId: Strategies.Identifiers.OpenOrderFromCollateral,
|
|
385
390
|
protocol: PROTOCOLS.AaveV3,
|
|
386
391
|
},
|
|
392
|
+
[Bundles.OptimismIds.AAVE_V3_REPAY_ON_PRICE]: {
|
|
393
|
+
strategyOrBundleId: Bundles.OptimismIds.AAVE_V3_REPAY_ON_PRICE,
|
|
394
|
+
strategyId: Strategies.Identifiers.RepayOnPrice,
|
|
395
|
+
protocol: PROTOCOLS.AaveV3,
|
|
396
|
+
},
|
|
387
397
|
};
|
|
388
398
|
export const BASE_BUNDLES_INFO = {
|
|
389
399
|
[Bundles.BaseIds.AAVE_V3_REPAY]: {
|
|
@@ -431,6 +441,11 @@ export const BASE_BUNDLES_INFO = {
|
|
|
431
441
|
strategyId: Strategies.Identifiers.OpenOrderFromCollateral,
|
|
432
442
|
protocol: PROTOCOLS.AaveV3,
|
|
433
443
|
},
|
|
444
|
+
[Bundles.BaseIds.AAVE_V3_REPAY_ON_PRICE]: {
|
|
445
|
+
strategyOrBundleId: Bundles.BaseIds.AAVE_V3_REPAY_ON_PRICE,
|
|
446
|
+
strategyId: Strategies.Identifiers.RepayOnPrice,
|
|
447
|
+
protocol: PROTOCOLS.AaveV3,
|
|
448
|
+
},
|
|
434
449
|
};
|
|
435
450
|
export const ARBITRUM_BUNDLES_INFO = {
|
|
436
451
|
[Bundles.ArbitrumIds.AAVE_V3_REPAY]: {
|
|
@@ -468,6 +483,11 @@ export const ARBITRUM_BUNDLES_INFO = {
|
|
|
468
483
|
strategyId: Strategies.Identifiers.OpenOrderFromCollateral,
|
|
469
484
|
protocol: PROTOCOLS.AaveV3,
|
|
470
485
|
},
|
|
486
|
+
[Bundles.ArbitrumIds.AAVE_V3_REPAY_ON_PRICE]: {
|
|
487
|
+
strategyOrBundleId: Bundles.ArbitrumIds.AAVE_V3_REPAY_ON_PRICE,
|
|
488
|
+
strategyId: Strategies.Identifiers.RepayOnPrice,
|
|
489
|
+
protocol: PROTOCOLS.AaveV3,
|
|
490
|
+
},
|
|
471
491
|
};
|
|
472
492
|
export const BUNDLES_INFO = {
|
|
473
493
|
[ChainId.Ethereum]: MAINNET_BUNDLES_INFO,
|
|
@@ -2,7 +2,7 @@ import { getAssetInfoByAddress } from '@defisaver/tokens';
|
|
|
2
2
|
import { cloneDeep } from 'lodash';
|
|
3
3
|
import { BUNDLES_INFO, STRATEGIES_INFO } from '../constants';
|
|
4
4
|
import { ChainId, ProtocolIdentifiers, Strategies } from '../types/enums';
|
|
5
|
-
import { getPositionId, getRatioStateInfoForAaveCloseStrategy, isRatioStateOver, wethToEthByAddress, } from './utils';
|
|
5
|
+
import { getPositionId, getRatioStateInfoForAaveCloseStrategy, getStopLossAndTakeProfitTypeByCloseStrategyType, isRatioStateOver, wethToEthByAddress, } from './utils';
|
|
6
6
|
import * as subDataService from './subDataService';
|
|
7
7
|
import * as triggerService from './triggerService';
|
|
8
8
|
const SPARK_MARKET_ADDRESSES = {
|
|
@@ -403,6 +403,39 @@ function parseLiquityLeverageManagement(position, parseData) {
|
|
|
403
403
|
_position.strategy.strategyId = Strategies.IdOverrides.LeverageManagement;
|
|
404
404
|
return _position;
|
|
405
405
|
}
|
|
406
|
+
function parseLiquityV2LeverageManagement(position, parseData) {
|
|
407
|
+
const _position = cloneDeep(position);
|
|
408
|
+
const { subStruct, subId, subHash } = parseData.subscriptionEventData;
|
|
409
|
+
const { isEnabled } = parseData.strategiesSubsData;
|
|
410
|
+
const triggerData = triggerService.liquityV2RatioTrigger.decode(subStruct.triggerData);
|
|
411
|
+
const subData = subDataService.liquityV2LeverageManagementSubData.decode(subStruct.subData);
|
|
412
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
413
|
+
_position.strategyData.decoded.subData = subData;
|
|
414
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, triggerData.troveId, triggerData.market);
|
|
415
|
+
const isRepay = _position.strategy.strategyId === Strategies.Identifiers.Repay;
|
|
416
|
+
if (isRepay) {
|
|
417
|
+
_position.specific = {
|
|
418
|
+
triggerRepayRatio: triggerData.ratio,
|
|
419
|
+
targetRepayRatio: subData.targetRatio,
|
|
420
|
+
repayEnabled: isEnabled,
|
|
421
|
+
subId1: Number(subId),
|
|
422
|
+
subHashRepay: subHash,
|
|
423
|
+
mergeWithId: Strategies.Identifiers.Boost,
|
|
424
|
+
};
|
|
425
|
+
}
|
|
426
|
+
else {
|
|
427
|
+
_position.specific = {
|
|
428
|
+
triggerBoostRatio: triggerData.ratio,
|
|
429
|
+
targetBoostRatio: subData.targetRatio,
|
|
430
|
+
boostEnabled: isEnabled,
|
|
431
|
+
subId2: Number(subId),
|
|
432
|
+
subHashBoost: subHash,
|
|
433
|
+
mergeId: Strategies.Identifiers.Boost,
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
_position.strategy.strategyId = Strategies.IdOverrides.LeverageManagement;
|
|
437
|
+
return _position;
|
|
438
|
+
}
|
|
406
439
|
function parseSparkLeverageManagement(position, parseData) {
|
|
407
440
|
const _position = cloneDeep(position);
|
|
408
441
|
const { subStruct, subId } = parseData.subscriptionEventData;
|
|
@@ -564,11 +597,11 @@ function parseMorphoBlueLeverageManagement(position, parseData) {
|
|
|
564
597
|
_position.strategy.strategyId = isEOA ? Strategies.IdOverrides.EoaLeverageManagement : Strategies.IdOverrides.LeverageManagement;
|
|
565
598
|
return _position;
|
|
566
599
|
}
|
|
567
|
-
function
|
|
600
|
+
function parseAaveV3LeverageManagementOnPrice(position, parseData) {
|
|
568
601
|
const _position = cloneDeep(position);
|
|
569
602
|
const { subStruct } = parseData.subscriptionEventData;
|
|
570
603
|
const triggerData = triggerService.aaveV3QuotePriceTrigger.decode(subStruct.triggerData);
|
|
571
|
-
const subData = subDataService.
|
|
604
|
+
const subData = subDataService.aaveV3LeverageManagementOnPriceSubData.decode(subStruct.subData);
|
|
572
605
|
_position.strategyData.decoded.triggerData = triggerData;
|
|
573
606
|
_position.strategyData.decoded.subData = subData;
|
|
574
607
|
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, Math.random());
|
|
@@ -585,6 +618,32 @@ function parseAaveV3OpenOrderFromCollateral(position, parseData) {
|
|
|
585
618
|
};
|
|
586
619
|
return _position;
|
|
587
620
|
}
|
|
621
|
+
function parseLiquityV2CloseOnPrice(position, parseData) {
|
|
622
|
+
const _position = cloneDeep(position);
|
|
623
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
624
|
+
const triggerData = triggerService.closePriceTrigger.decode(subStruct.triggerData);
|
|
625
|
+
const subData = subDataService.liquityV2CloseSubData.decode(subStruct.subData);
|
|
626
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
627
|
+
_position.strategyData.decoded.subData = subData;
|
|
628
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, subData.troveId, subData.market);
|
|
629
|
+
const { takeProfitType, stopLossType } = getStopLossAndTakeProfitTypeByCloseStrategyType(+subData.closeType);
|
|
630
|
+
// User can have:
|
|
631
|
+
// - Only TakeProfit
|
|
632
|
+
// - Only StopLoss
|
|
633
|
+
// - Both
|
|
634
|
+
// TODO: see on frontend what specific data we need here because stop-loss and take-profit is one bundle now
|
|
635
|
+
_position.strategy.strategyId = Strategies.Identifiers.CloseOnPrice;
|
|
636
|
+
_position.specific = {
|
|
637
|
+
market: subData.market,
|
|
638
|
+
troveId: subData.troveId,
|
|
639
|
+
stopLossPrice: triggerData.lowerPrice,
|
|
640
|
+
takeProfitPrice: triggerData.upperPrice,
|
|
641
|
+
closeToAssetAddr: triggerData.tokenAddr,
|
|
642
|
+
takeProfitType,
|
|
643
|
+
stopLossType,
|
|
644
|
+
};
|
|
645
|
+
return _position;
|
|
646
|
+
}
|
|
588
647
|
const parsingMethodsMapping = {
|
|
589
648
|
[ProtocolIdentifiers.StrategiesAutomation.MakerDAO]: {
|
|
590
649
|
[Strategies.Identifiers.SavingsLiqProtection]: parseMakerSavingsLiqProtection,
|
|
@@ -605,6 +664,11 @@ const parsingMethodsMapping = {
|
|
|
605
664
|
[Strategies.Identifiers.SavingsDsrSupply]: parseLiquitySavingsLiqProtection,
|
|
606
665
|
[Strategies.Identifiers.DebtInFrontRepay]: parseLiquityDebtInFrontRepay,
|
|
607
666
|
},
|
|
667
|
+
[ProtocolIdentifiers.StrategiesAutomation.LiquityV2]: {
|
|
668
|
+
[Strategies.Identifiers.Repay]: parseLiquityV2LeverageManagement,
|
|
669
|
+
[Strategies.Identifiers.Boost]: parseLiquityV2LeverageManagement,
|
|
670
|
+
[Strategies.Identifiers.CloseOnPrice]: parseLiquityV2CloseOnPrice,
|
|
671
|
+
},
|
|
608
672
|
[ProtocolIdentifiers.StrategiesAutomation.AaveV2]: {
|
|
609
673
|
[Strategies.Identifiers.Repay]: parseAaveV2LeverageManagement,
|
|
610
674
|
[Strategies.Identifiers.Boost]: parseAaveV2LeverageManagement,
|
|
@@ -616,7 +680,8 @@ const parsingMethodsMapping = {
|
|
|
616
680
|
[Strategies.Identifiers.CloseToDebtWithGasPrice]: parseAaveV3CloseOnPriceWithMaximumGasPrice,
|
|
617
681
|
[Strategies.Identifiers.CloseToCollateral]: parseAaveV3CloseOnPrice,
|
|
618
682
|
[Strategies.Identifiers.CloseToCollateralWithGasPrice]: parseAaveV3CloseOnPriceWithMaximumGasPrice,
|
|
619
|
-
[Strategies.Identifiers.OpenOrderFromCollateral]:
|
|
683
|
+
[Strategies.Identifiers.OpenOrderFromCollateral]: parseAaveV3LeverageManagementOnPrice,
|
|
684
|
+
[Strategies.Identifiers.RepayOnPrice]: parseAaveV3LeverageManagementOnPrice,
|
|
620
685
|
},
|
|
621
686
|
[ProtocolIdentifiers.StrategiesAutomation.CompoundV2]: {
|
|
622
687
|
[Strategies.Identifiers.Repay]: parseCompoundV2LeverageManagement,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { OrderType } from '../types/enums';
|
|
2
|
-
import { Bundles, ChainId, RatioState, Strategies } from '../types/enums';
|
|
2
|
+
import { CloseToAssetType, Bundles, ChainId, RatioState, Strategies } from '../types/enums';
|
|
3
3
|
import type { EthereumAddress, StrategyOrBundleIds } from '../types';
|
|
4
4
|
export declare const makerEncode: {
|
|
5
5
|
repayFromSavings(bundleId: StrategyOrBundleIds, vaultId: number, triggerRepayRatio: number, targetRepayRatio: number, isBundle?: boolean, chainId?: ChainId, daiAddr?: EthereumAddress, mcdCdpManagerAddr?: EthereumAddress): (boolean | string[] | Strategies.MainnetIds | Strategies.OptimismIds | Strategies.ArbitrumIds | Strategies.BaseIds | Bundles.MainnetIds | Bundles.OptimismIds | Bundles.ArbitrumIds | Bundles.BaseIds)[];
|
|
@@ -47,7 +47,7 @@ export declare const aaveV3Encode: {
|
|
|
47
47
|
debtAsset: EthereumAddress;
|
|
48
48
|
debtAssetId: number;
|
|
49
49
|
}): (number | boolean | string[])[];
|
|
50
|
-
|
|
50
|
+
leverageManagementOnPrice(strategyOrBundleId: number, isBundle: boolean | undefined, triggerData: {
|
|
51
51
|
baseTokenAddress: EthereumAddress;
|
|
52
52
|
quoteTokenAddress: EthereumAddress;
|
|
53
53
|
price: number;
|
|
@@ -98,3 +98,7 @@ export declare const crvUSDEncode: {
|
|
|
98
98
|
export declare const morphoBlueEncode: {
|
|
99
99
|
leverageManagement(marketId: string, loanToken: EthereumAddress, collToken: EthereumAddress, oracle: EthereumAddress, irm: EthereumAddress, lltv: string, ratioState: RatioState, targetRatio: number, triggerRatio: number, user: EthereumAddress, isEOA: boolean, network: ChainId): (boolean | string[] | Bundles.MainnetIds)[] | (boolean | string[] | Bundles.BaseIds)[];
|
|
100
100
|
};
|
|
101
|
+
export declare const liquityV2Encode: {
|
|
102
|
+
leverageManagement(market: EthereumAddress, troveId: string, ratioState: RatioState, targetRatio: number, triggerRatio: number, strategyOrBundleId: number): (number | boolean | string[])[];
|
|
103
|
+
closeOnPrice(strategyOrBundleId: number, market: EthereumAddress, troveId: string, collToken: EthereumAddress, boldToken: EthereumAddress, stopLossPrice?: number, stopLossType?: CloseToAssetType, takeProfitPrice?: number, takeProfitType?: CloseToAssetType): (number | boolean | string[])[];
|
|
104
|
+
};
|