@defisaver/automation-sdk 3.0.0 → 3.0.2-dev
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/LegacyAutomation.js +2 -2
- package/esm/automation/private/StrategiesAutomation.d.ts +1 -0
- package/esm/automation/private/StrategiesAutomation.js +34 -24
- package/esm/automation/private/StrategiesAutomation.test.d.ts +1 -0
- package/esm/automation/private/StrategiesAutomation.test.js +671 -0
- package/esm/constants/index.js +10 -0
- package/esm/services/ethereumService.test.d.ts +1 -1
- package/esm/services/ethereumService.test.js +1 -0
- package/esm/services/strategiesService.js +37 -0
- package/esm/services/strategiesService.test.d.ts +1 -1
- package/esm/services/strategiesService.test.js +1 -0
- package/esm/services/strategySubService.d.ts +3 -0
- package/esm/services/strategySubService.js +11 -1
- package/esm/services/strategySubService.test.d.ts +1 -1
- package/esm/services/strategySubService.test.js +74 -0
- package/esm/services/subDataService.d.ts +12 -0
- package/esm/services/subDataService.js +33 -1
- package/esm/services/subDataService.test.d.ts +1 -1
- package/esm/services/subDataService.test.js +89 -0
- package/esm/services/triggerService.d.ts +9 -0
- package/esm/services/triggerService.js +17 -1
- package/esm/services/triggerService.test.d.ts +1 -1
- package/esm/services/triggerService.test.js +37 -0
- package/esm/services/utils.test.d.ts +1 -1
- package/esm/services/utils.test.js +1 -0
- package/esm/types/enums.d.ts +5 -2
- package/esm/types/enums.js +3 -0
- package/esm/types/index.d.ts +1 -1
- package/package.json +2 -2
- package/scripts/generateContractTypes.js +1 -1
- package/src/automation/private/LegacyAutomation.ts +2 -2
- package/src/automation/private/StrategiesAutomation.test.ts +663 -0
- package/src/automation/private/StrategiesAutomation.ts +56 -41
- package/src/constants/index.ts +10 -0
- package/src/services/ethereumService.test.ts +1 -0
- package/src/services/strategiesService.test.ts +1 -0
- package/src/services/strategiesService.ts +42 -0
- package/src/services/strategySubService.test.ts +90 -1
- package/src/services/strategySubService.ts +25 -0
- package/src/services/subDataService.test.ts +97 -1
- package/src/services/subDataService.ts +43 -0
- package/src/services/triggerService.test.ts +40 -0
- package/src/services/triggerService.ts +23 -0
- package/src/services/utils.test.ts +1 -0
- package/src/types/enums.ts +3 -0
- package/src/types/index.ts +1 -1
- package/umd/index.js +162 -33
- package/.env +0 -4
- package/.yarn/releases/yarn-1.22.1.cjs +0 -147386
- package/.yarnrc.yml +0 -3
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! 🥳
|
|
@@ -83,11 +83,11 @@ class LegacyAutomation extends Automation_1.default {
|
|
|
83
83
|
}
|
|
84
84
|
getParsedSubscriptions(addresses, options) {
|
|
85
85
|
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
-
|
|
86
|
+
const legacyAutomationSunset = 18213086;
|
|
87
87
|
if (!(options === null || options === void 0 ? void 0 : options.fromBlock)
|
|
88
88
|
|| (options === null || options === void 0 ? void 0 : options.fromBlock) === 'latest'
|
|
89
89
|
|| (options === null || options === void 0 ? void 0 : options.fromBlock) === 'pending'
|
|
90
|
-
|| ((options === null || options === void 0 ? void 0 : options.fromBlock) && new decimal_js_1.default(options === null || options === void 0 ? void 0 : options.fromBlock.toString()).
|
|
90
|
+
|| ((options === null || options === void 0 ? void 0 : options.fromBlock) && new decimal_js_1.default(options === null || options === void 0 ? void 0 : options.fromBlock.toString()).gte(legacyAutomationSunset))) {
|
|
91
91
|
return [];
|
|
92
92
|
}
|
|
93
93
|
const subscriptions = yield this._getSubscriptions(addresses, options);
|
|
@@ -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)[]>;
|
|
@@ -30,7 +30,11 @@ class StrategiesAutomation extends Automation_1.default {
|
|
|
30
30
|
this.assert();
|
|
31
31
|
}
|
|
32
32
|
getEventFromSubStorage(event, options) {
|
|
33
|
+
var _a;
|
|
33
34
|
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
if (new decimal_js_1.default(this.subStorageContract.createdBlock.toString()).gt(((_a = options === null || options === void 0 ? void 0 : options.fromBlock) === null || _a === void 0 ? void 0 : _a.toString()) || 0)) {
|
|
36
|
+
return [];
|
|
37
|
+
}
|
|
34
38
|
return (0, ethereumService_1.getEventsFromContract)(this.subStorageContract, this.subStorageContractFork, event, options);
|
|
35
39
|
});
|
|
36
40
|
}
|
|
@@ -95,7 +99,34 @@ class StrategiesAutomation extends Automation_1.default {
|
|
|
95
99
|
&& (s.protocol.id !== enums_1.ProtocolIdentifiers.StrategiesAutomation.MakerDAO // reflexer needs to get added if we have it
|
|
96
100
|
|| s.strategyData.decoded.subData.vaultId === current.strategyData.decoded.triggerData.vaultId)
|
|
97
101
|
&& (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())
|
|
102
|
+
|| s.strategyData.decoded.subData.controller.toLowerCase() === current.strategyData.decoded.triggerData.controller.toLowerCase())
|
|
103
|
+
&& (s.protocol.id !== enums_1.ProtocolIdentifiers.StrategiesAutomation.MorphoBlue // merge morpho blue with the same marketId
|
|
104
|
+
|| s.strategyData.decoded.triggerData.marketId.toLowerCase() === current.strategyData.decoded.triggerData.marketId.toLowerCase());
|
|
105
|
+
}
|
|
106
|
+
mergeSubs(_subscriptions) {
|
|
107
|
+
const mergeBase = _subscriptions.filter(s => (0, utils_1.isDefined)(s) && (0, utils_1.isDefined)(s.specific.mergeWithId));
|
|
108
|
+
const mergeExtension = _subscriptions.filter(s => (0, utils_1.isDefined)(s) && (0, utils_1.isDefined)(s.specific.mergeId));
|
|
109
|
+
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] })));
|
|
110
|
+
mergeBase.forEach((current) => {
|
|
111
|
+
const mergePairIndexSubEnabled = mergeExtension.findIndex(s => this._mergeCheck(s, current) && s.isEnabled === current.isEnabled);
|
|
112
|
+
const mergePairIndexSubDisabled = mergeExtension.findIndex(s => this._mergeCheck(s, current));
|
|
113
|
+
const mergePairIndex = mergePairIndexSubEnabled !== -1 ? mergePairIndexSubEnabled : mergePairIndexSubDisabled;
|
|
114
|
+
if (mergePairIndex !== -1) {
|
|
115
|
+
const mergePair = mergeExtension[mergePairIndex];
|
|
116
|
+
mergeExtension.splice(mergePairIndex, 1);
|
|
117
|
+
subscriptions.push(Object.assign(Object.assign(Object.assign({}, mergePair), current), {
|
|
118
|
+
// @ts-ignore
|
|
119
|
+
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) }));
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
subscriptions.push(Object.assign(Object.assign({}, current), { subIds: [current.subId] }));
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
if (mergeExtension.length > 0) {
|
|
126
|
+
console.error('Not all merge-able extensions were used', mergeExtension);
|
|
127
|
+
subscriptions = [...subscriptions, ...mergeExtension.map((s) => (Object.assign(Object.assign({}, s), { subIds: [s.subId] })))];
|
|
128
|
+
}
|
|
129
|
+
return subscriptions;
|
|
99
130
|
}
|
|
100
131
|
_getSubscriptions(addresses, options) {
|
|
101
132
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -127,29 +158,8 @@ class StrategiesAutomation extends Automation_1.default {
|
|
|
127
158
|
strategiesSubsData: sub,
|
|
128
159
|
});
|
|
129
160
|
})));
|
|
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
|
-
}
|
|
161
|
+
if (options === null || options === void 0 ? void 0 : options.mergeSubs) {
|
|
162
|
+
subscriptions = this.mergeSubs(subscriptions);
|
|
153
163
|
}
|
|
154
164
|
}
|
|
155
165
|
return _options.unexpiredOnly ? this.removeExpiredSubscriptions(subscriptions) : subscriptions;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '../../configuration';
|