@defisaver/automation-sdk 3.3.2-dev → 3.3.2-dev.1

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.
Files changed (45) hide show
  1. package/cjs/constants/index.js +100 -5
  2. package/cjs/index.d.ts +2 -1
  3. package/cjs/index.js +1 -1
  4. package/cjs/services/strategiesService.js +28 -27
  5. package/cjs/services/strategySubService.d.ts +3 -2
  6. package/cjs/services/strategySubService.js +15 -9
  7. package/cjs/services/strategySubService.test.js +314 -0
  8. package/cjs/services/subDataService.d.ts +25 -9
  9. package/cjs/services/subDataService.js +78 -26
  10. package/cjs/services/subDataService.test.js +456 -0
  11. package/cjs/services/triggerService.d.ts +6 -6
  12. package/cjs/services/triggerService.js +14 -11
  13. package/cjs/services/triggerService.test.js +46 -0
  14. package/cjs/types/enums.d.ts +26 -8
  15. package/cjs/types/enums.js +21 -2
  16. package/cjs/types/index.d.ts +1 -8
  17. package/esm/constants/index.js +100 -5
  18. package/esm/index.d.ts +2 -1
  19. package/esm/index.js +2 -2
  20. package/esm/services/strategiesService.js +28 -27
  21. package/esm/services/strategySubService.d.ts +3 -2
  22. package/esm/services/strategySubService.js +15 -9
  23. package/esm/services/strategySubService.test.js +314 -0
  24. package/esm/services/subDataService.d.ts +25 -9
  25. package/esm/services/subDataService.js +77 -25
  26. package/esm/services/subDataService.test.js +456 -0
  27. package/esm/services/triggerService.d.ts +6 -6
  28. package/esm/services/triggerService.js +13 -10
  29. package/esm/services/triggerService.test.js +47 -1
  30. package/esm/types/enums.d.ts +26 -8
  31. package/esm/types/enums.js +21 -2
  32. package/esm/types/index.d.ts +1 -8
  33. package/package.json +2 -2
  34. package/src/constants/index.ts +103 -5
  35. package/src/index.ts +4 -2
  36. package/src/services/strategiesService.ts +31 -37
  37. package/src/services/strategySubService.test.ts +347 -0
  38. package/src/services/strategySubService.ts +57 -20
  39. package/src/services/subDataService.test.ts +532 -0
  40. package/src/services/subDataService.ts +122 -33
  41. package/src/services/triggerService.test.ts +50 -0
  42. package/src/services/triggerService.ts +21 -14
  43. package/src/types/enums.ts +21 -2
  44. package/src/types/index.ts +20 -9
  45. package/umd/index.js +0 -34219
@@ -1455,4 +1455,460 @@ describe('Feature: subDataService.ts', () => {
1455
1455
  });
1456
1456
  });
1457
1457
  });
1458
+ describe("When testing subDataService.aaveV3LeverageManagementOnPriceGeneric", () => {
1459
+ describe("encode()", () => {
1460
+ const examples = [
1461
+ [
1462
+ [
1463
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1464
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1465
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1466
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1467
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1468
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
1469
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1470
+ ],
1471
+ [
1472
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
1473
+ 0,
1474
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
1475
+ 1,
1476
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1477
+ 200,
1478
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1479
+ ]
1480
+ ],
1481
+ [
1482
+ [
1483
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
1484
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
1485
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1486
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1487
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1488
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
1489
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
1490
+ ],
1491
+ [
1492
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WBTC', enums_1.ChainId.Ethereum).address),
1493
+ 2,
1494
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
1495
+ 1,
1496
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1497
+ 200,
1498
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
1499
+ ]
1500
+ ],
1501
+ ];
1502
+ examples.forEach(([expected, actual]) => {
1503
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1504
+ (0, chai_1.expect)(subDataService.aaveV3LeverageManagementOnPriceGeneric.encode(...actual)).to.eql(expected);
1505
+ });
1506
+ });
1507
+ });
1508
+ describe("decode()", () => {
1509
+ const examples = [
1510
+ [
1511
+ {
1512
+ collAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
1513
+ collAssetId: 0,
1514
+ debtAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
1515
+ debtAssetId: 1,
1516
+ marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1517
+ targetRatio: 200,
1518
+ user: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1519
+ },
1520
+ [
1521
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1522
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1523
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1524
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1525
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1526
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
1527
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1528
+ ]
1529
+ ],
1530
+ [
1531
+ {
1532
+ collAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WBTC', enums_1.ChainId.Ethereum).address),
1533
+ collAssetId: 2,
1534
+ debtAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
1535
+ debtAssetId: 1,
1536
+ marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1537
+ targetRatio: 200,
1538
+ user: web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
1539
+ },
1540
+ [
1541
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
1542
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
1543
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1544
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1545
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1546
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
1547
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
1548
+ ]
1549
+ ],
1550
+ ];
1551
+ examples.forEach(([expected, actual]) => {
1552
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1553
+ (0, chai_1.expect)(subDataService.aaveV3LeverageManagementOnPriceGeneric.decode(actual)).to.eql(expected);
1554
+ });
1555
+ });
1556
+ });
1557
+ });
1558
+ describe("When testing subDataService.aaveV3CloseGenericSubData", () => {
1559
+ describe("encode()", () => {
1560
+ const examples = [
1561
+ // TAKE_PROFIT_IN_COLLATERAL
1562
+ [
1563
+ [
1564
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1565
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1566
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1567
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1568
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1569
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1570
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1571
+ ],
1572
+ [
1573
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
1574
+ 0,
1575
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
1576
+ 1,
1577
+ enums_1.CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL,
1578
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1579
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1580
+ ]
1581
+ ],
1582
+ // STOP_LOSS_IN_COLLATERAL
1583
+ [
1584
+ [
1585
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1586
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1587
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1588
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1589
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1590
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1591
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1592
+ ],
1593
+ [
1594
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
1595
+ 0,
1596
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
1597
+ 1,
1598
+ enums_1.CloseStrategyType.STOP_LOSS_IN_COLLATERAL,
1599
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1600
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1601
+ ]
1602
+ ],
1603
+ // TAKE_PROFIT_IN_DEBT
1604
+ [
1605
+ [
1606
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1607
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1608
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1609
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1610
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
1611
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1612
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1613
+ ],
1614
+ [
1615
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
1616
+ 0,
1617
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
1618
+ 1,
1619
+ enums_1.CloseStrategyType.TAKE_PROFIT_IN_DEBT,
1620
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1621
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1622
+ ]
1623
+ ],
1624
+ // STOP_LOSS_IN_DEBT
1625
+ [
1626
+ [
1627
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1628
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1629
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1630
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1631
+ '0x0000000000000000000000000000000000000000000000000000000000000003',
1632
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1633
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1634
+ ],
1635
+ [
1636
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
1637
+ 0,
1638
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
1639
+ 1,
1640
+ enums_1.CloseStrategyType.STOP_LOSS_IN_DEBT,
1641
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1642
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1643
+ ]
1644
+ ],
1645
+ // TAKE_PROFIT_AND_STOP_LOSS_IN_COLLATERAL
1646
+ [
1647
+ [
1648
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1649
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1650
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1651
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1652
+ '0x0000000000000000000000000000000000000000000000000000000000000004',
1653
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1654
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
1655
+ ],
1656
+ [
1657
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
1658
+ 0,
1659
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
1660
+ 1,
1661
+ enums_1.CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_COLLATERAL,
1662
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1663
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
1664
+ ]
1665
+ ],
1666
+ // TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT
1667
+ [
1668
+ [
1669
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
1670
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
1671
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1672
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1673
+ '0x0000000000000000000000000000000000000000000000000000000000000005',
1674
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1675
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1676
+ ],
1677
+ [
1678
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WBTC', enums_1.ChainId.Ethereum).address),
1679
+ 2,
1680
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
1681
+ 1,
1682
+ enums_1.CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT,
1683
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1684
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1685
+ ]
1686
+ ],
1687
+ // TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT
1688
+ [
1689
+ [
1690
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
1691
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
1692
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1693
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1694
+ '0x0000000000000000000000000000000000000000000000000000000000000006',
1695
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1696
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1697
+ ],
1698
+ [
1699
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WBTC', enums_1.ChainId.Ethereum).address),
1700
+ 2,
1701
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
1702
+ 1,
1703
+ enums_1.CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT,
1704
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1705
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1706
+ ]
1707
+ ],
1708
+ // TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL
1709
+ [
1710
+ [
1711
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
1712
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
1713
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1714
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1715
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
1716
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1717
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1718
+ ],
1719
+ [
1720
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WBTC', enums_1.ChainId.Ethereum).address),
1721
+ 2,
1722
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
1723
+ 1,
1724
+ enums_1.CloseStrategyType.TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL,
1725
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1726
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1727
+ ]
1728
+ ],
1729
+ ];
1730
+ examples.forEach(([expected, actual]) => {
1731
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1732
+ (0, chai_1.expect)(subDataService.aaveV3CloseGenericSubData.encode(...actual)).to.eql(expected);
1733
+ });
1734
+ });
1735
+ });
1736
+ describe("decode()", () => {
1737
+ const examples = [
1738
+ // TAKE_PROFIT_IN_COLLATERAL
1739
+ [
1740
+ {
1741
+ collAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
1742
+ collAssetId: 0,
1743
+ debtAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
1744
+ debtAssetId: 1,
1745
+ closeType: enums_1.CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL,
1746
+ marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1747
+ user: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1748
+ },
1749
+ [
1750
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1751
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1752
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1753
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1754
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1755
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1756
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1757
+ ]
1758
+ ],
1759
+ // STOP_LOSS_IN_COLLATERAL
1760
+ [
1761
+ {
1762
+ collAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
1763
+ collAssetId: 0,
1764
+ debtAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
1765
+ debtAssetId: 1,
1766
+ closeType: enums_1.CloseStrategyType.STOP_LOSS_IN_COLLATERAL,
1767
+ marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1768
+ user: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1769
+ },
1770
+ [
1771
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1772
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1773
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1774
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1775
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1776
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1777
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1778
+ ]
1779
+ ],
1780
+ // TAKE_PROFIT_IN_DEBT
1781
+ [
1782
+ {
1783
+ collAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
1784
+ collAssetId: 0,
1785
+ debtAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
1786
+ debtAssetId: 1,
1787
+ closeType: enums_1.CloseStrategyType.TAKE_PROFIT_IN_DEBT,
1788
+ marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1789
+ user: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1790
+ },
1791
+ [
1792
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1793
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1794
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1795
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1796
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
1797
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1798
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1799
+ ]
1800
+ ],
1801
+ // STOP_LOSS_IN_DEBT
1802
+ [
1803
+ {
1804
+ collAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
1805
+ collAssetId: 0,
1806
+ debtAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
1807
+ debtAssetId: 1,
1808
+ closeType: enums_1.CloseStrategyType.STOP_LOSS_IN_DEBT,
1809
+ marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1810
+ user: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1811
+ },
1812
+ [
1813
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1814
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1815
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1816
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1817
+ '0x0000000000000000000000000000000000000000000000000000000000000003',
1818
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1819
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1820
+ ]
1821
+ ],
1822
+ // TAKE_PROFIT_AND_STOP_LOSS_IN_COLLATERAL
1823
+ [
1824
+ {
1825
+ collAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
1826
+ collAssetId: 0,
1827
+ debtAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
1828
+ debtAssetId: 1,
1829
+ closeType: enums_1.CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_COLLATERAL,
1830
+ marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1831
+ user: web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
1832
+ },
1833
+ [
1834
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1835
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1836
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1837
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1838
+ '0x0000000000000000000000000000000000000000000000000000000000000004',
1839
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1840
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
1841
+ ]
1842
+ ],
1843
+ // TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT
1844
+ [
1845
+ {
1846
+ collAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WBTC', enums_1.ChainId.Ethereum).address),
1847
+ collAssetId: 2,
1848
+ debtAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
1849
+ debtAssetId: 1,
1850
+ closeType: enums_1.CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT,
1851
+ marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1852
+ user: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1853
+ },
1854
+ [
1855
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
1856
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
1857
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1858
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1859
+ '0x0000000000000000000000000000000000000000000000000000000000000005',
1860
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1861
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1862
+ ]
1863
+ ],
1864
+ // TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT
1865
+ [
1866
+ {
1867
+ collAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WBTC', enums_1.ChainId.Ethereum).address),
1868
+ collAssetId: 2,
1869
+ debtAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
1870
+ debtAssetId: 1,
1871
+ closeType: enums_1.CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT,
1872
+ marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1873
+ user: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1874
+ },
1875
+ [
1876
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
1877
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
1878
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1879
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1880
+ '0x0000000000000000000000000000000000000000000000000000000000000006',
1881
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1882
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1883
+ ]
1884
+ ],
1885
+ // TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL
1886
+ [
1887
+ {
1888
+ collAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WBTC', enums_1.ChainId.Ethereum).address),
1889
+ collAssetId: 2,
1890
+ debtAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
1891
+ debtAssetId: 1,
1892
+ closeType: enums_1.CloseStrategyType.TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL,
1893
+ marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1894
+ user: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1895
+ },
1896
+ [
1897
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
1898
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
1899
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1900
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1901
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
1902
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1903
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1904
+ ]
1905
+ ],
1906
+ ];
1907
+ examples.forEach(([expected, actual]) => {
1908
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1909
+ (0, chai_1.expect)(subDataService.aaveV3CloseGenericSubData.decode(actual)).to.eql(expected);
1910
+ });
1911
+ });
1912
+ });
1913
+ });
1458
1914
  });
@@ -266,12 +266,12 @@ export declare const compoundV3PriceRangeTrigger: {
266
266
  upperPrice: string;
267
267
  };
268
268
  };
269
- export declare const liquityV2InterestRateAdjustmentTrigger: {
270
- encode(market: EthereumAddress, troveId: string, criticalDebtInFrontLimit: string, nonCriticalDebtInFrontLimit: string): string[];
269
+ export declare const aaveV3QuotePriceRangeTrigger: {
270
+ encode(collToken: EthereumAddress, debtToken: EthereumAddress, lowerPrice: number, upperPrice: number): string[];
271
271
  decode(triggerData: string[]): {
272
- market: EthereumAddress;
273
- troveId: string;
274
- criticalDebtInFrontLimit: string;
275
- nonCriticalDebtInFrontLimit: string;
272
+ collToken: string;
273
+ debtToken: string;
274
+ lowerPrice: string;
275
+ upperPrice: string;
276
276
  };
277
277
  };
@@ -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.liquityV2InterestRateAdjustmentTrigger = exports.compoundV3PriceRangeTrigger = exports.compoundV3PriceTrigger = exports.fluidRatioTrigger = exports.morphoBluePriceTrigger = exports.closePriceTrigger = exports.liquityV2QuotePriceTrigger = exports.liquityV2RatioTrigger = exports.morphoBlueRatioTrigger = exports.crvUsdHealthRatioTrigger = exports.crvUSDRatioTrigger = exports.curveUsdSoftLiquidationTrigger = exports.curveUsdBorrowRateTrigger = exports.sparkQuotePriceTrigger = exports.sparkRatioTrigger = exports.exchangeOffchainPriceTrigger = exports.exchangeTimestampTrigger = exports.compoundV3RatioTrigger = exports.cBondsRebondTrigger = exports.aaveV2RatioTrigger = exports.liquityV2AdjustTimeTrigger = exports.liquityV2DebtInFrontTrigger = exports.liquityDebtInFrontWithLimitTrigger = exports.liquityDebtInFrontTrigger = exports.liquityRatioTrigger = exports.compoundV2RatioTrigger = exports.aaveV3QuotePriceWithMaximumGasPriceTrigger = exports.aaveV3QuotePriceTrigger = exports.morphoAaveV2RatioTrigger = exports.aaveV3RatioTrigger = exports.makerRatioTrigger = exports.trailingStopTrigger = exports.chainlinkPriceTrigger = void 0;
29
+ exports.aaveV3QuotePriceRangeTrigger = exports.compoundV3PriceRangeTrigger = exports.compoundV3PriceTrigger = exports.fluidRatioTrigger = exports.morphoBluePriceTrigger = exports.closePriceTrigger = exports.liquityV2QuotePriceTrigger = exports.liquityV2RatioTrigger = exports.morphoBlueRatioTrigger = exports.crvUsdHealthRatioTrigger = exports.crvUSDRatioTrigger = exports.curveUsdSoftLiquidationTrigger = exports.curveUsdBorrowRateTrigger = exports.sparkQuotePriceTrigger = exports.sparkRatioTrigger = exports.exchangeOffchainPriceTrigger = exports.exchangeTimestampTrigger = exports.compoundV3RatioTrigger = exports.cBondsRebondTrigger = exports.aaveV2RatioTrigger = exports.liquityV2AdjustTimeTrigger = exports.liquityV2DebtInFrontTrigger = 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"));
@@ -507,19 +507,22 @@ exports.compoundV3PriceRangeTrigger = {
507
507
  };
508
508
  },
509
509
  };
510
- exports.liquityV2InterestRateAdjustmentTrigger = {
511
- encode(market, troveId, criticalDebtInFrontLimit, nonCriticalDebtInFrontLimit) {
512
- const criticalDebtInFrontLimitWei = web3Utils.toWei(new decimal_js_1.default(criticalDebtInFrontLimit).toString(), 'ether');
513
- const nonCriticalDebtInFrontLimitWei = web3Utils.toWei(new decimal_js_1.default(nonCriticalDebtInFrontLimit).toString(), 'ether');
514
- return [web3_eth_abi_1.default.encodeParameters(['address', 'uint256', 'uint256', 'uint256'], [market, troveId, criticalDebtInFrontLimitWei, nonCriticalDebtInFrontLimitWei])];
510
+ exports.aaveV3QuotePriceRangeTrigger = {
511
+ encode(collToken, debtToken, lowerPrice, upperPrice) {
512
+ // Price is scaled to 1e8
513
+ const lowerPriceFormatted = new decimal_js_1.default(lowerPrice).mul(1e8).floor().toString();
514
+ const upperPriceFormatted = new decimal_js_1.default(upperPrice).mul(1e8).floor().toString();
515
+ return [
516
+ web3_eth_abi_1.default.encodeParameters(['address', 'address', 'uint256', 'uint256'], [collToken, debtToken, lowerPriceFormatted, upperPriceFormatted]),
517
+ ];
515
518
  },
516
519
  decode(triggerData) {
517
- const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'uint256', 'uint256', 'uint256'], triggerData[0]);
520
+ const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'address', 'uint256', 'uint256'], triggerData[0]);
518
521
  return {
519
- market: decodedData[0],
520
- troveId: decodedData[1],
521
- criticalDebtInFrontLimit: new decimal_js_1.default(decodedData[2]).div(Math.pow(10, 18)).toString(),
522
- nonCriticalDebtInFrontLimit: new decimal_js_1.default(decodedData[3]).div(Math.pow(10, 18)).toString(),
522
+ collToken: decodedData[0],
523
+ debtToken: decodedData[1],
524
+ lowerPrice: new decimal_js_1.default(decodedData[2]).div(1e8).toString(),
525
+ upperPrice: new decimal_js_1.default(decodedData[3]).div(1e8).toString(),
523
526
  };
524
527
  },
525
528
  };
@@ -1136,4 +1136,50 @@ describe('Feature: triggerService.ts', () => {
1136
1136
  });
1137
1137
  });
1138
1138
  });
1139
+ describe('When testing triggerService.aaveV3PriceRangeTrigger', () => {
1140
+ describe('encode()', () => {
1141
+ const examples = [
1142
+ [
1143
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
1144
+ [web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'), web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'), 1500, 4000]
1145
+ ],
1146
+ [
1147
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000746a528800'],
1148
+ [web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'), web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'), 0, 5000]
1149
+ ],
1150
+ ];
1151
+ examples.forEach(([expected, actual]) => {
1152
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
1153
+ (0, chai_1.expect)(triggerService_1.aaveV3QuotePriceRangeTrigger.encode(...actual)).to.eql(expected);
1154
+ });
1155
+ });
1156
+ });
1157
+ describe('decode()', () => {
1158
+ const examples = [
1159
+ [
1160
+ {
1161
+ collToken: web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
1162
+ debtToken: web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
1163
+ lowerPrice: '1500',
1164
+ upperPrice: '4000',
1165
+ },
1166
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
1167
+ ],
1168
+ [
1169
+ {
1170
+ collToken: web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
1171
+ debtToken: web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
1172
+ lowerPrice: '0',
1173
+ upperPrice: '5000',
1174
+ },
1175
+ ['000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000746a528800'],
1176
+ ],
1177
+ ];
1178
+ examples.forEach(([expected, actual]) => {
1179
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1180
+ (0, chai_1.expect)(triggerService_1.aaveV3QuotePriceRangeTrigger.decode(actual)).to.eql(expected);
1181
+ });
1182
+ });
1183
+ });
1184
+ });
1139
1185
  });