@defisaver/automation-sdk 3.3.10-aave-v4-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 +2 -2
  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
@@ -672,6 +672,29 @@ function parseSparkLeverageManagement(position, parseData) {
672
672
  _position.strategy.strategyId = Strategies.IdOverrides.LeverageManagement;
673
673
  return _position;
674
674
  }
675
+ function parseSparkLeverageManagementOnPrice(position, parseData) {
676
+ const _position = cloneDeep(position);
677
+ const { subStruct } = parseData.subscriptionEventData;
678
+ const triggerData = triggerService.sparkQuotePriceTrigger.decode(subStruct.triggerData);
679
+ const subData = subDataService.sparkLeverageManagementOnPriceSubData.decode(subStruct.subData);
680
+ _position.strategyData.decoded.triggerData = triggerData;
681
+ _position.strategyData.decoded.subData = subData;
682
+ _position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, subData.marketAddr);
683
+ _position.specific = {
684
+ // subData
685
+ collAsset: subData.collAsset,
686
+ collAssetId: subData.collAssetId,
687
+ debtAsset: subData.debtAsset,
688
+ debtAssetId: subData.debtAssetId,
689
+ ratio: subData.targetRatio,
690
+ // triggerData
691
+ baseToken: triggerData.baseTokenAddr,
692
+ quoteToken: triggerData.quoteTokenAddr,
693
+ price: triggerData.price,
694
+ ratioState: triggerData.ratioState,
695
+ };
696
+ return _position;
697
+ }
675
698
  function parseSparkCloseOnPrice(position, parseData) {
676
699
  const _position = cloneDeep(position);
677
700
  const { subStruct } = parseData.subscriptionEventData;
@@ -1045,6 +1068,8 @@ const parsingMethodsMapping = {
1045
1068
  [ProtocolIdentifiers.StrategiesAutomation.Spark]: {
1046
1069
  [Strategies.Identifiers.Repay]: parseSparkLeverageManagement,
1047
1070
  [Strategies.Identifiers.Boost]: parseSparkLeverageManagement,
1071
+ [Strategies.Identifiers.RepayOnPrice]: parseSparkLeverageManagementOnPrice,
1072
+ [Strategies.Identifiers.BoostOnPrice]: parseSparkLeverageManagementOnPrice,
1048
1073
  [Strategies.Identifiers.CloseOnPrice]: parseSparkCloseOnPrice,
1049
1074
  },
1050
1075
  [ProtocolIdentifiers.StrategiesAutomation.CrvUSD]: {
@@ -86,6 +86,19 @@ export declare const exchangeEncode: {
86
86
  };
87
87
  export declare const sparkEncode: {
88
88
  leverageManagement(triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean): string;
89
+ leverageManagementOnPrice(strategyOrBundleId: number, isBundle: boolean | undefined, triggerData: {
90
+ baseTokenAddr: EthereumAddress;
91
+ quoteTokenAddr: EthereumAddress;
92
+ price: number;
93
+ ratioState: RatioState;
94
+ }, subData: {
95
+ collAsset: EthereumAddress;
96
+ collAssetId: number;
97
+ debtAsset: EthereumAddress;
98
+ debtAssetId: number;
99
+ marketAddr: EthereumAddress;
100
+ targetRatio: number;
101
+ }): (number | boolean | string[])[];
89
102
  closeOnPriceGeneric(strategyOrBundleId: number, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, marketAddr: EthereumAddress, user: EthereumAddress, stopLossPrice?: number, stopLossType?: CloseToAssetType, takeProfitPrice?: number, takeProfitType?: CloseToAssetType): (number | boolean | string[])[];
90
103
  leverageManagementWithoutSubProxy(strategyOrBundleId: number, market: EthereumAddress, user: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number): (number | boolean | string[])[];
91
104
  };
@@ -243,6 +243,13 @@ export const sparkEncode = {
243
243
  subInput = subInput.concat(boostEnabled ? '01' : '00');
244
244
  return subInput;
245
245
  },
246
+ leverageManagementOnPrice(strategyOrBundleId, isBundle = true, triggerData, subData) {
247
+ const { collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio, } = subData;
248
+ const subDataEncoded = subDataService.sparkLeverageManagementOnPriceSubData.encode(collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio);
249
+ const { baseTokenAddr, quoteTokenAddr, price, ratioState, } = triggerData;
250
+ const triggerDataEncoded = triggerService.sparkQuotePriceTrigger.encode(baseTokenAddr, quoteTokenAddr, price, ratioState);
251
+ return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
252
+ },
246
253
  closeOnPriceGeneric(strategyOrBundleId, collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, user, stopLossPrice = 0, stopLossType = CloseToAssetType.DEBT, takeProfitPrice = 0, takeProfitType = CloseToAssetType.COLLATERAL) {
247
254
  const isBundle = true;
248
255
  const closeType = getCloseStrategyType(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
@@ -5,7 +5,7 @@ import { getAssetInfo, MAXUINT } from '@defisaver/tokens';
5
5
  import * as web3Utils from 'web3-utils';
6
6
  import { Bundles, ChainId, CloseToAssetType, OrderType, RatioState, Strategies } from '../types/enums';
7
7
  import '../configuration';
8
- import { aaveV2Encode, chickenBondsEncode, liquityEncode, makerEncode, aaveV3Encode, compoundV2Encode, compoundV3Encode, morphoAaveV2Encode, exchangeEncode, crvUSDEncode, compoundV3L2Encode, morphoBlueEncode, aaveV4Encode, } from './strategySubService';
8
+ import { aaveV2Encode, chickenBondsEncode, liquityEncode, makerEncode, aaveV3Encode, compoundV2Encode, compoundV3Encode, morphoAaveV2Encode, exchangeEncode, crvUSDEncode, compoundV3L2Encode, morphoBlueEncode, sparkEncode, aaveV4Encode, } from './strategySubService';
9
9
  describe('Feature: strategySubService.ts', () => {
10
10
  describe('When testing strategySubService.makerEncode', () => {
11
11
  // @ts-ignore // TODO - this requires change in @defisaver/tokens
@@ -1453,6 +1453,139 @@ describe('Feature: strategySubService.ts', () => {
1453
1453
  });
1454
1454
  });
1455
1455
  });
1456
+ describe('When testing strategySubService.sparkEncode', () => {
1457
+ describe('leverageManagement()', () => {
1458
+ const examples = [
1459
+ [
1460
+ '0x0000000000000000136dcc951d8c00000000000000000000214e8348c4f0000000000000000000001d24b2dfac52000000000000000000001a5e27eef13e000001',
1461
+ [140, 240, 210, 190, true]
1462
+ ],
1463
+ [
1464
+ '0x0000000000000000130337bdce49000000000000000000001988fe4052b800000000000000000000281b57b028e1000000000000000000002223acf76376000000',
1465
+ [137, 184, 289, 246, false]
1466
+ ]
1467
+ ];
1468
+ examples.forEach(([expected, actual]) => {
1469
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1470
+ expect(sparkEncode.leverageManagement(...actual)).to.eql(expected);
1471
+ });
1472
+ });
1473
+ });
1474
+ describe('leverageManagementOnPrice()', () => {
1475
+ const examples = [
1476
+ [
1477
+ [
1478
+ Bundles.MainnetIds.SPARK_REPAY_ON_PRICE,
1479
+ true,
1480
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000003a352944000000000000000000000000000000000000000000000000000000000000000001'],
1481
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1482
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1483
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1484
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1485
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
1486
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
1487
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1488
+ ],
1489
+ ],
1490
+ [
1491
+ 59,
1492
+ true,
1493
+ {
1494
+ baseTokenAddr: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1495
+ quoteTokenAddr: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1496
+ price: 2500,
1497
+ ratioState: RatioState.UNDER,
1498
+ },
1499
+ {
1500
+ collAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1501
+ collAssetId: 0,
1502
+ debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1503
+ debtAssetId: 1,
1504
+ marketAddr: web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
1505
+ targetRatio: 200,
1506
+ },
1507
+ ]
1508
+ ],
1509
+ [
1510
+ [
1511
+ Bundles.MainnetIds.SPARK_BOOST_ON_PRICE,
1512
+ true,
1513
+ ['0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000006b175474e89094c44da98b954eedeac495271d0f00000000000000000000000000000000000000000000000000000417bce6c8000000000000000000000000000000000000000000000000000000000000000000'],
1514
+ [
1515
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
1516
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
1517
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
1518
+ '0x0000000000000000000000000000000000000000000000000000000000000004',
1519
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
1520
+ '0x00000000000000000000000000000000000000000000000022b1c8c1227a0000',
1521
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1522
+ ]
1523
+ ],
1524
+ [
1525
+ 60,
1526
+ true,
1527
+ {
1528
+ baseTokenAddr: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
1529
+ quoteTokenAddr: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
1530
+ price: 45000,
1531
+ ratioState: RatioState.OVER,
1532
+ },
1533
+ {
1534
+ collAsset: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
1535
+ collAssetId: 2,
1536
+ debtAsset: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
1537
+ debtAssetId: 4,
1538
+ marketAddr: web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
1539
+ targetRatio: 250,
1540
+ },
1541
+ ]
1542
+ ]
1543
+ ];
1544
+ examples.forEach(([expected, actual]) => {
1545
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1546
+ expect(sparkEncode.leverageManagementOnPrice(...actual)).to.eql(expected);
1547
+ });
1548
+ });
1549
+ });
1550
+ describe('closeOnPrice()', () => {
1551
+ const examples = [
1552
+ [
1553
+ [
1554
+ Bundles.MainnetIds.SPARK_CLOSE,
1555
+ true,
1556
+ ['0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000000000000000000000000000000003a35294400000000000000000000000000000000000000000000000000000000574fbde6000'],
1557
+ [
1558
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
1559
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
1560
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
1561
+ '0x0000000000000000000000000000000000000000000000000000000000000004',
1562
+ '0x0000000000000000000000000000000000000000000000000000000000000005',
1563
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
1564
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
1565
+ ]
1566
+ ],
1567
+ [
1568
+ 57,
1569
+ web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
1570
+ 2,
1571
+ web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
1572
+ 4,
1573
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
1574
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
1575
+ 40000,
1576
+ CloseToAssetType.DEBT,
1577
+ 60000,
1578
+ CloseToAssetType.COLLATERAL,
1579
+ ]
1580
+ ],
1581
+ ];
1582
+ examples.forEach(([expected, actual]) => {
1583
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1584
+ expect(sparkEncode.closeOnPriceGeneric(...actual)).to.eql(expected);
1585
+ });
1586
+ });
1587
+ });
1588
+ });
1456
1589
  describe('When testing strategySubService.aaveV4Encode', () => {
1457
1590
  describe('leverageManagement()', () => {
1458
1591
  const examples = [
@@ -418,6 +418,17 @@ export declare const sparkCloseGenericSubData: {
418
418
  owner: EthereumAddress;
419
419
  };
420
420
  };
421
+ export declare const sparkLeverageManagementOnPriceSubData: {
422
+ encode(collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, marketAddr: EthereumAddress, targetRatio: number): string[];
423
+ decode(subData: string[]): {
424
+ collAsset: EthereumAddress;
425
+ collAssetId: number;
426
+ debtAsset: EthereumAddress;
427
+ debtAssetId: number;
428
+ marketAddr: EthereumAddress;
429
+ targetRatio: number;
430
+ };
431
+ };
421
432
  /**
422
433
  ______ .______ ____ ____ __ __ _______. _______
423
434
  / || _ \ \ \ / / | | | | / || \
@@ -943,6 +943,30 @@ export const sparkCloseGenericSubData = {
943
943
  };
944
944
  },
945
945
  };
946
+ export const sparkLeverageManagementOnPriceSubData = {
947
+ encode(collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio) {
948
+ const encodedColl = AbiCoder.encodeParameter('address', collAsset);
949
+ const encodedCollId = AbiCoder.encodeParameter('uint16', collAssetId);
950
+ const encodedDebt = AbiCoder.encodeParameter('address', debtAsset);
951
+ const encodedDebtId = AbiCoder.encodeParameter('uint16', debtAssetId);
952
+ const encodedMarket = AbiCoder.encodeParameter('address', marketAddr);
953
+ const encodedTargetRatio = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
954
+ const useOnBehalfEncoded = AbiCoder.encodeParameter('bool', false);
955
+ return [encodedColl, encodedCollId, encodedDebt, encodedDebtId, encodedMarket, encodedTargetRatio, useOnBehalfEncoded];
956
+ },
957
+ decode(subData) {
958
+ const collAsset = AbiCoder.decodeParameter('address', subData[0]);
959
+ const collAssetId = Number(AbiCoder.decodeParameter('uint16', subData[1]));
960
+ const debtAsset = AbiCoder.decodeParameter('address', subData[2]);
961
+ const debtAssetId = Number(AbiCoder.decodeParameter('uint16', subData[3]));
962
+ const marketAddr = AbiCoder.decodeParameter('address', subData[4]);
963
+ const weiRatio = AbiCoder.decodeParameter('uint256', subData[5]);
964
+ const targetRatio = weiToRatioPercentage(weiRatio);
965
+ return {
966
+ collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio,
967
+ };
968
+ },
969
+ };
946
970
  /**
947
971
  ______ .______ ____ ____ __ __ _______. _______
948
972
  / || _ \ \ \ / / | | | | / || \
@@ -2061,6 +2061,63 @@ describe('Feature: subDataService.ts', () => {
2061
2061
  });
2062
2062
  });
2063
2063
  });
2064
+ describe('When testing subDataService.sparkLeverageManagementOnPriceSubData', () => {
2065
+ describe('encode()', () => {
2066
+ const examples = [
2067
+ [
2068
+ [
2069
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
2070
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
2071
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
2072
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
2073
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
2074
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
2075
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
2076
+ ],
2077
+ [
2078
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
2079
+ 0,
2080
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
2081
+ 1,
2082
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
2083
+ 200,
2084
+ ]
2085
+ ]
2086
+ ];
2087
+ examples.forEach(([expected, actual]) => {
2088
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
2089
+ expect(subDataService.sparkLeverageManagementOnPriceSubData.encode(...actual)).to.eql(expected);
2090
+ });
2091
+ });
2092
+ });
2093
+ describe('decode()', () => {
2094
+ const examples = [
2095
+ [
2096
+ {
2097
+ collAsset: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
2098
+ collAssetId: 2,
2099
+ debtAsset: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
2100
+ debtAssetId: 4,
2101
+ marketAddr: web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
2102
+ targetRatio: 175
2103
+ },
2104
+ [
2105
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
2106
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
2107
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
2108
+ '0x0000000000000000000000000000000000000000000000000000000000000004',
2109
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
2110
+ '0x00000000000000000000000000000000000000000000000018493fba64ef0000'
2111
+ ]
2112
+ ]
2113
+ ];
2114
+ examples.forEach(([expected, actual]) => {
2115
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
2116
+ expect(subDataService.sparkLeverageManagementOnPriceSubData.decode(actual)).to.eql(expected);
2117
+ });
2118
+ });
2119
+ });
2120
+ });
2064
2121
  describe('When testing subDataService.aaveV4LeverageManagementSubData', () => {
2065
2122
  describe('encode()', () => {
2066
2123
  const examples = [
@@ -285,6 +285,15 @@ export declare const morphoBluePriceRangeTrigger: {
285
285
  upperPrice: string;
286
286
  };
287
287
  };
288
+ export declare const sparkQuotePriceTrigger: {
289
+ encode(baseTokenAddr: EthereumAddress, quoteTokenAddr: EthereumAddress, price: number, ratioState: RatioState): string[];
290
+ decode(triggerData: string[]): {
291
+ baseTokenAddr: string;
292
+ quoteTokenAddr: string;
293
+ price: string;
294
+ ratioState: number;
295
+ };
296
+ };
288
297
  export declare const aaveV4RatioTrigger: {
289
298
  encode(owner: EthereumAddress, spoke: EthereumAddress, ratioPercentage: number, ratioState: RatioState): string[];
290
299
  decode(triggerData: string[]): {
@@ -518,6 +518,21 @@ export const morphoBluePriceRangeTrigger = {
518
518
  };
519
519
  },
520
520
  };
521
+ export const sparkQuotePriceTrigger = {
522
+ encode(baseTokenAddr, quoteTokenAddr, price, ratioState) {
523
+ const _price = new Dec(price.toString()).mul(1e8).floor().toString();
524
+ return [AbiCoder.encodeParameters(['address', 'address', 'uint256', 'uint8'], [baseTokenAddr, quoteTokenAddr, _price, ratioState])];
525
+ },
526
+ decode(triggerData) {
527
+ const decodedData = AbiCoder.decodeParameters(['address', 'address', 'uint256', 'uint8'], triggerData[0]);
528
+ return {
529
+ baseTokenAddr: decodedData[0],
530
+ quoteTokenAddr: decodedData[1],
531
+ price: new Dec(decodedData[2]).div(1e8).toString(),
532
+ ratioState: Number(decodedData[3]),
533
+ };
534
+ },
535
+ };
521
536
  export const aaveV4RatioTrigger = {
522
537
  encode(owner, spoke, ratioPercentage, ratioState) {
523
538
  const ratioWei = ratioPercentageToWei(ratioPercentage);
@@ -3,7 +3,7 @@ import { getAssetInfo, MAXUINT } from '@defisaver/tokens';
3
3
  import * as web3Utils from 'web3-utils';
4
4
  import { ChainId, OrderType, RatioState } from '../types/enums';
5
5
  import '../configuration';
6
- import { aaveV2RatioTrigger, aaveV3QuotePriceTrigger, aaveV3QuotePriceWithMaximumGasPriceTrigger, aaveV3RatioTrigger, cBondsRebondTrigger, chainlinkPriceTrigger, compoundV2RatioTrigger, compoundV3RatioTrigger, compoundV3PriceTrigger, curveUsdBorrowRateTrigger, curveUsdSoftLiquidationTrigger, exchangeOffchainPriceTrigger, exchangeTimestampTrigger, liquityDebtInFrontTrigger, makerRatioTrigger, morphoAaveV2RatioTrigger, sparkRatioTrigger, trailingStopTrigger, liquityDebtInFrontWithLimitTrigger, crvUSDRatioTrigger, morphoBlueRatioTrigger, crvUsdHealthRatioTrigger, liquityV2DebtInFrontTrigger, liquityV2AdjustTimeTrigger, compoundV3PriceRangeTrigger, aaveV3QuotePriceRangeTrigger, morphoBluePriceRangeTrigger, aaveV4RatioTrigger, aaveV4QuotePriceTrigger, aaveV4QuotePriceRangeTrigger, } from './triggerService';
6
+ import { aaveV2RatioTrigger, aaveV3QuotePriceTrigger, aaveV3QuotePriceWithMaximumGasPriceTrigger, aaveV3RatioTrigger, cBondsRebondTrigger, chainlinkPriceTrigger, compoundV2RatioTrigger, compoundV3RatioTrigger, compoundV3PriceTrigger, curveUsdBorrowRateTrigger, curveUsdSoftLiquidationTrigger, exchangeOffchainPriceTrigger, exchangeTimestampTrigger, liquityDebtInFrontTrigger, makerRatioTrigger, morphoAaveV2RatioTrigger, sparkRatioTrigger, trailingStopTrigger, liquityDebtInFrontWithLimitTrigger, crvUSDRatioTrigger, morphoBlueRatioTrigger, crvUsdHealthRatioTrigger, liquityV2DebtInFrontTrigger, liquityV2AdjustTimeTrigger, compoundV3PriceRangeTrigger, aaveV3QuotePriceRangeTrigger, morphoBluePriceRangeTrigger, sparkQuotePriceTrigger, aaveV4RatioTrigger, aaveV4QuotePriceTrigger, aaveV4QuotePriceRangeTrigger, } from './triggerService';
7
7
  describe('Feature: triggerService.ts', () => {
8
8
  describe('When testing triggerService.chainlinkPriceTrigger', () => {
9
9
  describe('encode()', () => {
@@ -1243,4 +1243,50 @@ describe('Feature: triggerService.ts', () => {
1243
1243
  });
1244
1244
  });
1245
1245
  });
1246
+ describe('When testing triggerService.sparkQuotePriceTrigger', () => {
1247
+ describe('encode()', () => {
1248
+ const examples = [
1249
+ [
1250
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000003a352944000000000000000000000000000000000000000000000000000000000000000001'],
1251
+ [web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address), web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address), 2500, RatioState.UNDER]
1252
+ ],
1253
+ [
1254
+ ['0x000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec70000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000000000000000000000000000000000000000000c1c0000000000000000000000000000000000000000000000000000000000000000'],
1255
+ [web3Utils.toChecksumAddress(getAssetInfo('USDT', ChainId.Ethereum).address), web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address), 0.000031, RatioState.OVER]
1256
+ ],
1257
+ ];
1258
+ examples.forEach(([expected, actual]) => {
1259
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
1260
+ expect(sparkQuotePriceTrigger.encode(...actual)).to.eql(expected);
1261
+ });
1262
+ });
1263
+ });
1264
+ describe('decode()', () => {
1265
+ const examples = [
1266
+ [
1267
+ {
1268
+ baseTokenAddr: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1269
+ quoteTokenAddr: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1270
+ price: '2500',
1271
+ ratioState: RatioState.UNDER
1272
+ },
1273
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000003a352944000000000000000000000000000000000000000000000000000000000000000001']
1274
+ ],
1275
+ [
1276
+ {
1277
+ baseTokenAddr: web3Utils.toChecksumAddress(getAssetInfo('USDT', ChainId.Ethereum).address),
1278
+ quoteTokenAddr: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
1279
+ price: '0.000031',
1280
+ ratioState: RatioState.OVER
1281
+ },
1282
+ ['0x000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec70000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000000000000000000000000000000000000000000c1c0000000000000000000000000000000000000000000000000000000000000000']
1283
+ ]
1284
+ ];
1285
+ examples.forEach(([expected, actual]) => {
1286
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1287
+ expect(sparkQuotePriceTrigger.decode(actual)).to.eql(expected);
1288
+ });
1289
+ });
1290
+ });
1291
+ });
1246
1292
  });
@@ -88,7 +88,8 @@ export declare namespace Strategies {
88
88
  CURVEUSD_PAYBACK = 92,
89
89
  LIQUITY_V2_PAYBACK = 113,
90
90
  AAVE_V3_COLLATERAL_SWITCH = 135,
91
- AAVE_V4_COLLATERAL_SWITCH = 151
91
+ AAVE_V4_COLLATERAL_SWITCH = 154,
92
+ AAVE_V4_COLLATERAL_SWITCH_EOA = 165
92
93
  }
93
94
  enum OptimismIds {
94
95
  EXCHANGE_DCA = 8,
@@ -135,7 +136,8 @@ export declare namespace Strategies {
135
136
  RepayOnPrice = "repay-on-price",
136
137
  EoaBoostOnPrice = "eoa-boost-on-price",
137
138
  EoaRepayOnPrice = "eoa-repay-on-price",
138
- CollateralSwitch = "collateral-switch"
139
+ CollateralSwitch = "collateral-switch",
140
+ EoaCollateralSwitch = "eoa-collateral-switch"
139
141
  }
140
142
  enum IdOverrides {
141
143
  TakeProfit = "take-profit",
@@ -210,16 +212,18 @@ export declare namespace Bundles {
210
212
  AAVE_V3_EOA_CLOSE = 56,
211
213
  SPARK_CLOSE = 57,
212
214
  MORPHO_BLUE_CLOSE = 58,
213
- AAVE_V4_REPAY = 59,
214
- AAVE_V4_BOOST = 60,
215
- AAVE_V4_REPAY_ON_PRICE = 61,
216
- AAVE_V4_BOOST_ON_PRICE = 62,
217
- AAVE_V4_CLOSE = 63,
218
- AAVE_V4_EOA_REPAY = 64,
219
- AAVE_V4_EOA_BOOST = 65,
220
- AAVE_V4_EOA_REPAY_ON_PRICE = 66,
221
- AAVE_V4_EOA_BOOST_ON_PRICE = 67,
222
- AAVE_V4_EOA_CLOSE = 68
215
+ SPARK_REPAY_ON_PRICE = 59,
216
+ SPARK_BOOST_ON_PRICE = 60,
217
+ AAVE_V4_REPAY = 61,
218
+ AAVE_V4_BOOST = 62,
219
+ AAVE_V4_REPAY_ON_PRICE = 63,
220
+ AAVE_V4_BOOST_ON_PRICE = 64,
221
+ AAVE_V4_CLOSE = 65,
222
+ AAVE_V4_EOA_REPAY = 66,
223
+ AAVE_V4_EOA_BOOST = 67,
224
+ AAVE_V4_EOA_REPAY_ON_PRICE = 68,
225
+ AAVE_V4_EOA_BOOST_ON_PRICE = 69,
226
+ AAVE_V4_EOA_CLOSE = 70
223
227
  }
224
228
  enum OptimismIds {
225
229
  AAVE_V3_REPAY = 0,
@@ -101,7 +101,8 @@ export var Strategies;
101
101
  MainnetIds[MainnetIds["CURVEUSD_PAYBACK"] = 92] = "CURVEUSD_PAYBACK";
102
102
  MainnetIds[MainnetIds["LIQUITY_V2_PAYBACK"] = 113] = "LIQUITY_V2_PAYBACK";
103
103
  MainnetIds[MainnetIds["AAVE_V3_COLLATERAL_SWITCH"] = 135] = "AAVE_V3_COLLATERAL_SWITCH";
104
- MainnetIds[MainnetIds["AAVE_V4_COLLATERAL_SWITCH"] = 151] = "AAVE_V4_COLLATERAL_SWITCH";
104
+ MainnetIds[MainnetIds["AAVE_V4_COLLATERAL_SWITCH"] = 154] = "AAVE_V4_COLLATERAL_SWITCH";
105
+ MainnetIds[MainnetIds["AAVE_V4_COLLATERAL_SWITCH_EOA"] = 165] = "AAVE_V4_COLLATERAL_SWITCH_EOA";
105
106
  })(MainnetIds = Strategies.MainnetIds || (Strategies.MainnetIds = {}));
106
107
  let OptimismIds;
107
108
  (function (OptimismIds) {
@@ -153,6 +154,7 @@ export var Strategies;
153
154
  Identifiers["EoaBoostOnPrice"] = "eoa-boost-on-price";
154
155
  Identifiers["EoaRepayOnPrice"] = "eoa-repay-on-price";
155
156
  Identifiers["CollateralSwitch"] = "collateral-switch";
157
+ Identifiers["EoaCollateralSwitch"] = "eoa-collateral-switch";
156
158
  })(Identifiers = Strategies.Identifiers || (Strategies.Identifiers = {}));
157
159
  let IdOverrides;
158
160
  (function (IdOverrides) {
@@ -230,16 +232,18 @@ export var Bundles;
230
232
  MainnetIds[MainnetIds["AAVE_V3_EOA_CLOSE"] = 56] = "AAVE_V3_EOA_CLOSE";
231
233
  MainnetIds[MainnetIds["SPARK_CLOSE"] = 57] = "SPARK_CLOSE";
232
234
  MainnetIds[MainnetIds["MORPHO_BLUE_CLOSE"] = 58] = "MORPHO_BLUE_CLOSE";
233
- MainnetIds[MainnetIds["AAVE_V4_REPAY"] = 59] = "AAVE_V4_REPAY";
234
- MainnetIds[MainnetIds["AAVE_V4_BOOST"] = 60] = "AAVE_V4_BOOST";
235
- MainnetIds[MainnetIds["AAVE_V4_REPAY_ON_PRICE"] = 61] = "AAVE_V4_REPAY_ON_PRICE";
236
- MainnetIds[MainnetIds["AAVE_V4_BOOST_ON_PRICE"] = 62] = "AAVE_V4_BOOST_ON_PRICE";
237
- MainnetIds[MainnetIds["AAVE_V4_CLOSE"] = 63] = "AAVE_V4_CLOSE";
238
- MainnetIds[MainnetIds["AAVE_V4_EOA_REPAY"] = 64] = "AAVE_V4_EOA_REPAY";
239
- MainnetIds[MainnetIds["AAVE_V4_EOA_BOOST"] = 65] = "AAVE_V4_EOA_BOOST";
240
- MainnetIds[MainnetIds["AAVE_V4_EOA_REPAY_ON_PRICE"] = 66] = "AAVE_V4_EOA_REPAY_ON_PRICE";
241
- MainnetIds[MainnetIds["AAVE_V4_EOA_BOOST_ON_PRICE"] = 67] = "AAVE_V4_EOA_BOOST_ON_PRICE";
242
- MainnetIds[MainnetIds["AAVE_V4_EOA_CLOSE"] = 68] = "AAVE_V4_EOA_CLOSE";
235
+ MainnetIds[MainnetIds["SPARK_REPAY_ON_PRICE"] = 59] = "SPARK_REPAY_ON_PRICE";
236
+ MainnetIds[MainnetIds["SPARK_BOOST_ON_PRICE"] = 60] = "SPARK_BOOST_ON_PRICE";
237
+ MainnetIds[MainnetIds["AAVE_V4_REPAY"] = 61] = "AAVE_V4_REPAY";
238
+ MainnetIds[MainnetIds["AAVE_V4_BOOST"] = 62] = "AAVE_V4_BOOST";
239
+ MainnetIds[MainnetIds["AAVE_V4_REPAY_ON_PRICE"] = 63] = "AAVE_V4_REPAY_ON_PRICE";
240
+ MainnetIds[MainnetIds["AAVE_V4_BOOST_ON_PRICE"] = 64] = "AAVE_V4_BOOST_ON_PRICE";
241
+ MainnetIds[MainnetIds["AAVE_V4_CLOSE"] = 65] = "AAVE_V4_CLOSE";
242
+ MainnetIds[MainnetIds["AAVE_V4_EOA_REPAY"] = 66] = "AAVE_V4_EOA_REPAY";
243
+ MainnetIds[MainnetIds["AAVE_V4_EOA_BOOST"] = 67] = "AAVE_V4_EOA_BOOST";
244
+ MainnetIds[MainnetIds["AAVE_V4_EOA_REPAY_ON_PRICE"] = 68] = "AAVE_V4_EOA_REPAY_ON_PRICE";
245
+ MainnetIds[MainnetIds["AAVE_V4_EOA_BOOST_ON_PRICE"] = 69] = "AAVE_V4_EOA_BOOST_ON_PRICE";
246
+ MainnetIds[MainnetIds["AAVE_V4_EOA_CLOSE"] = 70] = "AAVE_V4_EOA_CLOSE";
243
247
  })(MainnetIds = Bundles.MainnetIds || (Bundles.MainnetIds = {}));
244
248
  let OptimismIds;
245
249
  (function (OptimismIds) {
@@ -197,6 +197,17 @@ export declare namespace Position {
197
197
  stopLossType: CloseToAssetType | undefined;
198
198
  takeProfitType: CloseToAssetType | undefined;
199
199
  }
200
+ interface SparkOnPrice extends Base {
201
+ collAsset: EthereumAddress;
202
+ collAssetId: number;
203
+ debtAsset: EthereumAddress;
204
+ debtAssetId: number;
205
+ baseToken: EthereumAddress;
206
+ quoteToken: EthereumAddress;
207
+ price: string;
208
+ ratioState: RatioState;
209
+ ratio: number;
210
+ }
200
211
  interface CloseBase extends Base {
201
212
  stopLossPrice: string;
202
213
  takeProfitPrice: string;
@@ -219,7 +230,7 @@ export declare namespace Position {
219
230
  debtAssetId: number;
220
231
  }
221
232
  }
222
- type SpecificAny = Specific.CloseOnPrice | Specific.TrailingStop | Specific.RatioProtection | Specific.CloseOnPriceAave | Specific.BoostOnPriceAave | Specific.CloseOnPriceWithMaximumGasPriceAave | Specific.DebtInFrontRepay | Specific.LeverageManagementCrvUSD | Specific.CloseOnPriceLiquityV2 | Specific.BoostOnPriceMorpho | Specific.BoostOnPriceLiquityV2 | Specific.PaybackLiquityV2 | Specific.CompoundV3LeverageManagementOnPrice | Specific.CompoundV3CloseOnPrice | Specific.AaveV3CloseOnPriceGeneric | Specific.AaveV4LeverageManagementOnPrice | Specific.AaveV4CloseOnPrice;
233
+ type SpecificAny = Specific.CloseOnPrice | Specific.TrailingStop | Specific.RatioProtection | Specific.CloseOnPriceAave | Specific.BoostOnPriceAave | Specific.CloseOnPriceWithMaximumGasPriceAave | Specific.DebtInFrontRepay | Specific.LeverageManagementCrvUSD | Specific.CloseOnPriceLiquityV2 | Specific.BoostOnPriceMorpho | Specific.BoostOnPriceLiquityV2 | Specific.PaybackLiquityV2 | Specific.CompoundV3LeverageManagementOnPrice | Specific.CompoundV3CloseOnPrice | Specific.AaveV3CloseOnPriceGeneric | Specific.AaveV4LeverageManagementOnPrice | Specific.AaveV4CloseOnPrice | Specific.SparkOnPrice;
223
234
  interface Automated {
224
235
  chainId: ChainId;
225
236
  positionId: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defisaver/automation-sdk",
3
- "version": "3.3.10-aave-v4-dev",
3
+ "version": "3.3.10-aave-v4-2-dev",
4
4
  "description": "",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./esm/index.js",
@@ -23,7 +23,7 @@
23
23
  "repository": "https://github.com/defisaver/automation-sdk",
24
24
  "license": "ISC",
25
25
  "dependencies": {
26
- "@defisaver/sdk": "^1.3.15",
26
+ "@defisaver/sdk": "1.3.18-aave-v4-dev",
27
27
  "@defisaver/tokens": "^1.6.19",
28
28
  "@ethersproject/address": "^5.0.10",
29
29
  "@ethersproject/solidity": "^5.0.9",
@@ -128,6 +128,11 @@ export const MAINNET_STRATEGIES_INFO: MainnetStrategiesInfo = {
128
128
  strategyId: Strategies.Identifiers.CollateralSwitch,
129
129
  protocol: PROTOCOLS.AaveV4,
130
130
  },
131
+ [Strategies.MainnetIds.AAVE_V4_COLLATERAL_SWITCH_EOA]: {
132
+ strategyOrBundleId: Strategies.MainnetIds.AAVE_V4_COLLATERAL_SWITCH_EOA,
133
+ strategyId: Strategies.Identifiers.EoaCollateralSwitch,
134
+ protocol: PROTOCOLS.AaveV4,
135
+ },
131
136
  };
132
137
 
133
138
  export const OPTIMISM_STRATEGIES_INFO: OptimismStrategiesInfo = {
@@ -501,6 +506,16 @@ export const MAINNET_BUNDLES_INFO: MainnetBundleInfo = {
501
506
  strategyId: Strategies.Identifiers.CloseOnPrice,
502
507
  protocol: PROTOCOLS.MorphoBlue,
503
508
  },
509
+ [Bundles.MainnetIds.SPARK_REPAY_ON_PRICE]: {
510
+ strategyOrBundleId: Bundles.MainnetIds.SPARK_REPAY_ON_PRICE,
511
+ strategyId: Strategies.Identifiers.RepayOnPrice,
512
+ protocol: PROTOCOLS.Spark,
513
+ },
514
+ [Bundles.MainnetIds.SPARK_BOOST_ON_PRICE]: {
515
+ strategyOrBundleId: Bundles.MainnetIds.SPARK_BOOST_ON_PRICE,
516
+ strategyId: Strategies.Identifiers.BoostOnPrice,
517
+ protocol: PROTOCOLS.Spark,
518
+ },
504
519
  [Bundles.MainnetIds.AAVE_V4_REPAY]: {
505
520
  strategyOrBundleId: Bundles.MainnetIds.AAVE_V4_REPAY,
506
521
  strategyId: Strategies.Identifiers.Repay,