@defisaver/automation-sdk 3.3.10 → 3.3.11-aave-v4-1-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/automation/private/StrategiesAutomation.d.ts +2 -0
- package/cjs/automation/private/StrategiesAutomation.js +10 -1
- package/cjs/automation/private/StrategiesAutomation.test.js +25 -0
- package/cjs/constants/index.d.ts +1 -0
- package/cjs/constants/index.js +72 -1
- package/cjs/services/ethereumService.test.js +2 -0
- package/cjs/services/strategiesService.js +129 -0
- package/cjs/services/strategySubService.d.ts +19 -0
- package/cjs/services/strategySubService.js +37 -1
- package/cjs/services/strategySubService.test.js +229 -0
- package/cjs/services/subDataService.d.ts +298 -129
- package/cjs/services/subDataService.js +639 -369
- package/cjs/services/subDataService.test.js +214 -0
- package/cjs/services/triggerService.d.ts +38 -0
- package/cjs/services/triggerService.js +68 -1
- package/cjs/services/triggerService.test.js +130 -0
- package/cjs/services/utils.d.ts +1 -1
- package/cjs/services/utils.js +10 -2
- package/cjs/types/enums.d.ts +19 -3
- package/cjs/types/enums.js +16 -0
- package/cjs/types/index.d.ts +33 -1
- package/esm/automation/private/StrategiesAutomation.d.ts +2 -0
- package/esm/automation/private/StrategiesAutomation.js +10 -1
- package/esm/automation/private/StrategiesAutomation.test.js +25 -0
- package/esm/constants/index.d.ts +1 -0
- package/esm/constants/index.js +71 -0
- package/esm/services/ethereumService.test.js +2 -0
- package/esm/services/strategiesService.js +130 -1
- package/esm/services/strategySubService.d.ts +19 -0
- package/esm/services/strategySubService.js +36 -0
- package/esm/services/strategySubService.test.js +230 -1
- package/esm/services/subDataService.d.ts +298 -129
- package/esm/services/subDataService.js +639 -369
- package/esm/services/subDataService.test.js +214 -0
- package/esm/services/triggerService.d.ts +38 -0
- package/esm/services/triggerService.js +67 -0
- package/esm/services/triggerService.test.js +131 -1
- package/esm/services/utils.d.ts +1 -1
- package/esm/services/utils.js +10 -2
- package/esm/types/enums.d.ts +19 -3
- package/esm/types/enums.js +16 -0
- package/esm/types/index.d.ts +33 -1
- package/package.json +2 -2
- package/src/automation/private/StrategiesAutomation.test.ts +40 -0
- package/src/automation/private/StrategiesAutomation.ts +11 -0
- package/src/constants/index.ts +72 -0
- package/src/services/ethereumService.test.ts +2 -0
- package/src/services/strategiesService.ts +150 -2
- package/src/services/strategySubService.test.ts +286 -0
- package/src/services/strategySubService.ts +140 -0
- package/src/services/subDataService.test.ts +239 -0
- package/src/services/subDataService.ts +1072 -784
- package/src/services/triggerService.test.ts +148 -0
- package/src/services/triggerService.ts +97 -1
- package/src/services/utils.ts +15 -4
- package/src/types/enums.ts +16 -0
- package/src/types/index.ts +40 -1
|
@@ -5,7 +5,7 @@ import { getAssetInfo, MAXUINT } from '@defisaver/tokens';
|
|
|
5
5
|
import * as web3Utils from 'web3-utils';
|
|
6
6
|
import { Bundles, ChainId, CloseToAssetType, OrderType, RatioState, Strategies } from '../types/enums';
|
|
7
7
|
import '../configuration';
|
|
8
|
-
import { aaveV2Encode, chickenBondsEncode, liquityEncode, makerEncode, aaveV3Encode, compoundV2Encode, compoundV3Encode, morphoAaveV2Encode, exchangeEncode, crvUSDEncode, compoundV3L2Encode, morphoBlueEncode, } from './strategySubService';
|
|
8
|
+
import { aaveV2Encode, chickenBondsEncode, liquityEncode, makerEncode, aaveV3Encode, compoundV2Encode, compoundV3Encode, morphoAaveV2Encode, exchangeEncode, crvUSDEncode, compoundV3L2Encode, morphoBlueEncode, sparkEncode, aaveV4Encode, } from './strategySubService';
|
|
9
9
|
describe('Feature: strategySubService.ts', () => {
|
|
10
10
|
describe('When testing strategySubService.makerEncode', () => {
|
|
11
11
|
// @ts-ignore // TODO - this requires change in @defisaver/tokens
|
|
@@ -1453,4 +1453,233 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1453
1453
|
});
|
|
1454
1454
|
});
|
|
1455
1455
|
});
|
|
1456
|
+
describe('When testing strategySubService.sparkEncode', () => {
|
|
1457
|
+
describe('leverageManagement()', () => {
|
|
1458
|
+
const examples = [
|
|
1459
|
+
[
|
|
1460
|
+
'0x0000000000000000136dcc951d8c00000000000000000000214e8348c4f0000000000000000000001d24b2dfac52000000000000000000001a5e27eef13e000001',
|
|
1461
|
+
[140, 240, 210, 190, true]
|
|
1462
|
+
],
|
|
1463
|
+
[
|
|
1464
|
+
'0x0000000000000000130337bdce49000000000000000000001988fe4052b800000000000000000000281b57b028e1000000000000000000002223acf76376000000',
|
|
1465
|
+
[137, 184, 289, 246, false]
|
|
1466
|
+
]
|
|
1467
|
+
];
|
|
1468
|
+
examples.forEach(([expected, actual]) => {
|
|
1469
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1470
|
+
expect(sparkEncode.leverageManagement(...actual)).to.eql(expected);
|
|
1471
|
+
});
|
|
1472
|
+
});
|
|
1473
|
+
});
|
|
1474
|
+
describe('leverageManagementOnPrice()', () => {
|
|
1475
|
+
const examples = [
|
|
1476
|
+
[
|
|
1477
|
+
[
|
|
1478
|
+
Bundles.MainnetIds.SPARK_REPAY_ON_PRICE,
|
|
1479
|
+
true,
|
|
1480
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000003a352944000000000000000000000000000000000000000000000000000000000000000001'],
|
|
1481
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1482
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1483
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
1484
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1485
|
+
'0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
|
|
1486
|
+
'0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
|
|
1487
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1488
|
+
],
|
|
1489
|
+
],
|
|
1490
|
+
[
|
|
1491
|
+
59,
|
|
1492
|
+
true,
|
|
1493
|
+
{
|
|
1494
|
+
baseTokenAddr: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1495
|
+
quoteTokenAddr: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1496
|
+
price: 2500,
|
|
1497
|
+
ratioState: RatioState.UNDER,
|
|
1498
|
+
},
|
|
1499
|
+
{
|
|
1500
|
+
collAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1501
|
+
collAssetId: 0,
|
|
1502
|
+
debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1503
|
+
debtAssetId: 1,
|
|
1504
|
+
marketAddr: web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
|
|
1505
|
+
targetRatio: 200,
|
|
1506
|
+
},
|
|
1507
|
+
]
|
|
1508
|
+
],
|
|
1509
|
+
[
|
|
1510
|
+
[
|
|
1511
|
+
Bundles.MainnetIds.SPARK_BOOST_ON_PRICE,
|
|
1512
|
+
true,
|
|
1513
|
+
['0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000006b175474e89094c44da98b954eedeac495271d0f00000000000000000000000000000000000000000000000000000417bce6c8000000000000000000000000000000000000000000000000000000000000000000'],
|
|
1514
|
+
[
|
|
1515
|
+
'0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
|
|
1516
|
+
'0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
1517
|
+
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
1518
|
+
'0x0000000000000000000000000000000000000000000000000000000000000004',
|
|
1519
|
+
'0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
|
|
1520
|
+
'0x00000000000000000000000000000000000000000000000022b1c8c1227a0000',
|
|
1521
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1522
|
+
]
|
|
1523
|
+
],
|
|
1524
|
+
[
|
|
1525
|
+
60,
|
|
1526
|
+
true,
|
|
1527
|
+
{
|
|
1528
|
+
baseTokenAddr: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
|
|
1529
|
+
quoteTokenAddr: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
1530
|
+
price: 45000,
|
|
1531
|
+
ratioState: RatioState.OVER,
|
|
1532
|
+
},
|
|
1533
|
+
{
|
|
1534
|
+
collAsset: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
|
|
1535
|
+
collAssetId: 2,
|
|
1536
|
+
debtAsset: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
1537
|
+
debtAssetId: 4,
|
|
1538
|
+
marketAddr: web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
|
|
1539
|
+
targetRatio: 250,
|
|
1540
|
+
},
|
|
1541
|
+
]
|
|
1542
|
+
]
|
|
1543
|
+
];
|
|
1544
|
+
examples.forEach(([expected, actual]) => {
|
|
1545
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1546
|
+
expect(sparkEncode.leverageManagementOnPrice(...actual)).to.eql(expected);
|
|
1547
|
+
});
|
|
1548
|
+
});
|
|
1549
|
+
});
|
|
1550
|
+
describe('closeOnPrice()', () => {
|
|
1551
|
+
const examples = [
|
|
1552
|
+
[
|
|
1553
|
+
[
|
|
1554
|
+
Bundles.MainnetIds.SPARK_CLOSE,
|
|
1555
|
+
true,
|
|
1556
|
+
['0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000000000000000000000000000000003a35294400000000000000000000000000000000000000000000000000000000574fbde6000'],
|
|
1557
|
+
[
|
|
1558
|
+
'0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
|
|
1559
|
+
'0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
1560
|
+
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
1561
|
+
'0x0000000000000000000000000000000000000000000000000000000000000004',
|
|
1562
|
+
'0x0000000000000000000000000000000000000000000000000000000000000005',
|
|
1563
|
+
'0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
|
|
1564
|
+
'0x0000000000000000000000001234567890123456789012345678901234567890',
|
|
1565
|
+
]
|
|
1566
|
+
],
|
|
1567
|
+
[
|
|
1568
|
+
57,
|
|
1569
|
+
web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
|
|
1570
|
+
2,
|
|
1571
|
+
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
1572
|
+
4,
|
|
1573
|
+
web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
|
|
1574
|
+
web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
|
|
1575
|
+
40000,
|
|
1576
|
+
CloseToAssetType.DEBT,
|
|
1577
|
+
60000,
|
|
1578
|
+
CloseToAssetType.COLLATERAL,
|
|
1579
|
+
]
|
|
1580
|
+
],
|
|
1581
|
+
];
|
|
1582
|
+
examples.forEach(([expected, actual]) => {
|
|
1583
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1584
|
+
expect(sparkEncode.closeOnPriceGeneric(...actual)).to.eql(expected);
|
|
1585
|
+
});
|
|
1586
|
+
});
|
|
1587
|
+
});
|
|
1588
|
+
});
|
|
1589
|
+
describe('When testing strategySubService.aaveV4Encode', () => {
|
|
1590
|
+
describe('leverageManagement()', () => {
|
|
1591
|
+
const examples = [
|
|
1592
|
+
[
|
|
1593
|
+
[1, true, ["0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000001"], ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x00000000000000000000000000000000000000000000000014d1120d7b160000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"]],
|
|
1594
|
+
[
|
|
1595
|
+
1,
|
|
1596
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1597
|
+
web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
|
|
1598
|
+
RatioState.UNDER,
|
|
1599
|
+
150,
|
|
1600
|
+
120,
|
|
1601
|
+
]
|
|
1602
|
+
]
|
|
1603
|
+
];
|
|
1604
|
+
examples.forEach(([expected, actual]) => {
|
|
1605
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1606
|
+
expect(aaveV4Encode.leverageManagement(...actual)).to.eql(expected);
|
|
1607
|
+
});
|
|
1608
|
+
});
|
|
1609
|
+
});
|
|
1610
|
+
describe('leverageManagementOnPrice()', () => {
|
|
1611
|
+
const examples = [
|
|
1612
|
+
[
|
|
1613
|
+
[2, true, ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000005150ae84a8cdf000000000000000000000000000000000000000000000000000000000000000000000"], ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x00000000000000000000000000000000000000000000000016345785d8a00000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"]],
|
|
1614
|
+
[
|
|
1615
|
+
2,
|
|
1616
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1617
|
+
web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
|
|
1618
|
+
web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
|
|
1619
|
+
10,
|
|
1620
|
+
web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
|
|
1621
|
+
20,
|
|
1622
|
+
160,
|
|
1623
|
+
'1500',
|
|
1624
|
+
RatioState.OVER,
|
|
1625
|
+
RatioState.OVER, // ratioState - UNDER for repay, OVER for boost
|
|
1626
|
+
]
|
|
1627
|
+
]
|
|
1628
|
+
];
|
|
1629
|
+
examples.forEach(([expected, actual]) => {
|
|
1630
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1631
|
+
expect(aaveV4Encode.leverageManagementOnPrice(...actual)).to.eql(expected);
|
|
1632
|
+
});
|
|
1633
|
+
});
|
|
1634
|
+
});
|
|
1635
|
+
describe('closeOnPrice()', () => {
|
|
1636
|
+
const examples = [
|
|
1637
|
+
[
|
|
1638
|
+
[3, true, ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000004be4e7267b6ae000000000000000000000000000000000000000000000000000000000000000000000"], ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000000000000000003", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"]],
|
|
1639
|
+
[
|
|
1640
|
+
3,
|
|
1641
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1642
|
+
web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
|
|
1643
|
+
web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
|
|
1644
|
+
10,
|
|
1645
|
+
web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
|
|
1646
|
+
20,
|
|
1647
|
+
'1400',
|
|
1648
|
+
CloseToAssetType.DEBT,
|
|
1649
|
+
'0',
|
|
1650
|
+
CloseToAssetType.COLLATERAL
|
|
1651
|
+
]
|
|
1652
|
+
]
|
|
1653
|
+
];
|
|
1654
|
+
examples.forEach(([expected, actual]) => {
|
|
1655
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1656
|
+
expect(aaveV4Encode.closeOnPrice(...actual)).to.eql(expected);
|
|
1657
|
+
});
|
|
1658
|
+
});
|
|
1659
|
+
});
|
|
1660
|
+
describe('collateralSwitch()', () => {
|
|
1661
|
+
const examples = [
|
|
1662
|
+
[
|
|
1663
|
+
[4, false, ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000005150ae84a8cdf000000000000000000000000000000000000000000000000000000000000000000001"], ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000de0b6b3a7640000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"]],
|
|
1664
|
+
[
|
|
1665
|
+
4,
|
|
1666
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1667
|
+
web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
|
|
1668
|
+
web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
|
|
1669
|
+
10,
|
|
1670
|
+
web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
|
|
1671
|
+
20,
|
|
1672
|
+
'1000000000000000000',
|
|
1673
|
+
'1500',
|
|
1674
|
+
RatioState.UNDER,
|
|
1675
|
+
]
|
|
1676
|
+
]
|
|
1677
|
+
];
|
|
1678
|
+
examples.forEach(([expected, actual]) => {
|
|
1679
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1680
|
+
expect(aaveV4Encode.collateralSwitch(...actual)).to.eql(expected);
|
|
1681
|
+
});
|
|
1682
|
+
});
|
|
1683
|
+
});
|
|
1684
|
+
});
|
|
1456
1685
|
});
|