@defisaver/automation-sdk 2.0.5 → 2.0.8

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 (50) hide show
  1. package/.env.dev +5 -0
  2. package/.tests.sh +3 -0
  3. package/README.md +3 -1
  4. package/esm/automation/private/LegacyProtocol.test.d.ts +1 -0
  5. package/esm/automation/private/LegacyProtocol.test.js +25 -0
  6. package/esm/automation/private/Protocol.test.d.ts +1 -0
  7. package/esm/automation/private/Protocol.test.js +25 -0
  8. package/esm/automation/private/StrategiesAutomation.js +1 -1
  9. package/esm/constants/index.js +15 -0
  10. package/esm/services/contractService.d.ts +3 -2
  11. package/esm/services/contractService.js +7 -1
  12. package/esm/services/ethereumService.test.d.ts +1 -0
  13. package/esm/services/ethereumService.test.js +241 -0
  14. package/esm/services/strategiesService.js +40 -0
  15. package/esm/services/strategiesService.test.d.ts +1 -0
  16. package/esm/services/strategiesService.test.js +108 -0
  17. package/esm/services/strategySubService.d.ts +17 -3
  18. package/esm/services/strategySubService.js +17 -6
  19. package/esm/services/strategySubService.test.d.ts +1 -0
  20. package/esm/services/strategySubService.test.js +692 -0
  21. package/esm/services/subDataService.d.ts +8 -1
  22. package/esm/services/subDataService.js +23 -14
  23. package/esm/services/subDataService.test.d.ts +1 -0
  24. package/esm/services/subDataService.test.js +993 -0
  25. package/esm/services/triggerService.d.ts +17 -0
  26. package/esm/services/triggerService.js +42 -1
  27. package/esm/services/triggerService.test.js +119 -17
  28. package/esm/types/enums.d.ts +10 -2
  29. package/esm/types/enums.js +8 -0
  30. package/esm/types/index.d.ts +19 -2
  31. package/package.json +3 -3
  32. package/src/automation/private/LegacyProtocol.test.ts +24 -0
  33. package/src/automation/private/Protocol.test.ts +24 -0
  34. package/src/automation/private/StrategiesAutomation.ts +1 -1
  35. package/src/constants/index.ts +15 -0
  36. package/src/services/contractService.ts +17 -4
  37. package/src/services/ethereumService.test.ts +256 -0
  38. package/src/services/ethereumService.ts +2 -1
  39. package/src/services/strategiesService.test.ts +103 -0
  40. package/src/services/strategiesService.ts +66 -3
  41. package/src/services/strategySubService.test.ts +835 -0
  42. package/src/services/strategySubService.ts +50 -15
  43. package/src/services/subDataService.test.ts +1063 -0
  44. package/src/services/subDataService.ts +29 -14
  45. package/src/services/triggerService.test.ts +133 -20
  46. package/src/services/triggerService.ts +55 -0
  47. package/src/services/utils.test.ts +1 -1
  48. package/src/types/enums.ts +8 -0
  49. package/src/types/index.ts +27 -3
  50. package/umd/index.js +282 -115
@@ -50,6 +50,16 @@ export declare const aaveV3QuotePriceTrigger: {
50
50
  ratioState: RatioState;
51
51
  };
52
52
  };
53
+ export declare const aaveV3QuotePriceWithMaximumGasPriceTrigger: {
54
+ encode(baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: number, ratioState: RatioState, maximumGasPriceInGwei?: number): string[];
55
+ decode(triggerData: string[]): {
56
+ baseTokenAddress: EthereumAddress;
57
+ quoteTokenAddress: EthereumAddress;
58
+ price: string;
59
+ ratioState: RatioState;
60
+ maximumGasPrice: string;
61
+ };
62
+ };
53
63
  export declare const compoundV2RatioTrigger: {
54
64
  encode(owner: EthereumAddress, ratioPercentage: number, ratioState: RatioState): string[];
55
65
  decode(triggerData: string[]): {
@@ -73,6 +83,13 @@ export declare const liquityDebtInFrontTrigger: {
73
83
  debtInFrontMin: string;
74
84
  };
75
85
  };
86
+ export declare const liquityDebtInFrontWithLimitTrigger: {
87
+ encode(owner: EthereumAddress, debtInFrontMin: string): string[];
88
+ decode(triggerData: string[]): {
89
+ owner: EthereumAddress;
90
+ debtInFrontMin: string;
91
+ };
92
+ };
76
93
  export declare const aaveV2RatioTrigger: {
77
94
  encode(owner: EthereumAddress, market: EthereumAddress, ratioPercentage: number, ratioState: RatioState): string[];
78
95
  decode(triggerData: string[]): {
@@ -26,8 +26,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.curveUsdSoftLiquidationTrigger = exports.curveUsdBorrowRateTrigger = exports.sparkQuotePriceTrigger = exports.sparkRatioTrigger = exports.exchangeOffchainPriceTrigger = exports.exchangeTimestampTrigger = exports.compoundV3RatioTrigger = exports.cBondsRebondTrigger = exports.aaveV2RatioTrigger = exports.liquityDebtInFrontTrigger = exports.liquityRatioTrigger = exports.compoundV2RatioTrigger = exports.aaveV3QuotePriceTrigger = exports.morphoAaveV2RatioTrigger = exports.aaveV3RatioTrigger = exports.makerRatioTrigger = exports.trailingStopTrigger = exports.chainlinkPriceTrigger = void 0;
29
+ exports.curveUsdSoftLiquidationTrigger = exports.curveUsdBorrowRateTrigger = exports.sparkQuotePriceTrigger = exports.sparkRatioTrigger = exports.exchangeOffchainPriceTrigger = exports.exchangeTimestampTrigger = exports.compoundV3RatioTrigger = exports.cBondsRebondTrigger = exports.aaveV2RatioTrigger = exports.liquityDebtInFrontWithLimitTrigger = exports.liquityDebtInFrontTrigger = exports.liquityRatioTrigger = exports.compoundV2RatioTrigger = exports.aaveV3QuotePriceWithMaximumGasPriceTrigger = exports.aaveV3QuotePriceTrigger = exports.morphoAaveV2RatioTrigger = exports.aaveV3RatioTrigger = exports.makerRatioTrigger = exports.trailingStopTrigger = exports.chainlinkPriceTrigger = void 0;
30
30
  const decimal_js_1 = __importDefault(require("decimal.js"));
31
+ const tokens_1 = require("@defisaver/tokens");
31
32
  const web3_eth_abi_1 = __importDefault(require("web3-eth-abi"));
32
33
  const web3Utils = __importStar(require("web3-utils"));
33
34
  const utils_1 = require("./utils");
@@ -109,6 +110,33 @@ exports.aaveV3QuotePriceTrigger = {
109
110
  };
110
111
  },
111
112
  };
113
+ exports.aaveV3QuotePriceWithMaximumGasPriceTrigger = {
114
+ encode(baseTokenAddress, quoteTokenAddress, price, ratioState, maximumGasPriceInGwei) {
115
+ // Price is always in 8 decimals
116
+ const _price = new decimal_js_1.default(price.toString()).mul(Math.pow(10, 8)).floor().toString();
117
+ const _maximumGasPrice = maximumGasPriceInGwei
118
+ ? new decimal_js_1.default(maximumGasPriceInGwei.toString()).mul(Math.pow(10, 9)).floor().toString() // We convert it to WEI
119
+ : tokens_1.MAXUINT; // If undefined than set to MAXUINT
120
+ return [
121
+ web3_eth_abi_1.default.encodeParameters(['address', 'address', 'uint256', 'uint8'], [baseTokenAddress, quoteTokenAddress, _price, ratioState]),
122
+ web3_eth_abi_1.default.encodeParameters(['uint256'], [_maximumGasPrice]),
123
+ ];
124
+ },
125
+ decode(triggerData) {
126
+ const decodedPriceTrigger = web3_eth_abi_1.default.decodeParameters(['address', 'address', 'uint256', 'uint8'], triggerData[0]);
127
+ const decodedMaximumGasPriceTrigger = web3_eth_abi_1.default.decodeParameters(['uint256'], triggerData[1]);
128
+ // Price is always in 8 decimals
129
+ const price = new decimal_js_1.default(decodedPriceTrigger[2]).div(Math.pow(10, 8)).toDP(8).toString();
130
+ const maximumGasPrice = new decimal_js_1.default(decodedMaximumGasPriceTrigger[0]).div(Math.pow(10, 9)).toDP(9).toString();
131
+ return {
132
+ baseTokenAddress: decodedPriceTrigger[0],
133
+ quoteTokenAddress: decodedPriceTrigger[1],
134
+ price,
135
+ ratioState: +decodedPriceTrigger[3],
136
+ maximumGasPrice,
137
+ };
138
+ },
139
+ };
112
140
  exports.compoundV2RatioTrigger = {
113
141
  encode(owner, ratioPercentage, ratioState) {
114
142
  const ratioWei = (0, utils_1.ratioPercentageToWei)(ratioPercentage);
@@ -149,6 +177,19 @@ exports.liquityDebtInFrontTrigger = {
149
177
  };
150
178
  },
151
179
  };
180
+ exports.liquityDebtInFrontWithLimitTrigger = {
181
+ encode(owner, debtInFrontMin) {
182
+ const debtInFrontMinWei = web3Utils.toWei(new decimal_js_1.default(debtInFrontMin).toString(), 'ether');
183
+ return [web3_eth_abi_1.default.encodeParameters(['address', 'uint256'], [owner, debtInFrontMinWei])];
184
+ },
185
+ decode(triggerData) {
186
+ const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'uint256'], triggerData[0]);
187
+ return {
188
+ owner: decodedData[0],
189
+ debtInFrontMin: new decimal_js_1.default(decodedData[1]).div(Math.pow(10, 18)).toString(),
190
+ };
191
+ },
192
+ };
152
193
  exports.aaveV2RatioTrigger = {
153
194
  encode(owner, market, ratioPercentage, ratioState) {
154
195
  const ratioWei = (0, utils_1.ratioPercentageToWei)(ratioPercentage);
@@ -59,7 +59,7 @@ describe('Feature: triggerService.ts', () => {
59
59
  ],
60
60
  ];
61
61
  examples.forEach(([expected, actual]) => {
62
- it(`Given ${actual} should return expected value: ${expected}`, () => {
62
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
63
63
  (0, chai_1.expect)(triggerService_1.chainlinkPriceTrigger.decode(actual)).to.eql(expected);
64
64
  });
65
65
  });
@@ -95,7 +95,7 @@ describe('Feature: triggerService.ts', () => {
95
95
  ],
96
96
  ];
97
97
  examples.forEach(([expected, actual]) => {
98
- it(`Given ${actual} should return expected value: ${expected}`, () => {
98
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
99
99
  (0, chai_1.expect)(triggerService_1.trailingStopTrigger.decode(actual)).to.eql(expected);
100
100
  });
101
101
  });
@@ -131,7 +131,7 @@ describe('Feature: triggerService.ts', () => {
131
131
  ],
132
132
  ];
133
133
  examples.forEach(([expected, actual]) => {
134
- it(`Given ${actual} should return expected value: ${expected}`, () => {
134
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
135
135
  (0, chai_1.expect)(triggerService_1.makerRatioTrigger.decode(actual)).to.eql(expected);
136
136
  });
137
137
  });
@@ -167,7 +167,7 @@ describe('Feature: triggerService.ts', () => {
167
167
  ],
168
168
  ];
169
169
  examples.forEach(([expected, actual]) => {
170
- it(`Given ${actual} should return expected value: ${expected}`, () => {
170
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
171
171
  (0, chai_1.expect)(triggerService_1.aaveV3RatioTrigger.decode(actual)).to.eql(expected);
172
172
  });
173
173
  });
@@ -203,7 +203,7 @@ describe('Feature: triggerService.ts', () => {
203
203
  ],
204
204
  ];
205
205
  examples.forEach(([expected, actual]) => {
206
- it(`Given ${actual} should return expected value: ${expected}`, () => {
206
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
207
207
  (0, chai_1.expect)(triggerService_1.morphoAaveV2RatioTrigger.decode(actual)).to.eql(expected);
208
208
  });
209
209
  });
@@ -249,12 +249,72 @@ describe('Feature: triggerService.ts', () => {
249
249
  ]
250
250
  ];
251
251
  examples.forEach(([expected, actual]) => {
252
- it(`Given ${actual} should return expected value: ${expected}`, () => {
252
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
253
253
  (0, chai_1.expect)(triggerService_1.aaveV3QuotePriceTrigger.decode(actual)).to.eql(expected);
254
254
  });
255
255
  });
256
256
  });
257
257
  });
258
+ describe('When testing triggerService.aaveV3QuotePriceWithMaximumGasPriceTrigger', () => {
259
+ describe('encode()', () => {
260
+ const examples = [
261
+ [
262
+ [
263
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000009c400000000000000000000000000000000000000000000000000000000000000001',
264
+ '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
265
+ ],
266
+ [(0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Ethereum).address, (0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address, 0.0004, enums_1.RatioState.UNDER]
267
+ ],
268
+ [
269
+ [
270
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec700000000000000000000000000000000000000000000000000000000000000170000000000000000000000000000000000000000000000000000000000000000',
271
+ '0x00000000000000000000000000000000000000000000000000000002cb417800',
272
+ ],
273
+ [(0, tokens_1.getAssetInfo)('WBTC', enums_1.ChainId.Ethereum).address, (0, tokens_1.getAssetInfo)('USDT', enums_1.ChainId.Ethereum).address, 0.00000023, enums_1.RatioState.OVER, 12]
274
+ ],
275
+ ];
276
+ examples.forEach(([expected, actual]) => {
277
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
278
+ (0, chai_1.expect)(triggerService_1.aaveV3QuotePriceWithMaximumGasPriceTrigger.encode(...actual)).to.eql(expected);
279
+ });
280
+ });
281
+ });
282
+ describe('decode()', () => {
283
+ const examples = [
284
+ [
285
+ {
286
+ baseTokenAddress: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Ethereum).address),
287
+ quoteTokenAddress: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
288
+ price: '0.0004',
289
+ ratioState: enums_1.RatioState.UNDER,
290
+ maximumGasPrice: web3Utils.fromWei(tokens_1.MAXUINT, 'gwei')
291
+ },
292
+ [
293
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000009c400000000000000000000000000000000000000000000000000000000000000001',
294
+ '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
295
+ ],
296
+ ],
297
+ [
298
+ {
299
+ baseTokenAddress: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WBTC', enums_1.ChainId.Ethereum).address),
300
+ quoteTokenAddress: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDT', enums_1.ChainId.Ethereum).address),
301
+ price: '0.00000023',
302
+ ratioState: enums_1.RatioState.OVER,
303
+ maximumGasPrice: '12',
304
+ },
305
+ [
306
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec700000000000000000000000000000000000000000000000000000000000000170000000000000000000000000000000000000000000000000000000000000000',
307
+ '0x00000000000000000000000000000000000000000000000000000002cb417800',
308
+ ],
309
+ ]
310
+ ];
311
+ examples.forEach(([expected, actual]) => {
312
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
313
+ (0, chai_1.expect)(triggerService_1.aaveV3QuotePriceWithMaximumGasPriceTrigger.decode(actual)).to.eql(expected);
314
+ });
315
+ });
316
+ });
317
+ });
258
318
  describe('When testing triggerService.liquityRatioTrigger', () => {
259
319
  describe('encode()', () => {
260
320
  const examples = [
@@ -293,7 +353,7 @@ describe('Feature: triggerService.ts', () => {
293
353
  ],
294
354
  ];
295
355
  examples.forEach(([expected, actual]) => {
296
- it(`Given ${actual} should return expected value: ${expected}`, () => {
356
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
297
357
  (0, chai_1.expect)(triggerService_1.compoundV2RatioTrigger.decode(actual)).to.eql(expected);
298
358
  });
299
359
  });
@@ -335,7 +395,7 @@ describe('Feature: triggerService.ts', () => {
335
395
  ],
336
396
  ];
337
397
  examples.forEach(([expected, actual]) => {
338
- it(`Given ${actual} should return expected value: ${expected}`, () => {
398
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
339
399
  (0, chai_1.expect)(triggerService_1.liquityDebtInFrontTrigger.decode(actual)).to.eql(expected);
340
400
  });
341
401
  });
@@ -368,7 +428,7 @@ describe('Feature: triggerService.ts', () => {
368
428
  ],
369
429
  ];
370
430
  examples.forEach(([expected, actual]) => {
371
- it(`Given ${actual} should return expected value: ${expected}`, () => {
431
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
372
432
  (0, chai_1.expect)(triggerService_1.aaveV2RatioTrigger.decode(actual)).to.eql(expected);
373
433
  });
374
434
  });
@@ -404,7 +464,7 @@ describe('Feature: triggerService.ts', () => {
404
464
  ],
405
465
  ];
406
466
  examples.forEach(([expected, actual]) => {
407
- it(`Given ${actual} should return expected value: ${expected}`, () => {
467
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
408
468
  (0, chai_1.expect)(triggerService_1.cBondsRebondTrigger.decode(actual)).to.eql(expected);
409
469
  });
410
470
  });
@@ -450,7 +510,7 @@ describe('Feature: triggerService.ts', () => {
450
510
  ],
451
511
  ];
452
512
  examples.forEach(([expected, actual]) => {
453
- it(`Given ${actual} should return expected value: ${expected}`, () => {
513
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
454
514
  (0, chai_1.expect)(triggerService_1.compoundV3RatioTrigger.decode(actual)).to.eql(expected);
455
515
  });
456
516
  });
@@ -490,7 +550,7 @@ describe('Feature: triggerService.ts', () => {
490
550
  ],
491
551
  ];
492
552
  examples.forEach(([expected, actual]) => {
493
- it(`Given ${actual} should return expected value: ${expected}`, () => {
553
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
494
554
  (0, chai_1.expect)(triggerService_1.exchangeTimestampTrigger.decode(actual)).to.eql(expected);
495
555
  });
496
556
  });
@@ -538,7 +598,7 @@ describe('Feature: triggerService.ts', () => {
538
598
  ],
539
599
  ];
540
600
  examples.forEach(([expected, actual]) => {
541
- it(`Given ${actual} should return expected value: ${expected}`, () => {
601
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
542
602
  (0, chai_1.expect)(triggerService_1.exchangeOffchainPriceTrigger.decode(...actual)).to.eql(expected);
543
603
  });
544
604
  });
@@ -574,7 +634,7 @@ describe('Feature: triggerService.ts', () => {
574
634
  ],
575
635
  ];
576
636
  examples.forEach(([expected, actual]) => {
577
- it(`Given ${actual} should return expected value: ${expected}`, () => {
637
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
578
638
  (0, chai_1.expect)(triggerService_1.sparkRatioTrigger.decode(actual)).to.eql(expected);
579
639
  });
580
640
  });
@@ -620,7 +680,7 @@ describe('Feature: triggerService.ts', () => {
620
680
  ]
621
681
  ];
622
682
  examples.forEach(([expected, actual]) => {
623
- it(`Given ${actual} should return expected value: ${expected}`, () => {
683
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
624
684
  (0, chai_1.expect)(triggerService_1.sparkQuotePriceTrigger.decode(actual)).to.eql(expected);
625
685
  });
626
686
  });
@@ -666,7 +726,7 @@ describe('Feature: triggerService.ts', () => {
666
726
  ],
667
727
  ];
668
728
  examples.forEach(([expected, actual]) => {
669
- it(`Given ${actual} should return expected value: ${expected}`, () => {
729
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
670
730
  (0, chai_1.expect)(triggerService_1.curveUsdBorrowRateTrigger.decode(actual)).to.eql(expected);
671
731
  });
672
732
  });
@@ -710,10 +770,52 @@ describe('Feature: triggerService.ts', () => {
710
770
  ],
711
771
  ];
712
772
  examples.forEach(([expected, actual]) => {
713
- it(`Given ${actual} should return expected value: ${expected}`, () => {
773
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
714
774
  (0, chai_1.expect)(triggerService_1.curveUsdSoftLiquidationTrigger.decode(actual)).to.eql(expected);
715
775
  });
716
776
  });
717
777
  });
718
778
  });
779
+ describe('When testing triggerService.liquityDebtInFrontWithLimitTrigger', () => {
780
+ describe('encode()', () => {
781
+ const examples = [
782
+ [
783
+ ['0x000000000000000000000000235d6a8db3c57c3f7b4eba749e1738db6093732a0000000000000000000000000000000000000000019d971e4fe8401e74000000'],
784
+ [web3Utils.toChecksumAddress('0x235d6A8DB3C57c3f7b4ebA749E1738Db6093732a'), '500000000']
785
+ ],
786
+ [
787
+ ['0x000000000000000000000000235d6a8db3c57c3f7b4eba749e1738db6093732a00000000000000000000000000000000000000000001a784379d99db42000000'],
788
+ [web3Utils.toChecksumAddress('0x235d6A8DB3C57c3f7b4ebA749E1738Db6093732a'), '2000000']
789
+ ],
790
+ ];
791
+ examples.forEach(([expected, actual]) => {
792
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
793
+ (0, chai_1.expect)(triggerService_1.liquityDebtInFrontWithLimitTrigger.encode(...actual)).to.eql(expected);
794
+ });
795
+ });
796
+ });
797
+ describe('decode()', () => {
798
+ const examples = [
799
+ [
800
+ {
801
+ owner: web3Utils.toChecksumAddress('0x235d6A8DB3C57c3f7b4ebA749E1738Db6093732a'),
802
+ debtInFrontMin: '500000000',
803
+ },
804
+ ['0x000000000000000000000000235d6a8db3c57c3f7b4eba749e1738db6093732a0000000000000000000000000000000000000000019d971e4fe8401e74000000'],
805
+ ],
806
+ [
807
+ {
808
+ owner: web3Utils.toChecksumAddress('0x235d6A8DB3C57c3f7b4ebA749E1738Db6093732a'),
809
+ debtInFrontMin: '2000000',
810
+ },
811
+ ['0x000000000000000000000000235d6a8db3c57c3f7b4eba749e1738db6093732a00000000000000000000000000000000000000000001a784379d99db42000000'],
812
+ ],
813
+ ];
814
+ examples.forEach(([expected, actual]) => {
815
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
816
+ (0, chai_1.expect)(triggerService_1.liquityDebtInFrontWithLimitTrigger.decode(actual)).to.eql(expected);
817
+ });
818
+ });
819
+ });
820
+ });
719
821
  });
@@ -55,7 +55,8 @@ export declare namespace Strategies {
55
55
  EXCHANGE_DCA = 46,
56
56
  EXCHANGE_LIMIT_ORDER = 51,
57
57
  LIQUITY_DSR_PAYBACK = 69,
58
- LIQUITY_DSR_SUPPLY = 70
58
+ LIQUITY_DSR_SUPPLY = 70,
59
+ LIQUITY_DEBT_IN_FRONT_REPAY = 75
59
60
  }
60
61
  enum OptimismIds {
61
62
  EXCHANGE_DCA = 8,
@@ -74,7 +75,9 @@ export declare namespace Strategies {
74
75
  Boost = "boost",
75
76
  EoaBoost = "eoa-boost",
76
77
  CloseToDebt = "close-to-debt",
78
+ CloseToDebtWithGasPrice = "close-to-debt-with-gas-price",
77
79
  CloseToCollateral = "close-to-collateral",
80
+ CloseToCollateralWithGasPrice = "close-to-collateral-with-gas-price",
78
81
  CloseOnPriceToDebt = "close-on-price-to-debt",
79
82
  CloseOnPriceToColl = "close-on-price-to-collateral",
80
83
  TrailingStopToColl = "trailing-stop-to-collateral",
@@ -82,11 +85,14 @@ export declare namespace Strategies {
82
85
  Rebond = "rebond",
83
86
  BondProtection = "bond-protection",
84
87
  Dca = "dca",
85
- LimitOrder = "limit-order"
88
+ LimitOrder = "limit-order",
89
+ DebtInFrontRepay = "debt-in-front-repay"
86
90
  }
87
91
  enum IdOverrides {
88
92
  TakeProfit = "take-profit",
89
93
  StopLoss = "stop-loss",
94
+ TakeProfitWithGasPrice = "take-profit-with-gas-price",
95
+ StopLossWithGasPrice = "stop-loss-with-gas-price",
90
96
  TrailingStop = "trailing-stop",
91
97
  LeverageManagement = "leverage-management",
92
98
  EoaLeverageManagement = "leverage-management-eoa"
@@ -107,7 +113,9 @@ export declare namespace Bundles {
107
113
  MAKER_REPAY = 10,
108
114
  MAKER_BOOST = 11,
109
115
  AAVE_V3_CLOSE_TO_DEBT = 12,
116
+ AAVE_V3_CLOSE_TO_DEBT_WITH_GAS_PRICE = 24,
110
117
  AAVE_V3_CLOSE_TO_COLLATERAL = 13,
118
+ AAVE_V3_CLOSE_TO_COLLATERAL_WITH_GAS_PRICE = 25,
111
119
  MORPHO_AAVE_V2_REPAY = 14,
112
120
  MORPHO_AAVE_V2_BOOST = 15,
113
121
  LIQUITY_REPAY = 16,
@@ -68,6 +68,7 @@ var Strategies;
68
68
  MainnetIds[MainnetIds["EXCHANGE_LIMIT_ORDER"] = 51] = "EXCHANGE_LIMIT_ORDER";
69
69
  MainnetIds[MainnetIds["LIQUITY_DSR_PAYBACK"] = 69] = "LIQUITY_DSR_PAYBACK";
70
70
  MainnetIds[MainnetIds["LIQUITY_DSR_SUPPLY"] = 70] = "LIQUITY_DSR_SUPPLY";
71
+ MainnetIds[MainnetIds["LIQUITY_DEBT_IN_FRONT_REPAY"] = 75] = "LIQUITY_DEBT_IN_FRONT_REPAY";
71
72
  })(MainnetIds = Strategies.MainnetIds || (Strategies.MainnetIds = {}));
72
73
  let OptimismIds;
73
74
  (function (OptimismIds) {
@@ -89,7 +90,9 @@ var Strategies;
89
90
  Identifiers["Boost"] = "boost";
90
91
  Identifiers["EoaBoost"] = "eoa-boost";
91
92
  Identifiers["CloseToDebt"] = "close-to-debt";
93
+ Identifiers["CloseToDebtWithGasPrice"] = "close-to-debt-with-gas-price";
92
94
  Identifiers["CloseToCollateral"] = "close-to-collateral";
95
+ Identifiers["CloseToCollateralWithGasPrice"] = "close-to-collateral-with-gas-price";
93
96
  Identifiers["CloseOnPriceToDebt"] = "close-on-price-to-debt";
94
97
  Identifiers["CloseOnPriceToColl"] = "close-on-price-to-collateral";
95
98
  Identifiers["TrailingStopToColl"] = "trailing-stop-to-collateral";
@@ -98,11 +101,14 @@ var Strategies;
98
101
  Identifiers["BondProtection"] = "bond-protection";
99
102
  Identifiers["Dca"] = "dca";
100
103
  Identifiers["LimitOrder"] = "limit-order";
104
+ Identifiers["DebtInFrontRepay"] = "debt-in-front-repay";
101
105
  })(Identifiers = Strategies.Identifiers || (Strategies.Identifiers = {}));
102
106
  let IdOverrides;
103
107
  (function (IdOverrides) {
104
108
  IdOverrides["TakeProfit"] = "take-profit";
105
109
  IdOverrides["StopLoss"] = "stop-loss";
110
+ IdOverrides["TakeProfitWithGasPrice"] = "take-profit-with-gas-price";
111
+ IdOverrides["StopLossWithGasPrice"] = "stop-loss-with-gas-price";
106
112
  IdOverrides["TrailingStop"] = "trailing-stop";
107
113
  IdOverrides["LeverageManagement"] = "leverage-management";
108
114
  IdOverrides["EoaLeverageManagement"] = "leverage-management-eoa";
@@ -125,7 +131,9 @@ var Bundles;
125
131
  MainnetIds[MainnetIds["MAKER_REPAY"] = 10] = "MAKER_REPAY";
126
132
  MainnetIds[MainnetIds["MAKER_BOOST"] = 11] = "MAKER_BOOST";
127
133
  MainnetIds[MainnetIds["AAVE_V3_CLOSE_TO_DEBT"] = 12] = "AAVE_V3_CLOSE_TO_DEBT";
134
+ MainnetIds[MainnetIds["AAVE_V3_CLOSE_TO_DEBT_WITH_GAS_PRICE"] = 24] = "AAVE_V3_CLOSE_TO_DEBT_WITH_GAS_PRICE";
128
135
  MainnetIds[MainnetIds["AAVE_V3_CLOSE_TO_COLLATERAL"] = 13] = "AAVE_V3_CLOSE_TO_COLLATERAL";
136
+ MainnetIds[MainnetIds["AAVE_V3_CLOSE_TO_COLLATERAL_WITH_GAS_PRICE"] = 25] = "AAVE_V3_CLOSE_TO_COLLATERAL_WITH_GAS_PRICE";
129
137
  MainnetIds[MainnetIds["MORPHO_AAVE_V2_REPAY"] = 14] = "MORPHO_AAVE_V2_REPAY";
130
138
  MainnetIds[MainnetIds["MORPHO_AAVE_V2_BOOST"] = 15] = "MORPHO_AAVE_V2_BOOST";
131
139
  MainnetIds[MainnetIds["LIQUITY_REPAY"] = 16] = "LIQUITY_REPAY";
@@ -116,13 +116,28 @@ export declare namespace Position {
116
116
  price: string;
117
117
  ratioState: RatioState;
118
118
  }
119
+ interface CloseOnPriceWithMaximumGasPriceAave extends Base {
120
+ collAsset: EthereumAddress;
121
+ collAssetId: number;
122
+ debtAsset: EthereumAddress;
123
+ debtAssetId: number;
124
+ baseToken: EthereumAddress;
125
+ quoteToken: EthereumAddress;
126
+ price: string;
127
+ maximumGasPrice: string;
128
+ ratioState: RatioState;
129
+ }
119
130
  interface TrailingStop extends Base {
120
131
  roundId: number;
121
132
  triggerPercentage: number;
122
133
  closeToAssetAddr: EthereumAddress;
123
134
  }
135
+ interface DebtInFrontRepay extends Base {
136
+ debtInFrontMin: string;
137
+ targetRepayRatioIncrease: number;
138
+ }
124
139
  }
125
- type SpecificAny = Specific.CloseOnPrice | Specific.TrailingStop | Specific.RatioProtection | Specific.CloseOnPriceAave;
140
+ type SpecificAny = Specific.CloseOnPrice | Specific.TrailingStop | Specific.RatioProtection | Specific.CloseOnPriceAave | Specific.CloseOnPriceWithMaximumGasPriceAave | Specific.DebtInFrontRepay;
126
141
  interface Automated {
127
142
  chainId: ChainId;
128
143
  owner: EthereumAddress;
@@ -161,10 +176,12 @@ type StrategyInfo<T extends number> = Record<T, Strategy<T>>;
161
176
  export type MainnetStrategiesInfo = StrategyInfo<Strategies.MainnetIds>;
162
177
  export type OptimismStrategiesInfo = StrategyInfo<Strategies.OptimismIds>;
163
178
  export type ArbitrumStrategiesInfo = StrategyInfo<Strategies.ArbitrumIds>;
179
+ export type StrategyInfoUnion = MainnetStrategiesInfo | OptimismStrategiesInfo | ArbitrumStrategiesInfo;
164
180
  type BundleInfo<T extends number> = Record<T, BundleOrStrategy<T>>;
165
181
  export type MainnetBundleInfo = BundleInfo<Bundles.MainnetIds>;
166
182
  export type OptimismBundleInfo = BundleInfo<Bundles.OptimismIds>;
167
183
  export type ArbitrumBundleInfo = BundleInfo<Bundles.ArbitrumIds>;
184
+ export type BundleInfoUnion = MainnetBundleInfo | OptimismBundleInfo | ArbitrumBundleInfo;
168
185
  export interface StrategiesInfo {
169
186
  [ChainId.Ethereum]: MainnetStrategiesInfo;
170
187
  [ChainId.Optimism]: OptimismStrategiesInfo;
@@ -175,7 +192,7 @@ export interface BundlesInfo {
175
192
  [ChainId.Optimism]: OptimismBundleInfo;
176
193
  [ChainId.Arbitrum]: ArbitrumBundleInfo;
177
194
  }
178
- export type StrategyOrBundleIds = Strategies.MainnetIds & Strategies.OptimismIds & Strategies.ArbitrumIds & Bundles.MainnetIds & Bundles.OptimismIds & Bundles.ArbitrumIds;
195
+ export type StrategyOrBundleIds = typeof Strategies.MainnetIds[keyof typeof Strategies.MainnetIds] | typeof Strategies.OptimismIds[keyof typeof Strategies.OptimismIds] | typeof Strategies.ArbitrumIds[keyof typeof Strategies.ArbitrumIds] | typeof Bundles.MainnetIds[keyof typeof Bundles.MainnetIds] | typeof Bundles.OptimismIds[keyof typeof Bundles.OptimismIds] | typeof Bundles.ArbitrumIds[keyof typeof Bundles.ArbitrumIds];
179
196
  export interface ParseData {
180
197
  chainId: ChainId;
181
198
  blockNumber: BlockNumber;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defisaver/automation-sdk",
3
- "version": "2.0.5",
3
+ "version": "2.0.8",
4
4
  "description": "",
5
5
  "main": "./umd/index.js",
6
6
  "module": "./esm/index.js",
@@ -15,7 +15,7 @@
15
15
  "lint": "node_modules/.bin/eslint ./src",
16
16
  "gtc": "node scripts/generateContractTypes.js",
17
17
  "prepare": "husky install && npm run gtc",
18
- "test": "mocha \"./src/**/*.test.ts\" --loader=ts-node/esm --extension ts"
18
+ "test": "./.tests.sh"
19
19
  },
20
20
  "author": "DeFi Saver",
21
21
  "repository": "https://github.com/defisaver/automation-sdk",
@@ -45,7 +45,7 @@
45
45
  "@typescript-eslint/parser": "^5.42.0",
46
46
  "babel-loader": "^8.2.2",
47
47
  "chai": "^4.3.8",
48
- "dotenv": "^10.0.0",
48
+ "dotenv": "^16.3.1",
49
49
  "eslint": "8.22.0",
50
50
  "eslint-config-airbnb": "^18.0.2",
51
51
  "eslint-config-airbnb-typescript": "^17.0.0",
@@ -0,0 +1,24 @@
1
+ import { expect } from 'chai';
2
+
3
+ import { ProtocolIdentifiers } from '../../types/enums';
4
+
5
+ import LegacyProtocol from './LegacyProtocol';
6
+
7
+ describe('Feature: LegacyProtocol.ts', () => {
8
+ describe('When testing class LegacyProtocol', () => {
9
+ const exampleProtocol = new LegacyProtocol({ id: ProtocolIdentifiers.LegacyAutomation.MakerDAO });
10
+ const examples: Array<[string, string]> = [
11
+ [exampleProtocol.id, 'MakerDAO'],
12
+ [exampleProtocol.name, 'MakerDAO'],
13
+ [exampleProtocol.slug, 'makerdao'],
14
+ [exampleProtocol.version, ''],
15
+ [exampleProtocol.fullName, 'MakerDAO'],
16
+ ];
17
+
18
+ examples.forEach(([expected, actual]) => {
19
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
20
+ expect(actual).to.equal(expected);
21
+ });
22
+ });
23
+ });
24
+ });
@@ -0,0 +1,24 @@
1
+ import { expect } from 'chai';
2
+
3
+ import { ProtocolIdentifiers } from '../../types/enums';
4
+
5
+ import Protocol from './Protocol';
6
+
7
+ describe('Feature: Protocol.ts', () => {
8
+ describe('When testing class Protocol', () => {
9
+ const exampleProtocol = new Protocol({ id: ProtocolIdentifiers.StrategiesAutomation.AaveV3 });
10
+ const examples: Array<[string, string]> = [
11
+ [exampleProtocol.id, 'Aave__V3'],
12
+ [exampleProtocol.name, 'Aave'],
13
+ [exampleProtocol.slug, 'aave'],
14
+ [exampleProtocol.version, 'V3'],
15
+ [exampleProtocol.fullName, 'Aave V3'],
16
+ ];
17
+
18
+ examples.forEach(([expected, actual]) => {
19
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
20
+ expect(actual).to.equal(expected);
21
+ });
22
+ });
23
+ });
24
+ });
@@ -97,7 +97,7 @@ export default class StrategiesAutomation extends Automation {
97
97
 
98
98
  if (subscriptionEvents) {
99
99
  // @ts-ignore
100
- const strategiesSubs = await this.getStrategiesSubs(subscriptionEvents.map((e) => e.returnValues.subId), _options.fromBlock);
100
+ const strategiesSubs = await this.getStrategiesSubs(subscriptionEvents.map((e) => e.returnValues.subId), _options.toBlock);
101
101
 
102
102
  subscriptions = await Promise.all(strategiesSubs.map(async (sub, index: number) => {
103
103
  let latestUpdate = subscriptionEvents[index].returnValues;
@@ -90,6 +90,11 @@ export const MAINNET_STRATEGIES_INFO: MainnetStrategiesInfo = {
90
90
  strategyId: Strategies.Identifiers.SavingsDsrSupply,
91
91
  protocol: PROTOCOLS.Liquity,
92
92
  },
93
+ [Strategies.MainnetIds.LIQUITY_DEBT_IN_FRONT_REPAY]: {
94
+ strategyOrBundleId: Strategies.MainnetIds.LIQUITY_DEBT_IN_FRONT_REPAY,
95
+ strategyId: Strategies.Identifiers.DebtInFrontRepay,
96
+ protocol: PROTOCOLS.Liquity,
97
+ },
93
98
  };
94
99
 
95
100
  export const OPTIMISM_STRATEGIES_INFO = {
@@ -203,11 +208,21 @@ export const MAINNET_BUNDLES_INFO: MainnetBundleInfo = {
203
208
  strategyId: Strategies.Identifiers.CloseToDebt,
204
209
  protocol: PROTOCOLS.AaveV3,
205
210
  },
211
+ [Bundles.MainnetIds.AAVE_V3_CLOSE_TO_DEBT_WITH_GAS_PRICE]: {
212
+ strategyOrBundleId: Bundles.MainnetIds.AAVE_V3_CLOSE_TO_DEBT_WITH_GAS_PRICE,
213
+ strategyId: Strategies.Identifiers.CloseToDebtWithGasPrice,
214
+ protocol: PROTOCOLS.AaveV3,
215
+ },
206
216
  [Bundles.MainnetIds.AAVE_V3_CLOSE_TO_COLLATERAL]: {
207
217
  strategyOrBundleId: Bundles.MainnetIds.AAVE_V3_CLOSE_TO_COLLATERAL,
208
218
  strategyId: Strategies.Identifiers.CloseToCollateral,
209
219
  protocol: PROTOCOLS.AaveV3,
210
220
  },
221
+ [Bundles.MainnetIds.AAVE_V3_CLOSE_TO_COLLATERAL_WITH_GAS_PRICE]: {
222
+ strategyOrBundleId: Bundles.MainnetIds.AAVE_V3_CLOSE_TO_COLLATERAL_WITH_GAS_PRICE,
223
+ strategyId: Strategies.Identifiers.CloseToCollateralWithGasPrice,
224
+ protocol: PROTOCOLS.AaveV3,
225
+ },
211
226
  [Bundles.MainnetIds.MORPHO_AAVE_V2_REPAY]: {
212
227
  strategyOrBundleId: Bundles.MainnetIds.MORPHO_AAVE_V2_REPAY,
213
228
  strategyId: Strategies.Identifiers.Repay,
@@ -1,13 +1,17 @@
1
1
  import type Web3 from 'web3';
2
2
  import type { AbiItem } from 'web3-utils';
3
+
3
4
  import type {
4
- BlockNumber, Contract,
5
+ BlockNumber, Contract, EthereumAddress,
5
6
  } from '../types';
6
-
7
7
  import type { BaseContract } from '../types/contracts/generated/types';
8
- import type { Legacy_AuthCheck, SubStorage, UniMulticall } from '../types/contracts/generated';
8
+ import type {
9
+ Legacy_AuthCheck, SubStorage, UniMulticall, Erc20,
10
+ } from '../types/contracts/generated';
9
11
 
10
- import { UniMulticallJson, SubStorageJson, AuthCheckJson } from '../abis';
12
+ import {
13
+ UniMulticallJson, SubStorageJson, AuthCheckJson, Erc20Json,
14
+ } from '../abis';
11
15
 
12
16
  import { isDefined } from './utils';
13
17
  import { ChainId } from '../types/enums';
@@ -62,4 +66,13 @@ export function makeAuthCheckerContract(web3: Web3, chainId: ChainId) {
62
66
 
63
67
  export function makeLegacySubscriptionContract<T extends BaseContract>(web3: Web3, contractJson: Contract.Json) {
64
68
  return makeContract<T>(web3, contractJson, ChainId.Ethereum);
69
+ }
70
+
71
+ export function makeErc20Contract(web3: Web3, tokenAddress: EthereumAddress, chainId: ChainId) {
72
+ return makeContract<Erc20>(web3, {
73
+ ...Erc20Json,
74
+ networks: {
75
+ [chainId]: { address: tokenAddress },
76
+ },
77
+ }, chainId);
65
78
  }