@defisaver/automation-sdk 2.0.6 → 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.
- package/.env.dev +5 -0
- package/.tests.sh +3 -0
- package/README.md +3 -1
- package/esm/automation/private/LegacyProtocol.test.d.ts +1 -0
- package/esm/automation/private/LegacyProtocol.test.js +25 -0
- package/esm/automation/private/Protocol.test.d.ts +1 -0
- package/esm/automation/private/Protocol.test.js +25 -0
- package/esm/constants/index.js +5 -0
- package/esm/services/contractService.d.ts +3 -2
- package/esm/services/contractService.js +7 -1
- package/esm/services/ethereumService.test.d.ts +1 -0
- package/esm/services/ethereumService.test.js +241 -0
- package/esm/services/strategiesService.js +14 -0
- package/esm/services/strategiesService.test.d.ts +1 -0
- package/esm/services/strategiesService.test.js +108 -0
- package/esm/services/strategySubService.d.ts +5 -3
- package/esm/services/strategySubService.js +10 -6
- package/esm/services/strategySubService.test.d.ts +1 -0
- package/esm/services/strategySubService.test.js +692 -0
- package/esm/services/subDataService.d.ts +8 -1
- package/esm/services/subDataService.js +23 -14
- package/esm/services/subDataService.test.d.ts +1 -0
- package/esm/services/subDataService.test.js +993 -0
- package/esm/services/triggerService.d.ts +7 -0
- package/esm/services/triggerService.js +14 -1
- package/esm/services/triggerService.test.js +119 -17
- package/esm/types/enums.d.ts +4 -2
- package/esm/types/enums.js +2 -0
- package/esm/types/index.d.ts +8 -2
- package/package.json +3 -3
- package/src/automation/private/LegacyProtocol.test.ts +24 -0
- package/src/automation/private/Protocol.test.ts +24 -0
- package/src/constants/index.ts +5 -0
- package/src/services/contractService.ts +17 -4
- package/src/services/ethereumService.test.ts +256 -0
- package/src/services/ethereumService.ts +2 -1
- package/src/services/strategiesService.test.ts +103 -0
- package/src/services/strategiesService.ts +27 -3
- package/src/services/strategySubService.test.ts +835 -0
- package/src/services/strategySubService.ts +28 -15
- package/src/services/subDataService.test.ts +1063 -0
- package/src/services/subDataService.ts +29 -14
- package/src/services/triggerService.test.ts +131 -19
- package/src/services/triggerService.ts +14 -0
- package/src/services/utils.test.ts +1 -1
- package/src/types/enums.ts +2 -0
- package/src/types/index.ts +14 -3
- package/umd/index.js +148 -74
|
@@ -83,6 +83,13 @@ export declare const liquityDebtInFrontTrigger: {
|
|
|
83
83
|
debtInFrontMin: string;
|
|
84
84
|
};
|
|
85
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
|
+
};
|
|
86
93
|
export declare const aaveV2RatioTrigger: {
|
|
87
94
|
encode(owner: EthereumAddress, market: EthereumAddress, ratioPercentage: number, ratioState: RatioState): string[];
|
|
88
95
|
decode(triggerData: string[]): {
|
|
@@ -26,7 +26,7 @@ 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.aaveV3QuotePriceWithMaximumGasPriceTrigger = 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
31
|
const tokens_1 = require("@defisaver/tokens");
|
|
32
32
|
const web3_eth_abi_1 = __importDefault(require("web3-eth-abi"));
|
|
@@ -177,6 +177,19 @@ exports.liquityDebtInFrontTrigger = {
|
|
|
177
177
|
};
|
|
178
178
|
},
|
|
179
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
|
+
};
|
|
180
193
|
exports.aaveV2RatioTrigger = {
|
|
181
194
|
encode(owner, market, ratioPercentage, ratioState) {
|
|
182
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
|
});
|
package/esm/types/enums.d.ts
CHANGED
|
@@ -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,
|
|
@@ -84,7 +85,8 @@ export declare namespace Strategies {
|
|
|
84
85
|
Rebond = "rebond",
|
|
85
86
|
BondProtection = "bond-protection",
|
|
86
87
|
Dca = "dca",
|
|
87
|
-
LimitOrder = "limit-order"
|
|
88
|
+
LimitOrder = "limit-order",
|
|
89
|
+
DebtInFrontRepay = "debt-in-front-repay"
|
|
88
90
|
}
|
|
89
91
|
enum IdOverrides {
|
|
90
92
|
TakeProfit = "take-profit",
|
package/esm/types/enums.js
CHANGED
|
@@ -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) {
|
|
@@ -100,6 +101,7 @@ var Strategies;
|
|
|
100
101
|
Identifiers["BondProtection"] = "bond-protection";
|
|
101
102
|
Identifiers["Dca"] = "dca";
|
|
102
103
|
Identifiers["LimitOrder"] = "limit-order";
|
|
104
|
+
Identifiers["DebtInFrontRepay"] = "debt-in-front-repay";
|
|
103
105
|
})(Identifiers = Strategies.Identifiers || (Strategies.Identifiers = {}));
|
|
104
106
|
let IdOverrides;
|
|
105
107
|
(function (IdOverrides) {
|
package/esm/types/index.d.ts
CHANGED
|
@@ -132,8 +132,12 @@ export declare namespace Position {
|
|
|
132
132
|
triggerPercentage: number;
|
|
133
133
|
closeToAssetAddr: EthereumAddress;
|
|
134
134
|
}
|
|
135
|
+
interface DebtInFrontRepay extends Base {
|
|
136
|
+
debtInFrontMin: string;
|
|
137
|
+
targetRepayRatioIncrease: number;
|
|
138
|
+
}
|
|
135
139
|
}
|
|
136
|
-
type SpecificAny = Specific.CloseOnPrice | Specific.TrailingStop | Specific.RatioProtection | Specific.CloseOnPriceAave | Specific.CloseOnPriceWithMaximumGasPriceAave;
|
|
140
|
+
type SpecificAny = Specific.CloseOnPrice | Specific.TrailingStop | Specific.RatioProtection | Specific.CloseOnPriceAave | Specific.CloseOnPriceWithMaximumGasPriceAave | Specific.DebtInFrontRepay;
|
|
137
141
|
interface Automated {
|
|
138
142
|
chainId: ChainId;
|
|
139
143
|
owner: EthereumAddress;
|
|
@@ -172,10 +176,12 @@ type StrategyInfo<T extends number> = Record<T, Strategy<T>>;
|
|
|
172
176
|
export type MainnetStrategiesInfo = StrategyInfo<Strategies.MainnetIds>;
|
|
173
177
|
export type OptimismStrategiesInfo = StrategyInfo<Strategies.OptimismIds>;
|
|
174
178
|
export type ArbitrumStrategiesInfo = StrategyInfo<Strategies.ArbitrumIds>;
|
|
179
|
+
export type StrategyInfoUnion = MainnetStrategiesInfo | OptimismStrategiesInfo | ArbitrumStrategiesInfo;
|
|
175
180
|
type BundleInfo<T extends number> = Record<T, BundleOrStrategy<T>>;
|
|
176
181
|
export type MainnetBundleInfo = BundleInfo<Bundles.MainnetIds>;
|
|
177
182
|
export type OptimismBundleInfo = BundleInfo<Bundles.OptimismIds>;
|
|
178
183
|
export type ArbitrumBundleInfo = BundleInfo<Bundles.ArbitrumIds>;
|
|
184
|
+
export type BundleInfoUnion = MainnetBundleInfo | OptimismBundleInfo | ArbitrumBundleInfo;
|
|
179
185
|
export interface StrategiesInfo {
|
|
180
186
|
[ChainId.Ethereum]: MainnetStrategiesInfo;
|
|
181
187
|
[ChainId.Optimism]: OptimismStrategiesInfo;
|
|
@@ -186,7 +192,7 @@ export interface BundlesInfo {
|
|
|
186
192
|
[ChainId.Optimism]: OptimismBundleInfo;
|
|
187
193
|
[ChainId.Arbitrum]: ArbitrumBundleInfo;
|
|
188
194
|
}
|
|
189
|
-
export type StrategyOrBundleIds = Strategies.MainnetIds
|
|
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];
|
|
190
196
|
export interface ParseData {
|
|
191
197
|
chainId: ChainId;
|
|
192
198
|
blockNumber: BlockNumber;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defisaver/automation-sdk",
|
|
3
|
-
"version": "2.0.
|
|
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": "
|
|
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": "^
|
|
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
|
+
});
|
package/src/constants/index.ts
CHANGED
|
@@ -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 = {
|
|
@@ -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 {
|
|
8
|
+
import type {
|
|
9
|
+
Legacy_AuthCheck, SubStorage, UniMulticall, Erc20,
|
|
10
|
+
} from '../types/contracts/generated';
|
|
9
11
|
|
|
10
|
-
import {
|
|
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
|
}
|