@defisaver/automation-sdk 3.3.1 → 3.3.2-dev.0

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 (42) hide show
  1. package/cjs/constants/index.js +100 -0
  2. package/cjs/index.d.ts +2 -1
  3. package/cjs/index.js +1 -1
  4. package/cjs/services/strategiesService.js +28 -9
  5. package/cjs/services/strategySubService.d.ts +3 -1
  6. package/cjs/services/strategySubService.js +15 -2
  7. package/cjs/services/strategySubService.test.js +314 -0
  8. package/cjs/services/subDataService.d.ts +25 -1
  9. package/cjs/services/subDataService.js +78 -2
  10. package/cjs/services/subDataService.test.js +456 -0
  11. package/cjs/services/triggerService.d.ts +9 -0
  12. package/cjs/services/triggerService.js +20 -1
  13. package/cjs/services/triggerService.test.js +46 -0
  14. package/cjs/types/enums.d.ts +24 -4
  15. package/cjs/types/enums.js +21 -0
  16. package/esm/constants/index.js +100 -0
  17. package/esm/index.d.ts +2 -1
  18. package/esm/index.js +2 -2
  19. package/esm/services/strategiesService.js +28 -9
  20. package/esm/services/strategySubService.d.ts +3 -1
  21. package/esm/services/strategySubService.js +15 -2
  22. package/esm/services/strategySubService.test.js +314 -0
  23. package/esm/services/subDataService.d.ts +25 -1
  24. package/esm/services/subDataService.js +77 -1
  25. package/esm/services/subDataService.test.js +456 -0
  26. package/esm/services/triggerService.d.ts +9 -0
  27. package/esm/services/triggerService.js +19 -0
  28. package/esm/services/triggerService.test.js +47 -1
  29. package/esm/types/enums.d.ts +24 -4
  30. package/esm/types/enums.js +21 -0
  31. package/package.json +1 -1
  32. package/src/constants/index.ts +103 -0
  33. package/src/index.ts +4 -2
  34. package/src/services/strategiesService.ts +31 -10
  35. package/src/services/strategySubService.test.ts +347 -0
  36. package/src/services/strategySubService.ts +57 -1
  37. package/src/services/subDataService.test.ts +532 -0
  38. package/src/services/subDataService.ts +122 -2
  39. package/src/services/triggerService.test.ts +50 -0
  40. package/src/services/triggerService.ts +29 -0
  41. package/src/types/enums.ts +21 -0
  42. package/src/types/index.ts +20 -0
@@ -1427,4 +1427,460 @@ describe('Feature: subDataService.ts', () => {
1427
1427
  });
1428
1428
  });
1429
1429
  });
1430
+ describe("When testing subDataService.aaveV3LeverageManagementOnPriceGeneric", () => {
1431
+ describe("encode()", () => {
1432
+ const examples = [
1433
+ [
1434
+ [
1435
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1436
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1437
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1438
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1439
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1440
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
1441
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1442
+ ],
1443
+ [
1444
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1445
+ 0,
1446
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1447
+ 1,
1448
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1449
+ 200,
1450
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1451
+ ]
1452
+ ],
1453
+ [
1454
+ [
1455
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
1456
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
1457
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1458
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1459
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1460
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
1461
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
1462
+ ],
1463
+ [
1464
+ web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
1465
+ 2,
1466
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1467
+ 1,
1468
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1469
+ 200,
1470
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
1471
+ ]
1472
+ ],
1473
+ ];
1474
+ examples.forEach(([expected, actual]) => {
1475
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1476
+ expect(subDataService.aaveV3LeverageManagementOnPriceGeneric.encode(...actual)).to.eql(expected);
1477
+ });
1478
+ });
1479
+ });
1480
+ describe("decode()", () => {
1481
+ const examples = [
1482
+ [
1483
+ {
1484
+ collAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1485
+ collAssetId: 0,
1486
+ debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1487
+ debtAssetId: 1,
1488
+ marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1489
+ targetRatio: 200,
1490
+ user: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1491
+ },
1492
+ [
1493
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1494
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1495
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1496
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1497
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1498
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
1499
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1500
+ ]
1501
+ ],
1502
+ [
1503
+ {
1504
+ collAsset: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
1505
+ collAssetId: 2,
1506
+ debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1507
+ debtAssetId: 1,
1508
+ marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1509
+ targetRatio: 200,
1510
+ user: web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
1511
+ },
1512
+ [
1513
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
1514
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
1515
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1516
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1517
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1518
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
1519
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
1520
+ ]
1521
+ ],
1522
+ ];
1523
+ examples.forEach(([expected, actual]) => {
1524
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1525
+ expect(subDataService.aaveV3LeverageManagementOnPriceGeneric.decode(actual)).to.eql(expected);
1526
+ });
1527
+ });
1528
+ });
1529
+ });
1530
+ describe("When testing subDataService.aaveV3CloseGenericSubData", () => {
1531
+ describe("encode()", () => {
1532
+ const examples = [
1533
+ // TAKE_PROFIT_IN_COLLATERAL
1534
+ [
1535
+ [
1536
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1537
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1538
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1539
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1540
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1541
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1542
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1543
+ ],
1544
+ [
1545
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1546
+ 0,
1547
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1548
+ 1,
1549
+ CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL,
1550
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1551
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1552
+ ]
1553
+ ],
1554
+ // STOP_LOSS_IN_COLLATERAL
1555
+ [
1556
+ [
1557
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1558
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1559
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1560
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1561
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1562
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1563
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1564
+ ],
1565
+ [
1566
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1567
+ 0,
1568
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1569
+ 1,
1570
+ CloseStrategyType.STOP_LOSS_IN_COLLATERAL,
1571
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1572
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1573
+ ]
1574
+ ],
1575
+ // TAKE_PROFIT_IN_DEBT
1576
+ [
1577
+ [
1578
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1579
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1580
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1581
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1582
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
1583
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1584
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1585
+ ],
1586
+ [
1587
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1588
+ 0,
1589
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1590
+ 1,
1591
+ CloseStrategyType.TAKE_PROFIT_IN_DEBT,
1592
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1593
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1594
+ ]
1595
+ ],
1596
+ // STOP_LOSS_IN_DEBT
1597
+ [
1598
+ [
1599
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1600
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1601
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1602
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1603
+ '0x0000000000000000000000000000000000000000000000000000000000000003',
1604
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1605
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1606
+ ],
1607
+ [
1608
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1609
+ 0,
1610
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1611
+ 1,
1612
+ CloseStrategyType.STOP_LOSS_IN_DEBT,
1613
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1614
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1615
+ ]
1616
+ ],
1617
+ // TAKE_PROFIT_AND_STOP_LOSS_IN_COLLATERAL
1618
+ [
1619
+ [
1620
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1621
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1622
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1623
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1624
+ '0x0000000000000000000000000000000000000000000000000000000000000004',
1625
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1626
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
1627
+ ],
1628
+ [
1629
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1630
+ 0,
1631
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1632
+ 1,
1633
+ CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_COLLATERAL,
1634
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1635
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
1636
+ ]
1637
+ ],
1638
+ // TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT
1639
+ [
1640
+ [
1641
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
1642
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
1643
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1644
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1645
+ '0x0000000000000000000000000000000000000000000000000000000000000005',
1646
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1647
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1648
+ ],
1649
+ [
1650
+ web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
1651
+ 2,
1652
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1653
+ 1,
1654
+ CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT,
1655
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1656
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1657
+ ]
1658
+ ],
1659
+ // TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT
1660
+ [
1661
+ [
1662
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
1663
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
1664
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1665
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1666
+ '0x0000000000000000000000000000000000000000000000000000000000000006',
1667
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1668
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1669
+ ],
1670
+ [
1671
+ web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
1672
+ 2,
1673
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1674
+ 1,
1675
+ CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT,
1676
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1677
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1678
+ ]
1679
+ ],
1680
+ // TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL
1681
+ [
1682
+ [
1683
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
1684
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
1685
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1686
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1687
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
1688
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1689
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1690
+ ],
1691
+ [
1692
+ web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
1693
+ 2,
1694
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1695
+ 1,
1696
+ CloseStrategyType.TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL,
1697
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1698
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1699
+ ]
1700
+ ],
1701
+ ];
1702
+ examples.forEach(([expected, actual]) => {
1703
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1704
+ expect(subDataService.aaveV3CloseGenericSubData.encode(...actual)).to.eql(expected);
1705
+ });
1706
+ });
1707
+ });
1708
+ describe("decode()", () => {
1709
+ const examples = [
1710
+ // TAKE_PROFIT_IN_COLLATERAL
1711
+ [
1712
+ {
1713
+ collAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1714
+ collAssetId: 0,
1715
+ debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1716
+ debtAssetId: 1,
1717
+ closeType: CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL,
1718
+ marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1719
+ user: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1720
+ },
1721
+ [
1722
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1723
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1724
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1725
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1726
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1727
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1728
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1729
+ ]
1730
+ ],
1731
+ // STOP_LOSS_IN_COLLATERAL
1732
+ [
1733
+ {
1734
+ collAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1735
+ collAssetId: 0,
1736
+ debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1737
+ debtAssetId: 1,
1738
+ closeType: CloseStrategyType.STOP_LOSS_IN_COLLATERAL,
1739
+ marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1740
+ user: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1741
+ },
1742
+ [
1743
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1744
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1745
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1746
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1747
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1748
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1749
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1750
+ ]
1751
+ ],
1752
+ // TAKE_PROFIT_IN_DEBT
1753
+ [
1754
+ {
1755
+ collAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1756
+ collAssetId: 0,
1757
+ debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1758
+ debtAssetId: 1,
1759
+ closeType: CloseStrategyType.TAKE_PROFIT_IN_DEBT,
1760
+ marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1761
+ user: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1762
+ },
1763
+ [
1764
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1765
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1766
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1767
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1768
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
1769
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1770
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1771
+ ]
1772
+ ],
1773
+ // STOP_LOSS_IN_DEBT
1774
+ [
1775
+ {
1776
+ collAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1777
+ collAssetId: 0,
1778
+ debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1779
+ debtAssetId: 1,
1780
+ closeType: CloseStrategyType.STOP_LOSS_IN_DEBT,
1781
+ marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1782
+ user: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1783
+ },
1784
+ [
1785
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1786
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1787
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1788
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1789
+ '0x0000000000000000000000000000000000000000000000000000000000000003',
1790
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1791
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1792
+ ]
1793
+ ],
1794
+ // TAKE_PROFIT_AND_STOP_LOSS_IN_COLLATERAL
1795
+ [
1796
+ {
1797
+ collAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1798
+ collAssetId: 0,
1799
+ debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1800
+ debtAssetId: 1,
1801
+ closeType: CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_COLLATERAL,
1802
+ marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1803
+ user: web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
1804
+ },
1805
+ [
1806
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1807
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1808
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1809
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1810
+ '0x0000000000000000000000000000000000000000000000000000000000000004',
1811
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1812
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
1813
+ ]
1814
+ ],
1815
+ // TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT
1816
+ [
1817
+ {
1818
+ collAsset: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
1819
+ collAssetId: 2,
1820
+ debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1821
+ debtAssetId: 1,
1822
+ closeType: CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT,
1823
+ marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1824
+ user: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1825
+ },
1826
+ [
1827
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
1828
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
1829
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1830
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1831
+ '0x0000000000000000000000000000000000000000000000000000000000000005',
1832
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1833
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1834
+ ]
1835
+ ],
1836
+ // TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT
1837
+ [
1838
+ {
1839
+ collAsset: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
1840
+ collAssetId: 2,
1841
+ debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1842
+ debtAssetId: 1,
1843
+ closeType: CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT,
1844
+ marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1845
+ user: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1846
+ },
1847
+ [
1848
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
1849
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
1850
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1851
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1852
+ '0x0000000000000000000000000000000000000000000000000000000000000006',
1853
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1854
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1855
+ ]
1856
+ ],
1857
+ // TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL
1858
+ [
1859
+ {
1860
+ collAsset: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
1861
+ collAssetId: 2,
1862
+ debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1863
+ debtAssetId: 1,
1864
+ closeType: CloseStrategyType.TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL,
1865
+ marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1866
+ user: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1867
+ },
1868
+ [
1869
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
1870
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
1871
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1872
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1873
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
1874
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1875
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1876
+ ]
1877
+ ],
1878
+ ];
1879
+ examples.forEach(([expected, actual]) => {
1880
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1881
+ expect(subDataService.aaveV3CloseGenericSubData.decode(actual)).to.eql(expected);
1882
+ });
1883
+ });
1884
+ });
1885
+ });
1430
1886
  });
@@ -266,3 +266,12 @@ export declare const compoundV3PriceRangeTrigger: {
266
266
  upperPrice: string;
267
267
  };
268
268
  };
269
+ export declare const aaveV3QuotePriceRangeTrigger: {
270
+ encode(collToken: EthereumAddress, debtToken: EthereumAddress, lowerPrice: number, upperPrice: number): string[];
271
+ decode(triggerData: string[]): {
272
+ collToken: string;
273
+ debtToken: string;
274
+ lowerPrice: string;
275
+ upperPrice: string;
276
+ };
277
+ };
@@ -478,3 +478,22 @@ export const compoundV3PriceRangeTrigger = {
478
478
  };
479
479
  },
480
480
  };
481
+ export const aaveV3QuotePriceRangeTrigger = {
482
+ encode(collToken, debtToken, lowerPrice, upperPrice) {
483
+ // Price is scaled to 1e8
484
+ const lowerPriceFormatted = new Dec(lowerPrice).mul(1e8).floor().toString();
485
+ const upperPriceFormatted = new Dec(upperPrice).mul(1e8).floor().toString();
486
+ return [
487
+ AbiCoder.encodeParameters(['address', 'address', 'uint256', 'uint256'], [collToken, debtToken, lowerPriceFormatted, upperPriceFormatted]),
488
+ ];
489
+ },
490
+ decode(triggerData) {
491
+ const decodedData = AbiCoder.decodeParameters(['address', 'address', 'uint256', 'uint256'], triggerData[0]);
492
+ return {
493
+ collToken: decodedData[0],
494
+ debtToken: decodedData[1],
495
+ lowerPrice: new Dec(decodedData[2]).div(1e8).toString(),
496
+ upperPrice: new Dec(decodedData[3]).div(1e8).toString(),
497
+ };
498
+ },
499
+ };
@@ -3,7 +3,7 @@ import { getAssetInfo, MAXUINT } from '@defisaver/tokens';
3
3
  import * as web3Utils from 'web3-utils';
4
4
  import { ChainId, OrderType, RatioState } from '../types/enums';
5
5
  import '../configuration';
6
- import { aaveV2RatioTrigger, aaveV3QuotePriceTrigger, aaveV3QuotePriceWithMaximumGasPriceTrigger, aaveV3RatioTrigger, cBondsRebondTrigger, chainlinkPriceTrigger, compoundV2RatioTrigger, compoundV3RatioTrigger, compoundV3PriceTrigger, curveUsdBorrowRateTrigger, curveUsdSoftLiquidationTrigger, exchangeOffchainPriceTrigger, exchangeTimestampTrigger, liquityDebtInFrontTrigger, makerRatioTrigger, morphoAaveV2RatioTrigger, sparkQuotePriceTrigger, sparkRatioTrigger, trailingStopTrigger, liquityDebtInFrontWithLimitTrigger, crvUSDRatioTrigger, morphoBlueRatioTrigger, crvUsdHealthRatioTrigger, liquityV2DebtInFrontTrigger, liquityV2AdjustTimeTrigger, compoundV3PriceRangeTrigger, } from './triggerService';
6
+ import { aaveV2RatioTrigger, aaveV3QuotePriceTrigger, aaveV3QuotePriceWithMaximumGasPriceTrigger, aaveV3RatioTrigger, cBondsRebondTrigger, chainlinkPriceTrigger, compoundV2RatioTrigger, compoundV3RatioTrigger, compoundV3PriceTrigger, curveUsdBorrowRateTrigger, curveUsdSoftLiquidationTrigger, exchangeOffchainPriceTrigger, exchangeTimestampTrigger, liquityDebtInFrontTrigger, makerRatioTrigger, morphoAaveV2RatioTrigger, sparkQuotePriceTrigger, sparkRatioTrigger, trailingStopTrigger, liquityDebtInFrontWithLimitTrigger, crvUSDRatioTrigger, morphoBlueRatioTrigger, crvUsdHealthRatioTrigger, liquityV2DebtInFrontTrigger, liquityV2AdjustTimeTrigger, compoundV3PriceRangeTrigger, aaveV3QuotePriceRangeTrigger, } from './triggerService';
7
7
  describe('Feature: triggerService.ts', () => {
8
8
  describe('When testing triggerService.chainlinkPriceTrigger', () => {
9
9
  describe('encode()', () => {
@@ -1111,4 +1111,50 @@ describe('Feature: triggerService.ts', () => {
1111
1111
  });
1112
1112
  });
1113
1113
  });
1114
+ describe('When testing triggerService.aaveV3PriceRangeTrigger', () => {
1115
+ describe('encode()', () => {
1116
+ const examples = [
1117
+ [
1118
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
1119
+ [web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'), web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'), 1500, 4000]
1120
+ ],
1121
+ [
1122
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000746a528800'],
1123
+ [web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'), web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'), 0, 5000]
1124
+ ],
1125
+ ];
1126
+ examples.forEach(([expected, actual]) => {
1127
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
1128
+ expect(aaveV3QuotePriceRangeTrigger.encode(...actual)).to.eql(expected);
1129
+ });
1130
+ });
1131
+ });
1132
+ describe('decode()', () => {
1133
+ const examples = [
1134
+ [
1135
+ {
1136
+ collToken: web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
1137
+ debtToken: web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
1138
+ lowerPrice: '1500',
1139
+ upperPrice: '4000',
1140
+ },
1141
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
1142
+ ],
1143
+ [
1144
+ {
1145
+ collToken: web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
1146
+ debtToken: web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
1147
+ lowerPrice: '0',
1148
+ upperPrice: '5000',
1149
+ },
1150
+ ['000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000746a528800'],
1151
+ ],
1152
+ ];
1153
+ examples.forEach(([expected, actual]) => {
1154
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1155
+ expect(aaveV3QuotePriceRangeTrigger.decode(actual)).to.eql(expected);
1156
+ });
1157
+ });
1158
+ });
1159
+ });
1114
1160
  });
@@ -197,7 +197,12 @@ export declare namespace Bundles {
197
197
  COMP_V3_SW_CLOSE = 48,
198
198
  COMP_V3_EOA_REPAY_ON_PRICE = 49,
199
199
  COMP_V3_EOA_BOOST_ON_PRICE = 50,
200
- COMP_V3_EOA_CLOSE = 51
200
+ COMP_V3_EOA_CLOSE = 51,
201
+ AAVE_V3_EOA_REPAY = 52,
202
+ AAVE_V3_EOA_BOOST = 53,
203
+ AAVE_V3_EOA_REPAY_ON_PRICE = 54,
204
+ AAVE_V3_EOA_BOOST_ON_PRICE = 55,
205
+ AAVE_V3_EOA_CLOSE = 56
201
206
  }
202
207
  enum OptimismIds {
203
208
  AAVE_V3_REPAY = 0,
@@ -205,7 +210,12 @@ export declare namespace Bundles {
205
210
  AAVE_V3_CLOSE_TO_DEBT = 2,
206
211
  AAVE_V3_CLOSE_TO_COLLATERAL = 3,
207
212
  AAVE_V3_OPEN_ORDER_FROM_COLLATERAL = 4,
208
- AAVE_V3_REPAY_ON_PRICE = 5
213
+ AAVE_V3_REPAY_ON_PRICE = 5,
214
+ AAVE_V3_EOA_REPAY = 6,
215
+ AAVE_V3_EOA_BOOST = 7,
216
+ AAVE_V3_EOA_REPAY_ON_PRICE = 8,
217
+ AAVE_V3_EOA_BOOST_ON_PRICE = 9,
218
+ AAVE_V3_EOA_CLOSE = 10
209
219
  }
210
220
  enum BaseIds {
211
221
  AAVE_V3_REPAY = 0,
@@ -228,7 +238,12 @@ export declare namespace Bundles {
228
238
  COMP_V3_EOA_BOOST_ON_PRICE = 19,
229
239
  COMP_V3_EOA_CLOSE = 20,
230
240
  COMP_V3_EOA_REPAY = 21,
231
- COMP_V3_EOA_BOOST = 22
241
+ COMP_V3_EOA_BOOST = 22,
242
+ AAVE_V3_EOA_REPAY = 23,
243
+ AAVE_V3_EOA_BOOST = 24,
244
+ AAVE_V3_EOA_REPAY_ON_PRICE = 25,
245
+ AAVE_V3_EOA_BOOST_ON_PRICE = 26,
246
+ AAVE_V3_EOA_CLOSE = 27
232
247
  }
233
248
  enum ArbitrumIds {
234
249
  AAVE_V3_REPAY = 0,
@@ -248,6 +263,11 @@ export declare namespace Bundles {
248
263
  COMP_V3_EOA_BOOST_ON_PRICE = 14,
249
264
  COMP_V3_EOA_CLOSE = 15,
250
265
  COMP_V3_EOA_REPAY = 16,
251
- COMP_V3_EOA_BOOST = 17
266
+ COMP_V3_EOA_BOOST = 17,
267
+ AAVE_V3_EOA_REPAY = 18,
268
+ AAVE_V3_EOA_BOOST = 19,
269
+ AAVE_V3_EOA_REPAY_ON_PRICE = 20,
270
+ AAVE_V3_EOA_BOOST_ON_PRICE = 21,
271
+ AAVE_V3_EOA_CLOSE = 22
252
272
  }
253
273
  }