@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.
Files changed (42) hide show
  1. package/cjs/constants/index.js +10 -0
  2. package/cjs/services/ethereumService.test.js +2 -0
  3. package/cjs/services/strategiesService.js +25 -0
  4. package/cjs/services/strategySubService.d.ts +13 -0
  5. package/cjs/services/strategySubService.js +7 -0
  6. package/cjs/services/strategySubService.test.js +133 -0
  7. package/cjs/services/subDataService.d.ts +11 -0
  8. package/cjs/services/subDataService.js +25 -1
  9. package/cjs/services/subDataService.test.js +57 -0
  10. package/cjs/services/triggerService.d.ts +9 -0
  11. package/cjs/services/triggerService.js +16 -1
  12. package/cjs/services/triggerService.test.js +46 -0
  13. package/cjs/types/enums.d.ts +3 -1
  14. package/cjs/types/enums.js +2 -0
  15. package/cjs/types/index.d.ts +12 -1
  16. package/esm/constants/index.js +10 -0
  17. package/esm/services/ethereumService.test.js +2 -0
  18. package/esm/services/strategiesService.js +25 -0
  19. package/esm/services/strategySubService.d.ts +13 -0
  20. package/esm/services/strategySubService.js +7 -0
  21. package/esm/services/strategySubService.test.js +134 -1
  22. package/esm/services/subDataService.d.ts +11 -0
  23. package/esm/services/subDataService.js +24 -0
  24. package/esm/services/subDataService.test.js +57 -0
  25. package/esm/services/triggerService.d.ts +9 -0
  26. package/esm/services/triggerService.js +15 -0
  27. package/esm/services/triggerService.test.js +47 -1
  28. package/esm/types/enums.d.ts +3 -1
  29. package/esm/types/enums.js +2 -0
  30. package/esm/types/index.d.ts +12 -1
  31. package/package.json +2 -2
  32. package/src/constants/index.ts +10 -0
  33. package/src/services/ethereumService.test.ts +2 -0
  34. package/src/services/strategiesService.ts +31 -1
  35. package/src/services/strategySubService.test.ts +162 -0
  36. package/src/services/strategySubService.ts +22 -0
  37. package/src/services/subDataService.test.ts +67 -0
  38. package/src/services/subDataService.ts +39 -0
  39. package/src/services/triggerService.test.ts +51 -0
  40. package/src/services/triggerService.ts +23 -0
  41. package/src/types/enums.ts +2 -0
  42. package/src/types/index.ts +14 -1
@@ -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, } from './strategySubService';
8
+ import { aaveV2Encode, chickenBondsEncode, liquityEncode, makerEncode, aaveV3Encode, compoundV2Encode, compoundV3Encode, morphoAaveV2Encode, exchangeEncode, crvUSDEncode, compoundV3L2Encode, morphoBlueEncode, sparkEncode, } 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,4 +1453,137 @@ 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
  });
@@ -345,3 +345,14 @@ export declare const morphoBlueCloseOnPriceSubData: {
345
345
  closeType: CloseStrategyType;
346
346
  };
347
347
  };
348
+ export declare const sparkLeverageManagementOnPriceSubData: {
349
+ encode(collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, marketAddr: EthereumAddress, targetRatio: number): string[];
350
+ decode(subData: string[]): {
351
+ collAsset: EthereumAddress;
352
+ collAssetId: number;
353
+ debtAsset: EthereumAddress;
354
+ debtAssetId: number;
355
+ marketAddr: EthereumAddress;
356
+ targetRatio: number;
357
+ };
358
+ };
@@ -910,3 +910,27 @@ export const morphoBlueCloseOnPriceSubData = {
910
910
  };
911
911
  },
912
912
  };
913
+ export const sparkLeverageManagementOnPriceSubData = {
914
+ encode(collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio) {
915
+ const encodedColl = AbiCoder.encodeParameter('address', collAsset);
916
+ const encodedCollId = AbiCoder.encodeParameter('uint16', collAssetId);
917
+ const encodedDebt = AbiCoder.encodeParameter('address', debtAsset);
918
+ const encodedDebtId = AbiCoder.encodeParameter('uint16', debtAssetId);
919
+ const encodedMarket = AbiCoder.encodeParameter('address', marketAddr);
920
+ const encodedTargetRatio = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
921
+ const useOnBehalfEncoded = AbiCoder.encodeParameter('bool', false);
922
+ return [encodedColl, encodedCollId, encodedDebt, encodedDebtId, encodedMarket, encodedTargetRatio, useOnBehalfEncoded];
923
+ },
924
+ decode(subData) {
925
+ const collAsset = AbiCoder.decodeParameter('address', subData[0]);
926
+ const collAssetId = Number(AbiCoder.decodeParameter('uint16', subData[1]));
927
+ const debtAsset = AbiCoder.decodeParameter('address', subData[2]);
928
+ const debtAssetId = Number(AbiCoder.decodeParameter('uint16', subData[3]));
929
+ const marketAddr = AbiCoder.decodeParameter('address', subData[4]);
930
+ const weiRatio = AbiCoder.decodeParameter('uint256', subData[5]);
931
+ const targetRatio = weiToRatioPercentage(weiRatio);
932
+ return {
933
+ collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio,
934
+ };
935
+ },
936
+ };
@@ -2061,4 +2061,61 @@ 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
  });
@@ -285,3 +285,12 @@ 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
+ };
@@ -518,3 +518,18 @@ 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
+ };
@@ -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, } 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, } from './triggerService';
7
7
  describe('Feature: triggerService.ts', () => {
8
8
  describe('When testing triggerService.chainlinkPriceTrigger', () => {
9
9
  describe('encode()', () => {
@@ -1159,4 +1159,50 @@ describe('Feature: triggerService.ts', () => {
1159
1159
  });
1160
1160
  });
1161
1161
  });
1162
+ describe('When testing triggerService.sparkQuotePriceTrigger', () => {
1163
+ describe('encode()', () => {
1164
+ const examples = [
1165
+ [
1166
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000003a352944000000000000000000000000000000000000000000000000000000000000000001'],
1167
+ [web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address), web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address), 2500, RatioState.UNDER]
1168
+ ],
1169
+ [
1170
+ ['0x000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec70000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000000000000000000000000000000000000000000c1c0000000000000000000000000000000000000000000000000000000000000000'],
1171
+ [web3Utils.toChecksumAddress(getAssetInfo('USDT', ChainId.Ethereum).address), web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address), 0.000031, RatioState.OVER]
1172
+ ],
1173
+ ];
1174
+ examples.forEach(([expected, actual]) => {
1175
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
1176
+ expect(sparkQuotePriceTrigger.encode(...actual)).to.eql(expected);
1177
+ });
1178
+ });
1179
+ });
1180
+ describe('decode()', () => {
1181
+ const examples = [
1182
+ [
1183
+ {
1184
+ baseTokenAddr: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1185
+ quoteTokenAddr: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1186
+ price: '2500',
1187
+ ratioState: RatioState.UNDER
1188
+ },
1189
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000003a352944000000000000000000000000000000000000000000000000000000000000000001']
1190
+ ],
1191
+ [
1192
+ {
1193
+ baseTokenAddr: web3Utils.toChecksumAddress(getAssetInfo('USDT', ChainId.Ethereum).address),
1194
+ quoteTokenAddr: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
1195
+ price: '0.000031',
1196
+ ratioState: RatioState.OVER
1197
+ },
1198
+ ['0x000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec70000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000000000000000000000000000000000000000000c1c0000000000000000000000000000000000000000000000000000000000000000']
1199
+ ]
1200
+ ];
1201
+ examples.forEach(([expected, actual]) => {
1202
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1203
+ expect(sparkQuotePriceTrigger.decode(actual)).to.eql(expected);
1204
+ });
1205
+ });
1206
+ });
1207
+ });
1162
1208
  });
@@ -207,7 +207,9 @@ export declare namespace Bundles {
207
207
  AAVE_V3_EOA_BOOST_ON_PRICE = 55,
208
208
  AAVE_V3_EOA_CLOSE = 56,
209
209
  SPARK_CLOSE = 57,
210
- MORPHO_BLUE_CLOSE = 58
210
+ MORPHO_BLUE_CLOSE = 58,
211
+ SPARK_REPAY_ON_PRICE = 59,
212
+ SPARK_BOOST_ON_PRICE = 60
211
213
  }
212
214
  enum OptimismIds {
213
215
  AAVE_V3_REPAY = 0,
@@ -228,6 +228,8 @@ export var Bundles;
228
228
  MainnetIds[MainnetIds["AAVE_V3_EOA_CLOSE"] = 56] = "AAVE_V3_EOA_CLOSE";
229
229
  MainnetIds[MainnetIds["SPARK_CLOSE"] = 57] = "SPARK_CLOSE";
230
230
  MainnetIds[MainnetIds["MORPHO_BLUE_CLOSE"] = 58] = "MORPHO_BLUE_CLOSE";
231
+ MainnetIds[MainnetIds["SPARK_REPAY_ON_PRICE"] = 59] = "SPARK_REPAY_ON_PRICE";
232
+ MainnetIds[MainnetIds["SPARK_BOOST_ON_PRICE"] = 60] = "SPARK_BOOST_ON_PRICE";
231
233
  })(MainnetIds = Bundles.MainnetIds || (Bundles.MainnetIds = {}));
232
234
  let OptimismIds;
233
235
  (function (OptimismIds) {
@@ -197,8 +197,19 @@ 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
  }
201
- 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;
212
+ 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.SparkOnPrice;
202
213
  interface Automated {
203
214
  chainId: ChainId;
204
215
  positionId: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defisaver/automation-sdk",
3
- "version": "3.3.10",
3
+ "version": "3.3.11",
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.21",
27
27
  "@defisaver/tokens": "^1.6.19",
28
28
  "@ethersproject/address": "^5.0.10",
29
29
  "@ethersproject/solidity": "^5.0.9",
@@ -496,6 +496,16 @@ export const MAINNET_BUNDLES_INFO: MainnetBundleInfo = {
496
496
  strategyId: Strategies.Identifiers.CloseOnPrice,
497
497
  protocol: PROTOCOLS.MorphoBlue,
498
498
  },
499
+ [Bundles.MainnetIds.SPARK_REPAY_ON_PRICE]: {
500
+ strategyOrBundleId: Bundles.MainnetIds.SPARK_REPAY_ON_PRICE,
501
+ strategyId: Strategies.Identifiers.RepayOnPrice,
502
+ protocol: PROTOCOLS.Spark,
503
+ },
504
+ [Bundles.MainnetIds.SPARK_BOOST_ON_PRICE]: {
505
+ strategyOrBundleId: Bundles.MainnetIds.SPARK_BOOST_ON_PRICE,
506
+ strategyId: Strategies.Identifiers.BoostOnPrice,
507
+ protocol: PROTOCOLS.Spark,
508
+ },
499
509
  };
500
510
 
501
511
  export const OPTIMISM_BUNDLES_INFO: OptimismBundleInfo = {
@@ -161,6 +161,7 @@ describe('Feature: ethereumService.ts', () => {
161
161
  'address': '0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1',
162
162
  'blockHash': '0xacb0213af63b4c17c436f084a96d1ac385641a59a9a4cf014ae3337cbe545aa7',
163
163
  'blockNumber': 5353002,
164
+ 'blockTimestamp': '0x624c1a5b',
164
165
  'event': 'Transfer',
165
166
  'id': 'log_f49645b8',
166
167
  'logIndex': 1,
@@ -206,6 +207,7 @@ describe('Feature: ethereumService.ts', () => {
206
207
  'address': '0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1',
207
208
  'blockHash': '0xacb0213af63b4c17c436f084a96d1ac385641a59a9a4cf014ae3337cbe545aa7',
208
209
  'blockNumber': 5353002,
210
+ 'blockTimestamp': '0x624c1a5b',
209
211
  'event': 'Transfer',
210
212
  'id': 'log_f49645b8',
211
213
  'logIndex': 1,
@@ -782,9 +782,37 @@ function parseSparkLeverageManagement(position: Position.Automated, parseData: P
782
782
  return _position;
783
783
  }
784
784
 
785
- function parseSparkCloseOnPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
785
+ function parseSparkLeverageManagementOnPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
786
786
  const _position = cloneDeep(position);
787
+ const { subStruct } = parseData.subscriptionEventData;
788
+
789
+ const triggerData = triggerService.sparkQuotePriceTrigger.decode(subStruct.triggerData);
790
+ const subData = subDataService.sparkLeverageManagementOnPriceSubData.decode(subStruct.subData);
791
+
792
+ _position.strategyData.decoded.triggerData = triggerData;
793
+ _position.strategyData.decoded.subData = subData;
787
794
 
795
+ _position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, subData.marketAddr);
796
+
797
+ _position.specific = {
798
+ // subData
799
+ collAsset: subData.collAsset,
800
+ collAssetId: subData.collAssetId,
801
+ debtAsset: subData.debtAsset,
802
+ debtAssetId: subData.debtAssetId,
803
+ ratio: subData.targetRatio,
804
+ // triggerData
805
+ baseToken: triggerData.baseTokenAddr,
806
+ quoteToken: triggerData.quoteTokenAddr,
807
+ price: triggerData.price,
808
+ ratioState: triggerData.ratioState,
809
+ };
810
+
811
+ return _position;
812
+ }
813
+
814
+ function parseSparkCloseOnPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
815
+ const _position = cloneDeep(position);
788
816
  const { subStruct } = parseData.subscriptionEventData;
789
817
 
790
818
  const triggerData = triggerService.sparkQuotePriceRangeTrigger.decode(subStruct.triggerData);
@@ -1237,6 +1265,8 @@ const parsingMethodsMapping: StrategiesToProtocolVersionMapping = {
1237
1265
  [ProtocolIdentifiers.StrategiesAutomation.Spark]: {
1238
1266
  [Strategies.Identifiers.Repay]: parseSparkLeverageManagement,
1239
1267
  [Strategies.Identifiers.Boost]: parseSparkLeverageManagement,
1268
+ [Strategies.Identifiers.RepayOnPrice]: parseSparkLeverageManagementOnPrice,
1269
+ [Strategies.Identifiers.BoostOnPrice]: parseSparkLeverageManagementOnPrice,
1240
1270
  [Strategies.Identifiers.CloseOnPrice]: parseSparkCloseOnPrice,
1241
1271
  },
1242
1272
  [ProtocolIdentifiers.StrategiesAutomation.CrvUSD]: {