@defisaver/automation-sdk 3.3.16-liq-prot-dev → 3.3.17
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/cjs/constants/index.js +42 -117
- package/cjs/index.d.ts +2 -2
- package/cjs/index.js +2 -5
- package/cjs/services/strategiesService.js +21 -160
- package/cjs/services/strategySubService.d.ts +21 -18
- package/cjs/services/strategySubService.js +74 -78
- package/cjs/services/strategySubService.test.js +149 -3
- package/cjs/services/subDataService.d.ts +20 -70
- package/cjs/services/subDataService.js +79 -23
- package/cjs/services/subDataService.test.js +202 -17
- package/cjs/services/utils.d.ts +1 -2
- package/cjs/services/utils.js +1 -14
- package/cjs/types/enums.d.ts +17 -36
- package/cjs/types/enums.js +11 -30
- package/esm/constants/index.js +42 -117
- package/esm/index.d.ts +2 -2
- package/esm/index.js +2 -5
- package/esm/services/strategiesService.js +21 -160
- package/esm/services/strategySubService.d.ts +21 -18
- package/esm/services/strategySubService.js +73 -78
- package/esm/services/strategySubService.test.js +147 -4
- package/esm/services/subDataService.d.ts +20 -70
- package/esm/services/subDataService.js +77 -21
- package/esm/services/subDataService.test.js +200 -18
- package/esm/services/utils.d.ts +1 -2
- package/esm/services/utils.js +1 -13
- package/esm/types/enums.d.ts +17 -36
- package/esm/types/enums.js +11 -30
- package/package.json +1 -1
- package/src/constants/index.ts +43 -119
- package/src/index.ts +6 -22
- package/src/services/strategiesService.ts +23 -225
- package/src/services/strategySubService.test.ts +191 -3
- package/src/services/strategySubService.ts +121 -173
- package/src/services/subDataService.test.ts +214 -18
- package/src/services/subDataService.ts +106 -42
- package/src/services/utils.test.ts +1 -1
- package/src/services/utils.ts +1 -15
- package/src/types/enums.ts +13 -30
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { expect } from 'chai';
|
|
2
|
+
import Dec from 'decimal.js';
|
|
2
3
|
import { otherAddresses } from '@defisaver/sdk';
|
|
3
4
|
import { getAssetInfo, MAXUINT } from '@defisaver/tokens';
|
|
4
5
|
import * as web3Utils from 'web3-utils';
|
|
@@ -8,10 +9,12 @@ import type { EthereumAddress, StrategyOrBundleIds, SubData, TriggerData } from
|
|
|
8
9
|
|
|
9
10
|
import '../configuration';
|
|
10
11
|
import {
|
|
12
|
+
chickenBondsEncode,
|
|
11
13
|
liquityEncode,
|
|
12
14
|
makerEncode,
|
|
13
15
|
aaveV3Encode,
|
|
14
16
|
compoundV3Encode,
|
|
17
|
+
morphoAaveV2Encode,
|
|
15
18
|
exchangeEncode,
|
|
16
19
|
crvUSDEncode,
|
|
17
20
|
morphoBlueEncode,
|
|
@@ -134,7 +137,7 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
134
137
|
});
|
|
135
138
|
});
|
|
136
139
|
|
|
137
|
-
describe('
|
|
140
|
+
describe('leverageManagementWithoutSubProxy()', () => {
|
|
138
141
|
const examples: Array<[
|
|
139
142
|
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
140
143
|
[
|
|
@@ -184,7 +187,7 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
184
187
|
|
|
185
188
|
examples.forEach(([expected, actual]) => {
|
|
186
189
|
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
187
|
-
expect(makerEncode.
|
|
190
|
+
expect(makerEncode.leverageManagementWithoutSubProxy(...actual)).to.eql(expected);
|
|
188
191
|
});
|
|
189
192
|
});
|
|
190
193
|
});
|
|
@@ -345,6 +348,26 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
345
348
|
});
|
|
346
349
|
});
|
|
347
350
|
|
|
351
|
+
describe('When testing strategySubService.chickenBondsEncode', () => {
|
|
352
|
+
describe('rebond()', () => {
|
|
353
|
+
const examples: Array<[
|
|
354
|
+
SubData,
|
|
355
|
+
[bondId: number],
|
|
356
|
+
]> = [
|
|
357
|
+
[
|
|
358
|
+
['0x00000000000000000000000000000000000000000000000000000000000005e3'],
|
|
359
|
+
[1507]
|
|
360
|
+
]
|
|
361
|
+
];
|
|
362
|
+
|
|
363
|
+
examples.forEach(([expected, actual]) => {
|
|
364
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
365
|
+
expect(chickenBondsEncode.rebond(...actual)).to.eql(expected);
|
|
366
|
+
});
|
|
367
|
+
});
|
|
368
|
+
});
|
|
369
|
+
});
|
|
370
|
+
|
|
348
371
|
describe('When testing strategySubService.aaveV3Encode', () => {
|
|
349
372
|
describe('closeToAsset()', () => {
|
|
350
373
|
const examples: Array<[
|
|
@@ -1133,6 +1156,27 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1133
1156
|
});
|
|
1134
1157
|
});
|
|
1135
1158
|
|
|
1159
|
+
describe('When testing strategySubService.morphoAaveV2Encode', () => {
|
|
1160
|
+
describe('leverageManagement()', () => {
|
|
1161
|
+
const examples: Array<[[string, string, string, string, boolean], [triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean]]> = [
|
|
1162
|
+
[
|
|
1163
|
+
[new Dec(160).mul(1e16).toString(), new Dec(220).mul(1e16).toString(), new Dec(180).mul(1e16).toString(), new Dec(190).mul(1e16).toString(), true],
|
|
1164
|
+
[160, 220, 180, 190, true]
|
|
1165
|
+
],
|
|
1166
|
+
[
|
|
1167
|
+
[new Dec(160).mul(1e16).toString(), new Dec(200).mul(1e16).toString(), new Dec(180).mul(1e16).toString(), new Dec(190).mul(1e16).toString(), false],
|
|
1168
|
+
[160, 200, 180, 190, false]
|
|
1169
|
+
],
|
|
1170
|
+
];
|
|
1171
|
+
|
|
1172
|
+
examples.forEach(([expected, actual]) => {
|
|
1173
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1174
|
+
expect(morphoAaveV2Encode.leverageManagement(...actual)).to.eql(expected);
|
|
1175
|
+
});
|
|
1176
|
+
});
|
|
1177
|
+
});
|
|
1178
|
+
});
|
|
1179
|
+
|
|
1136
1180
|
describe('When testing strategySubService.exchangeEncode', () => {
|
|
1137
1181
|
describe('dca()', () => {
|
|
1138
1182
|
const examples: Array<[
|
|
@@ -1457,6 +1501,93 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1457
1501
|
});
|
|
1458
1502
|
});
|
|
1459
1503
|
|
|
1504
|
+
describe('leverageManagementOnPriceGeneric()', () => {
|
|
1505
|
+
const examples: Array<[
|
|
1506
|
+
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
1507
|
+
[
|
|
1508
|
+
loanToken: EthereumAddress,
|
|
1509
|
+
collToken: EthereumAddress,
|
|
1510
|
+
oracle: EthereumAddress,
|
|
1511
|
+
irm: EthereumAddress,
|
|
1512
|
+
lltv: string,
|
|
1513
|
+
user: EthereumAddress,
|
|
1514
|
+
targetRatio: number,
|
|
1515
|
+
price: number,
|
|
1516
|
+
priceState: RatioState,
|
|
1517
|
+
isBoost: boolean,
|
|
1518
|
+
isEOA: boolean,
|
|
1519
|
+
network: ChainId,
|
|
1520
|
+
]
|
|
1521
|
+
]> = [
|
|
1522
|
+
[
|
|
1523
|
+
[
|
|
1524
|
+
Bundles.MainnetIds.MORPHO_BLUE_REPAY_ON_PRICE,
|
|
1525
|
+
true,
|
|
1526
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000003a352944000000000000000000000000000000000000000000000000000000000000000001'],
|
|
1527
|
+
[
|
|
1528
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1529
|
+
'0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
|
|
1530
|
+
'0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
|
|
1531
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1532
|
+
'0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
|
|
1533
|
+
'0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
|
|
1534
|
+
'0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
|
|
1535
|
+
],
|
|
1536
|
+
],
|
|
1537
|
+
[
|
|
1538
|
+
web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
|
|
1539
|
+
web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1540
|
+
web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1541
|
+
web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1542
|
+
'945000000000000000',
|
|
1543
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1544
|
+
200,
|
|
1545
|
+
2500,
|
|
1546
|
+
RatioState.UNDER,
|
|
1547
|
+
false,
|
|
1548
|
+
false,
|
|
1549
|
+
ChainId.Ethereum,
|
|
1550
|
+
],
|
|
1551
|
+
],
|
|
1552
|
+
[
|
|
1553
|
+
[
|
|
1554
|
+
Bundles.MainnetIds.MORPHO_BLUE_BOOST_ON_PRICE,
|
|
1555
|
+
true,
|
|
1556
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000005d21dba0000000000000000000000000000000000000000000000000000000000000000000'],
|
|
1557
|
+
[
|
|
1558
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1559
|
+
'0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
|
|
1560
|
+
'0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
|
|
1561
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1562
|
+
'0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
|
|
1563
|
+
'0x00000000000000000000000000000000000000000000000016345785d8a00000',
|
|
1564
|
+
'0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
|
|
1565
|
+
],
|
|
1566
|
+
],
|
|
1567
|
+
[
|
|
1568
|
+
web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
|
|
1569
|
+
web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1570
|
+
web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1571
|
+
web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1572
|
+
'945000000000000000',
|
|
1573
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1574
|
+
160,
|
|
1575
|
+
4000,
|
|
1576
|
+
RatioState.OVER,
|
|
1577
|
+
true,
|
|
1578
|
+
false,
|
|
1579
|
+
ChainId.Ethereum,
|
|
1580
|
+
],
|
|
1581
|
+
],
|
|
1582
|
+
];
|
|
1583
|
+
|
|
1584
|
+
examples.forEach(([expected, actual]) => {
|
|
1585
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1586
|
+
expect(morphoBlueEncode.leverageManagementOnPriceGeneric(...actual)).to.eql(expected);
|
|
1587
|
+
});
|
|
1588
|
+
});
|
|
1589
|
+
});
|
|
1590
|
+
|
|
1460
1591
|
describe('closeOnPrice()', () => {
|
|
1461
1592
|
const examples: Array<[
|
|
1462
1593
|
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
@@ -1500,7 +1631,7 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1500
1631
|
1500,
|
|
1501
1632
|
CloseToAssetType.DEBT,
|
|
1502
1633
|
4000,
|
|
1503
|
-
CloseToAssetType.COLLATERAL
|
|
1634
|
+
CloseToAssetType.COLLATERAL,
|
|
1504
1635
|
]
|
|
1505
1636
|
],
|
|
1506
1637
|
];
|
|
@@ -1511,6 +1642,63 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1511
1642
|
});
|
|
1512
1643
|
});
|
|
1513
1644
|
});
|
|
1645
|
+
|
|
1646
|
+
describe('closeOnPriceGeneric()', () => {
|
|
1647
|
+
const examples: Array<[
|
|
1648
|
+
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
1649
|
+
[
|
|
1650
|
+
loanToken: EthereumAddress,
|
|
1651
|
+
collToken: EthereumAddress,
|
|
1652
|
+
oracle: EthereumAddress,
|
|
1653
|
+
irm: EthereumAddress,
|
|
1654
|
+
lltv: string,
|
|
1655
|
+
user: EthereumAddress,
|
|
1656
|
+
stopLossPrice: number,
|
|
1657
|
+
stopLossType: CloseToAssetType,
|
|
1658
|
+
takeProfitPrice: number,
|
|
1659
|
+
takeProfitType: CloseToAssetType,
|
|
1660
|
+
isEOA: boolean,
|
|
1661
|
+
network: ChainId,
|
|
1662
|
+
]
|
|
1663
|
+
]> = [
|
|
1664
|
+
[
|
|
1665
|
+
[
|
|
1666
|
+
Bundles.MainnetIds.MORPHO_BLUE_CLOSE,
|
|
1667
|
+
true,
|
|
1668
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
|
|
1669
|
+
[
|
|
1670
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1671
|
+
'0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
|
|
1672
|
+
'0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
|
|
1673
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1674
|
+
'0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
|
|
1675
|
+
'0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
|
|
1676
|
+
'0x0000000000000000000000000000000000000000000000000000000000000005',
|
|
1677
|
+
],
|
|
1678
|
+
],
|
|
1679
|
+
[
|
|
1680
|
+
web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
|
|
1681
|
+
web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1682
|
+
web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1683
|
+
web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1684
|
+
'945000000000000000',
|
|
1685
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1686
|
+
1500,
|
|
1687
|
+
CloseToAssetType.DEBT,
|
|
1688
|
+
4000,
|
|
1689
|
+
CloseToAssetType.COLLATERAL,
|
|
1690
|
+
false,
|
|
1691
|
+
ChainId.Ethereum,
|
|
1692
|
+
]
|
|
1693
|
+
],
|
|
1694
|
+
];
|
|
1695
|
+
|
|
1696
|
+
examples.forEach(([expected, actual]) => {
|
|
1697
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1698
|
+
expect(morphoBlueEncode.closeOnPriceGeneric(...actual)).to.eql(expected);
|
|
1699
|
+
});
|
|
1700
|
+
});
|
|
1701
|
+
});
|
|
1514
1702
|
});
|
|
1515
1703
|
|
|
1516
1704
|
describe('When testing strategySubService.sparkEncode', () => {
|