@defisaver/automation-sdk 3.2.0 → 3.2.2
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/.env +4 -5
- package/cjs/automation/private/StrategiesAutomation.js +5 -6
- package/cjs/constants/index.js +70 -0
- package/cjs/services/strategiesService.js +174 -0
- package/cjs/services/strategySubService.d.ts +11 -1
- package/cjs/services/strategySubService.js +42 -1
- package/cjs/services/subDataService.d.ts +63 -1
- package/cjs/services/subDataService.js +195 -1
- package/cjs/services/triggerService.d.ts +43 -0
- package/cjs/services/triggerService.js +81 -1
- package/cjs/services/utils.d.ts +6 -1
- package/cjs/services/utils.js +52 -1
- package/cjs/types/contracts/generated/SubStorage.d.ts +4 -0
- package/cjs/types/enums.d.ts +45 -5
- package/cjs/types/enums.js +45 -1
- package/cjs/types/index.d.ts +26 -2
- package/esm/automation/private/StrategiesAutomation.js +5 -6
- package/esm/constants/index.js +70 -0
- package/esm/services/strategiesService.js +172 -1
- package/esm/services/strategySubService.d.ts +11 -1
- package/esm/services/strategySubService.js +43 -2
- package/esm/services/subDataService.d.ts +63 -1
- package/esm/services/subDataService.js +195 -1
- package/esm/services/triggerService.d.ts +43 -0
- package/esm/services/triggerService.js +80 -0
- package/esm/services/utils.d.ts +6 -1
- package/esm/services/utils.js +50 -1
- package/esm/types/contracts/generated/SubStorage.d.ts +4 -0
- package/esm/types/enums.d.ts +45 -5
- package/esm/types/enums.js +44 -0
- package/esm/types/index.d.ts +26 -2
- package/package.json +3 -5
- package/src/automation/private/StrategiesAutomation.ts +5 -5
- package/src/constants/index.ts +70 -0
- package/src/services/strategiesService.ts +224 -1
- package/src/services/strategySubService.ts +111 -1
- package/src/services/subDataService.ts +271 -2
- package/src/services/triggerService.ts +125 -0
- package/src/services/utils.ts +60 -1
- package/src/types/enums.ts +44 -0
- package/src/types/index.ts +34 -1
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";
|
|
@@ -47,6 +74,7 @@ var ProtocolIdentifiers;
|
|
|
47
74
|
StrategiesAutomation["Spark"] = "Spark";
|
|
48
75
|
StrategiesAutomation["CrvUSD"] = "CurveUSD";
|
|
49
76
|
StrategiesAutomation["MorphoBlue"] = "MorphoBlue";
|
|
77
|
+
StrategiesAutomation["FluidT1"] = "FluidT1";
|
|
50
78
|
})(StrategiesAutomation = ProtocolIdentifiers.StrategiesAutomation || (ProtocolIdentifiers.StrategiesAutomation = {}));
|
|
51
79
|
let LegacyAutomation;
|
|
52
80
|
(function (LegacyAutomation) {
|
|
@@ -73,6 +101,7 @@ var Strategies;
|
|
|
73
101
|
MainnetIds[MainnetIds["LIQUITY_DSR_SUPPLY"] = 70] = "LIQUITY_DSR_SUPPLY";
|
|
74
102
|
MainnetIds[MainnetIds["LIQUITY_DEBT_IN_FRONT_REPAY"] = 75] = "LIQUITY_DEBT_IN_FRONT_REPAY";
|
|
75
103
|
MainnetIds[MainnetIds["CURVEUSD_PAYBACK"] = 92] = "CURVEUSD_PAYBACK";
|
|
104
|
+
MainnetIds[MainnetIds["LIQUITY_V2_PAYBACK"] = 113] = "LIQUITY_V2_PAYBACK";
|
|
76
105
|
})(MainnetIds = Strategies.MainnetIds || (Strategies.MainnetIds = {}));
|
|
77
106
|
let OptimismIds;
|
|
78
107
|
(function (OptimismIds) {
|
|
@@ -104,6 +133,7 @@ var Strategies;
|
|
|
104
133
|
Identifiers["CloseToCollateralWithGasPrice"] = "close-to-collateral-with-gas-price";
|
|
105
134
|
Identifiers["CloseOnPriceToDebt"] = "close-on-price-to-debt";
|
|
106
135
|
Identifiers["CloseOnPriceToColl"] = "close-on-price-to-collateral";
|
|
136
|
+
Identifiers["CloseOnPrice"] = "close-on-price";
|
|
107
137
|
Identifiers["TrailingStopToColl"] = "trailing-stop-to-collateral";
|
|
108
138
|
Identifiers["TrailingStopToDebt"] = "trailing-stop-to-debt";
|
|
109
139
|
Identifiers["Rebond"] = "rebond";
|
|
@@ -114,6 +144,7 @@ var Strategies;
|
|
|
114
144
|
Identifiers["DebtInFrontRepay"] = "debt-in-front-repay";
|
|
115
145
|
Identifiers["OpenOrderFromCollateral"] = "open-order-from-collateral";
|
|
116
146
|
Identifiers["OpenOrderFromDebt"] = "open-order-from-debt";
|
|
147
|
+
Identifiers["BoostOnPrice"] = "boost-on-price";
|
|
117
148
|
Identifiers["RepayOnPrice"] = "repay-on-price";
|
|
118
149
|
})(Identifiers = Strategies.Identifiers || (Strategies.Identifiers = {}));
|
|
119
150
|
let IdOverrides;
|
|
@@ -171,6 +202,14 @@ var Bundles;
|
|
|
171
202
|
MainnetIds[MainnetIds["MORPHO_BLUE_EOA_BOOST"] = 35] = "MORPHO_BLUE_EOA_BOOST";
|
|
172
203
|
MainnetIds[MainnetIds["AAVE_V3_OPEN_ORDER_FROM_COLLATERAL"] = 36] = "AAVE_V3_OPEN_ORDER_FROM_COLLATERAL";
|
|
173
204
|
MainnetIds[MainnetIds["AAVE_V3_REPAY_ON_PRICE"] = 37] = "AAVE_V3_REPAY_ON_PRICE";
|
|
205
|
+
MainnetIds[MainnetIds["MORPHO_BLUE_BOOST_ON_PRICE"] = 38] = "MORPHO_BLUE_BOOST_ON_PRICE";
|
|
206
|
+
MainnetIds[MainnetIds["LIQUITY_V2_REPAY"] = 39] = "LIQUITY_V2_REPAY";
|
|
207
|
+
MainnetIds[MainnetIds["LIQUITY_V2_BOOST"] = 40] = "LIQUITY_V2_BOOST";
|
|
208
|
+
MainnetIds[MainnetIds["LIQUITY_V2_CLOSE"] = 41] = "LIQUITY_V2_CLOSE";
|
|
209
|
+
MainnetIds[MainnetIds["LIQUITY_V2_REPAY_ON_PRICE"] = 42] = "LIQUITY_V2_REPAY_ON_PRICE";
|
|
210
|
+
MainnetIds[MainnetIds["LIQUITY_V2_BOOST_ON_PRICE"] = 43] = "LIQUITY_V2_BOOST_ON_PRICE";
|
|
211
|
+
MainnetIds[MainnetIds["FLUID_T1_REPAY"] = 44] = "FLUID_T1_REPAY";
|
|
212
|
+
MainnetIds[MainnetIds["FLUID_T1_BOOST"] = 45] = "FLUID_T1_BOOST";
|
|
174
213
|
})(MainnetIds = Bundles.MainnetIds || (Bundles.MainnetIds = {}));
|
|
175
214
|
let OptimismIds;
|
|
176
215
|
(function (OptimismIds) {
|
|
@@ -193,6 +232,9 @@ var Bundles;
|
|
|
193
232
|
BaseIds[BaseIds["MORPHO_BLUE_BOOST"] = 9] = "MORPHO_BLUE_BOOST";
|
|
194
233
|
BaseIds[BaseIds["AAVE_V3_OPEN_ORDER_FROM_COLLATERAL"] = 10] = "AAVE_V3_OPEN_ORDER_FROM_COLLATERAL";
|
|
195
234
|
BaseIds[BaseIds["AAVE_V3_REPAY_ON_PRICE"] = 11] = "AAVE_V3_REPAY_ON_PRICE";
|
|
235
|
+
BaseIds[BaseIds["MORPHO_BLUE_BOOST_ON_PRICE"] = 12] = "MORPHO_BLUE_BOOST_ON_PRICE";
|
|
236
|
+
BaseIds[BaseIds["FLUID_T1_REPAY"] = 13] = "FLUID_T1_REPAY";
|
|
237
|
+
BaseIds[BaseIds["FLUID_T1_BOOST"] = 14] = "FLUID_T1_BOOST";
|
|
196
238
|
})(BaseIds = Bundles.BaseIds || (Bundles.BaseIds = {}));
|
|
197
239
|
let ArbitrumIds;
|
|
198
240
|
(function (ArbitrumIds) {
|
|
@@ -204,5 +246,7 @@ var Bundles;
|
|
|
204
246
|
ArbitrumIds[ArbitrumIds["COMP_V3_SW_BOOST_BUNDLE"] = 5] = "COMP_V3_SW_BOOST_BUNDLE";
|
|
205
247
|
ArbitrumIds[ArbitrumIds["AAVE_V3_OPEN_ORDER_FROM_COLLATERAL"] = 6] = "AAVE_V3_OPEN_ORDER_FROM_COLLATERAL";
|
|
206
248
|
ArbitrumIds[ArbitrumIds["AAVE_V3_REPAY_ON_PRICE"] = 7] = "AAVE_V3_REPAY_ON_PRICE";
|
|
249
|
+
ArbitrumIds[ArbitrumIds["FLUID_T1_REPAY"] = 8] = "FLUID_T1_REPAY";
|
|
250
|
+
ArbitrumIds[ArbitrumIds["FLUID_T1_BOOST"] = 9] = "FLUID_T1_BOOST";
|
|
207
251
|
})(ArbitrumIds = Bundles.ArbitrumIds || (Bundles.ArbitrumIds = {}));
|
|
208
252
|
})(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;
|
|
@@ -123,6 +123,10 @@ export declare namespace Position {
|
|
|
123
123
|
interface BoostOnPriceAave extends CloseOnPriceAave {
|
|
124
124
|
ratio: number;
|
|
125
125
|
}
|
|
126
|
+
interface BoostOnPriceMorpho extends Base {
|
|
127
|
+
marketId: string;
|
|
128
|
+
subHash: string;
|
|
129
|
+
}
|
|
126
130
|
interface CloseOnPriceWithMaximumGasPriceAave extends Base {
|
|
127
131
|
collAsset: EthereumAddress;
|
|
128
132
|
collAssetId: number;
|
|
@@ -134,6 +138,26 @@ export declare namespace Position {
|
|
|
134
138
|
maximumGasPrice: string;
|
|
135
139
|
ratioState: RatioState;
|
|
136
140
|
}
|
|
141
|
+
interface CloseOnPriceLiquityV2 extends Base {
|
|
142
|
+
market: EthereumAddress;
|
|
143
|
+
troveId: string;
|
|
144
|
+
stopLossPrice: string;
|
|
145
|
+
takeProfitPrice: string;
|
|
146
|
+
closeToAssetAddr: EthereumAddress;
|
|
147
|
+
stopLossType: CloseToAssetType | undefined;
|
|
148
|
+
takeProfitType: CloseToAssetType | undefined;
|
|
149
|
+
}
|
|
150
|
+
interface BoostOnPriceLiquityV2 extends Base {
|
|
151
|
+
market: EthereumAddress;
|
|
152
|
+
troveId: string;
|
|
153
|
+
subHash: string;
|
|
154
|
+
}
|
|
155
|
+
interface PaybackLiquityV2 extends Base {
|
|
156
|
+
market: EthereumAddress;
|
|
157
|
+
troveId: string;
|
|
158
|
+
targetRatio: number;
|
|
159
|
+
triggerRatio: number;
|
|
160
|
+
}
|
|
137
161
|
interface TrailingStop extends Base {
|
|
138
162
|
roundId: number;
|
|
139
163
|
triggerPercentage: number;
|
|
@@ -148,7 +172,7 @@ export declare namespace Position {
|
|
|
148
172
|
subHashRepay?: string;
|
|
149
173
|
}
|
|
150
174
|
}
|
|
151
|
-
type SpecificAny = Specific.CloseOnPrice | Specific.TrailingStop | Specific.RatioProtection | Specific.CloseOnPriceAave | Specific.BoostOnPriceAave | Specific.CloseOnPriceWithMaximumGasPriceAave | Specific.DebtInFrontRepay | Specific.LeverageManagementCrvUSD;
|
|
175
|
+
type SpecificAny = Specific.CloseOnPrice | Specific.TrailingStop | Specific.RatioProtection | Specific.CloseOnPriceAave | Specific.BoostOnPriceAave | Specific.CloseOnPriceWithMaximumGasPriceAave | Specific.DebtInFrontRepay | Specific.LeverageManagementCrvUSD | Specific.CloseOnPriceLiquityV2 | Specific.BoostOnPriceMorpho | Specific.BoostOnPriceLiquityV2 | Specific.PaybackLiquityV2;
|
|
152
176
|
interface Automated {
|
|
153
177
|
chainId: ChainId;
|
|
154
178
|
positionId: string;
|
|
@@ -121,7 +121,6 @@ export default class StrategiesAutomation extends Automation {
|
|
|
121
121
|
}
|
|
122
122
|
});
|
|
123
123
|
if (mergeExtension.length > 0) {
|
|
124
|
-
console.error('Not all merge-able extensions were used', mergeExtension);
|
|
125
124
|
subscriptions = [...subscriptions, ...mergeExtension.map((s) => (Object.assign(Object.assign({}, s), { subIds: [s.subId] })))];
|
|
126
125
|
}
|
|
127
126
|
return subscriptions;
|
|
@@ -145,10 +144,10 @@ export default class StrategiesAutomation extends Automation {
|
|
|
145
144
|
const replaceSubWithUpdate = (index) => __awaiter(this, void 0, void 0, function* () {
|
|
146
145
|
var _a;
|
|
147
146
|
const sub = strategiesSubs[index];
|
|
148
|
-
let latestUpdate = subscriptionEvents[index].returnValues;
|
|
147
|
+
let latestUpdate = Object.assign({}, subscriptionEvents[index].returnValues);
|
|
149
148
|
if (latestUpdate.subHash !== (sub === null || sub === void 0 ? void 0 : sub.strategySubHash)) {
|
|
150
149
|
const updates = yield this.getUpdateDataEventsFromSubStorage(Object.assign(Object.assign({}, addToObjectIf(!!_options, _options)), { filter: { subId: latestUpdate.subId } }));
|
|
151
|
-
latestUpdate = Object.assign(Object.assign({}, latestUpdate), (_a = updates === null || updates === void 0 ? void 0 : updates[updates.length - 1]) === null || _a === void 0 ? void 0 : _a.returnValues);
|
|
150
|
+
latestUpdate = Object.assign(Object.assign(Object.assign({}, latestUpdate), (_a = updates === null || updates === void 0 ? void 0 : updates[updates.length - 1]) === null || _a === void 0 ? void 0 : _a.returnValues), { 2: latestUpdate[2] });
|
|
152
151
|
}
|
|
153
152
|
subscriptions.push(this.getParsedSubscriptions({
|
|
154
153
|
chainId: this.chainId,
|
|
@@ -157,12 +156,12 @@ export default class StrategiesAutomation extends Automation {
|
|
|
157
156
|
strategiesSubsData: sub,
|
|
158
157
|
}));
|
|
159
158
|
});
|
|
160
|
-
|
|
159
|
+
// eslint-disable-next-line func-names
|
|
160
|
+
const pool = new PromisePool(function* () {
|
|
161
161
|
for (let index = 0; index < strategiesSubs.length; index++) {
|
|
162
162
|
yield replaceSubWithUpdate(index);
|
|
163
163
|
}
|
|
164
|
-
};
|
|
165
|
-
const pool = new PromisePool(generatePromises, 50);
|
|
164
|
+
}, 50);
|
|
166
165
|
yield pool.start();
|
|
167
166
|
if (options === null || options === void 0 ? void 0 : options.mergeSubs) {
|
|
168
167
|
subscriptions = this.mergeSubs(subscriptions);
|
package/esm/constants/index.js
CHANGED
|
@@ -90,6 +90,11 @@ export const MAINNET_STRATEGIES_INFO = {
|
|
|
90
90
|
strategyId: Strategies.Identifiers.Payback,
|
|
91
91
|
protocol: PROTOCOLS.CrvUSD,
|
|
92
92
|
},
|
|
93
|
+
[Strategies.MainnetIds.LIQUITY_V2_PAYBACK]: {
|
|
94
|
+
strategyOrBundleId: Strategies.MainnetIds.LIQUITY_V2_PAYBACK,
|
|
95
|
+
strategyId: Strategies.Identifiers.Payback,
|
|
96
|
+
protocol: PROTOCOLS.LiquityV2,
|
|
97
|
+
},
|
|
93
98
|
};
|
|
94
99
|
export const OPTIMISM_STRATEGIES_INFO = {
|
|
95
100
|
[Strategies.OptimismIds.EXCHANGE_DCA]: {
|
|
@@ -347,6 +352,46 @@ export const MAINNET_BUNDLES_INFO = {
|
|
|
347
352
|
strategyId: Strategies.Identifiers.RepayOnPrice,
|
|
348
353
|
protocol: PROTOCOLS.AaveV3,
|
|
349
354
|
},
|
|
355
|
+
[Bundles.MainnetIds.LIQUITY_V2_REPAY]: {
|
|
356
|
+
strategyOrBundleId: Bundles.MainnetIds.LIQUITY_V2_REPAY,
|
|
357
|
+
strategyId: Strategies.Identifiers.Repay,
|
|
358
|
+
protocol: PROTOCOLS.LiquityV2,
|
|
359
|
+
},
|
|
360
|
+
[Bundles.MainnetIds.LIQUITY_V2_BOOST]: {
|
|
361
|
+
strategyOrBundleId: Bundles.MainnetIds.LIQUITY_V2_BOOST,
|
|
362
|
+
strategyId: Strategies.Identifiers.Boost,
|
|
363
|
+
protocol: PROTOCOLS.LiquityV2,
|
|
364
|
+
},
|
|
365
|
+
[Bundles.MainnetIds.LIQUITY_V2_CLOSE]: {
|
|
366
|
+
strategyOrBundleId: Bundles.MainnetIds.LIQUITY_V2_CLOSE,
|
|
367
|
+
strategyId: Strategies.Identifiers.CloseOnPrice,
|
|
368
|
+
protocol: PROTOCOLS.LiquityV2,
|
|
369
|
+
},
|
|
370
|
+
[Bundles.MainnetIds.LIQUITY_V2_REPAY_ON_PRICE]: {
|
|
371
|
+
strategyOrBundleId: Bundles.MainnetIds.LIQUITY_V2_REPAY_ON_PRICE,
|
|
372
|
+
strategyId: Strategies.Identifiers.RepayOnPrice,
|
|
373
|
+
protocol: PROTOCOLS.LiquityV2,
|
|
374
|
+
},
|
|
375
|
+
[Bundles.MainnetIds.LIQUITY_V2_BOOST_ON_PRICE]: {
|
|
376
|
+
strategyOrBundleId: Bundles.MainnetIds.LIQUITY_V2_BOOST_ON_PRICE,
|
|
377
|
+
strategyId: Strategies.Identifiers.BoostOnPrice,
|
|
378
|
+
protocol: PROTOCOLS.LiquityV2,
|
|
379
|
+
},
|
|
380
|
+
[Bundles.MainnetIds.MORPHO_BLUE_BOOST_ON_PRICE]: {
|
|
381
|
+
strategyOrBundleId: Bundles.MainnetIds.MORPHO_BLUE_BOOST_ON_PRICE,
|
|
382
|
+
strategyId: Strategies.Identifiers.BoostOnPrice,
|
|
383
|
+
protocol: PROTOCOLS.MorphoBlue,
|
|
384
|
+
},
|
|
385
|
+
[Bundles.MainnetIds.FLUID_T1_REPAY]: {
|
|
386
|
+
strategyOrBundleId: Bundles.MainnetIds.FLUID_T1_REPAY,
|
|
387
|
+
strategyId: Strategies.Identifiers.Repay,
|
|
388
|
+
protocol: PROTOCOLS.FluidT1,
|
|
389
|
+
},
|
|
390
|
+
[Bundles.MainnetIds.FLUID_T1_BOOST]: {
|
|
391
|
+
strategyOrBundleId: Bundles.MainnetIds.FLUID_T1_BOOST,
|
|
392
|
+
strategyId: Strategies.Identifiers.Boost,
|
|
393
|
+
protocol: PROTOCOLS.FluidT1,
|
|
394
|
+
},
|
|
350
395
|
};
|
|
351
396
|
export const OPTIMISM_BUNDLES_INFO = {
|
|
352
397
|
[Bundles.OptimismIds.AAVE_V3_REPAY]: {
|
|
@@ -431,6 +476,21 @@ export const BASE_BUNDLES_INFO = {
|
|
|
431
476
|
strategyId: Strategies.Identifiers.RepayOnPrice,
|
|
432
477
|
protocol: PROTOCOLS.AaveV3,
|
|
433
478
|
},
|
|
479
|
+
[Bundles.BaseIds.MORPHO_BLUE_BOOST_ON_PRICE]: {
|
|
480
|
+
strategyOrBundleId: Bundles.BaseIds.MORPHO_BLUE_BOOST_ON_PRICE,
|
|
481
|
+
strategyId: Strategies.Identifiers.BoostOnPrice,
|
|
482
|
+
protocol: PROTOCOLS.MorphoBlue,
|
|
483
|
+
},
|
|
484
|
+
[Bundles.BaseIds.FLUID_T1_REPAY]: {
|
|
485
|
+
strategyOrBundleId: Bundles.BaseIds.FLUID_T1_REPAY,
|
|
486
|
+
strategyId: Strategies.Identifiers.Repay,
|
|
487
|
+
protocol: PROTOCOLS.FluidT1,
|
|
488
|
+
},
|
|
489
|
+
[Bundles.BaseIds.FLUID_T1_BOOST]: {
|
|
490
|
+
strategyOrBundleId: Bundles.BaseIds.FLUID_T1_BOOST,
|
|
491
|
+
strategyId: Strategies.Identifiers.Boost,
|
|
492
|
+
protocol: PROTOCOLS.FluidT1,
|
|
493
|
+
},
|
|
434
494
|
};
|
|
435
495
|
export const ARBITRUM_BUNDLES_INFO = {
|
|
436
496
|
[Bundles.ArbitrumIds.AAVE_V3_REPAY]: {
|
|
@@ -473,6 +533,16 @@ export const ARBITRUM_BUNDLES_INFO = {
|
|
|
473
533
|
strategyId: Strategies.Identifiers.RepayOnPrice,
|
|
474
534
|
protocol: PROTOCOLS.AaveV3,
|
|
475
535
|
},
|
|
536
|
+
[Bundles.ArbitrumIds.FLUID_T1_REPAY]: {
|
|
537
|
+
strategyOrBundleId: Bundles.ArbitrumIds.FLUID_T1_REPAY,
|
|
538
|
+
strategyId: Strategies.Identifiers.Repay,
|
|
539
|
+
protocol: PROTOCOLS.FluidT1,
|
|
540
|
+
},
|
|
541
|
+
[Bundles.ArbitrumIds.FLUID_T1_BOOST]: {
|
|
542
|
+
strategyOrBundleId: Bundles.ArbitrumIds.FLUID_T1_BOOST,
|
|
543
|
+
strategyId: Strategies.Identifiers.Boost,
|
|
544
|
+
protocol: PROTOCOLS.FluidT1,
|
|
545
|
+
},
|
|
476
546
|
};
|
|
477
547
|
export const BUNDLES_INFO = {
|
|
478
548
|
[ChainId.Ethereum]: MAINNET_BUNDLES_INFO,
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { getAssetInfoByAddress } from '@defisaver/tokens';
|
|
2
2
|
import { cloneDeep } from 'lodash';
|
|
3
|
+
import Web3 from 'web3';
|
|
3
4
|
import { BUNDLES_INFO, STRATEGIES_INFO } from '../constants';
|
|
4
5
|
import { ChainId, ProtocolIdentifiers, Strategies } from '../types/enums';
|
|
5
|
-
import { getPositionId, getRatioStateInfoForAaveCloseStrategy, isRatioStateOver, wethToEthByAddress, } from './utils';
|
|
6
|
+
import { getPositionId, getRatioStateInfoForAaveCloseStrategy, getStopLossAndTakeProfitTypeByCloseStrategyType, isRatioStateOver, wethToEthByAddress, } from './utils';
|
|
6
7
|
import * as subDataService from './subDataService';
|
|
7
8
|
import * as triggerService from './triggerService';
|
|
9
|
+
const web3 = new Web3();
|
|
8
10
|
const SPARK_MARKET_ADDRESSES = {
|
|
9
11
|
[ChainId.Ethereum]: '0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE',
|
|
10
12
|
};
|
|
@@ -403,6 +405,39 @@ function parseLiquityLeverageManagement(position, parseData) {
|
|
|
403
405
|
_position.strategy.strategyId = Strategies.IdOverrides.LeverageManagement;
|
|
404
406
|
return _position;
|
|
405
407
|
}
|
|
408
|
+
function parseLiquityV2LeverageManagement(position, parseData) {
|
|
409
|
+
const _position = cloneDeep(position);
|
|
410
|
+
const { subStruct, subId, subHash } = parseData.subscriptionEventData;
|
|
411
|
+
const { isEnabled } = parseData.strategiesSubsData;
|
|
412
|
+
const triggerData = triggerService.liquityV2RatioTrigger.decode(subStruct.triggerData);
|
|
413
|
+
const subData = subDataService.liquityV2LeverageManagementSubData.decode(subStruct.subData);
|
|
414
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
415
|
+
_position.strategyData.decoded.subData = subData;
|
|
416
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, triggerData.troveId, triggerData.market);
|
|
417
|
+
const isRepay = _position.strategy.strategyId === Strategies.Identifiers.Repay;
|
|
418
|
+
if (isRepay) {
|
|
419
|
+
_position.specific = {
|
|
420
|
+
triggerRepayRatio: triggerData.ratio,
|
|
421
|
+
targetRepayRatio: subData.targetRatio,
|
|
422
|
+
repayEnabled: isEnabled,
|
|
423
|
+
subId1: Number(subId),
|
|
424
|
+
subHashRepay: subHash,
|
|
425
|
+
mergeWithId: Strategies.Identifiers.Boost,
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
else {
|
|
429
|
+
_position.specific = {
|
|
430
|
+
triggerBoostRatio: triggerData.ratio,
|
|
431
|
+
targetBoostRatio: subData.targetRatio,
|
|
432
|
+
boostEnabled: isEnabled,
|
|
433
|
+
subId2: Number(subId),
|
|
434
|
+
subHashBoost: subHash,
|
|
435
|
+
mergeId: Strategies.Identifiers.Boost,
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
_position.strategy.strategyId = Strategies.IdOverrides.LeverageManagement;
|
|
439
|
+
return _position;
|
|
440
|
+
}
|
|
406
441
|
function parseSparkLeverageManagement(position, parseData) {
|
|
407
442
|
const _position = cloneDeep(position);
|
|
408
443
|
const { subStruct, subId } = parseData.subscriptionEventData;
|
|
@@ -564,6 +599,32 @@ function parseMorphoBlueLeverageManagement(position, parseData) {
|
|
|
564
599
|
_position.strategy.strategyId = isEOA ? Strategies.IdOverrides.EoaLeverageManagement : Strategies.IdOverrides.LeverageManagement;
|
|
565
600
|
return _position;
|
|
566
601
|
}
|
|
602
|
+
function parseMorphoBlueLeverageManagementOnPrice(position, parseData) {
|
|
603
|
+
const _position = cloneDeep(position);
|
|
604
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
605
|
+
const triggerData = triggerService.morphoBluePriceTrigger.decode(subStruct.triggerData);
|
|
606
|
+
const subData = subDataService.morphoBlueLeverageManagementOnPriceSubData.decode(subStruct.subData);
|
|
607
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
608
|
+
_position.strategyData.decoded.subData = subData;
|
|
609
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, Math.random());
|
|
610
|
+
const marketIdEncodedData = web3.eth.abi.encodeParameters(['address', 'address', 'address', 'address', 'uint256'], [
|
|
611
|
+
subData.loanToken,
|
|
612
|
+
subData.collToken,
|
|
613
|
+
subData.oracle,
|
|
614
|
+
subData.irm,
|
|
615
|
+
subData.lltv,
|
|
616
|
+
]);
|
|
617
|
+
const marketId = web3.utils.keccak256(marketIdEncodedData);
|
|
618
|
+
_position.specific = {
|
|
619
|
+
subHash: _position.subHash,
|
|
620
|
+
marketId,
|
|
621
|
+
collAsset: subData.collToken,
|
|
622
|
+
debtAsset: subData.loanToken,
|
|
623
|
+
price: triggerData.price,
|
|
624
|
+
ratio: subData.targetRatio,
|
|
625
|
+
};
|
|
626
|
+
return _position;
|
|
627
|
+
}
|
|
567
628
|
function parseAaveV3LeverageManagementOnPrice(position, parseData) {
|
|
568
629
|
const _position = cloneDeep(position);
|
|
569
630
|
const { subStruct } = parseData.subscriptionEventData;
|
|
@@ -585,6 +646,103 @@ function parseAaveV3LeverageManagementOnPrice(position, parseData) {
|
|
|
585
646
|
};
|
|
586
647
|
return _position;
|
|
587
648
|
}
|
|
649
|
+
function parseLiquityV2CloseOnPrice(position, parseData) {
|
|
650
|
+
const _position = cloneDeep(position);
|
|
651
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
652
|
+
const triggerData = triggerService.closePriceTrigger.decode(subStruct.triggerData);
|
|
653
|
+
const subData = subDataService.liquityV2CloseSubData.decode(subStruct.subData);
|
|
654
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
655
|
+
_position.strategyData.decoded.subData = subData;
|
|
656
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, subData.troveId, subData.market);
|
|
657
|
+
const { takeProfitType, stopLossType } = getStopLossAndTakeProfitTypeByCloseStrategyType(+subData.closeType);
|
|
658
|
+
// User can have:
|
|
659
|
+
// - Only TakeProfit
|
|
660
|
+
// - Only StopLoss
|
|
661
|
+
// - Both
|
|
662
|
+
// TODO: see on frontend what specific data we need here because stop-loss and take-profit is one bundle now
|
|
663
|
+
_position.strategy.strategyId = Strategies.Identifiers.CloseOnPrice;
|
|
664
|
+
_position.specific = {
|
|
665
|
+
market: subData.market,
|
|
666
|
+
troveId: subData.troveId,
|
|
667
|
+
stopLossPrice: triggerData.lowerPrice,
|
|
668
|
+
takeProfitPrice: triggerData.upperPrice,
|
|
669
|
+
closeToAssetAddr: triggerData.tokenAddr,
|
|
670
|
+
takeProfitType,
|
|
671
|
+
stopLossType,
|
|
672
|
+
};
|
|
673
|
+
return _position;
|
|
674
|
+
}
|
|
675
|
+
function parseLiquityV2LeverageManagementOnPrice(position, parseData) {
|
|
676
|
+
const _position = cloneDeep(position);
|
|
677
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
678
|
+
const triggerData = triggerService.liquityV2QuotePriceTrigger.decode(subStruct.triggerData);
|
|
679
|
+
const subData = subDataService.liquityV2LeverageManagementOnPriceSubData.decode(subStruct.subData);
|
|
680
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
681
|
+
_position.strategyData.decoded.subData = subData;
|
|
682
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, Math.random());
|
|
683
|
+
_position.specific = {
|
|
684
|
+
subHash: _position.subHash,
|
|
685
|
+
market: subData.market,
|
|
686
|
+
troveId: subData.troveId,
|
|
687
|
+
collAsset: subData.collToken,
|
|
688
|
+
debtAsset: subData.boldToken,
|
|
689
|
+
price: triggerData.price,
|
|
690
|
+
ratio: subData.targetRatio,
|
|
691
|
+
ratioState: triggerData.ratioState,
|
|
692
|
+
};
|
|
693
|
+
return _position;
|
|
694
|
+
}
|
|
695
|
+
function parseLiquityV2Payback(position, parseData) {
|
|
696
|
+
const _position = cloneDeep(position);
|
|
697
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
698
|
+
const triggerData = triggerService.liquityV2RatioTrigger.decode(subStruct.triggerData);
|
|
699
|
+
const subData = subDataService.liquityV2PaybackSubData.decode(subStruct.subData);
|
|
700
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
701
|
+
_position.strategyData.decoded.subData = subData;
|
|
702
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, triggerData.troveId, triggerData.market);
|
|
703
|
+
_position.strategy.strategyId = Strategies.Identifiers.Payback;
|
|
704
|
+
_position.specific = {
|
|
705
|
+
subHash: _position.subHash,
|
|
706
|
+
market: subData.market,
|
|
707
|
+
troveId: subData.troveId,
|
|
708
|
+
targetRatio: subData.targetRatio,
|
|
709
|
+
triggerRatio: triggerData.ratio,
|
|
710
|
+
};
|
|
711
|
+
return _position;
|
|
712
|
+
}
|
|
713
|
+
function parseFluidT1LeverageManagement(position, parseData) {
|
|
714
|
+
const _position = cloneDeep(position);
|
|
715
|
+
const { subStruct, subId, subHash } = parseData.subscriptionEventData;
|
|
716
|
+
const { isEnabled } = parseData.strategiesSubsData;
|
|
717
|
+
const triggerData = triggerService.fluidRatioTrigger.decode(subStruct.triggerData);
|
|
718
|
+
const subData = subDataService.fluidLeverageManagementSubData.decode(subStruct.subData);
|
|
719
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
720
|
+
_position.strategyData.decoded.subData = subData;
|
|
721
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, triggerData.nftId, subData.vault);
|
|
722
|
+
const isRepay = _position.strategy.strategyId === Strategies.Identifiers.Repay;
|
|
723
|
+
if (isRepay) {
|
|
724
|
+
_position.specific = {
|
|
725
|
+
triggerRepayRatio: triggerData.ratio,
|
|
726
|
+
targetRepayRatio: subData.targetRatio,
|
|
727
|
+
repayEnabled: isEnabled,
|
|
728
|
+
subId1: Number(subId),
|
|
729
|
+
subHashRepay: subHash,
|
|
730
|
+
mergeWithId: Strategies.Identifiers.Boost,
|
|
731
|
+
};
|
|
732
|
+
}
|
|
733
|
+
else {
|
|
734
|
+
_position.specific = {
|
|
735
|
+
triggerBoostRatio: triggerData.ratio,
|
|
736
|
+
targetBoostRatio: subData.targetRatio,
|
|
737
|
+
boostEnabled: isEnabled,
|
|
738
|
+
subId2: Number(subId),
|
|
739
|
+
subHashBoost: subHash,
|
|
740
|
+
mergeId: Strategies.Identifiers.Boost,
|
|
741
|
+
};
|
|
742
|
+
}
|
|
743
|
+
_position.strategy.strategyId = Strategies.IdOverrides.LeverageManagement;
|
|
744
|
+
return _position;
|
|
745
|
+
}
|
|
588
746
|
const parsingMethodsMapping = {
|
|
589
747
|
[ProtocolIdentifiers.StrategiesAutomation.MakerDAO]: {
|
|
590
748
|
[Strategies.Identifiers.SavingsLiqProtection]: parseMakerSavingsLiqProtection,
|
|
@@ -605,6 +763,14 @@ const parsingMethodsMapping = {
|
|
|
605
763
|
[Strategies.Identifiers.SavingsDsrSupply]: parseLiquitySavingsLiqProtection,
|
|
606
764
|
[Strategies.Identifiers.DebtInFrontRepay]: parseLiquityDebtInFrontRepay,
|
|
607
765
|
},
|
|
766
|
+
[ProtocolIdentifiers.StrategiesAutomation.LiquityV2]: {
|
|
767
|
+
[Strategies.Identifiers.Repay]: parseLiquityV2LeverageManagement,
|
|
768
|
+
[Strategies.Identifiers.Boost]: parseLiquityV2LeverageManagement,
|
|
769
|
+
[Strategies.Identifiers.CloseOnPrice]: parseLiquityV2CloseOnPrice,
|
|
770
|
+
[Strategies.Identifiers.BoostOnPrice]: parseLiquityV2LeverageManagementOnPrice,
|
|
771
|
+
[Strategies.Identifiers.RepayOnPrice]: parseLiquityV2LeverageManagementOnPrice,
|
|
772
|
+
[Strategies.Identifiers.Payback]: parseLiquityV2Payback,
|
|
773
|
+
},
|
|
608
774
|
[ProtocolIdentifiers.StrategiesAutomation.AaveV2]: {
|
|
609
775
|
[Strategies.Identifiers.Repay]: parseAaveV2LeverageManagement,
|
|
610
776
|
[Strategies.Identifiers.Boost]: parseAaveV2LeverageManagement,
|
|
@@ -656,6 +822,11 @@ const parsingMethodsMapping = {
|
|
|
656
822
|
[Strategies.Identifiers.Boost]: parseMorphoBlueLeverageManagement,
|
|
657
823
|
[Strategies.Identifiers.EoaRepay]: parseMorphoBlueLeverageManagement,
|
|
658
824
|
[Strategies.Identifiers.EoaBoost]: parseMorphoBlueLeverageManagement,
|
|
825
|
+
[Strategies.Identifiers.BoostOnPrice]: parseMorphoBlueLeverageManagementOnPrice,
|
|
826
|
+
},
|
|
827
|
+
[ProtocolIdentifiers.StrategiesAutomation.FluidT1]: {
|
|
828
|
+
[Strategies.Identifiers.Repay]: parseFluidT1LeverageManagement,
|
|
829
|
+
[Strategies.Identifiers.Boost]: parseFluidT1LeverageManagement,
|
|
659
830
|
},
|
|
660
831
|
};
|
|
661
832
|
function getParsingMethod(id, strategy) {
|
|
@@ -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)[];
|
|
@@ -97,4 +97,14 @@ export declare const crvUSDEncode: {
|
|
|
97
97
|
};
|
|
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
|
+
leverageManagementOnPrice(strategyOrBundleId: number, isBundle: boolean | undefined, loanToken: EthereumAddress, collToken: EthereumAddress, oracle: EthereumAddress, irm: EthereumAddress, lltv: string, user: EthereumAddress, targetRatio: number, price: number, priceState: RatioState): (number | boolean | string[])[];
|
|
101
|
+
};
|
|
102
|
+
export declare const liquityV2Encode: {
|
|
103
|
+
leverageManagement(market: EthereumAddress, troveId: string, collToken: EthereumAddress, boldToken: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number, strategyOrBundleId: number): (number | boolean | string[])[];
|
|
104
|
+
closeOnPrice(strategyOrBundleId: number, market: EthereumAddress, troveId: string, collToken: EthereumAddress, boldToken: EthereumAddress, stopLossPrice?: number, stopLossType?: CloseToAssetType, takeProfitPrice?: number, takeProfitType?: CloseToAssetType): (number | boolean | string[])[];
|
|
105
|
+
leverageManagementOnPrice(strategyOrBundleId: number, market: EthereumAddress, price: number, state: RatioState, troveId: string, collToken: EthereumAddress, boldToken: EthereumAddress, targetRatio: number, isRepayOnPrice: boolean): (number | boolean | string[])[];
|
|
106
|
+
payback(market: EthereumAddress, troveId: string, boldToken: EthereumAddress, targetRatio: number, ratioState: RatioState, triggerRatio: number): (boolean | string[] | Strategies.MainnetIds)[];
|
|
107
|
+
};
|
|
108
|
+
export declare const fluidEncode: {
|
|
109
|
+
leverageManagement(nftId: string, vault: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number, strategyOrBundleId: number): (number | boolean | string[])[];
|
|
100
110
|
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import Dec from 'decimal.js';
|
|
2
2
|
import { getAssetInfo } from '@defisaver/tokens';
|
|
3
|
-
import { Bundles, ChainId, RatioState, Strategies, } from '../types/enums';
|
|
3
|
+
import { CloseToAssetType, Bundles, ChainId, RatioState, Strategies, } from '../types/enums';
|
|
4
4
|
import { STRATEGY_IDS } from '../constants';
|
|
5
5
|
import * as subDataService from './subDataService';
|
|
6
6
|
import * as triggerService from './triggerService';
|
|
7
|
-
import { compareAddresses, requireAddress, requireAddresses } from './utils';
|
|
7
|
+
import { compareAddresses, getCloseStrategyType, requireAddress, requireAddresses, } from './utils';
|
|
8
8
|
export const makerEncode = {
|
|
9
9
|
repayFromSavings(bundleId, vaultId, triggerRepayRatio, targetRepayRatio, isBundle = true, chainId = ChainId.Ethereum, daiAddr, mcdCdpManagerAddr) {
|
|
10
10
|
const subData = subDataService.makerRepayFromSavingsSubData.encode(vaultId, targetRepayRatio, chainId, daiAddr, mcdCdpManagerAddr);
|
|
@@ -235,4 +235,45 @@ export const morphoBlueEncode = {
|
|
|
235
235
|
const isBundle = true;
|
|
236
236
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
237
237
|
},
|
|
238
|
+
leverageManagementOnPrice(strategyOrBundleId, isBundle = true, loanToken, collToken, oracle, irm, lltv, user, targetRatio, price, priceState) {
|
|
239
|
+
const subData = subDataService.morphoBlueLeverageManagementOnPriceSubData.encode(loanToken, collToken, oracle, irm, lltv, targetRatio, user);
|
|
240
|
+
const triggerData = triggerService.morphoBluePriceTrigger.encode(oracle, collToken, loanToken, price, priceState);
|
|
241
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
242
|
+
},
|
|
243
|
+
};
|
|
244
|
+
export const liquityV2Encode = {
|
|
245
|
+
leverageManagement(market, troveId, collToken, boldToken, ratioState, targetRatio, triggerRatio, strategyOrBundleId) {
|
|
246
|
+
const isBundle = true;
|
|
247
|
+
const subData = subDataService.liquityV2LeverageManagementSubData.encode(market, troveId, collToken, boldToken, ratioState, targetRatio);
|
|
248
|
+
const triggerData = triggerService.liquityV2RatioTrigger.encode(market, troveId, triggerRatio, ratioState);
|
|
249
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
250
|
+
},
|
|
251
|
+
closeOnPrice(strategyOrBundleId, market, troveId, collToken, boldToken, stopLossPrice = 0, stopLossType = CloseToAssetType.DEBT, takeProfitPrice = 0, takeProfitType = CloseToAssetType.COLLATERAL) {
|
|
252
|
+
const isBundle = true;
|
|
253
|
+
const closeType = getCloseStrategyType(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
|
|
254
|
+
const subData = subDataService.liquityV2CloseSubData.encode(market, troveId, collToken, boldToken, closeType);
|
|
255
|
+
const triggerData = triggerService.closePriceTrigger.encode(collToken, stopLossPrice, takeProfitPrice);
|
|
256
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
257
|
+
},
|
|
258
|
+
leverageManagementOnPrice(strategyOrBundleId, market, price, state, troveId, collToken, boldToken, targetRatio, isRepayOnPrice) {
|
|
259
|
+
const subDataEncoded = subDataService.liquityV2LeverageManagementOnPriceSubData.encode(market, troveId, collToken, boldToken, targetRatio, isRepayOnPrice);
|
|
260
|
+
const triggerDataEncoded = triggerService.liquityV2QuotePriceTrigger.encode(market, price, state);
|
|
261
|
+
const isBundle = true;
|
|
262
|
+
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
263
|
+
},
|
|
264
|
+
payback(market, troveId, boldToken, targetRatio, ratioState, triggerRatio) {
|
|
265
|
+
const strategyId = Strategies.MainnetIds.LIQUITY_V2_PAYBACK;
|
|
266
|
+
const isBundle = false;
|
|
267
|
+
const subData = subDataService.liquityV2PaybackSubData.encode(market, troveId, boldToken, targetRatio, ratioState);
|
|
268
|
+
const triggerData = triggerService.liquityV2RatioTrigger.encode(market, troveId, triggerRatio, ratioState);
|
|
269
|
+
return [strategyId, isBundle, triggerData, subData];
|
|
270
|
+
},
|
|
271
|
+
};
|
|
272
|
+
export const fluidEncode = {
|
|
273
|
+
leverageManagement(nftId, vault, ratioState, targetRatio, triggerRatio, strategyOrBundleId) {
|
|
274
|
+
const isBundle = true;
|
|
275
|
+
const subData = subDataService.fluidLeverageManagementSubData.encode(nftId, vault, ratioState, targetRatio);
|
|
276
|
+
const triggerData = triggerService.fluidRatioTrigger.encode(nftId, triggerRatio, ratioState);
|
|
277
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
278
|
+
},
|
|
238
279
|
};
|