@defisaver/automation-sdk 3.3.2-dev.0 → 3.3.2-dev.10
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 +92 -60
- 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 +92 -60
- 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 +2 -2
- package/src/services/strategiesService.ts +112 -82
- package/src/services/subDataService.ts +6 -6
- package/src/types/index.ts +14 -1
|
@@ -192,22 +192,26 @@ 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
|
-
const
|
|
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
|
+
}
|
|
196
203
|
_position.strategyData.decoded.triggerData = triggerData;
|
|
197
204
|
_position.strategyData.decoded.subData = subData;
|
|
198
205
|
_position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, triggerData.market);
|
|
199
|
-
// TODO -> check if this change breaks something?
|
|
200
|
-
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
201
|
-
// TODO -> check if this change breaks something?
|
|
202
206
|
const isRepay = [enums_1.Strategies.Identifiers.Repay, enums_1.Strategies.Identifiers.EoaRepay].includes(_position.strategy.strategyId);
|
|
203
207
|
if (isRepay) {
|
|
204
208
|
_position.specific = {
|
|
205
209
|
triggerRepayRatio: triggerData.ratio,
|
|
206
210
|
targetRepayRatio: subData.targetRatio,
|
|
207
|
-
repayEnabled:
|
|
211
|
+
repayEnabled: isEnabled,
|
|
208
212
|
subId1: Number(subId),
|
|
209
|
-
subHashRepay: subHash,
|
|
210
213
|
mergeWithId: isEOA ? enums_1.Strategies.Identifiers.EoaBoost : enums_1.Strategies.Identifiers.Boost,
|
|
214
|
+
subHashRepay: subHash,
|
|
211
215
|
};
|
|
212
216
|
}
|
|
213
217
|
else {
|
|
@@ -216,11 +220,91 @@ function parseAaveV3LeverageManagement(position, parseData) {
|
|
|
216
220
|
targetBoostRatio: subData.targetRatio,
|
|
217
221
|
boostEnabled: isEnabled,
|
|
218
222
|
subId2: Number(subId),
|
|
219
|
-
subHashBoost: subHash,
|
|
220
223
|
mergeId: isEOA ? enums_1.Strategies.Identifiers.EoaBoost : enums_1.Strategies.Identifiers.Boost,
|
|
224
|
+
subHashBoost: subHash,
|
|
221
225
|
};
|
|
222
226
|
}
|
|
223
|
-
|
|
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
|
+
const { takeProfitType, stopLossType } = (0, utils_1.getStopLossAndTakeProfitTypeByCloseStrategyType)(+subData.closeType);
|
|
272
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
273
|
+
_position.strategyData.decoded.subData = subData;
|
|
274
|
+
_position.specific = {
|
|
275
|
+
collAsset: subData.collAsset,
|
|
276
|
+
collAssetId: subData.collAssetId,
|
|
277
|
+
debtAsset: subData.debtAsset,
|
|
278
|
+
debtAssetId: subData.debtAssetId,
|
|
279
|
+
baseToken: triggerData.collToken,
|
|
280
|
+
quoteToken: triggerData.debtToken,
|
|
281
|
+
stopLossPrice: triggerData.lowerPrice,
|
|
282
|
+
takeProfitPrice: triggerData.upperPrice,
|
|
283
|
+
stopLossType,
|
|
284
|
+
takeProfitType,
|
|
285
|
+
};
|
|
286
|
+
_position.strategy.strategyId = enums_1.Strategies.Identifiers.EoaCloseOnPrice;
|
|
287
|
+
}
|
|
288
|
+
else {
|
|
289
|
+
const triggerData = triggerService.aaveV3QuotePriceTrigger.decode(subStruct.triggerData);
|
|
290
|
+
const subData = subDataService.aaveV3QuotePriceSubData.decode(subStruct.subData);
|
|
291
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
292
|
+
_position.strategyData.decoded.subData = subData;
|
|
293
|
+
_position.specific = {
|
|
294
|
+
collAsset: subData.collAsset,
|
|
295
|
+
collAssetId: subData.collAssetId,
|
|
296
|
+
debtAsset: subData.debtAsset,
|
|
297
|
+
debtAssetId: subData.debtAssetId,
|
|
298
|
+
baseToken: triggerData.baseTokenAddress,
|
|
299
|
+
quoteToken: triggerData.quoteTokenAddress,
|
|
300
|
+
price: triggerData.price,
|
|
301
|
+
ratioState: triggerData.ratioState,
|
|
302
|
+
};
|
|
303
|
+
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);
|
|
304
|
+
_position.strategy.strategyId = (0, utils_1.isRatioStateOver)(ratioState)
|
|
305
|
+
? enums_1.Strategies.IdOverrides.TakeProfit
|
|
306
|
+
: enums_1.Strategies.IdOverrides.StopLoss;
|
|
307
|
+
}
|
|
224
308
|
return _position;
|
|
225
309
|
}
|
|
226
310
|
function parseMorphoAaveV2LeverageManagement(position, parseData) {
|
|
@@ -254,34 +338,6 @@ function parseMorphoAaveV2LeverageManagement(position, parseData) {
|
|
|
254
338
|
_position.strategy.strategyId = enums_1.Strategies.IdOverrides.LeverageManagement;
|
|
255
339
|
return _position;
|
|
256
340
|
}
|
|
257
|
-
function parseAaveV3CloseOnPrice(position, parseData) {
|
|
258
|
-
const _position = (0, lodash_1.cloneDeep)(position);
|
|
259
|
-
const { subStruct } = parseData.subscriptionEventData;
|
|
260
|
-
const triggerData = triggerService.aaveV3QuotePriceTrigger.decode(subStruct.triggerData);
|
|
261
|
-
const subData = subDataService.aaveV3QuotePriceSubData.decode(subStruct.subData);
|
|
262
|
-
_position.strategyData.decoded.triggerData = triggerData;
|
|
263
|
-
_position.strategyData.decoded.subData = subData;
|
|
264
|
-
_position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, AAVE_V3_MARKET_ADDRESSES[_position.chainId]);
|
|
265
|
-
_position.specific = {
|
|
266
|
-
collAsset: subData.collAsset,
|
|
267
|
-
collAssetId: subData.collAssetId,
|
|
268
|
-
debtAsset: subData.debtAsset,
|
|
269
|
-
debtAssetId: subData.debtAssetId,
|
|
270
|
-
baseToken: triggerData.baseTokenAddress,
|
|
271
|
-
quoteToken: triggerData.quoteTokenAddress,
|
|
272
|
-
price: triggerData.price,
|
|
273
|
-
ratioState: triggerData.ratioState,
|
|
274
|
-
};
|
|
275
|
-
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);
|
|
276
|
-
// TODO -> Check if those changes break something?
|
|
277
|
-
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
278
|
-
_position.strategy.strategyId = isEOA
|
|
279
|
-
? enums_1.Strategies.Identifiers.EoaCloseOnPrice
|
|
280
|
-
: (_position.strategy.strategyId = (0, utils_1.isRatioStateOver)(ratioState)
|
|
281
|
-
? enums_1.Strategies.IdOverrides.TakeProfit
|
|
282
|
-
: enums_1.Strategies.IdOverrides.StopLoss);
|
|
283
|
-
return _position;
|
|
284
|
-
}
|
|
285
341
|
function parseAaveV3CloseOnPriceWithMaximumGasPrice(position, parseData) {
|
|
286
342
|
const _position = (0, lodash_1.cloneDeep)(position);
|
|
287
343
|
const { subStruct } = parseData.subscriptionEventData;
|
|
@@ -706,30 +762,6 @@ function parseMorphoBlueLeverageManagementOnPrice(position, parseData) {
|
|
|
706
762
|
};
|
|
707
763
|
return _position;
|
|
708
764
|
}
|
|
709
|
-
function parseAaveV3LeverageManagementOnPrice(position, parseData) {
|
|
710
|
-
const _position = (0, lodash_1.cloneDeep)(position);
|
|
711
|
-
const { subStruct } = parseData.subscriptionEventData;
|
|
712
|
-
const triggerData = triggerService.aaveV3QuotePriceTrigger.decode(subStruct.triggerData);
|
|
713
|
-
const subData = subDataService.aaveV3LeverageManagementOnPriceSubData.decode(subStruct.subData);
|
|
714
|
-
_position.strategyData.decoded.triggerData = triggerData;
|
|
715
|
-
_position.strategyData.decoded.subData = subData;
|
|
716
|
-
_position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, Math.random());
|
|
717
|
-
_position.specific = {
|
|
718
|
-
collAsset: subData.collAsset,
|
|
719
|
-
debtAsset: subData.debtAsset,
|
|
720
|
-
baseToken: triggerData.baseTokenAddress,
|
|
721
|
-
quoteToken: triggerData.quoteTokenAddress,
|
|
722
|
-
price: triggerData.price,
|
|
723
|
-
ratioState: triggerData.ratioState,
|
|
724
|
-
debtAssetId: subData.debtAssetId,
|
|
725
|
-
collAssetId: subData.collAssetId,
|
|
726
|
-
ratio: subData.targetRatio,
|
|
727
|
-
};
|
|
728
|
-
// TODO -> check if this change breaks something?
|
|
729
|
-
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
730
|
-
_position.strategy.strategyId = isEOA ? enums_1.Strategies.IdOverrides.EoaLeverageManagementOnPrice : enums_1.Strategies.IdOverrides.LeverageManagementOnPrice;
|
|
731
|
-
return _position;
|
|
732
|
-
}
|
|
733
765
|
function parseLiquityV2CloseOnPrice(position, parseData) {
|
|
734
766
|
const _position = (0, lodash_1.cloneDeep)(position);
|
|
735
767
|
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,22 +163,26 @@ 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
|
-
const
|
|
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
|
+
}
|
|
167
174
|
_position.strategyData.decoded.triggerData = triggerData;
|
|
168
175
|
_position.strategyData.decoded.subData = subData;
|
|
169
176
|
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, triggerData.market);
|
|
170
|
-
// TODO -> check if this change breaks something?
|
|
171
|
-
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
172
|
-
// TODO -> check if this change breaks something?
|
|
173
177
|
const isRepay = [Strategies.Identifiers.Repay, Strategies.Identifiers.EoaRepay].includes(_position.strategy.strategyId);
|
|
174
178
|
if (isRepay) {
|
|
175
179
|
_position.specific = {
|
|
176
180
|
triggerRepayRatio: triggerData.ratio,
|
|
177
181
|
targetRepayRatio: subData.targetRatio,
|
|
178
|
-
repayEnabled:
|
|
182
|
+
repayEnabled: isEnabled,
|
|
179
183
|
subId1: Number(subId),
|
|
180
|
-
subHashRepay: subHash,
|
|
181
184
|
mergeWithId: isEOA ? Strategies.Identifiers.EoaBoost : Strategies.Identifiers.Boost,
|
|
185
|
+
subHashRepay: subHash,
|
|
182
186
|
};
|
|
183
187
|
}
|
|
184
188
|
else {
|
|
@@ -187,11 +191,91 @@ function parseAaveV3LeverageManagement(position, parseData) {
|
|
|
187
191
|
targetBoostRatio: subData.targetRatio,
|
|
188
192
|
boostEnabled: isEnabled,
|
|
189
193
|
subId2: Number(subId),
|
|
190
|
-
subHashBoost: subHash,
|
|
191
194
|
mergeId: isEOA ? Strategies.Identifiers.EoaBoost : Strategies.Identifiers.Boost,
|
|
195
|
+
subHashBoost: subHash,
|
|
192
196
|
};
|
|
193
197
|
}
|
|
194
|
-
|
|
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
|
+
const { takeProfitType, stopLossType } = getStopLossAndTakeProfitTypeByCloseStrategyType(+subData.closeType);
|
|
243
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
244
|
+
_position.strategyData.decoded.subData = subData;
|
|
245
|
+
_position.specific = {
|
|
246
|
+
collAsset: subData.collAsset,
|
|
247
|
+
collAssetId: subData.collAssetId,
|
|
248
|
+
debtAsset: subData.debtAsset,
|
|
249
|
+
debtAssetId: subData.debtAssetId,
|
|
250
|
+
baseToken: triggerData.collToken,
|
|
251
|
+
quoteToken: triggerData.debtToken,
|
|
252
|
+
stopLossPrice: triggerData.lowerPrice,
|
|
253
|
+
takeProfitPrice: triggerData.upperPrice,
|
|
254
|
+
stopLossType,
|
|
255
|
+
takeProfitType,
|
|
256
|
+
};
|
|
257
|
+
_position.strategy.strategyId = Strategies.Identifiers.EoaCloseOnPrice;
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
const triggerData = triggerService.aaveV3QuotePriceTrigger.decode(subStruct.triggerData);
|
|
261
|
+
const subData = subDataService.aaveV3QuotePriceSubData.decode(subStruct.subData);
|
|
262
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
263
|
+
_position.strategyData.decoded.subData = subData;
|
|
264
|
+
_position.specific = {
|
|
265
|
+
collAsset: subData.collAsset,
|
|
266
|
+
collAssetId: subData.collAssetId,
|
|
267
|
+
debtAsset: subData.debtAsset,
|
|
268
|
+
debtAssetId: subData.debtAssetId,
|
|
269
|
+
baseToken: triggerData.baseTokenAddress,
|
|
270
|
+
quoteToken: triggerData.quoteTokenAddress,
|
|
271
|
+
price: triggerData.price,
|
|
272
|
+
ratioState: triggerData.ratioState,
|
|
273
|
+
};
|
|
274
|
+
const { ratioState } = getRatioStateInfoForAaveCloseStrategy(_position.specific.ratioState, wethToEthByAddress(_position.specific.collAsset, parseData.chainId), wethToEthByAddress(_position.specific.debtAsset, parseData.chainId), parseData.chainId);
|
|
275
|
+
_position.strategy.strategyId = isRatioStateOver(ratioState)
|
|
276
|
+
? Strategies.IdOverrides.TakeProfit
|
|
277
|
+
: Strategies.IdOverrides.StopLoss;
|
|
278
|
+
}
|
|
195
279
|
return _position;
|
|
196
280
|
}
|
|
197
281
|
function parseMorphoAaveV2LeverageManagement(position, parseData) {
|
|
@@ -225,34 +309,6 @@ function parseMorphoAaveV2LeverageManagement(position, parseData) {
|
|
|
225
309
|
_position.strategy.strategyId = Strategies.IdOverrides.LeverageManagement;
|
|
226
310
|
return _position;
|
|
227
311
|
}
|
|
228
|
-
function parseAaveV3CloseOnPrice(position, parseData) {
|
|
229
|
-
const _position = cloneDeep(position);
|
|
230
|
-
const { subStruct } = parseData.subscriptionEventData;
|
|
231
|
-
const triggerData = triggerService.aaveV3QuotePriceTrigger.decode(subStruct.triggerData);
|
|
232
|
-
const subData = subDataService.aaveV3QuotePriceSubData.decode(subStruct.subData);
|
|
233
|
-
_position.strategyData.decoded.triggerData = triggerData;
|
|
234
|
-
_position.strategyData.decoded.subData = subData;
|
|
235
|
-
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, AAVE_V3_MARKET_ADDRESSES[_position.chainId]);
|
|
236
|
-
_position.specific = {
|
|
237
|
-
collAsset: subData.collAsset,
|
|
238
|
-
collAssetId: subData.collAssetId,
|
|
239
|
-
debtAsset: subData.debtAsset,
|
|
240
|
-
debtAssetId: subData.debtAssetId,
|
|
241
|
-
baseToken: triggerData.baseTokenAddress,
|
|
242
|
-
quoteToken: triggerData.quoteTokenAddress,
|
|
243
|
-
price: triggerData.price,
|
|
244
|
-
ratioState: triggerData.ratioState,
|
|
245
|
-
};
|
|
246
|
-
const { ratioState } = getRatioStateInfoForAaveCloseStrategy(_position.specific.ratioState, wethToEthByAddress(_position.specific.collAsset, parseData.chainId), wethToEthByAddress(_position.specific.debtAsset, parseData.chainId), parseData.chainId);
|
|
247
|
-
// TODO -> Check if those changes break something?
|
|
248
|
-
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
249
|
-
_position.strategy.strategyId = isEOA
|
|
250
|
-
? Strategies.Identifiers.EoaCloseOnPrice
|
|
251
|
-
: (_position.strategy.strategyId = isRatioStateOver(ratioState)
|
|
252
|
-
? Strategies.IdOverrides.TakeProfit
|
|
253
|
-
: Strategies.IdOverrides.StopLoss);
|
|
254
|
-
return _position;
|
|
255
|
-
}
|
|
256
312
|
function parseAaveV3CloseOnPriceWithMaximumGasPrice(position, parseData) {
|
|
257
313
|
const _position = cloneDeep(position);
|
|
258
314
|
const { subStruct } = parseData.subscriptionEventData;
|
|
@@ -677,30 +733,6 @@ function parseMorphoBlueLeverageManagementOnPrice(position, parseData) {
|
|
|
677
733
|
};
|
|
678
734
|
return _position;
|
|
679
735
|
}
|
|
680
|
-
function parseAaveV3LeverageManagementOnPrice(position, parseData) {
|
|
681
|
-
const _position = cloneDeep(position);
|
|
682
|
-
const { subStruct } = parseData.subscriptionEventData;
|
|
683
|
-
const triggerData = triggerService.aaveV3QuotePriceTrigger.decode(subStruct.triggerData);
|
|
684
|
-
const subData = subDataService.aaveV3LeverageManagementOnPriceSubData.decode(subStruct.subData);
|
|
685
|
-
_position.strategyData.decoded.triggerData = triggerData;
|
|
686
|
-
_position.strategyData.decoded.subData = subData;
|
|
687
|
-
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, Math.random());
|
|
688
|
-
_position.specific = {
|
|
689
|
-
collAsset: subData.collAsset,
|
|
690
|
-
debtAsset: subData.debtAsset,
|
|
691
|
-
baseToken: triggerData.baseTokenAddress,
|
|
692
|
-
quoteToken: triggerData.quoteTokenAddress,
|
|
693
|
-
price: triggerData.price,
|
|
694
|
-
ratioState: triggerData.ratioState,
|
|
695
|
-
debtAssetId: subData.debtAssetId,
|
|
696
|
-
collAssetId: subData.collAssetId,
|
|
697
|
-
ratio: subData.targetRatio,
|
|
698
|
-
};
|
|
699
|
-
// TODO -> check if this change breaks something?
|
|
700
|
-
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
701
|
-
_position.strategy.strategyId = isEOA ? Strategies.IdOverrides.EoaLeverageManagementOnPrice : Strategies.IdOverrides.LeverageManagementOnPrice;
|
|
702
|
-
return _position;
|
|
703
|
-
}
|
|
704
736
|
function parseLiquityV2CloseOnPrice(position, parseData) {
|
|
705
737
|
const _position = cloneDeep(position);
|
|
706
738
|
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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defisaver/automation-sdk",
|
|
3
|
-
"version": "3.3.2-dev.
|
|
3
|
+
"version": "3.3.2-dev.10",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./cjs/index.js",
|
|
6
6
|
"module": "./esm/index.js",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"repository": "https://github.com/defisaver/automation-sdk",
|
|
24
24
|
"license": "ISC",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@defisaver/sdk": "
|
|
26
|
+
"@defisaver/sdk": "1.3.6-dev.3",
|
|
27
27
|
"@defisaver/tokens": "^1.6.19",
|
|
28
28
|
"@ethersproject/address": "^5.0.10",
|
|
29
29
|
"@ethersproject/solidity": "^5.0.9",
|
|
@@ -235,27 +235,29 @@ function parseAaveV3LeverageManagement(position: Position.Automated, parseData:
|
|
|
235
235
|
const { isEnabled } = parseData.strategiesSubsData;
|
|
236
236
|
|
|
237
237
|
const triggerData = triggerService.aaveV3RatioTrigger.decode(subStruct.triggerData);
|
|
238
|
-
const
|
|
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
|
+
}
|
|
239
245
|
|
|
240
246
|
_position.strategyData.decoded.triggerData = triggerData;
|
|
241
247
|
_position.strategyData.decoded.subData = subData;
|
|
242
248
|
|
|
243
249
|
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, triggerData.market);
|
|
244
250
|
|
|
245
|
-
// TODO -> check if this change breaks something?
|
|
246
|
-
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
247
|
-
|
|
248
|
-
// TODO -> check if this change breaks something?
|
|
249
251
|
const isRepay = [Strategies.Identifiers.Repay, Strategies.Identifiers.EoaRepay].includes(_position.strategy.strategyId as Strategies.Identifiers);
|
|
250
252
|
|
|
251
253
|
if (isRepay) {
|
|
252
254
|
_position.specific = {
|
|
253
255
|
triggerRepayRatio: triggerData.ratio,
|
|
254
256
|
targetRepayRatio: subData.targetRatio,
|
|
255
|
-
repayEnabled:
|
|
257
|
+
repayEnabled: isEnabled,
|
|
256
258
|
subId1: Number(subId),
|
|
257
|
-
subHashRepay: subHash,
|
|
258
259
|
mergeWithId: isEOA ? Strategies.Identifiers.EoaBoost : Strategies.Identifiers.Boost,
|
|
260
|
+
subHashRepay: subHash,
|
|
259
261
|
};
|
|
260
262
|
} else {
|
|
261
263
|
_position.specific = {
|
|
@@ -263,12 +265,113 @@ function parseAaveV3LeverageManagement(position: Position.Automated, parseData:
|
|
|
263
265
|
targetBoostRatio: subData.targetRatio,
|
|
264
266
|
boostEnabled: isEnabled,
|
|
265
267
|
subId2: Number(subId),
|
|
266
|
-
subHashBoost: subHash,
|
|
267
268
|
mergeId: isEOA ? Strategies.Identifiers.EoaBoost : Strategies.Identifiers.Boost,
|
|
269
|
+
subHashBoost: subHash,
|
|
268
270
|
};
|
|
269
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
|
+
const { takeProfitType, stopLossType } = getStopLossAndTakeProfitTypeByCloseStrategyType(+subData.closeType);
|
|
327
|
+
|
|
328
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
329
|
+
_position.strategyData.decoded.subData = subData;
|
|
330
|
+
|
|
331
|
+
_position.specific = {
|
|
332
|
+
collAsset: subData.collAsset,
|
|
333
|
+
collAssetId: subData.collAssetId,
|
|
334
|
+
debtAsset: subData.debtAsset,
|
|
335
|
+
debtAssetId: subData.debtAssetId,
|
|
336
|
+
baseToken: triggerData.collToken,
|
|
337
|
+
quoteToken: triggerData.debtToken,
|
|
338
|
+
stopLossPrice: triggerData.lowerPrice,
|
|
339
|
+
takeProfitPrice: triggerData.upperPrice,
|
|
340
|
+
stopLossType,
|
|
341
|
+
takeProfitType,
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
_position.strategy.strategyId = Strategies.Identifiers.EoaCloseOnPrice;
|
|
345
|
+
} else {
|
|
346
|
+
const triggerData = triggerService.aaveV3QuotePriceTrigger.decode(subStruct.triggerData);
|
|
347
|
+
const subData = subDataService.aaveV3QuotePriceSubData.decode(subStruct.subData);
|
|
348
|
+
|
|
349
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
350
|
+
_position.strategyData.decoded.subData = subData;
|
|
351
|
+
|
|
352
|
+
_position.specific = {
|
|
353
|
+
collAsset: subData.collAsset,
|
|
354
|
+
collAssetId: subData.collAssetId,
|
|
355
|
+
debtAsset: subData.debtAsset,
|
|
356
|
+
debtAssetId: subData.debtAssetId,
|
|
357
|
+
baseToken: triggerData.baseTokenAddress,
|
|
358
|
+
quoteToken: triggerData.quoteTokenAddress,
|
|
359
|
+
price: triggerData.price,
|
|
360
|
+
ratioState: triggerData.ratioState,
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
const { ratioState } = getRatioStateInfoForAaveCloseStrategy(
|
|
364
|
+
_position.specific.ratioState,
|
|
365
|
+
wethToEthByAddress(_position.specific.collAsset, parseData.chainId),
|
|
366
|
+
wethToEthByAddress(_position.specific.debtAsset, parseData.chainId),
|
|
367
|
+
parseData.chainId,
|
|
368
|
+
);
|
|
369
|
+
|
|
370
|
+
_position.strategy.strategyId = isRatioStateOver(ratioState)
|
|
371
|
+
? Strategies.IdOverrides.TakeProfit
|
|
372
|
+
: Strategies.IdOverrides.StopLoss;
|
|
373
|
+
}
|
|
270
374
|
|
|
271
|
-
_position.strategy.strategyId = isEOA ? Strategies.IdOverrides.EoaLeverageManagement : Strategies.IdOverrides.LeverageManagement;
|
|
272
375
|
return _position;
|
|
273
376
|
}
|
|
274
377
|
|
|
@@ -311,48 +414,6 @@ function parseMorphoAaveV2LeverageManagement(position: Position.Automated, parse
|
|
|
311
414
|
return _position;
|
|
312
415
|
}
|
|
313
416
|
|
|
314
|
-
function parseAaveV3CloseOnPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
315
|
-
const _position = cloneDeep(position);
|
|
316
|
-
|
|
317
|
-
const { subStruct } = parseData.subscriptionEventData;
|
|
318
|
-
|
|
319
|
-
const triggerData = triggerService.aaveV3QuotePriceTrigger.decode(subStruct.triggerData);
|
|
320
|
-
const subData = subDataService.aaveV3QuotePriceSubData.decode(subStruct.subData);
|
|
321
|
-
|
|
322
|
-
_position.strategyData.decoded.triggerData = triggerData;
|
|
323
|
-
_position.strategyData.decoded.subData = subData;
|
|
324
|
-
|
|
325
|
-
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, AAVE_V3_MARKET_ADDRESSES[_position.chainId]);
|
|
326
|
-
|
|
327
|
-
_position.specific = {
|
|
328
|
-
collAsset: subData.collAsset,
|
|
329
|
-
collAssetId: subData.collAssetId,
|
|
330
|
-
debtAsset: subData.debtAsset,
|
|
331
|
-
debtAssetId: subData.debtAssetId,
|
|
332
|
-
baseToken: triggerData.baseTokenAddress,
|
|
333
|
-
quoteToken: triggerData.quoteTokenAddress,
|
|
334
|
-
price: triggerData.price,
|
|
335
|
-
ratioState: triggerData.ratioState,
|
|
336
|
-
};
|
|
337
|
-
|
|
338
|
-
const { ratioState } = getRatioStateInfoForAaveCloseStrategy(
|
|
339
|
-
_position.specific.ratioState,
|
|
340
|
-
wethToEthByAddress(_position.specific.collAsset, parseData.chainId),
|
|
341
|
-
wethToEthByAddress(_position.specific.debtAsset, parseData.chainId),
|
|
342
|
-
parseData.chainId,
|
|
343
|
-
);
|
|
344
|
-
|
|
345
|
-
// TODO -> Check if those changes break something?
|
|
346
|
-
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
347
|
-
_position.strategy.strategyId = isEOA
|
|
348
|
-
? Strategies.Identifiers.EoaCloseOnPrice
|
|
349
|
-
: (_position.strategy.strategyId = isRatioStateOver(ratioState)
|
|
350
|
-
? Strategies.IdOverrides.TakeProfit
|
|
351
|
-
: Strategies.IdOverrides.StopLoss);
|
|
352
|
-
|
|
353
|
-
return _position;
|
|
354
|
-
}
|
|
355
|
-
|
|
356
417
|
function parseAaveV3CloseOnPriceWithMaximumGasPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
357
418
|
const _position = cloneDeep(position);
|
|
358
419
|
|
|
@@ -926,37 +987,6 @@ function parseMorphoBlueLeverageManagementOnPrice(position: Position.Automated,
|
|
|
926
987
|
return _position;
|
|
927
988
|
}
|
|
928
989
|
|
|
929
|
-
function parseAaveV3LeverageManagementOnPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
930
|
-
const _position = cloneDeep(position);
|
|
931
|
-
|
|
932
|
-
const { subStruct } = parseData.subscriptionEventData;
|
|
933
|
-
|
|
934
|
-
const triggerData = triggerService.aaveV3QuotePriceTrigger.decode(subStruct.triggerData);
|
|
935
|
-
const subData = subDataService.aaveV3LeverageManagementOnPriceSubData.decode(subStruct.subData);
|
|
936
|
-
|
|
937
|
-
_position.strategyData.decoded.triggerData = triggerData;
|
|
938
|
-
_position.strategyData.decoded.subData = subData;
|
|
939
|
-
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, Math.random());
|
|
940
|
-
|
|
941
|
-
_position.specific = {
|
|
942
|
-
collAsset: subData.collAsset,
|
|
943
|
-
debtAsset: subData.debtAsset,
|
|
944
|
-
baseToken: triggerData.baseTokenAddress,
|
|
945
|
-
quoteToken: triggerData.quoteTokenAddress,
|
|
946
|
-
price: triggerData.price,
|
|
947
|
-
ratioState: triggerData.ratioState,
|
|
948
|
-
debtAssetId: subData.debtAssetId,
|
|
949
|
-
collAssetId: subData.collAssetId,
|
|
950
|
-
ratio: subData.targetRatio,
|
|
951
|
-
};
|
|
952
|
-
|
|
953
|
-
// TODO -> check if this change breaks something?
|
|
954
|
-
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
955
|
-
_position.strategy.strategyId = isEOA ? Strategies.IdOverrides.EoaLeverageManagementOnPrice : Strategies.IdOverrides.LeverageManagementOnPrice;
|
|
956
|
-
|
|
957
|
-
return _position;
|
|
958
|
-
}
|
|
959
|
-
|
|
960
990
|
function parseLiquityV2CloseOnPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
961
991
|
const _position = cloneDeep(position);
|
|
962
992
|
|
|
@@ -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,
|