@defisaver/automation-sdk 2.1.6 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -48,7 +48,7 @@ export declare namespace Multicall {
48
48
  interface _SubscriptionOptions {
49
49
  toBlock: BlockNumber;
50
50
  fromBlock: BlockNumber;
51
- mergeWithSameId: boolean;
51
+ mergeSubs: boolean;
52
52
  enabledOnly: boolean;
53
53
  unexpiredOnly: boolean;
54
54
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defisaver/automation-sdk",
3
- "version": "2.1.6",
3
+ "version": "3.0.1",
4
4
  "description": "",
5
5
  "main": "./umd/index.js",
6
6
  "module": "./esm/index.js",
@@ -0,0 +1,661 @@
1
+ import {expect} from 'chai';
2
+
3
+ import {ChainId} from '../../types/enums';
4
+
5
+ import StrategiesAutomation from "./StrategiesAutomation";
6
+ import Web3 from "web3";
7
+
8
+ require('dotenv').config({ path: '.env' });
9
+ const Web3_1 = new Web3(process.env.RPC_1!);
10
+
11
+ describe('Feature: StrategiesAutomation.ts', () => {
12
+ describe('When testing class StrategiesAutomation', async () => {
13
+ const exampleStrategiesAutomation = new StrategiesAutomation({
14
+ chainId:ChainId.Ethereum,
15
+ provider: Web3_1,
16
+ providerFork: null!,
17
+ });
18
+
19
+ const examples: Array<[any, any]> = [
20
+ [
21
+ [
22
+ {
23
+ "isEnabled": true,
24
+ "chainId": 1,
25
+ "subHash": "0x7a14b187374b9ab02f6f7c95f275ef547376da010d53c715870cd053199a6aee",
26
+ "blockNumber": 0,
27
+ "positionId": "1-aave__v3",
28
+ "subId": 0,
29
+ "protocol": {
30
+ "id": "Aave__V3",
31
+ "name": "Aave",
32
+ "slug": "aave",
33
+ "version": "V3",
34
+ "fullName": "Aave V3"
35
+ },
36
+ "strategy": {
37
+ "isBundle": true,
38
+ "strategyOrBundleId": 0,
39
+ "strategyId": "leverage-management",
40
+ "protocol": {
41
+ "id": "Aave__V3",
42
+ "name": "Aave",
43
+ "slug": "aave",
44
+ "version": "V3",
45
+ "fullName": "Aave V3"
46
+ }
47
+ },
48
+ "strategyData": {
49
+ "encoded": {
50
+ "subData": [
51
+ "0x000000000000000000000000000000000000000000000000120a871cc0020000",
52
+ "0x0000000000000000000000000000000000000000000000000000000000000001",
53
+ "0x0000000000000000000000000000000000000000000000000000000000000001",
54
+ "0x0000000000000000000000000000000000000000000000000000000000000000"
55
+ ]
56
+ },
57
+ "decoded": {
58
+ "triggerData": {
59
+ "market": "0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb",
60
+ "ratio": 120,
61
+ "ratioState": 1
62
+ },
63
+ "subData": {
64
+ "targetRatio": 130
65
+ }
66
+ }
67
+ },
68
+ "specific": {
69
+ "triggerRepayRatio": 120,
70
+ "targetRepayRatio": 130,
71
+ "repayEnabled": true,
72
+ "subId1": 0,
73
+ "mergeWithId": "boost"
74
+ }
75
+ },
76
+ {
77
+ "isEnabled": false,
78
+ "chainId": 1,
79
+ "subHash": "0x7a14b187374b9ab02f6f7c95f275ef547376da010d53c715870cd053199a6aee",
80
+ "blockNumber": 0,
81
+ "positionId": "1-aave__v3",
82
+ "subId": 1,
83
+ "protocol": {
84
+ "id": "Aave__V3",
85
+ "name": "Aave",
86
+ "slug": "aave",
87
+ "version": "V3",
88
+ "fullName": "Aave V3"
89
+ },
90
+ "strategy": {
91
+ "isBundle": true,
92
+ "strategyOrBundleId": 0,
93
+ "strategyId": "leverage-management",
94
+ "protocol": {
95
+ "id": "Aave__V3",
96
+ "name": "Aave",
97
+ "slug": "aave",
98
+ "version": "V3",
99
+ "fullName": "Aave V3"
100
+ }
101
+ },
102
+ "strategyData": {
103
+ "encoded": {
104
+ "subData": [
105
+ "0x000000000000000000000000000000000000000000000000120a871cc0020000",
106
+ "0x0000000000000000000000000000000000000000000000000000000000000001",
107
+ "0x0000000000000000000000000000000000000000000000000000000000000001",
108
+ "0x0000000000000000000000000000000000000000000000000000000000000000"
109
+ ]
110
+ },
111
+ "decoded": {
112
+ "triggerData": {
113
+ "market": "0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb",
114
+ "ratio": 120,
115
+ "ratioState": 1
116
+ },
117
+ "subData": {
118
+ "targetRatio": 130
119
+ }
120
+ }
121
+ },
122
+ "specific": {
123
+ "triggerRepayRatio": 120,
124
+ "targetRepayRatio": 130,
125
+ "repayEnabled": true,
126
+ "subId1": 1,
127
+ "mergeWithId": "boost"
128
+ }
129
+ },
130
+ {
131
+ "isEnabled": false,
132
+ "chainId": 1,
133
+ "subHash": "0xe55917c42ac3e8f6c080e3780c5e0ea7a0a3da6c05e7ced5fe69fee48133a5eb",
134
+ "blockNumber": 0,
135
+ "positionId": "1-aave__v3",
136
+ "subId": 2,
137
+ "protocol": {
138
+ "id": "Aave__V3",
139
+ "name": "Aave",
140
+ "slug": "aave",
141
+ "version": "V3",
142
+ "fullName": "Aave V3"
143
+ },
144
+ "strategy": {
145
+ "isBundle": true,
146
+ "strategyOrBundleId": 0,
147
+ "strategyId": "leverage-management",
148
+ "protocol": {
149
+ "id": "Aave__V3",
150
+ "name": "Aave",
151
+ "slug": "aave",
152
+ "version": "V3",
153
+ "fullName": "Aave V3"
154
+ }
155
+ },
156
+ "strategyData": {
157
+ "encoded": {
158
+ "subData": [
159
+ "0x00000000000000000000000000000000000000000000000014d1120d7b160000",
160
+ "0x0000000000000000000000000000000000000000000000000000000000000001",
161
+ "0x0000000000000000000000000000000000000000000000000000000000000001",
162
+ "0x0000000000000000000000000000000000000000000000000000000000000000"
163
+ ]
164
+ },
165
+ "decoded": {
166
+ "triggerData": {
167
+ "market": "0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb",
168
+ "ratio": 135,
169
+ "ratioState": 1
170
+ },
171
+ "subData": {
172
+ "targetRatio": 150
173
+ }
174
+ }
175
+ },
176
+ "specific": {
177
+ "triggerRepayRatio": 135,
178
+ "targetRepayRatio": 150,
179
+ "repayEnabled": true,
180
+ "subId1": 2,
181
+ "mergeWithId": "boost"
182
+ }
183
+ },
184
+ {
185
+ "isEnabled": false,
186
+ "chainId": 1,
187
+ "subHash": "0x96d6a5fe8127765a0fa55115621495bf66ebd16029b0883bc097eda1b597ab0b",
188
+ "blockNumber": 0,
189
+ "positionId": "1-aave__v3",
190
+ "subId": 3,
191
+ "protocol": {
192
+ "id": "Aave__V3",
193
+ "name": "Aave",
194
+ "slug": "aave",
195
+ "version": "V3",
196
+ "fullName": "Aave V3"
197
+ },
198
+ "strategy": {
199
+ "isBundle": true,
200
+ "strategyOrBundleId": 1,
201
+ "strategyId": "leverage-management",
202
+ "protocol": {
203
+ "id": "Aave__V3",
204
+ "name": "Aave",
205
+ "slug": "aave",
206
+ "version": "V3",
207
+ "fullName": "Aave V3"
208
+ }
209
+ },
210
+ "strategyData": {
211
+ "encoded": {
212
+ "subData": [
213
+ "0x00000000000000000000000000000000000000000000000014d1120d7b160000",
214
+ "0x0000000000000000000000000000000000000000000000000000000000000000",
215
+ "0x0000000000000000000000000000000000000000000000000000000000000001",
216
+ "0x0000000000000000000000000000000000000000000000000000000000000000",
217
+ "0x0000000000000000000000000000000000000000000000000000000000000001"
218
+ ]
219
+ },
220
+ "decoded": {
221
+ "triggerData": {
222
+ "market": "0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb",
223
+ "ratio": 165,
224
+ "ratioState": 0
225
+ },
226
+ "subData": {
227
+ "targetRatio": 150
228
+ }
229
+ }
230
+ },
231
+ "specific": {
232
+ "triggerBoostRatio": 165,
233
+ "targetBoostRatio": 150,
234
+ "boostEnabled": false,
235
+ "subId2": 3,
236
+ "mergeId": "boost"
237
+ }
238
+ },
239
+ {
240
+ "isEnabled": false,
241
+ "chainId": 1,
242
+ "subHash": "0x96d6a5fe8127765a0fa55115621495bf66ebd16029b0883bc097eda1b597ab0b",
243
+ "blockNumber": 1,
244
+ "positionId": "1-aave__v3",
245
+ "subId": 4,
246
+ "protocol": {
247
+ "id": "Aave__V3",
248
+ "name": "Aave",
249
+ "slug": "aave",
250
+ "version": "V3",
251
+ "fullName": "Aave V3"
252
+ },
253
+ "strategy": {
254
+ "isBundle": true,
255
+ "strategyOrBundleId": 1,
256
+ "strategyId": "leverage-management",
257
+ "protocol": {
258
+ "id": "Aave__V3",
259
+ "name": "Aave",
260
+ "slug": "aave",
261
+ "version": "V3",
262
+ "fullName": "Aave V3"
263
+ }
264
+ },
265
+ "strategyData": {
266
+ "encoded": {
267
+ "subData": [
268
+ "0x00000000000000000000000000000000000000000000000014d1120d7b160000",
269
+ "0x0000000000000000000000000000000000000000000000000000000000000000",
270
+ "0x0000000000000000000000000000000000000000000000000000000000000001",
271
+ "0x0000000000000000000000000000000000000000000000000000000000000000",
272
+ "0x0000000000000000000000000000000000000000000000000000000000000001"
273
+ ]
274
+ },
275
+ "decoded": {
276
+ "triggerData": {
277
+ "market": "0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb",
278
+ "ratio": 165,
279
+ "ratioState": 0
280
+ },
281
+ "subData": {
282
+ "targetRatio": 150
283
+ }
284
+ }
285
+ },
286
+ "specific": {
287
+ "triggerBoostRatio": 165,
288
+ "targetBoostRatio": 150,
289
+ "boostEnabled": false,
290
+ "subId2": 4,
291
+ "mergeId": "boost"
292
+ }
293
+ },
294
+ {
295
+ "isEnabled": false,
296
+ "chainId": 1,
297
+ "subHash": "0x96d6a5fe8127765a0fa55115621495bf66ebd16029b0883bc097eda1b597ab0b",
298
+ "blockNumber": 1,
299
+ "positionId": "1-aave__v3",
300
+ "subId": 5,
301
+ "protocol": {
302
+ "id": "Aave__V3",
303
+ "name": "Aave",
304
+ "slug": "aave",
305
+ "version": "V3",
306
+ "fullName": "Aave V3"
307
+ },
308
+ "strategy": {
309
+ "isBundle": true,
310
+ "strategyOrBundleId": 1,
311
+ "strategyId": "leverage-management",
312
+ "protocol": {
313
+ "id": "Aave__V3",
314
+ "name": "Aave",
315
+ "slug": "aave",
316
+ "version": "V3",
317
+ "fullName": "Aave V3"
318
+ }
319
+ },
320
+ "strategyData": {
321
+ "encoded": {
322
+ "subData": [
323
+ "0x00000000000000000000000000000000000000000000000014d1120d7b160000",
324
+ "0x0000000000000000000000000000000000000000000000000000000000000000",
325
+ "0x0000000000000000000000000000000000000000000000000000000000000001",
326
+ "0x0000000000000000000000000000000000000000000000000000000000000000",
327
+ "0x0000000000000000000000000000000000000000000000000000000000000001"
328
+ ]
329
+ },
330
+ "decoded": {
331
+ "triggerData": {
332
+ "market": "0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb",
333
+ "ratio": 165,
334
+ "ratioState": 0
335
+ },
336
+ "subData": {
337
+ "targetRatio": 150
338
+ }
339
+ }
340
+ },
341
+ "specific": {
342
+ "triggerBoostRatio": 165,
343
+ "targetBoostRatio": 150,
344
+ "boostEnabled": false,
345
+ "subId2": 5,
346
+ "mergeId": "boost"
347
+ }
348
+ },
349
+ {
350
+ "isEnabled": false,
351
+ "chainId": 1,
352
+ "subHash": "0x52cd11186443c2734f027a7175bccf80158c6a45906f4b33b5713b77244aa7f6",
353
+ "blockNumber": 1,
354
+ "positionId": "1-aave__v3",
355
+ "subId": 6,
356
+ "protocol": {
357
+ "id": "Aave__V3",
358
+ "name": "Aave",
359
+ "slug": "aave",
360
+ "version": "V3",
361
+ "fullName": "Aave V3"
362
+ },
363
+ "strategy": {
364
+ "isBundle": true,
365
+ "strategyOrBundleId": 0,
366
+ "strategyId": "leverage-management",
367
+ "protocol": {
368
+ "id": "Aave__V3",
369
+ "name": "Aave",
370
+ "slug": "aave",
371
+ "version": "V3",
372
+ "fullName": "Aave V3"
373
+ }
374
+ },
375
+ "strategyData": {
376
+ "encoded": {
377
+ "subData": [
378
+ "0x00000000000000000000000000000000000000000000000012bc29d8eec70000",
379
+ "0x0000000000000000000000000000000000000000000000000000000000000001",
380
+ "0x0000000000000000000000000000000000000000000000000000000000000001",
381
+ "0x0000000000000000000000000000000000000000000000000000000000000000"
382
+ ]
383
+ },
384
+ "decoded": {
385
+ "triggerData": {
386
+ "market": "0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb",
387
+ "ratio": 120,
388
+ "ratioState": 1
389
+ },
390
+ "subData": {
391
+ "targetRatio": 135
392
+ }
393
+ }
394
+ },
395
+ "specific": {
396
+ "triggerRepayRatio": 120,
397
+ "targetRepayRatio": 135,
398
+ "repayEnabled": true,
399
+ "subId1": 6,
400
+ "mergeWithId": "boost"
401
+ }
402
+ }
403
+ ],[
404
+ {
405
+ "isEnabled": true,
406
+ "chainId": 1,
407
+ "subHash": "0x7a14b187374b9ab02f6f7c95f275ef547376da010d53c715870cd053199a6aee",
408
+ "blockNumber": 0,
409
+ "positionId": "1-aave__v3",
410
+ "subId": 0,
411
+ "protocol": {
412
+ "id": "Aave__V3",
413
+ "name": "Aave",
414
+ "slug": "aave",
415
+ "version": "V3",
416
+ "fullName": "Aave V3"
417
+ },
418
+ "strategy": {
419
+ "isBundle": true,
420
+ "strategyOrBundleId": 0,
421
+ "strategyId": "leverage-management",
422
+ "protocol": {
423
+ "id": "Aave__V3",
424
+ "name": "Aave",
425
+ "slug": "aave",
426
+ "version": "V3",
427
+ "fullName": "Aave V3"
428
+ }
429
+ },
430
+ "strategyData": {
431
+ "encoded": {
432
+ "subData": [
433
+ "0x000000000000000000000000000000000000000000000000120a871cc0020000",
434
+ "0x0000000000000000000000000000000000000000000000000000000000000001",
435
+ "0x0000000000000000000000000000000000000000000000000000000000000001",
436
+ "0x0000000000000000000000000000000000000000000000000000000000000000"
437
+ ]
438
+ },
439
+ "decoded": {
440
+ "triggerData": {
441
+ "market": "0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb",
442
+ "ratio": 120,
443
+ "ratioState": 1
444
+ },
445
+ "subData": {
446
+ "targetRatio": 130
447
+ }
448
+ }
449
+ },
450
+ "specific": {
451
+ "triggerBoostRatio": 165,
452
+ "targetBoostRatio": 150,
453
+ "boostEnabled": false,
454
+ "subId2": 3,
455
+ "mergeId": "boost",
456
+ "triggerRepayRatio": 120,
457
+ "targetRepayRatio": 130,
458
+ "repayEnabled": true,
459
+ "subId1": 0,
460
+ "mergeWithId": "boost"
461
+ },
462
+ "subIds": [
463
+ 0,
464
+ 3
465
+ ]
466
+ },
467
+ {
468
+ "isEnabled": false,
469
+ "chainId": 1,
470
+ "subHash": "0x7a14b187374b9ab02f6f7c95f275ef547376da010d53c715870cd053199a6aee",
471
+ "blockNumber": 1,
472
+ "positionId": "1-aave__v3",
473
+ "subId": 1,
474
+ "protocol": {
475
+ "id": "Aave__V3",
476
+ "name": "Aave",
477
+ "slug": "aave",
478
+ "version": "V3",
479
+ "fullName": "Aave V3"
480
+ },
481
+ "strategy": {
482
+ "isBundle": true,
483
+ "strategyOrBundleId": 0,
484
+ "strategyId": "leverage-management",
485
+ "protocol": {
486
+ "id": "Aave__V3",
487
+ "name": "Aave",
488
+ "slug": "aave",
489
+ "version": "V3",
490
+ "fullName": "Aave V3"
491
+ }
492
+ },
493
+ "strategyData": {
494
+ "encoded": {
495
+ "subData": [
496
+ "0x000000000000000000000000000000000000000000000000120a871cc0020000",
497
+ "0x0000000000000000000000000000000000000000000000000000000000000001",
498
+ "0x0000000000000000000000000000000000000000000000000000000000000001",
499
+ "0x0000000000000000000000000000000000000000000000000000000000000000"
500
+ ]
501
+ },
502
+ "decoded": {
503
+ "triggerData": {
504
+ "market": "0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb",
505
+ "ratio": 120,
506
+ "ratioState": 1
507
+ },
508
+ "subData": {
509
+ "targetRatio": 130
510
+ }
511
+ }
512
+ },
513
+ "specific": {
514
+ "triggerBoostRatio": 165,
515
+ "targetBoostRatio": 150,
516
+ "boostEnabled": false,
517
+ "subId2": 4,
518
+ "mergeId": "boost",
519
+ "triggerRepayRatio": 120,
520
+ "targetRepayRatio": 130,
521
+ "repayEnabled": true,
522
+ "subId1": 1,
523
+ "mergeWithId": "boost"
524
+ },
525
+ "subIds": [
526
+ 1,
527
+ 4
528
+ ]
529
+ },
530
+ {
531
+ "isEnabled": false,
532
+ "chainId": 1,
533
+ "subHash": "0xe55917c42ac3e8f6c080e3780c5e0ea7a0a3da6c05e7ced5fe69fee48133a5eb",
534
+ "blockNumber": 1,
535
+ "positionId": "1-aave__v3",
536
+ "subId": 2,
537
+ "protocol": {
538
+ "id": "Aave__V3",
539
+ "name": "Aave",
540
+ "slug": "aave",
541
+ "version": "V3",
542
+ "fullName": "Aave V3"
543
+ },
544
+ "strategy": {
545
+ "isBundle": true,
546
+ "strategyOrBundleId": 0,
547
+ "strategyId": "leverage-management",
548
+ "protocol": {
549
+ "id": "Aave__V3",
550
+ "name": "Aave",
551
+ "slug": "aave",
552
+ "version": "V3",
553
+ "fullName": "Aave V3"
554
+ }
555
+ },
556
+ "strategyData": {
557
+ "encoded": {
558
+ "subData": [
559
+ "0x00000000000000000000000000000000000000000000000014d1120d7b160000",
560
+ "0x0000000000000000000000000000000000000000000000000000000000000001",
561
+ "0x0000000000000000000000000000000000000000000000000000000000000001",
562
+ "0x0000000000000000000000000000000000000000000000000000000000000000"
563
+ ]
564
+ },
565
+ "decoded": {
566
+ "triggerData": {
567
+ "market": "0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb",
568
+ "ratio": 135,
569
+ "ratioState": 1
570
+ },
571
+ "subData": {
572
+ "targetRatio": 150
573
+ }
574
+ }
575
+ },
576
+ "specific": {
577
+ "triggerBoostRatio": 165,
578
+ "targetBoostRatio": 150,
579
+ "boostEnabled": false,
580
+ "subId2": 5,
581
+ "mergeId": "boost",
582
+ "triggerRepayRatio": 135,
583
+ "targetRepayRatio": 150,
584
+ "repayEnabled": true,
585
+ "subId1": 2,
586
+ "mergeWithId": "boost"
587
+ },
588
+ "subIds": [
589
+ 2,
590
+ 5
591
+ ]
592
+ },
593
+ {
594
+ "isEnabled": false,
595
+ "chainId": 1,
596
+ "subHash": "0x52cd11186443c2734f027a7175bccf80158c6a45906f4b33b5713b77244aa7f6",
597
+ "blockNumber": 1,
598
+ "positionId": "1-aave__v3",
599
+ "subId": 6,
600
+ "protocol": {
601
+ "id": "Aave__V3",
602
+ "name": "Aave",
603
+ "slug": "aave",
604
+ "version": "V3",
605
+ "fullName": "Aave V3"
606
+ },
607
+ "strategy": {
608
+ "isBundle": true,
609
+ "strategyOrBundleId": 0,
610
+ "strategyId": "leverage-management",
611
+ "protocol": {
612
+ "id": "Aave__V3",
613
+ "name": "Aave",
614
+ "slug": "aave",
615
+ "version": "V3",
616
+ "fullName": "Aave V3"
617
+ }
618
+ },
619
+ "strategyData": {
620
+ "encoded": {
621
+ "subData": [
622
+ "0x00000000000000000000000000000000000000000000000012bc29d8eec70000",
623
+ "0x0000000000000000000000000000000000000000000000000000000000000001",
624
+ "0x0000000000000000000000000000000000000000000000000000000000000001",
625
+ "0x0000000000000000000000000000000000000000000000000000000000000000"
626
+ ]
627
+ },
628
+ "decoded": {
629
+ "triggerData": {
630
+ "market": "0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb",
631
+ "ratio": 120,
632
+ "ratioState": 1
633
+ },
634
+ "subData": {
635
+ "targetRatio": 135
636
+ }
637
+ }
638
+ },
639
+ "specific": {
640
+ "triggerRepayRatio": 120,
641
+ "targetRepayRatio": 135,
642
+ "repayEnabled": true,
643
+ "subId1": 6,
644
+ "mergeWithId": "boost"
645
+ },
646
+ "subIds": [
647
+ 6
648
+ ]
649
+ }
650
+ ]
651
+ ],
652
+ ];
653
+ examples.forEach(([input, actual]) => {
654
+ it(`Given ${input} should return expected value:`, async () => {
655
+ // @ts-ignore
656
+ const expected = exampleStrategiesAutomation.mergeSubs(input);
657
+ expect(JSON.stringify(actual)).to.equal(JSON.stringify(expected));
658
+ });
659
+ });
660
+ });
661
+ });