@defisaver/automation-sdk 2.1.4 → 2.1.6
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/.yarn/releases/yarn-1.22.1.cjs +147386 -0
- package/.yarnrc.yml +3 -0
- package/esm/automation/private/StrategiesAutomation.d.ts +1 -0
- package/esm/automation/private/StrategiesAutomation.js +29 -26
- package/esm/services/strategiesService.js +18 -9
- package/esm/services/strategiesService.test.js +1 -1
- package/esm/services/subDataService.js +2 -2
- package/esm/types/index.d.ts +2 -1
- package/package.json +1 -1
- package/src/automation/private/StrategiesAutomation.ts +52 -50
- package/src/services/strategiesService.test.ts +1 -1
- package/src/services/strategiesService.ts +18 -9
- package/src/services/subDataService.ts +3 -3
- package/src/types/index.ts +2 -1
- package/umd/index.js +539 -391
- package/.env +0 -4
package/.yarnrc.yml
ADDED
|
@@ -24,6 +24,7 @@ export default class StrategiesAutomation extends Automation {
|
|
|
24
24
|
* @description Removes expired Limit Order subscriptions
|
|
25
25
|
*/
|
|
26
26
|
protected removeExpiredSubscriptions(subscriptions: (Position.Automated | null)[]): (Position.Automated | null)[];
|
|
27
|
+
private _mergeCheck;
|
|
27
28
|
protected _getSubscriptions(addresses?: EthereumAddress[], options?: SubscriptionOptions): Promise<(Position.Automated | null)[]>;
|
|
28
29
|
getSubscriptions(options?: SubscriptionOptions): Promise<(Position.Automated | null)[]>;
|
|
29
30
|
getSubscriptionsFor(addresses: EthereumAddress[], options?: SubscriptionOptions): Promise<(Position.Automated | null)[]>;
|
|
@@ -87,6 +87,16 @@ class StrategiesAutomation extends Automation_1.default {
|
|
|
87
87
|
return true;
|
|
88
88
|
});
|
|
89
89
|
}
|
|
90
|
+
_mergeCheck(s, current) {
|
|
91
|
+
return s.owner === current.owner
|
|
92
|
+
&& s.strategy.strategyId === current.strategy.strategyId
|
|
93
|
+
&& s.protocol.id === current.protocol.id
|
|
94
|
+
&& s.specific.mergeId === current.specific.mergeWithId
|
|
95
|
+
&& (s.protocol.id !== enums_1.ProtocolIdentifiers.StrategiesAutomation.MakerDAO // reflexer needs to get added if we have it
|
|
96
|
+
|| s.strategyData.decoded.subData.vaultId === current.strategyData.decoded.triggerData.vaultId)
|
|
97
|
+
&& (s.protocol.id !== enums_1.ProtocolIdentifiers.StrategiesAutomation.CrvUSD // merge only crvUSD leverage management for the same market
|
|
98
|
+
|| s.strategyData.decoded.subData.controller.toLowerCase() === current.strategyData.decoded.triggerData.controller.toLowerCase());
|
|
99
|
+
}
|
|
90
100
|
_getSubscriptions(addresses, options) {
|
|
91
101
|
return __awaiter(this, void 0, void 0, function* () {
|
|
92
102
|
const _options = Object.assign(Object.assign({}, (0, utils_1.addToObjectIf)((0, utils_1.isDefined)(options), options)), (0, utils_1.addToObjectIf)((0, utils_1.isDefined)(addresses), { filter: { proxy: addresses } }));
|
|
@@ -118,35 +128,28 @@ class StrategiesAutomation extends Automation_1.default {
|
|
|
118
128
|
});
|
|
119
129
|
})));
|
|
120
130
|
if (options === null || options === void 0 ? void 0 : options.mergeWithSameId) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
const mergePair = copyList[mergePairIndex];
|
|
135
|
-
if ((0, utils_1.isDefined)(mergePair)) {
|
|
136
|
-
copyList[mergePairIndex] = Object.assign(Object.assign(Object.assign({}, mergePair), current), {
|
|
137
|
-
// @ts-ignore
|
|
138
|
-
blockNumber: decimal_js_1.default.max(mergePair.blockNumber, current.blockNumber).toNumber(), subIds: (0, utils_1.isDefined)(mergePair.subIds) ? [...mergePair.subIds, current.subId] : undefined, isEnabled: mergePair.isEnabled || current.isEnabled, subId: mergePair.subId, specific: Object.assign(Object.assign(Object.assign({}, mergePair.specific), current.specific), { mergeWithSameId: false }) });
|
|
139
|
-
return copyList;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
131
|
+
const mergeBase = subscriptions.filter(s => (0, utils_1.isDefined)(s) && s.specific.mergeWithId);
|
|
132
|
+
const mergeExtension = subscriptions.filter(s => (0, utils_1.isDefined)(s) && s.specific.mergeId);
|
|
133
|
+
subscriptions = subscriptions.filter(s => (0, utils_1.isDefined)(s) && !(s === null || s === void 0 ? void 0 : s.specific.mergeWithId) && !(s === null || s === void 0 ? void 0 : s.specific.mergeId)).map((s) => (Object.assign(Object.assign({}, s), { subIds: [s.subId] })));
|
|
134
|
+
mergeBase.forEach((current) => {
|
|
135
|
+
const mergePairIndexWithEnabledCheck = mergeExtension.findIndex(s => this._mergeCheck(s, current) && s.isEnabled === current.isEnabled);
|
|
136
|
+
const mergePairIndexWithoutEnabledCheck = mergeExtension.findIndex(s => this._mergeCheck(s, current));
|
|
137
|
+
const mergePairIndex = mergePairIndexWithEnabledCheck !== -1 ? mergePairIndexWithEnabledCheck : mergePairIndexWithoutEnabledCheck;
|
|
138
|
+
if (mergePairIndex !== -1) {
|
|
139
|
+
const mergePair = mergeExtension[mergePairIndex];
|
|
140
|
+
mergeExtension.splice(mergePairIndex, 1);
|
|
141
|
+
subscriptions.push(Object.assign(Object.assign(Object.assign({}, mergePair), current), {
|
|
142
|
+
// @ts-ignore
|
|
143
|
+
blockNumber: decimal_js_1.default.max(mergePair.blockNumber, current.blockNumber).toNumber(), subIds: [current.subId, mergePair.subId], isEnabled: mergePair.isEnabled || current.isEnabled, specific: Object.assign(Object.assign({}, mergePair.specific), current.specific) }));
|
|
143
144
|
}
|
|
144
145
|
else {
|
|
145
|
-
|
|
146
|
+
subscriptions.push(current);
|
|
146
147
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
148
|
+
});
|
|
149
|
+
if (mergeExtension.length > 0) {
|
|
150
|
+
console.error('Not all merge-able extensions were used', mergeExtension);
|
|
151
|
+
subscriptions = [...subscriptions, ...mergeExtension.map((s) => (Object.assign(Object.assign({}, s), { subIds: [s.subId] })))];
|
|
152
|
+
}
|
|
150
153
|
}
|
|
151
154
|
}
|
|
152
155
|
return _options.unexpiredOnly ? this.removeExpiredSubscriptions(subscriptions) : subscriptions;
|
|
@@ -103,6 +103,7 @@ function parseMakerLeverageManagement(position, parseData) {
|
|
|
103
103
|
targetRepayRatio: subData.targetRatio,
|
|
104
104
|
repayEnabled: true,
|
|
105
105
|
subId1: Number(subId),
|
|
106
|
+
mergeWithId: enums_1.Strategies.Identifiers.Boost,
|
|
106
107
|
};
|
|
107
108
|
}
|
|
108
109
|
else {
|
|
@@ -111,10 +112,10 @@ function parseMakerLeverageManagement(position, parseData) {
|
|
|
111
112
|
targetBoostRatio: subData.targetRatio,
|
|
112
113
|
boostEnabled: isEnabled,
|
|
113
114
|
subId2: Number(subId),
|
|
115
|
+
mergeId: enums_1.Strategies.Identifiers.Boost,
|
|
114
116
|
};
|
|
115
117
|
}
|
|
116
118
|
_position.strategy.strategyId = enums_1.Strategies.IdOverrides.LeverageManagement;
|
|
117
|
-
_position.specific.mergeWithSameId = true;
|
|
118
119
|
return _position;
|
|
119
120
|
}
|
|
120
121
|
function parseLiquityCloseOnPrice(position, parseData) {
|
|
@@ -165,6 +166,7 @@ function parseAaveV2LeverageManagement(position, parseData) {
|
|
|
165
166
|
targetRepayRatio: subData.targetRatio,
|
|
166
167
|
repayEnabled: true,
|
|
167
168
|
subId1: Number(subId),
|
|
169
|
+
mergeWithId: enums_1.Strategies.Identifiers.Boost,
|
|
168
170
|
};
|
|
169
171
|
}
|
|
170
172
|
else {
|
|
@@ -173,10 +175,10 @@ function parseAaveV2LeverageManagement(position, parseData) {
|
|
|
173
175
|
targetBoostRatio: subData.targetRatio,
|
|
174
176
|
boostEnabled: isEnabled,
|
|
175
177
|
subId2: Number(subId),
|
|
178
|
+
mergeId: enums_1.Strategies.Identifiers.Boost,
|
|
176
179
|
};
|
|
177
180
|
}
|
|
178
181
|
_position.strategy.strategyId = enums_1.Strategies.IdOverrides.LeverageManagement;
|
|
179
|
-
_position.specific.mergeWithSameId = true;
|
|
180
182
|
return _position;
|
|
181
183
|
}
|
|
182
184
|
function parseAaveV3LeverageManagement(position, parseData) {
|
|
@@ -195,6 +197,7 @@ function parseAaveV3LeverageManagement(position, parseData) {
|
|
|
195
197
|
targetRepayRatio: subData.targetRatio,
|
|
196
198
|
repayEnabled: true,
|
|
197
199
|
subId1: Number(subId),
|
|
200
|
+
mergeWithId: enums_1.Strategies.Identifiers.Boost,
|
|
198
201
|
};
|
|
199
202
|
}
|
|
200
203
|
else {
|
|
@@ -203,10 +206,10 @@ function parseAaveV3LeverageManagement(position, parseData) {
|
|
|
203
206
|
targetBoostRatio: subData.targetRatio,
|
|
204
207
|
boostEnabled: isEnabled,
|
|
205
208
|
subId2: Number(subId),
|
|
209
|
+
mergeId: enums_1.Strategies.Identifiers.Boost,
|
|
206
210
|
};
|
|
207
211
|
}
|
|
208
212
|
_position.strategy.strategyId = enums_1.Strategies.IdOverrides.LeverageManagement;
|
|
209
|
-
_position.specific.mergeWithSameId = true;
|
|
210
213
|
return _position;
|
|
211
214
|
}
|
|
212
215
|
function parseMorphoAaveV2LeverageManagement(position, parseData) {
|
|
@@ -225,6 +228,7 @@ function parseMorphoAaveV2LeverageManagement(position, parseData) {
|
|
|
225
228
|
targetRepayRatio: subData.targetRatio,
|
|
226
229
|
repayEnabled: true,
|
|
227
230
|
subId1: Number(subId),
|
|
231
|
+
mergeWithId: enums_1.Strategies.Identifiers.Boost,
|
|
228
232
|
};
|
|
229
233
|
}
|
|
230
234
|
else {
|
|
@@ -233,10 +237,10 @@ function parseMorphoAaveV2LeverageManagement(position, parseData) {
|
|
|
233
237
|
targetBoostRatio: subData.targetRatio,
|
|
234
238
|
boostEnabled: isEnabled,
|
|
235
239
|
subId2: Number(subId),
|
|
240
|
+
mergeId: enums_1.Strategies.Identifiers.Boost,
|
|
236
241
|
};
|
|
237
242
|
}
|
|
238
243
|
_position.strategy.strategyId = enums_1.Strategies.IdOverrides.LeverageManagement;
|
|
239
|
-
_position.specific.mergeWithSameId = true;
|
|
240
244
|
return _position;
|
|
241
245
|
}
|
|
242
246
|
function parseAaveV3CloseOnPrice(position, parseData) {
|
|
@@ -303,6 +307,7 @@ function parseCompoundV2LeverageManagement(position, parseData) {
|
|
|
303
307
|
targetRepayRatio: subData.targetRatio,
|
|
304
308
|
repayEnabled: true,
|
|
305
309
|
subId1: Number(subId),
|
|
310
|
+
mergeWithId: enums_1.Strategies.Identifiers.Boost,
|
|
306
311
|
};
|
|
307
312
|
}
|
|
308
313
|
else {
|
|
@@ -311,10 +316,10 @@ function parseCompoundV2LeverageManagement(position, parseData) {
|
|
|
311
316
|
targetBoostRatio: subData.targetRatio,
|
|
312
317
|
boostEnabled: isEnabled,
|
|
313
318
|
subId2: Number(subId),
|
|
319
|
+
mergeId: enums_1.Strategies.Identifiers.Boost,
|
|
314
320
|
};
|
|
315
321
|
}
|
|
316
322
|
_position.strategy.strategyId = enums_1.Strategies.IdOverrides.LeverageManagement;
|
|
317
|
-
_position.specific.mergeWithSameId = true;
|
|
318
323
|
return _position;
|
|
319
324
|
}
|
|
320
325
|
function parseCompoundV3LeverageManagement(position, parseData) {
|
|
@@ -337,6 +342,7 @@ function parseCompoundV3LeverageManagement(position, parseData) {
|
|
|
337
342
|
targetRepayRatio: subData.targetRatio,
|
|
338
343
|
repayEnabled: true,
|
|
339
344
|
subId1: Number(subId),
|
|
345
|
+
mergeWithId: enums_1.Strategies.Identifiers.Boost,
|
|
340
346
|
};
|
|
341
347
|
}
|
|
342
348
|
else {
|
|
@@ -345,11 +351,11 @@ function parseCompoundV3LeverageManagement(position, parseData) {
|
|
|
345
351
|
targetBoostRatio: subData.targetRatio,
|
|
346
352
|
boostEnabled: isEnabled,
|
|
347
353
|
subId2: Number(subId),
|
|
354
|
+
mergeId: enums_1.Strategies.Identifiers.Boost,
|
|
348
355
|
};
|
|
349
356
|
}
|
|
350
357
|
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
351
358
|
_position.strategy.strategyId = isEOA ? enums_1.Strategies.IdOverrides.EoaLeverageManagement : enums_1.Strategies.IdOverrides.LeverageManagement;
|
|
352
|
-
_position.specific.mergeWithSameId = true;
|
|
353
359
|
return _position;
|
|
354
360
|
}
|
|
355
361
|
function parseChickenBondsRebond(position, parseData) {
|
|
@@ -408,6 +414,7 @@ function parseLiquityLeverageManagement(position, parseData) {
|
|
|
408
414
|
targetRepayRatio: subData.targetRatio,
|
|
409
415
|
repayEnabled: true,
|
|
410
416
|
subId1: Number(subId),
|
|
417
|
+
mergeWithId: enums_1.Strategies.Identifiers.Boost,
|
|
411
418
|
};
|
|
412
419
|
}
|
|
413
420
|
else {
|
|
@@ -416,10 +423,10 @@ function parseLiquityLeverageManagement(position, parseData) {
|
|
|
416
423
|
targetBoostRatio: subData.targetRatio,
|
|
417
424
|
boostEnabled: isEnabled,
|
|
418
425
|
subId2: Number(subId),
|
|
426
|
+
mergeId: enums_1.Strategies.Identifiers.Boost,
|
|
419
427
|
};
|
|
420
428
|
}
|
|
421
429
|
_position.strategy.strategyId = enums_1.Strategies.IdOverrides.LeverageManagement;
|
|
422
|
-
_position.specific.mergeWithSameId = true;
|
|
423
430
|
return _position;
|
|
424
431
|
}
|
|
425
432
|
function parseSparkLeverageManagement(position, parseData) {
|
|
@@ -438,6 +445,7 @@ function parseSparkLeverageManagement(position, parseData) {
|
|
|
438
445
|
targetRepayRatio: subData.targetRatio,
|
|
439
446
|
repayEnabled: true,
|
|
440
447
|
subId1: Number(subId),
|
|
448
|
+
mergeWithId: enums_1.Strategies.Identifiers.Boost,
|
|
441
449
|
};
|
|
442
450
|
}
|
|
443
451
|
else {
|
|
@@ -446,10 +454,10 @@ function parseSparkLeverageManagement(position, parseData) {
|
|
|
446
454
|
targetBoostRatio: subData.targetRatio,
|
|
447
455
|
boostEnabled: isEnabled,
|
|
448
456
|
subId2: Number(subId),
|
|
457
|
+
mergeId: enums_1.Strategies.Identifiers.Boost,
|
|
449
458
|
};
|
|
450
459
|
}
|
|
451
460
|
_position.strategy.strategyId = enums_1.Strategies.IdOverrides.LeverageManagement;
|
|
452
|
-
_position.specific.mergeWithSameId = true;
|
|
453
461
|
return _position;
|
|
454
462
|
}
|
|
455
463
|
function parseSparkCloseOnPrice(position, parseData) {
|
|
@@ -520,6 +528,7 @@ function parseCrvUSDLeverageManagement(position, parseData) {
|
|
|
520
528
|
repayEnabled: isEnabled,
|
|
521
529
|
subId1: Number(subId),
|
|
522
530
|
subHashRepay: subHash,
|
|
531
|
+
mergeWithId: enums_1.Strategies.Identifiers.Boost,
|
|
523
532
|
};
|
|
524
533
|
}
|
|
525
534
|
else {
|
|
@@ -529,11 +538,11 @@ function parseCrvUSDLeverageManagement(position, parseData) {
|
|
|
529
538
|
boostEnabled: isEnabled,
|
|
530
539
|
subId2: Number(subId),
|
|
531
540
|
subHashBoost: subHash,
|
|
541
|
+
mergeId: enums_1.Strategies.Identifiers.Boost,
|
|
532
542
|
};
|
|
533
543
|
}
|
|
534
544
|
_position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, triggerData.controller);
|
|
535
545
|
_position.strategy.strategyId = enums_1.Strategies.IdOverrides.LeverageManagement;
|
|
536
|
-
_position.specific.mergeWithSameId = true;
|
|
537
546
|
return _position;
|
|
538
547
|
}
|
|
539
548
|
const parsingMethodsMapping = {
|
|
@@ -183,8 +183,8 @@ exports.compoundV3LeverageManagementSubData = {
|
|
|
183
183
|
exports.compoundV3L2LeverageManagementSubData = {
|
|
184
184
|
encode(market, baseToken, triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled) {
|
|
185
185
|
let subInput = '0x';
|
|
186
|
-
subInput = subInput.concat(market.slice(2)
|
|
187
|
-
subInput = subInput.concat(baseToken.slice(2)
|
|
186
|
+
subInput = subInput.concat(market.slice(2));
|
|
187
|
+
subInput = subInput.concat(baseToken.slice(2));
|
|
188
188
|
subInput = subInput.concat(new decimal_js_1.default(triggerRepayRatio).mul(1e16).toHex().slice(2)
|
|
189
189
|
.padStart(32, '0'));
|
|
190
190
|
subInput = subInput.concat(new decimal_js_1.default(triggerBoostRatio).mul(1e16).toHex().slice(2)
|
package/esm/types/index.d.ts
CHANGED
|
@@ -95,7 +95,8 @@ export declare namespace Position {
|
|
|
95
95
|
interface Base {
|
|
96
96
|
subId1?: number;
|
|
97
97
|
subId2?: number;
|
|
98
|
-
|
|
98
|
+
mergeWithId?: Strategies.Identifiers;
|
|
99
|
+
mergeId?: Strategies.Identifiers;
|
|
99
100
|
}
|
|
100
101
|
interface RatioProtection extends Base {
|
|
101
102
|
triggerRepayRatio?: number;
|
package/package.json
CHANGED
|
@@ -107,6 +107,21 @@ export default class StrategiesAutomation extends Automation {
|
|
|
107
107
|
});
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
+
private _mergeCheck(s:Position.Automated, current:Position.Automated) {
|
|
111
|
+
return s.owner === current.owner
|
|
112
|
+
&& s.strategy.strategyId === current.strategy.strategyId
|
|
113
|
+
&& s.protocol.id === current.protocol.id
|
|
114
|
+
&& s.specific.mergeId === current.specific.mergeWithId
|
|
115
|
+
&& (
|
|
116
|
+
s.protocol.id !== ProtocolIdentifiers.StrategiesAutomation.MakerDAO // reflexer needs to get added if we have it
|
|
117
|
+
|| s.strategyData.decoded.subData.vaultId === current.strategyData.decoded.triggerData.vaultId
|
|
118
|
+
)
|
|
119
|
+
&& (
|
|
120
|
+
s.protocol.id !== ProtocolIdentifiers.StrategiesAutomation.CrvUSD // merge only crvUSD leverage management for the same market
|
|
121
|
+
|| s.strategyData.decoded.subData.controller.toLowerCase() === current.strategyData.decoded.triggerData.controller.toLowerCase()
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
|
|
110
125
|
protected async _getSubscriptions(addresses?: EthereumAddress[], options?: SubscriptionOptions): Promise<(Position.Automated | null)[]> {
|
|
111
126
|
const _options = {
|
|
112
127
|
...addToObjectIf(isDefined(options), options),
|
|
@@ -155,58 +170,45 @@ export default class StrategiesAutomation extends Automation {
|
|
|
155
170
|
}));
|
|
156
171
|
|
|
157
172
|
if (options?.mergeWithSameId) {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
subIds: isDefined(mergePair.subIds) ? [...mergePair.subIds, current.subId] : undefined,
|
|
187
|
-
isEnabled: mergePair.isEnabled || current.isEnabled,
|
|
188
|
-
subId: mergePair.subId,
|
|
189
|
-
specific: {
|
|
190
|
-
...mergePair.specific,
|
|
191
|
-
...current.specific,
|
|
192
|
-
mergeWithSameId: false,
|
|
193
|
-
},
|
|
194
|
-
};
|
|
195
|
-
return copyList;
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
}
|
|
173
|
+
const mergeBase = subscriptions.filter(s => isDefined(s) && s.specific.mergeWithId) as Position.Automated[];
|
|
174
|
+
const mergeExtension = subscriptions.filter(s => isDefined(s) && s.specific.mergeId) as Position.Automated[];
|
|
175
|
+
|
|
176
|
+
subscriptions = (subscriptions.filter(s => isDefined(s) && !s?.specific.mergeWithId && !s?.specific.mergeId) as Position.Automated[]).map((s) => ({
|
|
177
|
+
...s,
|
|
178
|
+
subIds: [s.subId],
|
|
179
|
+
}));
|
|
180
|
+
mergeBase.forEach((current) => {
|
|
181
|
+
const mergePairIndexWithEnabledCheck = mergeExtension.findIndex(s => this._mergeCheck(s, current) && s.isEnabled === current.isEnabled);
|
|
182
|
+
const mergePairIndexWithoutEnabledCheck = mergeExtension.findIndex(s => this._mergeCheck(s, current));
|
|
183
|
+
|
|
184
|
+
const mergePairIndex = mergePairIndexWithEnabledCheck !== -1 ? mergePairIndexWithEnabledCheck : mergePairIndexWithoutEnabledCheck;
|
|
185
|
+
|
|
186
|
+
if (mergePairIndex !== -1) {
|
|
187
|
+
const mergePair = mergeExtension[mergePairIndex];
|
|
188
|
+
mergeExtension.splice(mergePairIndex, 1);
|
|
189
|
+
subscriptions.push({
|
|
190
|
+
...mergePair,
|
|
191
|
+
...current,
|
|
192
|
+
// @ts-ignore
|
|
193
|
+
blockNumber: Dec.max(mergePair.blockNumber, current.blockNumber).toNumber(),
|
|
194
|
+
subIds: [current.subId, mergePair.subId],
|
|
195
|
+
isEnabled: mergePair.isEnabled || current.isEnabled,
|
|
196
|
+
specific: {
|
|
197
|
+
...mergePair.specific,
|
|
198
|
+
...current.specific,
|
|
199
|
+
},
|
|
200
|
+
});
|
|
199
201
|
} else {
|
|
200
|
-
|
|
202
|
+
subscriptions.push(current);
|
|
201
203
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
}
|
|
204
|
+
});
|
|
205
|
+
if (mergeExtension.length > 0) {
|
|
206
|
+
console.error('Not all merge-able extensions were used', mergeExtension);
|
|
207
|
+
subscriptions = [...subscriptions, ...mergeExtension.map((s) => ({
|
|
208
|
+
...s,
|
|
209
|
+
subIds: [s.subId],
|
|
210
|
+
}))];
|
|
211
|
+
}
|
|
210
212
|
}
|
|
211
213
|
}
|
|
212
214
|
|
|
@@ -118,6 +118,7 @@ function parseMakerLeverageManagement(position: Position.Automated, parseData: P
|
|
|
118
118
|
targetRepayRatio: subData.targetRatio,
|
|
119
119
|
repayEnabled: true,
|
|
120
120
|
subId1: Number(subId),
|
|
121
|
+
mergeWithId: Strategies.Identifiers.Boost,
|
|
121
122
|
};
|
|
122
123
|
} else {
|
|
123
124
|
_position.specific = {
|
|
@@ -125,11 +126,11 @@ function parseMakerLeverageManagement(position: Position.Automated, parseData: P
|
|
|
125
126
|
targetBoostRatio: subData.targetRatio,
|
|
126
127
|
boostEnabled: isEnabled,
|
|
127
128
|
subId2: Number(subId),
|
|
129
|
+
mergeId: Strategies.Identifiers.Boost,
|
|
128
130
|
};
|
|
129
131
|
}
|
|
130
132
|
|
|
131
133
|
_position.strategy.strategyId = Strategies.IdOverrides.LeverageManagement;
|
|
132
|
-
_position.specific.mergeWithSameId = true;
|
|
133
134
|
|
|
134
135
|
return _position;
|
|
135
136
|
}
|
|
@@ -205,6 +206,7 @@ function parseAaveV2LeverageManagement(position: Position.Automated, parseData:
|
|
|
205
206
|
targetRepayRatio: subData.targetRatio,
|
|
206
207
|
repayEnabled: true,
|
|
207
208
|
subId1: Number(subId),
|
|
209
|
+
mergeWithId: Strategies.Identifiers.Boost,
|
|
208
210
|
};
|
|
209
211
|
} else {
|
|
210
212
|
_position.specific = {
|
|
@@ -212,11 +214,11 @@ function parseAaveV2LeverageManagement(position: Position.Automated, parseData:
|
|
|
212
214
|
targetBoostRatio: subData.targetRatio,
|
|
213
215
|
boostEnabled: isEnabled,
|
|
214
216
|
subId2: Number(subId),
|
|
217
|
+
mergeId: Strategies.Identifiers.Boost,
|
|
215
218
|
};
|
|
216
219
|
}
|
|
217
220
|
|
|
218
221
|
_position.strategy.strategyId = Strategies.IdOverrides.LeverageManagement;
|
|
219
|
-
_position.specific.mergeWithSameId = true;
|
|
220
222
|
|
|
221
223
|
return _position;
|
|
222
224
|
}
|
|
@@ -243,6 +245,7 @@ function parseAaveV3LeverageManagement(position: Position.Automated, parseData:
|
|
|
243
245
|
targetRepayRatio: subData.targetRatio,
|
|
244
246
|
repayEnabled: true,
|
|
245
247
|
subId1: Number(subId),
|
|
248
|
+
mergeWithId: Strategies.Identifiers.Boost,
|
|
246
249
|
};
|
|
247
250
|
} else {
|
|
248
251
|
_position.specific = {
|
|
@@ -250,11 +253,11 @@ function parseAaveV3LeverageManagement(position: Position.Automated, parseData:
|
|
|
250
253
|
targetBoostRatio: subData.targetRatio,
|
|
251
254
|
boostEnabled: isEnabled,
|
|
252
255
|
subId2: Number(subId),
|
|
256
|
+
mergeId: Strategies.Identifiers.Boost,
|
|
253
257
|
};
|
|
254
258
|
}
|
|
255
259
|
|
|
256
260
|
_position.strategy.strategyId = Strategies.IdOverrides.LeverageManagement;
|
|
257
|
-
_position.specific.mergeWithSameId = true;
|
|
258
261
|
|
|
259
262
|
return _position;
|
|
260
263
|
}
|
|
@@ -281,6 +284,7 @@ function parseMorphoAaveV2LeverageManagement(position: Position.Automated, parse
|
|
|
281
284
|
targetRepayRatio: subData.targetRatio,
|
|
282
285
|
repayEnabled: true,
|
|
283
286
|
subId1: Number(subId),
|
|
287
|
+
mergeWithId: Strategies.Identifiers.Boost,
|
|
284
288
|
};
|
|
285
289
|
} else {
|
|
286
290
|
_position.specific = {
|
|
@@ -288,11 +292,11 @@ function parseMorphoAaveV2LeverageManagement(position: Position.Automated, parse
|
|
|
288
292
|
targetBoostRatio: subData.targetRatio,
|
|
289
293
|
boostEnabled: isEnabled,
|
|
290
294
|
subId2: Number(subId),
|
|
295
|
+
mergeId: Strategies.Identifiers.Boost,
|
|
291
296
|
};
|
|
292
297
|
}
|
|
293
298
|
|
|
294
299
|
_position.strategy.strategyId = Strategies.IdOverrides.LeverageManagement;
|
|
295
|
-
_position.specific.mergeWithSameId = true;
|
|
296
300
|
|
|
297
301
|
return _position;
|
|
298
302
|
}
|
|
@@ -395,6 +399,7 @@ function parseCompoundV2LeverageManagement(position: Position.Automated, parseDa
|
|
|
395
399
|
targetRepayRatio: subData.targetRatio,
|
|
396
400
|
repayEnabled: true,
|
|
397
401
|
subId1: Number(subId),
|
|
402
|
+
mergeWithId: Strategies.Identifiers.Boost,
|
|
398
403
|
};
|
|
399
404
|
} else {
|
|
400
405
|
_position.specific = {
|
|
@@ -402,11 +407,11 @@ function parseCompoundV2LeverageManagement(position: Position.Automated, parseDa
|
|
|
402
407
|
targetBoostRatio: subData.targetRatio,
|
|
403
408
|
boostEnabled: isEnabled,
|
|
404
409
|
subId2: Number(subId),
|
|
410
|
+
mergeId: Strategies.Identifiers.Boost,
|
|
405
411
|
};
|
|
406
412
|
}
|
|
407
413
|
|
|
408
414
|
_position.strategy.strategyId = Strategies.IdOverrides.LeverageManagement;
|
|
409
|
-
_position.specific.mergeWithSameId = true;
|
|
410
415
|
|
|
411
416
|
return _position;
|
|
412
417
|
}
|
|
@@ -438,6 +443,7 @@ function parseCompoundV3LeverageManagement(position: Position.Automated, parseDa
|
|
|
438
443
|
targetRepayRatio: subData.targetRatio,
|
|
439
444
|
repayEnabled: true,
|
|
440
445
|
subId1: Number(subId),
|
|
446
|
+
mergeWithId: Strategies.Identifiers.Boost,
|
|
441
447
|
};
|
|
442
448
|
} else {
|
|
443
449
|
_position.specific = {
|
|
@@ -445,13 +451,13 @@ function parseCompoundV3LeverageManagement(position: Position.Automated, parseDa
|
|
|
445
451
|
targetBoostRatio: subData.targetRatio,
|
|
446
452
|
boostEnabled: isEnabled,
|
|
447
453
|
subId2: Number(subId),
|
|
454
|
+
mergeId: Strategies.Identifiers.Boost,
|
|
448
455
|
};
|
|
449
456
|
}
|
|
450
457
|
|
|
451
458
|
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
452
459
|
_position.strategy.strategyId = isEOA ? Strategies.IdOverrides.EoaLeverageManagement : Strategies.IdOverrides.LeverageManagement;
|
|
453
460
|
|
|
454
|
-
_position.specific.mergeWithSameId = true;
|
|
455
461
|
|
|
456
462
|
return _position;
|
|
457
463
|
}
|
|
@@ -539,6 +545,7 @@ function parseLiquityLeverageManagement(position: Position.Automated, parseData:
|
|
|
539
545
|
targetRepayRatio: subData.targetRatio,
|
|
540
546
|
repayEnabled: true,
|
|
541
547
|
subId1: Number(subId),
|
|
548
|
+
mergeWithId: Strategies.Identifiers.Boost,
|
|
542
549
|
};
|
|
543
550
|
} else {
|
|
544
551
|
_position.specific = {
|
|
@@ -546,11 +553,11 @@ function parseLiquityLeverageManagement(position: Position.Automated, parseData:
|
|
|
546
553
|
targetBoostRatio: subData.targetRatio,
|
|
547
554
|
boostEnabled: isEnabled,
|
|
548
555
|
subId2: Number(subId),
|
|
556
|
+
mergeId: Strategies.Identifiers.Boost,
|
|
549
557
|
};
|
|
550
558
|
}
|
|
551
559
|
|
|
552
560
|
_position.strategy.strategyId = Strategies.IdOverrides.LeverageManagement;
|
|
553
|
-
_position.specific.mergeWithSameId = true;
|
|
554
561
|
|
|
555
562
|
return _position;
|
|
556
563
|
}
|
|
@@ -577,6 +584,7 @@ function parseSparkLeverageManagement(position: Position.Automated, parseData: P
|
|
|
577
584
|
targetRepayRatio: subData.targetRatio,
|
|
578
585
|
repayEnabled: true,
|
|
579
586
|
subId1: Number(subId),
|
|
587
|
+
mergeWithId: Strategies.Identifiers.Boost,
|
|
580
588
|
};
|
|
581
589
|
} else {
|
|
582
590
|
_position.specific = {
|
|
@@ -584,11 +592,11 @@ function parseSparkLeverageManagement(position: Position.Automated, parseData: P
|
|
|
584
592
|
targetBoostRatio: subData.targetRatio,
|
|
585
593
|
boostEnabled: isEnabled,
|
|
586
594
|
subId2: Number(subId),
|
|
595
|
+
mergeId: Strategies.Identifiers.Boost,
|
|
587
596
|
};
|
|
588
597
|
}
|
|
589
598
|
|
|
590
599
|
_position.strategy.strategyId = Strategies.IdOverrides.LeverageManagement;
|
|
591
|
-
_position.specific.mergeWithSameId = true;
|
|
592
600
|
|
|
593
601
|
return _position;
|
|
594
602
|
}
|
|
@@ -692,6 +700,7 @@ function parseCrvUSDLeverageManagement(position: Position.Automated, parseData:
|
|
|
692
700
|
repayEnabled: isEnabled,
|
|
693
701
|
subId1: Number(subId),
|
|
694
702
|
subHashRepay: subHash,
|
|
703
|
+
mergeWithId: Strategies.Identifiers.Boost,
|
|
695
704
|
};
|
|
696
705
|
} else {
|
|
697
706
|
_position.specific = {
|
|
@@ -700,12 +709,12 @@ function parseCrvUSDLeverageManagement(position: Position.Automated, parseData:
|
|
|
700
709
|
boostEnabled: isEnabled,
|
|
701
710
|
subId2: Number(subId),
|
|
702
711
|
subHashBoost: subHash,
|
|
712
|
+
mergeId: Strategies.Identifiers.Boost,
|
|
703
713
|
};
|
|
704
714
|
}
|
|
705
715
|
|
|
706
716
|
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, triggerData.controller);
|
|
707
717
|
_position.strategy.strategyId = Strategies.IdOverrides.LeverageManagement;
|
|
708
|
-
_position.specific.mergeWithSameId = true;
|
|
709
718
|
|
|
710
719
|
return _position;
|
|
711
720
|
}
|
|
@@ -3,7 +3,7 @@ import AbiCoder from 'web3-eth-abi';
|
|
|
3
3
|
import { assetAmountInEth, getAssetInfo, getAssetInfoByAddress } from '@defisaver/tokens';
|
|
4
4
|
import { otherAddresses } from '@defisaver/sdk';
|
|
5
5
|
|
|
6
|
-
import type {
|
|
6
|
+
import type { SubData, EthereumAddress } from '../types';
|
|
7
7
|
import type { OrderType } from '../types/enums';
|
|
8
8
|
import { ChainId, RatioState } from '../types/enums';
|
|
9
9
|
|
|
@@ -267,8 +267,8 @@ export const compoundV3L2LeverageManagementSubData = {
|
|
|
267
267
|
): string {
|
|
268
268
|
let subInput = '0x';
|
|
269
269
|
|
|
270
|
-
subInput = subInput.concat(market.slice(2)
|
|
271
|
-
subInput = subInput.concat(baseToken.slice(2)
|
|
270
|
+
subInput = subInput.concat(market.slice(2));
|
|
271
|
+
subInput = subInput.concat(baseToken.slice(2));
|
|
272
272
|
subInput = subInput.concat(new Dec(triggerRepayRatio).mul(1e16).toHex().slice(2)
|
|
273
273
|
.padStart(32, '0'));
|
|
274
274
|
subInput = subInput.concat(new Dec(triggerBoostRatio).mul(1e16).toHex().slice(2)
|
package/src/types/index.ts
CHANGED
|
@@ -120,7 +120,8 @@ export declare namespace Position {
|
|
|
120
120
|
interface Base {
|
|
121
121
|
subId1?: number,
|
|
122
122
|
subId2?: number,
|
|
123
|
-
|
|
123
|
+
mergeWithId?: Strategies.Identifiers,
|
|
124
|
+
mergeId?: Strategies.Identifiers
|
|
124
125
|
}
|
|
125
126
|
interface RatioProtection extends Base {
|
|
126
127
|
triggerRepayRatio?: number,
|