@defisaver/automation-sdk 3.3.10 → 3.3.11
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 +10 -0
- package/cjs/services/ethereumService.test.js +2 -0
- package/cjs/services/strategiesService.js +25 -0
- package/cjs/services/strategySubService.d.ts +13 -0
- package/cjs/services/strategySubService.js +7 -0
- package/cjs/services/strategySubService.test.js +133 -0
- package/cjs/services/subDataService.d.ts +11 -0
- package/cjs/services/subDataService.js +25 -1
- package/cjs/services/subDataService.test.js +57 -0
- package/cjs/services/triggerService.d.ts +9 -0
- package/cjs/services/triggerService.js +16 -1
- package/cjs/services/triggerService.test.js +46 -0
- package/cjs/types/enums.d.ts +3 -1
- package/cjs/types/enums.js +2 -0
- package/cjs/types/index.d.ts +12 -1
- package/esm/constants/index.js +10 -0
- package/esm/services/ethereumService.test.js +2 -0
- package/esm/services/strategiesService.js +25 -0
- package/esm/services/strategySubService.d.ts +13 -0
- package/esm/services/strategySubService.js +7 -0
- package/esm/services/strategySubService.test.js +134 -1
- package/esm/services/subDataService.d.ts +11 -0
- package/esm/services/subDataService.js +24 -0
- package/esm/services/subDataService.test.js +57 -0
- package/esm/services/triggerService.d.ts +9 -0
- package/esm/services/triggerService.js +15 -0
- package/esm/services/triggerService.test.js +47 -1
- package/esm/types/enums.d.ts +3 -1
- package/esm/types/enums.js +2 -0
- package/esm/types/index.d.ts +12 -1
- package/package.json +2 -2
- package/src/constants/index.ts +10 -0
- package/src/services/ethereumService.test.ts +2 -0
- package/src/services/strategiesService.ts +31 -1
- package/src/services/strategySubService.test.ts +162 -0
- package/src/services/strategySubService.ts +22 -0
- package/src/services/subDataService.test.ts +67 -0
- package/src/services/subDataService.ts +39 -0
- package/src/services/triggerService.test.ts +51 -0
- package/src/services/triggerService.ts +23 -0
- package/src/types/enums.ts +2 -0
- package/src/types/index.ts +14 -1
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
crvUSDEncode,
|
|
22
22
|
compoundV3L2Encode,
|
|
23
23
|
morphoBlueEncode,
|
|
24
|
+
sparkEncode,
|
|
24
25
|
} from './strategySubService';
|
|
25
26
|
|
|
26
27
|
describe('Feature: strategySubService.ts', () => {
|
|
@@ -1730,4 +1731,165 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1730
1731
|
});
|
|
1731
1732
|
});
|
|
1732
1733
|
});
|
|
1734
|
+
|
|
1735
|
+
describe('When testing strategySubService.sparkEncode', () => {
|
|
1736
|
+
describe('leverageManagement()', () => {
|
|
1737
|
+
const examples: Array<[string, [number, number, number, number, boolean]]> = [
|
|
1738
|
+
[
|
|
1739
|
+
'0x0000000000000000136dcc951d8c00000000000000000000214e8348c4f0000000000000000000001d24b2dfac52000000000000000000001a5e27eef13e000001',
|
|
1740
|
+
[140,240,210,190,true]
|
|
1741
|
+
],
|
|
1742
|
+
[
|
|
1743
|
+
'0x0000000000000000130337bdce49000000000000000000001988fe4052b800000000000000000000281b57b028e1000000000000000000002223acf76376000000',
|
|
1744
|
+
[137, 184, 289, 246, false]
|
|
1745
|
+
]
|
|
1746
|
+
];
|
|
1747
|
+
|
|
1748
|
+
examples.forEach(([expected, actual]) => {
|
|
1749
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1750
|
+
expect(sparkEncode.leverageManagement(...actual)).to.eql(expected);
|
|
1751
|
+
});
|
|
1752
|
+
});
|
|
1753
|
+
});
|
|
1754
|
+
|
|
1755
|
+
describe('leverageManagementOnPrice()', () => {
|
|
1756
|
+
const examples: Array<[[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
1757
|
+
[
|
|
1758
|
+
strategyOrBundleId: number,
|
|
1759
|
+
isBundle: boolean,
|
|
1760
|
+
triggerData: { baseTokenAddr: EthereumAddress, quoteTokenAddr: EthereumAddress, price: number, ratioState: RatioState },
|
|
1761
|
+
subData: { collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, marketAddr: EthereumAddress, targetRatio: number }
|
|
1762
|
+
]]> = [
|
|
1763
|
+
[
|
|
1764
|
+
[
|
|
1765
|
+
Bundles.MainnetIds.SPARK_REPAY_ON_PRICE,
|
|
1766
|
+
true,
|
|
1767
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000003a352944000000000000000000000000000000000000000000000000000000000000000001'],
|
|
1768
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1769
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1770
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
1771
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1772
|
+
'0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
|
|
1773
|
+
'0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
|
|
1774
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1775
|
+
],
|
|
1776
|
+
],
|
|
1777
|
+
[
|
|
1778
|
+
59,
|
|
1779
|
+
true,
|
|
1780
|
+
{
|
|
1781
|
+
baseTokenAddr: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1782
|
+
quoteTokenAddr: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1783
|
+
price: 2500,
|
|
1784
|
+
ratioState: RatioState.UNDER,
|
|
1785
|
+
},
|
|
1786
|
+
{
|
|
1787
|
+
collAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1788
|
+
collAssetId: 0,
|
|
1789
|
+
debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1790
|
+
debtAssetId: 1,
|
|
1791
|
+
marketAddr: web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
|
|
1792
|
+
targetRatio: 200,
|
|
1793
|
+
},
|
|
1794
|
+
]
|
|
1795
|
+
],
|
|
1796
|
+
[
|
|
1797
|
+
[
|
|
1798
|
+
Bundles.MainnetIds.SPARK_BOOST_ON_PRICE,
|
|
1799
|
+
true,
|
|
1800
|
+
['0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000006b175474e89094c44da98b954eedeac495271d0f00000000000000000000000000000000000000000000000000000417bce6c8000000000000000000000000000000000000000000000000000000000000000000'],
|
|
1801
|
+
[
|
|
1802
|
+
'0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
|
|
1803
|
+
'0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
1804
|
+
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
1805
|
+
'0x0000000000000000000000000000000000000000000000000000000000000004',
|
|
1806
|
+
'0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
|
|
1807
|
+
'0x00000000000000000000000000000000000000000000000022b1c8c1227a0000',
|
|
1808
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1809
|
+
]
|
|
1810
|
+
],
|
|
1811
|
+
[
|
|
1812
|
+
60,
|
|
1813
|
+
true,
|
|
1814
|
+
{
|
|
1815
|
+
baseTokenAddr: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
|
|
1816
|
+
quoteTokenAddr: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
1817
|
+
price: 45000,
|
|
1818
|
+
ratioState: RatioState.OVER,
|
|
1819
|
+
},
|
|
1820
|
+
{
|
|
1821
|
+
collAsset: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
|
|
1822
|
+
collAssetId: 2,
|
|
1823
|
+
debtAsset: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
1824
|
+
debtAssetId: 4,
|
|
1825
|
+
marketAddr: web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
|
|
1826
|
+
targetRatio: 250,
|
|
1827
|
+
},
|
|
1828
|
+
]
|
|
1829
|
+
]
|
|
1830
|
+
];
|
|
1831
|
+
|
|
1832
|
+
examples.forEach(([expected, actual]) => {
|
|
1833
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1834
|
+
expect(sparkEncode.leverageManagementOnPrice(...actual)).to.eql(expected);
|
|
1835
|
+
});
|
|
1836
|
+
});
|
|
1837
|
+
});
|
|
1838
|
+
|
|
1839
|
+
describe('closeOnPrice()', () => {
|
|
1840
|
+
const examples: Array<[
|
|
1841
|
+
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
1842
|
+
[
|
|
1843
|
+
strategyOrBundleId: number,
|
|
1844
|
+
collAsset: EthereumAddress,
|
|
1845
|
+
collAssetId: number,
|
|
1846
|
+
debtAsset: EthereumAddress,
|
|
1847
|
+
debtAssetId: number,
|
|
1848
|
+
marketAddr: EthereumAddress,
|
|
1849
|
+
user: EthereumAddress,
|
|
1850
|
+
stopLossPrice: number,
|
|
1851
|
+
stopLossType: CloseToAssetType,
|
|
1852
|
+
takeProfitPrice: number,
|
|
1853
|
+
takeProfitType: CloseToAssetType,
|
|
1854
|
+
]
|
|
1855
|
+
] > =
|
|
1856
|
+
[
|
|
1857
|
+
[
|
|
1858
|
+
[
|
|
1859
|
+
Bundles.MainnetIds.SPARK_CLOSE,
|
|
1860
|
+
true,
|
|
1861
|
+
['0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000000000000000000000000000000003a35294400000000000000000000000000000000000000000000000000000000574fbde6000'],
|
|
1862
|
+
[
|
|
1863
|
+
'0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
|
|
1864
|
+
'0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
1865
|
+
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
1866
|
+
'0x0000000000000000000000000000000000000000000000000000000000000004',
|
|
1867
|
+
'0x0000000000000000000000000000000000000000000000000000000000000005',
|
|
1868
|
+
'0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
|
|
1869
|
+
'0x0000000000000000000000001234567890123456789012345678901234567890',
|
|
1870
|
+
]
|
|
1871
|
+
],
|
|
1872
|
+
[
|
|
1873
|
+
57,
|
|
1874
|
+
web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
|
|
1875
|
+
2,
|
|
1876
|
+
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
1877
|
+
4,
|
|
1878
|
+
web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
|
|
1879
|
+
web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
|
|
1880
|
+
40000,
|
|
1881
|
+
CloseToAssetType.DEBT,
|
|
1882
|
+
60000,
|
|
1883
|
+
CloseToAssetType.COLLATERAL,
|
|
1884
|
+
]
|
|
1885
|
+
],
|
|
1886
|
+
]
|
|
1887
|
+
|
|
1888
|
+
examples.forEach(([expected, actual]) => {
|
|
1889
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1890
|
+
expect(sparkEncode.closeOnPriceGeneric(...actual)).to.eql(expected);
|
|
1891
|
+
});
|
|
1892
|
+
});
|
|
1893
|
+
});
|
|
1894
|
+
});
|
|
1733
1895
|
});
|
|
@@ -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,
|
|
@@ -2263,4 +2263,71 @@ describe('Feature: subDataService.ts', () => {
|
|
|
2263
2263
|
});
|
|
2264
2264
|
});
|
|
2265
2265
|
});
|
|
2266
|
+
describe('When testing subDataService.sparkLeverageManagementOnPriceSubData', () => {
|
|
2267
|
+
describe('encode()', () => {
|
|
2268
|
+
const examples: Array<[SubData, [collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, marketAddr: EthereumAddress, targetRatio: number]] > =
|
|
2269
|
+
[
|
|
2270
|
+
[
|
|
2271
|
+
[
|
|
2272
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
2273
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
2274
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
2275
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
2276
|
+
'0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
|
|
2277
|
+
'0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
|
|
2278
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
2279
|
+
],
|
|
2280
|
+
[
|
|
2281
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
2282
|
+
0,
|
|
2283
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
2284
|
+
1,
|
|
2285
|
+
web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
|
|
2286
|
+
200,
|
|
2287
|
+
]
|
|
2288
|
+
]
|
|
2289
|
+
];
|
|
2290
|
+
|
|
2291
|
+
examples.forEach(([expected, actual]) => {
|
|
2292
|
+
it(`Given ${JSON.stringify(
|
|
2293
|
+
actual
|
|
2294
|
+
)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
2295
|
+
expect(subDataService.sparkLeverageManagementOnPriceSubData.encode(...actual)).to.eql(expected);
|
|
2296
|
+
});
|
|
2297
|
+
});
|
|
2298
|
+
});
|
|
2299
|
+
|
|
2300
|
+
describe('decode()', () => {
|
|
2301
|
+
const examples: Array<[{ collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, marketAddr: EthereumAddress, targetRatio: number}, SubData]> =
|
|
2302
|
+
[
|
|
2303
|
+
[
|
|
2304
|
+
{
|
|
2305
|
+
collAsset: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
|
|
2306
|
+
collAssetId: 2,
|
|
2307
|
+
debtAsset: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
2308
|
+
debtAssetId: 4,
|
|
2309
|
+
marketAddr: web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
|
|
2310
|
+
targetRatio: 175
|
|
2311
|
+
}
|
|
2312
|
+
,
|
|
2313
|
+
[
|
|
2314
|
+
'0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
|
|
2315
|
+
'0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
2316
|
+
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
2317
|
+
'0x0000000000000000000000000000000000000000000000000000000000000004',
|
|
2318
|
+
'0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
|
|
2319
|
+
'0x00000000000000000000000000000000000000000000000018493fba64ef0000'
|
|
2320
|
+
]
|
|
2321
|
+
]
|
|
2322
|
+
];
|
|
2323
|
+
|
|
2324
|
+
examples.forEach(([expected, actual]) => {
|
|
2325
|
+
it(`Given ${JSON.stringify(
|
|
2326
|
+
actual
|
|
2327
|
+
)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
2328
|
+
expect(subDataService.sparkLeverageManagementOnPriceSubData.decode(actual)).to.eql(expected);
|
|
2329
|
+
});
|
|
2330
|
+
});
|
|
2331
|
+
});
|
|
2332
|
+
});
|
|
2266
2333
|
});
|
|
@@ -1292,3 +1292,42 @@ export const morphoBlueCloseOnPriceSubData = {
|
|
|
1292
1292
|
};
|
|
1293
1293
|
},
|
|
1294
1294
|
};
|
|
1295
|
+
|
|
1296
|
+
export const sparkLeverageManagementOnPriceSubData = {
|
|
1297
|
+
encode(
|
|
1298
|
+
collAsset: EthereumAddress,
|
|
1299
|
+
collAssetId: number,
|
|
1300
|
+
debtAsset: EthereumAddress,
|
|
1301
|
+
debtAssetId: number,
|
|
1302
|
+
marketAddr: EthereumAddress,
|
|
1303
|
+
targetRatio: number,
|
|
1304
|
+
): SubData {
|
|
1305
|
+
const encodedColl = AbiCoder.encodeParameter('address', collAsset);
|
|
1306
|
+
const encodedCollId = AbiCoder.encodeParameter('uint16', collAssetId);
|
|
1307
|
+
const encodedDebt = AbiCoder.encodeParameter('address', debtAsset);
|
|
1308
|
+
const encodedDebtId = AbiCoder.encodeParameter('uint16', debtAssetId);
|
|
1309
|
+
const encodedMarket = AbiCoder.encodeParameter('address', marketAddr);
|
|
1310
|
+
const encodedTargetRatio = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
|
|
1311
|
+
const useOnBehalfEncoded = AbiCoder.encodeParameter('bool', false);
|
|
1312
|
+
return [encodedColl, encodedCollId, encodedDebt, encodedDebtId, encodedMarket, encodedTargetRatio, useOnBehalfEncoded];
|
|
1313
|
+
},
|
|
1314
|
+
decode(subData: SubData): {
|
|
1315
|
+
collAsset: EthereumAddress,
|
|
1316
|
+
collAssetId: number,
|
|
1317
|
+
debtAsset: EthereumAddress,
|
|
1318
|
+
debtAssetId: number,
|
|
1319
|
+
marketAddr: EthereumAddress,
|
|
1320
|
+
targetRatio: number,
|
|
1321
|
+
} {
|
|
1322
|
+
const collAsset = AbiCoder.decodeParameter('address', subData[0]) as unknown as EthereumAddress;
|
|
1323
|
+
const collAssetId = Number(AbiCoder.decodeParameter('uint16', subData[1]));
|
|
1324
|
+
const debtAsset = AbiCoder.decodeParameter('address', subData[2]) as unknown as EthereumAddress;
|
|
1325
|
+
const debtAssetId = Number(AbiCoder.decodeParameter('uint16', subData[3]));
|
|
1326
|
+
const marketAddr = AbiCoder.decodeParameter('address', subData[4]) as unknown as EthereumAddress;
|
|
1327
|
+
const weiRatio = AbiCoder.decodeParameter('uint256', subData[5]) as any as string;
|
|
1328
|
+
const targetRatio = weiToRatioPercentage(weiRatio);
|
|
1329
|
+
return {
|
|
1330
|
+
collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio,
|
|
1331
|
+
};
|
|
1332
|
+
},
|
|
1333
|
+
};
|
|
@@ -32,6 +32,7 @@ import {
|
|
|
32
32
|
compoundV3PriceRangeTrigger,
|
|
33
33
|
aaveV3QuotePriceRangeTrigger,
|
|
34
34
|
morphoBluePriceRangeTrigger,
|
|
35
|
+
sparkQuotePriceTrigger,
|
|
35
36
|
} from './triggerService';
|
|
36
37
|
|
|
37
38
|
describe('Feature: triggerService.ts', () => {
|
|
@@ -1283,4 +1284,54 @@ describe('Feature: triggerService.ts', () => {
|
|
|
1283
1284
|
});
|
|
1284
1285
|
});
|
|
1285
1286
|
});
|
|
1287
|
+
|
|
1288
|
+
describe('When testing triggerService.sparkQuotePriceTrigger', () => {
|
|
1289
|
+
describe('encode()', () => {
|
|
1290
|
+
const examples: Array<[[string], [baseTokenAddr: EthereumAddress, quoteTokenAddr: EthereumAddress, price: number, ratioState: RatioState]]> = [
|
|
1291
|
+
[
|
|
1292
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000003a352944000000000000000000000000000000000000000000000000000000000000000001'],
|
|
1293
|
+
[web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address), web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address), 2500, RatioState.UNDER]
|
|
1294
|
+
],
|
|
1295
|
+
[
|
|
1296
|
+
['0x000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec70000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000000000000000000000000000000000000000000c1c0000000000000000000000000000000000000000000000000000000000000000'],
|
|
1297
|
+
[web3Utils.toChecksumAddress(getAssetInfo('USDT', ChainId.Ethereum).address), web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address), 0.000031, RatioState.OVER]
|
|
1298
|
+
],
|
|
1299
|
+
];
|
|
1300
|
+
|
|
1301
|
+
examples.forEach(([expected, actual]) => {
|
|
1302
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
1303
|
+
expect(sparkQuotePriceTrigger.encode(...actual)).to.eql(expected);
|
|
1304
|
+
});
|
|
1305
|
+
});
|
|
1306
|
+
});
|
|
1307
|
+
|
|
1308
|
+
describe('decode()', () => {
|
|
1309
|
+
const examples: Array<[{ baseTokenAddr: EthereumAddress, quoteTokenAddr: EthereumAddress, price: string, ratioState: RatioState }, TriggerData]> = [
|
|
1310
|
+
[
|
|
1311
|
+
{
|
|
1312
|
+
baseTokenAddr: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1313
|
+
quoteTokenAddr: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1314
|
+
price: '2500',
|
|
1315
|
+
ratioState: RatioState.UNDER
|
|
1316
|
+
},
|
|
1317
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000003a352944000000000000000000000000000000000000000000000000000000000000000001']
|
|
1318
|
+
],
|
|
1319
|
+
[
|
|
1320
|
+
{
|
|
1321
|
+
baseTokenAddr: web3Utils.toChecksumAddress(getAssetInfo('USDT', ChainId.Ethereum).address),
|
|
1322
|
+
quoteTokenAddr: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
|
|
1323
|
+
price: '0.000031',
|
|
1324
|
+
ratioState: RatioState.OVER
|
|
1325
|
+
},
|
|
1326
|
+
['0x000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec70000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000000000000000000000000000000000000000000c1c0000000000000000000000000000000000000000000000000000000000000000']
|
|
1327
|
+
]
|
|
1328
|
+
];
|
|
1329
|
+
|
|
1330
|
+
examples.forEach(([expected, actual]) => {
|
|
1331
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1332
|
+
expect(sparkQuotePriceTrigger.decode(actual)).to.eql(expected);
|
|
1333
|
+
});
|
|
1334
|
+
});
|
|
1335
|
+
});
|
|
1336
|
+
});
|
|
1286
1337
|
});
|
|
@@ -720,4 +720,27 @@ export const morphoBluePriceRangeTrigger = {
|
|
|
720
720
|
upperPrice: new Dec(decodedData[4] as string).div(1e8).toString(),
|
|
721
721
|
};
|
|
722
722
|
},
|
|
723
|
+
};
|
|
724
|
+
|
|
725
|
+
export const sparkQuotePriceTrigger = {
|
|
726
|
+
encode(
|
|
727
|
+
baseTokenAddr: EthereumAddress,
|
|
728
|
+
quoteTokenAddr: EthereumAddress,
|
|
729
|
+
price: number,
|
|
730
|
+
ratioState: RatioState,
|
|
731
|
+
) {
|
|
732
|
+
const _price = new Dec(price.toString()).mul(1e8).floor().toString();
|
|
733
|
+
return [AbiCoder.encodeParameters(['address', 'address', 'uint256', 'uint8'], [baseTokenAddr, quoteTokenAddr, _price, ratioState])];
|
|
734
|
+
},
|
|
735
|
+
decode(
|
|
736
|
+
triggerData: TriggerData,
|
|
737
|
+
) {
|
|
738
|
+
const decodedData = AbiCoder.decodeParameters(['address', 'address', 'uint256', 'uint8'], triggerData[0]);
|
|
739
|
+
return {
|
|
740
|
+
baseTokenAddr: decodedData[0] as EthereumAddress,
|
|
741
|
+
quoteTokenAddr: decodedData[1] as EthereumAddress,
|
|
742
|
+
price: new Dec(decodedData[2] as string).div(1e8).toString(),
|
|
743
|
+
ratioState: Number(decodedData[3]),
|
|
744
|
+
};
|
|
745
|
+
},
|
|
723
746
|
};
|
package/src/types/enums.ts
CHANGED
package/src/types/index.ts
CHANGED
|
@@ -236,6 +236,18 @@ export declare namespace Position {
|
|
|
236
236
|
stopLossType: CloseToAssetType | undefined,
|
|
237
237
|
takeProfitType: CloseToAssetType | undefined,
|
|
238
238
|
}
|
|
239
|
+
|
|
240
|
+
interface SparkOnPrice extends Base {
|
|
241
|
+
collAsset: EthereumAddress,
|
|
242
|
+
collAssetId: number,
|
|
243
|
+
debtAsset: EthereumAddress,
|
|
244
|
+
debtAssetId: number,
|
|
245
|
+
baseToken: EthereumAddress,
|
|
246
|
+
quoteToken: EthereumAddress,
|
|
247
|
+
price: string,
|
|
248
|
+
ratioState: RatioState,
|
|
249
|
+
ratio: number,
|
|
250
|
+
}
|
|
239
251
|
}
|
|
240
252
|
|
|
241
253
|
type SpecificAny =
|
|
@@ -253,7 +265,8 @@ export declare namespace Position {
|
|
|
253
265
|
| Specific.PaybackLiquityV2
|
|
254
266
|
| Specific.CompoundV3LeverageManagementOnPrice
|
|
255
267
|
| Specific.CompoundV3CloseOnPrice
|
|
256
|
-
| Specific.AaveV3CloseOnPriceGeneric
|
|
268
|
+
| Specific.AaveV3CloseOnPriceGeneric
|
|
269
|
+
| Specific.SparkOnPrice;
|
|
257
270
|
|
|
258
271
|
export interface Automated {
|
|
259
272
|
chainId: ChainId,
|