@defisaver/automation-sdk 3.3.10-aave-v4-1-dev → 3.3.10-aave-v4-2-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.
Files changed (39) hide show
  1. package/cjs/constants/index.js +15 -0
  2. package/cjs/services/strategiesService.js +25 -0
  3. package/cjs/services/strategySubService.d.ts +13 -0
  4. package/cjs/services/strategySubService.js +7 -0
  5. package/cjs/services/strategySubService.test.js +133 -0
  6. package/cjs/services/subDataService.d.ts +11 -0
  7. package/cjs/services/subDataService.js +25 -1
  8. package/cjs/services/subDataService.test.js +57 -0
  9. package/cjs/services/triggerService.d.ts +9 -0
  10. package/cjs/services/triggerService.js +16 -1
  11. package/cjs/services/triggerService.test.js +46 -0
  12. package/cjs/types/enums.d.ts +16 -12
  13. package/cjs/types/enums.js +15 -11
  14. package/cjs/types/index.d.ts +12 -1
  15. package/esm/constants/index.js +15 -0
  16. package/esm/services/strategiesService.js +25 -0
  17. package/esm/services/strategySubService.d.ts +13 -0
  18. package/esm/services/strategySubService.js +7 -0
  19. package/esm/services/strategySubService.test.js +134 -1
  20. package/esm/services/subDataService.d.ts +11 -0
  21. package/esm/services/subDataService.js +24 -0
  22. package/esm/services/subDataService.test.js +57 -0
  23. package/esm/services/triggerService.d.ts +9 -0
  24. package/esm/services/triggerService.js +15 -0
  25. package/esm/services/triggerService.test.js +47 -1
  26. package/esm/types/enums.d.ts +16 -12
  27. package/esm/types/enums.js +15 -11
  28. package/esm/types/index.d.ts +12 -1
  29. package/package.json +1 -1
  30. package/src/constants/index.ts +15 -0
  31. package/src/services/strategiesService.ts +31 -1
  32. package/src/services/strategySubService.test.ts +161 -0
  33. package/src/services/strategySubService.ts +22 -0
  34. package/src/services/subDataService.test.ts +66 -0
  35. package/src/services/subDataService.ts +38 -1
  36. package/src/services/triggerService.test.ts +50 -1
  37. package/src/services/triggerService.ts +23 -0
  38. package/src/types/enums.ts +15 -11
  39. package/src/types/index.ts +14 -1
@@ -884,9 +884,37 @@ function parseSparkLeverageManagement(position: Position.Automated, parseData: P
884
884
  return _position;
885
885
  }
886
886
 
887
- function parseSparkCloseOnPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
887
+ function parseSparkLeverageManagementOnPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
888
888
  const _position = cloneDeep(position);
889
+ const { subStruct } = parseData.subscriptionEventData;
890
+
891
+ const triggerData = triggerService.sparkQuotePriceTrigger.decode(subStruct.triggerData);
892
+ const subData = subDataService.sparkLeverageManagementOnPriceSubData.decode(subStruct.subData);
893
+
894
+ _position.strategyData.decoded.triggerData = triggerData;
895
+ _position.strategyData.decoded.subData = subData;
889
896
 
897
+ _position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, subData.marketAddr);
898
+
899
+ _position.specific = {
900
+ // subData
901
+ collAsset: subData.collAsset,
902
+ collAssetId: subData.collAssetId,
903
+ debtAsset: subData.debtAsset,
904
+ debtAssetId: subData.debtAssetId,
905
+ ratio: subData.targetRatio,
906
+ // triggerData
907
+ baseToken: triggerData.baseTokenAddr,
908
+ quoteToken: triggerData.quoteTokenAddr,
909
+ price: triggerData.price,
910
+ ratioState: triggerData.ratioState,
911
+ };
912
+
913
+ return _position;
914
+ }
915
+
916
+ function parseSparkCloseOnPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
917
+ const _position = cloneDeep(position);
890
918
  const { subStruct } = parseData.subscriptionEventData;
891
919
 
892
920
  const triggerData = triggerService.sparkQuotePriceRangeTrigger.decode(subStruct.triggerData);
@@ -1352,6 +1380,8 @@ const parsingMethodsMapping: StrategiesToProtocolVersionMapping = {
1352
1380
  [ProtocolIdentifiers.StrategiesAutomation.Spark]: {
1353
1381
  [Strategies.Identifiers.Repay]: parseSparkLeverageManagement,
1354
1382
  [Strategies.Identifiers.Boost]: parseSparkLeverageManagement,
1383
+ [Strategies.Identifiers.RepayOnPrice]: parseSparkLeverageManagementOnPrice,
1384
+ [Strategies.Identifiers.BoostOnPrice]: parseSparkLeverageManagementOnPrice,
1355
1385
  [Strategies.Identifiers.CloseOnPrice]: parseSparkCloseOnPrice,
1356
1386
  },
1357
1387
  [ProtocolIdentifiers.StrategiesAutomation.CrvUSD]: {
@@ -21,6 +21,7 @@ import {
21
21
  crvUSDEncode,
22
22
  compoundV3L2Encode,
23
23
  morphoBlueEncode,
24
+ sparkEncode,
24
25
  aaveV4Encode,
25
26
  } from './strategySubService';
26
27
 
@@ -1732,6 +1733,166 @@ describe('Feature: strategySubService.ts', () => {
1732
1733
  });
1733
1734
  });
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
+ });
1735
1896
  describe('When testing strategySubService.aaveV4Encode', () => {
1736
1897
  describe('leverageManagement()', () => {
1737
1898
  const examples: Array<[
@@ -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,7 +2263,73 @@ 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
+ ];
2266
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
+ });
2267
2333
  describe('When testing subDataService.aaveV4LeverageManagementSubData', () => {
2268
2334
  describe('encode()', () => {
2269
2335
  const examples: Array<[SubData, [spoke: EthereumAddress, owner: EthereumAddress, ratioState: RatioState, targetRatio: number]]> = [
@@ -1275,6 +1275,44 @@ export const sparkCloseGenericSubData = {
1275
1275
  };
1276
1276
  },
1277
1277
  };
1278
+ export const sparkLeverageManagementOnPriceSubData = {
1279
+ encode(
1280
+ collAsset: EthereumAddress,
1281
+ collAssetId: number,
1282
+ debtAsset: EthereumAddress,
1283
+ debtAssetId: number,
1284
+ marketAddr: EthereumAddress,
1285
+ targetRatio: number,
1286
+ ): SubData {
1287
+ const encodedColl = AbiCoder.encodeParameter('address', collAsset);
1288
+ const encodedCollId = AbiCoder.encodeParameter('uint16', collAssetId);
1289
+ const encodedDebt = AbiCoder.encodeParameter('address', debtAsset);
1290
+ const encodedDebtId = AbiCoder.encodeParameter('uint16', debtAssetId);
1291
+ const encodedMarket = AbiCoder.encodeParameter('address', marketAddr);
1292
+ const encodedTargetRatio = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
1293
+ const useOnBehalfEncoded = AbiCoder.encodeParameter('bool', false);
1294
+ return [encodedColl, encodedCollId, encodedDebt, encodedDebtId, encodedMarket, encodedTargetRatio, useOnBehalfEncoded];
1295
+ },
1296
+ decode(subData: SubData): {
1297
+ collAsset: EthereumAddress,
1298
+ collAssetId: number,
1299
+ debtAsset: EthereumAddress,
1300
+ debtAssetId: number,
1301
+ marketAddr: EthereumAddress,
1302
+ targetRatio: number,
1303
+ } {
1304
+ const collAsset = AbiCoder.decodeParameter('address', subData[0]) as unknown as EthereumAddress;
1305
+ const collAssetId = Number(AbiCoder.decodeParameter('uint16', subData[1]));
1306
+ const debtAsset = AbiCoder.decodeParameter('address', subData[2]) as unknown as EthereumAddress;
1307
+ const debtAssetId = Number(AbiCoder.decodeParameter('uint16', subData[3]));
1308
+ const marketAddr = AbiCoder.decodeParameter('address', subData[4]) as unknown as EthereumAddress;
1309
+ const weiRatio = AbiCoder.decodeParameter('uint256', subData[5]) as any as string;
1310
+ const targetRatio = weiToRatioPercentage(weiRatio);
1311
+ return {
1312
+ collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio,
1313
+ };
1314
+ },
1315
+ };
1278
1316
 
1279
1317
  /**
1280
1318
  ______ .______ ____ ____ __ __ _______. _______
@@ -1525,4 +1563,3 @@ export const fluidLeverageManagementSubData = {
1525
1563
  };
1526
1564
  },
1527
1565
  };
1528
-
@@ -32,6 +32,7 @@ import {
32
32
  compoundV3PriceRangeTrigger,
33
33
  aaveV3QuotePriceRangeTrigger,
34
34
  morphoBluePriceRangeTrigger,
35
+ sparkQuotePriceTrigger,
35
36
  aaveV4RatioTrigger,
36
37
  aaveV4QuotePriceTrigger,
37
38
  aaveV4QuotePriceRangeTrigger,
@@ -1286,7 +1287,6 @@ describe('Feature: triggerService.ts', () => {
1286
1287
  });
1287
1288
  });
1288
1289
  });
1289
-
1290
1290
  describe('When testing triggerService.aaveV4RatioTrigger', () => {
1291
1291
  describe('encode()', () => {
1292
1292
  const examples: Array<[[string], [owner: EthereumAddress, spoke: EthereumAddress, ratioPercentage: number, ratioState: RatioState]]> = [
@@ -1382,4 +1382,53 @@ describe('Feature: triggerService.ts', () => {
1382
1382
  });
1383
1383
  });
1384
1384
  });
1385
+ describe('When testing triggerService.sparkQuotePriceTrigger', () => {
1386
+ describe('encode()', () => {
1387
+ const examples: Array<[[string], [baseTokenAddr: EthereumAddress, quoteTokenAddr: EthereumAddress, price: number, ratioState: RatioState]]> = [
1388
+ [
1389
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000003a352944000000000000000000000000000000000000000000000000000000000000000001'],
1390
+ [web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address), web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address), 2500, RatioState.UNDER]
1391
+ ],
1392
+ [
1393
+ ['0x000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec70000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000000000000000000000000000000000000000000c1c0000000000000000000000000000000000000000000000000000000000000000'],
1394
+ [web3Utils.toChecksumAddress(getAssetInfo('USDT', ChainId.Ethereum).address), web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address), 0.000031, RatioState.OVER]
1395
+ ],
1396
+ ];
1397
+
1398
+ examples.forEach(([expected, actual]) => {
1399
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
1400
+ expect(sparkQuotePriceTrigger.encode(...actual)).to.eql(expected);
1401
+ });
1402
+ });
1403
+ });
1404
+
1405
+ describe('decode()', () => {
1406
+ const examples: Array<[{ baseTokenAddr: EthereumAddress, quoteTokenAddr: EthereumAddress, price: string, ratioState: RatioState }, TriggerData]> = [
1407
+ [
1408
+ {
1409
+ baseTokenAddr: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1410
+ quoteTokenAddr: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1411
+ price: '2500',
1412
+ ratioState: RatioState.UNDER
1413
+ },
1414
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000003a352944000000000000000000000000000000000000000000000000000000000000000001']
1415
+ ],
1416
+ [
1417
+ {
1418
+ baseTokenAddr: web3Utils.toChecksumAddress(getAssetInfo('USDT', ChainId.Ethereum).address),
1419
+ quoteTokenAddr: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
1420
+ price: '0.000031',
1421
+ ratioState: RatioState.OVER
1422
+ },
1423
+ ['0x000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec70000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000000000000000000000000000000000000000000c1c0000000000000000000000000000000000000000000000000000000000000000']
1424
+ ]
1425
+ ];
1426
+
1427
+ examples.forEach(([expected, actual]) => {
1428
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1429
+ expect(sparkQuotePriceTrigger.decode(actual)).to.eql(expected);
1430
+ });
1431
+ });
1432
+ });
1433
+ });
1385
1434
  });
@@ -722,6 +722,29 @@ export const morphoBluePriceRangeTrigger = {
722
722
  },
723
723
  };
724
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
+ },
746
+ };
747
+
725
748
  export const aaveV4RatioTrigger = {
726
749
  encode(owner: EthereumAddress, spoke: EthereumAddress, ratioPercentage: number, ratioState: RatioState) {
727
750
  const ratioWei = ratioPercentageToWei(ratioPercentage);
@@ -98,7 +98,8 @@ export namespace Strategies {
98
98
  CURVEUSD_PAYBACK = 92,
99
99
  LIQUITY_V2_PAYBACK = 113,
100
100
  AAVE_V3_COLLATERAL_SWITCH = 135,
101
- AAVE_V4_COLLATERAL_SWITCH = 151,
101
+ AAVE_V4_COLLATERAL_SWITCH = 154,
102
+ AAVE_V4_COLLATERAL_SWITCH_EOA = 165,
102
103
  }
103
104
 
104
105
  export enum OptimismIds {
@@ -150,6 +151,7 @@ export namespace Strategies {
150
151
  EoaBoostOnPrice = 'eoa-boost-on-price',
151
152
  EoaRepayOnPrice = 'eoa-repay-on-price',
152
153
  CollateralSwitch = 'collateral-switch',
154
+ EoaCollateralSwitch = 'eoa-collateral-switch',
153
155
  }
154
156
  export enum IdOverrides {
155
157
  TakeProfit = 'take-profit',
@@ -225,16 +227,18 @@ export namespace Bundles {
225
227
  AAVE_V3_EOA_CLOSE = 56,
226
228
  SPARK_CLOSE = 57,
227
229
  MORPHO_BLUE_CLOSE = 58,
228
- AAVE_V4_REPAY = 59,
229
- AAVE_V4_BOOST = 60,
230
- AAVE_V4_REPAY_ON_PRICE = 61,
231
- AAVE_V4_BOOST_ON_PRICE = 62,
232
- AAVE_V4_CLOSE = 63,
233
- AAVE_V4_EOA_REPAY = 64,
234
- AAVE_V4_EOA_BOOST = 65,
235
- AAVE_V4_EOA_REPAY_ON_PRICE = 66,
236
- AAVE_V4_EOA_BOOST_ON_PRICE = 67,
237
- AAVE_V4_EOA_CLOSE = 68,
230
+ SPARK_REPAY_ON_PRICE = 59,
231
+ SPARK_BOOST_ON_PRICE = 60,
232
+ AAVE_V4_REPAY = 61,
233
+ AAVE_V4_BOOST = 62,
234
+ AAVE_V4_REPAY_ON_PRICE = 63,
235
+ AAVE_V4_BOOST_ON_PRICE = 64,
236
+ AAVE_V4_CLOSE = 65,
237
+ AAVE_V4_EOA_REPAY = 66,
238
+ AAVE_V4_EOA_BOOST = 67,
239
+ AAVE_V4_EOA_REPAY_ON_PRICE = 68,
240
+ AAVE_V4_EOA_BOOST_ON_PRICE = 69,
241
+ AAVE_V4_EOA_CLOSE = 70,
238
242
  }
239
243
 
240
244
  export enum OptimismIds {
@@ -237,6 +237,18 @@ export declare namespace Position {
237
237
  takeProfitType: CloseToAssetType | undefined,
238
238
  }
239
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
+ }
251
+
240
252
  interface CloseBase extends Base {
241
253
  stopLossPrice: string,
242
254
  takeProfitPrice: string,
@@ -279,7 +291,8 @@ export declare namespace Position {
279
291
  | Specific.CompoundV3CloseOnPrice
280
292
  | Specific.AaveV3CloseOnPriceGeneric
281
293
  | Specific.AaveV4LeverageManagementOnPrice
282
- | Specific.AaveV4CloseOnPrice;
294
+ | Specific.AaveV4CloseOnPrice
295
+ | Specific.SparkOnPrice;
283
296
 
284
297
  export interface Automated {
285
298
  chainId: ChainId,