@defisaver/automation-sdk 1.0.11 → 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.
@@ -77,16 +77,19 @@ export default class LegacyAutomation extends Automation {
77
77
  }
78
78
  getParsedSubscriptions(addresses) {
79
79
  return __awaiter(this, void 0, void 0, function* () {
80
- let subscriptions = yield this._getSubscriptions(addresses);
80
+ const subscriptions = yield this._getSubscriptions(addresses);
81
81
  // @ts-ignore
82
- subscriptions = subscriptions.map(sub => ({
82
+ return subscriptions.map((sub) => ({
83
83
  chainId: this.chainId,
84
84
  owner: sub[this.getOwnerPropName()],
85
85
  isEnabled: true,
86
86
  protocol: this.protocol,
87
87
  specific: Object.assign({}, sub),
88
+ strategy: {
89
+ strategyId: 'legacy',
90
+ protocol: this.protocol,
91
+ },
88
92
  }));
89
- return subscriptions;
90
93
  });
91
94
  }
92
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)).map(e => e.returnValues); // TODO PlaceholderType
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), { 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 }) });
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),
@@ -24,7 +24,7 @@ export const makerEncode = {
24
24
  requireAddresses([closeToAssetAddr, chainlinkCollAddress]);
25
25
  const subData = subDataService.makerCloseSubData.encode(vaultId, closeToAssetAddr, chainId, daiAddr, mcdCdpManagerAddr);
26
26
  const triggerData = triggerService.trailingStopTrigger.encode(chainlinkCollAddress, triggerPercentage, roundId);
27
- const strategyOrBundleId = compareAddresses(closeToAssetAddr, getAssetInfo('DAI').address)
27
+ const strategyOrBundleId = compareAddresses(closeToAssetAddr, getAssetInfo('DAI', chainId).address)
28
28
  ? Strategies.MainnetIds.MAKER_TRAILING_STOP_LOSS_TO_DAI
29
29
  : Strategies.MainnetIds.MAKER_TRAILING_STOP_LOSS_TO_COLL;
30
30
  const isBundle = false;
@@ -53,8 +53,9 @@ export declare const liquityPaybackUsingChickenBondSubData: {
53
53
  /**
54
54
  * @param sourceId bondId or subId
55
55
  * @param sourceType 0 for bond, 1 for subId
56
+ * @param chainId
56
57
  */
57
- encode: (sourceId: string, sourceType: number) => string[];
58
+ encode: (sourceId: string, sourceType: number, chainId?: ChainId) => string[];
58
59
  decode: (subData: string[]) => {
59
60
  sourceId: string;
60
61
  sourceType: string;
@@ -132,12 +132,13 @@ export const liquityPaybackUsingChickenBondSubData = {
132
132
  /**
133
133
  * @param sourceId bondId or subId
134
134
  * @param sourceType 0 for bond, 1 for subId
135
+ * @param chainId
135
136
  */
136
- encode: (sourceId, sourceType) => {
137
+ encode: (sourceId, sourceType, chainId = ChainId.Ethereum) => {
137
138
  const sourceIdEncoded = mockedWeb3.eth.abi.encodeParameter('uint256', sourceId);
138
139
  const sourceTypeEncoded = mockedWeb3.eth.abi.encodeParameter('uint256', sourceType);
139
- const lusdAddressEncoded = mockedWeb3.eth.abi.encodeParameter('address', getAssetInfo('LUSD').address);
140
- const bLusdAddressEncoded = mockedWeb3.eth.abi.encodeParameter('address', getAssetInfo('bLUSD').address);
140
+ const lusdAddressEncoded = mockedWeb3.eth.abi.encodeParameter('address', getAssetInfo('LUSD', chainId).address);
141
+ const bLusdAddressEncoded = mockedWeb3.eth.abi.encodeParameter('address', getAssetInfo('bLUSD', chainId).address);
141
142
  return [sourceIdEncoded, sourceTypeEncoded, lusdAddressEncoded, bLusdAddressEncoded];
142
143
  },
143
144
  decode: (subData) => {
@@ -21,14 +21,14 @@ export declare enum BundleProtocols {
21
21
  */
22
22
  export declare namespace ProtocolIdentifiers {
23
23
  enum StrategiesAutomation {
24
- MakerDAO = "MakerDAO__MCD",
24
+ MakerDAO = "MakerDAO",
25
25
  Liquity = "Liquity",
26
- ChickenBonds = "ChickenBonds",
26
+ ChickenBonds = "Chicken Bonds",
27
27
  CompoundV3 = "Compound__V3",
28
28
  AaveV3 = "Aave__V3"
29
29
  }
30
30
  enum LegacyAutomation {
31
- MakerDAO = "MakerDAO__MCD",
31
+ MakerDAO = "MakerDAO",
32
32
  CompoundV2 = "Compound__V2",
33
33
  AaveV2 = "Aave__V2"
34
34
  }
@@ -26,15 +26,15 @@ export var ProtocolIdentifiers;
26
26
  (function (ProtocolIdentifiers) {
27
27
  let StrategiesAutomation;
28
28
  (function (StrategiesAutomation) {
29
- StrategiesAutomation["MakerDAO"] = "MakerDAO__MCD";
29
+ StrategiesAutomation["MakerDAO"] = "MakerDAO";
30
30
  StrategiesAutomation["Liquity"] = "Liquity";
31
- StrategiesAutomation["ChickenBonds"] = "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"] = "MakerDAO__MCD";
37
+ LegacyAutomation["MakerDAO"] = "MakerDAO";
38
38
  LegacyAutomation["CompoundV2"] = "Compound__V2";
39
39
  LegacyAutomation["AaveV2"] = "Aave__V2";
40
40
  })(LegacyAutomation = ProtocolIdentifiers.LegacyAutomation || (ProtocolIdentifiers.LegacyAutomation = {}));
@@ -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: {
@@ -147,6 +148,10 @@ export declare namespace Position {
147
148
  owner: EthereumAddress;
148
149
  isEnabled: boolean;
149
150
  protocol: Interfaces.LegacyProtocol;
151
+ strategy: {
152
+ strategyId: string;
153
+ protocol: Interfaces.Protocol;
154
+ };
150
155
  specific: any;
151
156
  }
152
157
  }
@@ -171,6 +176,7 @@ export interface BundlesInfo {
171
176
  export type StrategyOrBundleIds = Strategies.MainnetIds & Strategies.OptimismIds & Strategies.ArbitrumIds & Bundles.MainnetIds & Bundles.OptimismIds & Bundles.ArbitrumIds;
172
177
  export interface ParseData {
173
178
  chainId: ChainId;
179
+ blockNumber: BlockNumber;
174
180
  subscriptionEventData: Subscribe['returnValues'];
175
181
  strategiesSubsData: StrategyModel.StoredSubDataStructOutputStruct;
176
182
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defisaver/automation-sdk",
3
- "version": "1.0.11",
3
+ "version": "1.0.14",
4
4
  "description": "",
5
5
  "main": "./umd/index.js",
6
6
  "module": "./esm/index.js",
@@ -21,7 +21,7 @@
21
21
  "license": "ISC",
22
22
  "dependencies": {
23
23
  "@defisaver/sdk": "^1.0.5",
24
- "@defisaver/tokens": "^1.4.18",
24
+ "@defisaver/tokens": "^1.4.25",
25
25
  "@ethersproject/address": "^5.0.10",
26
26
  "@ethersproject/solidity": "^5.0.9",
27
27
  "decimal.js": "^10.4.3",
@@ -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,18 +99,20 @@ export default class LegacyAutomation extends Automation {
100
99
  }
101
100
 
102
101
  protected async getParsedSubscriptions(addresses?: EthereumAddress[]): Promise<Position.LegacyAutomated[]> {
103
- let subscriptions = await this._getSubscriptions(addresses);
102
+ const subscriptions = await this._getSubscriptions(addresses);
104
103
 
105
104
  // @ts-ignore
106
- subscriptions = subscriptions.map(sub => ({
105
+ return subscriptions.map((sub) => ({
107
106
  chainId: this.chainId,
108
107
  owner: sub[this.getOwnerPropName()],
109
108
  isEnabled: true,
110
109
  protocol: this.protocol,
111
110
  specific: { ...sub },
111
+ strategy: {
112
+ strategyId: 'legacy',
113
+ protocol: this.protocol,
114
+ },
112
115
  }));
113
-
114
- return subscriptions;
115
116
  }
116
117
 
117
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)).map(e => e.returnValues) as PlaceholderType; // TODO PlaceholderType
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 { chainId, subscriptionEventData, strategiesSubsData } = parseData;
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: {
@@ -64,7 +64,7 @@ export const makerEncode = {
64
64
  const subData = subDataService.makerCloseSubData.encode(vaultId, closeToAssetAddr, chainId, daiAddr, mcdCdpManagerAddr);
65
65
  const triggerData = triggerService.trailingStopTrigger.encode(chainlinkCollAddress, triggerPercentage, roundId);
66
66
 
67
- const strategyOrBundleId = compareAddresses(closeToAssetAddr, getAssetInfo('DAI').address)
67
+ const strategyOrBundleId = compareAddresses(closeToAssetAddr, getAssetInfo('DAI', chainId).address)
68
68
  ? Strategies.MainnetIds.MAKER_TRAILING_STOP_LOSS_TO_DAI
69
69
  : Strategies.MainnetIds.MAKER_TRAILING_STOP_LOSS_TO_COLL;
70
70
 
@@ -194,12 +194,13 @@ export const liquityPaybackUsingChickenBondSubData = {
194
194
  /**
195
195
  * @param sourceId bondId or subId
196
196
  * @param sourceType 0 for bond, 1 for subId
197
+ * @param chainId
197
198
  */
198
- encode: (sourceId: string, sourceType: number): SubData => {
199
+ encode: (sourceId: string, sourceType: number, chainId: ChainId = ChainId.Ethereum): SubData => {
199
200
  const sourceIdEncoded = mockedWeb3.eth.abi.encodeParameter('uint256', sourceId);
200
201
  const sourceTypeEncoded = mockedWeb3.eth.abi.encodeParameter('uint256', sourceType);
201
- const lusdAddressEncoded = mockedWeb3.eth.abi.encodeParameter('address', getAssetInfo('LUSD').address);
202
- const bLusdAddressEncoded = mockedWeb3.eth.abi.encodeParameter('address', getAssetInfo('bLUSD').address);
202
+ const lusdAddressEncoded = mockedWeb3.eth.abi.encodeParameter('address', getAssetInfo('LUSD', chainId).address);
203
+ const bLusdAddressEncoded = mockedWeb3.eth.abi.encodeParameter('address', getAssetInfo('bLUSD', chainId).address);
203
204
 
204
205
  return [sourceIdEncoded, sourceTypeEncoded, lusdAddressEncoded, bLusdAddressEncoded];
205
206
  },
@@ -24,15 +24,15 @@ export enum BundleProtocols {
24
24
  */
25
25
  export namespace ProtocolIdentifiers {
26
26
  export enum StrategiesAutomation {
27
- MakerDAO = 'MakerDAO__MCD',
27
+ MakerDAO = 'MakerDAO',
28
28
  Liquity = 'Liquity',
29
- ChickenBonds = '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 = 'MakerDAO__MCD',
35
+ MakerDAO = 'MakerDAO',
36
36
  CompoundV2 = 'Compound__V2',
37
37
  AaveV2 = 'Aave__V2',
38
38
  }
@@ -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,16 +169,19 @@ 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,
175
176
  protocol: Interfaces.LegacyProtocol,
177
+ strategy: {
178
+ strategyId: string,
179
+ protocol: Interfaces.Protocol,
180
+ },
176
181
  specific: any,
177
182
  }
178
183
  }
179
184
 
180
-
181
185
  type StrategyInfo<T extends number> = Record<T, Strategy<T>>;
182
186
  export type MainnetStrategiesInfo = StrategyInfo<Strategies.MainnetIds>;
183
187
  export type OptimismStrategiesInfo = StrategyInfo<Strategies.OptimismIds>;
@@ -204,9 +208,9 @@ export type StrategyOrBundleIds =
204
208
  Strategies.MainnetIds & Strategies.OptimismIds & Strategies.ArbitrumIds
205
209
  & Bundles.MainnetIds & Bundles.OptimismIds & Bundles.ArbitrumIds;
206
210
 
207
-
208
211
  export interface ParseData {
209
212
  chainId: ChainId,
213
+ blockNumber: BlockNumber,
210
214
  subscriptionEventData: Subscribe['returnValues']
211
215
  strategiesSubsData: StrategyModel.StoredSubDataStructOutputStruct,
212
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"] = "MakerDAO__MCD";
329
+ StrategiesAutomation["MakerDAO"] = "MakerDAO";
330
330
  StrategiesAutomation["Liquity"] = "Liquity";
331
- StrategiesAutomation["ChickenBonds"] = "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"] = "MakerDAO__MCD";
338
+ LegacyAutomation["MakerDAO"] = "MakerDAO";
339
339
  LegacyAutomation["CompoundV2"] = "Compound__V2";
340
340
  LegacyAutomation["AaveV2"] = "Aave__V2";
341
341
  })(LegacyAutomation || (LegacyAutomation = {}));
@@ -919,14 +919,17 @@ class LegacyAutomation extends _Automation__WEBPACK_IMPORTED_MODULE_3__["default
919
919
  var subscriptions = yield _this4._getSubscriptions(addresses);
920
920
 
921
921
  // @ts-ignore
922
- subscriptions = subscriptions.map(sub => ({
922
+ return subscriptions.map(sub => ({
923
923
  chainId: _this4.chainId,
924
924
  owner: sub[_this4.getOwnerPropName()],
925
925
  isEnabled: true,
926
926
  protocol: _this4.protocol,
927
- specific: _objectSpread({}, sub)
927
+ specific: _objectSpread({}, sub),
928
+ strategy: {
929
+ strategyId: 'legacy',
930
+ protocol: _this4.protocol
931
+ }
928
932
  }));
929
- return subscriptions;
930
933
  })();
931
934
  }
932
935
  getSubscriptions() {
@@ -1139,11 +1142,13 @@ __webpack_require__.r(__webpack_exports__);
1139
1142
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
1140
1143
  /* harmony export */ "default": () => (/* binding */ StrategiesAutomation)
1141
1144
  /* harmony export */ });
1142
- /* harmony import */ var _services_utils__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(18);
1143
- /* harmony import */ var _services_contractService__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(17);
1144
- /* harmony import */ var _services_ethereumService__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(21);
1145
- /* harmony import */ var _Automation__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(22);
1146
- /* harmony import */ var _services_strategiesService__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(27);
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);
1147
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; }
1148
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; }
1149
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); } }
@@ -1156,7 +1161,8 @@ function _toPrimitive(input, hint) { if (typeof input !== "object" || input ===
1156
1161
 
1157
1162
 
1158
1163
 
1159
- class StrategiesAutomation extends _Automation__WEBPACK_IMPORTED_MODULE_3__["default"] {
1164
+
1165
+ class StrategiesAutomation extends _Automation__WEBPACK_IMPORTED_MODULE_4__["default"] {
1160
1166
  constructor(args) {
1161
1167
  super();
1162
1168
  _defineProperty(this, "chainId", void 0);
@@ -1164,13 +1170,13 @@ class StrategiesAutomation extends _Automation__WEBPACK_IMPORTED_MODULE_3__["def
1164
1170
  _defineProperty(this, "subStorageContract", void 0);
1165
1171
  this.web3 = args.provider;
1166
1172
  this.chainId = args.chainId;
1167
- this.subStorageContract = (0,_services_contractService__WEBPACK_IMPORTED_MODULE_1__.makeSubStorageContract)(this.web3, this.chainId);
1173
+ this.subStorageContract = (0,_services_contractService__WEBPACK_IMPORTED_MODULE_2__.makeSubStorageContract)(this.web3, this.chainId);
1168
1174
  this.assert();
1169
1175
  }
1170
1176
  getEventFromSubStorage(event, options) {
1171
1177
  var _this = this;
1172
1178
  return _asyncToGenerator(function* () {
1173
- return (0,_services_ethereumService__WEBPACK_IMPORTED_MODULE_2__.getEventsFromContract)(_this.subStorageContract, event, options);
1179
+ return (0,_services_ethereumService__WEBPACK_IMPORTED_MODULE_3__.getEventsFromContract)(_this.subStorageContract, event, options);
1174
1180
  })();
1175
1181
  }
1176
1182
  getStrategiesSubs(subIds) {
@@ -1179,12 +1185,12 @@ class StrategiesAutomation extends _Automation__WEBPACK_IMPORTED_MODULE_3__["def
1179
1185
  var subStorageContract = _this2.subStorageContract;
1180
1186
  var defaultOptions = {
1181
1187
  target: subStorageContract.address,
1182
- abiItem: (0,_services_contractService__WEBPACK_IMPORTED_MODULE_1__.getAbiItem)(subStorageContract.abi, 'strategiesSubs')
1188
+ abiItem: (0,_services_contractService__WEBPACK_IMPORTED_MODULE_2__.getAbiItem)(subStorageContract.abi, 'strategiesSubs')
1183
1189
  };
1184
1190
  var multicallCalls = subIds.map(subId => _objectSpread(_objectSpread({}, defaultOptions), {}, {
1185
1191
  params: [subId]
1186
1192
  }));
1187
- return (0,_services_ethereumService__WEBPACK_IMPORTED_MODULE_2__.multicall)(_this2.web3, _this2.chainId, multicallCalls);
1193
+ return (0,_services_ethereumService__WEBPACK_IMPORTED_MODULE_3__.multicall)(_this2.web3, _this2.chainId, multicallCalls);
1188
1194
  })();
1189
1195
  }
1190
1196
  getSubscriptionEventsFromSubStorage(options) {
@@ -1202,28 +1208,28 @@ class StrategiesAutomation extends _Automation__WEBPACK_IMPORTED_MODULE_3__["def
1202
1208
  })();
1203
1209
  }
1204
1210
  getParsedSubscriptions(parseData) {
1205
- return (0,_services_strategiesService__WEBPACK_IMPORTED_MODULE_4__.parseStrategiesAutomatedPosition)(parseData);
1211
+ return (0,_services_strategiesService__WEBPACK_IMPORTED_MODULE_5__.parseStrategiesAutomatedPosition)(parseData);
1206
1212
  }
1207
1213
  _getSubscriptions(addresses, options) {
1208
1214
  var _this5 = this;
1209
1215
  return _asyncToGenerator(function* () {
1210
- var _options = _objectSpread(_objectSpread({}, (0,_services_utils__WEBPACK_IMPORTED_MODULE_0__.addToObjectIf)((0,_services_utils__WEBPACK_IMPORTED_MODULE_0__.isDefined)(options), options)), (0,_services_utils__WEBPACK_IMPORTED_MODULE_0__.addToObjectIf)((0,_services_utils__WEBPACK_IMPORTED_MODULE_0__.isDefined)(addresses), {
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), {
1211
1217
  filter: {
1212
1218
  proxy: addresses
1213
1219
  }
1214
1220
  }));
1215
- var subscriptionEvents = (yield _this5.getSubscriptionEventsFromSubStorage(_options)).map(e => e.returnValues); // TODO PlaceholderType
1221
+ var subscriptionEvents = yield _this5.getSubscriptionEventsFromSubStorage(_options); // TODO PlaceholderType
1216
1222
 
1217
1223
  var subscriptions = [];
1218
1224
  if (subscriptionEvents) {
1219
1225
  // @ts-ignore
1220
- var strategiesSubs = yield _this5.getStrategiesSubs(subscriptionEvents.map(e => e.subId));
1226
+ var strategiesSubs = yield _this5.getStrategiesSubs(subscriptionEvents.map(e => e.returnValues.subId));
1221
1227
  subscriptions = yield Promise.all(strategiesSubs.map( /*#__PURE__*/function () {
1222
1228
  var _ref = _asyncToGenerator(function* (sub, index) {
1223
- var latestUpdate = subscriptionEvents[index];
1229
+ var latestUpdate = subscriptionEvents[index].returnValues;
1224
1230
  if (latestUpdate.subHash !== (sub === null || sub === void 0 ? void 0 : sub.strategySubHash)) {
1225
1231
  var _updates;
1226
- var updates = yield _this5.getUpdateDataEventsFromSubStorage(_objectSpread(_objectSpread({}, (0,_services_utils__WEBPACK_IMPORTED_MODULE_0__.addToObjectIf)(!!_options, _options)), {}, {
1232
+ var updates = yield _this5.getUpdateDataEventsFromSubStorage(_objectSpread(_objectSpread({}, (0,_services_utils__WEBPACK_IMPORTED_MODULE_1__.addToObjectIf)(!!_options, _options)), {}, {
1227
1233
  filter: {
1228
1234
  subId: latestUpdate.subId
1229
1235
  }
@@ -1232,6 +1238,7 @@ class StrategiesAutomation extends _Automation__WEBPACK_IMPORTED_MODULE_3__["def
1232
1238
  }
1233
1239
  return _this5.getParsedSubscriptions({
1234
1240
  chainId: _this5.chainId,
1241
+ blockNumber: subscriptionEvents[index].blockNumber,
1235
1242
  subscriptionEventData: latestUpdate,
1236
1243
  strategiesSubsData: sub
1237
1244
  });
@@ -1243,14 +1250,16 @@ class StrategiesAutomation extends _Automation__WEBPACK_IMPORTED_MODULE_3__["def
1243
1250
  if (options !== null && options !== void 0 && options.mergeWithSameId) {
1244
1251
  subscriptions = subscriptions.reduce((list, current) => {
1245
1252
  var copyList = [...list];
1246
- if ((0,_services_utils__WEBPACK_IMPORTED_MODULE_0__.isDefined)(current)) {
1253
+ if ((0,_services_utils__WEBPACK_IMPORTED_MODULE_1__.isDefined)(current)) {
1247
1254
  if (current.specific.mergeWithSameId) {
1248
- 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);
1249
1256
  if (mergePairIndex !== -1) {
1250
1257
  var mergePair = copyList[mergePairIndex];
1251
- if ((0,_services_utils__WEBPACK_IMPORTED_MODULE_0__.isDefined)(mergePair)) {
1258
+ if ((0,_services_utils__WEBPACK_IMPORTED_MODULE_1__.isDefined)(mergePair)) {
1252
1259
  copyList[mergePairIndex] = _objectSpread(_objectSpread(_objectSpread({}, mergePair), current), {}, {
1253
- subIds: (0,_services_utils__WEBPACK_IMPORTED_MODULE_0__.isDefined)(mergePair.subIds) ? [...mergePair.subIds, current.subId] : undefined,
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,
1254
1263
  isEnabled: mergePair.isEnabled || current.isEnabled,
1255
1264
  subId: mergePair.subId,
1256
1265
  specific: _objectSpread(_objectSpread(_objectSpread({}, mergePair.specific), current.specific), {}, {
@@ -1553,6 +1562,7 @@ function getParsingMethod(id, strategy) {
1553
1562
  function parseStrategiesAutomatedPosition(parseData) {
1554
1563
  var {
1555
1564
  chainId,
1565
+ blockNumber,
1556
1566
  subscriptionEventData,
1557
1567
  strategiesSubsData
1558
1568
  } = parseData;
@@ -1572,6 +1582,7 @@ function parseStrategiesAutomatedPosition(parseData) {
1572
1582
  isEnabled,
1573
1583
  chainId,
1574
1584
  subHash,
1585
+ blockNumber,
1575
1586
  subId: Number(subId),
1576
1587
  owner: proxy,
1577
1588
  protocol: _objectSpread({}, strategyOrBundleInfo.protocol),
@@ -18975,12 +18986,14 @@ var liquityPaybackUsingChickenBondSubData = {
18975
18986
  /**
18976
18987
  * @param sourceId bondId or subId
18977
18988
  * @param sourceType 0 for bond, 1 for subId
18989
+ * @param chainId
18978
18990
  */
18979
- encode: (sourceId, sourceType) => {
18991
+ encode: function encode(sourceId, sourceType) {
18992
+ var chainId = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _types_enums__WEBPACK_IMPORTED_MODULE_3__.ChainId.Ethereum;
18980
18993
  var sourceIdEncoded = mockedWeb3.eth.abi.encodeParameter('uint256', sourceId);
18981
18994
  var sourceTypeEncoded = mockedWeb3.eth.abi.encodeParameter('uint256', sourceType);
18982
- var lusdAddressEncoded = mockedWeb3.eth.abi.encodeParameter('address', (0,_defisaver_tokens__WEBPACK_IMPORTED_MODULE_1__.getAssetInfo)('LUSD').address);
18983
- var bLusdAddressEncoded = mockedWeb3.eth.abi.encodeParameter('address', (0,_defisaver_tokens__WEBPACK_IMPORTED_MODULE_1__.getAssetInfo)('bLUSD').address);
18995
+ var lusdAddressEncoded = mockedWeb3.eth.abi.encodeParameter('address', (0,_defisaver_tokens__WEBPACK_IMPORTED_MODULE_1__.getAssetInfo)('LUSD', chainId).address);
18996
+ var bLusdAddressEncoded = mockedWeb3.eth.abi.encodeParameter('address', (0,_defisaver_tokens__WEBPACK_IMPORTED_MODULE_1__.getAssetInfo)('bLUSD', chainId).address);
18984
18997
  return [sourceIdEncoded, sourceTypeEncoded, lusdAddressEncoded, bLusdAddressEncoded];
18985
18998
  },
18986
18999
  decode: subData => {
@@ -28776,7 +28789,7 @@ var makerEncode = {
28776
28789
  (0,_utils__WEBPACK_IMPORTED_MODULE_5__.requireAddresses)([closeToAssetAddr, chainlinkCollAddress]);
28777
28790
  var subData = _subDataService__WEBPACK_IMPORTED_MODULE_3__.makerCloseSubData.encode(vaultId, closeToAssetAddr, chainId, daiAddr, mcdCdpManagerAddr);
28778
28791
  var triggerData = _triggerService__WEBPACK_IMPORTED_MODULE_4__.trailingStopTrigger.encode(chainlinkCollAddress, triggerPercentage, roundId);
28779
- var strategyOrBundleId = (0,_utils__WEBPACK_IMPORTED_MODULE_5__.compareAddresses)(closeToAssetAddr, (0,_defisaver_tokens__WEBPACK_IMPORTED_MODULE_1__.getAssetInfo)('DAI').address) ? _types_enums__WEBPACK_IMPORTED_MODULE_2__.Strategies.MainnetIds.MAKER_TRAILING_STOP_LOSS_TO_DAI : _types_enums__WEBPACK_IMPORTED_MODULE_2__.Strategies.MainnetIds.MAKER_TRAILING_STOP_LOSS_TO_COLL;
28792
+ var strategyOrBundleId = (0,_utils__WEBPACK_IMPORTED_MODULE_5__.compareAddresses)(closeToAssetAddr, (0,_defisaver_tokens__WEBPACK_IMPORTED_MODULE_1__.getAssetInfo)('DAI', chainId).address) ? _types_enums__WEBPACK_IMPORTED_MODULE_2__.Strategies.MainnetIds.MAKER_TRAILING_STOP_LOSS_TO_DAI : _types_enums__WEBPACK_IMPORTED_MODULE_2__.Strategies.MainnetIds.MAKER_TRAILING_STOP_LOSS_TO_COLL;
28780
28793
  var isBundle = false;
28781
28794
  return [strategyOrBundleId, isBundle, triggerData, subData];
28782
28795
  }