@defisaver/automation-sdk 3.3.22-instant-twap-close-dev → 3.3.22

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 (52) hide show
  1. package/cjs/automation/private/StrategiesAutomation.d.ts +5 -1
  2. package/cjs/automation/private/StrategiesAutomation.js +12 -0
  3. package/cjs/automation/private/StrategiesAutomation.test.js +51 -0
  4. package/cjs/constants/index.js +0 -40
  5. package/cjs/services/apiSubscriptionsService.d.ts +7 -0
  6. package/cjs/services/apiSubscriptionsService.js +33 -0
  7. package/cjs/services/apiSubscriptionsService.test.d.ts +1 -0
  8. package/cjs/services/apiSubscriptionsService.test.js +67 -0
  9. package/cjs/services/strategiesService.js +0 -25
  10. package/cjs/services/strategiesService.test.js +0 -63
  11. package/cjs/services/strategySubService.d.ts +0 -1
  12. package/cjs/services/strategySubService.js +0 -7
  13. package/cjs/services/strategySubService.test.js +0 -111
  14. package/cjs/services/subDataService.d.ts +0 -14
  15. package/cjs/services/subDataService.js +2 -40
  16. package/cjs/services/subDataService.test.js +0 -70
  17. package/cjs/types/enums.d.ts +4 -14
  18. package/cjs/types/enums.js +0 -11
  19. package/cjs/types/index.d.ts +24 -2
  20. package/esm/automation/private/StrategiesAutomation.d.ts +5 -1
  21. package/esm/automation/private/StrategiesAutomation.js +12 -0
  22. package/esm/automation/private/StrategiesAutomation.test.js +51 -0
  23. package/esm/constants/index.js +0 -40
  24. package/esm/services/apiSubscriptionsService.d.ts +7 -0
  25. package/esm/services/apiSubscriptionsService.js +29 -0
  26. package/esm/services/apiSubscriptionsService.test.d.ts +1 -0
  27. package/esm/services/apiSubscriptionsService.test.js +65 -0
  28. package/esm/services/strategiesService.js +0 -25
  29. package/esm/services/strategiesService.test.js +1 -64
  30. package/esm/services/strategySubService.d.ts +0 -1
  31. package/esm/services/strategySubService.js +0 -7
  32. package/esm/services/strategySubService.test.js +0 -111
  33. package/esm/services/subDataService.d.ts +0 -14
  34. package/esm/services/subDataService.js +0 -38
  35. package/esm/services/subDataService.test.js +0 -70
  36. package/esm/types/enums.d.ts +4 -14
  37. package/esm/types/enums.js +0 -11
  38. package/esm/types/index.d.ts +24 -2
  39. package/package.json +1 -1
  40. package/src/automation/private/StrategiesAutomation.test.ts +65 -1
  41. package/src/automation/private/StrategiesAutomation.ts +17 -0
  42. package/src/constants/index.ts +0 -40
  43. package/src/services/apiSubscriptionsService.test.ts +73 -0
  44. package/src/services/apiSubscriptionsService.ts +33 -0
  45. package/src/services/strategiesService.test.ts +1 -79
  46. package/src/services/strategiesService.ts +0 -33
  47. package/src/services/strategySubService.test.ts +0 -130
  48. package/src/services/strategySubService.ts +0 -26
  49. package/src/services/subDataService.test.ts +0 -98
  50. package/src/services/subDataService.ts +0 -61
  51. package/src/types/enums.ts +0 -11
  52. package/src/types/index.ts +26 -2
@@ -164,13 +164,6 @@ export const aaveV3Encode = {
164
164
  const triggerDataEncoded = triggerService.aaveV3QuotePriceRangeTrigger.encode(collAsset, debtAsset, stopLossPrice, takeProfitPrice);
165
165
  return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
166
166
  },
167
- instantCloseOnPriceGeneric(strategyOrBundleId, collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, user, tsi, slippage, stopLossPrice = 0, stopLossType = CloseToAssetType.DEBT, takeProfitPrice = 0, takeProfitType = CloseToAssetType.COLLATERAL) {
168
- const isBundle = true;
169
- const closeType = getCloseStrategyType(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
170
- const subDataEncoded = subDataService.aaveV3InstantCloseGenericSubData.encode(collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr, user, tsi, slippage);
171
- const triggerDataEncoded = triggerService.aaveV3QuotePriceRangeTrigger.encode(collAsset, debtAsset, stopLossPrice, takeProfitPrice);
172
- return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
173
- },
174
167
  collateralSwitch(strategyOrBundleId, fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, baseTokenAddress, quoteTokenAddress, price, state) {
175
168
  const isBundle = false;
176
169
  const subDataEncoded = subDataService.aaveV3CollateralSwitchSubData.encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch);
@@ -732,117 +732,6 @@ describe('Feature: strategySubService.ts', () => {
732
732
  });
733
733
  });
734
734
  });
735
- describe('instantCloseOnPriceGeneric()', () => {
736
- const examples = [
737
- // Stop loss only (to debt)
738
- [
739
- [
740
- Bundles.MainnetIds.AAVE_V3_EOA_INSTANT_CLOSE,
741
- true,
742
- ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000000000000000'],
743
- [
744
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
745
- '0x0000000000000000000000000000000000000000000000000000000000000000',
746
- '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
747
- '0x0000000000000000000000000000000000000000000000000000000000000001',
748
- '0x0000000000000000000000000000000000000000000000000000000000000003',
749
- '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
750
- '0x0000000000000000000000001234567890123456789012345678901234567890',
751
- '0x0000000000000000000000000000000000000000000000000de0b6b3a7640000',
752
- '0x000000000000000000000000000000000000000000000000002386f26fc10000',
753
- ],
754
- ],
755
- [
756
- Bundles.MainnetIds.AAVE_V3_EOA_INSTANT_CLOSE,
757
- web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
758
- 0,
759
- web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
760
- 1,
761
- web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
762
- web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
763
- '1000000000000000000',
764
- '10000000000000000',
765
- 1500,
766
- CloseToAssetType.DEBT,
767
- 0,
768
- CloseToAssetType.COLLATERAL, // takeProfitType (not used since price is 0)
769
- ]
770
- ],
771
- // Take profit only (to collateral), zero tsi and slippage
772
- [
773
- [
774
- Bundles.MainnetIds.AAVE_V3_EOA_INSTANT_CLOSE,
775
- true,
776
- ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000746a528800'],
777
- [
778
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
779
- '0x0000000000000000000000000000000000000000000000000000000000000000',
780
- '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
781
- '0x0000000000000000000000000000000000000000000000000000000000000001',
782
- '0x0000000000000000000000000000000000000000000000000000000000000000',
783
- '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
784
- '0x0000000000000000000000001234567890123456789012345678901234567890',
785
- '0x0000000000000000000000000000000000000000000000000000000000000000',
786
- '0x0000000000000000000000000000000000000000000000000000000000000000',
787
- ],
788
- ],
789
- [
790
- Bundles.MainnetIds.AAVE_V3_EOA_INSTANT_CLOSE,
791
- web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
792
- 0,
793
- web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
794
- 1,
795
- web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
796
- web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
797
- '0',
798
- '0',
799
- 0,
800
- CloseToAssetType.DEBT,
801
- 5000,
802
- CloseToAssetType.COLLATERAL, // takeProfitType
803
- ]
804
- ],
805
- // Take profit (to debt) and stop loss (to collateral)
806
- [
807
- [
808
- Bundles.MainnetIds.AAVE_V3_EOA_INSTANT_CLOSE,
809
- true,
810
- ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
811
- [
812
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
813
- '0x0000000000000000000000000000000000000000000000000000000000000000',
814
- '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
815
- '0x0000000000000000000000000000000000000000000000000000000000000001',
816
- '0x0000000000000000000000000000000000000000000000000000000000000007',
817
- '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
818
- '0x0000000000000000000000001234567890123456789012345678901234567890',
819
- '0x00000000000000000000000000000000000000000000000000b1a2bc2ec50000',
820
- '0x0000000000000000000000000000000000000000000000000011c37937e08000',
821
- ],
822
- ],
823
- [
824
- Bundles.MainnetIds.AAVE_V3_EOA_INSTANT_CLOSE,
825
- web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
826
- 0,
827
- web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
828
- 1,
829
- web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
830
- web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
831
- '50000000000000000',
832
- '5000000000000000',
833
- 1500,
834
- CloseToAssetType.COLLATERAL,
835
- 4000,
836
- CloseToAssetType.DEBT, // takeProfitType
837
- ]
838
- ],
839
- ];
840
- examples.forEach(([expected, actual]) => {
841
- it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
842
- expect(aaveV3Encode.instantCloseOnPriceGeneric(...actual)).to.eql(expected);
843
- });
844
- });
845
- });
846
735
  describe('collateralSwitch()', () => {
847
736
  const examples = [
848
737
  // WETH -> USDC, price 100000, state UNDER
@@ -248,20 +248,6 @@ export declare const aaveV3CloseGenericSubData: {
248
248
  owner: EthereumAddress;
249
249
  };
250
250
  };
251
- export declare const aaveV3InstantCloseGenericSubData: {
252
- encode(collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, closeType: CloseStrategyType, marketAddr: EthereumAddress, user: EthereumAddress, tsi: string, slippage: string): string[];
253
- decode(subData: string[]): {
254
- collAsset: EthereumAddress;
255
- collAssetId: number;
256
- debtAsset: EthereumAddress;
257
- debtAssetId: number;
258
- closeType: CloseStrategyType;
259
- marketAddr: EthereumAddress;
260
- owner: EthereumAddress;
261
- tsi: string;
262
- slippage: string;
263
- };
264
- };
265
251
  export declare const aaveV3CollateralSwitchSubData: {
266
252
  encode(fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, marketAddr: EthereumAddress, amountToSwitch: string, useOnBehalf?: boolean): string[];
267
253
  decode(subData: string[]): {
@@ -511,44 +511,6 @@ export const aaveV3CloseGenericSubData = {
511
511
  };
512
512
  },
513
513
  };
514
- export const aaveV3InstantCloseGenericSubData = {
515
- encode(collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr, user, tsi, slippage) {
516
- const encodedColl = AbiCoder.encodeParameter('address', collAsset);
517
- const encodedCollId = AbiCoder.encodeParameter('uint16', collAssetId);
518
- const encodedDebt = AbiCoder.encodeParameter('address', debtAsset);
519
- const encodedDebtId = AbiCoder.encodeParameter('uint16', debtAssetId);
520
- const encodedCloseType = AbiCoder.encodeParameter('uint8', closeType);
521
- const encodedMarket = AbiCoder.encodeParameter('address', marketAddr);
522
- const encodedUser = AbiCoder.encodeParameter('address', user);
523
- const encodedTsi = AbiCoder.encodeParameter('uint256', tsi);
524
- const encodedSlippage = AbiCoder.encodeParameter('uint256', slippage);
525
- return [
526
- encodedColl,
527
- encodedCollId,
528
- encodedDebt,
529
- encodedDebtId,
530
- encodedCloseType,
531
- encodedMarket,
532
- encodedUser,
533
- encodedTsi,
534
- encodedSlippage,
535
- ];
536
- },
537
- decode(subData) {
538
- const collAsset = AbiCoder.decodeParameter('address', subData[0]);
539
- const collAssetId = Number(AbiCoder.decodeParameter('uint16', subData[1]));
540
- const debtAsset = AbiCoder.decodeParameter('address', subData[2]);
541
- const debtAssetId = Number(AbiCoder.decodeParameter('uint16', subData[3]));
542
- const closeType = Number(AbiCoder.decodeParameter('uint8', subData[4]));
543
- const marketAddr = AbiCoder.decodeParameter('address', subData[5]);
544
- const owner = AbiCoder.decodeParameter('address', subData[6]);
545
- const tsi = AbiCoder.decodeParameter('uint256', subData[7]);
546
- const slippage = AbiCoder.decodeParameter('uint256', subData[8]);
547
- return {
548
- collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr, owner, tsi, slippage,
549
- };
550
- },
551
- };
552
514
  export const aaveV3CollateralSwitchSubData = {
553
515
  encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, useOnBehalf = false) {
554
516
  const encodedFromAsset = AbiCoder.encodeParameter('address', fromAsset);
@@ -2256,76 +2256,6 @@ describe('Feature: subDataService.ts', () => {
2256
2256
  });
2257
2257
  });
2258
2258
  });
2259
- describe("When testing subDataService.aaveV3InstantCloseGenericSubData", () => {
2260
- const WETH = web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address);
2261
- const USDC = web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address);
2262
- const MARKET = web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39');
2263
- const USER = web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890');
2264
- const examples = [
2265
- // TAKE_PROFIT_IN_COLLATERAL, zero tsi and slippage
2266
- [
2267
- [
2268
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
2269
- '0x0000000000000000000000000000000000000000000000000000000000000000',
2270
- '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
2271
- '0x0000000000000000000000000000000000000000000000000000000000000001',
2272
- '0x0000000000000000000000000000000000000000000000000000000000000000',
2273
- '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
2274
- '0x0000000000000000000000001234567890123456789012345678901234567890',
2275
- '0x0000000000000000000000000000000000000000000000000000000000000000',
2276
- '0x0000000000000000000000000000000000000000000000000000000000000000',
2277
- ],
2278
- [WETH, 0, USDC, 1, CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL, MARKET, USER, '0', '0'],
2279
- ],
2280
- // STOP_LOSS_IN_DEBT
2281
- [
2282
- [
2283
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
2284
- '0x0000000000000000000000000000000000000000000000000000000000000000',
2285
- '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
2286
- '0x0000000000000000000000000000000000000000000000000000000000000001',
2287
- '0x0000000000000000000000000000000000000000000000000000000000000003',
2288
- '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
2289
- '0x0000000000000000000000001234567890123456789012345678901234567890',
2290
- '0x0000000000000000000000000000000000000000000000000de0b6b3a7640000',
2291
- '0x000000000000000000000000000000000000000000000000002386f26fc10000',
2292
- ],
2293
- [WETH, 0, USDC, 1, CloseStrategyType.STOP_LOSS_IN_DEBT, MARKET, USER, '1000000000000000000', '10000000000000000'],
2294
- ],
2295
- // TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL, asset ids above uint8 range
2296
- [
2297
- [
2298
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
2299
- '0x000000000000000000000000000000000000000000000000000000000000012c',
2300
- '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
2301
- '0x0000000000000000000000000000000000000000000000000000000000000190',
2302
- '0x0000000000000000000000000000000000000000000000000000000000000007',
2303
- '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
2304
- '0x0000000000000000000000001234567890123456789012345678901234567890',
2305
- '0x00000000000000000000000000000000000000000000000000b1a2bc2ec50000',
2306
- '0x0000000000000000000000000000000000000000000000000011c37937e08000',
2307
- ],
2308
- [WETH, 300, USDC, 400, CloseStrategyType.TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL, MARKET, USER, '50000000000000000', '5000000000000000'],
2309
- ],
2310
- ];
2311
- describe("encode()", () => {
2312
- examples.forEach(([expected, actual]) => {
2313
- it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
2314
- expect(subDataService.aaveV3InstantCloseGenericSubData.encode(...actual)).to.eql(expected);
2315
- });
2316
- });
2317
- });
2318
- describe("decode()", () => {
2319
- examples.forEach(([encoded, [collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr, user, tsi, slippage]]) => {
2320
- const expected = {
2321
- collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr, owner: user, tsi, slippage,
2322
- };
2323
- it(`Given ${JSON.stringify(encoded)} should return expected value: ${JSON.stringify(expected)}`, () => {
2324
- expect(subDataService.aaveV3InstantCloseGenericSubData.decode(encoded)).to.eql(expected);
2325
- });
2326
- });
2327
- });
2328
- });
2329
2259
  describe('When testing subDataService.sparkLeverageManagementOnPriceSubData', () => {
2330
2260
  describe('encode()', () => {
2331
2261
  const examples = [
@@ -124,8 +124,6 @@ export declare namespace Strategies {
124
124
  CloseOnPriceToColl = "close-on-price-to-collateral",
125
125
  CloseOnPrice = "close-on-price",
126
126
  EoaCloseOnPrice = "eoa-close-on-price",
127
- InstantCloseOnPrice = "instant-close-on-price",
128
- EoaInstantCloseOnPrice = "eoa-instant-close-on-price",
129
127
  TrailingStopToColl = "trailing-stop-to-collateral",
130
128
  TrailingStopToDebt = "trailing-stop-to-debt",
131
129
  Rebond = "rebond",
@@ -252,9 +250,7 @@ export declare namespace Bundles {
252
250
  SPARK_EOA_REPAY_ON_PRICE = 90,
253
251
  SPARK_EOA_BOOST_ON_PRICE = 91,
254
252
  SPARK_EOA_CLOSE = 92,
255
- SPARK_EOA_LIQUIDATION_PROTECTION = 93,
256
- AAVE_V3_SW_INSTANT_CLOSE = 94,
257
- AAVE_V3_EOA_INSTANT_CLOSE = 95
253
+ SPARK_EOA_LIQUIDATION_PROTECTION = 93
258
254
  }
259
255
  enum OptimismIds {
260
256
  AAVE_V3_REPAY = 0,
@@ -269,9 +265,7 @@ export declare namespace Bundles {
269
265
  AAVE_V3_EOA_BOOST_ON_PRICE = 9,
270
266
  AAVE_V3_EOA_CLOSE = 10,
271
267
  AAVE_V3_SW_LIQUIDATION_PROTECTION = 11,
272
- AAVE_V3_EOA_LIQUIDATION_PROTECTION = 12,
273
- AAVE_V3_SW_INSTANT_CLOSE = 13,
274
- AAVE_V3_EOA_INSTANT_CLOSE = 14
268
+ AAVE_V3_EOA_LIQUIDATION_PROTECTION = 12
275
269
  }
276
270
  enum BaseIds {
277
271
  AAVE_V3_REPAY = 0,
@@ -313,9 +307,7 @@ export declare namespace Bundles {
313
307
  MORPHO_BLUE_EOA_BOOST_ON_PRICE = 39,
314
308
  MORPHO_BLUE_EOA_REPAY_ON_PRICE = 40,
315
309
  MORPHO_BLUE_EOA_CLOSE = 41,
316
- MORPHO_BLUE_EOA_LIQUIDATION_PROTECTION = 42,
317
- AAVE_V3_SW_INSTANT_CLOSE = 43,
318
- AAVE_V3_EOA_INSTANT_CLOSE = 44
310
+ MORPHO_BLUE_EOA_LIQUIDATION_PROTECTION = 42
319
311
  }
320
312
  enum ArbitrumIds {
321
313
  AAVE_V3_REPAY = 0,
@@ -357,8 +349,6 @@ export declare namespace Bundles {
357
349
  MORPHO_BLUE_REPAY_ON_PRICE = 36,
358
350
  MORPHO_BLUE_EOA_BOOST_ON_PRICE = 37,
359
351
  MORPHO_BLUE_EOA_REPAY_ON_PRICE = 38,
360
- MORPHO_BLUE_EOA_CLOSE = 39,
361
- AAVE_V3_SW_INSTANT_CLOSE = 40,
362
- AAVE_V3_EOA_INSTANT_CLOSE = 41
352
+ MORPHO_BLUE_EOA_CLOSE = 39
363
353
  }
364
354
  }
@@ -141,8 +141,6 @@ export var Strategies;
141
141
  Identifiers["CloseOnPriceToColl"] = "close-on-price-to-collateral";
142
142
  Identifiers["CloseOnPrice"] = "close-on-price";
143
143
  Identifiers["EoaCloseOnPrice"] = "eoa-close-on-price";
144
- Identifiers["InstantCloseOnPrice"] = "instant-close-on-price";
145
- Identifiers["EoaInstantCloseOnPrice"] = "eoa-instant-close-on-price";
146
144
  Identifiers["TrailingStopToColl"] = "trailing-stop-to-collateral";
147
145
  Identifiers["TrailingStopToDebt"] = "trailing-stop-to-debt";
148
146
  Identifiers["Rebond"] = "rebond";
@@ -273,8 +271,6 @@ export var Bundles;
273
271
  MainnetIds[MainnetIds["SPARK_EOA_BOOST_ON_PRICE"] = 91] = "SPARK_EOA_BOOST_ON_PRICE";
274
272
  MainnetIds[MainnetIds["SPARK_EOA_CLOSE"] = 92] = "SPARK_EOA_CLOSE";
275
273
  MainnetIds[MainnetIds["SPARK_EOA_LIQUIDATION_PROTECTION"] = 93] = "SPARK_EOA_LIQUIDATION_PROTECTION";
276
- MainnetIds[MainnetIds["AAVE_V3_SW_INSTANT_CLOSE"] = 94] = "AAVE_V3_SW_INSTANT_CLOSE";
277
- MainnetIds[MainnetIds["AAVE_V3_EOA_INSTANT_CLOSE"] = 95] = "AAVE_V3_EOA_INSTANT_CLOSE";
278
274
  })(MainnetIds = Bundles.MainnetIds || (Bundles.MainnetIds = {}));
279
275
  let OptimismIds;
280
276
  (function (OptimismIds) {
@@ -291,9 +287,6 @@ export var Bundles;
291
287
  OptimismIds[OptimismIds["AAVE_V3_EOA_CLOSE"] = 10] = "AAVE_V3_EOA_CLOSE";
292
288
  OptimismIds[OptimismIds["AAVE_V3_SW_LIQUIDATION_PROTECTION"] = 11] = "AAVE_V3_SW_LIQUIDATION_PROTECTION";
293
289
  OptimismIds[OptimismIds["AAVE_V3_EOA_LIQUIDATION_PROTECTION"] = 12] = "AAVE_V3_EOA_LIQUIDATION_PROTECTION";
294
- // TODO -> Fix ids
295
- OptimismIds[OptimismIds["AAVE_V3_SW_INSTANT_CLOSE"] = 13] = "AAVE_V3_SW_INSTANT_CLOSE";
296
- OptimismIds[OptimismIds["AAVE_V3_EOA_INSTANT_CLOSE"] = 14] = "AAVE_V3_EOA_INSTANT_CLOSE";
297
290
  })(OptimismIds = Bundles.OptimismIds || (Bundles.OptimismIds = {}));
298
291
  let BaseIds;
299
292
  (function (BaseIds) {
@@ -337,8 +330,6 @@ export var Bundles;
337
330
  BaseIds[BaseIds["MORPHO_BLUE_EOA_REPAY_ON_PRICE"] = 40] = "MORPHO_BLUE_EOA_REPAY_ON_PRICE";
338
331
  BaseIds[BaseIds["MORPHO_BLUE_EOA_CLOSE"] = 41] = "MORPHO_BLUE_EOA_CLOSE";
339
332
  BaseIds[BaseIds["MORPHO_BLUE_EOA_LIQUIDATION_PROTECTION"] = 42] = "MORPHO_BLUE_EOA_LIQUIDATION_PROTECTION";
340
- BaseIds[BaseIds["AAVE_V3_SW_INSTANT_CLOSE"] = 43] = "AAVE_V3_SW_INSTANT_CLOSE";
341
- BaseIds[BaseIds["AAVE_V3_EOA_INSTANT_CLOSE"] = 44] = "AAVE_V3_EOA_INSTANT_CLOSE";
342
333
  })(BaseIds = Bundles.BaseIds || (Bundles.BaseIds = {}));
343
334
  let ArbitrumIds;
344
335
  (function (ArbitrumIds) {
@@ -382,7 +373,5 @@ export var Bundles;
382
373
  ArbitrumIds[ArbitrumIds["MORPHO_BLUE_EOA_BOOST_ON_PRICE"] = 37] = "MORPHO_BLUE_EOA_BOOST_ON_PRICE";
383
374
  ArbitrumIds[ArbitrumIds["MORPHO_BLUE_EOA_REPAY_ON_PRICE"] = 38] = "MORPHO_BLUE_EOA_REPAY_ON_PRICE";
384
375
  ArbitrumIds[ArbitrumIds["MORPHO_BLUE_EOA_CLOSE"] = 39] = "MORPHO_BLUE_EOA_CLOSE";
385
- ArbitrumIds[ArbitrumIds["AAVE_V3_SW_INSTANT_CLOSE"] = 40] = "AAVE_V3_SW_INSTANT_CLOSE";
386
- ArbitrumIds[ArbitrumIds["AAVE_V3_EOA_INSTANT_CLOSE"] = 41] = "AAVE_V3_EOA_INSTANT_CLOSE";
387
376
  })(ArbitrumIds = Bundles.ArbitrumIds || (Bundles.ArbitrumIds = {}));
388
377
  })(Bundles || (Bundles = {}));
@@ -1,7 +1,7 @@
1
1
  import type Web3 from 'web3';
2
2
  import type { AbiItem } from 'web3-utils';
3
3
  import type { BaseContract, BlockType } from './contracts/generated/types';
4
- import type { Subscribe, StrategyModel } from './contracts/generated/SubStorage';
4
+ import type { StrategyModel } from './contracts/generated/SubStorage';
5
5
  import type { ChainId, Strategies, Bundles, ProtocolIdentifiers, RatioState, CloseToAssetType } from './enums';
6
6
  export type PlaceholderType = any;
7
7
  export type EthereumAddress = string;
@@ -53,6 +53,21 @@ interface _SubscriptionOptions {
53
53
  unexpiredOnly: boolean;
54
54
  }
55
55
  export type SubscriptionOptions = Partial<_SubscriptionOptions>;
56
+ /** Subscription record as returned by the automation API (GET /v1/subscriptions) */
57
+ export interface ApiSubscriptionRecord {
58
+ id: number;
59
+ wallet: EthereumAddress;
60
+ wallet_type: string;
61
+ is_enabled: boolean;
62
+ is_bundle: boolean;
63
+ strategy_or_bundle_id: number;
64
+ strategy_ids: number[];
65
+ sub_data_hash: string;
66
+ trigger_data: string[];
67
+ sub_data: string[];
68
+ block_number: number;
69
+ additional_triggers: string[] | null;
70
+ }
56
71
  export declare namespace Interfaces {
57
72
  interface ProtocolBase {
58
73
  id: ProtocolIdentifiers.StrategiesAutomation | ProtocolIdentifiers.LegacyAutomation;
@@ -291,10 +306,17 @@ export interface BundlesInfo {
291
306
  [ChainId.Base]: BaseBundleInfo;
292
307
  }
293
308
  export type StrategyOrBundleIds = typeof Strategies.MainnetIds[keyof typeof Strategies.MainnetIds] | typeof Strategies.OptimismIds[keyof typeof Strategies.OptimismIds] | typeof Strategies.ArbitrumIds[keyof typeof Strategies.ArbitrumIds] | typeof Strategies.BaseIds[keyof typeof Strategies.BaseIds] | typeof Bundles.MainnetIds[keyof typeof Bundles.MainnetIds] | typeof Bundles.OptimismIds[keyof typeof Bundles.OptimismIds] | typeof Bundles.ArbitrumIds[keyof typeof Bundles.ArbitrumIds] | typeof Bundles.BaseIds[keyof typeof Bundles.BaseIds];
309
+ /** Fields of the Subscribe event that parsing relies on */
310
+ export interface SubscriptionEventData {
311
+ subId: string;
312
+ proxy: EthereumAddress;
313
+ subHash: string;
314
+ subStruct: StrategyModel.StrategySubStructOutputStruct;
315
+ }
294
316
  export interface ParseData {
295
317
  chainId: ChainId;
296
318
  blockNumber: BlockNumber;
297
- subscriptionEventData: Subscribe['returnValues'];
319
+ subscriptionEventData: SubscriptionEventData;
298
320
  strategiesSubsData: StrategyModel.StoredSubDataStructOutputStruct;
299
321
  }
300
322
  type MapToProtocolVersion<T> = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defisaver/automation-sdk",
3
- "version": "3.3.22-instant-twap-close-dev",
3
+ "version": "3.3.22",
4
4
  "description": "",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./esm/index.js",
@@ -1,7 +1,8 @@
1
1
  import Web3 from 'web3';
2
2
  import { expect } from 'chai';
3
3
 
4
- import {ChainId} from '../../types/enums';
4
+ import { ChainId } from '../../types/enums';
5
+ import type { ApiSubscriptionRecord } from '../../types';
5
6
 
6
7
  import '../../configuration';
7
8
  import StrategiesAutomation from './StrategiesAutomation';
@@ -700,4 +701,67 @@ describe('Feature: StrategiesAutomation.ts', () => {
700
701
  expect(loneBoost?.subId).to.equal(1);
701
702
  });
702
703
  });
704
+
705
+ describe('When testing StrategiesAutomation.parseSubscriptionsFromApi', () => {
706
+ const strategiesAutomation = new StrategiesAutomation({
707
+ chainId: ChainId.Ethereum,
708
+ provider: Web3_1,
709
+ providerFork: null!,
710
+ });
711
+
712
+ const owner = '0x9cB7E19861665366011899d74E75d4F2A419aEeD';
713
+ const subData = [
714
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
715
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
716
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
717
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
718
+ ];
719
+ // Aave V3 leverage management: repay (bundle 8, ratio under) and boost (bundle 9, ratio over) for the same owner and market
720
+ const repay: ApiSubscriptionRecord = {
721
+ id: 379,
722
+ wallet: owner,
723
+ wallet_type: 'safe',
724
+ is_enabled: true,
725
+ is_bundle: true,
726
+ strategy_or_bundle_id: 8,
727
+ strategy_ids: [34, 35],
728
+ sub_data_hash: '0xafa4d200be62f171b57b1ae0f4e8348d1ac3f6d0812ad6da74a2adae8037dde1',
729
+ trigger_data: ['0000000000000000000000009cb7e19861665366011899d74e75d4f2a419aeed0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e00000000000000000000000000000000000000000000000019ac8532c27900000000000000000000000000000000000000000000000000000000000000000001'],
730
+ sub_data: subData,
731
+ block_number: 18015756,
732
+ additional_triggers: null,
733
+ };
734
+ const boost: ApiSubscriptionRecord = {
735
+ ...repay,
736
+ id: 380,
737
+ is_enabled: false,
738
+ strategy_or_bundle_id: 9,
739
+ sub_data_hash: '0x1111111111111111111111111111111111111111111111111111111111111111',
740
+ trigger_data: ['0000000000000000000000009cb7e19861665366011899d74e75d4f2a419aeed0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e0000000000000000000000000000000000000000000000002386f26fc10000000000000000000000000000000000000000000000000000000000000000000000'],
741
+ };
742
+
743
+ it('Given API records should return parsed positions', () => {
744
+ const positions = strategiesAutomation.parseSubscriptionsFromApi([repay, boost]);
745
+ expect(positions).to.have.length(2);
746
+ expect(positions.map((p) => p?.subId)).to.eql([379, 380]);
747
+ expect(positions.map((p) => p?.isEnabled)).to.eql([true, false]);
748
+ });
749
+
750
+ it('Given mergeSubs option should merge the repay and boost pair', () => {
751
+ const positions = strategiesAutomation.parseSubscriptionsFromApi([repay, boost], { mergeSubs: true });
752
+ expect(positions).to.have.length(1);
753
+ expect(positions[0]?.subIds).to.eql([379, 380]);
754
+ expect(positions[0]?.isEnabled).to.equal(true);
755
+ });
756
+
757
+ it('Given enabledOnly option should drop disabled records before parsing', () => {
758
+ const positions = strategiesAutomation.parseSubscriptionsFromApi([repay, boost], { enabledOnly: true });
759
+ expect(positions.map((p) => p?.subId)).to.eql([379]);
760
+ });
761
+
762
+ it('Given a record of an unknown strategy should return null for it', () => {
763
+ const positions = strategiesAutomation.parseSubscriptionsFromApi([{ ...repay, strategy_or_bundle_id: 9999 }]);
764
+ expect(positions).to.eql([null]);
765
+ });
766
+ });
703
767
  });
@@ -4,6 +4,7 @@ import type { PastEventOptions } from 'web3-eth-contract';
4
4
  import PromisePool from 'es6-promise-pool';
5
5
  import type {
6
6
  Position, Interfaces, EthereumAddress, SubscriptionOptions, Contract, ParseData, PlaceholderType, BlockNumber,
7
+ ApiSubscriptionRecord,
7
8
  } from '../../types';
8
9
  import type {
9
10
  StrategyModel, Subscribe, SubStorage, UpdateData,
@@ -15,6 +16,7 @@ import { addToObjectIf, isDefined, isUndefined } from '../../services/utils';
15
16
  import { getAbiItem, makeSubStorageContract } from '../../services/contractService';
16
17
  import { getEventsFromContract, multicall } from '../../services/ethereumService';
17
18
  import { parseStrategiesAutomatedPosition } from '../../services/strategiesService';
19
+ import { parseDataFromApiSubscription } from '../../services/apiSubscriptionsService';
18
20
 
19
21
  import Automation from './Automation';
20
22
 
@@ -259,6 +261,21 @@ export default class StrategiesAutomation extends Automation {
259
261
  return this._getSubscriptions(undefined, options);
260
262
  }
261
263
 
264
+ /**
265
+ * @description Parses subscriptions returned by the automation API (GET /v1/subscriptions)
266
+ */
267
+ public parseSubscriptionsFromApi(records: ApiSubscriptionRecord[], options?: SubscriptionOptions): (Position.Automated | null)[] {
268
+ const filtered = options?.enabledOnly ? records.filter((record) => record.is_enabled) : records;
269
+
270
+ let subscriptions = filtered.map((record) => this.getParsedSubscriptions(parseDataFromApiSubscription(record, this.chainId)));
271
+
272
+ if (options?.mergeSubs) {
273
+ subscriptions = this.mergeSubs(subscriptions);
274
+ }
275
+
276
+ return options?.unexpiredOnly ? this.removeExpiredSubscriptions(subscriptions) : subscriptions;
277
+ }
278
+
262
279
  public async getSubscriptionsFor(addresses: EthereumAddress[], options?: SubscriptionOptions): Promise<(Position.Automated | null)[]> {
263
280
  return this._getSubscriptions(addresses, options);
264
281
  }
@@ -684,16 +684,6 @@ export const MAINNET_BUNDLES_INFO: MainnetBundleInfo = {
684
684
  strategyId: Strategies.Identifiers.EoaLiquidationProtection,
685
685
  protocol: PROTOCOLS.Spark,
686
686
  },
687
- [Bundles.MainnetIds.AAVE_V3_SW_INSTANT_CLOSE]: {
688
- strategyOrBundleId: Bundles.MainnetIds.AAVE_V3_SW_INSTANT_CLOSE,
689
- strategyId: Strategies.Identifiers.InstantCloseOnPrice,
690
- protocol: PROTOCOLS.AaveV3,
691
- },
692
- [Bundles.MainnetIds.AAVE_V3_EOA_INSTANT_CLOSE]: {
693
- strategyOrBundleId: Bundles.MainnetIds.AAVE_V3_EOA_INSTANT_CLOSE,
694
- strategyId: Strategies.Identifiers.EoaInstantCloseOnPrice,
695
- protocol: PROTOCOLS.AaveV3,
696
- },
697
687
  };
698
688
 
699
689
  export const OPTIMISM_BUNDLES_INFO: OptimismBundleInfo = {
@@ -762,16 +752,6 @@ export const OPTIMISM_BUNDLES_INFO: OptimismBundleInfo = {
762
752
  strategyId: Strategies.Identifiers.EoaLiquidationProtection,
763
753
  protocol: PROTOCOLS.AaveV3,
764
754
  },
765
- [Bundles.OptimismIds.AAVE_V3_SW_INSTANT_CLOSE]: {
766
- strategyOrBundleId: Bundles.OptimismIds.AAVE_V3_SW_INSTANT_CLOSE,
767
- strategyId: Strategies.Identifiers.InstantCloseOnPrice,
768
- protocol: PROTOCOLS.AaveV3,
769
- },
770
- [Bundles.OptimismIds.AAVE_V3_EOA_INSTANT_CLOSE]: {
771
- strategyOrBundleId: Bundles.OptimismIds.AAVE_V3_EOA_INSTANT_CLOSE,
772
- strategyId: Strategies.Identifiers.EoaInstantCloseOnPrice,
773
- protocol: PROTOCOLS.AaveV3,
774
- },
775
755
  };
776
756
 
777
757
  export const BASE_BUNDLES_INFO: BaseBundleInfo = {
@@ -975,16 +955,6 @@ export const BASE_BUNDLES_INFO: BaseBundleInfo = {
975
955
  strategyId: Strategies.Identifiers.EoaCloseOnPrice,
976
956
  protocol: PROTOCOLS.MorphoBlue,
977
957
  },
978
- [Bundles.BaseIds.AAVE_V3_SW_INSTANT_CLOSE]: {
979
- strategyOrBundleId: Bundles.BaseIds.AAVE_V3_SW_INSTANT_CLOSE,
980
- strategyId: Strategies.Identifiers.InstantCloseOnPrice,
981
- protocol: PROTOCOLS.AaveV3,
982
- },
983
- [Bundles.BaseIds.AAVE_V3_EOA_INSTANT_CLOSE]: {
984
- strategyOrBundleId: Bundles.BaseIds.AAVE_V3_EOA_INSTANT_CLOSE,
985
- strategyId: Strategies.Identifiers.EoaInstantCloseOnPrice,
986
- protocol: PROTOCOLS.AaveV3,
987
- },
988
958
  };
989
959
 
990
960
  export const ARBITRUM_BUNDLES_INFO: ArbitrumBundleInfo = {
@@ -1189,16 +1159,6 @@ export const ARBITRUM_BUNDLES_INFO: ArbitrumBundleInfo = {
1189
1159
  strategyId: Strategies.Identifiers.EoaCloseOnPrice,
1190
1160
  protocol: PROTOCOLS.MorphoBlue,
1191
1161
  },
1192
- [Bundles.ArbitrumIds.AAVE_V3_SW_INSTANT_CLOSE]: {
1193
- strategyOrBundleId: Bundles.ArbitrumIds.AAVE_V3_SW_INSTANT_CLOSE,
1194
- strategyId: Strategies.Identifiers.InstantCloseOnPrice,
1195
- protocol: PROTOCOLS.AaveV3,
1196
- },
1197
- [Bundles.ArbitrumIds.AAVE_V3_EOA_INSTANT_CLOSE]: {
1198
- strategyOrBundleId: Bundles.ArbitrumIds.AAVE_V3_EOA_INSTANT_CLOSE,
1199
- strategyId: Strategies.Identifiers.EoaInstantCloseOnPrice,
1200
- protocol: PROTOCOLS.AaveV3,
1201
- },
1202
1162
  };
1203
1163
 
1204
1164
  export const BUNDLES_INFO: BundlesInfo = {