@defisaver/automation-sdk 3.3.16 → 3.3.17-liq-prot-dev
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 +190 -0
- package/cjs/index.d.ts +2 -2
- package/cjs/index.js +5 -2
- package/cjs/services/strategiesService.js +169 -12
- package/cjs/services/strategySubService.d.ts +22 -17
- package/cjs/services/strategySubService.js +115 -38
- package/cjs/services/strategySubService.test.js +111 -41
- package/cjs/services/subDataService.d.ts +70 -20
- package/cjs/services/subDataService.js +23 -79
- package/cjs/services/subDataService.test.js +17 -202
- package/cjs/types/enums.d.ts +48 -6
- package/cjs/types/enums.js +42 -0
- package/esm/constants/index.js +190 -0
- package/esm/index.d.ts +2 -2
- package/esm/index.js +5 -2
- package/esm/services/strategiesService.js +169 -12
- package/esm/services/strategySubService.d.ts +22 -17
- package/esm/services/strategySubService.js +113 -37
- package/esm/services/strategySubService.test.js +112 -39
- package/esm/services/subDataService.d.ts +70 -20
- package/esm/services/subDataService.js +21 -77
- package/esm/services/subDataService.test.js +18 -200
- package/esm/types/enums.d.ts +48 -6
- package/esm/types/enums.js +42 -0
- package/package.json +1 -1
- package/src/constants/index.ts +192 -1
- package/src/index.ts +22 -6
- package/src/services/strategiesService.ts +234 -12
- package/src/services/strategySubService.test.ts +147 -47
- package/src/services/strategySubService.ts +246 -47
- package/src/services/subDataService.test.ts +18 -214
- package/src/services/subDataService.ts +42 -106
- package/src/services/utils.test.ts +1 -1
- package/src/services/utils.ts +3 -1
- package/src/types/enums.ts +42 -2
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { expect } from 'chai';
|
|
2
|
-
import Dec from 'decimal.js';
|
|
3
2
|
import { otherAddresses } from '@defisaver/sdk';
|
|
4
3
|
import { getAssetInfo, MAXUINT } from '@defisaver/tokens';
|
|
5
4
|
import * as web3Utils from 'web3-utils';
|
|
@@ -9,12 +8,10 @@ import type { EthereumAddress, StrategyOrBundleIds, SubData, TriggerData } from
|
|
|
9
8
|
|
|
10
9
|
import '../configuration';
|
|
11
10
|
import {
|
|
12
|
-
chickenBondsEncode,
|
|
13
11
|
liquityEncode,
|
|
14
12
|
makerEncode,
|
|
15
13
|
aaveV3Encode,
|
|
16
14
|
compoundV3Encode,
|
|
17
|
-
morphoAaveV2Encode,
|
|
18
15
|
exchangeEncode,
|
|
19
16
|
crvUSDEncode,
|
|
20
17
|
morphoBlueEncode,
|
|
@@ -137,7 +134,7 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
137
134
|
});
|
|
138
135
|
});
|
|
139
136
|
|
|
140
|
-
describe('
|
|
137
|
+
describe('leverageManagement()', () => {
|
|
141
138
|
const examples: Array<[
|
|
142
139
|
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
143
140
|
[
|
|
@@ -187,7 +184,7 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
187
184
|
|
|
188
185
|
examples.forEach(([expected, actual]) => {
|
|
189
186
|
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
190
|
-
expect(makerEncode.
|
|
187
|
+
expect(makerEncode.leverageManagement(...actual)).to.eql(expected);
|
|
191
188
|
});
|
|
192
189
|
});
|
|
193
190
|
});
|
|
@@ -348,26 +345,6 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
348
345
|
});
|
|
349
346
|
});
|
|
350
347
|
|
|
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
|
-
|
|
371
348
|
describe('When testing strategySubService.aaveV3Encode', () => {
|
|
372
349
|
describe('closeToAsset()', () => {
|
|
373
350
|
const examples: Array<[
|
|
@@ -1156,27 +1133,6 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1156
1133
|
});
|
|
1157
1134
|
});
|
|
1158
1135
|
|
|
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
|
-
|
|
1180
1136
|
describe('When testing strategySubService.exchangeEncode', () => {
|
|
1181
1137
|
describe('dca()', () => {
|
|
1182
1138
|
const examples: Array<[
|
|
@@ -1501,6 +1457,93 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1501
1457
|
});
|
|
1502
1458
|
});
|
|
1503
1459
|
|
|
1460
|
+
describe('leverageManagementOnPriceGeneric()', () => {
|
|
1461
|
+
const examples: Array<[
|
|
1462
|
+
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
1463
|
+
[
|
|
1464
|
+
loanToken: EthereumAddress,
|
|
1465
|
+
collToken: EthereumAddress,
|
|
1466
|
+
oracle: EthereumAddress,
|
|
1467
|
+
irm: EthereumAddress,
|
|
1468
|
+
lltv: string,
|
|
1469
|
+
user: EthereumAddress,
|
|
1470
|
+
targetRatio: number,
|
|
1471
|
+
price: number,
|
|
1472
|
+
priceState: RatioState,
|
|
1473
|
+
isBoost: boolean,
|
|
1474
|
+
isEOA: boolean,
|
|
1475
|
+
network: ChainId,
|
|
1476
|
+
]
|
|
1477
|
+
]> = [
|
|
1478
|
+
[
|
|
1479
|
+
[
|
|
1480
|
+
Bundles.MainnetIds.MORPHO_BLUE_REPAY_ON_PRICE,
|
|
1481
|
+
true,
|
|
1482
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000003a352944000000000000000000000000000000000000000000000000000000000000000001'],
|
|
1483
|
+
[
|
|
1484
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1485
|
+
'0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
|
|
1486
|
+
'0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
|
|
1487
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1488
|
+
'0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
|
|
1489
|
+
'0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
|
|
1490
|
+
'0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
|
|
1491
|
+
],
|
|
1492
|
+
],
|
|
1493
|
+
[
|
|
1494
|
+
web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
|
|
1495
|
+
web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1496
|
+
web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1497
|
+
web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1498
|
+
'945000000000000000',
|
|
1499
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1500
|
+
200,
|
|
1501
|
+
2500,
|
|
1502
|
+
RatioState.UNDER,
|
|
1503
|
+
false,
|
|
1504
|
+
false,
|
|
1505
|
+
ChainId.Ethereum,
|
|
1506
|
+
],
|
|
1507
|
+
],
|
|
1508
|
+
[
|
|
1509
|
+
[
|
|
1510
|
+
Bundles.MainnetIds.MORPHO_BLUE_BOOST_ON_PRICE,
|
|
1511
|
+
true,
|
|
1512
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000005d21dba0000000000000000000000000000000000000000000000000000000000000000000'],
|
|
1513
|
+
[
|
|
1514
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1515
|
+
'0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
|
|
1516
|
+
'0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
|
|
1517
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1518
|
+
'0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
|
|
1519
|
+
'0x00000000000000000000000000000000000000000000000016345785d8a00000',
|
|
1520
|
+
'0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
|
|
1521
|
+
],
|
|
1522
|
+
],
|
|
1523
|
+
[
|
|
1524
|
+
web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
|
|
1525
|
+
web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1526
|
+
web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1527
|
+
web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1528
|
+
'945000000000000000',
|
|
1529
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1530
|
+
160,
|
|
1531
|
+
4000,
|
|
1532
|
+
RatioState.OVER,
|
|
1533
|
+
true,
|
|
1534
|
+
false,
|
|
1535
|
+
ChainId.Ethereum,
|
|
1536
|
+
],
|
|
1537
|
+
],
|
|
1538
|
+
];
|
|
1539
|
+
|
|
1540
|
+
examples.forEach(([expected, actual]) => {
|
|
1541
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1542
|
+
expect(morphoBlueEncode.leverageManagementOnPriceGeneric(...actual)).to.eql(expected);
|
|
1543
|
+
});
|
|
1544
|
+
});
|
|
1545
|
+
});
|
|
1546
|
+
|
|
1504
1547
|
describe('closeOnPrice()', () => {
|
|
1505
1548
|
const examples: Array<[
|
|
1506
1549
|
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
@@ -1544,7 +1587,7 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1544
1587
|
1500,
|
|
1545
1588
|
CloseToAssetType.DEBT,
|
|
1546
1589
|
4000,
|
|
1547
|
-
CloseToAssetType.COLLATERAL
|
|
1590
|
+
CloseToAssetType.COLLATERAL,
|
|
1548
1591
|
]
|
|
1549
1592
|
],
|
|
1550
1593
|
];
|
|
@@ -1555,6 +1598,63 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1555
1598
|
});
|
|
1556
1599
|
});
|
|
1557
1600
|
});
|
|
1601
|
+
|
|
1602
|
+
describe('closeOnPriceGeneric()', () => {
|
|
1603
|
+
const examples: Array<[
|
|
1604
|
+
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
1605
|
+
[
|
|
1606
|
+
loanToken: EthereumAddress,
|
|
1607
|
+
collToken: EthereumAddress,
|
|
1608
|
+
oracle: EthereumAddress,
|
|
1609
|
+
irm: EthereumAddress,
|
|
1610
|
+
lltv: string,
|
|
1611
|
+
user: EthereumAddress,
|
|
1612
|
+
stopLossPrice: number,
|
|
1613
|
+
stopLossType: CloseToAssetType,
|
|
1614
|
+
takeProfitPrice: number,
|
|
1615
|
+
takeProfitType: CloseToAssetType,
|
|
1616
|
+
isEOA: boolean,
|
|
1617
|
+
network: ChainId,
|
|
1618
|
+
]
|
|
1619
|
+
]> = [
|
|
1620
|
+
[
|
|
1621
|
+
[
|
|
1622
|
+
Bundles.MainnetIds.MORPHO_BLUE_CLOSE,
|
|
1623
|
+
true,
|
|
1624
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
|
|
1625
|
+
[
|
|
1626
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1627
|
+
'0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
|
|
1628
|
+
'0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
|
|
1629
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1630
|
+
'0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
|
|
1631
|
+
'0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
|
|
1632
|
+
'0x0000000000000000000000000000000000000000000000000000000000000005',
|
|
1633
|
+
],
|
|
1634
|
+
],
|
|
1635
|
+
[
|
|
1636
|
+
web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
|
|
1637
|
+
web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1638
|
+
web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1639
|
+
web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1640
|
+
'945000000000000000',
|
|
1641
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1642
|
+
1500,
|
|
1643
|
+
CloseToAssetType.DEBT,
|
|
1644
|
+
4000,
|
|
1645
|
+
CloseToAssetType.COLLATERAL,
|
|
1646
|
+
false,
|
|
1647
|
+
ChainId.Ethereum,
|
|
1648
|
+
]
|
|
1649
|
+
],
|
|
1650
|
+
];
|
|
1651
|
+
|
|
1652
|
+
examples.forEach(([expected, actual]) => {
|
|
1653
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1654
|
+
expect(morphoBlueEncode.closeOnPriceGeneric(...actual)).to.eql(expected);
|
|
1655
|
+
});
|
|
1656
|
+
});
|
|
1657
|
+
});
|
|
1558
1658
|
});
|
|
1559
1659
|
|
|
1560
1660
|
describe('When testing strategySubService.sparkEncode', () => {
|