@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
|
@@ -1481,4 +1481,233 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1481
1481
|
});
|
|
1482
1482
|
});
|
|
1483
1483
|
});
|
|
1484
|
+
describe('When testing strategySubService.sparkEncode', () => {
|
|
1485
|
+
describe('leverageManagement()', () => {
|
|
1486
|
+
const examples = [
|
|
1487
|
+
[
|
|
1488
|
+
'0x0000000000000000136dcc951d8c00000000000000000000214e8348c4f0000000000000000000001d24b2dfac52000000000000000000001a5e27eef13e000001',
|
|
1489
|
+
[140, 240, 210, 190, true]
|
|
1490
|
+
],
|
|
1491
|
+
[
|
|
1492
|
+
'0x0000000000000000130337bdce49000000000000000000001988fe4052b800000000000000000000281b57b028e1000000000000000000002223acf76376000000',
|
|
1493
|
+
[137, 184, 289, 246, false]
|
|
1494
|
+
]
|
|
1495
|
+
];
|
|
1496
|
+
examples.forEach(([expected, actual]) => {
|
|
1497
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1498
|
+
(0, chai_1.expect)(strategySubService_1.sparkEncode.leverageManagement(...actual)).to.eql(expected);
|
|
1499
|
+
});
|
|
1500
|
+
});
|
|
1501
|
+
});
|
|
1502
|
+
describe('leverageManagementOnPrice()', () => {
|
|
1503
|
+
const examples = [
|
|
1504
|
+
[
|
|
1505
|
+
[
|
|
1506
|
+
enums_1.Bundles.MainnetIds.SPARK_REPAY_ON_PRICE,
|
|
1507
|
+
true,
|
|
1508
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000003a352944000000000000000000000000000000000000000000000000000000000000000001'],
|
|
1509
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1510
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1511
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
1512
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1513
|
+
'0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
|
|
1514
|
+
'0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
|
|
1515
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1516
|
+
],
|
|
1517
|
+
],
|
|
1518
|
+
[
|
|
1519
|
+
59,
|
|
1520
|
+
true,
|
|
1521
|
+
{
|
|
1522
|
+
baseTokenAddr: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
|
|
1523
|
+
quoteTokenAddr: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
|
|
1524
|
+
price: 2500,
|
|
1525
|
+
ratioState: enums_1.RatioState.UNDER,
|
|
1526
|
+
},
|
|
1527
|
+
{
|
|
1528
|
+
collAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
|
|
1529
|
+
collAssetId: 0,
|
|
1530
|
+
debtAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
|
|
1531
|
+
debtAssetId: 1,
|
|
1532
|
+
marketAddr: web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
|
|
1533
|
+
targetRatio: 200,
|
|
1534
|
+
},
|
|
1535
|
+
]
|
|
1536
|
+
],
|
|
1537
|
+
[
|
|
1538
|
+
[
|
|
1539
|
+
enums_1.Bundles.MainnetIds.SPARK_BOOST_ON_PRICE,
|
|
1540
|
+
true,
|
|
1541
|
+
['0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000006b175474e89094c44da98b954eedeac495271d0f00000000000000000000000000000000000000000000000000000417bce6c8000000000000000000000000000000000000000000000000000000000000000000'],
|
|
1542
|
+
[
|
|
1543
|
+
'0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
|
|
1544
|
+
'0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
1545
|
+
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
1546
|
+
'0x0000000000000000000000000000000000000000000000000000000000000004',
|
|
1547
|
+
'0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
|
|
1548
|
+
'0x00000000000000000000000000000000000000000000000022b1c8c1227a0000',
|
|
1549
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1550
|
+
]
|
|
1551
|
+
],
|
|
1552
|
+
[
|
|
1553
|
+
60,
|
|
1554
|
+
true,
|
|
1555
|
+
{
|
|
1556
|
+
baseTokenAddr: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WBTC', enums_1.ChainId.Ethereum).address),
|
|
1557
|
+
quoteTokenAddr: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Ethereum).address),
|
|
1558
|
+
price: 45000,
|
|
1559
|
+
ratioState: enums_1.RatioState.OVER,
|
|
1560
|
+
},
|
|
1561
|
+
{
|
|
1562
|
+
collAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WBTC', enums_1.ChainId.Ethereum).address),
|
|
1563
|
+
collAssetId: 2,
|
|
1564
|
+
debtAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Ethereum).address),
|
|
1565
|
+
debtAssetId: 4,
|
|
1566
|
+
marketAddr: web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
|
|
1567
|
+
targetRatio: 250,
|
|
1568
|
+
},
|
|
1569
|
+
]
|
|
1570
|
+
]
|
|
1571
|
+
];
|
|
1572
|
+
examples.forEach(([expected, actual]) => {
|
|
1573
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1574
|
+
(0, chai_1.expect)(strategySubService_1.sparkEncode.leverageManagementOnPrice(...actual)).to.eql(expected);
|
|
1575
|
+
});
|
|
1576
|
+
});
|
|
1577
|
+
});
|
|
1578
|
+
describe('closeOnPrice()', () => {
|
|
1579
|
+
const examples = [
|
|
1580
|
+
[
|
|
1581
|
+
[
|
|
1582
|
+
enums_1.Bundles.MainnetIds.SPARK_CLOSE,
|
|
1583
|
+
true,
|
|
1584
|
+
['0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000000000000000000000000000000003a35294400000000000000000000000000000000000000000000000000000000574fbde6000'],
|
|
1585
|
+
[
|
|
1586
|
+
'0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
|
|
1587
|
+
'0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
1588
|
+
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
1589
|
+
'0x0000000000000000000000000000000000000000000000000000000000000004',
|
|
1590
|
+
'0x0000000000000000000000000000000000000000000000000000000000000005',
|
|
1591
|
+
'0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
|
|
1592
|
+
'0x0000000000000000000000001234567890123456789012345678901234567890',
|
|
1593
|
+
]
|
|
1594
|
+
],
|
|
1595
|
+
[
|
|
1596
|
+
57,
|
|
1597
|
+
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WBTC', enums_1.ChainId.Ethereum).address),
|
|
1598
|
+
2,
|
|
1599
|
+
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Ethereum).address),
|
|
1600
|
+
4,
|
|
1601
|
+
web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
|
|
1602
|
+
web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
|
|
1603
|
+
40000,
|
|
1604
|
+
enums_1.CloseToAssetType.DEBT,
|
|
1605
|
+
60000,
|
|
1606
|
+
enums_1.CloseToAssetType.COLLATERAL,
|
|
1607
|
+
]
|
|
1608
|
+
],
|
|
1609
|
+
];
|
|
1610
|
+
examples.forEach(([expected, actual]) => {
|
|
1611
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1612
|
+
(0, chai_1.expect)(strategySubService_1.sparkEncode.closeOnPriceGeneric(...actual)).to.eql(expected);
|
|
1613
|
+
});
|
|
1614
|
+
});
|
|
1615
|
+
});
|
|
1616
|
+
});
|
|
1617
|
+
describe('When testing strategySubService.aaveV4Encode', () => {
|
|
1618
|
+
describe('leverageManagement()', () => {
|
|
1619
|
+
const examples = [
|
|
1620
|
+
[
|
|
1621
|
+
[1, true, ["0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000001"], ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x00000000000000000000000000000000000000000000000014d1120d7b160000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"]],
|
|
1622
|
+
[
|
|
1623
|
+
1,
|
|
1624
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1625
|
+
web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
|
|
1626
|
+
enums_1.RatioState.UNDER,
|
|
1627
|
+
150,
|
|
1628
|
+
120,
|
|
1629
|
+
]
|
|
1630
|
+
]
|
|
1631
|
+
];
|
|
1632
|
+
examples.forEach(([expected, actual]) => {
|
|
1633
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1634
|
+
(0, chai_1.expect)(strategySubService_1.aaveV4Encode.leverageManagement(...actual)).to.eql(expected);
|
|
1635
|
+
});
|
|
1636
|
+
});
|
|
1637
|
+
});
|
|
1638
|
+
describe('leverageManagementOnPrice()', () => {
|
|
1639
|
+
const examples = [
|
|
1640
|
+
[
|
|
1641
|
+
[2, true, ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000005150ae84a8cdf000000000000000000000000000000000000000000000000000000000000000000000"], ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x00000000000000000000000000000000000000000000000016345785d8a00000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"]],
|
|
1642
|
+
[
|
|
1643
|
+
2,
|
|
1644
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1645
|
+
web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
|
|
1646
|
+
web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
|
|
1647
|
+
10,
|
|
1648
|
+
web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
|
|
1649
|
+
20,
|
|
1650
|
+
160,
|
|
1651
|
+
'1500',
|
|
1652
|
+
enums_1.RatioState.OVER,
|
|
1653
|
+
enums_1.RatioState.OVER, // ratioState - UNDER for repay, OVER for boost
|
|
1654
|
+
]
|
|
1655
|
+
]
|
|
1656
|
+
];
|
|
1657
|
+
examples.forEach(([expected, actual]) => {
|
|
1658
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1659
|
+
(0, chai_1.expect)(strategySubService_1.aaveV4Encode.leverageManagementOnPrice(...actual)).to.eql(expected);
|
|
1660
|
+
});
|
|
1661
|
+
});
|
|
1662
|
+
});
|
|
1663
|
+
describe('closeOnPrice()', () => {
|
|
1664
|
+
const examples = [
|
|
1665
|
+
[
|
|
1666
|
+
[3, true, ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000004be4e7267b6ae000000000000000000000000000000000000000000000000000000000000000000000"], ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000000000000000003", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"]],
|
|
1667
|
+
[
|
|
1668
|
+
3,
|
|
1669
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1670
|
+
web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
|
|
1671
|
+
web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
|
|
1672
|
+
10,
|
|
1673
|
+
web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
|
|
1674
|
+
20,
|
|
1675
|
+
'1400',
|
|
1676
|
+
enums_1.CloseToAssetType.DEBT,
|
|
1677
|
+
'0',
|
|
1678
|
+
enums_1.CloseToAssetType.COLLATERAL
|
|
1679
|
+
]
|
|
1680
|
+
]
|
|
1681
|
+
];
|
|
1682
|
+
examples.forEach(([expected, actual]) => {
|
|
1683
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1684
|
+
(0, chai_1.expect)(strategySubService_1.aaveV4Encode.closeOnPrice(...actual)).to.eql(expected);
|
|
1685
|
+
});
|
|
1686
|
+
});
|
|
1687
|
+
});
|
|
1688
|
+
describe('collateralSwitch()', () => {
|
|
1689
|
+
const examples = [
|
|
1690
|
+
[
|
|
1691
|
+
[4, false, ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000005150ae84a8cdf000000000000000000000000000000000000000000000000000000000000000000001"], ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000de0b6b3a7640000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"]],
|
|
1692
|
+
[
|
|
1693
|
+
4,
|
|
1694
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1695
|
+
web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
|
|
1696
|
+
web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
|
|
1697
|
+
10,
|
|
1698
|
+
web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
|
|
1699
|
+
20,
|
|
1700
|
+
'1000000000000000000',
|
|
1701
|
+
'1500',
|
|
1702
|
+
enums_1.RatioState.UNDER,
|
|
1703
|
+
]
|
|
1704
|
+
]
|
|
1705
|
+
];
|
|
1706
|
+
examples.forEach(([expected, actual]) => {
|
|
1707
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1708
|
+
(0, chai_1.expect)(strategySubService_1.aaveV4Encode.collateralSwitch(...actual)).to.eql(expected);
|
|
1709
|
+
});
|
|
1710
|
+
});
|
|
1711
|
+
});
|
|
1712
|
+
});
|
|
1484
1713
|
});
|