@defisaver/automation-sdk 3.3.6 → 3.3.7-dev.0

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 +5 -10
  2. package/cjs/services/strategiesService.js +11 -14
  3. package/cjs/services/strategySubService.d.ts +1 -11
  4. package/cjs/services/strategySubService.js +5 -5
  5. package/cjs/services/strategySubService.test.js +0 -72
  6. package/cjs/services/subDataService.d.ts +12 -9
  7. package/cjs/services/subDataService.js +33 -20
  8. package/cjs/services/subDataService.test.js +0 -72
  9. package/cjs/services/triggerService.d.ts +9 -9
  10. package/cjs/services/triggerService.js +20 -19
  11. package/cjs/services/triggerService.test.js +0 -46
  12. package/cjs/services/utils.test.js +0 -77
  13. package/cjs/types/enums.d.ts +2 -3
  14. package/cjs/types/enums.js +1 -2
  15. package/esm/constants/index.js +5 -10
  16. package/esm/services/strategiesService.js +11 -14
  17. package/esm/services/strategySubService.d.ts +1 -11
  18. package/esm/services/strategySubService.js +5 -5
  19. package/esm/services/strategySubService.test.js +1 -73
  20. package/esm/services/subDataService.d.ts +12 -9
  21. package/esm/services/subDataService.js +32 -19
  22. package/esm/services/subDataService.test.js +0 -72
  23. package/esm/services/triggerService.d.ts +9 -9
  24. package/esm/services/triggerService.js +19 -18
  25. package/esm/services/triggerService.test.js +1 -47
  26. package/esm/services/utils.test.js +1 -52
  27. package/esm/types/enums.d.ts +2 -3
  28. package/esm/types/enums.js +1 -2
  29. package/package.json +1 -1
  30. package/src/constants/index.ts +5 -12
  31. package/src/services/strategiesService.ts +12 -22
  32. package/src/services/strategySubService.test.ts +4 -94
  33. package/src/services/strategySubService.ts +15 -16
  34. package/src/services/subDataService.test.ts +1 -78
  35. package/src/services/subDataService.ts +52 -31
  36. package/src/services/triggerService.test.ts +0 -51
  37. package/src/services/triggerService.ts +29 -26
  38. package/src/services/utils.test.ts +0 -59
  39. package/src/types/enums.ts +1 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defisaver/automation-sdk",
3
- "version": "3.3.6",
3
+ "version": "3.3.7-dev.0",
4
4
  "description": "",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./esm/index.js",
@@ -331,16 +331,6 @@ export const MAINNET_BUNDLES_INFO: MainnetBundleInfo = {
331
331
  strategyId: Strategies.Identifiers.Boost,
332
332
  protocol: PROTOCOLS.Spark,
333
333
  },
334
- [Bundles.MainnetIds.SPARK_CLOSE_TO_DEBT]: {
335
- strategyOrBundleId: Bundles.MainnetIds.SPARK_CLOSE_TO_DEBT,
336
- strategyId: Strategies.Identifiers.CloseToDebt,
337
- protocol: PROTOCOLS.Spark,
338
- },
339
- [Bundles.MainnetIds.SPARK_CLOSE_TO_COLLATERAL]: {
340
- strategyOrBundleId: Bundles.MainnetIds.SPARK_CLOSE_TO_COLLATERAL,
341
- strategyId: Strategies.Identifiers.CloseToCollateral,
342
- protocol: PROTOCOLS.Spark,
343
- },
344
334
  [Bundles.MainnetIds.AAVE_V2_REPAY]: {
345
335
  strategyOrBundleId: Bundles.MainnetIds.AAVE_V2_REPAY,
346
336
  strategyId: Strategies.Identifiers.Repay,
@@ -496,7 +486,11 @@ export const MAINNET_BUNDLES_INFO: MainnetBundleInfo = {
496
486
  strategyId: Strategies.Identifiers.EoaCloseOnPrice,
497
487
  protocol: PROTOCOLS.AaveV3,
498
488
  },
499
-
489
+ [Bundles.MainnetIds.SPARK_CLOSE]: {
490
+ strategyOrBundleId: Bundles.MainnetIds.SPARK_CLOSE,
491
+ strategyId: Strategies.Identifiers.CloseOnPrice,
492
+ protocol: PROTOCOLS.Spark,
493
+ },
500
494
  };
501
495
 
502
496
  export const OPTIMISM_BUNDLES_INFO: OptimismBundleInfo = {
@@ -689,7 +683,6 @@ export const BASE_BUNDLES_INFO: BaseBundleInfo = {
689
683
  strategyId: Strategies.Identifiers.EoaCloseOnPrice,
690
684
  protocol: PROTOCOLS.AaveV3,
691
685
  },
692
-
693
686
  };
694
687
 
695
688
  export const ARBITRUM_BUNDLES_INFO: ArbitrumBundleInfo = {
@@ -17,10 +17,6 @@ import * as triggerService from './triggerService';
17
17
 
18
18
  const web3 = new Web3();
19
19
 
20
- const SPARK_MARKET_ADDRESSES = {
21
- [ChainId.Ethereum]: '0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE',
22
- };
23
-
24
20
  const AAVE_V3_MARKET_ADDRESSES = {
25
21
  [ChainId.Ethereum]: '0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e',
26
22
  [ChainId.Optimism]: '0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb',
@@ -791,34 +787,29 @@ function parseSparkCloseOnPrice(position: Position.Automated, parseData: ParseDa
791
787
 
792
788
  const { subStruct } = parseData.subscriptionEventData;
793
789
 
794
- const triggerData = triggerService.sparkQuotePriceTrigger.decode(subStruct.triggerData);
795
- const subData = subDataService.sparkQuotePriceSubData.decode(subStruct.subData);
790
+ const triggerData = triggerService.sparkQuotePriceRangeTrigger.decode(subStruct.triggerData);
791
+ const subData = subDataService.sparkCloseGenericSubData.decode(subStruct.subData);
796
792
 
797
793
  _position.strategyData.decoded.triggerData = triggerData;
798
794
  _position.strategyData.decoded.subData = subData;
799
795
 
800
- _position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, SPARK_MARKET_ADDRESSES[_position.chainId as ChainId.Ethereum]);
796
+ _position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, subData.marketAddr);
797
+
798
+ const { takeProfitType, stopLossType } = getStopLossAndTakeProfitTypeByCloseStrategyType(+subData.closeType);
801
799
 
802
800
  _position.specific = {
803
801
  collAsset: subData.collAsset,
804
802
  collAssetId: subData.collAssetId,
805
803
  debtAsset: subData.debtAsset,
806
804
  debtAssetId: subData.debtAssetId,
807
- baseToken: triggerData.baseTokenAddress,
808
- quoteToken: triggerData.quoteTokenAddress,
809
- price: triggerData.price,
810
- ratioState: triggerData.ratioState,
805
+ baseToken: triggerData.collToken,
806
+ quoteToken: triggerData.debtToken,
807
+ stopLossPrice: triggerData.lowerPrice,
808
+ takeProfitPrice: triggerData.upperPrice,
809
+ stopLossType,
810
+ takeProfitType,
811
811
  };
812
812
 
813
- const { ratioState } = getRatioStateInfoForAaveCloseStrategy(
814
- _position.specific.ratioState,
815
- wethToEthByAddress(_position.specific.collAsset, parseData.chainId),
816
- wethToEthByAddress(_position.specific.debtAsset, parseData.chainId),
817
- parseData.chainId,
818
- );
819
-
820
- _position.strategy.strategyId = isRatioStateOver(ratioState) ? Strategies.IdOverrides.TakeProfit : Strategies.IdOverrides.StopLoss;
821
-
822
813
  return _position;
823
814
  }
824
815
 
@@ -1204,8 +1195,7 @@ const parsingMethodsMapping: StrategiesToProtocolVersionMapping = {
1204
1195
  [ProtocolIdentifiers.StrategiesAutomation.Spark]: {
1205
1196
  [Strategies.Identifiers.Repay]: parseSparkLeverageManagement,
1206
1197
  [Strategies.Identifiers.Boost]: parseSparkLeverageManagement,
1207
- [Strategies.Identifiers.CloseToDebt]: parseSparkCloseOnPrice,
1208
- [Strategies.Identifiers.CloseToCollateral]: parseSparkCloseOnPrice,
1198
+ [Strategies.Identifiers.CloseOnPrice]: parseSparkCloseOnPrice,
1209
1199
  },
1210
1200
  [ProtocolIdentifiers.StrategiesAutomation.CrvUSD]: {
1211
1201
  [Strategies.Identifiers.Repay]: parseCrvUSDLeverageManagement,
@@ -18,8 +18,9 @@ import {
18
18
  compoundV3Encode,
19
19
  morphoAaveV2Encode,
20
20
  exchangeEncode,
21
- sparkEncode,
22
- crvUSDEncode, compoundV3L2Encode, morphoBlueEncode,
21
+ crvUSDEncode,
22
+ compoundV3L2Encode,
23
+ morphoBlueEncode,
23
24
  } from './strategySubService';
24
25
 
25
26
  describe('Feature: strategySubService.ts', () => {
@@ -1387,97 +1388,6 @@ describe('Feature: strategySubService.ts', () => {
1387
1388
  });
1388
1389
  });
1389
1390
 
1390
- describe('When testing strategySubService.sparkEncode', () => {
1391
- describe('leverageManagement()', () => {
1392
- const examples: Array<[
1393
- string,
1394
- [triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean],
1395
- ]> = [
1396
- [
1397
- '0x000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000001a5e27eef13e000001',
1398
- [160, 220, 180, 190, true]
1399
- ],
1400
- [
1401
- '0x000000000000000016345785d8a0000000000000000000001bc16d674ec80000000000000000000018fae27693b4000000000000000000001a5e27eef13e000000',
1402
- [160, 200, 180, 190, false]
1403
- ],
1404
- ];
1405
-
1406
- examples.forEach(([expected, actual]) => {
1407
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1408
- expect(sparkEncode.leverageManagement(...actual)).to.eql(expected);
1409
- });
1410
- });
1411
- });
1412
-
1413
- describe('closeToAsset()', () => {
1414
- const examples: Array<[
1415
- [StrategyOrBundleIds, boolean, TriggerData, SubData],
1416
- [
1417
- strategyOrBundleId: number,
1418
- isBundle: boolean,
1419
- triggerData: {
1420
- baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: number, ratioState: RatioState
1421
- },
1422
- subData: {
1423
- collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number,
1424
- },
1425
- ]
1426
- ]> = [
1427
- [
1428
- [
1429
- Bundles.MainnetIds.SPARK_CLOSE_TO_COLLATERAL,
1430
- true,
1431
- ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000006b175474e89094c44da98b954eedeac495271d0f00000000000000000000000000000000000000000000000000000026e1f9c6000000000000000000000000000000000000000000000000000000000000000000'],
1432
- [
1433
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000000000000000000000000000000000000000000015',
1434
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000020',
1435
- '0x0000000000000000000000000000000000000000000000000000000000000000',
1436
- ],
1437
- ],
1438
- [
1439
- Bundles.MainnetIds.SPARK_CLOSE_TO_COLLATERAL,
1440
- true,
1441
- {
1442
- baseTokenAddress: getAssetInfo('WETH').address, quoteTokenAddress: getAssetInfo('DAI').address, price: 1670, ratioState: RatioState.OVER
1443
- },
1444
- {
1445
- collAsset: getAssetInfo('WETH').address, collAssetId: 21, debtAsset: getAssetInfo('DAI').address, debtAssetId: 32,
1446
- },
1447
- ]
1448
- ],
1449
- [
1450
- [
1451
- Bundles.MainnetIds.SPARK_CLOSE_TO_DEBT,
1452
- true,
1453
- ['0x000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000000000000000000000000000000000000000084d000000000000000000000000000000000000000000000000000000000000000001'],
1454
- [
1455
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000015',
1456
- '0x000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca', '0x0000000000000000000000000000000000000000000000000000000000000020',
1457
- '0x0000000000000000000000000000000000000000000000000000000000000000',
1458
- ],
1459
- ],
1460
- [
1461
- Bundles.MainnetIds.SPARK_CLOSE_TO_DEBT,
1462
- true,
1463
- {
1464
- baseTokenAddress: getAssetInfo('LINK').address, quoteTokenAddress: getAssetInfo('DAI').address, price: 0.00544, ratioState: RatioState.UNDER
1465
- },
1466
- {
1467
- collAsset: getAssetInfo('DAI').address, collAssetId: 21, debtAsset: getAssetInfo('LINK').address, debtAssetId: 32,
1468
- },
1469
- ]
1470
- ]
1471
- ];
1472
-
1473
- examples.forEach(([expected, actual]) => {
1474
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1475
- expect(sparkEncode.closeToAsset(...actual)).to.eql(expected);
1476
- });
1477
- });
1478
- });
1479
- });
1480
-
1481
1391
  describe('When testing strategySubService.crvUSDEncode', () => {
1482
1392
  describe('leverageManagement()', () => {
1483
1393
  const examples: Array<[
@@ -1581,6 +1491,7 @@ describe('Feature: strategySubService.ts', () => {
1581
1491
  });
1582
1492
  });
1583
1493
  });
1494
+
1584
1495
  describe('When testing strategySubService.morphoBlueEncode', () => {
1585
1496
  describe('leverageManagement()', () => {
1586
1497
  const examples: Array<[
@@ -1709,5 +1620,4 @@ describe('Feature: strategySubService.ts', () => {
1709
1620
  });
1710
1621
  });
1711
1622
  });
1712
-
1713
1623
  });
@@ -557,25 +557,24 @@ export const sparkEncode = {
557
557
 
558
558
  return subInput;
559
559
  },
560
- closeToAsset(
560
+ closeOnPriceGeneric(
561
561
  strategyOrBundleId: number,
562
- isBundle: boolean = true,
563
- triggerData: {
564
- baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: number, ratioState: RatioState
565
- },
566
- subData: {
567
- collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number,
568
- },
562
+ collAsset: EthereumAddress,
563
+ collAssetId: number,
564
+ debtAsset: EthereumAddress,
565
+ debtAssetId: number,
566
+ marketAddr: EthereumAddress,
567
+ user: EthereumAddress,
568
+ stopLossPrice: number = 0,
569
+ stopLossType: CloseToAssetType = CloseToAssetType.DEBT,
570
+ takeProfitPrice: number = 0,
571
+ takeProfitType: CloseToAssetType = CloseToAssetType.COLLATERAL,
569
572
  ) {
570
- const {
571
- collAsset, collAssetId, debtAsset, debtAssetId,
572
- } = subData;
573
- const subDataEncoded = subDataService.sparkQuotePriceSubData.encode(collAsset, collAssetId, debtAsset, debtAssetId);
573
+ const isBundle = true;
574
+ const closeType = getCloseStrategyType(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
574
575
 
575
- const {
576
- baseTokenAddress, quoteTokenAddress, price, ratioState,
577
- } = triggerData;
578
- const triggerDataEncoded = triggerService.sparkQuotePriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, ratioState);
576
+ const subDataEncoded = subDataService.sparkCloseGenericSubData.encode(collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr, user);
577
+ const triggerDataEncoded = triggerService.sparkQuotePriceRangeTrigger.encode(collAsset, debtAsset, stopLossPrice, takeProfitPrice);
579
578
 
580
579
  return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
581
580
  },
@@ -4,12 +4,11 @@ import { getAssetInfo } from '@defisaver/tokens';
4
4
  import * as web3Utils from 'web3-utils';
5
5
  import { MAXUINT } from '@defisaver/tokens';
6
6
 
7
- import { ChainId, CloseStrategyType, CloseToAssetType, OrderType, RatioState } from '../types/enums';
7
+ import { ChainId, CloseStrategyType, OrderType, RatioState } from '../types/enums';
8
8
  import type { EthereumAddress, SubData } from '../types';
9
9
 
10
10
  import '../configuration';
11
11
  import * as subDataService from './subDataService';
12
- import { AAVE_V3_VARIABLE_BORROW_RATE } from '../constants';
13
12
 
14
13
  describe('Feature: subDataService.ts', () => {
15
14
 
@@ -941,82 +940,6 @@ describe('Feature: subDataService.ts', () => {
941
940
  });
942
941
  });
943
942
 
944
- describe('When testing subDataService.sparkQuotePriceSubData', () => {
945
- describe('encode()', () => {
946
- const examples: Array<[SubData, [collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, nullAddress?: EthereumAddress]]> = [
947
- [
948
- [
949
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000000000000000000000000000000000000000000002',
950
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000004',
951
- '0x0000000000000000000000000000000000000000000000000000000000000000',
952
- ],
953
- [
954
- web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
955
- 2,
956
- web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
957
- 4,
958
- ]
959
- ],
960
- [
961
- [
962
- '0x0000000000000000000000005979d7b546e38e414f7e9822514be443a4800529', '0x0000000000000000000000000000000000000000000000000000000000000006',
963
- '0x000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e5831', '0x0000000000000000000000000000000000000000000000000000000000000002',
964
- '0x0000000000000000000000000000000000000000000000000000000000000000',
965
- ],
966
- [
967
- web3Utils.toChecksumAddress(getAssetInfo('wstETH', ChainId.Arbitrum).address),
968
- 6,
969
- web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
970
- 2,
971
- ]
972
- ],
973
- ];
974
-
975
- examples.forEach(([expected, actual]) => {
976
- it(`Given ${actual} should return expected value: ${expected}`, () => {
977
- expect(subDataService.sparkQuotePriceSubData.encode(...actual)).to.eql(expected);
978
- });
979
- });
980
- });
981
-
982
- describe('decode()', () => {
983
- const examples: Array<[{ collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number }, SubData]> = [
984
- [
985
- {
986
- collAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
987
- collAssetId: 2,
988
- debtAsset: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
989
- debtAssetId: 4,
990
- },
991
- [
992
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000000000000000000000000000000000000000000002',
993
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000004',
994
- '0x0000000000000000000000000000000000000000000000000000000000000000',
995
- ],
996
- ],
997
- [
998
- {
999
- collAsset: web3Utils.toChecksumAddress(getAssetInfo('wstETH', ChainId.Arbitrum).address),
1000
- collAssetId: 6,
1001
- debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
1002
- debtAssetId: 2,
1003
- },
1004
- [
1005
- '0x0000000000000000000000005979d7b546e38e414f7e9822514be443a4800529', '0x0000000000000000000000000000000000000000000000000000000000000006',
1006
- '0x000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e5831', '0x0000000000000000000000000000000000000000000000000000000000000002',
1007
- '0x0000000000000000000000000000000000000000000000000000000000000000',
1008
- ],
1009
- ],
1010
- ];
1011
-
1012
- examples.forEach(([expected, actual]) => {
1013
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1014
- expect(subDataService.sparkQuotePriceSubData.decode(actual)).to.eql(expected);
1015
- });
1016
- });
1017
- });
1018
- });
1019
-
1020
943
  describe('When testing subDataService.liquityDsrPaybackSubData', () => {
1021
944
  describe('encode()', () => {
1022
945
  const examples: Array<[SubData, [targetRatio: number]]> = [
@@ -593,37 +593,6 @@ export const sparkLeverageManagementSubData = { // TODO encode?
593
593
  },
594
594
  };
595
595
 
596
- export const sparkQuotePriceSubData = {
597
- encode(
598
- collAsset: EthereumAddress,
599
- collAssetId: number,
600
- debtAsset: EthereumAddress,
601
- debtAssetId: number,
602
- nullAddress: EthereumAddress = ZERO_ADDRESS,
603
- ): SubData {
604
- const encodedColl = AbiCoder.encodeParameter('address', collAsset);
605
- const encodedCollId = AbiCoder.encodeParameter('uint8', collAssetId);
606
-
607
- const encodedDebt = AbiCoder.encodeParameter('address', debtAsset);
608
- const encodedDebtId = AbiCoder.encodeParameter('uint8', debtAssetId);
609
-
610
- const encodedNullAddress = AbiCoder.encodeParameter('address', nullAddress);
611
-
612
- return [encodedColl, encodedCollId, encodedDebt, encodedDebtId, encodedNullAddress];
613
- },
614
- decode(subData: SubData): { collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number } {
615
- const collAsset = AbiCoder.decodeParameter('address', subData[0]) as unknown as EthereumAddress;
616
- const collAssetId = Number(AbiCoder.decodeParameter('uint8', subData[1]));
617
-
618
- const debtAsset = AbiCoder.decodeParameter('address', subData[2]) as unknown as EthereumAddress;
619
- const debtAssetId = Number(AbiCoder.decodeParameter('uint8', subData[3]));
620
-
621
- return {
622
- collAsset, collAssetId, debtAsset, debtAssetId,
623
- };
624
- },
625
- };
626
-
627
596
  export const liquityDsrPaybackSubData = {
628
597
  encode: (targetRatio: number) => {
629
598
  const daiAddress = getAssetInfo('DAI').address;
@@ -1191,3 +1160,55 @@ export const compoundV3CloseSubData = {
1191
1160
  };
1192
1161
  },
1193
1162
  };
1163
+
1164
+ export const sparkCloseGenericSubData = {
1165
+ encode(
1166
+ collAsset: EthereumAddress,
1167
+ collAssetId: number,
1168
+ debtAsset: EthereumAddress,
1169
+ debtAssetId: number,
1170
+ closeType: CloseStrategyType,
1171
+ marketAddr: EthereumAddress,
1172
+ user: EthereumAddress,
1173
+ ): SubData {
1174
+ const encodedColl = AbiCoder.encodeParameter('address', collAsset);
1175
+ const encodedCollId = AbiCoder.encodeParameter('uint8', collAssetId);
1176
+ const encodedDebt = AbiCoder.encodeParameter('address', debtAsset);
1177
+ const encodedDebtId = AbiCoder.encodeParameter('uint8', debtAssetId);
1178
+ const encodedCloseType = AbiCoder.encodeParameter('uint8', closeType);
1179
+ const encodedMarket = AbiCoder.encodeParameter('address', marketAddr);
1180
+ const userEncoded = AbiCoder.encodeParameter('address', user);
1181
+
1182
+ return [
1183
+ encodedColl,
1184
+ encodedCollId,
1185
+ encodedDebt,
1186
+ encodedDebtId,
1187
+ encodedCloseType,
1188
+ encodedMarket,
1189
+ userEncoded,
1190
+ ];
1191
+ },
1192
+
1193
+ decode(subData: SubData): {
1194
+ collAsset: EthereumAddress,
1195
+ collAssetId: number,
1196
+ debtAsset: EthereumAddress,
1197
+ debtAssetId: number,
1198
+ closeType: CloseStrategyType,
1199
+ marketAddr: EthereumAddress,
1200
+ owner: EthereumAddress,
1201
+ } {
1202
+ const collAsset = AbiCoder.decodeParameter('address', subData[0]) as unknown as EthereumAddress;
1203
+ const collAssetId = Number(AbiCoder.decodeParameter('uint8', subData[1]));
1204
+ const debtAsset = AbiCoder.decodeParameter('address', subData[2]) as unknown as EthereumAddress;
1205
+ const debtAssetId = Number(AbiCoder.decodeParameter('uint8', subData[3]));
1206
+ const closeType = Number(AbiCoder.decodeParameter('uint8', subData[4])) as CloseStrategyType;
1207
+ const marketAddr = AbiCoder.decodeParameter('address', subData[5]) as unknown as EthereumAddress;
1208
+ const owner = AbiCoder.decodeParameter('address', subData[6]) as unknown as EthereumAddress;
1209
+
1210
+ return {
1211
+ collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr, owner,
1212
+ };
1213
+ },
1214
+ };
@@ -23,7 +23,6 @@ import {
23
23
  liquityDebtInFrontTrigger,
24
24
  makerRatioTrigger,
25
25
  morphoAaveV2RatioTrigger,
26
- sparkQuotePriceTrigger,
27
26
  sparkRatioTrigger,
28
27
  trailingStopTrigger,
29
28
  liquityDebtInFrontWithLimitTrigger,
@@ -879,56 +878,6 @@ describe('Feature: triggerService.ts', () => {
879
878
  });
880
879
  });
881
880
 
882
- describe('When testing triggerService.sparkQuotePriceTrigger', () => {
883
- describe('encode()', () => {
884
- const examples: Array<[[string], [baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: number, ratioState: RatioState]]> = [
885
- [
886
- ['0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000000000000000000000000000000000000000a8ca0000000000000000000000000000000000000000000000000000000000000001'],
887
- [getAssetInfo('DAI', ChainId.Ethereum).address, getAssetInfo('wstETH', ChainId.Ethereum).address, 0.0004321, RatioState.UNDER]
888
- ],
889
- [
890
- ['0x0000000000000000000000002f2a2543b76a4166549f7aab2e75bef0aefc5b0f000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e583100000000000000000000000000000000000000000000000000000000000186b70000000000000000000000000000000000000000000000000000000000000000'],
891
- [getAssetInfo('WBTC', ChainId.Arbitrum).address, getAssetInfo('USDC', ChainId.Arbitrum).address, 0.00100023, RatioState.OVER]
892
- ],
893
- ];
894
-
895
- examples.forEach(([expected, actual]) => {
896
- it(`Given ${actual} should return expected value: ${expected}`, () => {
897
- expect(sparkQuotePriceTrigger.encode(...actual)).to.eql(expected);
898
- });
899
- });
900
- });
901
-
902
- describe('decode()', () => {
903
- const examples: Array<[{ baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: string, ratioState: RatioState }, TriggerData]> = [
904
- [
905
- {
906
- baseTokenAddress: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
907
- quoteTokenAddress: web3Utils.toChecksumAddress(getAssetInfo('wstETH', ChainId.Ethereum).address),
908
- price: '0.0004321',
909
- ratioState: RatioState.UNDER,
910
- },
911
- ['0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000000000000000000000000000000000000000a8ca0000000000000000000000000000000000000000000000000000000000000001'],
912
- ],
913
- [
914
- {
915
- baseTokenAddress: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Arbitrum).address),
916
- quoteTokenAddress: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
917
- price: '0.00100023',
918
- ratioState: RatioState.OVER,
919
- },
920
- ['0x0000000000000000000000002f2a2543b76a4166549f7aab2e75bef0aefc5b0f000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e583100000000000000000000000000000000000000000000000000000000000186b70000000000000000000000000000000000000000000000000000000000000000'],
921
- ]
922
- ];
923
-
924
- examples.forEach(([expected, actual]) => {
925
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
926
- expect(sparkQuotePriceTrigger.decode(actual)).to.eql(expected);
927
- });
928
- });
929
- });
930
- });
931
-
932
881
  describe('When testing triggerService.curveUsdBorrowRateTrigger', () => {
933
882
  describe('encode()', () => {
934
883
  const examples: Array<[[string], [market: EthereumAddress, targetRate: string, rateState: RatioState]]> = [
@@ -328,32 +328,6 @@ export const sparkRatioTrigger = {
328
328
  },
329
329
  };
330
330
 
331
- export const sparkQuotePriceTrigger = {
332
- encode(
333
- baseTokenAddress: EthereumAddress,
334
- quoteTokenAddress: EthereumAddress,
335
- price: number,
336
- ratioState: RatioState,
337
- ) {
338
- // Price is always in 8 decimals
339
- const _price = new Dec(price.toString()).mul(10 ** 8).floor().toString();
340
- return [AbiCoder.encodeParameters(['address', 'address', 'uint256', 'uint8'], [baseTokenAddress, quoteTokenAddress, _price, ratioState])];
341
- },
342
- decode(
343
- triggerData: TriggerData,
344
- ): { baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: string, ratioState: RatioState } {
345
- const decodedData = AbiCoder.decodeParameters(['address', 'address', 'uint256', 'uint8'], triggerData[0]);
346
- // Price is always in 8 decimals
347
- const price = new Dec(decodedData[2] as string).div(10 ** 8).toDP(8).toString();
348
- return {
349
- price,
350
- baseTokenAddress: decodedData[0] as EthereumAddress,
351
- quoteTokenAddress: decodedData[1] as EthereumAddress,
352
- ratioState: +decodedData[3]!,
353
- };
354
- },
355
- };
356
-
357
331
  export const curveUsdBorrowRateTrigger = {
358
332
  encode(
359
333
  market: EthereumAddress,
@@ -685,4 +659,33 @@ export const aaveV3QuotePriceRangeTrigger = {
685
659
  upperPrice: new Dec(decodedData[3] as string).div(1e8).toString(),
686
660
  };
687
661
  },
662
+ };
663
+
664
+ export const sparkQuotePriceRangeTrigger = {
665
+ encode(
666
+ collToken: EthereumAddress,
667
+ debtToken: EthereumAddress,
668
+ lowerPrice: number,
669
+ upperPrice: number,
670
+ ) {
671
+ // Price is scaled to 1e8
672
+ const lowerPriceFormatted = new Dec(lowerPrice).mul(1e8).floor().toString();
673
+ const upperPriceFormatted = new Dec(upperPrice).mul(1e8).floor().toString();
674
+ return [
675
+ AbiCoder.encodeParameters(
676
+ ['address', 'address', 'uint256', 'uint256'],
677
+ [collToken, debtToken, lowerPriceFormatted, upperPriceFormatted]),
678
+ ];
679
+ },
680
+ decode(
681
+ triggerData: TriggerData,
682
+ ) {
683
+ const decodedData = AbiCoder.decodeParameters(['address', 'address', 'uint256', 'uint256'], triggerData[0]);
684
+ return {
685
+ collToken: decodedData[0] as EthereumAddress,
686
+ debtToken: decodedData[1] as EthereumAddress,
687
+ lowerPrice: new Dec(decodedData[2] as string).div(1e8).toString(),
688
+ upperPrice: new Dec(decodedData[3] as string).div(1e8).toString(),
689
+ };
690
+ },
688
691
  };