@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.
- package/cjs/constants/index.js +100 -5
- package/cjs/index.d.ts +2 -1
- package/cjs/index.js +1 -1
- package/cjs/services/strategiesService.js +28 -27
- package/cjs/services/strategySubService.d.ts +3 -2
- package/cjs/services/strategySubService.js +15 -9
- package/cjs/services/strategySubService.test.js +314 -0
- package/cjs/services/subDataService.d.ts +25 -9
- package/cjs/services/subDataService.js +78 -26
- package/cjs/services/subDataService.test.js +456 -0
- package/cjs/services/triggerService.d.ts +6 -6
- package/cjs/services/triggerService.js +14 -11
- package/cjs/services/triggerService.test.js +46 -0
- package/cjs/types/enums.d.ts +26 -8
- package/cjs/types/enums.js +21 -2
- package/cjs/types/index.d.ts +1 -8
- package/esm/constants/index.js +100 -5
- package/esm/index.d.ts +2 -1
- package/esm/index.js +2 -2
- package/esm/services/strategiesService.js +28 -27
- package/esm/services/strategySubService.d.ts +3 -2
- package/esm/services/strategySubService.js +15 -9
- package/esm/services/strategySubService.test.js +314 -0
- package/esm/services/subDataService.d.ts +25 -9
- package/esm/services/subDataService.js +77 -25
- package/esm/services/subDataService.test.js +456 -0
- package/esm/services/triggerService.d.ts +6 -6
- package/esm/services/triggerService.js +13 -10
- package/esm/services/triggerService.test.js +47 -1
- package/esm/types/enums.d.ts +26 -8
- package/esm/types/enums.js +21 -2
- package/esm/types/index.d.ts +1 -8
- package/package.json +2 -2
- package/src/constants/index.ts +103 -5
- package/src/index.ts +4 -2
- package/src/services/strategiesService.ts +31 -37
- package/src/services/strategySubService.test.ts +347 -0
- package/src/services/strategySubService.ts +57 -20
- package/src/services/subDataService.test.ts +532 -0
- package/src/services/subDataService.ts +122 -33
- package/src/services/triggerService.test.ts +50 -0
- package/src/services/triggerService.ts +21 -14
- package/src/types/enums.ts +21 -2
- package/src/types/index.ts +20 -9
- package/umd/index.js +0 -34219
|
@@ -1543,4 +1543,536 @@ describe('Feature: subDataService.ts', () => {
|
|
|
1543
1543
|
});
|
|
1544
1544
|
});
|
|
1545
1545
|
});
|
|
1546
|
+
|
|
1547
|
+
describe("When testing subDataService.aaveV3LeverageManagementOnPriceGeneric", () => {
|
|
1548
|
+
describe("encode()", () => {
|
|
1549
|
+
const examples: Array<
|
|
1550
|
+
[
|
|
1551
|
+
string[],
|
|
1552
|
+
[
|
|
1553
|
+
collAsset: EthereumAddress,
|
|
1554
|
+
collAssetId: number,
|
|
1555
|
+
debtAsset: EthereumAddress,
|
|
1556
|
+
debtAssetId: number,
|
|
1557
|
+
marketAddr: EthereumAddress,
|
|
1558
|
+
targetRatio: number,
|
|
1559
|
+
user: EthereumAddress
|
|
1560
|
+
]
|
|
1561
|
+
]
|
|
1562
|
+
> = [
|
|
1563
|
+
[
|
|
1564
|
+
[
|
|
1565
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1566
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1567
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
1568
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1569
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
1570
|
+
'0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
|
|
1571
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1572
|
+
],
|
|
1573
|
+
[
|
|
1574
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1575
|
+
0,
|
|
1576
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1577
|
+
1,
|
|
1578
|
+
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
1579
|
+
200,
|
|
1580
|
+
web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1581
|
+
]
|
|
1582
|
+
],
|
|
1583
|
+
[
|
|
1584
|
+
[
|
|
1585
|
+
'0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
|
|
1586
|
+
'0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
1587
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
1588
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1589
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
1590
|
+
'0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
|
|
1591
|
+
'0x0000000000000000000000001234567890123456789012345678901234567890',
|
|
1592
|
+
],
|
|
1593
|
+
[
|
|
1594
|
+
web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
|
|
1595
|
+
2,
|
|
1596
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1597
|
+
1,
|
|
1598
|
+
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
1599
|
+
200,
|
|
1600
|
+
web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
|
|
1601
|
+
]
|
|
1602
|
+
],
|
|
1603
|
+
];
|
|
1604
|
+
|
|
1605
|
+
examples.forEach(([expected, actual]) => {
|
|
1606
|
+
it(`Given ${JSON.stringify(
|
|
1607
|
+
actual
|
|
1608
|
+
)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1609
|
+
expect(
|
|
1610
|
+
subDataService.aaveV3LeverageManagementOnPriceGeneric.encode(...actual)
|
|
1611
|
+
).to.eql(expected);
|
|
1612
|
+
});
|
|
1613
|
+
});
|
|
1614
|
+
});
|
|
1615
|
+
|
|
1616
|
+
describe("decode()", () => {
|
|
1617
|
+
const examples: Array<
|
|
1618
|
+
[
|
|
1619
|
+
{
|
|
1620
|
+
collAsset: EthereumAddress,
|
|
1621
|
+
collAssetId: number,
|
|
1622
|
+
debtAsset: EthereumAddress,
|
|
1623
|
+
debtAssetId: number,
|
|
1624
|
+
marketAddr: EthereumAddress,
|
|
1625
|
+
targetRatio: number,
|
|
1626
|
+
user: EthereumAddress,
|
|
1627
|
+
},
|
|
1628
|
+
string[]
|
|
1629
|
+
]
|
|
1630
|
+
> = [
|
|
1631
|
+
[
|
|
1632
|
+
{
|
|
1633
|
+
collAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1634
|
+
collAssetId: 0,
|
|
1635
|
+
debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1636
|
+
debtAssetId: 1,
|
|
1637
|
+
marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
1638
|
+
targetRatio: 200,
|
|
1639
|
+
user: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1640
|
+
},
|
|
1641
|
+
[
|
|
1642
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1643
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1644
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
1645
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1646
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
1647
|
+
'0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
|
|
1648
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1649
|
+
]
|
|
1650
|
+
],
|
|
1651
|
+
[
|
|
1652
|
+
{
|
|
1653
|
+
collAsset: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
|
|
1654
|
+
collAssetId: 2,
|
|
1655
|
+
debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1656
|
+
debtAssetId: 1,
|
|
1657
|
+
marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
1658
|
+
targetRatio: 200,
|
|
1659
|
+
user: web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
|
|
1660
|
+
},
|
|
1661
|
+
[
|
|
1662
|
+
'0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
|
|
1663
|
+
'0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
1664
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
1665
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1666
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
1667
|
+
'0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
|
|
1668
|
+
'0x0000000000000000000000001234567890123456789012345678901234567890',
|
|
1669
|
+
]
|
|
1670
|
+
],
|
|
1671
|
+
];
|
|
1672
|
+
|
|
1673
|
+
examples.forEach(([expected, actual]) => {
|
|
1674
|
+
it(`Given ${JSON.stringify(
|
|
1675
|
+
actual
|
|
1676
|
+
)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1677
|
+
expect(
|
|
1678
|
+
subDataService.aaveV3LeverageManagementOnPriceGeneric.decode(actual)
|
|
1679
|
+
).to.eql(expected);
|
|
1680
|
+
});
|
|
1681
|
+
});
|
|
1682
|
+
});
|
|
1683
|
+
});
|
|
1684
|
+
|
|
1685
|
+
describe("When testing subDataService.aaveV3CloseGenericSubData", () => {
|
|
1686
|
+
describe("encode()", () => {
|
|
1687
|
+
const examples: Array<
|
|
1688
|
+
[
|
|
1689
|
+
string[],
|
|
1690
|
+
[
|
|
1691
|
+
collAsset: EthereumAddress,
|
|
1692
|
+
collAssetId: number,
|
|
1693
|
+
debtAsset: EthereumAddress,
|
|
1694
|
+
debtAssetId: number,
|
|
1695
|
+
closeType: CloseStrategyType,
|
|
1696
|
+
marketAddr: EthereumAddress,
|
|
1697
|
+
user: EthereumAddress
|
|
1698
|
+
]
|
|
1699
|
+
]
|
|
1700
|
+
> = [
|
|
1701
|
+
// TAKE_PROFIT_IN_COLLATERAL
|
|
1702
|
+
[
|
|
1703
|
+
[
|
|
1704
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1705
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1706
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
1707
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1708
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1709
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
1710
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1711
|
+
],
|
|
1712
|
+
[
|
|
1713
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1714
|
+
0,
|
|
1715
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1716
|
+
1,
|
|
1717
|
+
CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL,
|
|
1718
|
+
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
1719
|
+
web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1720
|
+
]
|
|
1721
|
+
],
|
|
1722
|
+
// STOP_LOSS_IN_COLLATERAL
|
|
1723
|
+
[
|
|
1724
|
+
[
|
|
1725
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1726
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1727
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
1728
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1729
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1730
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
1731
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1732
|
+
],
|
|
1733
|
+
[
|
|
1734
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1735
|
+
0,
|
|
1736
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1737
|
+
1,
|
|
1738
|
+
CloseStrategyType.STOP_LOSS_IN_COLLATERAL,
|
|
1739
|
+
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
1740
|
+
web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1741
|
+
]
|
|
1742
|
+
],
|
|
1743
|
+
// TAKE_PROFIT_IN_DEBT
|
|
1744
|
+
[
|
|
1745
|
+
[
|
|
1746
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1747
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1748
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
1749
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1750
|
+
'0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
1751
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
1752
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1753
|
+
],
|
|
1754
|
+
[
|
|
1755
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1756
|
+
0,
|
|
1757
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1758
|
+
1,
|
|
1759
|
+
CloseStrategyType.TAKE_PROFIT_IN_DEBT,
|
|
1760
|
+
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
1761
|
+
web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1762
|
+
]
|
|
1763
|
+
],
|
|
1764
|
+
// STOP_LOSS_IN_DEBT
|
|
1765
|
+
[
|
|
1766
|
+
[
|
|
1767
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1768
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1769
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
1770
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1771
|
+
'0x0000000000000000000000000000000000000000000000000000000000000003',
|
|
1772
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
1773
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1774
|
+
],
|
|
1775
|
+
[
|
|
1776
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1777
|
+
0,
|
|
1778
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1779
|
+
1,
|
|
1780
|
+
CloseStrategyType.STOP_LOSS_IN_DEBT,
|
|
1781
|
+
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
1782
|
+
web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1783
|
+
]
|
|
1784
|
+
],
|
|
1785
|
+
// TAKE_PROFIT_AND_STOP_LOSS_IN_COLLATERAL
|
|
1786
|
+
[
|
|
1787
|
+
[
|
|
1788
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1789
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1790
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
1791
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1792
|
+
'0x0000000000000000000000000000000000000000000000000000000000000004',
|
|
1793
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
1794
|
+
'0x0000000000000000000000001234567890123456789012345678901234567890',
|
|
1795
|
+
],
|
|
1796
|
+
[
|
|
1797
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1798
|
+
0,
|
|
1799
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1800
|
+
1,
|
|
1801
|
+
CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_COLLATERAL,
|
|
1802
|
+
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
1803
|
+
web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
|
|
1804
|
+
]
|
|
1805
|
+
],
|
|
1806
|
+
// TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT
|
|
1807
|
+
[
|
|
1808
|
+
[
|
|
1809
|
+
'0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
|
|
1810
|
+
'0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
1811
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
1812
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1813
|
+
'0x0000000000000000000000000000000000000000000000000000000000000005',
|
|
1814
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
1815
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1816
|
+
],
|
|
1817
|
+
[
|
|
1818
|
+
web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
|
|
1819
|
+
2,
|
|
1820
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1821
|
+
1,
|
|
1822
|
+
CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT,
|
|
1823
|
+
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
1824
|
+
web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1825
|
+
]
|
|
1826
|
+
],
|
|
1827
|
+
// TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT
|
|
1828
|
+
[
|
|
1829
|
+
[
|
|
1830
|
+
'0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
|
|
1831
|
+
'0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
1832
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
1833
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1834
|
+
'0x0000000000000000000000000000000000000000000000000000000000000006',
|
|
1835
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
1836
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1837
|
+
],
|
|
1838
|
+
[
|
|
1839
|
+
web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
|
|
1840
|
+
2,
|
|
1841
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1842
|
+
1,
|
|
1843
|
+
CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT,
|
|
1844
|
+
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
1845
|
+
web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1846
|
+
]
|
|
1847
|
+
],
|
|
1848
|
+
// TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL
|
|
1849
|
+
[
|
|
1850
|
+
[
|
|
1851
|
+
'0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
|
|
1852
|
+
'0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
1853
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
1854
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1855
|
+
'0x0000000000000000000000000000000000000000000000000000000000000007',
|
|
1856
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
1857
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1858
|
+
],
|
|
1859
|
+
[
|
|
1860
|
+
web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
|
|
1861
|
+
2,
|
|
1862
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1863
|
+
1,
|
|
1864
|
+
CloseStrategyType.TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL,
|
|
1865
|
+
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
1866
|
+
web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1867
|
+
]
|
|
1868
|
+
],
|
|
1869
|
+
];
|
|
1870
|
+
|
|
1871
|
+
examples.forEach(([expected, actual]) => {
|
|
1872
|
+
it(`Given ${JSON.stringify(
|
|
1873
|
+
actual
|
|
1874
|
+
)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1875
|
+
expect(
|
|
1876
|
+
subDataService.aaveV3CloseGenericSubData.encode(...actual)
|
|
1877
|
+
).to.eql(expected);
|
|
1878
|
+
});
|
|
1879
|
+
});
|
|
1880
|
+
});
|
|
1881
|
+
|
|
1882
|
+
describe("decode()", () => {
|
|
1883
|
+
const examples: Array<
|
|
1884
|
+
[
|
|
1885
|
+
{
|
|
1886
|
+
collAsset: EthereumAddress,
|
|
1887
|
+
collAssetId: number,
|
|
1888
|
+
debtAsset: EthereumAddress,
|
|
1889
|
+
debtAssetId: number,
|
|
1890
|
+
closeType: CloseStrategyType,
|
|
1891
|
+
marketAddr: EthereumAddress,
|
|
1892
|
+
user: EthereumAddress,
|
|
1893
|
+
},
|
|
1894
|
+
string[]
|
|
1895
|
+
]
|
|
1896
|
+
> = [
|
|
1897
|
+
// TAKE_PROFIT_IN_COLLATERAL
|
|
1898
|
+
[
|
|
1899
|
+
{
|
|
1900
|
+
collAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1901
|
+
collAssetId: 0,
|
|
1902
|
+
debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1903
|
+
debtAssetId: 1,
|
|
1904
|
+
closeType: CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL,
|
|
1905
|
+
marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
1906
|
+
user: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1907
|
+
},
|
|
1908
|
+
[
|
|
1909
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1910
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1911
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
1912
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1913
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1914
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
1915
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1916
|
+
]
|
|
1917
|
+
],
|
|
1918
|
+
// STOP_LOSS_IN_COLLATERAL
|
|
1919
|
+
[
|
|
1920
|
+
{
|
|
1921
|
+
collAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1922
|
+
collAssetId: 0,
|
|
1923
|
+
debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1924
|
+
debtAssetId: 1,
|
|
1925
|
+
closeType: CloseStrategyType.STOP_LOSS_IN_COLLATERAL,
|
|
1926
|
+
marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
1927
|
+
user: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1928
|
+
},
|
|
1929
|
+
[
|
|
1930
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1931
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1932
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
1933
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1934
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1935
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
1936
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1937
|
+
]
|
|
1938
|
+
],
|
|
1939
|
+
// TAKE_PROFIT_IN_DEBT
|
|
1940
|
+
[
|
|
1941
|
+
{
|
|
1942
|
+
collAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1943
|
+
collAssetId: 0,
|
|
1944
|
+
debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1945
|
+
debtAssetId: 1,
|
|
1946
|
+
closeType: CloseStrategyType.TAKE_PROFIT_IN_DEBT,
|
|
1947
|
+
marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
1948
|
+
user: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1949
|
+
},
|
|
1950
|
+
[
|
|
1951
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1952
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1953
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
1954
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1955
|
+
'0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
1956
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
1957
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1958
|
+
]
|
|
1959
|
+
],
|
|
1960
|
+
// STOP_LOSS_IN_DEBT
|
|
1961
|
+
[
|
|
1962
|
+
{
|
|
1963
|
+
collAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1964
|
+
collAssetId: 0,
|
|
1965
|
+
debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1966
|
+
debtAssetId: 1,
|
|
1967
|
+
closeType: CloseStrategyType.STOP_LOSS_IN_DEBT,
|
|
1968
|
+
marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
1969
|
+
user: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1970
|
+
},
|
|
1971
|
+
[
|
|
1972
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1973
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1974
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
1975
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1976
|
+
'0x0000000000000000000000000000000000000000000000000000000000000003',
|
|
1977
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
1978
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1979
|
+
]
|
|
1980
|
+
],
|
|
1981
|
+
// TAKE_PROFIT_AND_STOP_LOSS_IN_COLLATERAL
|
|
1982
|
+
[
|
|
1983
|
+
{
|
|
1984
|
+
collAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1985
|
+
collAssetId: 0,
|
|
1986
|
+
debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1987
|
+
debtAssetId: 1,
|
|
1988
|
+
closeType: CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_COLLATERAL,
|
|
1989
|
+
marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
1990
|
+
user: web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
|
|
1991
|
+
},
|
|
1992
|
+
[
|
|
1993
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1994
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1995
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
1996
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1997
|
+
'0x0000000000000000000000000000000000000000000000000000000000000004',
|
|
1998
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
1999
|
+
'0x0000000000000000000000001234567890123456789012345678901234567890',
|
|
2000
|
+
]
|
|
2001
|
+
],
|
|
2002
|
+
// TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT
|
|
2003
|
+
[
|
|
2004
|
+
{
|
|
2005
|
+
collAsset: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
|
|
2006
|
+
collAssetId: 2,
|
|
2007
|
+
debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
2008
|
+
debtAssetId: 1,
|
|
2009
|
+
closeType: CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT,
|
|
2010
|
+
marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
2011
|
+
user: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
2012
|
+
},
|
|
2013
|
+
[
|
|
2014
|
+
'0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
|
|
2015
|
+
'0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
2016
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
2017
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
2018
|
+
'0x0000000000000000000000000000000000000000000000000000000000000005',
|
|
2019
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
2020
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
2021
|
+
]
|
|
2022
|
+
],
|
|
2023
|
+
// TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT
|
|
2024
|
+
[
|
|
2025
|
+
{
|
|
2026
|
+
collAsset: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
|
|
2027
|
+
collAssetId: 2,
|
|
2028
|
+
debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
2029
|
+
debtAssetId: 1,
|
|
2030
|
+
closeType: CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT,
|
|
2031
|
+
marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
2032
|
+
user: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
2033
|
+
},
|
|
2034
|
+
[
|
|
2035
|
+
'0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
|
|
2036
|
+
'0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
2037
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
2038
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
2039
|
+
'0x0000000000000000000000000000000000000000000000000000000000000006',
|
|
2040
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
2041
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
2042
|
+
]
|
|
2043
|
+
],
|
|
2044
|
+
// TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL
|
|
2045
|
+
[
|
|
2046
|
+
{
|
|
2047
|
+
collAsset: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
|
|
2048
|
+
collAssetId: 2,
|
|
2049
|
+
debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
2050
|
+
debtAssetId: 1,
|
|
2051
|
+
closeType: CloseStrategyType.TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL,
|
|
2052
|
+
marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
2053
|
+
user: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
2054
|
+
},
|
|
2055
|
+
[
|
|
2056
|
+
'0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
|
|
2057
|
+
'0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
2058
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
2059
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
2060
|
+
'0x0000000000000000000000000000000000000000000000000000000000000007',
|
|
2061
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
2062
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
2063
|
+
]
|
|
2064
|
+
],
|
|
2065
|
+
];
|
|
2066
|
+
|
|
2067
|
+
examples.forEach(([expected, actual]) => {
|
|
2068
|
+
it(`Given ${JSON.stringify(
|
|
2069
|
+
actual
|
|
2070
|
+
)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
2071
|
+
expect(
|
|
2072
|
+
subDataService.aaveV3CloseGenericSubData.decode(actual)
|
|
2073
|
+
).to.eql(expected);
|
|
2074
|
+
});
|
|
2075
|
+
});
|
|
2076
|
+
});
|
|
2077
|
+
});
|
|
1546
2078
|
});
|