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