@defisaver/automation-sdk 3.3.17 → 3.3.18-spark-eoa-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/constants/index.js +170 -0
- package/cjs/index.d.ts +2 -2
- package/cjs/index.js +5 -2
- package/cjs/services/ethereumService.test.js +4 -7
- package/cjs/services/strategiesService.js +195 -15
- package/cjs/services/strategySubService.d.ts +22 -17
- package/cjs/services/strategySubService.js +92 -28
- package/cjs/services/strategySubService.test.js +297 -40
- package/cjs/services/subDataService.d.ts +108 -20
- package/cjs/services/subDataService.js +97 -79
- package/cjs/services/subDataService.test.js +479 -174
- package/cjs/types/enums.d.ts +44 -6
- package/cjs/types/enums.js +38 -0
- package/esm/constants/index.js +170 -0
- package/esm/index.d.ts +2 -2
- package/esm/index.js +5 -2
- package/esm/services/ethereumService.test.js +4 -7
- package/esm/services/strategiesService.js +195 -15
- package/esm/services/strategySubService.d.ts +22 -17
- package/esm/services/strategySubService.js +91 -27
- package/esm/services/strategySubService.test.js +298 -38
- package/esm/services/subDataService.d.ts +108 -20
- package/esm/services/subDataService.js +95 -77
- package/esm/services/subDataService.test.js +480 -172
- package/esm/types/enums.d.ts +44 -6
- package/esm/types/enums.js +38 -0
- package/package.json +1 -1
- package/src/constants/index.ts +172 -1
- package/src/index.ts +22 -6
- package/src/services/ethereumService.test.ts +5 -8
- package/src/services/strategiesService.ts +262 -16
- package/src/services/strategySubService.test.ts +384 -46
- package/src/services/strategySubService.ts +251 -40
- package/src/services/subDataService.test.ts +639 -231
- package/src/services/subDataService.ts +149 -106
- package/src/services/utils.test.ts +1 -1
- package/src/services/utils.ts +3 -1
- package/src/types/enums.ts +38 -2
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { expect } from 'chai';
|
|
2
|
-
import Dec from 'decimal.js';
|
|
3
2
|
import { otherAddresses } from '@defisaver/sdk';
|
|
4
3
|
import { getAssetInfo, MAXUINT } from '@defisaver/tokens';
|
|
5
4
|
import * as web3Utils from 'web3-utils';
|
|
@@ -9,12 +8,10 @@ import type { EthereumAddress, StrategyOrBundleIds, SubData, TriggerData } from
|
|
|
9
8
|
|
|
10
9
|
import '../configuration';
|
|
11
10
|
import {
|
|
12
|
-
chickenBondsEncode,
|
|
13
11
|
liquityEncode,
|
|
14
12
|
makerEncode,
|
|
15
13
|
aaveV3Encode,
|
|
16
14
|
compoundV3Encode,
|
|
17
|
-
morphoAaveV2Encode,
|
|
18
15
|
exchangeEncode,
|
|
19
16
|
crvUSDEncode,
|
|
20
17
|
morphoBlueEncode,
|
|
@@ -137,7 +134,7 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
137
134
|
});
|
|
138
135
|
});
|
|
139
136
|
|
|
140
|
-
describe('
|
|
137
|
+
describe('leverageManagement()', () => {
|
|
141
138
|
const examples: Array<[
|
|
142
139
|
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
143
140
|
[
|
|
@@ -187,7 +184,7 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
187
184
|
|
|
188
185
|
examples.forEach(([expected, actual]) => {
|
|
189
186
|
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
190
|
-
expect(makerEncode.
|
|
187
|
+
expect(makerEncode.leverageManagement(...actual)).to.eql(expected);
|
|
191
188
|
});
|
|
192
189
|
});
|
|
193
190
|
});
|
|
@@ -348,26 +345,6 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
348
345
|
});
|
|
349
346
|
});
|
|
350
347
|
|
|
351
|
-
describe('When testing strategySubService.chickenBondsEncode', () => {
|
|
352
|
-
describe('rebond()', () => {
|
|
353
|
-
const examples: Array<[
|
|
354
|
-
SubData,
|
|
355
|
-
[bondId: number],
|
|
356
|
-
]> = [
|
|
357
|
-
[
|
|
358
|
-
['0x00000000000000000000000000000000000000000000000000000000000005e3'],
|
|
359
|
-
[1507]
|
|
360
|
-
]
|
|
361
|
-
];
|
|
362
|
-
|
|
363
|
-
examples.forEach(([expected, actual]) => {
|
|
364
|
-
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
365
|
-
expect(chickenBondsEncode.rebond(...actual)).to.eql(expected);
|
|
366
|
-
});
|
|
367
|
-
});
|
|
368
|
-
});
|
|
369
|
-
});
|
|
370
|
-
|
|
371
348
|
describe('When testing strategySubService.aaveV3Encode', () => {
|
|
372
349
|
describe('closeToAsset()', () => {
|
|
373
350
|
const examples: Array<[
|
|
@@ -1156,27 +1133,6 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1156
1133
|
});
|
|
1157
1134
|
});
|
|
1158
1135
|
|
|
1159
|
-
describe('When testing strategySubService.morphoAaveV2Encode', () => {
|
|
1160
|
-
describe('leverageManagement()', () => {
|
|
1161
|
-
const examples: Array<[[string, string, string, string, boolean], [triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean]]> = [
|
|
1162
|
-
[
|
|
1163
|
-
[new Dec(160).mul(1e16).toString(), new Dec(220).mul(1e16).toString(), new Dec(180).mul(1e16).toString(), new Dec(190).mul(1e16).toString(), true],
|
|
1164
|
-
[160, 220, 180, 190, true]
|
|
1165
|
-
],
|
|
1166
|
-
[
|
|
1167
|
-
[new Dec(160).mul(1e16).toString(), new Dec(200).mul(1e16).toString(), new Dec(180).mul(1e16).toString(), new Dec(190).mul(1e16).toString(), false],
|
|
1168
|
-
[160, 200, 180, 190, false]
|
|
1169
|
-
],
|
|
1170
|
-
];
|
|
1171
|
-
|
|
1172
|
-
examples.forEach(([expected, actual]) => {
|
|
1173
|
-
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1174
|
-
expect(morphoAaveV2Encode.leverageManagement(...actual)).to.eql(expected);
|
|
1175
|
-
});
|
|
1176
|
-
});
|
|
1177
|
-
});
|
|
1178
|
-
});
|
|
1179
|
-
|
|
1180
1136
|
describe('When testing strategySubService.exchangeEncode', () => {
|
|
1181
1137
|
describe('dca()', () => {
|
|
1182
1138
|
const examples: Array<[
|
|
@@ -1786,6 +1742,276 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1786
1742
|
});
|
|
1787
1743
|
});
|
|
1788
1744
|
|
|
1745
|
+
describe('leverageManagementGeneric()', () => {
|
|
1746
|
+
const examples: Array<[
|
|
1747
|
+
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
1748
|
+
[
|
|
1749
|
+
strategyOrBundleId: number,
|
|
1750
|
+
market: EthereumAddress,
|
|
1751
|
+
user: EthereumAddress,
|
|
1752
|
+
ratioState: RatioState,
|
|
1753
|
+
targetRatio: number,
|
|
1754
|
+
triggerRatio: number,
|
|
1755
|
+
]
|
|
1756
|
+
]> = [
|
|
1757
|
+
[
|
|
1758
|
+
[
|
|
1759
|
+
Bundles.MainnetIds.SPARK_EOA_REPAY,
|
|
1760
|
+
true,
|
|
1761
|
+
['0x000000000000000000000000123456789012345678901234567890123456789000000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee000000000000000000000000000000000000000000000000136dcc951d8c00000000000000000000000000000000000000000000000000000000000000000001'],
|
|
1762
|
+
[
|
|
1763
|
+
'0x00000000000000000000000000000000000000000000000018fae27693b40000',
|
|
1764
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1765
|
+
'0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
|
|
1766
|
+
'0x0000000000000000000000001234567890123456789012345678901234567890',
|
|
1767
|
+
],
|
|
1768
|
+
],
|
|
1769
|
+
[
|
|
1770
|
+
Bundles.MainnetIds.SPARK_EOA_REPAY,
|
|
1771
|
+
web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
|
|
1772
|
+
web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
|
|
1773
|
+
RatioState.UNDER,
|
|
1774
|
+
180,
|
|
1775
|
+
140,
|
|
1776
|
+
],
|
|
1777
|
+
],
|
|
1778
|
+
[
|
|
1779
|
+
[
|
|
1780
|
+
Bundles.MainnetIds.SPARK_EOA_BOOST,
|
|
1781
|
+
true,
|
|
1782
|
+
['0x000000000000000000000000123456789012345678901234567890123456789000000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee0000000000000000000000000000000000000000000000001bc16d674ec800000000000000000000000000000000000000000000000000000000000000000000'],
|
|
1783
|
+
[
|
|
1784
|
+
'0x00000000000000000000000000000000000000000000000016345785d8a00000',
|
|
1785
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1786
|
+
'0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
|
|
1787
|
+
'0x0000000000000000000000001234567890123456789012345678901234567890',
|
|
1788
|
+
],
|
|
1789
|
+
],
|
|
1790
|
+
[
|
|
1791
|
+
Bundles.MainnetIds.SPARK_EOA_BOOST,
|
|
1792
|
+
web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
|
|
1793
|
+
web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
|
|
1794
|
+
RatioState.OVER,
|
|
1795
|
+
160,
|
|
1796
|
+
200,
|
|
1797
|
+
],
|
|
1798
|
+
],
|
|
1799
|
+
];
|
|
1800
|
+
|
|
1801
|
+
examples.forEach(([expected, actual]) => {
|
|
1802
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1803
|
+
expect(sparkEncode.leverageManagementGeneric(...actual)).to.eql(expected);
|
|
1804
|
+
});
|
|
1805
|
+
});
|
|
1806
|
+
});
|
|
1807
|
+
|
|
1808
|
+
describe('liquidationProtection()', () => {
|
|
1809
|
+
const examples: Array<[
|
|
1810
|
+
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
1811
|
+
[
|
|
1812
|
+
strategyOrBundleId: number,
|
|
1813
|
+
market: EthereumAddress,
|
|
1814
|
+
user: EthereumAddress,
|
|
1815
|
+
ratioState: RatioState,
|
|
1816
|
+
targetRatio: number,
|
|
1817
|
+
triggerRatio: number,
|
|
1818
|
+
]
|
|
1819
|
+
]> = [
|
|
1820
|
+
[
|
|
1821
|
+
[
|
|
1822
|
+
Bundles.MainnetIds.SPARK_SW_LIQUIDATION_PROTECTION,
|
|
1823
|
+
true,
|
|
1824
|
+
['0x000000000000000000000000123456789012345678901234567890123456789000000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee000000000000000000000000000000000000000000000000136dcc951d8c00000000000000000000000000000000000000000000000000000000000000000001'],
|
|
1825
|
+
[
|
|
1826
|
+
'0x00000000000000000000000000000000000000000000000018fae27693b40000',
|
|
1827
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1828
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1829
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1830
|
+
],
|
|
1831
|
+
],
|
|
1832
|
+
[
|
|
1833
|
+
Bundles.MainnetIds.SPARK_SW_LIQUIDATION_PROTECTION,
|
|
1834
|
+
web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
|
|
1835
|
+
web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
|
|
1836
|
+
RatioState.UNDER,
|
|
1837
|
+
180,
|
|
1838
|
+
140,
|
|
1839
|
+
],
|
|
1840
|
+
],
|
|
1841
|
+
[
|
|
1842
|
+
[
|
|
1843
|
+
Bundles.MainnetIds.SPARK_SW_LIQUIDATION_PROTECTION,
|
|
1844
|
+
true,
|
|
1845
|
+
['0x000000000000000000000000123456789012345678901234567890123456789000000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee0000000000000000000000000000000000000000000000001bc16d674ec800000000000000000000000000000000000000000000000000000000000000000000'],
|
|
1846
|
+
[
|
|
1847
|
+
'0x00000000000000000000000000000000000000000000000016345785d8a00000',
|
|
1848
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1849
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1850
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1851
|
+
],
|
|
1852
|
+
],
|
|
1853
|
+
[
|
|
1854
|
+
Bundles.MainnetIds.SPARK_SW_LIQUIDATION_PROTECTION,
|
|
1855
|
+
web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
|
|
1856
|
+
web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
|
|
1857
|
+
RatioState.OVER,
|
|
1858
|
+
160,
|
|
1859
|
+
200,
|
|
1860
|
+
],
|
|
1861
|
+
],
|
|
1862
|
+
];
|
|
1863
|
+
|
|
1864
|
+
examples.forEach(([expected, actual]) => {
|
|
1865
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1866
|
+
expect(sparkEncode.liquidationProtection(...actual)).to.eql(expected);
|
|
1867
|
+
});
|
|
1868
|
+
});
|
|
1869
|
+
});
|
|
1870
|
+
|
|
1871
|
+
describe('liquidationProtectionGeneric()', () => {
|
|
1872
|
+
const examples: Array<[
|
|
1873
|
+
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
1874
|
+
[
|
|
1875
|
+
strategyOrBundleId: number,
|
|
1876
|
+
market: EthereumAddress,
|
|
1877
|
+
user: EthereumAddress,
|
|
1878
|
+
ratioState: RatioState,
|
|
1879
|
+
targetRatio: number,
|
|
1880
|
+
triggerRatio: number,
|
|
1881
|
+
]
|
|
1882
|
+
]> = [
|
|
1883
|
+
[
|
|
1884
|
+
[
|
|
1885
|
+
Bundles.MainnetIds.SPARK_EOA_LIQUIDATION_PROTECTION,
|
|
1886
|
+
true,
|
|
1887
|
+
['0x000000000000000000000000123456789012345678901234567890123456789000000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee000000000000000000000000000000000000000000000000136dcc951d8c00000000000000000000000000000000000000000000000000000000000000000001'],
|
|
1888
|
+
[
|
|
1889
|
+
'0x00000000000000000000000000000000000000000000000018fae27693b40000',
|
|
1890
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1891
|
+
'0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
|
|
1892
|
+
'0x0000000000000000000000001234567890123456789012345678901234567890',
|
|
1893
|
+
],
|
|
1894
|
+
],
|
|
1895
|
+
[
|
|
1896
|
+
Bundles.MainnetIds.SPARK_EOA_LIQUIDATION_PROTECTION,
|
|
1897
|
+
web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
|
|
1898
|
+
web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
|
|
1899
|
+
RatioState.UNDER,
|
|
1900
|
+
180,
|
|
1901
|
+
140,
|
|
1902
|
+
],
|
|
1903
|
+
],
|
|
1904
|
+
[
|
|
1905
|
+
[
|
|
1906
|
+
Bundles.MainnetIds.SPARK_EOA_LIQUIDATION_PROTECTION,
|
|
1907
|
+
true,
|
|
1908
|
+
['0x000000000000000000000000123456789012345678901234567890123456789000000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee0000000000000000000000000000000000000000000000001bc16d674ec800000000000000000000000000000000000000000000000000000000000000000000'],
|
|
1909
|
+
[
|
|
1910
|
+
'0x00000000000000000000000000000000000000000000000016345785d8a00000',
|
|
1911
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1912
|
+
'0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
|
|
1913
|
+
'0x0000000000000000000000001234567890123456789012345678901234567890',
|
|
1914
|
+
],
|
|
1915
|
+
],
|
|
1916
|
+
[
|
|
1917
|
+
Bundles.MainnetIds.SPARK_EOA_LIQUIDATION_PROTECTION,
|
|
1918
|
+
web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
|
|
1919
|
+
web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
|
|
1920
|
+
RatioState.OVER,
|
|
1921
|
+
160,
|
|
1922
|
+
200,
|
|
1923
|
+
],
|
|
1924
|
+
],
|
|
1925
|
+
];
|
|
1926
|
+
|
|
1927
|
+
examples.forEach(([expected, actual]) => {
|
|
1928
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1929
|
+
expect(sparkEncode.liquidationProtectionGeneric(...actual)).to.eql(expected);
|
|
1930
|
+
});
|
|
1931
|
+
});
|
|
1932
|
+
});
|
|
1933
|
+
|
|
1934
|
+
describe('leverageManagementOnPriceGeneric()', () => {
|
|
1935
|
+
const examples: Array<[
|
|
1936
|
+
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
1937
|
+
[
|
|
1938
|
+
strategyOrBundleId: number,
|
|
1939
|
+
price: number,
|
|
1940
|
+
ratioState: RatioState,
|
|
1941
|
+
collAsset: EthereumAddress,
|
|
1942
|
+
collAssetId: number,
|
|
1943
|
+
debtAsset: EthereumAddress,
|
|
1944
|
+
debtAssetId: number,
|
|
1945
|
+
marketAddr: EthereumAddress,
|
|
1946
|
+
targetRatio: number,
|
|
1947
|
+
user: EthereumAddress,
|
|
1948
|
+
]
|
|
1949
|
+
]> = [
|
|
1950
|
+
[
|
|
1951
|
+
[
|
|
1952
|
+
Bundles.MainnetIds.SPARK_EOA_REPAY_ON_PRICE,
|
|
1953
|
+
true,
|
|
1954
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000003a352944000000000000000000000000000000000000000000000000000000000000000001'],
|
|
1955
|
+
[
|
|
1956
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1957
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1958
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
1959
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1960
|
+
'0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
|
|
1961
|
+
'0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
|
|
1962
|
+
'0x0000000000000000000000001234567890123456789012345678901234567890',
|
|
1963
|
+
],
|
|
1964
|
+
],
|
|
1965
|
+
[
|
|
1966
|
+
Bundles.MainnetIds.SPARK_EOA_REPAY_ON_PRICE,
|
|
1967
|
+
2500,
|
|
1968
|
+
RatioState.UNDER,
|
|
1969
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1970
|
+
0,
|
|
1971
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1972
|
+
1,
|
|
1973
|
+
web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
|
|
1974
|
+
200,
|
|
1975
|
+
web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
|
|
1976
|
+
],
|
|
1977
|
+
],
|
|
1978
|
+
[
|
|
1979
|
+
[
|
|
1980
|
+
Bundles.MainnetIds.SPARK_EOA_BOOST_ON_PRICE,
|
|
1981
|
+
true,
|
|
1982
|
+
['0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000006b175474e89094c44da98b954eedeac495271d0f00000000000000000000000000000000000000000000000000000417bce6c8000000000000000000000000000000000000000000000000000000000000000000'],
|
|
1983
|
+
[
|
|
1984
|
+
'0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
|
|
1985
|
+
'0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
1986
|
+
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
1987
|
+
'0x0000000000000000000000000000000000000000000000000000000000000004',
|
|
1988
|
+
'0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
|
|
1989
|
+
'0x00000000000000000000000000000000000000000000000022b1c8c1227a0000',
|
|
1990
|
+
'0x0000000000000000000000001234567890123456789012345678901234567890',
|
|
1991
|
+
],
|
|
1992
|
+
],
|
|
1993
|
+
[
|
|
1994
|
+
Bundles.MainnetIds.SPARK_EOA_BOOST_ON_PRICE,
|
|
1995
|
+
45000,
|
|
1996
|
+
RatioState.OVER,
|
|
1997
|
+
web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
|
|
1998
|
+
2,
|
|
1999
|
+
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
2000
|
+
4,
|
|
2001
|
+
web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
|
|
2002
|
+
250,
|
|
2003
|
+
web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
|
|
2004
|
+
],
|
|
2005
|
+
],
|
|
2006
|
+
];
|
|
2007
|
+
|
|
2008
|
+
examples.forEach(([expected, actual]) => {
|
|
2009
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
2010
|
+
expect(sparkEncode.leverageManagementOnPriceGeneric(...actual)).to.eql(expected);
|
|
2011
|
+
});
|
|
2012
|
+
});
|
|
2013
|
+
});
|
|
2014
|
+
|
|
1789
2015
|
describe('closeOnPrice()', () => {
|
|
1790
2016
|
const examples: Array<[
|
|
1791
2017
|
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
@@ -1842,6 +2068,61 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1842
2068
|
});
|
|
1843
2069
|
});
|
|
1844
2070
|
|
|
2071
|
+
describe('closeOnPriceGeneric()', () => {
|
|
2072
|
+
const examples: Array<[
|
|
2073
|
+
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
2074
|
+
[
|
|
2075
|
+
strategyOrBundleId: number,
|
|
2076
|
+
collAsset: EthereumAddress,
|
|
2077
|
+
collAssetId: number,
|
|
2078
|
+
debtAsset: EthereumAddress,
|
|
2079
|
+
debtAssetId: number,
|
|
2080
|
+
marketAddr: EthereumAddress,
|
|
2081
|
+
user: EthereumAddress,
|
|
2082
|
+
stopLossPrice: number,
|
|
2083
|
+
stopLossType: CloseToAssetType,
|
|
2084
|
+
takeProfitPrice: number,
|
|
2085
|
+
takeProfitType: CloseToAssetType,
|
|
2086
|
+
]
|
|
2087
|
+
]> = [
|
|
2088
|
+
[
|
|
2089
|
+
[
|
|
2090
|
+
Bundles.MainnetIds.SPARK_EOA_CLOSE,
|
|
2091
|
+
true,
|
|
2092
|
+
['0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000000000000000000000000000000003a35294400000000000000000000000000000000000000000000000000000000574fbde6000'],
|
|
2093
|
+
[
|
|
2094
|
+
'0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
|
|
2095
|
+
'0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
2096
|
+
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
2097
|
+
'0x0000000000000000000000000000000000000000000000000000000000000004',
|
|
2098
|
+
'0x0000000000000000000000000000000000000000000000000000000000000005',
|
|
2099
|
+
'0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
|
|
2100
|
+
'0x0000000000000000000000001234567890123456789012345678901234567890',
|
|
2101
|
+
],
|
|
2102
|
+
],
|
|
2103
|
+
[
|
|
2104
|
+
Bundles.MainnetIds.SPARK_EOA_CLOSE,
|
|
2105
|
+
web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
|
|
2106
|
+
2,
|
|
2107
|
+
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
2108
|
+
4,
|
|
2109
|
+
web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
|
|
2110
|
+
web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
|
|
2111
|
+
40000,
|
|
2112
|
+
CloseToAssetType.DEBT,
|
|
2113
|
+
60000,
|
|
2114
|
+
CloseToAssetType.COLLATERAL,
|
|
2115
|
+
],
|
|
2116
|
+
],
|
|
2117
|
+
];
|
|
2118
|
+
|
|
2119
|
+
examples.forEach(([expected, actual]) => {
|
|
2120
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
2121
|
+
expect(sparkEncode.closeOnPriceGeneric(...actual)).to.eql(expected);
|
|
2122
|
+
});
|
|
2123
|
+
});
|
|
2124
|
+
});
|
|
2125
|
+
|
|
1845
2126
|
describe('collateralSwitch()', () => {
|
|
1846
2127
|
const examples: Array<[
|
|
1847
2128
|
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
@@ -1957,6 +2238,63 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1957
2238
|
});
|
|
1958
2239
|
});
|
|
1959
2240
|
});
|
|
2241
|
+
|
|
2242
|
+
describe('collateralSwitchGeneric()', () => {
|
|
2243
|
+
const examples: Array<[
|
|
2244
|
+
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
2245
|
+
[
|
|
2246
|
+
strategyOrBundleId: number,
|
|
2247
|
+
fromAsset: EthereumAddress,
|
|
2248
|
+
fromAssetId: number,
|
|
2249
|
+
toAsset: EthereumAddress,
|
|
2250
|
+
toAssetId: number,
|
|
2251
|
+
marketAddr: EthereumAddress,
|
|
2252
|
+
amountToSwitch: string,
|
|
2253
|
+
user: EthereumAddress,
|
|
2254
|
+
baseTokenAddress: EthereumAddress,
|
|
2255
|
+
quoteTokenAddress: EthereumAddress,
|
|
2256
|
+
price: number,
|
|
2257
|
+
state: RatioState,
|
|
2258
|
+
]
|
|
2259
|
+
]> = [
|
|
2260
|
+
[
|
|
2261
|
+
[
|
|
2262
|
+
Strategies.MainnetIds.SPARK_GENERIC_FL_COLLATERAL_SWITCH,
|
|
2263
|
+
false,
|
|
2264
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf00000000000000000000000000000000000000000000000000000000002625a00000000000000000000000000000000000000000000000000000000000000001'],
|
|
2265
|
+
[
|
|
2266
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
2267
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
2268
|
+
'0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
|
|
2269
|
+
'0x0000000000000000000000000000000000000000000000000000000000000007',
|
|
2270
|
+
'0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
|
|
2271
|
+
'0x0000000000000000000000000000000000000000000000008ac7230489e80000',
|
|
2272
|
+
'0x0000000000000000000000001234567890123456789012345678901234567890',
|
|
2273
|
+
],
|
|
2274
|
+
],
|
|
2275
|
+
[
|
|
2276
|
+
Strategies.MainnetIds.SPARK_GENERIC_FL_COLLATERAL_SWITCH,
|
|
2277
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
2278
|
+
0,
|
|
2279
|
+
web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
|
|
2280
|
+
7,
|
|
2281
|
+
web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
|
|
2282
|
+
'10000000000000000000',
|
|
2283
|
+
web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
|
|
2284
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
2285
|
+
web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
|
|
2286
|
+
0.025,
|
|
2287
|
+
RatioState.UNDER,
|
|
2288
|
+
],
|
|
2289
|
+
],
|
|
2290
|
+
];
|
|
2291
|
+
|
|
2292
|
+
examples.forEach(([expected, actual]) => {
|
|
2293
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
2294
|
+
expect(sparkEncode.collateralSwitchGeneric(...actual)).to.eql(expected);
|
|
2295
|
+
});
|
|
2296
|
+
});
|
|
2297
|
+
});
|
|
1960
2298
|
});
|
|
1961
2299
|
|
|
1962
2300
|
describe('When testing strategySubService.aaveV4Encode', () => {
|