@defisaver/automation-sdk 3.0.0 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.dev +1 -1
- package/README.md +3 -3
- package/esm/automation/private/StrategiesAutomation.d.ts +1 -0
- package/esm/automation/private/StrategiesAutomation.js +27 -23
- package/esm/automation/private/StrategiesAutomation.test.d.ts +1 -0
- package/esm/automation/private/StrategiesAutomation.test.js +670 -0
- package/esm/types/index.d.ts +1 -1
- package/package.json +1 -1
- package/src/automation/private/StrategiesAutomation.test.ts +661 -0
- package/src/automation/private/StrategiesAutomation.ts +49 -41
- package/src/types/index.ts +1 -1
- package/umd/index.js +36 -30
package/.env.dev
CHANGED
package/README.md
CHANGED
|
@@ -15,10 +15,10 @@ const ethereumStrategies = new EthereumStrategies({
|
|
|
15
15
|
const subscriptions = await ethereumStrategies.getSubscriptionsFor(
|
|
16
16
|
// Pass one or multiple owner addresses, or use getSubscriptions method to fetch all subscriptions
|
|
17
17
|
['0x000000000000000000000000000000000000dEaD'],
|
|
18
|
-
{
|
|
18
|
+
{
|
|
19
19
|
fromBlock: 0,
|
|
20
20
|
toBlock: 'latest',
|
|
21
|
-
|
|
21
|
+
mergeSubs: true, // Used for merging subscriptions with same strategy ID (e.g. boost and repay)
|
|
22
22
|
enabledOnly: true,
|
|
23
23
|
unexpiredOnly: true, // Referring to exchange subscriptions
|
|
24
24
|
}
|
|
@@ -38,4 +38,4 @@ const subscriptions = await ethereumStrategies.getSubscriptionsFor(
|
|
|
38
38
|
- Write parsing for the strategy in `./src/services/strategeiesService.ts` and add assign it to `const parsingMethodsMapping`
|
|
39
39
|
- Write tests for each method
|
|
40
40
|
- Run tests with `yarn test` or `yarn test fileName` for a specific file (e.g. `yarn test utils`)
|
|
41
|
-
- Congrats! 🥳
|
|
41
|
+
- Congrats! 🥳
|
|
@@ -25,6 +25,7 @@ export default class StrategiesAutomation extends Automation {
|
|
|
25
25
|
*/
|
|
26
26
|
protected removeExpiredSubscriptions(subscriptions: (Position.Automated | null)[]): (Position.Automated | null)[];
|
|
27
27
|
private _mergeCheck;
|
|
28
|
+
protected mergeSubs(_subscriptions: (Position.Automated | null)[]): Position.Automated[];
|
|
28
29
|
protected _getSubscriptions(addresses?: EthereumAddress[], options?: SubscriptionOptions): Promise<(Position.Automated | null)[]>;
|
|
29
30
|
getSubscriptions(options?: SubscriptionOptions): Promise<(Position.Automated | null)[]>;
|
|
30
31
|
getSubscriptionsFor(addresses: EthereumAddress[], options?: SubscriptionOptions): Promise<(Position.Automated | null)[]>;
|
|
@@ -97,6 +97,31 @@ class StrategiesAutomation extends Automation_1.default {
|
|
|
97
97
|
&& (s.protocol.id !== enums_1.ProtocolIdentifiers.StrategiesAutomation.CrvUSD // merge only crvUSD leverage management for the same market
|
|
98
98
|
|| s.strategyData.decoded.subData.controller.toLowerCase() === current.strategyData.decoded.triggerData.controller.toLowerCase());
|
|
99
99
|
}
|
|
100
|
+
mergeSubs(_subscriptions) {
|
|
101
|
+
const mergeBase = _subscriptions.filter(s => (0, utils_1.isDefined)(s) && (0, utils_1.isDefined)(s.specific.mergeWithId));
|
|
102
|
+
const mergeExtension = _subscriptions.filter(s => (0, utils_1.isDefined)(s) && (0, utils_1.isDefined)(s.specific.mergeId));
|
|
103
|
+
let subscriptions = _subscriptions.filter(s => (0, utils_1.isDefined)(s) && (0, utils_1.isUndefined)(s.specific.mergeWithId) && (0, utils_1.isUndefined)(s.specific.mergeId)).map((s) => (Object.assign(Object.assign({}, s), { subIds: [s.subId] })));
|
|
104
|
+
mergeBase.forEach((current) => {
|
|
105
|
+
const mergePairIndexSubEnabled = mergeExtension.findIndex(s => this._mergeCheck(s, current) && s.isEnabled === current.isEnabled);
|
|
106
|
+
const mergePairIndexSubDisabled = mergeExtension.findIndex(s => this._mergeCheck(s, current));
|
|
107
|
+
const mergePairIndex = mergePairIndexSubEnabled !== -1 ? mergePairIndexSubEnabled : mergePairIndexSubDisabled;
|
|
108
|
+
if (mergePairIndex !== -1) {
|
|
109
|
+
const mergePair = mergeExtension[mergePairIndex];
|
|
110
|
+
mergeExtension.splice(mergePairIndex, 1);
|
|
111
|
+
subscriptions.push(Object.assign(Object.assign(Object.assign({}, mergePair), current), {
|
|
112
|
+
// @ts-ignore
|
|
113
|
+
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) }));
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
subscriptions.push(Object.assign(Object.assign({}, current), { subIds: [current.subId] }));
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
if (mergeExtension.length > 0) {
|
|
120
|
+
console.error('Not all merge-able extensions were used', mergeExtension);
|
|
121
|
+
subscriptions = [...subscriptions, ...mergeExtension.map((s) => (Object.assign(Object.assign({}, s), { subIds: [s.subId] })))];
|
|
122
|
+
}
|
|
123
|
+
return subscriptions;
|
|
124
|
+
}
|
|
100
125
|
_getSubscriptions(addresses, options) {
|
|
101
126
|
return __awaiter(this, void 0, void 0, function* () {
|
|
102
127
|
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 } }));
|
|
@@ -127,29 +152,8 @@ class StrategiesAutomation extends Automation_1.default {
|
|
|
127
152
|
strategiesSubsData: sub,
|
|
128
153
|
});
|
|
129
154
|
})));
|
|
130
|
-
if (options === null || options === void 0 ? void 0 : options.
|
|
131
|
-
|
|
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) }));
|
|
144
|
-
}
|
|
145
|
-
else {
|
|
146
|
-
subscriptions.push(current);
|
|
147
|
-
}
|
|
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
|
-
}
|
|
155
|
+
if (options === null || options === void 0 ? void 0 : options.mergeSubs) {
|
|
156
|
+
subscriptions = this.mergeSubs(subscriptions);
|
|
153
157
|
}
|
|
154
158
|
}
|
|
155
159
|
return _options.unexpiredOnly ? this.removeExpiredSubscriptions(subscriptions) : subscriptions;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|