@defisaver/automation-sdk 1.0.12 → 1.0.14
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/esm/automation/private/LegacyAutomation.js +2 -3
- package/esm/automation/private/StrategiesAutomation.js +9 -4
- package/esm/services/strategiesService.js +2 -1
- package/esm/types/enums.d.ts +3 -3
- package/esm/types/enums.js +3 -3
- package/esm/types/index.d.ts +2 -0
- package/package.json +1 -1
- package/src/automation/private/LegacyAutomation.ts +2 -5
- package/src/automation/private/StrategiesAutomation.ts +8 -3
- package/src/services/strategiesService.ts +4 -1
- package/src/types/enums.ts +3 -3
- package/src/types/index.ts +3 -3
- package/umd/index.js +32 -25
|
@@ -77,9 +77,9 @@ export default class LegacyAutomation extends Automation {
|
|
|
77
77
|
}
|
|
78
78
|
getParsedSubscriptions(addresses) {
|
|
79
79
|
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
-
|
|
80
|
+
const subscriptions = yield this._getSubscriptions(addresses);
|
|
81
81
|
// @ts-ignore
|
|
82
|
-
|
|
82
|
+
return subscriptions.map((sub) => ({
|
|
83
83
|
chainId: this.chainId,
|
|
84
84
|
owner: sub[this.getOwnerPropName()],
|
|
85
85
|
isEnabled: true,
|
|
@@ -90,7 +90,6 @@ export default class LegacyAutomation extends Automation {
|
|
|
90
90
|
protocol: this.protocol,
|
|
91
91
|
},
|
|
92
92
|
}));
|
|
93
|
-
return subscriptions;
|
|
94
93
|
});
|
|
95
94
|
}
|
|
96
95
|
getSubscriptions() {
|
|
@@ -7,6 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
+
import Dec from 'decimal.js';
|
|
10
11
|
import { addToObjectIf, isDefined } from '../../services/utils';
|
|
11
12
|
import { getAbiItem, makeSubStorageContract } from '../../services/contractService';
|
|
12
13
|
import { getEventsFromContract, multicall } from '../../services/ethereumService';
|
|
@@ -54,20 +55,21 @@ export default class StrategiesAutomation extends Automation {
|
|
|
54
55
|
_getSubscriptions(addresses, options) {
|
|
55
56
|
return __awaiter(this, void 0, void 0, function* () {
|
|
56
57
|
const _options = Object.assign(Object.assign({}, addToObjectIf(isDefined(options), options)), addToObjectIf(isDefined(addresses), { filter: { proxy: addresses } }));
|
|
57
|
-
const subscriptionEvents = (yield this.getSubscriptionEventsFromSubStorage(_options))
|
|
58
|
+
const subscriptionEvents = (yield this.getSubscriptionEventsFromSubStorage(_options)); // TODO PlaceholderType
|
|
58
59
|
let subscriptions = [];
|
|
59
60
|
if (subscriptionEvents) {
|
|
60
61
|
// @ts-ignore
|
|
61
|
-
const strategiesSubs = yield this.getStrategiesSubs(subscriptionEvents.map((e) => e.subId));
|
|
62
|
+
const strategiesSubs = yield this.getStrategiesSubs(subscriptionEvents.map((e) => e.returnValues.subId));
|
|
62
63
|
subscriptions = yield Promise.all(strategiesSubs.map((sub, index) => __awaiter(this, void 0, void 0, function* () {
|
|
63
64
|
var _a;
|
|
64
|
-
let latestUpdate = subscriptionEvents[index];
|
|
65
|
+
let latestUpdate = subscriptionEvents[index].returnValues;
|
|
65
66
|
if (latestUpdate.subHash !== (sub === null || sub === void 0 ? void 0 : sub.strategySubHash)) {
|
|
66
67
|
const updates = yield this.getUpdateDataEventsFromSubStorage(Object.assign(Object.assign({}, addToObjectIf(!!_options, _options)), { filter: { subId: latestUpdate.subId } }));
|
|
67
68
|
latestUpdate = Object.assign(Object.assign({}, latestUpdate), (_a = updates === null || updates === void 0 ? void 0 : updates[updates.length - 1]) === null || _a === void 0 ? void 0 : _a.returnValues);
|
|
68
69
|
}
|
|
69
70
|
return this.getParsedSubscriptions({
|
|
70
71
|
chainId: this.chainId,
|
|
72
|
+
blockNumber: subscriptionEvents[index].blockNumber,
|
|
71
73
|
subscriptionEventData: latestUpdate,
|
|
72
74
|
strategiesSubsData: sub,
|
|
73
75
|
});
|
|
@@ -78,12 +80,15 @@ export default class StrategiesAutomation extends Automation {
|
|
|
78
80
|
if (isDefined(current)) {
|
|
79
81
|
if (current.specific.mergeWithSameId) {
|
|
80
82
|
const mergePairIndex = copyList.findIndex(s => (s && s.specific.mergeWithSameId
|
|
83
|
+
&& s.owner === current.owner
|
|
81
84
|
&& s.strategy.strategyId === current.strategy.strategyId
|
|
82
85
|
&& s.protocol.id === current.protocol.id));
|
|
83
86
|
if (mergePairIndex !== -1) {
|
|
84
87
|
const mergePair = copyList[mergePairIndex];
|
|
85
88
|
if (isDefined(mergePair)) {
|
|
86
|
-
copyList[mergePairIndex] = Object.assign(Object.assign(Object.assign({}, mergePair), current), {
|
|
89
|
+
copyList[mergePairIndex] = Object.assign(Object.assign(Object.assign({}, mergePair), current), {
|
|
90
|
+
// @ts-ignore
|
|
91
|
+
blockNumber: Dec.max(mergePair.blockNumber, current.blockNumber).toNumber(), subIds: 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 }) });
|
|
87
92
|
return copyList;
|
|
88
93
|
}
|
|
89
94
|
}
|
|
@@ -212,7 +212,7 @@ function getParsingMethod(id, strategy) {
|
|
|
212
212
|
return parsingMethodsMapping[id][strategy.strategyId];
|
|
213
213
|
}
|
|
214
214
|
export function parseStrategiesAutomatedPosition(parseData) {
|
|
215
|
-
const { chainId, subscriptionEventData, strategiesSubsData } = parseData;
|
|
215
|
+
const { chainId, blockNumber, subscriptionEventData, strategiesSubsData, } = parseData;
|
|
216
216
|
const { subStruct, proxy, subId, subHash, } = subscriptionEventData;
|
|
217
217
|
const { isEnabled } = strategiesSubsData;
|
|
218
218
|
const id = subStruct.strategyOrBundleId;
|
|
@@ -225,6 +225,7 @@ export function parseStrategiesAutomatedPosition(parseData) {
|
|
|
225
225
|
isEnabled,
|
|
226
226
|
chainId,
|
|
227
227
|
subHash,
|
|
228
|
+
blockNumber,
|
|
228
229
|
subId: Number(subId),
|
|
229
230
|
owner: proxy,
|
|
230
231
|
protocol: Object.assign({}, strategyOrBundleInfo.protocol),
|
package/esm/types/enums.d.ts
CHANGED
|
@@ -21,14 +21,14 @@ export declare enum BundleProtocols {
|
|
|
21
21
|
*/
|
|
22
22
|
export declare namespace ProtocolIdentifiers {
|
|
23
23
|
enum StrategiesAutomation {
|
|
24
|
-
MakerDAO = "
|
|
24
|
+
MakerDAO = "MakerDAO",
|
|
25
25
|
Liquity = "Liquity",
|
|
26
|
-
ChickenBonds = "
|
|
26
|
+
ChickenBonds = "Chicken Bonds",
|
|
27
27
|
CompoundV3 = "Compound__V3",
|
|
28
28
|
AaveV3 = "Aave__V3"
|
|
29
29
|
}
|
|
30
30
|
enum LegacyAutomation {
|
|
31
|
-
MakerDAO = "
|
|
31
|
+
MakerDAO = "MakerDAO",
|
|
32
32
|
CompoundV2 = "Compound__V2",
|
|
33
33
|
AaveV2 = "Aave__V2"
|
|
34
34
|
}
|
package/esm/types/enums.js
CHANGED
|
@@ -26,15 +26,15 @@ export var ProtocolIdentifiers;
|
|
|
26
26
|
(function (ProtocolIdentifiers) {
|
|
27
27
|
let StrategiesAutomation;
|
|
28
28
|
(function (StrategiesAutomation) {
|
|
29
|
-
StrategiesAutomation["MakerDAO"] = "
|
|
29
|
+
StrategiesAutomation["MakerDAO"] = "MakerDAO";
|
|
30
30
|
StrategiesAutomation["Liquity"] = "Liquity";
|
|
31
|
-
StrategiesAutomation["ChickenBonds"] = "
|
|
31
|
+
StrategiesAutomation["ChickenBonds"] = "Chicken Bonds";
|
|
32
32
|
StrategiesAutomation["CompoundV3"] = "Compound__V3";
|
|
33
33
|
StrategiesAutomation["AaveV3"] = "Aave__V3";
|
|
34
34
|
})(StrategiesAutomation = ProtocolIdentifiers.StrategiesAutomation || (ProtocolIdentifiers.StrategiesAutomation = {}));
|
|
35
35
|
let LegacyAutomation;
|
|
36
36
|
(function (LegacyAutomation) {
|
|
37
|
-
LegacyAutomation["MakerDAO"] = "
|
|
37
|
+
LegacyAutomation["MakerDAO"] = "MakerDAO";
|
|
38
38
|
LegacyAutomation["CompoundV2"] = "Compound__V2";
|
|
39
39
|
LegacyAutomation["AaveV2"] = "Aave__V2";
|
|
40
40
|
})(LegacyAutomation = ProtocolIdentifiers.LegacyAutomation || (ProtocolIdentifiers.LegacyAutomation = {}));
|
package/esm/types/index.d.ts
CHANGED
|
@@ -128,6 +128,7 @@ export declare namespace Position {
|
|
|
128
128
|
subIds?: number[];
|
|
129
129
|
isEnabled?: boolean;
|
|
130
130
|
subHash: string;
|
|
131
|
+
blockNumber: BlockNumber;
|
|
131
132
|
protocol: Interfaces.Protocol;
|
|
132
133
|
strategy: BundleOrStrategy;
|
|
133
134
|
strategyData: {
|
|
@@ -175,6 +176,7 @@ export interface BundlesInfo {
|
|
|
175
176
|
export type StrategyOrBundleIds = Strategies.MainnetIds & Strategies.OptimismIds & Strategies.ArbitrumIds & Bundles.MainnetIds & Bundles.OptimismIds & Bundles.ArbitrumIds;
|
|
176
177
|
export interface ParseData {
|
|
177
178
|
chainId: ChainId;
|
|
179
|
+
blockNumber: BlockNumber;
|
|
178
180
|
subscriptionEventData: Subscribe['returnValues'];
|
|
179
181
|
strategiesSubsData: StrategyModel.StoredSubDataStructOutputStruct;
|
|
180
182
|
}
|
package/package.json
CHANGED
|
@@ -80,7 +80,6 @@ export default class LegacyAutomation extends Automation {
|
|
|
80
80
|
return (await multicall(this.web3, this.chainId, multicallCalls)).map(res => res[0]);
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
|
|
84
83
|
// Aave and Compound use 'user' for property name
|
|
85
84
|
private getOwnerPropName() {
|
|
86
85
|
return this.protocol.id === ProtocolIdentifiers.LegacyAutomation.MakerDAO ? 'owner' : 'user';
|
|
@@ -100,10 +99,10 @@ export default class LegacyAutomation extends Automation {
|
|
|
100
99
|
}
|
|
101
100
|
|
|
102
101
|
protected async getParsedSubscriptions(addresses?: EthereumAddress[]): Promise<Position.LegacyAutomated[]> {
|
|
103
|
-
|
|
102
|
+
const subscriptions = await this._getSubscriptions(addresses);
|
|
104
103
|
|
|
105
104
|
// @ts-ignore
|
|
106
|
-
|
|
105
|
+
return subscriptions.map((sub) => ({
|
|
107
106
|
chainId: this.chainId,
|
|
108
107
|
owner: sub[this.getOwnerPropName()],
|
|
109
108
|
isEnabled: true,
|
|
@@ -114,8 +113,6 @@ export default class LegacyAutomation extends Automation {
|
|
|
114
113
|
protocol: this.protocol,
|
|
115
114
|
},
|
|
116
115
|
}));
|
|
117
|
-
|
|
118
|
-
return subscriptions;
|
|
119
116
|
}
|
|
120
117
|
|
|
121
118
|
public async getSubscriptions(): Promise<Position.LegacyAutomated[]> {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import Dec from 'decimal.js';
|
|
1
2
|
import type Web3 from 'web3';
|
|
2
3
|
import type { PastEventOptions } from 'web3-eth-contract';
|
|
3
4
|
import type {
|
|
@@ -74,16 +75,16 @@ export default class StrategiesAutomation extends Automation {
|
|
|
74
75
|
...addToObjectIf(isDefined(addresses), { filter: { proxy: addresses } }),
|
|
75
76
|
};
|
|
76
77
|
|
|
77
|
-
const subscriptionEvents = (await this.getSubscriptionEventsFromSubStorage(_options))
|
|
78
|
+
const subscriptionEvents = (await this.getSubscriptionEventsFromSubStorage(_options)) as PlaceholderType; // TODO PlaceholderType
|
|
78
79
|
|
|
79
80
|
let subscriptions: (Position.Automated | null)[] = [];
|
|
80
81
|
|
|
81
82
|
if (subscriptionEvents) {
|
|
82
83
|
// @ts-ignore
|
|
83
|
-
const strategiesSubs = await this.getStrategiesSubs(subscriptionEvents.map((e) => e.subId));
|
|
84
|
+
const strategiesSubs = await this.getStrategiesSubs(subscriptionEvents.map((e) => e.returnValues.subId));
|
|
84
85
|
|
|
85
86
|
subscriptions = await Promise.all(strategiesSubs.map(async (sub, index: number) => {
|
|
86
|
-
let latestUpdate = subscriptionEvents[index];
|
|
87
|
+
let latestUpdate = subscriptionEvents[index].returnValues;
|
|
87
88
|
|
|
88
89
|
if (latestUpdate.subHash !== sub?.strategySubHash) {
|
|
89
90
|
const updates = await this.getUpdateDataEventsFromSubStorage({
|
|
@@ -97,6 +98,7 @@ export default class StrategiesAutomation extends Automation {
|
|
|
97
98
|
}
|
|
98
99
|
return this.getParsedSubscriptions({
|
|
99
100
|
chainId: this.chainId,
|
|
101
|
+
blockNumber: subscriptionEvents[index].blockNumber,
|
|
100
102
|
subscriptionEventData: latestUpdate,
|
|
101
103
|
strategiesSubsData: sub,
|
|
102
104
|
});
|
|
@@ -110,6 +112,7 @@ export default class StrategiesAutomation extends Automation {
|
|
|
110
112
|
if (current.specific.mergeWithSameId) {
|
|
111
113
|
const mergePairIndex = copyList.findIndex(s => (
|
|
112
114
|
s && s.specific.mergeWithSameId
|
|
115
|
+
&& s.owner === current.owner
|
|
113
116
|
&& s.strategy.strategyId === current.strategy.strategyId
|
|
114
117
|
&& s.protocol.id === current.protocol.id
|
|
115
118
|
));
|
|
@@ -120,6 +123,8 @@ export default class StrategiesAutomation extends Automation {
|
|
|
120
123
|
copyList[mergePairIndex] = {
|
|
121
124
|
...mergePair,
|
|
122
125
|
...current,
|
|
126
|
+
// @ts-ignore
|
|
127
|
+
blockNumber: Dec.max(mergePair.blockNumber, current.blockNumber).toNumber(),
|
|
123
128
|
subIds: isDefined(mergePair.subIds) ? [...mergePair.subIds, current.subId] : undefined,
|
|
124
129
|
isEnabled: mergePair.isEnabled || current.isEnabled,
|
|
125
130
|
subId: mergePair.subId,
|
|
@@ -293,7 +293,9 @@ function getParsingMethod(id: ProtocolIdentifiers.StrategiesAutomation, strategy
|
|
|
293
293
|
}
|
|
294
294
|
|
|
295
295
|
export function parseStrategiesAutomatedPosition(parseData: ParseData): Position.Automated | null {
|
|
296
|
-
const {
|
|
296
|
+
const {
|
|
297
|
+
chainId, blockNumber, subscriptionEventData, strategiesSubsData,
|
|
298
|
+
} = parseData;
|
|
297
299
|
const {
|
|
298
300
|
subStruct, proxy, subId, subHash,
|
|
299
301
|
} = subscriptionEventData;
|
|
@@ -313,6 +315,7 @@ export function parseStrategiesAutomatedPosition(parseData: ParseData): Position
|
|
|
313
315
|
isEnabled,
|
|
314
316
|
chainId,
|
|
315
317
|
subHash,
|
|
318
|
+
blockNumber,
|
|
316
319
|
subId: Number(subId),
|
|
317
320
|
owner: proxy,
|
|
318
321
|
protocol: {
|
package/src/types/enums.ts
CHANGED
|
@@ -24,15 +24,15 @@ export enum BundleProtocols {
|
|
|
24
24
|
*/
|
|
25
25
|
export namespace ProtocolIdentifiers {
|
|
26
26
|
export enum StrategiesAutomation {
|
|
27
|
-
MakerDAO = '
|
|
27
|
+
MakerDAO = 'MakerDAO',
|
|
28
28
|
Liquity = 'Liquity',
|
|
29
|
-
ChickenBonds = '
|
|
29
|
+
ChickenBonds = 'Chicken Bonds',
|
|
30
30
|
CompoundV3 = 'Compound__V3',
|
|
31
31
|
AaveV3 = 'Aave__V3',
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
export enum LegacyAutomation {
|
|
35
|
-
MakerDAO = '
|
|
35
|
+
MakerDAO = 'MakerDAO',
|
|
36
36
|
CompoundV2 = 'Compound__V2',
|
|
37
37
|
AaveV2 = 'Aave__V2',
|
|
38
38
|
}
|
package/src/types/index.ts
CHANGED
|
@@ -153,6 +153,7 @@ export declare namespace Position {
|
|
|
153
153
|
subIds?: number[],
|
|
154
154
|
isEnabled?: boolean,
|
|
155
155
|
subHash: string,
|
|
156
|
+
blockNumber: BlockNumber,
|
|
156
157
|
protocol: Interfaces.Protocol,
|
|
157
158
|
strategy: BundleOrStrategy,
|
|
158
159
|
strategyData: {
|
|
@@ -168,7 +169,7 @@ export declare namespace Position {
|
|
|
168
169
|
specific: Specific.CloseOnPrice | Specific.TrailingStop | Specific.RatioProtection | Specific.CloseOnPriceAave,
|
|
169
170
|
}
|
|
170
171
|
|
|
171
|
-
interface LegacyAutomated {
|
|
172
|
+
export interface LegacyAutomated {
|
|
172
173
|
chainId: ChainId,
|
|
173
174
|
owner: EthereumAddress,
|
|
174
175
|
isEnabled: boolean,
|
|
@@ -181,7 +182,6 @@ export declare namespace Position {
|
|
|
181
182
|
}
|
|
182
183
|
}
|
|
183
184
|
|
|
184
|
-
|
|
185
185
|
type StrategyInfo<T extends number> = Record<T, Strategy<T>>;
|
|
186
186
|
export type MainnetStrategiesInfo = StrategyInfo<Strategies.MainnetIds>;
|
|
187
187
|
export type OptimismStrategiesInfo = StrategyInfo<Strategies.OptimismIds>;
|
|
@@ -208,9 +208,9 @@ export type StrategyOrBundleIds =
|
|
|
208
208
|
Strategies.MainnetIds & Strategies.OptimismIds & Strategies.ArbitrumIds
|
|
209
209
|
& Bundles.MainnetIds & Bundles.OptimismIds & Bundles.ArbitrumIds;
|
|
210
210
|
|
|
211
|
-
|
|
212
211
|
export interface ParseData {
|
|
213
212
|
chainId: ChainId,
|
|
213
|
+
blockNumber: BlockNumber,
|
|
214
214
|
subscriptionEventData: Subscribe['returnValues']
|
|
215
215
|
strategiesSubsData: StrategyModel.StoredSubDataStructOutputStruct,
|
|
216
216
|
}
|
package/umd/index.js
CHANGED
|
@@ -326,16 +326,16 @@ var ProtocolIdentifiers;
|
|
|
326
326
|
(function (_ProtocolIdentifiers) {
|
|
327
327
|
var StrategiesAutomation;
|
|
328
328
|
(function (StrategiesAutomation) {
|
|
329
|
-
StrategiesAutomation["MakerDAO"] = "
|
|
329
|
+
StrategiesAutomation["MakerDAO"] = "MakerDAO";
|
|
330
330
|
StrategiesAutomation["Liquity"] = "Liquity";
|
|
331
|
-
StrategiesAutomation["ChickenBonds"] = "
|
|
331
|
+
StrategiesAutomation["ChickenBonds"] = "Chicken Bonds";
|
|
332
332
|
StrategiesAutomation["CompoundV3"] = "Compound__V3";
|
|
333
333
|
StrategiesAutomation["AaveV3"] = "Aave__V3";
|
|
334
334
|
})(StrategiesAutomation || (StrategiesAutomation = {}));
|
|
335
335
|
_ProtocolIdentifiers.StrategiesAutomation = StrategiesAutomation;
|
|
336
336
|
var LegacyAutomation;
|
|
337
337
|
(function (LegacyAutomation) {
|
|
338
|
-
LegacyAutomation["MakerDAO"] = "
|
|
338
|
+
LegacyAutomation["MakerDAO"] = "MakerDAO";
|
|
339
339
|
LegacyAutomation["CompoundV2"] = "Compound__V2";
|
|
340
340
|
LegacyAutomation["AaveV2"] = "Aave__V2";
|
|
341
341
|
})(LegacyAutomation || (LegacyAutomation = {}));
|
|
@@ -919,7 +919,7 @@ class LegacyAutomation extends _Automation__WEBPACK_IMPORTED_MODULE_3__["default
|
|
|
919
919
|
var subscriptions = yield _this4._getSubscriptions(addresses);
|
|
920
920
|
|
|
921
921
|
// @ts-ignore
|
|
922
|
-
|
|
922
|
+
return subscriptions.map(sub => ({
|
|
923
923
|
chainId: _this4.chainId,
|
|
924
924
|
owner: sub[_this4.getOwnerPropName()],
|
|
925
925
|
isEnabled: true,
|
|
@@ -930,7 +930,6 @@ class LegacyAutomation extends _Automation__WEBPACK_IMPORTED_MODULE_3__["default
|
|
|
930
930
|
protocol: _this4.protocol
|
|
931
931
|
}
|
|
932
932
|
}));
|
|
933
|
-
return subscriptions;
|
|
934
933
|
})();
|
|
935
934
|
}
|
|
936
935
|
getSubscriptions() {
|
|
@@ -1143,11 +1142,13 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
1143
1142
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
1144
1143
|
/* harmony export */ "default": () => (/* binding */ StrategiesAutomation)
|
|
1145
1144
|
/* harmony export */ });
|
|
1146
|
-
/* harmony import */ var
|
|
1147
|
-
/* harmony import */ var
|
|
1148
|
-
/* harmony import */ var
|
|
1149
|
-
/* harmony import */ var
|
|
1150
|
-
/* harmony import */ var
|
|
1145
|
+
/* harmony import */ var decimal_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(3);
|
|
1146
|
+
/* harmony import */ var decimal_js__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(decimal_js__WEBPACK_IMPORTED_MODULE_0__);
|
|
1147
|
+
/* harmony import */ var _services_utils__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(18);
|
|
1148
|
+
/* harmony import */ var _services_contractService__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(17);
|
|
1149
|
+
/* harmony import */ var _services_ethereumService__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(21);
|
|
1150
|
+
/* harmony import */ var _Automation__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(22);
|
|
1151
|
+
/* harmony import */ var _services_strategiesService__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(27);
|
|
1151
1152
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
1152
1153
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
1153
1154
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
@@ -1160,7 +1161,8 @@ function _toPrimitive(input, hint) { if (typeof input !== "object" || input ===
|
|
|
1160
1161
|
|
|
1161
1162
|
|
|
1162
1163
|
|
|
1163
|
-
|
|
1164
|
+
|
|
1165
|
+
class StrategiesAutomation extends _Automation__WEBPACK_IMPORTED_MODULE_4__["default"] {
|
|
1164
1166
|
constructor(args) {
|
|
1165
1167
|
super();
|
|
1166
1168
|
_defineProperty(this, "chainId", void 0);
|
|
@@ -1168,13 +1170,13 @@ class StrategiesAutomation extends _Automation__WEBPACK_IMPORTED_MODULE_3__["def
|
|
|
1168
1170
|
_defineProperty(this, "subStorageContract", void 0);
|
|
1169
1171
|
this.web3 = args.provider;
|
|
1170
1172
|
this.chainId = args.chainId;
|
|
1171
|
-
this.subStorageContract = (0,
|
|
1173
|
+
this.subStorageContract = (0,_services_contractService__WEBPACK_IMPORTED_MODULE_2__.makeSubStorageContract)(this.web3, this.chainId);
|
|
1172
1174
|
this.assert();
|
|
1173
1175
|
}
|
|
1174
1176
|
getEventFromSubStorage(event, options) {
|
|
1175
1177
|
var _this = this;
|
|
1176
1178
|
return _asyncToGenerator(function* () {
|
|
1177
|
-
return (0,
|
|
1179
|
+
return (0,_services_ethereumService__WEBPACK_IMPORTED_MODULE_3__.getEventsFromContract)(_this.subStorageContract, event, options);
|
|
1178
1180
|
})();
|
|
1179
1181
|
}
|
|
1180
1182
|
getStrategiesSubs(subIds) {
|
|
@@ -1183,12 +1185,12 @@ class StrategiesAutomation extends _Automation__WEBPACK_IMPORTED_MODULE_3__["def
|
|
|
1183
1185
|
var subStorageContract = _this2.subStorageContract;
|
|
1184
1186
|
var defaultOptions = {
|
|
1185
1187
|
target: subStorageContract.address,
|
|
1186
|
-
abiItem: (0,
|
|
1188
|
+
abiItem: (0,_services_contractService__WEBPACK_IMPORTED_MODULE_2__.getAbiItem)(subStorageContract.abi, 'strategiesSubs')
|
|
1187
1189
|
};
|
|
1188
1190
|
var multicallCalls = subIds.map(subId => _objectSpread(_objectSpread({}, defaultOptions), {}, {
|
|
1189
1191
|
params: [subId]
|
|
1190
1192
|
}));
|
|
1191
|
-
return (0,
|
|
1193
|
+
return (0,_services_ethereumService__WEBPACK_IMPORTED_MODULE_3__.multicall)(_this2.web3, _this2.chainId, multicallCalls);
|
|
1192
1194
|
})();
|
|
1193
1195
|
}
|
|
1194
1196
|
getSubscriptionEventsFromSubStorage(options) {
|
|
@@ -1206,28 +1208,28 @@ class StrategiesAutomation extends _Automation__WEBPACK_IMPORTED_MODULE_3__["def
|
|
|
1206
1208
|
})();
|
|
1207
1209
|
}
|
|
1208
1210
|
getParsedSubscriptions(parseData) {
|
|
1209
|
-
return (0,
|
|
1211
|
+
return (0,_services_strategiesService__WEBPACK_IMPORTED_MODULE_5__.parseStrategiesAutomatedPosition)(parseData);
|
|
1210
1212
|
}
|
|
1211
1213
|
_getSubscriptions(addresses, options) {
|
|
1212
1214
|
var _this5 = this;
|
|
1213
1215
|
return _asyncToGenerator(function* () {
|
|
1214
|
-
var _options = _objectSpread(_objectSpread({}, (0,
|
|
1216
|
+
var _options = _objectSpread(_objectSpread({}, (0,_services_utils__WEBPACK_IMPORTED_MODULE_1__.addToObjectIf)((0,_services_utils__WEBPACK_IMPORTED_MODULE_1__.isDefined)(options), options)), (0,_services_utils__WEBPACK_IMPORTED_MODULE_1__.addToObjectIf)((0,_services_utils__WEBPACK_IMPORTED_MODULE_1__.isDefined)(addresses), {
|
|
1215
1217
|
filter: {
|
|
1216
1218
|
proxy: addresses
|
|
1217
1219
|
}
|
|
1218
1220
|
}));
|
|
1219
|
-
var subscriptionEvents =
|
|
1221
|
+
var subscriptionEvents = yield _this5.getSubscriptionEventsFromSubStorage(_options); // TODO PlaceholderType
|
|
1220
1222
|
|
|
1221
1223
|
var subscriptions = [];
|
|
1222
1224
|
if (subscriptionEvents) {
|
|
1223
1225
|
// @ts-ignore
|
|
1224
|
-
var strategiesSubs = yield _this5.getStrategiesSubs(subscriptionEvents.map(e => e.subId));
|
|
1226
|
+
var strategiesSubs = yield _this5.getStrategiesSubs(subscriptionEvents.map(e => e.returnValues.subId));
|
|
1225
1227
|
subscriptions = yield Promise.all(strategiesSubs.map( /*#__PURE__*/function () {
|
|
1226
1228
|
var _ref = _asyncToGenerator(function* (sub, index) {
|
|
1227
|
-
var latestUpdate = subscriptionEvents[index];
|
|
1229
|
+
var latestUpdate = subscriptionEvents[index].returnValues;
|
|
1228
1230
|
if (latestUpdate.subHash !== (sub === null || sub === void 0 ? void 0 : sub.strategySubHash)) {
|
|
1229
1231
|
var _updates;
|
|
1230
|
-
var updates = yield _this5.getUpdateDataEventsFromSubStorage(_objectSpread(_objectSpread({}, (0,
|
|
1232
|
+
var updates = yield _this5.getUpdateDataEventsFromSubStorage(_objectSpread(_objectSpread({}, (0,_services_utils__WEBPACK_IMPORTED_MODULE_1__.addToObjectIf)(!!_options, _options)), {}, {
|
|
1231
1233
|
filter: {
|
|
1232
1234
|
subId: latestUpdate.subId
|
|
1233
1235
|
}
|
|
@@ -1236,6 +1238,7 @@ class StrategiesAutomation extends _Automation__WEBPACK_IMPORTED_MODULE_3__["def
|
|
|
1236
1238
|
}
|
|
1237
1239
|
return _this5.getParsedSubscriptions({
|
|
1238
1240
|
chainId: _this5.chainId,
|
|
1241
|
+
blockNumber: subscriptionEvents[index].blockNumber,
|
|
1239
1242
|
subscriptionEventData: latestUpdate,
|
|
1240
1243
|
strategiesSubsData: sub
|
|
1241
1244
|
});
|
|
@@ -1247,14 +1250,16 @@ class StrategiesAutomation extends _Automation__WEBPACK_IMPORTED_MODULE_3__["def
|
|
|
1247
1250
|
if (options !== null && options !== void 0 && options.mergeWithSameId) {
|
|
1248
1251
|
subscriptions = subscriptions.reduce((list, current) => {
|
|
1249
1252
|
var copyList = [...list];
|
|
1250
|
-
if ((0,
|
|
1253
|
+
if ((0,_services_utils__WEBPACK_IMPORTED_MODULE_1__.isDefined)(current)) {
|
|
1251
1254
|
if (current.specific.mergeWithSameId) {
|
|
1252
|
-
var mergePairIndex = copyList.findIndex(s => s && s.specific.mergeWithSameId && s.strategy.strategyId === current.strategy.strategyId && s.protocol.id === current.protocol.id);
|
|
1255
|
+
var mergePairIndex = copyList.findIndex(s => s && s.specific.mergeWithSameId && s.owner === current.owner && s.strategy.strategyId === current.strategy.strategyId && s.protocol.id === current.protocol.id);
|
|
1253
1256
|
if (mergePairIndex !== -1) {
|
|
1254
1257
|
var mergePair = copyList[mergePairIndex];
|
|
1255
|
-
if ((0,
|
|
1258
|
+
if ((0,_services_utils__WEBPACK_IMPORTED_MODULE_1__.isDefined)(mergePair)) {
|
|
1256
1259
|
copyList[mergePairIndex] = _objectSpread(_objectSpread(_objectSpread({}, mergePair), current), {}, {
|
|
1257
|
-
|
|
1260
|
+
// @ts-ignore
|
|
1261
|
+
blockNumber: decimal_js__WEBPACK_IMPORTED_MODULE_0___default().max(mergePair.blockNumber, current.blockNumber).toNumber(),
|
|
1262
|
+
subIds: (0,_services_utils__WEBPACK_IMPORTED_MODULE_1__.isDefined)(mergePair.subIds) ? [...mergePair.subIds, current.subId] : undefined,
|
|
1258
1263
|
isEnabled: mergePair.isEnabled || current.isEnabled,
|
|
1259
1264
|
subId: mergePair.subId,
|
|
1260
1265
|
specific: _objectSpread(_objectSpread(_objectSpread({}, mergePair.specific), current.specific), {}, {
|
|
@@ -1557,6 +1562,7 @@ function getParsingMethod(id, strategy) {
|
|
|
1557
1562
|
function parseStrategiesAutomatedPosition(parseData) {
|
|
1558
1563
|
var {
|
|
1559
1564
|
chainId,
|
|
1565
|
+
blockNumber,
|
|
1560
1566
|
subscriptionEventData,
|
|
1561
1567
|
strategiesSubsData
|
|
1562
1568
|
} = parseData;
|
|
@@ -1576,6 +1582,7 @@ function parseStrategiesAutomatedPosition(parseData) {
|
|
|
1576
1582
|
isEnabled,
|
|
1577
1583
|
chainId,
|
|
1578
1584
|
subHash,
|
|
1585
|
+
blockNumber,
|
|
1579
1586
|
subId: Number(subId),
|
|
1580
1587
|
owner: proxy,
|
|
1581
1588
|
protocol: _objectSpread({}, strategyOrBundleInfo.protocol),
|