@defisaver/automation-sdk 2.0.2 → 2.0.3

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.
Files changed (53) hide show
  1. package/.eslintrc.js +1 -0
  2. package/esm/abis/index.js +27 -15
  3. package/esm/automation/private/Automation.js +9 -6
  4. package/esm/automation/private/LegacyAutomation.d.ts +5 -5
  5. package/esm/automation/private/LegacyAutomation.js +30 -23
  6. package/esm/automation/private/LegacyProtocol.js +4 -1
  7. package/esm/automation/private/Protocol.js +4 -1
  8. package/esm/automation/private/StrategiesAutomation.d.ts +2 -2
  9. package/esm/automation/private/StrategiesAutomation.js +27 -21
  10. package/esm/automation/public/ArbitrumStrategies.js +10 -4
  11. package/esm/automation/public/EthereumStrategies.js +10 -4
  12. package/esm/automation/public/OptimismStrategies.js +10 -4
  13. package/esm/automation/public/legacy/LegacyAaveAutomation.js +13 -7
  14. package/esm/automation/public/legacy/LegacyCompoundAutomation.js +13 -7
  15. package/esm/automation/public/legacy/LegacyMakerAutomation.js +13 -7
  16. package/esm/configuration.js +8 -5
  17. package/esm/constants/index.js +281 -275
  18. package/esm/index.js +57 -17
  19. package/esm/services/contractService.js +22 -14
  20. package/esm/services/ethereumService.js +18 -10
  21. package/esm/services/strategiesService.js +130 -103
  22. package/esm/services/strategySubService.js +90 -61
  23. package/esm/services/subDataService.js +151 -145
  24. package/esm/services/triggerService.d.ts +5 -5
  25. package/esm/services/triggerService.js +124 -94
  26. package/esm/services/utils.js +82 -33
  27. package/esm/services/utils.test.d.ts +1 -0
  28. package/esm/services/utils.test.js +362 -0
  29. package/esm/types/contracts/generated/Erc20.js +2 -1
  30. package/esm/types/contracts/generated/Legacy_AaveV2Subscriptions.js +2 -1
  31. package/esm/types/contracts/generated/Legacy_AuthCheck.js +2 -1
  32. package/esm/types/contracts/generated/Legacy_CompoundV2Subscriptions.js +2 -1
  33. package/esm/types/contracts/generated/Legacy_MakerSubscriptions.js +2 -1
  34. package/esm/types/contracts/generated/SubStorage.js +2 -1
  35. package/esm/types/contracts/generated/UniMulticall.js +2 -1
  36. package/esm/types/contracts/generated/index.js +2 -1
  37. package/esm/types/contracts/generated/types.js +2 -1
  38. package/esm/types/enums.js +17 -14
  39. package/esm/types/index.js +2 -1
  40. package/package.json +11 -7
  41. package/src/automation/private/LegacyAutomation.ts +11 -10
  42. package/src/automation/private/StrategiesAutomation.ts +5 -6
  43. package/src/configuration.ts +0 -3
  44. package/src/index.ts +0 -1
  45. package/src/services/ethereumService.ts +6 -6
  46. package/src/services/subDataService.ts +75 -76
  47. package/src/services/triggerService.ts +83 -83
  48. package/src/services/utils.test.ts +414 -0
  49. package/src/services/utils.ts +6 -7
  50. package/tsconfig.json +1 -1
  51. package/umd/index.js +7016 -4105
  52. package/src/types/typings/process.d.ts +0 -9
  53. package/yarn-error.log +0 -7233
@@ -0,0 +1,362 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ const chai_1 = require("chai");
30
+ const web3Utils = __importStar(require("web3-utils"));
31
+ const web3_eth_abi_1 = __importDefault(require("web3-eth-abi"));
32
+ const tokens_1 = require("@defisaver/tokens");
33
+ const enums_1 = require("../types/enums");
34
+ const strategySubService_1 = require("./strategySubService");
35
+ const utils_1 = require("./utils");
36
+ describe('Feature: utils.ts', () => {
37
+ describe('When testing utils.isDefined()', () => {
38
+ const examples = [
39
+ [true, 'something'],
40
+ [true, NaN],
41
+ [true, 0],
42
+ [false, undefined],
43
+ [false, null],
44
+ ];
45
+ examples.forEach(([expected, actual]) => {
46
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
47
+ (0, chai_1.expect)((0, utils_1.isDefined)(actual)).to.equal(expected);
48
+ });
49
+ });
50
+ });
51
+ describe('When testing utils.isUndefined()', () => {
52
+ const examples = [
53
+ [false, 'something'],
54
+ [false, NaN],
55
+ [false, 0],
56
+ [true, undefined],
57
+ [true, null],
58
+ ];
59
+ examples.forEach(([expected, actual]) => {
60
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
61
+ (0, chai_1.expect)((0, utils_1.isUndefined)(actual)).to.equal(expected);
62
+ });
63
+ });
64
+ });
65
+ describe('When testing utils.compareAddresses()', () => {
66
+ const examples = [
67
+ [true, ['nesto', 'nesto']],
68
+ [true, ['', '']],
69
+ [false, ['something', 'nesto']],
70
+ [false, ['', 'nesto']],
71
+ ];
72
+ examples.forEach(([expected, actual]) => {
73
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
74
+ (0, chai_1.expect)((0, utils_1.compareAddresses)(...actual)).to.equal(expected);
75
+ });
76
+ });
77
+ });
78
+ describe('When testing utils.isAddress()', () => {
79
+ const examples = [
80
+ [true, '0x996bc83fa1b947cca00e5dcf776c438096549062'],
81
+ [true, '0x0000000000000000000000000000000000000000'],
82
+ [false, '0x996bc83fa147cca00e5dcf776c438096549062'],
83
+ [false, '0x996bc83fa147cca00e5dcf776c438096549062xx'],
84
+ [false, ''],
85
+ [false, 'majmune.eth'],
86
+ ];
87
+ examples.forEach(([expected, actual]) => {
88
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
89
+ (0, chai_1.expect)((0, utils_1.isAddress)(actual)).to.equal(expected);
90
+ });
91
+ });
92
+ });
93
+ describe('When testing utils.addToArrayIf()', () => {
94
+ const exampleOne = [1, ...(0, utils_1.addToArrayIf)(true, 2)];
95
+ const actualOne = [1, 2];
96
+ it(`Given ${actualOne.join(', ')} should return expected value: [${exampleOne.join(', ')}]`, () => {
97
+ (0, chai_1.expect)(actualOne).to.eql(exampleOne);
98
+ });
99
+ const exampleTwo = [1, ...(0, utils_1.addToArrayIf)(false, 2)];
100
+ const actualTwo = [1];
101
+ it(`Given ${actualTwo.join(', ')} should return expected value: [${exampleTwo.join(', ')}]`, () => {
102
+ (0, chai_1.expect)(actualTwo).to.eql(exampleTwo);
103
+ });
104
+ });
105
+ describe('When testing utils.addToObjectIf()', () => {
106
+ const exampleOne = Object.assign({ a: 1 }, (0, utils_1.addToObjectIf)(true, { b: 2 }));
107
+ const actualOne = { a: 1, b: 2 };
108
+ it(`Given ${JSON.stringify(actualOne)} should return expected value: ${JSON.stringify(exampleOne)}`, () => {
109
+ (0, chai_1.expect)(actualOne).to.eql(exampleOne);
110
+ });
111
+ const exampleTwo = Object.assign({ a: 1 }, (0, utils_1.addToObjectIf)(false, { b: 2 }));
112
+ const actualTwo = { a: 1 };
113
+ it(`Given ${JSON.stringify(actualTwo)} should return expected value: ${JSON.stringify(exampleTwo)}`, () => {
114
+ (0, chai_1.expect)(actualTwo).to.eql(exampleTwo);
115
+ });
116
+ });
117
+ describe('When testing utils.ethToWeth()', () => {
118
+ const examples = [
119
+ ['WETH', 'ETH'],
120
+ ['rETH', 'rETH'],
121
+ ['ETH.c', 'ETH.c'],
122
+ ['cETHx2', 'cETHx2'],
123
+ ['WETH', 'WETH'],
124
+ ['DAI', 'DAI'],
125
+ ];
126
+ examples.forEach(([expected, actual]) => {
127
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
128
+ (0, chai_1.expect)((0, utils_1.ethToWeth)(actual)).to.equal(expected);
129
+ });
130
+ });
131
+ });
132
+ describe('When testing utils.wethToEth()', () => {
133
+ const examples = [
134
+ ['ETH', 'ETH'],
135
+ ['rETH', 'rETH'],
136
+ ['ETH.c', 'ETH.c'],
137
+ ['cETHx2', 'cETHx2'],
138
+ ['ETH', 'WETH'],
139
+ ['DAI', 'DAI'],
140
+ ];
141
+ examples.forEach(([expected, actual]) => {
142
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
143
+ (0, chai_1.expect)((0, utils_1.wethToEth)(actual)).to.equal(expected);
144
+ });
145
+ });
146
+ });
147
+ describe('When testing utils.wethToEthByAddress()', () => {
148
+ /**
149
+ * @dev wethToEthByAddress will return empty string when asset doesn't exist in assets array of @defisaver/tokens
150
+ * This is @defisaver/tokens problem, but still seems like a wierd behaviour
151
+ */
152
+ const examples = [
153
+ ['0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', ['0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', 1]],
154
+ ['0xb3319f5d18bc0d84dd1b4825dcde5d5f7266d407', ['0xb3319f5d18bc0d84dd1b4825dcde5d5f7266d407', 1]],
155
+ ['0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', ['0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', 1]],
156
+ ['0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', ['0x4200000000000000000000000000000000000006', 10]],
157
+ ['0xab7badef82e9fe11f6f33f87bc9bc2aa27f2fcb5', ['0xab7badef82e9fe11f6f33f87bc9bc2aa27f2fcb5', 10]],
158
+ ['0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', ['0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', 10]],
159
+ ['0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', ['0x82aF49447D8a07e3bd95BD0d56f35241523fBab1', 42161]],
160
+ ['0xaf88d065e77c8cC2239327C5EDb3A432268e5831', ['0xaf88d065e77c8cC2239327C5EDb3A432268e5831', 42161]],
161
+ ['0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', ['0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', 42161]],
162
+ ];
163
+ examples.forEach(([expected, actual]) => {
164
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
165
+ (0, chai_1.expect)((0, utils_1.wethToEthByAddress)(...actual)).to.equal(expected);
166
+ });
167
+ });
168
+ });
169
+ describe('When testing utils.compareSubHashes()', () => {
170
+ const subDataToEncodeOne = [
171
+ 12,
172
+ false,
173
+ {
174
+ baseTokenAddress: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
175
+ quoteTokenAddress: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
176
+ price: 100,
177
+ ratioState: 1,
178
+ },
179
+ {
180
+ collAsset: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
181
+ collAssetId: 2,
182
+ debtAsset: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
183
+ debtAssetId: 3,
184
+ },
185
+ ];
186
+ const subDataToEncodeTwo = [
187
+ 13,
188
+ true,
189
+ {
190
+ baseTokenAddress: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
191
+ quoteTokenAddress: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
192
+ price: 100,
193
+ ratioState: 2,
194
+ },
195
+ {
196
+ collAsset: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
197
+ collAssetId: 2,
198
+ debtAsset: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
199
+ debtAssetId: 3,
200
+ },
201
+ ];
202
+ // @ts-ignore
203
+ const encodedSubDataOne = strategySubService_1.sparkEncode.closeToAsset(...subDataToEncodeOne);
204
+ // @ts-ignore
205
+ const encodedSubDataTwo = strategySubService_1.sparkEncode.closeToAsset(...subDataToEncodeTwo);
206
+ const encodedParams = web3Utils.keccak256(web3_eth_abi_1.default.encodeParameter('(uint64,bool,bytes[],bytes32[])', encodedSubDataOne));
207
+ const examples = [
208
+ [true, [encodedParams, encodedSubDataOne]],
209
+ [false, [encodedParams, encodedSubDataTwo]],
210
+ ];
211
+ examples.forEach(([expected, actual]) => {
212
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
213
+ (0, chai_1.expect)((0, utils_1.compareSubHashes)(...actual)).to.equal(expected);
214
+ });
215
+ });
216
+ });
217
+ describe('When testing utils.encodeSubId()', () => {
218
+ const examples = [
219
+ ['00000001', '1'],
220
+ ['00000002', '2'],
221
+ ['0021c503', '2213123']
222
+ ];
223
+ examples.forEach(([expected, actual]) => {
224
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
225
+ (0, chai_1.expect)((0, utils_1.encodeSubId)(actual)).to.equal(expected);
226
+ });
227
+ });
228
+ });
229
+ describe('When testing utils.ratioPercentageToWei()', () => {
230
+ const examples = [
231
+ ['1200000000000000000', 120],
232
+ ['2400000000000000000', 240],
233
+ ['870000000000000000', 87],
234
+ ];
235
+ examples.forEach(([expected, actual]) => {
236
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
237
+ (0, chai_1.expect)((0, utils_1.ratioPercentageToWei)(actual)).to.equal(expected);
238
+ });
239
+ });
240
+ });
241
+ describe('When testing utils.weiToRatioPercentage()', () => {
242
+ const examples = [
243
+ [120, '1200000000000000000'],
244
+ [240, '2400000000000000000'],
245
+ [87, '870000000000000000'],
246
+ ];
247
+ examples.forEach(([expected, actual]) => {
248
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
249
+ (0, chai_1.expect)((0, utils_1.weiToRatioPercentage)(actual)).to.equal(expected);
250
+ });
251
+ });
252
+ });
253
+ describe('When testing utils.isRatioStateOver()', () => {
254
+ const examples = [
255
+ [true, enums_1.RatioState.OVER],
256
+ [false, enums_1.RatioState.UNDER],
257
+ [false, NaN],
258
+ [false, 3],
259
+ [false, Infinity],
260
+ ];
261
+ examples.forEach(([expected, actual]) => {
262
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
263
+ (0, chai_1.expect)((0, utils_1.isRatioStateOver)(actual)).to.equal(expected);
264
+ });
265
+ });
266
+ });
267
+ describe('When testing utils.isRatioStateUnder()', () => {
268
+ const examples = [
269
+ [true, enums_1.RatioState.UNDER],
270
+ [false, enums_1.RatioState.OVER],
271
+ [false, NaN],
272
+ [false, 3],
273
+ [false, Infinity],
274
+ ];
275
+ examples.forEach(([expected, actual]) => {
276
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
277
+ (0, chai_1.expect)((0, utils_1.isRatioStateUnder)(actual)).to.equal(expected);
278
+ });
279
+ });
280
+ });
281
+ describe('When testing utils.isEmptyBytes()', () => {
282
+ const examples = [
283
+ [true, '0x0000000000000000000000000000000000000000'],
284
+ [false, '0x0000000000000000000000000000000000000001'],
285
+ [false, '0x00000000000000000000000000000000000000000000'],
286
+ [false, '0x000000000000000000000000000000000000000'],
287
+ [false, ''],
288
+ ];
289
+ examples.forEach(([expected, actual]) => {
290
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
291
+ (0, chai_1.expect)((0, utils_1.isEmptyBytes)(actual)).to.equal(expected);
292
+ });
293
+ });
294
+ });
295
+ describe('When testing utils.requireAddress()', () => {
296
+ const examples = [
297
+ [true, '0x1e5698681E03326d783215adfB3173acF3Cf2B6'],
298
+ [true, 1312],
299
+ [true, ''],
300
+ [true, '0x0000000000000000000000000000000000000000'],
301
+ [true, '0xZe5698681E03326d783215adfB3173acF3Cf2B6'],
302
+ [true, 'Ze5698681E03326d783215adfB3173acF3Cf2B6'],
303
+ [false, '0x1e5698681E03326d783215adfB3173acF3Cf2B61'],
304
+ ];
305
+ examples.forEach(([expected, actual]) => {
306
+ if (expected) {
307
+ it(`Given ${actual} should throw an error`, () => {
308
+ (0, chai_1.expect)(() => (0, utils_1.requireAddress)(actual)).to.throw(Error);
309
+ });
310
+ }
311
+ else {
312
+ it(`Given ${actual} should not throw an error`, () => {
313
+ (0, chai_1.expect)(() => (0, utils_1.requireAddress)(actual)).not.to.throw(Error);
314
+ });
315
+ }
316
+ });
317
+ });
318
+ describe('When testing utils.requireAddresses()', () => {
319
+ const examples = [
320
+ [true, '0x1e5698681E03326d783215adfB3173acF3Cf2B6'],
321
+ [true, [1312, '0x1e5698681E03326d783215adfB3173acF3Cf2B61']],
322
+ [true, ['', '0x1e5698681E03326d783215adfB3173acF3Cf2B61']],
323
+ [true, ['0x0000000000000000000000000000000000000000', '0x1e5698481E03326d783215adfB3173acF3Cf2B61']],
324
+ [true, ['0xZe5698681E03326d783215adfB3173acF3Cf2B6', '0x1e5698681E03326d783215adfB3173acF3Cc2B61']],
325
+ [true, ['Ze5698681E03326d783215adfB3173acF3Cf2B6', '', '0x1e5698681E03326d783215adfB3173acF3Cf2B61']],
326
+ [false, ['0x1e5698681E03326d783215adfB3173acF3Cf2B61', '0x2e5698681E03326d783215adfB3173acF3Cf2B61']],
327
+ ];
328
+ examples.forEach(([expected, actual]) => {
329
+ if (expected) {
330
+ it(`Given ${actual} should throw an error`, () => {
331
+ (0, chai_1.expect)(() => (0, utils_1.requireAddresses)(actual)).to.throw(Error);
332
+ });
333
+ }
334
+ else {
335
+ it(`Given ${actual} should not throw an error`, () => {
336
+ (0, chai_1.expect)(() => (0, utils_1.requireAddresses)(actual)).not.to.throw(Error);
337
+ });
338
+ }
339
+ });
340
+ });
341
+ describe('When testing utils.getRatioStateInfoForAaveCloseStrategy()', () => {
342
+ const examples = [
343
+ [
344
+ { shouldFlip: true, ratioState: enums_1.RatioState.UNDER },
345
+ [enums_1.RatioState.OVER, (0, tokens_1.getAssetInfo)('DAI').address, (0, tokens_1.getAssetInfo)('ETH').address, enums_1.ChainId.Ethereum]
346
+ ],
347
+ [
348
+ { shouldFlip: false, ratioState: enums_1.RatioState.UNDER },
349
+ [enums_1.RatioState.UNDER, (0, tokens_1.getAssetInfo)('DAI').address, (0, tokens_1.getAssetInfo)('ETH').address, enums_1.ChainId.Arbitrum]
350
+ ],
351
+ [
352
+ { shouldFlip: false, ratioState: enums_1.RatioState.OVER },
353
+ [enums_1.RatioState.OVER, (0, tokens_1.getAssetInfo)('ETH').address, (0, tokens_1.getAssetInfo)('ETH').address, enums_1.ChainId.Optimism]
354
+ ],
355
+ ];
356
+ examples.forEach(([expected, actual]) => {
357
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
358
+ (0, chai_1.expect)((0, utils_1.getRatioStateInfoForAaveCloseStrategy)(...actual)).to.eql(expected);
359
+ });
360
+ });
361
+ });
362
+ });
@@ -1,4 +1,5 @@
1
+ "use strict";
1
2
  /* Autogenerated file. Do not edit manually. */
2
3
  /* tslint:disable */
3
4
  /* eslint-disable */
4
- export {};
5
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,4 +1,5 @@
1
+ "use strict";
1
2
  /* Autogenerated file. Do not edit manually. */
2
3
  /* tslint:disable */
3
4
  /* eslint-disable */
4
- export {};
5
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,4 +1,5 @@
1
+ "use strict";
1
2
  /* Autogenerated file. Do not edit manually. */
2
3
  /* tslint:disable */
3
4
  /* eslint-disable */
4
- export {};
5
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,4 +1,5 @@
1
+ "use strict";
1
2
  /* Autogenerated file. Do not edit manually. */
2
3
  /* tslint:disable */
3
4
  /* eslint-disable */
4
- export {};
5
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,4 +1,5 @@
1
+ "use strict";
1
2
  /* Autogenerated file. Do not edit manually. */
2
3
  /* tslint:disable */
3
4
  /* eslint-disable */
4
- export {};
5
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,4 +1,5 @@
1
+ "use strict";
1
2
  /* Autogenerated file. Do not edit manually. */
2
3
  /* tslint:disable */
3
4
  /* eslint-disable */
4
- export {};
5
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,4 +1,5 @@
1
+ "use strict";
1
2
  /* Autogenerated file. Do not edit manually. */
2
3
  /* tslint:disable */
3
4
  /* eslint-disable */
4
- export {};
5
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +1,2 @@
1
- export {};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +1,2 @@
1
- export {};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,25 +1,28 @@
1
- export var ChainId;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Bundles = exports.Strategies = exports.ProtocolIdentifiers = exports.BundleProtocols = exports.OrderType = exports.RatioState = exports.ChainId = void 0;
4
+ var ChainId;
2
5
  (function (ChainId) {
3
6
  ChainId[ChainId["Ethereum"] = 1] = "Ethereum";
4
7
  ChainId[ChainId["Optimism"] = 10] = "Optimism";
5
8
  ChainId[ChainId["Arbitrum"] = 42161] = "Arbitrum";
6
- })(ChainId || (ChainId = {}));
7
- export var RatioState;
9
+ })(ChainId = exports.ChainId || (exports.ChainId = {}));
10
+ var RatioState;
8
11
  (function (RatioState) {
9
12
  RatioState[RatioState["OVER"] = 0] = "OVER";
10
13
  RatioState[RatioState["UNDER"] = 1] = "UNDER";
11
- })(RatioState || (RatioState = {}));
12
- export var OrderType;
14
+ })(RatioState = exports.RatioState || (exports.RatioState = {}));
15
+ var OrderType;
13
16
  (function (OrderType) {
14
17
  OrderType[OrderType["TAKE_PROFIT"] = 0] = "TAKE_PROFIT";
15
18
  OrderType[OrderType["STOP_LOSS"] = 1] = "STOP_LOSS";
16
- })(OrderType || (OrderType = {}));
17
- export var BundleProtocols;
19
+ })(OrderType = exports.OrderType || (exports.OrderType = {}));
20
+ var BundleProtocols;
18
21
  (function (BundleProtocols) {
19
22
  BundleProtocols["MStable"] = "mstable";
20
23
  BundleProtocols["Yearn"] = "yearn";
21
24
  BundleProtocols["Rari"] = "rari";
22
- })(BundleProtocols || (BundleProtocols = {}));
25
+ })(BundleProtocols = exports.BundleProtocols || (exports.BundleProtocols = {}));
23
26
  /**
24
27
  * @dev Follow the naming convention:
25
28
  * - Enum name consists of two parts, name and version
@@ -27,7 +30,7 @@ export var BundleProtocols;
27
30
  * - Version should be separated from the name with double underscores `__` (If there is no version leave it out)
28
31
  * - Example `Name of ThePROTOCOL__v1` (Without version `Name of ThePROTOCOL`)
29
32
  */
30
- export var ProtocolIdentifiers;
33
+ var ProtocolIdentifiers;
31
34
  (function (ProtocolIdentifiers) {
32
35
  let StrategiesAutomation;
33
36
  (function (StrategiesAutomation) {
@@ -48,8 +51,8 @@ export var ProtocolIdentifiers;
48
51
  LegacyAutomation["CompoundV2"] = "Compound__V2";
49
52
  LegacyAutomation["AaveV2"] = "Aave__V2";
50
53
  })(LegacyAutomation = ProtocolIdentifiers.LegacyAutomation || (ProtocolIdentifiers.LegacyAutomation = {}));
51
- })(ProtocolIdentifiers || (ProtocolIdentifiers = {}));
52
- export var Strategies;
54
+ })(ProtocolIdentifiers = exports.ProtocolIdentifiers || (exports.ProtocolIdentifiers = {}));
55
+ var Strategies;
53
56
  (function (Strategies) {
54
57
  let MainnetIds;
55
58
  (function (MainnetIds) {
@@ -104,8 +107,8 @@ export var Strategies;
104
107
  IdOverrides["LeverageManagement"] = "leverage-management";
105
108
  IdOverrides["EoaLeverageManagement"] = "leverage-management-eoa";
106
109
  })(IdOverrides = Strategies.IdOverrides || (Strategies.IdOverrides = {}));
107
- })(Strategies || (Strategies = {}));
108
- export var Bundles;
110
+ })(Strategies = exports.Strategies || (exports.Strategies = {}));
111
+ var Bundles;
109
112
  (function (Bundles) {
110
113
  let MainnetIds;
111
114
  (function (MainnetIds) {
@@ -150,4 +153,4 @@ export var Bundles;
150
153
  ArbitrumIds[ArbitrumIds["AAVE_V3_CLOSE_TO_DEBT"] = 2] = "AAVE_V3_CLOSE_TO_DEBT";
151
154
  ArbitrumIds[ArbitrumIds["AAVE_V3_CLOSE_TO_COLLATERAL"] = 3] = "AAVE_V3_CLOSE_TO_COLLATERAL";
152
155
  })(ArbitrumIds = Bundles.ArbitrumIds || (Bundles.ArbitrumIds = {}));
153
- })(Bundles || (Bundles = {}));
156
+ })(Bundles = exports.Bundles || (exports.Bundles = {}));
@@ -1 +1,2 @@
1
- export {};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defisaver/automation-sdk",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
4
4
  "description": "",
5
5
  "main": "./umd/index.js",
6
6
  "module": "./esm/index.js",
@@ -14,7 +14,8 @@
14
14
  "document": "npx typedoc --out docs/default",
15
15
  "lint": "node_modules/.bin/eslint ./src",
16
16
  "gtc": "node scripts/generateContractTypes.js",
17
- "prepare": "husky install && npm run gtc"
17
+ "prepare": "husky install && npm run gtc",
18
+ "test": "mocha \"./src/**/*.test.ts\" --loader=ts-node/esm --extension ts"
18
19
  },
19
20
  "author": "DeFi Saver",
20
21
  "repository": "https://github.com/defisaver/automation-sdk",
@@ -27,7 +28,8 @@
27
28
  "@ethersproject/solidity": "^5.0.9",
28
29
  "decimal.js": "^10.4.3",
29
30
  "lodash": "^4.17.21",
30
- "web3": "^1.10.1"
31
+ "web3-eth-abi": "^1.10.2",
32
+ "web3-utils": "^1.10.2"
31
33
  },
32
34
  "devDependencies": {
33
35
  "@babel/core": "^7.12.10",
@@ -35,13 +37,14 @@
35
37
  "@babel/preset-env": "^7.12.11",
36
38
  "@babel/preset-typescript": "^7.12.7",
37
39
  "@typechain/web3-v1": "https://gitpkg.now.sh/mihai9-lab/TypeChain/packages/target-web3-v1?temp",
40
+ "@types/chai": "^4.3.6",
38
41
  "@types/lodash": "^4.14.191",
42
+ "@types/mocha": "^10.0.1",
39
43
  "@types/node": "^18.11.15",
40
- "@types/web3": "^1.2.2",
41
44
  "@typescript-eslint/eslint-plugin": "^5.42.0",
42
45
  "@typescript-eslint/parser": "^5.42.0",
43
46
  "babel-loader": "^8.2.2",
44
- "chai": "^4.2.0",
47
+ "chai": "^4.3.8",
45
48
  "dotenv": "^10.0.0",
46
49
  "eslint": "8.22.0",
47
50
  "eslint-config-airbnb": "^18.0.2",
@@ -52,15 +55,16 @@
52
55
  "eslint-plugin-react": "^7.31.11",
53
56
  "husky": "^8.0.0",
54
57
  "jsdoc-to-markdown": "^6.0.1",
58
+ "mocha": "^10.2.0",
55
59
  "react": "^18.2.0",
56
60
  "ts-node": "^10.9.1",
57
61
  "typechain": "^8.1.0",
58
62
  "typedoc": "^0.23.20",
59
63
  "typedoc-plugin-markdown": "^3.13.6",
60
64
  "typescript": "^4.8.4",
61
- "web3-eth-abi": "^1.8.0",
65
+ "web3": "^1.10.2",
62
66
  "web3-eth-contract": "^1.8.1",
63
- "web3-utils": "^1.8.0",
67
+ "web3-types": "^1.1.1",
64
68
  "webpack": "^5.76.0",
65
69
  "webpack-cli": "^4.10.0"
66
70
  }
@@ -1,6 +1,6 @@
1
1
  import type Web3 from 'web3';
2
2
  import type {
3
- EthereumAddress, Position, Interfaces, Contract, PlaceholderType,
3
+ EthereumAddress, Position, Interfaces, Contract, PlaceholderType, SubscriptionOptions,
4
4
  } from '../../types';
5
5
  import type {
6
6
  Legacy_AaveV2Subscriptions, Legacy_CompoundV2Subscriptions, Legacy_MakerSubscriptions, Legacy_AuthCheck,
@@ -85,8 +85,8 @@ export default class LegacyAutomation extends Automation {
85
85
  return this.protocol.id === ProtocolIdentifiers.LegacyAutomation.MakerDAO ? 'owner' : 'user';
86
86
  }
87
87
 
88
- protected async _getSubscriptions(addresses?: EthereumAddress[]): Promise<PlaceholderType> { // TODO PlaceholderType
89
- let subscriptions = await this.subscriptionsContract.contract.methods.getSubscribers().call();
88
+ protected async _getSubscriptions(addresses?: EthereumAddress[], options?: SubscriptionOptions): Promise<PlaceholderType> { // TODO PlaceholderType
89
+ let subscriptions = await this.subscriptionsContract.contract.methods.getSubscribers().call({}, options?.fromBlock || 'latest');
90
90
 
91
91
  if (addresses) {
92
92
  const _addresses = addresses.map(a => a.toLowerCase());
@@ -98,14 +98,15 @@ export default class LegacyAutomation extends Automation {
98
98
  return subscriptions;
99
99
  }
100
100
 
101
- protected async getParsedSubscriptions(addresses?: EthereumAddress[]): Promise<Position.LegacyAutomated[]> {
102
- const subscriptions = await this._getSubscriptions(addresses);
101
+ protected async getParsedSubscriptions(addresses?: EthereumAddress[], options?: SubscriptionOptions): Promise<Position.LegacyAutomated[]> {
102
+ const subscriptions = await this._getSubscriptions(addresses, options);
103
103
 
104
104
  // @ts-ignore
105
105
  return subscriptions.map((sub) => ({
106
106
  chainId: this.chainId,
107
107
  owner: sub[this.getOwnerPropName()],
108
- isEnabled: true,
108
+ isEnabled: (options?.fromBlock && options?.fromBlock !== 'latest')
109
+ ? options?.fromBlock > 18213086 : false, // Legacy automation was disabled on block 18213086
109
110
  protocol: this.protocol,
110
111
  specific: { ...sub },
111
112
  strategy: {
@@ -115,11 +116,11 @@ export default class LegacyAutomation extends Automation {
115
116
  }));
116
117
  }
117
118
 
118
- public async getSubscriptions(): Promise<Position.LegacyAutomated[]> {
119
- return this.getParsedSubscriptions();
119
+ public async getSubscriptions(options?: SubscriptionOptions): Promise<Position.LegacyAutomated[]> {
120
+ return this.getParsedSubscriptions(undefined, options);
120
121
  }
121
122
 
122
- public async getSubscriptionsFor(addresses: EthereumAddress[]): Promise<Position.LegacyAutomated[]> {
123
- return this.getParsedSubscriptions(addresses);
123
+ public async getSubscriptionsFor(addresses: EthereumAddress[], options?: SubscriptionOptions): Promise<Position.LegacyAutomated[]> {
124
+ return this.getParsedSubscriptions(addresses, options);
124
125
  }
125
126
  }
@@ -2,11 +2,10 @@ import Dec from 'decimal.js';
2
2
  import type Web3 from 'web3';
3
3
  import type { PastEventOptions } from 'web3-eth-contract';
4
4
  import type {
5
- Position, Interfaces, EthereumAddress,
6
- SubscriptionOptions, Contract, ParseData, PlaceholderType,
5
+ Position, Interfaces, EthereumAddress, SubscriptionOptions, Contract, ParseData, PlaceholderType, BlockNumber,
7
6
  } from '../../types';
8
7
  import type {
9
- Subscribe, StrategyModel, SubStorage, UpdateData,
8
+ StrategyModel, SubStorage,
10
9
  } from '../../types/contracts/generated/SubStorage';
11
10
  import type { ChainId } from '../../types/enums';
12
11
 
@@ -49,7 +48,7 @@ export default class StrategiesAutomation extends Automation {
49
48
  return getEventsFromContract<SubStorage>(this.subStorageContract, this.subStorageContractFork, event, options);
50
49
  }
51
50
 
52
- protected async getStrategiesSubs(subIds: number[]): Promise<StrategyModel.StoredSubDataStructOutputStruct[]> {
51
+ protected async getStrategiesSubs(subIds: number[], fromBlock: BlockNumber = 'latest'): Promise<StrategyModel.StoredSubDataStructOutputStruct[]> {
53
52
  let options : any;
54
53
  let web3: Web3;
55
54
 
@@ -68,7 +67,7 @@ export default class StrategiesAutomation extends Automation {
68
67
  }
69
68
 
70
69
  const multicallCalls = subIds.map((subId) => ({ ...options, params: [subId] }));
71
- return multicall(web3, this.chainId, multicallCalls);
70
+ return multicall(web3, this.chainId, multicallCalls, fromBlock);
72
71
  }
73
72
 
74
73
  protected async getSubscriptionEventsFromSubStorage(options?: PastEventOptions) {
@@ -98,7 +97,7 @@ export default class StrategiesAutomation extends Automation {
98
97
 
99
98
  if (subscriptionEvents) {
100
99
  // @ts-ignore
101
- const strategiesSubs = await this.getStrategiesSubs(subscriptionEvents.map((e) => e.returnValues.subId));
100
+ const strategiesSubs = await this.getStrategiesSubs(subscriptionEvents.map((e) => e.returnValues.subId), _options.fromBlock);
102
101
 
103
102
  subscriptions = await Promise.all(strategiesSubs.map(async (sub, index: number) => {
104
103
  let latestUpdate = subscriptionEvents[index].returnValues;