@defisaver/automation-sdk 3.3.2-dev.3 → 3.3.2-dev.5
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/services/strategiesService.js +88 -62
- package/cjs/services/subDataService.d.ts +2 -2
- package/cjs/services/subDataService.js +4 -4
- package/cjs/types/index.d.ts +11 -1
- package/esm/services/strategiesService.js +88 -62
- package/esm/services/subDataService.d.ts +2 -2
- package/esm/services/subDataService.js +4 -4
- package/esm/types/index.d.ts +11 -1
- package/package.json +1 -1
- package/src/services/strategiesService.ts +107 -84
- package/src/services/subDataService.ts +6 -6
- package/src/types/index.ts +14 -1
|
@@ -192,14 +192,17 @@ function parseAaveV3LeverageManagement(position, parseData) {
|
|
|
192
192
|
const { subStruct, subId, subHash } = parseData.subscriptionEventData;
|
|
193
193
|
const { isEnabled } = parseData.strategiesSubsData;
|
|
194
194
|
const triggerData = triggerService.aaveV3RatioTrigger.decode(subStruct.triggerData);
|
|
195
|
-
|
|
196
|
-
|
|
195
|
+
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
196
|
+
let subData;
|
|
197
|
+
if (isEOA) {
|
|
198
|
+
subData = subDataService.aaveV3LeverageManagementSubDataWithoutSubProxy.decode(subStruct.subData);
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
subData = subDataService.aaveV3LeverageManagementSubData.decode(subStruct.subData);
|
|
202
|
+
}
|
|
197
203
|
_position.strategyData.decoded.triggerData = triggerData;
|
|
198
204
|
_position.strategyData.decoded.subData = subData;
|
|
199
205
|
_position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, triggerData.market);
|
|
200
|
-
// TODO -> check if this change breaks something?
|
|
201
|
-
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
202
|
-
// TODO -> check if this change breaks something?
|
|
203
206
|
const isRepay = [enums_1.Strategies.Identifiers.Repay, enums_1.Strategies.Identifiers.EoaRepay].includes(_position.strategy.strategyId);
|
|
204
207
|
if (isRepay) {
|
|
205
208
|
_position.specific = {
|
|
@@ -207,8 +210,8 @@ function parseAaveV3LeverageManagement(position, parseData) {
|
|
|
207
210
|
targetRepayRatio: subData.targetRatio,
|
|
208
211
|
repayEnabled: true,
|
|
209
212
|
subId1: Number(subId),
|
|
213
|
+
mergeWithId: isEOA ? enums_1.Strategies.Identifiers.EoaBoost : enums_1.Strategies.Identifiers.EoaBoost,
|
|
210
214
|
subHashRepay: subHash,
|
|
211
|
-
mergeWithId: isEOA ? enums_1.Strategies.Identifiers.EoaBoost : enums_1.Strategies.Identifiers.Boost,
|
|
212
215
|
};
|
|
213
216
|
}
|
|
214
217
|
else {
|
|
@@ -217,11 +220,88 @@ function parseAaveV3LeverageManagement(position, parseData) {
|
|
|
217
220
|
targetBoostRatio: subData.targetRatio,
|
|
218
221
|
boostEnabled: isEnabled,
|
|
219
222
|
subId2: Number(subId),
|
|
220
|
-
subHashBoost: subHash,
|
|
221
223
|
mergeId: isEOA ? enums_1.Strategies.Identifiers.EoaBoost : enums_1.Strategies.Identifiers.Boost,
|
|
224
|
+
subHashBoost: subHash,
|
|
222
225
|
};
|
|
223
226
|
}
|
|
224
|
-
|
|
227
|
+
if (!isEOA) {
|
|
228
|
+
_position.strategy.strategyId = enums_1.Strategies.IdOverrides.LeverageManagement;
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
_position.strategy.strategyId = enums_1.Strategies.IdOverrides.EoaLeverageManagement;
|
|
232
|
+
}
|
|
233
|
+
return _position;
|
|
234
|
+
}
|
|
235
|
+
function parseAaveV3LeverageManagementOnPrice(position, parseData) {
|
|
236
|
+
const _position = (0, lodash_1.cloneDeep)(position);
|
|
237
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
238
|
+
const triggerData = triggerService.aaveV3QuotePriceTrigger.decode(subStruct.triggerData);
|
|
239
|
+
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
240
|
+
let subData;
|
|
241
|
+
if (isEOA) {
|
|
242
|
+
subData = subDataService.aaveV3LeverageManagementOnPriceGeneric.decode(subStruct.subData);
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
subData = subDataService.aaveV3LeverageManagementOnPriceSubData.decode(subStruct.subData);
|
|
246
|
+
}
|
|
247
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
248
|
+
_position.strategyData.decoded.subData = subData;
|
|
249
|
+
_position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, Math.random());
|
|
250
|
+
_position.specific = {
|
|
251
|
+
collAsset: subData.collAsset,
|
|
252
|
+
debtAsset: subData.debtAsset,
|
|
253
|
+
baseToken: triggerData.baseTokenAddress,
|
|
254
|
+
quoteToken: triggerData.quoteTokenAddress,
|
|
255
|
+
price: triggerData.price,
|
|
256
|
+
ratioState: triggerData.ratioState,
|
|
257
|
+
debtAssetId: subData.debtAssetId,
|
|
258
|
+
collAssetId: subData.collAssetId,
|
|
259
|
+
ratio: subData.targetRatio,
|
|
260
|
+
};
|
|
261
|
+
return _position;
|
|
262
|
+
}
|
|
263
|
+
function parseAaveV3CloseOnPrice(position, parseData) {
|
|
264
|
+
const _position = (0, lodash_1.cloneDeep)(position);
|
|
265
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
266
|
+
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
267
|
+
_position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, AAVE_V3_MARKET_ADDRESSES[_position.chainId]);
|
|
268
|
+
if (isEOA) {
|
|
269
|
+
const triggerData = triggerService.aaveV3QuotePriceRangeTrigger.decode(subStruct.triggerData);
|
|
270
|
+
const subData = subDataService.aaveV3CloseGenericSubData.decode(subStruct.subData);
|
|
271
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
272
|
+
_position.strategyData.decoded.subData = subData;
|
|
273
|
+
_position.specific = {
|
|
274
|
+
collAsset: subData.collAsset,
|
|
275
|
+
collAssetId: subData.collAssetId,
|
|
276
|
+
debtAsset: subData.debtAsset,
|
|
277
|
+
debtAssetId: subData.debtAssetId,
|
|
278
|
+
baseToken: triggerData.collToken,
|
|
279
|
+
quoteToken: triggerData.debtToken,
|
|
280
|
+
stopLossPrice: triggerData.lowerPrice,
|
|
281
|
+
takeProfitPrice: triggerData.upperPrice,
|
|
282
|
+
};
|
|
283
|
+
_position.strategy.strategyId = enums_1.Strategies.Identifiers.EoaCloseOnPrice;
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
286
|
+
const triggerData = triggerService.aaveV3QuotePriceTrigger.decode(subStruct.triggerData);
|
|
287
|
+
const subData = subDataService.aaveV3QuotePriceSubData.decode(subStruct.subData);
|
|
288
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
289
|
+
_position.strategyData.decoded.subData = subData;
|
|
290
|
+
_position.specific = {
|
|
291
|
+
collAsset: subData.collAsset,
|
|
292
|
+
collAssetId: subData.collAssetId,
|
|
293
|
+
debtAsset: subData.debtAsset,
|
|
294
|
+
debtAssetId: subData.debtAssetId,
|
|
295
|
+
baseToken: triggerData.baseTokenAddress,
|
|
296
|
+
quoteToken: triggerData.quoteTokenAddress,
|
|
297
|
+
price: triggerData.price,
|
|
298
|
+
ratioState: triggerData.ratioState,
|
|
299
|
+
};
|
|
300
|
+
const { ratioState } = (0, utils_1.getRatioStateInfoForAaveCloseStrategy)(_position.specific.ratioState, (0, utils_1.wethToEthByAddress)(_position.specific.collAsset, parseData.chainId), (0, utils_1.wethToEthByAddress)(_position.specific.debtAsset, parseData.chainId), parseData.chainId);
|
|
301
|
+
_position.strategy.strategyId = (0, utils_1.isRatioStateOver)(ratioState)
|
|
302
|
+
? enums_1.Strategies.IdOverrides.TakeProfit
|
|
303
|
+
: enums_1.Strategies.IdOverrides.StopLoss;
|
|
304
|
+
}
|
|
225
305
|
return _position;
|
|
226
306
|
}
|
|
227
307
|
function parseMorphoAaveV2LeverageManagement(position, parseData) {
|
|
@@ -255,36 +335,6 @@ function parseMorphoAaveV2LeverageManagement(position, parseData) {
|
|
|
255
335
|
_position.strategy.strategyId = enums_1.Strategies.IdOverrides.LeverageManagement;
|
|
256
336
|
return _position;
|
|
257
337
|
}
|
|
258
|
-
function parseAaveV3CloseOnPrice(position, parseData) {
|
|
259
|
-
const _position = (0, lodash_1.cloneDeep)(position);
|
|
260
|
-
const { subStruct } = parseData.subscriptionEventData;
|
|
261
|
-
// TODO -> should prob be quote price range trigger?
|
|
262
|
-
const triggerData = triggerService.aaveV3QuotePriceTrigger.decode(subStruct.triggerData);
|
|
263
|
-
// TODO -> should change this?
|
|
264
|
-
const subData = subDataService.aaveV3QuotePriceSubData.decode(subStruct.subData);
|
|
265
|
-
_position.strategyData.decoded.triggerData = triggerData;
|
|
266
|
-
_position.strategyData.decoded.subData = subData;
|
|
267
|
-
_position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, AAVE_V3_MARKET_ADDRESSES[_position.chainId]);
|
|
268
|
-
_position.specific = {
|
|
269
|
-
collAsset: subData.collAsset,
|
|
270
|
-
collAssetId: subData.collAssetId,
|
|
271
|
-
debtAsset: subData.debtAsset,
|
|
272
|
-
debtAssetId: subData.debtAssetId,
|
|
273
|
-
baseToken: triggerData.baseTokenAddress,
|
|
274
|
-
quoteToken: triggerData.quoteTokenAddress,
|
|
275
|
-
price: triggerData.price,
|
|
276
|
-
ratioState: triggerData.ratioState,
|
|
277
|
-
};
|
|
278
|
-
const { ratioState } = (0, utils_1.getRatioStateInfoForAaveCloseStrategy)(_position.specific.ratioState, (0, utils_1.wethToEthByAddress)(_position.specific.collAsset, parseData.chainId), (0, utils_1.wethToEthByAddress)(_position.specific.debtAsset, parseData.chainId), parseData.chainId);
|
|
279
|
-
// TODO -> Check if those changes break something?
|
|
280
|
-
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
281
|
-
_position.strategy.strategyId = isEOA
|
|
282
|
-
? enums_1.Strategies.Identifiers.EoaCloseOnPrice
|
|
283
|
-
: (_position.strategy.strategyId = (0, utils_1.isRatioStateOver)(ratioState)
|
|
284
|
-
? enums_1.Strategies.IdOverrides.TakeProfit
|
|
285
|
-
: enums_1.Strategies.IdOverrides.StopLoss);
|
|
286
|
-
return _position;
|
|
287
|
-
}
|
|
288
338
|
function parseAaveV3CloseOnPriceWithMaximumGasPrice(position, parseData) {
|
|
289
339
|
const _position = (0, lodash_1.cloneDeep)(position);
|
|
290
340
|
const { subStruct } = parseData.subscriptionEventData;
|
|
@@ -709,30 +759,6 @@ function parseMorphoBlueLeverageManagementOnPrice(position, parseData) {
|
|
|
709
759
|
};
|
|
710
760
|
return _position;
|
|
711
761
|
}
|
|
712
|
-
function parseAaveV3LeverageManagementOnPrice(position, parseData) {
|
|
713
|
-
const _position = (0, lodash_1.cloneDeep)(position);
|
|
714
|
-
const { subStruct } = parseData.subscriptionEventData;
|
|
715
|
-
const triggerData = triggerService.aaveV3QuotePriceTrigger.decode(subStruct.triggerData);
|
|
716
|
-
const subData = subDataService.aaveV3LeverageManagementOnPriceGeneric.decode(subStruct.subData);
|
|
717
|
-
_position.strategyData.decoded.triggerData = triggerData;
|
|
718
|
-
_position.strategyData.decoded.subData = subData;
|
|
719
|
-
_position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, Math.random());
|
|
720
|
-
_position.specific = {
|
|
721
|
-
collAsset: subData.collAsset,
|
|
722
|
-
debtAsset: subData.debtAsset,
|
|
723
|
-
baseToken: triggerData.baseTokenAddress,
|
|
724
|
-
quoteToken: triggerData.quoteTokenAddress,
|
|
725
|
-
price: triggerData.price,
|
|
726
|
-
ratioState: triggerData.ratioState,
|
|
727
|
-
debtAssetId: subData.debtAssetId,
|
|
728
|
-
collAssetId: subData.collAssetId,
|
|
729
|
-
ratio: subData.targetRatio,
|
|
730
|
-
};
|
|
731
|
-
// // TODO -> check if this change breaks something?
|
|
732
|
-
// const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
733
|
-
// _position.strategy.strategyId = isEOA ? Strategies.IdOverrides.EoaLeverageManagementOnPrice : Strategies.IdOverrides.LeverageManagementOnPrice;
|
|
734
|
-
return _position;
|
|
735
|
-
}
|
|
736
762
|
function parseLiquityV2CloseOnPrice(position, parseData) {
|
|
737
763
|
const _position = (0, lodash_1.cloneDeep)(position);
|
|
738
764
|
const { subStruct } = parseData.subscriptionEventData;
|
|
@@ -67,7 +67,7 @@ export declare const aaveV3LeverageManagementOnPriceGeneric: {
|
|
|
67
67
|
debtAssetId: number;
|
|
68
68
|
marketAddr: EthereumAddress;
|
|
69
69
|
targetRatio: number;
|
|
70
|
-
|
|
70
|
+
owner: EthereumAddress;
|
|
71
71
|
};
|
|
72
72
|
};
|
|
73
73
|
export declare const aaveV3CloseGenericSubData: {
|
|
@@ -79,7 +79,7 @@ export declare const aaveV3CloseGenericSubData: {
|
|
|
79
79
|
debtAssetId: number;
|
|
80
80
|
closeType: CloseStrategyType;
|
|
81
81
|
marketAddr: EthereumAddress;
|
|
82
|
-
|
|
82
|
+
owner: EthereumAddress;
|
|
83
83
|
};
|
|
84
84
|
};
|
|
85
85
|
export declare const aaveV3QuotePriceSubData: {
|
|
@@ -172,7 +172,7 @@ exports.aaveV3LeverageManagementOnPriceGeneric = {
|
|
|
172
172
|
const marketAddr = web3_eth_abi_1.default.decodeParameter('address', subData[4]);
|
|
173
173
|
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[5]);
|
|
174
174
|
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
175
|
-
const
|
|
175
|
+
const owner = web3_eth_abi_1.default.decodeParameter('address', subData[6]);
|
|
176
176
|
return {
|
|
177
177
|
collAsset,
|
|
178
178
|
collAssetId,
|
|
@@ -180,7 +180,7 @@ exports.aaveV3LeverageManagementOnPriceGeneric = {
|
|
|
180
180
|
debtAssetId,
|
|
181
181
|
marketAddr,
|
|
182
182
|
targetRatio,
|
|
183
|
-
|
|
183
|
+
owner,
|
|
184
184
|
};
|
|
185
185
|
},
|
|
186
186
|
};
|
|
@@ -210,9 +210,9 @@ exports.aaveV3CloseGenericSubData = {
|
|
|
210
210
|
const debtAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[3]));
|
|
211
211
|
const closeType = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[4]));
|
|
212
212
|
const marketAddr = web3_eth_abi_1.default.decodeParameter('address', subData[5]);
|
|
213
|
-
const
|
|
213
|
+
const owner = web3_eth_abi_1.default.decodeParameter('address', subData[6]);
|
|
214
214
|
return {
|
|
215
|
-
collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr,
|
|
215
|
+
collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr, owner,
|
|
216
216
|
};
|
|
217
217
|
},
|
|
218
218
|
};
|
package/cjs/types/index.d.ts
CHANGED
|
@@ -120,6 +120,16 @@ export declare namespace Position {
|
|
|
120
120
|
price: string;
|
|
121
121
|
ratioState: RatioState;
|
|
122
122
|
}
|
|
123
|
+
interface AaveV3CloseOnPriceGeneric extends Base {
|
|
124
|
+
collAsset: EthereumAddress;
|
|
125
|
+
collAssetId: number;
|
|
126
|
+
debtAsset: EthereumAddress;
|
|
127
|
+
debtAssetId: number;
|
|
128
|
+
baseToken: EthereumAddress;
|
|
129
|
+
quoteToken: EthereumAddress;
|
|
130
|
+
stopLossPrice: string;
|
|
131
|
+
takeProfitPrice: string;
|
|
132
|
+
}
|
|
123
133
|
interface BoostOnPriceAave extends CloseOnPriceAave {
|
|
124
134
|
ratio: number;
|
|
125
135
|
}
|
|
@@ -188,7 +198,7 @@ export declare namespace Position {
|
|
|
188
198
|
takeProfitType: CloseToAssetType | undefined;
|
|
189
199
|
}
|
|
190
200
|
}
|
|
191
|
-
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 | Specific.CompoundV3LeverageManagementOnPrice | Specific.CompoundV3CloseOnPrice;
|
|
201
|
+
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 | Specific.CompoundV3LeverageManagementOnPrice | Specific.CompoundV3CloseOnPrice | Specific.AaveV3CloseOnPriceGeneric;
|
|
192
202
|
interface Automated {
|
|
193
203
|
chainId: ChainId;
|
|
194
204
|
positionId: string;
|
|
@@ -163,14 +163,17 @@ function parseAaveV3LeverageManagement(position, parseData) {
|
|
|
163
163
|
const { subStruct, subId, subHash } = parseData.subscriptionEventData;
|
|
164
164
|
const { isEnabled } = parseData.strategiesSubsData;
|
|
165
165
|
const triggerData = triggerService.aaveV3RatioTrigger.decode(subStruct.triggerData);
|
|
166
|
-
|
|
167
|
-
|
|
166
|
+
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
167
|
+
let subData;
|
|
168
|
+
if (isEOA) {
|
|
169
|
+
subData = subDataService.aaveV3LeverageManagementSubDataWithoutSubProxy.decode(subStruct.subData);
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
subData = subDataService.aaveV3LeverageManagementSubData.decode(subStruct.subData);
|
|
173
|
+
}
|
|
168
174
|
_position.strategyData.decoded.triggerData = triggerData;
|
|
169
175
|
_position.strategyData.decoded.subData = subData;
|
|
170
176
|
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, triggerData.market);
|
|
171
|
-
// TODO -> check if this change breaks something?
|
|
172
|
-
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
173
|
-
// TODO -> check if this change breaks something?
|
|
174
177
|
const isRepay = [Strategies.Identifiers.Repay, Strategies.Identifiers.EoaRepay].includes(_position.strategy.strategyId);
|
|
175
178
|
if (isRepay) {
|
|
176
179
|
_position.specific = {
|
|
@@ -178,8 +181,8 @@ function parseAaveV3LeverageManagement(position, parseData) {
|
|
|
178
181
|
targetRepayRatio: subData.targetRatio,
|
|
179
182
|
repayEnabled: true,
|
|
180
183
|
subId1: Number(subId),
|
|
184
|
+
mergeWithId: isEOA ? Strategies.Identifiers.EoaBoost : Strategies.Identifiers.EoaBoost,
|
|
181
185
|
subHashRepay: subHash,
|
|
182
|
-
mergeWithId: isEOA ? Strategies.Identifiers.EoaBoost : Strategies.Identifiers.Boost,
|
|
183
186
|
};
|
|
184
187
|
}
|
|
185
188
|
else {
|
|
@@ -188,11 +191,88 @@ function parseAaveV3LeverageManagement(position, parseData) {
|
|
|
188
191
|
targetBoostRatio: subData.targetRatio,
|
|
189
192
|
boostEnabled: isEnabled,
|
|
190
193
|
subId2: Number(subId),
|
|
191
|
-
subHashBoost: subHash,
|
|
192
194
|
mergeId: isEOA ? Strategies.Identifiers.EoaBoost : Strategies.Identifiers.Boost,
|
|
195
|
+
subHashBoost: subHash,
|
|
193
196
|
};
|
|
194
197
|
}
|
|
195
|
-
|
|
198
|
+
if (!isEOA) {
|
|
199
|
+
_position.strategy.strategyId = Strategies.IdOverrides.LeverageManagement;
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
_position.strategy.strategyId = Strategies.IdOverrides.EoaLeverageManagement;
|
|
203
|
+
}
|
|
204
|
+
return _position;
|
|
205
|
+
}
|
|
206
|
+
function parseAaveV3LeverageManagementOnPrice(position, parseData) {
|
|
207
|
+
const _position = cloneDeep(position);
|
|
208
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
209
|
+
const triggerData = triggerService.aaveV3QuotePriceTrigger.decode(subStruct.triggerData);
|
|
210
|
+
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
211
|
+
let subData;
|
|
212
|
+
if (isEOA) {
|
|
213
|
+
subData = subDataService.aaveV3LeverageManagementOnPriceGeneric.decode(subStruct.subData);
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
subData = subDataService.aaveV3LeverageManagementOnPriceSubData.decode(subStruct.subData);
|
|
217
|
+
}
|
|
218
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
219
|
+
_position.strategyData.decoded.subData = subData;
|
|
220
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, Math.random());
|
|
221
|
+
_position.specific = {
|
|
222
|
+
collAsset: subData.collAsset,
|
|
223
|
+
debtAsset: subData.debtAsset,
|
|
224
|
+
baseToken: triggerData.baseTokenAddress,
|
|
225
|
+
quoteToken: triggerData.quoteTokenAddress,
|
|
226
|
+
price: triggerData.price,
|
|
227
|
+
ratioState: triggerData.ratioState,
|
|
228
|
+
debtAssetId: subData.debtAssetId,
|
|
229
|
+
collAssetId: subData.collAssetId,
|
|
230
|
+
ratio: subData.targetRatio,
|
|
231
|
+
};
|
|
232
|
+
return _position;
|
|
233
|
+
}
|
|
234
|
+
function parseAaveV3CloseOnPrice(position, parseData) {
|
|
235
|
+
const _position = cloneDeep(position);
|
|
236
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
237
|
+
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
238
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, AAVE_V3_MARKET_ADDRESSES[_position.chainId]);
|
|
239
|
+
if (isEOA) {
|
|
240
|
+
const triggerData = triggerService.aaveV3QuotePriceRangeTrigger.decode(subStruct.triggerData);
|
|
241
|
+
const subData = subDataService.aaveV3CloseGenericSubData.decode(subStruct.subData);
|
|
242
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
243
|
+
_position.strategyData.decoded.subData = subData;
|
|
244
|
+
_position.specific = {
|
|
245
|
+
collAsset: subData.collAsset,
|
|
246
|
+
collAssetId: subData.collAssetId,
|
|
247
|
+
debtAsset: subData.debtAsset,
|
|
248
|
+
debtAssetId: subData.debtAssetId,
|
|
249
|
+
baseToken: triggerData.collToken,
|
|
250
|
+
quoteToken: triggerData.debtToken,
|
|
251
|
+
stopLossPrice: triggerData.lowerPrice,
|
|
252
|
+
takeProfitPrice: triggerData.upperPrice,
|
|
253
|
+
};
|
|
254
|
+
_position.strategy.strategyId = Strategies.Identifiers.EoaCloseOnPrice;
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
const triggerData = triggerService.aaveV3QuotePriceTrigger.decode(subStruct.triggerData);
|
|
258
|
+
const subData = subDataService.aaveV3QuotePriceSubData.decode(subStruct.subData);
|
|
259
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
260
|
+
_position.strategyData.decoded.subData = subData;
|
|
261
|
+
_position.specific = {
|
|
262
|
+
collAsset: subData.collAsset,
|
|
263
|
+
collAssetId: subData.collAssetId,
|
|
264
|
+
debtAsset: subData.debtAsset,
|
|
265
|
+
debtAssetId: subData.debtAssetId,
|
|
266
|
+
baseToken: triggerData.baseTokenAddress,
|
|
267
|
+
quoteToken: triggerData.quoteTokenAddress,
|
|
268
|
+
price: triggerData.price,
|
|
269
|
+
ratioState: triggerData.ratioState,
|
|
270
|
+
};
|
|
271
|
+
const { ratioState } = getRatioStateInfoForAaveCloseStrategy(_position.specific.ratioState, wethToEthByAddress(_position.specific.collAsset, parseData.chainId), wethToEthByAddress(_position.specific.debtAsset, parseData.chainId), parseData.chainId);
|
|
272
|
+
_position.strategy.strategyId = isRatioStateOver(ratioState)
|
|
273
|
+
? Strategies.IdOverrides.TakeProfit
|
|
274
|
+
: Strategies.IdOverrides.StopLoss;
|
|
275
|
+
}
|
|
196
276
|
return _position;
|
|
197
277
|
}
|
|
198
278
|
function parseMorphoAaveV2LeverageManagement(position, parseData) {
|
|
@@ -226,36 +306,6 @@ function parseMorphoAaveV2LeverageManagement(position, parseData) {
|
|
|
226
306
|
_position.strategy.strategyId = Strategies.IdOverrides.LeverageManagement;
|
|
227
307
|
return _position;
|
|
228
308
|
}
|
|
229
|
-
function parseAaveV3CloseOnPrice(position, parseData) {
|
|
230
|
-
const _position = cloneDeep(position);
|
|
231
|
-
const { subStruct } = parseData.subscriptionEventData;
|
|
232
|
-
// TODO -> should prob be quote price range trigger?
|
|
233
|
-
const triggerData = triggerService.aaveV3QuotePriceTrigger.decode(subStruct.triggerData);
|
|
234
|
-
// TODO -> should change this?
|
|
235
|
-
const subData = subDataService.aaveV3QuotePriceSubData.decode(subStruct.subData);
|
|
236
|
-
_position.strategyData.decoded.triggerData = triggerData;
|
|
237
|
-
_position.strategyData.decoded.subData = subData;
|
|
238
|
-
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, AAVE_V3_MARKET_ADDRESSES[_position.chainId]);
|
|
239
|
-
_position.specific = {
|
|
240
|
-
collAsset: subData.collAsset,
|
|
241
|
-
collAssetId: subData.collAssetId,
|
|
242
|
-
debtAsset: subData.debtAsset,
|
|
243
|
-
debtAssetId: subData.debtAssetId,
|
|
244
|
-
baseToken: triggerData.baseTokenAddress,
|
|
245
|
-
quoteToken: triggerData.quoteTokenAddress,
|
|
246
|
-
price: triggerData.price,
|
|
247
|
-
ratioState: triggerData.ratioState,
|
|
248
|
-
};
|
|
249
|
-
const { ratioState } = getRatioStateInfoForAaveCloseStrategy(_position.specific.ratioState, wethToEthByAddress(_position.specific.collAsset, parseData.chainId), wethToEthByAddress(_position.specific.debtAsset, parseData.chainId), parseData.chainId);
|
|
250
|
-
// TODO -> Check if those changes break something?
|
|
251
|
-
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
252
|
-
_position.strategy.strategyId = isEOA
|
|
253
|
-
? Strategies.Identifiers.EoaCloseOnPrice
|
|
254
|
-
: (_position.strategy.strategyId = isRatioStateOver(ratioState)
|
|
255
|
-
? Strategies.IdOverrides.TakeProfit
|
|
256
|
-
: Strategies.IdOverrides.StopLoss);
|
|
257
|
-
return _position;
|
|
258
|
-
}
|
|
259
309
|
function parseAaveV3CloseOnPriceWithMaximumGasPrice(position, parseData) {
|
|
260
310
|
const _position = cloneDeep(position);
|
|
261
311
|
const { subStruct } = parseData.subscriptionEventData;
|
|
@@ -680,30 +730,6 @@ function parseMorphoBlueLeverageManagementOnPrice(position, parseData) {
|
|
|
680
730
|
};
|
|
681
731
|
return _position;
|
|
682
732
|
}
|
|
683
|
-
function parseAaveV3LeverageManagementOnPrice(position, parseData) {
|
|
684
|
-
const _position = cloneDeep(position);
|
|
685
|
-
const { subStruct } = parseData.subscriptionEventData;
|
|
686
|
-
const triggerData = triggerService.aaveV3QuotePriceTrigger.decode(subStruct.triggerData);
|
|
687
|
-
const subData = subDataService.aaveV3LeverageManagementOnPriceGeneric.decode(subStruct.subData);
|
|
688
|
-
_position.strategyData.decoded.triggerData = triggerData;
|
|
689
|
-
_position.strategyData.decoded.subData = subData;
|
|
690
|
-
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, Math.random());
|
|
691
|
-
_position.specific = {
|
|
692
|
-
collAsset: subData.collAsset,
|
|
693
|
-
debtAsset: subData.debtAsset,
|
|
694
|
-
baseToken: triggerData.baseTokenAddress,
|
|
695
|
-
quoteToken: triggerData.quoteTokenAddress,
|
|
696
|
-
price: triggerData.price,
|
|
697
|
-
ratioState: triggerData.ratioState,
|
|
698
|
-
debtAssetId: subData.debtAssetId,
|
|
699
|
-
collAssetId: subData.collAssetId,
|
|
700
|
-
ratio: subData.targetRatio,
|
|
701
|
-
};
|
|
702
|
-
// // TODO -> check if this change breaks something?
|
|
703
|
-
// const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
704
|
-
// _position.strategy.strategyId = isEOA ? Strategies.IdOverrides.EoaLeverageManagementOnPrice : Strategies.IdOverrides.LeverageManagementOnPrice;
|
|
705
|
-
return _position;
|
|
706
|
-
}
|
|
707
733
|
function parseLiquityV2CloseOnPrice(position, parseData) {
|
|
708
734
|
const _position = cloneDeep(position);
|
|
709
735
|
const { subStruct } = parseData.subscriptionEventData;
|
|
@@ -67,7 +67,7 @@ export declare const aaveV3LeverageManagementOnPriceGeneric: {
|
|
|
67
67
|
debtAssetId: number;
|
|
68
68
|
marketAddr: EthereumAddress;
|
|
69
69
|
targetRatio: number;
|
|
70
|
-
|
|
70
|
+
owner: EthereumAddress;
|
|
71
71
|
};
|
|
72
72
|
};
|
|
73
73
|
export declare const aaveV3CloseGenericSubData: {
|
|
@@ -79,7 +79,7 @@ export declare const aaveV3CloseGenericSubData: {
|
|
|
79
79
|
debtAssetId: number;
|
|
80
80
|
closeType: CloseStrategyType;
|
|
81
81
|
marketAddr: EthereumAddress;
|
|
82
|
-
|
|
82
|
+
owner: EthereumAddress;
|
|
83
83
|
};
|
|
84
84
|
};
|
|
85
85
|
export declare const aaveV3QuotePriceSubData: {
|
|
@@ -166,7 +166,7 @@ export const aaveV3LeverageManagementOnPriceGeneric = {
|
|
|
166
166
|
const marketAddr = AbiCoder.decodeParameter('address', subData[4]);
|
|
167
167
|
const weiRatio = AbiCoder.decodeParameter('uint256', subData[5]);
|
|
168
168
|
const targetRatio = weiToRatioPercentage(weiRatio);
|
|
169
|
-
const
|
|
169
|
+
const owner = AbiCoder.decodeParameter('address', subData[6]);
|
|
170
170
|
return {
|
|
171
171
|
collAsset,
|
|
172
172
|
collAssetId,
|
|
@@ -174,7 +174,7 @@ export const aaveV3LeverageManagementOnPriceGeneric = {
|
|
|
174
174
|
debtAssetId,
|
|
175
175
|
marketAddr,
|
|
176
176
|
targetRatio,
|
|
177
|
-
|
|
177
|
+
owner,
|
|
178
178
|
};
|
|
179
179
|
},
|
|
180
180
|
};
|
|
@@ -204,9 +204,9 @@ export const aaveV3CloseGenericSubData = {
|
|
|
204
204
|
const debtAssetId = Number(AbiCoder.decodeParameter('uint8', subData[3]));
|
|
205
205
|
const closeType = Number(AbiCoder.decodeParameter('uint8', subData[4]));
|
|
206
206
|
const marketAddr = AbiCoder.decodeParameter('address', subData[5]);
|
|
207
|
-
const
|
|
207
|
+
const owner = AbiCoder.decodeParameter('address', subData[6]);
|
|
208
208
|
return {
|
|
209
|
-
collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr,
|
|
209
|
+
collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr, owner,
|
|
210
210
|
};
|
|
211
211
|
},
|
|
212
212
|
};
|
package/esm/types/index.d.ts
CHANGED
|
@@ -120,6 +120,16 @@ export declare namespace Position {
|
|
|
120
120
|
price: string;
|
|
121
121
|
ratioState: RatioState;
|
|
122
122
|
}
|
|
123
|
+
interface AaveV3CloseOnPriceGeneric extends Base {
|
|
124
|
+
collAsset: EthereumAddress;
|
|
125
|
+
collAssetId: number;
|
|
126
|
+
debtAsset: EthereumAddress;
|
|
127
|
+
debtAssetId: number;
|
|
128
|
+
baseToken: EthereumAddress;
|
|
129
|
+
quoteToken: EthereumAddress;
|
|
130
|
+
stopLossPrice: string;
|
|
131
|
+
takeProfitPrice: string;
|
|
132
|
+
}
|
|
123
133
|
interface BoostOnPriceAave extends CloseOnPriceAave {
|
|
124
134
|
ratio: number;
|
|
125
135
|
}
|
|
@@ -188,7 +198,7 @@ export declare namespace Position {
|
|
|
188
198
|
takeProfitType: CloseToAssetType | undefined;
|
|
189
199
|
}
|
|
190
200
|
}
|
|
191
|
-
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 | Specific.CompoundV3LeverageManagementOnPrice | Specific.CompoundV3CloseOnPrice;
|
|
201
|
+
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 | Specific.CompoundV3LeverageManagementOnPrice | Specific.CompoundV3CloseOnPrice | Specific.AaveV3CloseOnPriceGeneric;
|
|
192
202
|
interface Automated {
|
|
193
203
|
chainId: ChainId;
|
|
194
204
|
positionId: string;
|
package/package.json
CHANGED
|
@@ -235,18 +235,19 @@ function parseAaveV3LeverageManagement(position: Position.Automated, parseData:
|
|
|
235
235
|
const { isEnabled } = parseData.strategiesSubsData;
|
|
236
236
|
|
|
237
237
|
const triggerData = triggerService.aaveV3RatioTrigger.decode(subStruct.triggerData);
|
|
238
|
-
|
|
239
|
-
|
|
238
|
+
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
239
|
+
let subData;
|
|
240
|
+
if (isEOA) {
|
|
241
|
+
subData = subDataService.aaveV3LeverageManagementSubDataWithoutSubProxy.decode(subStruct.subData);
|
|
242
|
+
} else {
|
|
243
|
+
subData = subDataService.aaveV3LeverageManagementSubData.decode(subStruct.subData);
|
|
244
|
+
}
|
|
240
245
|
|
|
241
246
|
_position.strategyData.decoded.triggerData = triggerData;
|
|
242
247
|
_position.strategyData.decoded.subData = subData;
|
|
243
248
|
|
|
244
249
|
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, triggerData.market);
|
|
245
250
|
|
|
246
|
-
// TODO -> check if this change breaks something?
|
|
247
|
-
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
248
|
-
|
|
249
|
-
// TODO -> check if this change breaks something?
|
|
250
251
|
const isRepay = [Strategies.Identifiers.Repay, Strategies.Identifiers.EoaRepay].includes(_position.strategy.strategyId as Strategies.Identifiers);
|
|
251
252
|
|
|
252
253
|
if (isRepay) {
|
|
@@ -255,8 +256,8 @@ function parseAaveV3LeverageManagement(position: Position.Automated, parseData:
|
|
|
255
256
|
targetRepayRatio: subData.targetRatio,
|
|
256
257
|
repayEnabled: true,
|
|
257
258
|
subId1: Number(subId),
|
|
259
|
+
mergeWithId: isEOA ? Strategies.Identifiers.EoaBoost : Strategies.Identifiers.EoaBoost,
|
|
258
260
|
subHashRepay: subHash,
|
|
259
|
-
mergeWithId: isEOA ? Strategies.Identifiers.EoaBoost : Strategies.Identifiers.Boost,
|
|
260
261
|
};
|
|
261
262
|
} else {
|
|
262
263
|
_position.specific = {
|
|
@@ -264,12 +265,109 @@ function parseAaveV3LeverageManagement(position: Position.Automated, parseData:
|
|
|
264
265
|
targetBoostRatio: subData.targetRatio,
|
|
265
266
|
boostEnabled: isEnabled,
|
|
266
267
|
subId2: Number(subId),
|
|
267
|
-
subHashBoost: subHash,
|
|
268
268
|
mergeId: isEOA ? Strategies.Identifiers.EoaBoost : Strategies.Identifiers.Boost,
|
|
269
|
+
subHashBoost: subHash,
|
|
269
270
|
};
|
|
270
271
|
}
|
|
272
|
+
if (!isEOA) {
|
|
273
|
+
_position.strategy.strategyId = Strategies.IdOverrides.LeverageManagement;
|
|
274
|
+
} else {
|
|
275
|
+
_position.strategy.strategyId = Strategies.IdOverrides.EoaLeverageManagement;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
return _position;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
function parseAaveV3LeverageManagementOnPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
282
|
+
const _position = cloneDeep(position);
|
|
283
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
284
|
+
|
|
285
|
+
const triggerData = triggerService.aaveV3QuotePriceTrigger.decode(subStruct.triggerData);
|
|
286
|
+
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
287
|
+
let subData;
|
|
288
|
+
if (isEOA) {
|
|
289
|
+
subData = subDataService.aaveV3LeverageManagementOnPriceGeneric.decode(subStruct.subData);
|
|
290
|
+
} else {
|
|
291
|
+
subData = subDataService.aaveV3LeverageManagementOnPriceSubData.decode(subStruct.subData);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
295
|
+
_position.strategyData.decoded.subData = subData;
|
|
296
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, Math.random());
|
|
297
|
+
|
|
298
|
+
_position.specific = {
|
|
299
|
+
collAsset: subData.collAsset,
|
|
300
|
+
debtAsset: subData.debtAsset,
|
|
301
|
+
baseToken: triggerData.baseTokenAddress,
|
|
302
|
+
quoteToken: triggerData.quoteTokenAddress,
|
|
303
|
+
price: triggerData.price,
|
|
304
|
+
ratioState: triggerData.ratioState,
|
|
305
|
+
debtAssetId: subData.debtAssetId,
|
|
306
|
+
collAssetId: subData.collAssetId,
|
|
307
|
+
ratio: subData.targetRatio,
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
return _position;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
function parseAaveV3CloseOnPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
314
|
+
const _position = cloneDeep(position);
|
|
315
|
+
|
|
316
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
317
|
+
|
|
318
|
+
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
319
|
+
|
|
320
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, AAVE_V3_MARKET_ADDRESSES[_position.chainId]);
|
|
321
|
+
|
|
322
|
+
if (isEOA) {
|
|
323
|
+
const triggerData = triggerService.aaveV3QuotePriceRangeTrigger.decode(subStruct.triggerData);
|
|
324
|
+
const subData = subDataService.aaveV3CloseGenericSubData.decode(subStruct.subData);
|
|
325
|
+
|
|
326
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
327
|
+
_position.strategyData.decoded.subData = subData;
|
|
328
|
+
|
|
329
|
+
_position.specific = {
|
|
330
|
+
collAsset: subData.collAsset,
|
|
331
|
+
collAssetId: subData.collAssetId,
|
|
332
|
+
debtAsset: subData.debtAsset,
|
|
333
|
+
debtAssetId: subData.debtAssetId,
|
|
334
|
+
baseToken: triggerData.collToken,
|
|
335
|
+
quoteToken: triggerData.debtToken,
|
|
336
|
+
stopLossPrice: triggerData.lowerPrice,
|
|
337
|
+
takeProfitPrice: triggerData.upperPrice,
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
_position.strategy.strategyId = Strategies.Identifiers.EoaCloseOnPrice;
|
|
341
|
+
} else {
|
|
342
|
+
const triggerData = triggerService.aaveV3QuotePriceTrigger.decode(subStruct.triggerData);
|
|
343
|
+
const subData = subDataService.aaveV3QuotePriceSubData.decode(subStruct.subData);
|
|
344
|
+
|
|
345
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
346
|
+
_position.strategyData.decoded.subData = subData;
|
|
347
|
+
|
|
348
|
+
_position.specific = {
|
|
349
|
+
collAsset: subData.collAsset,
|
|
350
|
+
collAssetId: subData.collAssetId,
|
|
351
|
+
debtAsset: subData.debtAsset,
|
|
352
|
+
debtAssetId: subData.debtAssetId,
|
|
353
|
+
baseToken: triggerData.baseTokenAddress,
|
|
354
|
+
quoteToken: triggerData.quoteTokenAddress,
|
|
355
|
+
price: triggerData.price,
|
|
356
|
+
ratioState: triggerData.ratioState,
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
const { ratioState } = getRatioStateInfoForAaveCloseStrategy(
|
|
360
|
+
_position.specific.ratioState,
|
|
361
|
+
wethToEthByAddress(_position.specific.collAsset, parseData.chainId),
|
|
362
|
+
wethToEthByAddress(_position.specific.debtAsset, parseData.chainId),
|
|
363
|
+
parseData.chainId,
|
|
364
|
+
);
|
|
365
|
+
|
|
366
|
+
_position.strategy.strategyId = isRatioStateOver(ratioState)
|
|
367
|
+
? Strategies.IdOverrides.TakeProfit
|
|
368
|
+
: Strategies.IdOverrides.StopLoss;
|
|
369
|
+
}
|
|
271
370
|
|
|
272
|
-
_position.strategy.strategyId = isEOA ? Strategies.IdOverrides.EoaLeverageManagement : Strategies.IdOverrides.LeverageManagement;
|
|
273
371
|
return _position;
|
|
274
372
|
}
|
|
275
373
|
|
|
@@ -312,50 +410,6 @@ function parseMorphoAaveV2LeverageManagement(position: Position.Automated, parse
|
|
|
312
410
|
return _position;
|
|
313
411
|
}
|
|
314
412
|
|
|
315
|
-
function parseAaveV3CloseOnPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
316
|
-
const _position = cloneDeep(position);
|
|
317
|
-
|
|
318
|
-
const { subStruct } = parseData.subscriptionEventData;
|
|
319
|
-
|
|
320
|
-
// TODO -> should prob be quote price range trigger?
|
|
321
|
-
const triggerData = triggerService.aaveV3QuotePriceTrigger.decode(subStruct.triggerData);
|
|
322
|
-
// TODO -> should change this?
|
|
323
|
-
const subData = subDataService.aaveV3QuotePriceSubData.decode(subStruct.subData);
|
|
324
|
-
|
|
325
|
-
_position.strategyData.decoded.triggerData = triggerData;
|
|
326
|
-
_position.strategyData.decoded.subData = subData;
|
|
327
|
-
|
|
328
|
-
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, AAVE_V3_MARKET_ADDRESSES[_position.chainId]);
|
|
329
|
-
|
|
330
|
-
_position.specific = {
|
|
331
|
-
collAsset: subData.collAsset,
|
|
332
|
-
collAssetId: subData.collAssetId,
|
|
333
|
-
debtAsset: subData.debtAsset,
|
|
334
|
-
debtAssetId: subData.debtAssetId,
|
|
335
|
-
baseToken: triggerData.baseTokenAddress,
|
|
336
|
-
quoteToken: triggerData.quoteTokenAddress,
|
|
337
|
-
price: triggerData.price,
|
|
338
|
-
ratioState: triggerData.ratioState,
|
|
339
|
-
};
|
|
340
|
-
|
|
341
|
-
const { ratioState } = getRatioStateInfoForAaveCloseStrategy(
|
|
342
|
-
_position.specific.ratioState,
|
|
343
|
-
wethToEthByAddress(_position.specific.collAsset, parseData.chainId),
|
|
344
|
-
wethToEthByAddress(_position.specific.debtAsset, parseData.chainId),
|
|
345
|
-
parseData.chainId,
|
|
346
|
-
);
|
|
347
|
-
|
|
348
|
-
// TODO -> Check if those changes break something?
|
|
349
|
-
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
350
|
-
_position.strategy.strategyId = isEOA
|
|
351
|
-
? Strategies.Identifiers.EoaCloseOnPrice
|
|
352
|
-
: (_position.strategy.strategyId = isRatioStateOver(ratioState)
|
|
353
|
-
? Strategies.IdOverrides.TakeProfit
|
|
354
|
-
: Strategies.IdOverrides.StopLoss);
|
|
355
|
-
|
|
356
|
-
return _position;
|
|
357
|
-
}
|
|
358
|
-
|
|
359
413
|
function parseAaveV3CloseOnPriceWithMaximumGasPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
360
414
|
const _position = cloneDeep(position);
|
|
361
415
|
|
|
@@ -929,37 +983,6 @@ function parseMorphoBlueLeverageManagementOnPrice(position: Position.Automated,
|
|
|
929
983
|
return _position;
|
|
930
984
|
}
|
|
931
985
|
|
|
932
|
-
function parseAaveV3LeverageManagementOnPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
933
|
-
const _position = cloneDeep(position);
|
|
934
|
-
|
|
935
|
-
const { subStruct } = parseData.subscriptionEventData;
|
|
936
|
-
|
|
937
|
-
const triggerData = triggerService.aaveV3QuotePriceTrigger.decode(subStruct.triggerData);
|
|
938
|
-
const subData = subDataService.aaveV3LeverageManagementOnPriceGeneric.decode(subStruct.subData);
|
|
939
|
-
|
|
940
|
-
_position.strategyData.decoded.triggerData = triggerData;
|
|
941
|
-
_position.strategyData.decoded.subData = subData;
|
|
942
|
-
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, Math.random());
|
|
943
|
-
|
|
944
|
-
_position.specific = {
|
|
945
|
-
collAsset: subData.collAsset,
|
|
946
|
-
debtAsset: subData.debtAsset,
|
|
947
|
-
baseToken: triggerData.baseTokenAddress,
|
|
948
|
-
quoteToken: triggerData.quoteTokenAddress,
|
|
949
|
-
price: triggerData.price,
|
|
950
|
-
ratioState: triggerData.ratioState,
|
|
951
|
-
debtAssetId: subData.debtAssetId,
|
|
952
|
-
collAssetId: subData.collAssetId,
|
|
953
|
-
ratio: subData.targetRatio,
|
|
954
|
-
};
|
|
955
|
-
|
|
956
|
-
// // TODO -> check if this change breaks something?
|
|
957
|
-
// const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
958
|
-
// _position.strategy.strategyId = isEOA ? Strategies.IdOverrides.EoaLeverageManagementOnPrice : Strategies.IdOverrides.LeverageManagementOnPrice;
|
|
959
|
-
|
|
960
|
-
return _position;
|
|
961
|
-
}
|
|
962
|
-
|
|
963
986
|
function parseLiquityV2CloseOnPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
964
987
|
const _position = cloneDeep(position);
|
|
965
988
|
|
|
@@ -236,7 +236,7 @@ export const aaveV3LeverageManagementOnPriceGeneric = {
|
|
|
236
236
|
debtAssetId: number,
|
|
237
237
|
marketAddr: EthereumAddress,
|
|
238
238
|
targetRatio: number,
|
|
239
|
-
|
|
239
|
+
owner: EthereumAddress,
|
|
240
240
|
} {
|
|
241
241
|
const collAsset = AbiCoder.decodeParameter('address', subData[0]) as unknown as EthereumAddress;
|
|
242
242
|
const collAssetId = Number(AbiCoder.decodeParameter('uint8', subData[1]));
|
|
@@ -247,7 +247,7 @@ export const aaveV3LeverageManagementOnPriceGeneric = {
|
|
|
247
247
|
const weiRatio = AbiCoder.decodeParameter('uint256', subData[5]) as unknown as string;
|
|
248
248
|
const targetRatio = weiToRatioPercentage(weiRatio);
|
|
249
249
|
|
|
250
|
-
const
|
|
250
|
+
const owner = AbiCoder.decodeParameter('address', subData[6]) as unknown as EthereumAddress;
|
|
251
251
|
|
|
252
252
|
return {
|
|
253
253
|
collAsset,
|
|
@@ -256,7 +256,7 @@ export const aaveV3LeverageManagementOnPriceGeneric = {
|
|
|
256
256
|
debtAssetId,
|
|
257
257
|
marketAddr,
|
|
258
258
|
targetRatio,
|
|
259
|
-
|
|
259
|
+
owner,
|
|
260
260
|
};
|
|
261
261
|
},
|
|
262
262
|
};
|
|
@@ -297,7 +297,7 @@ export const aaveV3CloseGenericSubData = {
|
|
|
297
297
|
debtAssetId: number,
|
|
298
298
|
closeType: CloseStrategyType,
|
|
299
299
|
marketAddr: EthereumAddress,
|
|
300
|
-
|
|
300
|
+
owner: EthereumAddress,
|
|
301
301
|
} {
|
|
302
302
|
const collAsset = AbiCoder.decodeParameter('address', subData[0]) as unknown as EthereumAddress;
|
|
303
303
|
const collAssetId = Number(AbiCoder.decodeParameter('uint8', subData[1]));
|
|
@@ -305,10 +305,10 @@ export const aaveV3CloseGenericSubData = {
|
|
|
305
305
|
const debtAssetId = Number(AbiCoder.decodeParameter('uint8', subData[3]));
|
|
306
306
|
const closeType = Number(AbiCoder.decodeParameter('uint8', subData[4])) as CloseStrategyType;
|
|
307
307
|
const marketAddr = AbiCoder.decodeParameter('address', subData[5]) as unknown as EthereumAddress;
|
|
308
|
-
const
|
|
308
|
+
const owner = AbiCoder.decodeParameter('address', subData[6]) as unknown as EthereumAddress;
|
|
309
309
|
|
|
310
310
|
return {
|
|
311
|
-
collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr,
|
|
311
|
+
collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr, owner,
|
|
312
312
|
};
|
|
313
313
|
},
|
|
314
314
|
};
|
package/src/types/index.ts
CHANGED
|
@@ -166,6 +166,18 @@ export declare namespace Position {
|
|
|
166
166
|
price: string,
|
|
167
167
|
ratioState: RatioState,
|
|
168
168
|
}
|
|
169
|
+
|
|
170
|
+
interface AaveV3CloseOnPriceGeneric extends Base {
|
|
171
|
+
collAsset: EthereumAddress,
|
|
172
|
+
collAssetId: number,
|
|
173
|
+
debtAsset: EthereumAddress,
|
|
174
|
+
debtAssetId: number,
|
|
175
|
+
baseToken: EthereumAddress,
|
|
176
|
+
quoteToken: EthereumAddress,
|
|
177
|
+
stopLossPrice: string,
|
|
178
|
+
takeProfitPrice: string,
|
|
179
|
+
}
|
|
180
|
+
|
|
169
181
|
interface BoostOnPriceAave extends CloseOnPriceAave {
|
|
170
182
|
ratio: number,
|
|
171
183
|
}
|
|
@@ -260,7 +272,8 @@ export declare namespace Position {
|
|
|
260
272
|
| Specific.BoostOnPriceLiquityV2
|
|
261
273
|
| Specific.PaybackLiquityV2
|
|
262
274
|
| Specific.CompoundV3LeverageManagementOnPrice
|
|
263
|
-
| Specific.CompoundV3CloseOnPrice
|
|
275
|
+
| Specific.CompoundV3CloseOnPrice
|
|
276
|
+
| Specific.AaveV3CloseOnPriceGeneric;
|
|
264
277
|
|
|
265
278
|
export interface Automated {
|
|
266
279
|
chainId: ChainId,
|