@defisaver/automation-sdk 1.2.32 → 2.0.0
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/README.md +36 -0
- package/esm/abis/legacy_AaveV2Subscriptions.json +1 -1
- package/esm/abis/legacy_CompoundV2Subscriptions.json +1 -1
- package/esm/abis/legacy_MakerSubscriptions.json +1 -1
- package/esm/constants/index.js +20 -0
- package/esm/services/strategiesService.js +96 -29
- package/esm/services/strategySubService.d.ts +13 -7
- package/esm/services/strategySubService.js +37 -27
- package/esm/services/subDataService.d.ts +15 -3
- package/esm/services/subDataService.js +45 -11
- package/esm/services/triggerService.d.ts +2 -2
- package/esm/services/triggerService.js +2 -2
- package/esm/types/enums.d.ts +8 -2
- package/esm/types/enums.js +8 -2
- package/esm/types/index.d.ts +4 -4
- package/package.json +1 -1
- package/src/abis/legacy_AaveV2Subscriptions.json +1 -1
- package/src/abis/legacy_CompoundV2Subscriptions.json +1 -1
- package/src/abis/legacy_MakerSubscriptions.json +1 -1
- package/src/constants/index.ts +20 -0
- package/src/services/strategiesService.ts +109 -29
- package/src/services/strategySubService.ts +70 -46
- package/src/services/subDataService.ts +67 -17
- package/src/services/triggerService.ts +4 -4
- package/src/types/contracts/generated/Legacy_AaveV2Subscriptions.ts +8 -8
- package/src/types/contracts/generated/Legacy_CompoundV2Subscriptions.ts +8 -8
- package/src/types/contracts/generated/Legacy_MakerSubscriptions.ts +11 -11
- package/src/types/enums.ts +8 -2
- package/src/types/index.ts +4 -4
- package/umd/index.js +207 -64
package/src/constants/index.ts
CHANGED
|
@@ -238,6 +238,26 @@ export const MAINNET_BUNDLES_INFO: MainnetBundleInfo = {
|
|
|
238
238
|
strategyId: Strategies.Identifiers.CloseToCollateral,
|
|
239
239
|
protocol: PROTOCOLS.Spark,
|
|
240
240
|
},
|
|
241
|
+
[Bundles.MainnetIds.AAVE_V2_REPAY]: {
|
|
242
|
+
strategyOrBundleId: Bundles.MainnetIds.AAVE_V2_REPAY,
|
|
243
|
+
strategyId: Strategies.Identifiers.Repay,
|
|
244
|
+
protocol: PROTOCOLS.AaveV2,
|
|
245
|
+
},
|
|
246
|
+
[Bundles.MainnetIds.AAVE_V2_BOOST]: {
|
|
247
|
+
strategyOrBundleId: Bundles.MainnetIds.AAVE_V2_BOOST,
|
|
248
|
+
strategyId: Strategies.Identifiers.Boost,
|
|
249
|
+
protocol: PROTOCOLS.AaveV2,
|
|
250
|
+
},
|
|
251
|
+
[Bundles.MainnetIds.COMP_V2_REPAY]: {
|
|
252
|
+
strategyOrBundleId: Bundles.MainnetIds.COMP_V2_REPAY,
|
|
253
|
+
strategyId: Strategies.Identifiers.Repay,
|
|
254
|
+
protocol: PROTOCOLS.CompoundV2,
|
|
255
|
+
},
|
|
256
|
+
[Bundles.MainnetIds.COMP_V2_BOOST]: {
|
|
257
|
+
strategyOrBundleId: Bundles.MainnetIds.COMP_V2_BOOST,
|
|
258
|
+
strategyId: Strategies.Identifiers.Boost,
|
|
259
|
+
protocol: PROTOCOLS.CompoundV2,
|
|
260
|
+
},
|
|
241
261
|
};
|
|
242
262
|
|
|
243
263
|
export const OPTIMISM_BUNDLES_INFO: OptimismBundleInfo = {
|
|
@@ -24,8 +24,8 @@ function parseMakerSavingsLiqProtection(position: Position.Automated, parseData:
|
|
|
24
24
|
_position.strategyData.decoded.subData = subData;
|
|
25
25
|
|
|
26
26
|
_position.specific = {
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
triggerRepayRatio: Number(triggerData.ratio),
|
|
28
|
+
targetRepayRatio: Number(subData.targetRatio),
|
|
29
29
|
repayEnabled: true,
|
|
30
30
|
boostEnabled: false,
|
|
31
31
|
};
|
|
@@ -93,15 +93,15 @@ function parseMakerLeverageManagement(position: Position.Automated, parseData: P
|
|
|
93
93
|
|
|
94
94
|
if (isRepay) {
|
|
95
95
|
_position.specific = {
|
|
96
|
-
|
|
97
|
-
|
|
96
|
+
triggerRepayRatio: triggerData.ratio,
|
|
97
|
+
targetRepayRatio: subData.targetRatio,
|
|
98
98
|
repayEnabled: true,
|
|
99
99
|
subId1: Number(subId),
|
|
100
100
|
};
|
|
101
101
|
} else {
|
|
102
102
|
_position.specific = {
|
|
103
|
-
|
|
104
|
-
|
|
103
|
+
triggerBoostRatio: triggerData.ratio,
|
|
104
|
+
targetBoostRatio: subData.targetRatio,
|
|
105
105
|
boostEnabled: isEnabled,
|
|
106
106
|
subId2: Number(subId),
|
|
107
107
|
};
|
|
@@ -157,6 +157,42 @@ function parseLiquityTrailingStop(position: Position.Automated, parseData: Parse
|
|
|
157
157
|
return _position;
|
|
158
158
|
}
|
|
159
159
|
|
|
160
|
+
function parseAaveV2LeverageManagement(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
161
|
+
const _position = cloneDeep(position);
|
|
162
|
+
|
|
163
|
+
const { subStruct, subId } = parseData.subscriptionEventData;
|
|
164
|
+
const { isEnabled } = parseData.strategiesSubsData;
|
|
165
|
+
|
|
166
|
+
const triggerData = triggerService.aaveV2RatioTrigger.decode(subStruct.triggerData);
|
|
167
|
+
const subData = subDataService.aaveV2LeverageManagementSubData.decode(subStruct.subData);
|
|
168
|
+
|
|
169
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
170
|
+
_position.strategyData.decoded.subData = subData;
|
|
171
|
+
|
|
172
|
+
const isRepay = _position.strategy.strategyId === Strategies.Identifiers.Repay;
|
|
173
|
+
|
|
174
|
+
if (isRepay) {
|
|
175
|
+
_position.specific = {
|
|
176
|
+
triggerRepayRatio: triggerData.ratio,
|
|
177
|
+
targetRepayRatio: subData.targetRatio,
|
|
178
|
+
repayEnabled: true,
|
|
179
|
+
subId1: Number(subId),
|
|
180
|
+
};
|
|
181
|
+
} else {
|
|
182
|
+
_position.specific = {
|
|
183
|
+
triggerBoostRatio: triggerData.ratio,
|
|
184
|
+
targetBoostRatio: subData.targetRatio,
|
|
185
|
+
boostEnabled: isEnabled,
|
|
186
|
+
subId2: Number(subId),
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
_position.strategy.strategyId = Strategies.IdOverrides.LeverageManagement;
|
|
191
|
+
_position.specific.mergeWithSameId = true;
|
|
192
|
+
|
|
193
|
+
return _position;
|
|
194
|
+
}
|
|
195
|
+
|
|
160
196
|
function parseAaveV3LeverageManagement(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
161
197
|
const _position = cloneDeep(position);
|
|
162
198
|
|
|
@@ -164,7 +200,7 @@ function parseAaveV3LeverageManagement(position: Position.Automated, parseData:
|
|
|
164
200
|
const { isEnabled } = parseData.strategiesSubsData;
|
|
165
201
|
|
|
166
202
|
const triggerData = triggerService.aaveV3RatioTrigger.decode(subStruct.triggerData);
|
|
167
|
-
const subData = subDataService.
|
|
203
|
+
const subData = subDataService.aaveV3LeverageManagementSubData.decode(subStruct.subData);
|
|
168
204
|
|
|
169
205
|
_position.strategyData.decoded.triggerData = triggerData;
|
|
170
206
|
_position.strategyData.decoded.subData = subData;
|
|
@@ -173,15 +209,15 @@ function parseAaveV3LeverageManagement(position: Position.Automated, parseData:
|
|
|
173
209
|
|
|
174
210
|
if (isRepay) {
|
|
175
211
|
_position.specific = {
|
|
176
|
-
|
|
177
|
-
|
|
212
|
+
triggerRepayRatio: triggerData.ratio,
|
|
213
|
+
targetRepayRatio: subData.targetRatio,
|
|
178
214
|
repayEnabled: true,
|
|
179
215
|
subId1: Number(subId),
|
|
180
216
|
};
|
|
181
217
|
} else {
|
|
182
218
|
_position.specific = {
|
|
183
|
-
|
|
184
|
-
|
|
219
|
+
triggerBoostRatio: triggerData.ratio,
|
|
220
|
+
targetBoostRatio: subData.targetRatio,
|
|
185
221
|
boostEnabled: isEnabled,
|
|
186
222
|
subId2: Number(subId),
|
|
187
223
|
};
|
|
@@ -209,15 +245,15 @@ function parseMorphoAaveV2LeverageManagement(position: Position.Automated, parse
|
|
|
209
245
|
|
|
210
246
|
if (isRepay) {
|
|
211
247
|
_position.specific = {
|
|
212
|
-
|
|
213
|
-
|
|
248
|
+
triggerRepayRatio: triggerData.ratio,
|
|
249
|
+
targetRepayRatio: subData.targetRatio,
|
|
214
250
|
repayEnabled: true,
|
|
215
251
|
subId1: Number(subId),
|
|
216
252
|
};
|
|
217
253
|
} else {
|
|
218
254
|
_position.specific = {
|
|
219
|
-
|
|
220
|
-
|
|
255
|
+
triggerBoostRatio: triggerData.ratio,
|
|
256
|
+
targetBoostRatio: subData.targetRatio,
|
|
221
257
|
boostEnabled: isEnabled,
|
|
222
258
|
subId2: Number(subId),
|
|
223
259
|
};
|
|
@@ -263,6 +299,42 @@ function parseAaveV3CloseOnPrice(position: Position.Automated, parseData: ParseD
|
|
|
263
299
|
return _position;
|
|
264
300
|
}
|
|
265
301
|
|
|
302
|
+
function parseCompoundV2LeverageManagement(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
303
|
+
const _position = cloneDeep(position);
|
|
304
|
+
|
|
305
|
+
const { subStruct, subId } = parseData.subscriptionEventData;
|
|
306
|
+
const { isEnabled } = parseData.strategiesSubsData;
|
|
307
|
+
|
|
308
|
+
const triggerData = triggerService.compoundV2RatioTrigger.decode(subStruct.triggerData);
|
|
309
|
+
const subData = subDataService.compoundV2LeverageManagementSubData.decode(subStruct.subData);
|
|
310
|
+
|
|
311
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
312
|
+
_position.strategyData.decoded.subData = subData;
|
|
313
|
+
_position.owner = triggerData.owner;
|
|
314
|
+
const isRepay = [Strategies.Identifiers.Repay, Strategies.Identifiers.EoaRepay].includes(_position.strategy.strategyId as Strategies.Identifiers);
|
|
315
|
+
|
|
316
|
+
if (isRepay) {
|
|
317
|
+
_position.specific = {
|
|
318
|
+
triggerRepayRatio: triggerData.ratio,
|
|
319
|
+
targetRepayRatio: subData.targetRatio,
|
|
320
|
+
repayEnabled: true,
|
|
321
|
+
subId1: Number(subId),
|
|
322
|
+
};
|
|
323
|
+
} else {
|
|
324
|
+
_position.specific = {
|
|
325
|
+
triggerBoostRatio: triggerData.ratio,
|
|
326
|
+
targetBoostRatio: subData.targetRatio,
|
|
327
|
+
boostEnabled: isEnabled,
|
|
328
|
+
subId2: Number(subId),
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
_position.strategy.strategyId = Strategies.IdOverrides.LeverageManagement;
|
|
333
|
+
_position.specific.mergeWithSameId = true;
|
|
334
|
+
|
|
335
|
+
return _position;
|
|
336
|
+
}
|
|
337
|
+
|
|
266
338
|
function parseCompoundV3LeverageManagement(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
267
339
|
const _position = cloneDeep(position);
|
|
268
340
|
|
|
@@ -279,15 +351,15 @@ function parseCompoundV3LeverageManagement(position: Position.Automated, parseDa
|
|
|
279
351
|
|
|
280
352
|
if (isRepay) {
|
|
281
353
|
_position.specific = {
|
|
282
|
-
|
|
283
|
-
|
|
354
|
+
triggerRepayRatio: triggerData.ratio,
|
|
355
|
+
targetRepayRatio: subData.targetRatio,
|
|
284
356
|
repayEnabled: true,
|
|
285
357
|
subId1: Number(subId),
|
|
286
358
|
};
|
|
287
359
|
} else {
|
|
288
360
|
_position.specific = {
|
|
289
|
-
|
|
290
|
-
|
|
361
|
+
triggerBoostRatio: triggerData.ratio,
|
|
362
|
+
targetBoostRatio: subData.targetRatio,
|
|
291
363
|
boostEnabled: isEnabled,
|
|
292
364
|
subId2: Number(subId),
|
|
293
365
|
};
|
|
@@ -323,8 +395,8 @@ function parseLiquityBondProtection(position: Position.Automated, parseData: Par
|
|
|
323
395
|
_position.strategyData.decoded.triggerData = triggerData;
|
|
324
396
|
|
|
325
397
|
_position.specific = {
|
|
326
|
-
|
|
327
|
-
|
|
398
|
+
triggerRepayRatio: Number(triggerData.ratio),
|
|
399
|
+
targetRepayRatio: Infinity, // Unknown targetRepayRatio, uses all assets from chicken bond until trove min debt (2000LUSD)
|
|
328
400
|
repayEnabled: true,
|
|
329
401
|
};
|
|
330
402
|
return _position;
|
|
@@ -368,15 +440,15 @@ function parseLiquityLeverageManagement(position: Position.Automated, parseData:
|
|
|
368
440
|
|
|
369
441
|
if (isRepay) {
|
|
370
442
|
_position.specific = {
|
|
371
|
-
|
|
372
|
-
|
|
443
|
+
triggerRepayRatio: triggerData.ratio,
|
|
444
|
+
targetRepayRatio: subData.targetRatio,
|
|
373
445
|
repayEnabled: true,
|
|
374
446
|
subId1: Number(subId),
|
|
375
447
|
};
|
|
376
448
|
} else {
|
|
377
449
|
_position.specific = {
|
|
378
|
-
|
|
379
|
-
|
|
450
|
+
triggerBoostRatio: triggerData.ratio,
|
|
451
|
+
targetBoostRatio: subData.targetRatio,
|
|
380
452
|
boostEnabled: isEnabled,
|
|
381
453
|
subId2: Number(subId),
|
|
382
454
|
};
|
|
@@ -404,15 +476,15 @@ function parseSparkLeverageManagement(position: Position.Automated, parseData: P
|
|
|
404
476
|
|
|
405
477
|
if (isRepay) {
|
|
406
478
|
_position.specific = {
|
|
407
|
-
|
|
408
|
-
|
|
479
|
+
triggerRepayRatio: triggerData.ratio,
|
|
480
|
+
targetRepayRatio: subData.targetRatio,
|
|
409
481
|
repayEnabled: true,
|
|
410
482
|
subId1: Number(subId),
|
|
411
483
|
};
|
|
412
484
|
} else {
|
|
413
485
|
_position.specific = {
|
|
414
|
-
|
|
415
|
-
|
|
486
|
+
triggerBoostRatio: triggerData.ratio,
|
|
487
|
+
targetBoostRatio: subData.targetRatio,
|
|
416
488
|
boostEnabled: isEnabled,
|
|
417
489
|
subId2: Number(subId),
|
|
418
490
|
};
|
|
@@ -475,12 +547,20 @@ const parsingMethodsMapping: StrategiesToProtocolVersionMapping = {
|
|
|
475
547
|
[Strategies.Identifiers.Repay]: parseLiquityLeverageManagement,
|
|
476
548
|
[Strategies.Identifiers.Boost]: parseLiquityLeverageManagement,
|
|
477
549
|
},
|
|
550
|
+
[ProtocolIdentifiers.StrategiesAutomation.AaveV2]: {
|
|
551
|
+
[Strategies.Identifiers.Repay]: parseAaveV2LeverageManagement,
|
|
552
|
+
[Strategies.Identifiers.Boost]: parseAaveV2LeverageManagement,
|
|
553
|
+
},
|
|
478
554
|
[ProtocolIdentifiers.StrategiesAutomation.AaveV3]: {
|
|
479
555
|
[Strategies.Identifiers.Repay]: parseAaveV3LeverageManagement,
|
|
480
556
|
[Strategies.Identifiers.Boost]: parseAaveV3LeverageManagement,
|
|
481
557
|
[Strategies.Identifiers.CloseToDebt]: parseAaveV3CloseOnPrice,
|
|
482
558
|
[Strategies.Identifiers.CloseToCollateral]: parseAaveV3CloseOnPrice,
|
|
483
559
|
},
|
|
560
|
+
[ProtocolIdentifiers.StrategiesAutomation.CompoundV2]: {
|
|
561
|
+
[Strategies.Identifiers.Repay]: parseCompoundV2LeverageManagement,
|
|
562
|
+
[Strategies.Identifiers.Boost]: parseCompoundV2LeverageManagement,
|
|
563
|
+
},
|
|
484
564
|
[ProtocolIdentifiers.StrategiesAutomation.CompoundV3]: {
|
|
485
565
|
[Strategies.Identifiers.Repay]: parseCompoundV3LeverageManagement,
|
|
486
566
|
[Strategies.Identifiers.Boost]: parseCompoundV3LeverageManagement,
|
|
@@ -14,15 +14,15 @@ export const makerEncode = {
|
|
|
14
14
|
repayFromSavings(
|
|
15
15
|
bundleId: StrategyOrBundleIds,
|
|
16
16
|
vaultId: number,
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
triggerRepayRatio: number,
|
|
18
|
+
targetRepayRatio: number,
|
|
19
19
|
isBundle: boolean = true,
|
|
20
20
|
chainId: ChainId = ChainId.Ethereum,
|
|
21
21
|
daiAddr?: EthereumAddress,
|
|
22
22
|
mcdCdpManagerAddr?: EthereumAddress,
|
|
23
23
|
) {
|
|
24
|
-
const subData = subDataService.makerRepayFromSavingsSubData.encode(vaultId,
|
|
25
|
-
const triggerData = triggerService.makerRatioTrigger.encode(vaultId,
|
|
24
|
+
const subData = subDataService.makerRepayFromSavingsSubData.encode(vaultId, targetRepayRatio, chainId, daiAddr, mcdCdpManagerAddr);
|
|
25
|
+
const triggerData = triggerService.makerRatioTrigger.encode(vaultId, triggerRepayRatio, RatioState.UNDER);
|
|
26
26
|
|
|
27
27
|
return [bundleId, isBundle, triggerData, subData];
|
|
28
28
|
},
|
|
@@ -74,18 +74,18 @@ export const makerEncode = {
|
|
|
74
74
|
},
|
|
75
75
|
leverageManagement(
|
|
76
76
|
vaultId:number,
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
77
|
+
triggerRepayRatio:string,
|
|
78
|
+
triggerBoostRatio:string,
|
|
79
|
+
targetBoostRatio:string,
|
|
80
|
+
targetRepayRatio:string,
|
|
81
81
|
boostEnabled:boolean,
|
|
82
82
|
) {
|
|
83
83
|
return [
|
|
84
84
|
vaultId,
|
|
85
|
-
new Dec(
|
|
86
|
-
new Dec(
|
|
87
|
-
new Dec(
|
|
88
|
-
new Dec(
|
|
85
|
+
new Dec(triggerRepayRatio).mul(1e16).toString(),
|
|
86
|
+
new Dec(triggerBoostRatio).mul(1e16).toString(),
|
|
87
|
+
new Dec(targetBoostRatio).mul(1e16).toString(),
|
|
88
|
+
new Dec(targetRepayRatio).mul(1e16).toString(),
|
|
89
89
|
boostEnabled,
|
|
90
90
|
];
|
|
91
91
|
},
|
|
@@ -150,17 +150,17 @@ export const liquityEncode = {
|
|
|
150
150
|
return [strategyId, isBundle, triggerData, subData];
|
|
151
151
|
},
|
|
152
152
|
leverageManagement(
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
153
|
+
triggerRepayRatio:string,
|
|
154
|
+
triggerBoostRatio:string,
|
|
155
|
+
targetBoostRatio:string,
|
|
156
|
+
targetRepayRatio:string,
|
|
157
157
|
boostEnabled:boolean,
|
|
158
158
|
) {
|
|
159
159
|
return [
|
|
160
|
-
new Dec(
|
|
161
|
-
new Dec(
|
|
162
|
-
new Dec(
|
|
163
|
-
new Dec(
|
|
160
|
+
new Dec(triggerRepayRatio).mul(1e16).toString(),
|
|
161
|
+
new Dec(triggerBoostRatio).mul(1e16).toString(),
|
|
162
|
+
new Dec(targetBoostRatio).mul(1e16).toString(),
|
|
163
|
+
new Dec(targetRepayRatio).mul(1e16).toString(),
|
|
164
164
|
boostEnabled,
|
|
165
165
|
];
|
|
166
166
|
},
|
|
@@ -172,23 +172,35 @@ export const chickenBondsEncode = {
|
|
|
172
172
|
},
|
|
173
173
|
};
|
|
174
174
|
|
|
175
|
+
export const aaveV2Encode = {
|
|
176
|
+
leverageManagement(
|
|
177
|
+
triggerRepayRatio: number,
|
|
178
|
+
triggerBoostRatio: number,
|
|
179
|
+
targetBoostRatio: number,
|
|
180
|
+
targetRepayRatio: number,
|
|
181
|
+
boostEnabled: boolean,
|
|
182
|
+
) {
|
|
183
|
+
return subDataService.aaveV2LeverageManagementSubData.encode(triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled);
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
|
|
175
187
|
export const aaveV3Encode = {
|
|
176
188
|
leverageManagement(
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
189
|
+
triggerRepayRatio: number,
|
|
190
|
+
triggerBoostRatio: number,
|
|
191
|
+
targetBoostRatio: number,
|
|
192
|
+
targetRepayRatio: number,
|
|
181
193
|
boostEnabled: boolean,
|
|
182
194
|
) {
|
|
183
195
|
let subInput = '0x';
|
|
184
196
|
|
|
185
|
-
subInput = subInput.concat(new Dec(
|
|
197
|
+
subInput = subInput.concat(new Dec(triggerRepayRatio).mul(1e16).toHex().slice(2)
|
|
186
198
|
.padStart(32, '0'));
|
|
187
|
-
subInput = subInput.concat(new Dec(
|
|
199
|
+
subInput = subInput.concat(new Dec(triggerBoostRatio).mul(1e16).toHex().slice(2)
|
|
188
200
|
.padStart(32, '0'));
|
|
189
|
-
subInput = subInput.concat(new Dec(
|
|
201
|
+
subInput = subInput.concat(new Dec(targetBoostRatio).mul(1e16).toHex().slice(2)
|
|
190
202
|
.padStart(32, '0'));
|
|
191
|
-
subInput = subInput.concat(new Dec(
|
|
203
|
+
subInput = subInput.concat(new Dec(targetRepayRatio).mul(1e16).toHex().slice(2)
|
|
192
204
|
.padStart(32, '0'));
|
|
193
205
|
subInput = subInput.concat(boostEnabled ? '01' : '00');
|
|
194
206
|
|
|
@@ -218,30 +230,42 @@ export const aaveV3Encode = {
|
|
|
218
230
|
},
|
|
219
231
|
};
|
|
220
232
|
|
|
233
|
+
export const compoundV2Encode = {
|
|
234
|
+
leverageManagement(
|
|
235
|
+
triggerRepayRatio: number,
|
|
236
|
+
triggerBoostRatio: number,
|
|
237
|
+
targetBoostRatio: number,
|
|
238
|
+
targetRepayRatio: number,
|
|
239
|
+
boostEnabled: boolean,
|
|
240
|
+
) {
|
|
241
|
+
return subDataService.compoundV2LeverageManagementSubData.encode(triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled);
|
|
242
|
+
},
|
|
243
|
+
};
|
|
244
|
+
|
|
221
245
|
export const compoundV3Encode = {
|
|
222
246
|
leverageManagement(
|
|
223
247
|
market: EthereumAddress,
|
|
224
248
|
baseToken: EthereumAddress,
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
249
|
+
triggerRepayRatio: number,
|
|
250
|
+
triggerBoostRatio: number,
|
|
251
|
+
targetBoostRatio: number,
|
|
252
|
+
targetRepayRatio: number,
|
|
229
253
|
boostEnabled: boolean,
|
|
230
254
|
isEOA: boolean,
|
|
231
255
|
) {
|
|
232
|
-
return subDataService.compoundV3LeverageManagementSubData.encode(market, baseToken,
|
|
256
|
+
return subDataService.compoundV3LeverageManagementSubData.encode(market, baseToken, triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled, isEOA);
|
|
233
257
|
},
|
|
234
258
|
};
|
|
235
259
|
|
|
236
260
|
export const morphoAaveV2Encode = {
|
|
237
261
|
leverageManagement(
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
262
|
+
triggerRepayRatio: number,
|
|
263
|
+
triggerBoostRatio: number,
|
|
264
|
+
targetBoostRatio: number,
|
|
265
|
+
targetRepayRatio: number,
|
|
242
266
|
boostEnabled: boolean,
|
|
243
267
|
) {
|
|
244
|
-
return subDataService.morphoAaveV2LeverageManagementSubData.encode(
|
|
268
|
+
return subDataService.morphoAaveV2LeverageManagementSubData.encode(triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled);
|
|
245
269
|
},
|
|
246
270
|
};
|
|
247
271
|
|
|
@@ -281,21 +305,21 @@ export const exchangeEncode = {
|
|
|
281
305
|
|
|
282
306
|
export const sparkEncode = {
|
|
283
307
|
leverageManagement(
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
308
|
+
triggerRepayRatio: number,
|
|
309
|
+
triggerBoostRatio: number,
|
|
310
|
+
targetBoostRatio: number,
|
|
311
|
+
targetRepayRatio: number,
|
|
288
312
|
boostEnabled: boolean,
|
|
289
313
|
) {
|
|
290
314
|
let subInput = '0x';
|
|
291
315
|
|
|
292
|
-
subInput = subInput.concat(new Dec(
|
|
316
|
+
subInput = subInput.concat(new Dec(triggerRepayRatio).mul(1e16).toHex().slice(2)
|
|
293
317
|
.padStart(32, '0'));
|
|
294
|
-
subInput = subInput.concat(new Dec(
|
|
318
|
+
subInput = subInput.concat(new Dec(triggerBoostRatio).mul(1e16).toHex().slice(2)
|
|
295
319
|
.padStart(32, '0'));
|
|
296
|
-
subInput = subInput.concat(new Dec(
|
|
320
|
+
subInput = subInput.concat(new Dec(targetBoostRatio).mul(1e16).toHex().slice(2)
|
|
297
321
|
.padStart(32, '0'));
|
|
298
|
-
subInput = subInput.concat(new Dec(
|
|
322
|
+
subInput = subInput.concat(new Dec(targetRepayRatio).mul(1e16).toHex().slice(2)
|
|
299
323
|
.padStart(32, '0'));
|
|
300
324
|
subInput = subInput.concat(boostEnabled ? '01' : '00');
|
|
301
325
|
|
|
@@ -132,7 +132,32 @@ export const liquityCloseSubData = {
|
|
|
132
132
|
},
|
|
133
133
|
};
|
|
134
134
|
|
|
135
|
-
export const
|
|
135
|
+
export const aaveV2LeverageManagementSubData = {
|
|
136
|
+
encode(
|
|
137
|
+
triggerRepayRatio: number,
|
|
138
|
+
triggerBoostRatio: number,
|
|
139
|
+
targetBoostRatio: number,
|
|
140
|
+
targetRepayRatio: number,
|
|
141
|
+
boostEnabled: boolean,
|
|
142
|
+
): SubData {
|
|
143
|
+
return [
|
|
144
|
+
new Dec(triggerRepayRatio).mul(1e16).toString(),
|
|
145
|
+
new Dec(triggerBoostRatio).mul(1e16).toString(),
|
|
146
|
+
new Dec(targetBoostRatio).mul(1e16).toString(),
|
|
147
|
+
new Dec(targetRepayRatio).mul(1e16).toString(),
|
|
148
|
+
// @ts-ignore // TODO
|
|
149
|
+
boostEnabled,
|
|
150
|
+
];
|
|
151
|
+
},
|
|
152
|
+
decode(subData: SubData): { targetRatio: number } {
|
|
153
|
+
const ratioWei = mockedWeb3.eth.abi.decodeParameter('uint256', subData[1]) as any as string;
|
|
154
|
+
const targetRatio = weiToRatioPercentage(ratioWei);
|
|
155
|
+
|
|
156
|
+
return { targetRatio };
|
|
157
|
+
},
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
export const aaveV3LeverageManagementSubData = { // TODO encode?
|
|
136
161
|
decode(subData: SubData): { targetRatio: number } {
|
|
137
162
|
const ratioWei = mockedWeb3.eth.abi.decodeParameter('uint256', subData[0]) as any as string;
|
|
138
163
|
const targetRatio = weiToRatioPercentage(ratioWei);
|
|
@@ -172,24 +197,49 @@ export const aaveV3QuotePriceSubData = {
|
|
|
172
197
|
},
|
|
173
198
|
};
|
|
174
199
|
|
|
200
|
+
export const compoundV2LeverageManagementSubData = {
|
|
201
|
+
encode(
|
|
202
|
+
triggerRepayRatio: number,
|
|
203
|
+
triggerBoostRatio: number,
|
|
204
|
+
targetBoostRatio: number,
|
|
205
|
+
targetRepayRatio: number,
|
|
206
|
+
boostEnabled: boolean,
|
|
207
|
+
): SubData {
|
|
208
|
+
return [
|
|
209
|
+
new Dec(triggerRepayRatio).mul(1e16).toString(),
|
|
210
|
+
new Dec(triggerBoostRatio).mul(1e16).toString(),
|
|
211
|
+
new Dec(targetBoostRatio).mul(1e16).toString(),
|
|
212
|
+
new Dec(targetRepayRatio).mul(1e16).toString(),
|
|
213
|
+
// @ts-ignore // TODO
|
|
214
|
+
boostEnabled,
|
|
215
|
+
];
|
|
216
|
+
},
|
|
217
|
+
decode(subData: SubData): { targetRatio: number } {
|
|
218
|
+
const weiRatio = mockedWeb3.eth.abi.decodeParameter('uint256', subData[0]) as any as string;
|
|
219
|
+
const targetRatio = weiToRatioPercentage(weiRatio);
|
|
220
|
+
|
|
221
|
+
return { targetRatio };
|
|
222
|
+
},
|
|
223
|
+
};
|
|
224
|
+
|
|
175
225
|
export const compoundV3LeverageManagementSubData = {
|
|
176
226
|
encode(
|
|
177
227
|
market: EthereumAddress,
|
|
178
228
|
baseToken: EthereumAddress,
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
229
|
+
triggerRepayRatio: number,
|
|
230
|
+
triggerBoostRatio: number,
|
|
231
|
+
targetBoostRatio: number,
|
|
232
|
+
targetRepayRatio: number,
|
|
183
233
|
boostEnabled: boolean,
|
|
184
234
|
isEOA: boolean,
|
|
185
235
|
): SubData {
|
|
186
236
|
return [
|
|
187
237
|
market,
|
|
188
238
|
baseToken,
|
|
189
|
-
new Dec(
|
|
190
|
-
new Dec(
|
|
191
|
-
new Dec(
|
|
192
|
-
new Dec(
|
|
239
|
+
new Dec(triggerRepayRatio).mul(1e16).toString(),
|
|
240
|
+
new Dec(triggerBoostRatio).mul(1e16).toString(),
|
|
241
|
+
new Dec(targetBoostRatio).mul(1e16).toString(),
|
|
242
|
+
new Dec(targetRepayRatio).mul(1e16).toString(),
|
|
193
243
|
// @ts-ignore // TODO
|
|
194
244
|
boostEnabled, isEOA,
|
|
195
245
|
];
|
|
@@ -204,17 +254,17 @@ export const compoundV3LeverageManagementSubData = {
|
|
|
204
254
|
|
|
205
255
|
export const morphoAaveV2LeverageManagementSubData = {
|
|
206
256
|
encode(
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
257
|
+
triggerRepayRatio: number,
|
|
258
|
+
triggerBoostRatio: number,
|
|
259
|
+
targetBoostRatio: number,
|
|
260
|
+
targetRepayRatio: number,
|
|
211
261
|
boostEnabled: boolean,
|
|
212
262
|
): SubData {
|
|
213
263
|
return [
|
|
214
|
-
ratioPercentageToWei(
|
|
215
|
-
ratioPercentageToWei(
|
|
216
|
-
ratioPercentageToWei(
|
|
217
|
-
ratioPercentageToWei(
|
|
264
|
+
ratioPercentageToWei(triggerRepayRatio),
|
|
265
|
+
ratioPercentageToWei(triggerBoostRatio),
|
|
266
|
+
ratioPercentageToWei(targetBoostRatio),
|
|
267
|
+
ratioPercentageToWei(targetRepayRatio),
|
|
218
268
|
// @ts-ignore
|
|
219
269
|
boostEnabled,
|
|
220
270
|
];
|
|
@@ -105,11 +105,11 @@ export const compoundV2RatioTrigger = {
|
|
|
105
105
|
const ratioWei = ratioPercentageToWei(ratioPercentage);
|
|
106
106
|
return [mockedWeb3.eth.abi.encodeParameters(['address', 'uint256', 'uint8'], [owner, ratioWei, ratioState])];
|
|
107
107
|
},
|
|
108
|
-
decode(triggerData: TriggerData): { owner: EthereumAddress, ratioState: RatioState, ratio:
|
|
108
|
+
decode(triggerData: TriggerData): { owner: EthereumAddress, ratioState: RatioState, ratio: number } {
|
|
109
109
|
const decodedData = mockedWeb3.eth.abi.decodeParameters(['address', 'uint256', 'uint8'], triggerData[0]);
|
|
110
110
|
return {
|
|
111
111
|
owner: decodedData[0],
|
|
112
|
-
ratio: new Dec(mockedWeb3.utils.fromWei(decodedData[1])).mul(100).
|
|
112
|
+
ratio: new Dec(mockedWeb3.utils.fromWei(decodedData[1])).mul(100).toNumber(),
|
|
113
113
|
ratioState: +decodedData[2],
|
|
114
114
|
};
|
|
115
115
|
},
|
|
@@ -148,12 +148,12 @@ export const aaveV2RatioTrigger = {
|
|
|
148
148
|
const ratioWei = ratioPercentageToWei(ratioPercentage);
|
|
149
149
|
return [mockedWeb3.eth.abi.encodeParameters(['address', 'address', 'uint256', 'uint8'], [owner, market, ratioWei, ratioState])];
|
|
150
150
|
},
|
|
151
|
-
decode(triggerData: TriggerData): { owner: EthereumAddress, market:EthereumAddress, ratioState: RatioState, ratio:
|
|
151
|
+
decode(triggerData: TriggerData): { owner: EthereumAddress, market:EthereumAddress, ratioState: RatioState, ratio: number } {
|
|
152
152
|
const decodedData = mockedWeb3.eth.abi.decodeParameters(['address', 'address', 'uint256', 'uint8'], triggerData[0]);
|
|
153
153
|
return {
|
|
154
154
|
owner: decodedData[0],
|
|
155
155
|
market: decodedData[1],
|
|
156
|
-
ratio: new Dec(mockedWeb3.utils.fromWei(decodedData[2])).mul(100).
|
|
156
|
+
ratio: new Dec(mockedWeb3.utils.fromWei(decodedData[2])).mul(100).toNumber(),
|
|
157
157
|
ratioState: +decodedData[3],
|
|
158
158
|
};
|
|
159
159
|
},
|
|
@@ -33,8 +33,8 @@ export declare namespace AaveSubscriptionsV2 {
|
|
|
33
33
|
]
|
|
34
34
|
| {
|
|
35
35
|
user: string;
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
triggerRepayRatio: number | string | BN;
|
|
37
|
+
triggerBoostRatio: number | string | BN;
|
|
38
38
|
optimalRatioBoost: number | string | BN;
|
|
39
39
|
optimalRatioRepay: number | string | BN;
|
|
40
40
|
boostEnabled: boolean;
|
|
@@ -50,8 +50,8 @@ export declare namespace AaveSubscriptionsV2 {
|
|
|
50
50
|
];
|
|
51
51
|
export type AaveHolderStructOutputStruct = {
|
|
52
52
|
user: string;
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
triggerRepayRatio: string;
|
|
54
|
+
triggerBoostRatio: string;
|
|
55
55
|
optimalRatioBoost: string;
|
|
56
56
|
optimalRatioRepay: string;
|
|
57
57
|
boostEnabled: boolean;
|
|
@@ -124,8 +124,8 @@ export interface Legacy_AaveV2Subscriptions extends BaseContract {
|
|
|
124
124
|
setOwnerByAdmin(_owner: string): NonPayableTransactionObject<void>;
|
|
125
125
|
|
|
126
126
|
subscribe(
|
|
127
|
-
|
|
128
|
-
|
|
127
|
+
_triggerRepayRatio: number | string | BN,
|
|
128
|
+
_triggerBoostRatio: number | string | BN,
|
|
129
129
|
_optimalBoost: number | string | BN,
|
|
130
130
|
_optimalRepay: number | string | BN,
|
|
131
131
|
_boostEnabled: boolean
|
|
@@ -136,8 +136,8 @@ export interface Legacy_AaveV2Subscriptions extends BaseContract {
|
|
|
136
136
|
): NonPayableTransactionObject<
|
|
137
137
|
[string, string, string, string, string, boolean] & {
|
|
138
138
|
user: string;
|
|
139
|
-
|
|
140
|
-
|
|
139
|
+
triggerRepayRatio: string;
|
|
140
|
+
triggerBoostRatio: string;
|
|
141
141
|
optimalRatioBoost: string;
|
|
142
142
|
optimalRatioRepay: string;
|
|
143
143
|
boostEnabled: boolean;
|