@defisaver/automation-sdk 3.3.10 → 3.3.11-aave-v4-1-dev
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/automation/private/StrategiesAutomation.d.ts +2 -0
- package/cjs/automation/private/StrategiesAutomation.js +10 -1
- package/cjs/automation/private/StrategiesAutomation.test.js +25 -0
- package/cjs/constants/index.d.ts +1 -0
- package/cjs/constants/index.js +72 -1
- package/cjs/services/ethereumService.test.js +2 -0
- package/cjs/services/strategiesService.js +129 -0
- package/cjs/services/strategySubService.d.ts +19 -0
- package/cjs/services/strategySubService.js +37 -1
- package/cjs/services/strategySubService.test.js +229 -0
- package/cjs/services/subDataService.d.ts +298 -129
- package/cjs/services/subDataService.js +639 -369
- package/cjs/services/subDataService.test.js +214 -0
- package/cjs/services/triggerService.d.ts +38 -0
- package/cjs/services/triggerService.js +68 -1
- package/cjs/services/triggerService.test.js +130 -0
- package/cjs/services/utils.d.ts +1 -1
- package/cjs/services/utils.js +10 -2
- package/cjs/types/enums.d.ts +19 -3
- package/cjs/types/enums.js +16 -0
- package/cjs/types/index.d.ts +33 -1
- package/esm/automation/private/StrategiesAutomation.d.ts +2 -0
- package/esm/automation/private/StrategiesAutomation.js +10 -1
- package/esm/automation/private/StrategiesAutomation.test.js +25 -0
- package/esm/constants/index.d.ts +1 -0
- package/esm/constants/index.js +71 -0
- package/esm/services/ethereumService.test.js +2 -0
- package/esm/services/strategiesService.js +130 -1
- package/esm/services/strategySubService.d.ts +19 -0
- package/esm/services/strategySubService.js +36 -0
- package/esm/services/strategySubService.test.js +230 -1
- package/esm/services/subDataService.d.ts +298 -129
- package/esm/services/subDataService.js +639 -369
- package/esm/services/subDataService.test.js +214 -0
- package/esm/services/triggerService.d.ts +38 -0
- package/esm/services/triggerService.js +67 -0
- package/esm/services/triggerService.test.js +131 -1
- package/esm/services/utils.d.ts +1 -1
- package/esm/services/utils.js +10 -2
- package/esm/types/enums.d.ts +19 -3
- package/esm/types/enums.js +16 -0
- package/esm/types/index.d.ts +33 -1
- package/package.json +2 -2
- package/src/automation/private/StrategiesAutomation.test.ts +40 -0
- package/src/automation/private/StrategiesAutomation.ts +11 -0
- package/src/constants/index.ts +72 -0
- package/src/services/ethereumService.test.ts +2 -0
- package/src/services/strategiesService.ts +150 -2
- package/src/services/strategySubService.test.ts +286 -0
- package/src/services/strategySubService.ts +140 -0
- package/src/services/subDataService.test.ts +239 -0
- package/src/services/subDataService.ts +1072 -784
- package/src/services/triggerService.test.ts +148 -0
- package/src/services/triggerService.ts +97 -1
- package/src/services/utils.ts +15 -4
- package/src/types/enums.ts +16 -0
- package/src/types/index.ts +40 -1
|
@@ -21,6 +21,8 @@ import {
|
|
|
21
21
|
crvUSDEncode,
|
|
22
22
|
compoundV3L2Encode,
|
|
23
23
|
morphoBlueEncode,
|
|
24
|
+
sparkEncode,
|
|
25
|
+
aaveV4Encode,
|
|
24
26
|
} from './strategySubService';
|
|
25
27
|
|
|
26
28
|
describe('Feature: strategySubService.ts', () => {
|
|
@@ -1730,4 +1732,288 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1730
1732
|
});
|
|
1731
1733
|
});
|
|
1732
1734
|
});
|
|
1735
|
+
|
|
1736
|
+
describe('When testing strategySubService.sparkEncode', () => {
|
|
1737
|
+
describe('leverageManagement()', () => {
|
|
1738
|
+
const examples: Array<[string, [number, number, number, number, boolean]]> = [
|
|
1739
|
+
[
|
|
1740
|
+
'0x0000000000000000136dcc951d8c00000000000000000000214e8348c4f0000000000000000000001d24b2dfac52000000000000000000001a5e27eef13e000001',
|
|
1741
|
+
[140,240,210,190,true]
|
|
1742
|
+
],
|
|
1743
|
+
[
|
|
1744
|
+
'0x0000000000000000130337bdce49000000000000000000001988fe4052b800000000000000000000281b57b028e1000000000000000000002223acf76376000000',
|
|
1745
|
+
[137, 184, 289, 246, false]
|
|
1746
|
+
]
|
|
1747
|
+
];
|
|
1748
|
+
|
|
1749
|
+
examples.forEach(([expected, actual]) => {
|
|
1750
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1751
|
+
expect(sparkEncode.leverageManagement(...actual)).to.eql(expected);
|
|
1752
|
+
});
|
|
1753
|
+
});
|
|
1754
|
+
});
|
|
1755
|
+
|
|
1756
|
+
describe('leverageManagementOnPrice()', () => {
|
|
1757
|
+
const examples: Array<[[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
1758
|
+
[
|
|
1759
|
+
strategyOrBundleId: number,
|
|
1760
|
+
isBundle: boolean,
|
|
1761
|
+
triggerData: { baseTokenAddr: EthereumAddress, quoteTokenAddr: EthereumAddress, price: number, ratioState: RatioState },
|
|
1762
|
+
subData: { collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, marketAddr: EthereumAddress, targetRatio: number }
|
|
1763
|
+
]]> = [
|
|
1764
|
+
[
|
|
1765
|
+
[
|
|
1766
|
+
Bundles.MainnetIds.SPARK_REPAY_ON_PRICE,
|
|
1767
|
+
true,
|
|
1768
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000003a352944000000000000000000000000000000000000000000000000000000000000000001'],
|
|
1769
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1770
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1771
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
1772
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1773
|
+
'0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
|
|
1774
|
+
'0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
|
|
1775
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1776
|
+
],
|
|
1777
|
+
],
|
|
1778
|
+
[
|
|
1779
|
+
59,
|
|
1780
|
+
true,
|
|
1781
|
+
{
|
|
1782
|
+
baseTokenAddr: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1783
|
+
quoteTokenAddr: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1784
|
+
price: 2500,
|
|
1785
|
+
ratioState: RatioState.UNDER,
|
|
1786
|
+
},
|
|
1787
|
+
{
|
|
1788
|
+
collAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1789
|
+
collAssetId: 0,
|
|
1790
|
+
debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1791
|
+
debtAssetId: 1,
|
|
1792
|
+
marketAddr: web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
|
|
1793
|
+
targetRatio: 200,
|
|
1794
|
+
},
|
|
1795
|
+
]
|
|
1796
|
+
],
|
|
1797
|
+
[
|
|
1798
|
+
[
|
|
1799
|
+
Bundles.MainnetIds.SPARK_BOOST_ON_PRICE,
|
|
1800
|
+
true,
|
|
1801
|
+
['0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000006b175474e89094c44da98b954eedeac495271d0f00000000000000000000000000000000000000000000000000000417bce6c8000000000000000000000000000000000000000000000000000000000000000000'],
|
|
1802
|
+
[
|
|
1803
|
+
'0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
|
|
1804
|
+
'0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
1805
|
+
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
1806
|
+
'0x0000000000000000000000000000000000000000000000000000000000000004',
|
|
1807
|
+
'0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
|
|
1808
|
+
'0x00000000000000000000000000000000000000000000000022b1c8c1227a0000',
|
|
1809
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1810
|
+
]
|
|
1811
|
+
],
|
|
1812
|
+
[
|
|
1813
|
+
60,
|
|
1814
|
+
true,
|
|
1815
|
+
{
|
|
1816
|
+
baseTokenAddr: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
|
|
1817
|
+
quoteTokenAddr: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
1818
|
+
price: 45000,
|
|
1819
|
+
ratioState: RatioState.OVER,
|
|
1820
|
+
},
|
|
1821
|
+
{
|
|
1822
|
+
collAsset: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
|
|
1823
|
+
collAssetId: 2,
|
|
1824
|
+
debtAsset: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
1825
|
+
debtAssetId: 4,
|
|
1826
|
+
marketAddr: web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
|
|
1827
|
+
targetRatio: 250,
|
|
1828
|
+
},
|
|
1829
|
+
]
|
|
1830
|
+
]
|
|
1831
|
+
];
|
|
1832
|
+
|
|
1833
|
+
examples.forEach(([expected, actual]) => {
|
|
1834
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1835
|
+
expect(sparkEncode.leverageManagementOnPrice(...actual)).to.eql(expected);
|
|
1836
|
+
});
|
|
1837
|
+
});
|
|
1838
|
+
});
|
|
1839
|
+
|
|
1840
|
+
describe('closeOnPrice()', () => {
|
|
1841
|
+
const examples: Array<[
|
|
1842
|
+
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
1843
|
+
[
|
|
1844
|
+
strategyOrBundleId: number,
|
|
1845
|
+
collAsset: EthereumAddress,
|
|
1846
|
+
collAssetId: number,
|
|
1847
|
+
debtAsset: EthereumAddress,
|
|
1848
|
+
debtAssetId: number,
|
|
1849
|
+
marketAddr: EthereumAddress,
|
|
1850
|
+
user: EthereumAddress,
|
|
1851
|
+
stopLossPrice: number,
|
|
1852
|
+
stopLossType: CloseToAssetType,
|
|
1853
|
+
takeProfitPrice: number,
|
|
1854
|
+
takeProfitType: CloseToAssetType,
|
|
1855
|
+
]
|
|
1856
|
+
] > =
|
|
1857
|
+
[
|
|
1858
|
+
[
|
|
1859
|
+
[
|
|
1860
|
+
Bundles.MainnetIds.SPARK_CLOSE,
|
|
1861
|
+
true,
|
|
1862
|
+
['0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000000000000000000000000000000003a35294400000000000000000000000000000000000000000000000000000000574fbde6000'],
|
|
1863
|
+
[
|
|
1864
|
+
'0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
|
|
1865
|
+
'0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
1866
|
+
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
1867
|
+
'0x0000000000000000000000000000000000000000000000000000000000000004',
|
|
1868
|
+
'0x0000000000000000000000000000000000000000000000000000000000000005',
|
|
1869
|
+
'0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
|
|
1870
|
+
'0x0000000000000000000000001234567890123456789012345678901234567890',
|
|
1871
|
+
]
|
|
1872
|
+
],
|
|
1873
|
+
[
|
|
1874
|
+
57,
|
|
1875
|
+
web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
|
|
1876
|
+
2,
|
|
1877
|
+
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
1878
|
+
4,
|
|
1879
|
+
web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
|
|
1880
|
+
web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
|
|
1881
|
+
40000,
|
|
1882
|
+
CloseToAssetType.DEBT,
|
|
1883
|
+
60000,
|
|
1884
|
+
CloseToAssetType.COLLATERAL,
|
|
1885
|
+
]
|
|
1886
|
+
],
|
|
1887
|
+
]
|
|
1888
|
+
|
|
1889
|
+
examples.forEach(([expected, actual]) => {
|
|
1890
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1891
|
+
expect(sparkEncode.closeOnPriceGeneric(...actual)).to.eql(expected);
|
|
1892
|
+
});
|
|
1893
|
+
});
|
|
1894
|
+
});
|
|
1895
|
+
});
|
|
1896
|
+
describe('When testing strategySubService.aaveV4Encode', () => {
|
|
1897
|
+
describe('leverageManagement()', () => {
|
|
1898
|
+
const examples: Array<[
|
|
1899
|
+
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
1900
|
+
[
|
|
1901
|
+
strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number
|
|
1902
|
+
]
|
|
1903
|
+
]> = [
|
|
1904
|
+
[
|
|
1905
|
+
[1,true,["0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000001"],["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e","0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c","0x0000000000000000000000000000000000000000000000000000000000000001","0x00000000000000000000000000000000000000000000000014d1120d7b160000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000"]],
|
|
1906
|
+
[
|
|
1907
|
+
1,
|
|
1908
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1909
|
+
web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
|
|
1910
|
+
RatioState.UNDER,
|
|
1911
|
+
150,
|
|
1912
|
+
120,
|
|
1913
|
+
]
|
|
1914
|
+
]
|
|
1915
|
+
];
|
|
1916
|
+
|
|
1917
|
+
examples.forEach(([expected, actual]) => {
|
|
1918
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1919
|
+
expect(aaveV4Encode.leverageManagement(...actual)).to.eql(expected);
|
|
1920
|
+
});
|
|
1921
|
+
});
|
|
1922
|
+
});
|
|
1923
|
+
|
|
1924
|
+
describe('leverageManagementOnPrice()', () => {
|
|
1925
|
+
const examples: Array<[
|
|
1926
|
+
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
1927
|
+
[
|
|
1928
|
+
strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, targetRatio: number, price: string, priceState: RatioState, ratioState: RatioState
|
|
1929
|
+
]
|
|
1930
|
+
]> = [
|
|
1931
|
+
[
|
|
1932
|
+
[2,true,["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000005150ae84a8cdf000000000000000000000000000000000000000000000000000000000000000000000"],["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e","0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c","0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2","0x000000000000000000000000000000000000000000000000000000000000000a","0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48","0x0000000000000000000000000000000000000000000000000000000000000014","0x0000000000000000000000000000000000000000000000000000000000000000","0x00000000000000000000000000000000000000000000000016345785d8a00000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000"]],
|
|
1933
|
+
[
|
|
1934
|
+
2,
|
|
1935
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1936
|
+
web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
|
|
1937
|
+
web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
|
|
1938
|
+
10,
|
|
1939
|
+
web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
|
|
1940
|
+
20,
|
|
1941
|
+
160,
|
|
1942
|
+
'1500',
|
|
1943
|
+
RatioState.OVER, // priceState - goes to trigger
|
|
1944
|
+
RatioState.OVER, // ratioState - UNDER for repay, OVER for boost
|
|
1945
|
+
]
|
|
1946
|
+
]
|
|
1947
|
+
];
|
|
1948
|
+
|
|
1949
|
+
examples.forEach(([expected, actual]) => {
|
|
1950
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1951
|
+
expect(aaveV4Encode.leverageManagementOnPrice(...actual)).to.eql(expected);
|
|
1952
|
+
});
|
|
1953
|
+
});
|
|
1954
|
+
});
|
|
1955
|
+
|
|
1956
|
+
describe('closeOnPrice()', () => {
|
|
1957
|
+
const examples: Array<[
|
|
1958
|
+
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
1959
|
+
[
|
|
1960
|
+
strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, stopLossPrice: string, stopLossType: CloseToAssetType, takeProfitPrice: string, takeProfitType: CloseToAssetType
|
|
1961
|
+
]
|
|
1962
|
+
]> = [
|
|
1963
|
+
[
|
|
1964
|
+
[3,true,["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000004be4e7267b6ae000000000000000000000000000000000000000000000000000000000000000000000"],["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e","0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c","0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2","0x000000000000000000000000000000000000000000000000000000000000000a","0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48","0x0000000000000000000000000000000000000000000000000000000000000014","0x0000000000000000000000000000000000000000000000000000000000000003","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000"]],
|
|
1965
|
+
[
|
|
1966
|
+
3,
|
|
1967
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1968
|
+
web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
|
|
1969
|
+
web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
|
|
1970
|
+
10,
|
|
1971
|
+
web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
|
|
1972
|
+
20,
|
|
1973
|
+
'1400',
|
|
1974
|
+
CloseToAssetType.DEBT,
|
|
1975
|
+
'0',
|
|
1976
|
+
CloseToAssetType.COLLATERAL
|
|
1977
|
+
]
|
|
1978
|
+
]
|
|
1979
|
+
];
|
|
1980
|
+
|
|
1981
|
+
examples.forEach(([expected, actual]) => {
|
|
1982
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1983
|
+
expect(aaveV4Encode.closeOnPrice(...actual)).to.eql(expected);
|
|
1984
|
+
});
|
|
1985
|
+
});
|
|
1986
|
+
});
|
|
1987
|
+
|
|
1988
|
+
describe('collateralSwitch()', () => {
|
|
1989
|
+
const examples: Array<[
|
|
1990
|
+
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
1991
|
+
[
|
|
1992
|
+
strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, amountToSwitch: string, price: string, ratioState: RatioState
|
|
1993
|
+
]
|
|
1994
|
+
]> = [
|
|
1995
|
+
[
|
|
1996
|
+
[4,false,["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000005150ae84a8cdf000000000000000000000000000000000000000000000000000000000000000000001"],["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e","0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c","0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2","0x000000000000000000000000000000000000000000000000000000000000000a","0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48","0x0000000000000000000000000000000000000000000000000000000000000014","0x0000000000000000000000000000000000000000000000000de0b6b3a7640000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000"]],
|
|
1997
|
+
[
|
|
1998
|
+
4,
|
|
1999
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
2000
|
+
web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
|
|
2001
|
+
web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
|
|
2002
|
+
10,
|
|
2003
|
+
web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
|
|
2004
|
+
20,
|
|
2005
|
+
'1000000000000000000',
|
|
2006
|
+
'1500',
|
|
2007
|
+
RatioState.UNDER,
|
|
2008
|
+
]
|
|
2009
|
+
]
|
|
2010
|
+
];
|
|
2011
|
+
|
|
2012
|
+
examples.forEach(([expected, actual]) => {
|
|
2013
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
2014
|
+
expect(aaveV4Encode.collateralSwitch(...actual)).to.eql(expected);
|
|
2015
|
+
});
|
|
2016
|
+
});
|
|
2017
|
+
});
|
|
2018
|
+
});
|
|
1733
2019
|
});
|
|
@@ -581,6 +581,28 @@ export const sparkEncode = {
|
|
|
581
581
|
|
|
582
582
|
return subInput;
|
|
583
583
|
},
|
|
584
|
+
leverageManagementOnPrice(
|
|
585
|
+
strategyOrBundleId: number,
|
|
586
|
+
isBundle: boolean = true,
|
|
587
|
+
triggerData: {
|
|
588
|
+
baseTokenAddr: EthereumAddress, quoteTokenAddr: EthereumAddress, price: number, ratioState: RatioState
|
|
589
|
+
},
|
|
590
|
+
subData: {
|
|
591
|
+
collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, marketAddr: EthereumAddress, targetRatio: number,
|
|
592
|
+
},
|
|
593
|
+
) {
|
|
594
|
+
const {
|
|
595
|
+
collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio,
|
|
596
|
+
} = subData;
|
|
597
|
+
const subDataEncoded = subDataService.sparkLeverageManagementOnPriceSubData.encode(collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio);
|
|
598
|
+
|
|
599
|
+
const {
|
|
600
|
+
baseTokenAddr, quoteTokenAddr, price, ratioState,
|
|
601
|
+
} = triggerData;
|
|
602
|
+
const triggerDataEncoded = triggerService.sparkQuotePriceTrigger.encode(baseTokenAddr, quoteTokenAddr, price, ratioState);
|
|
603
|
+
|
|
604
|
+
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
605
|
+
},
|
|
584
606
|
closeOnPriceGeneric(
|
|
585
607
|
strategyOrBundleId: number,
|
|
586
608
|
collAsset: EthereumAddress,
|
|
@@ -824,3 +846,121 @@ export const fluidEncode = {
|
|
|
824
846
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
825
847
|
},
|
|
826
848
|
};
|
|
849
|
+
|
|
850
|
+
export const aaveV4Encode = {
|
|
851
|
+
leverageManagement(
|
|
852
|
+
strategyOrBundleId: number,
|
|
853
|
+
owner: EthereumAddress,
|
|
854
|
+
spoke: EthereumAddress,
|
|
855
|
+
ratioState: RatioState,
|
|
856
|
+
targetRatio: number,
|
|
857
|
+
triggerRatio: number,
|
|
858
|
+
) {
|
|
859
|
+
const isBundle = true;
|
|
860
|
+
const subData = subDataService.aaveV4LeverageManagementSubData.encode(spoke, owner, ratioState, targetRatio);
|
|
861
|
+
const triggerData = triggerService.aaveV4RatioTrigger.encode(owner, spoke, triggerRatio, ratioState);
|
|
862
|
+
|
|
863
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
864
|
+
},
|
|
865
|
+
leverageManagementOnPrice(
|
|
866
|
+
strategyOrBundleId: number,
|
|
867
|
+
owner: EthereumAddress,
|
|
868
|
+
spoke: EthereumAddress,
|
|
869
|
+
collAsset: EthereumAddress,
|
|
870
|
+
collAssetId: number,
|
|
871
|
+
debtAsset: EthereumAddress,
|
|
872
|
+
debtAssetId: number,
|
|
873
|
+
targetRatio: number,
|
|
874
|
+
price: string,
|
|
875
|
+
priceState: RatioState,
|
|
876
|
+
ratioState: RatioState, // UNDER for repay, OVER for boost
|
|
877
|
+
) {
|
|
878
|
+
const isBundle = true;
|
|
879
|
+
const subData = subDataService.aaveV4LeverageManagementOnPriceSubData.encode(
|
|
880
|
+
spoke,
|
|
881
|
+
owner,
|
|
882
|
+
collAsset,
|
|
883
|
+
collAssetId,
|
|
884
|
+
debtAsset,
|
|
885
|
+
debtAssetId,
|
|
886
|
+
ratioState,
|
|
887
|
+
targetRatio,
|
|
888
|
+
);
|
|
889
|
+
const triggerData = triggerService.aaveV4QuotePriceTrigger.encode(
|
|
890
|
+
spoke,
|
|
891
|
+
collAssetId,
|
|
892
|
+
debtAssetId,
|
|
893
|
+
price,
|
|
894
|
+
priceState,
|
|
895
|
+
);
|
|
896
|
+
|
|
897
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
898
|
+
},
|
|
899
|
+
closeOnPrice(
|
|
900
|
+
strategyOrBundleId: number,
|
|
901
|
+
owner: EthereumAddress,
|
|
902
|
+
spoke: EthereumAddress,
|
|
903
|
+
collAsset: EthereumAddress,
|
|
904
|
+
collAssetId: number,
|
|
905
|
+
debtAsset: EthereumAddress,
|
|
906
|
+
debtAssetId: number,
|
|
907
|
+
stopLossPrice: string = '0',
|
|
908
|
+
stopLossType: CloseToAssetType = CloseToAssetType.DEBT,
|
|
909
|
+
takeProfitPrice: string = '0',
|
|
910
|
+
takeProfitType: CloseToAssetType = CloseToAssetType.COLLATERAL,
|
|
911
|
+
) {
|
|
912
|
+
const isBundle = true;
|
|
913
|
+
const closeType = getCloseStrategyType(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
|
|
914
|
+
|
|
915
|
+
const subData = subDataService.aaveV4CloseSubData.encode(
|
|
916
|
+
spoke,
|
|
917
|
+
owner,
|
|
918
|
+
collAsset,
|
|
919
|
+
collAssetId,
|
|
920
|
+
debtAsset,
|
|
921
|
+
debtAssetId,
|
|
922
|
+
closeType,
|
|
923
|
+
);
|
|
924
|
+
const triggerData = triggerService.aaveV4QuotePriceRangeTrigger.encode(
|
|
925
|
+
spoke,
|
|
926
|
+
collAssetId,
|
|
927
|
+
debtAssetId,
|
|
928
|
+
stopLossPrice,
|
|
929
|
+
takeProfitPrice,
|
|
930
|
+
);
|
|
931
|
+
|
|
932
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
933
|
+
},
|
|
934
|
+
collateralSwitch(
|
|
935
|
+
strategyOrBundleId: number,
|
|
936
|
+
owner: EthereumAddress,
|
|
937
|
+
spoke: EthereumAddress,
|
|
938
|
+
fromAsset: EthereumAddress,
|
|
939
|
+
fromAssetId: number,
|
|
940
|
+
toAsset: EthereumAddress,
|
|
941
|
+
toAssetId: number,
|
|
942
|
+
amountToSwitch: string,
|
|
943
|
+
price: string,
|
|
944
|
+
ratioState: RatioState,
|
|
945
|
+
) {
|
|
946
|
+
const isBundle = false;
|
|
947
|
+
const subData = subDataService.aaveV4CollateralSwitchSubData.encode(
|
|
948
|
+
spoke,
|
|
949
|
+
owner,
|
|
950
|
+
fromAsset,
|
|
951
|
+
fromAssetId,
|
|
952
|
+
toAsset,
|
|
953
|
+
toAssetId,
|
|
954
|
+
amountToSwitch,
|
|
955
|
+
);
|
|
956
|
+
const triggerData = triggerService.aaveV4QuotePriceTrigger.encode(
|
|
957
|
+
spoke,
|
|
958
|
+
fromAssetId, // baseTokenId
|
|
959
|
+
toAssetId, // quoteTokenId
|
|
960
|
+
price,
|
|
961
|
+
ratioState,
|
|
962
|
+
);
|
|
963
|
+
|
|
964
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
965
|
+
},
|
|
966
|
+
};
|