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

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 +40 -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 +8 -21
  10. package/cjs/services/strategiesService.test.js +0 -63
  11. package/cjs/services/strategySubService.d.ts +1 -1
  12. package/cjs/services/strategySubService.js +6 -7
  13. package/cjs/services/strategySubService.test.js +71 -111
  14. package/cjs/services/subDataService.d.ts +10 -12
  15. package/cjs/services/subDataService.js +30 -36
  16. package/cjs/services/subDataService.test.js +104 -70
  17. package/cjs/types/enums.d.ts +18 -18
  18. package/cjs/types/enums.js +10 -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 +40 -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 +8 -21
  29. package/esm/services/strategiesService.test.js +1 -64
  30. package/esm/services/strategySubService.d.ts +1 -1
  31. package/esm/services/strategySubService.js +6 -7
  32. package/esm/services/strategySubService.test.js +71 -111
  33. package/esm/services/subDataService.d.ts +10 -12
  34. package/esm/services/subDataService.js +29 -35
  35. package/esm/services/subDataService.test.js +104 -70
  36. package/esm/types/enums.d.ts +18 -18
  37. package/esm/types/enums.js +10 -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 +40 -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 +8 -27
  47. package/src/services/strategySubService.test.ts +84 -125
  48. package/src/services/strategySubService.ts +16 -20
  49. package/src/services/subDataService.test.ts +108 -98
  50. package/src/services/subDataService.ts +40 -51
  51. package/src/types/enums.ts +10 -11
  52. package/src/types/index.ts +26 -2
@@ -687,68 +687,55 @@ export const aaveV3CloseGenericSubData = {
687
687
  };
688
688
  },
689
689
  };
690
- export const aaveV3InstantCloseGenericSubData = {
690
+ export const aaveV3CollateralSwitchSubData = {
691
691
  encode(
692
- collAsset: EthereumAddress,
693
- collAssetId: number,
694
- debtAsset: EthereumAddress,
695
- debtAssetId: number,
696
- closeType: CloseStrategyType,
692
+ fromAsset: EthereumAddress,
693
+ fromAssetId: number,
694
+ toAsset: EthereumAddress,
695
+ toAssetId: number,
697
696
  marketAddr: EthereumAddress,
698
- user: EthereumAddress,
699
- tsi: string,
700
- slippage: string,
697
+ amountToSwitch: string,
698
+ useOnBehalf: boolean = false,
701
699
  ): SubData {
702
- const encodedColl = AbiCoder.encodeParameter('address', collAsset);
703
- const encodedCollId = AbiCoder.encodeParameter('uint16', collAssetId);
704
- const encodedDebt = AbiCoder.encodeParameter('address', debtAsset);
705
- const encodedDebtId = AbiCoder.encodeParameter('uint16', debtAssetId);
706
- const encodedCloseType = AbiCoder.encodeParameter('uint8', closeType);
707
- const encodedMarket = AbiCoder.encodeParameter('address', marketAddr);
708
- const encodedUser = AbiCoder.encodeParameter('address', user);
709
- const encodedTsi = AbiCoder.encodeParameter('uint256', tsi);
710
- const encodedSlippage = AbiCoder.encodeParameter('uint256', slippage);
700
+ const encodedFromAsset = AbiCoder.encodeParameter('address', fromAsset);
701
+ const encodedFromAssetId = AbiCoder.encodeParameter('uint8', fromAssetId);
702
+ const encodedToAsset = AbiCoder.encodeParameter('address', toAsset);
703
+ const encodedToAssetId = AbiCoder.encodeParameter('uint8', toAssetId);
704
+ const encodedMarketAddr = AbiCoder.encodeParameter('address', marketAddr);
705
+ const encodedAmountToSwitch = AbiCoder.encodeParameter('uint256', amountToSwitch);
706
+ const encodedUseOnBehalf = AbiCoder.encodeParameter('bool', useOnBehalf);
711
707
 
712
708
  return [
713
- encodedColl,
714
- encodedCollId,
715
- encodedDebt,
716
- encodedDebtId,
717
- encodedCloseType,
718
- encodedMarket,
719
- encodedUser,
720
- encodedTsi,
721
- encodedSlippage,
709
+ encodedFromAsset,
710
+ encodedFromAssetId,
711
+ encodedToAsset,
712
+ encodedToAssetId,
713
+ encodedMarketAddr,
714
+ encodedAmountToSwitch,
715
+ encodedUseOnBehalf,
722
716
  ];
723
717
  },
724
-
725
718
  decode(subData: SubData): {
726
- collAsset: EthereumAddress,
727
- collAssetId: number,
728
- debtAsset: EthereumAddress,
729
- debtAssetId: number,
730
- closeType: CloseStrategyType,
719
+ fromAsset: EthereumAddress,
720
+ fromAssetId: number,
721
+ toAsset: EthereumAddress,
722
+ toAssetId: number,
731
723
  marketAddr: EthereumAddress,
732
- owner: EthereumAddress,
733
- tsi: string,
734
- slippage: string,
724
+ amountToSwitch: string,
735
725
  } {
736
- const collAsset = AbiCoder.decodeParameter('address', subData[0]) as unknown as EthereumAddress;
737
- const collAssetId = Number(AbiCoder.decodeParameter('uint16', subData[1]));
738
- const debtAsset = AbiCoder.decodeParameter('address', subData[2]) as unknown as EthereumAddress;
739
- const debtAssetId = Number(AbiCoder.decodeParameter('uint16', subData[3]));
740
- const closeType = Number(AbiCoder.decodeParameter('uint8', subData[4])) as CloseStrategyType;
741
- const marketAddr = AbiCoder.decodeParameter('address', subData[5]) as unknown as EthereumAddress;
742
- const owner = AbiCoder.decodeParameter('address', subData[6]) as unknown as EthereumAddress;
743
- const tsi = AbiCoder.decodeParameter('uint256', subData[7]) as unknown as string;
744
- const slippage = AbiCoder.decodeParameter('uint256', subData[8]) as unknown as string;
726
+ const fromAsset = AbiCoder.decodeParameter('address', subData[0]) as unknown as EthereumAddress;
727
+ const fromAssetId = Number(AbiCoder.decodeParameter('uint8', subData[1]));
728
+ const toAsset = AbiCoder.decodeParameter('address', subData[2]) as unknown as EthereumAddress;
729
+ const toAssetId = Number(AbiCoder.decodeParameter('uint8', subData[3]));
730
+ const marketAddr = AbiCoder.decodeParameter('address', subData[4]) as unknown as EthereumAddress;
731
+ const amountToSwitch = AbiCoder.decodeParameter('uint256', subData[5]) as unknown as string;
745
732
 
746
733
  return {
747
- collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr, owner, tsi, slippage,
734
+ fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch,
748
735
  };
749
736
  },
750
737
  };
751
- export const aaveV3CollateralSwitchSubData = {
738
+ export const aaveV3DebtSwitchSubData = {
752
739
  encode(
753
740
  fromAsset: EthereumAddress,
754
741
  fromAssetId: number,
@@ -756,7 +743,7 @@ export const aaveV3CollateralSwitchSubData = {
756
743
  toAssetId: number,
757
744
  marketAddr: EthereumAddress,
758
745
  amountToSwitch: string,
759
- useOnBehalf: boolean = false,
746
+ user: EthereumAddress,
760
747
  ): SubData {
761
748
  const encodedFromAsset = AbiCoder.encodeParameter('address', fromAsset);
762
749
  const encodedFromAssetId = AbiCoder.encodeParameter('uint8', fromAssetId);
@@ -764,7 +751,7 @@ export const aaveV3CollateralSwitchSubData = {
764
751
  const encodedToAssetId = AbiCoder.encodeParameter('uint8', toAssetId);
765
752
  const encodedMarketAddr = AbiCoder.encodeParameter('address', marketAddr);
766
753
  const encodedAmountToSwitch = AbiCoder.encodeParameter('uint256', amountToSwitch);
767
- const encodedUseOnBehalf = AbiCoder.encodeParameter('bool', useOnBehalf);
754
+ const encodedUser = AbiCoder.encodeParameter('address', user);
768
755
 
769
756
  return [
770
757
  encodedFromAsset,
@@ -773,7 +760,7 @@ export const aaveV3CollateralSwitchSubData = {
773
760
  encodedToAssetId,
774
761
  encodedMarketAddr,
775
762
  encodedAmountToSwitch,
776
- encodedUseOnBehalf,
763
+ encodedUser,
777
764
  ];
778
765
  },
779
766
  decode(subData: SubData): {
@@ -783,6 +770,7 @@ export const aaveV3CollateralSwitchSubData = {
783
770
  toAssetId: number,
784
771
  marketAddr: EthereumAddress,
785
772
  amountToSwitch: string,
773
+ user: EthereumAddress,
786
774
  } {
787
775
  const fromAsset = AbiCoder.decodeParameter('address', subData[0]) as unknown as EthereumAddress;
788
776
  const fromAssetId = Number(AbiCoder.decodeParameter('uint8', subData[1]));
@@ -790,9 +778,10 @@ export const aaveV3CollateralSwitchSubData = {
790
778
  const toAssetId = Number(AbiCoder.decodeParameter('uint8', subData[3]));
791
779
  const marketAddr = AbiCoder.decodeParameter('address', subData[4]) as unknown as EthereumAddress;
792
780
  const amountToSwitch = AbiCoder.decodeParameter('uint256', subData[5]) as unknown as string;
781
+ const user = AbiCoder.decodeParameter('address', subData[6]) as unknown as EthereumAddress;
793
782
 
794
783
  return {
795
- fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch,
784
+ fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user,
796
785
  };
797
786
  },
798
787
  };
@@ -102,24 +102,32 @@ export namespace Strategies {
102
102
  AAVE_V4_COLLATERAL_SWITCH_EOA = 155,
103
103
  SPARK_COLLATERAL_SWITCH = 156,
104
104
  SPARK_GENERIC_FL_COLLATERAL_SWITCH = 167,
105
+ AAVE_V3_DEBT_SWITCH = 168,
106
+ AAVE_V3_DEBT_SWITCH_EOA = 169,
105
107
  }
106
108
 
107
109
  export enum OptimismIds {
108
110
  EXCHANGE_DCA = 8,
109
111
  EXCHANGE_LIMIT_ORDER = 9,
110
112
  AAVE_V3_COLLATERAL_SWITCH = 24,
113
+ AAVE_V3_DEBT_SWITCH = 25,
114
+ AAVE_V3_DEBT_SWITCH_EOA = 26,
111
115
  }
112
116
 
113
117
  export enum BaseIds {
114
118
  EXCHANGE_DCA = 8,
115
119
  EXCHANGE_LIMIT_ORDER = 9,
116
120
  AAVE_V3_COLLATERAL_SWITCH = 56,
121
+ AAVE_V3_DEBT_SWITCH = 61,
122
+ AAVE_V3_DEBT_SWITCH_EOA = 62,
117
123
  }
118
124
 
119
125
  export enum ArbitrumIds {
120
126
  EXCHANGE_DCA = 8,
121
127
  EXCHANGE_LIMIT_ORDER = 9,
122
128
  AAVE_V3_COLLATERAL_SWITCH = 50,
129
+ AAVE_V3_DEBT_SWITCH = 55,
130
+ AAVE_V3_DEBT_SWITCH_EOA = 56,
123
131
  }
124
132
 
125
133
  export enum Identifiers {
@@ -138,8 +146,6 @@ export namespace Strategies {
138
146
  CloseOnPriceToColl = 'close-on-price-to-collateral',
139
147
  CloseOnPrice = 'close-on-price',
140
148
  EoaCloseOnPrice = 'eoa-close-on-price',
141
- InstantCloseOnPrice = 'instant-close-on-price',
142
- EoaInstantCloseOnPrice = 'eoa-instant-close-on-price',
143
149
  TrailingStopToColl = 'trailing-stop-to-collateral',
144
150
  TrailingStopToDebt = 'trailing-stop-to-debt',
145
151
  Rebond = 'rebond',
@@ -156,6 +162,8 @@ export namespace Strategies {
156
162
  EoaRepayOnPrice = 'eoa-repay-on-price',
157
163
  CollateralSwitch = 'collateral-switch',
158
164
  EoaCollateralSwitch = 'eoa-collateral-switch',
165
+ DebtSwitch = 'debt-switch',
166
+ EoaDebtSwitch = 'eoa-debt-switch',
159
167
  LiquidationProtection = 'liquidation-protection',
160
168
  EoaLiquidationProtection = 'liquidation-protection-eoa',
161
169
  }
@@ -268,8 +276,6 @@ export namespace Bundles {
268
276
  SPARK_EOA_BOOST_ON_PRICE = 91,
269
277
  SPARK_EOA_CLOSE = 92,
270
278
  SPARK_EOA_LIQUIDATION_PROTECTION = 93,
271
- AAVE_V3_SW_INSTANT_CLOSE = 94,
272
- AAVE_V3_EOA_INSTANT_CLOSE = 95,
273
279
  }
274
280
 
275
281
  export enum OptimismIds {
@@ -286,9 +292,6 @@ export namespace Bundles {
286
292
  AAVE_V3_EOA_CLOSE = 10,
287
293
  AAVE_V3_SW_LIQUIDATION_PROTECTION = 11,
288
294
  AAVE_V3_EOA_LIQUIDATION_PROTECTION = 12,
289
- // TODO -> Fix ids
290
- AAVE_V3_SW_INSTANT_CLOSE = 13,
291
- AAVE_V3_EOA_INSTANT_CLOSE = 14,
292
295
  }
293
296
 
294
297
  export enum BaseIds {
@@ -332,8 +335,6 @@ export namespace Bundles {
332
335
  MORPHO_BLUE_EOA_REPAY_ON_PRICE = 40,
333
336
  MORPHO_BLUE_EOA_CLOSE = 41,
334
337
  MORPHO_BLUE_EOA_LIQUIDATION_PROTECTION = 42,
335
- AAVE_V3_SW_INSTANT_CLOSE = 43,
336
- AAVE_V3_EOA_INSTANT_CLOSE = 44,
337
338
  }
338
339
 
339
340
  export enum ArbitrumIds {
@@ -377,7 +378,5 @@ export namespace Bundles {
377
378
  MORPHO_BLUE_EOA_BOOST_ON_PRICE = 37,
378
379
  MORPHO_BLUE_EOA_REPAY_ON_PRICE = 38,
379
380
  MORPHO_BLUE_EOA_CLOSE = 39,
380
- AAVE_V3_SW_INSTANT_CLOSE = 40,
381
- AAVE_V3_EOA_INSTANT_CLOSE = 41,
382
381
  }
383
382
  }
@@ -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 {
6
6
  ChainId, Strategies, Bundles, ProtocolIdentifiers,
7
7
  RatioState,
@@ -72,6 +72,22 @@ interface _SubscriptionOptions {
72
72
 
73
73
  export type SubscriptionOptions = Partial<_SubscriptionOptions>;
74
74
 
75
+ /** Subscription record as returned by the automation API (GET /v1/subscriptions) */
76
+ export interface ApiSubscriptionRecord {
77
+ id: number,
78
+ wallet: EthereumAddress,
79
+ wallet_type: string,
80
+ is_enabled: boolean,
81
+ is_bundle: boolean,
82
+ strategy_or_bundle_id: number,
83
+ strategy_ids: number[],
84
+ sub_data_hash: string,
85
+ trigger_data: string[],
86
+ sub_data: string[],
87
+ block_number: number,
88
+ additional_triggers: string[] | null,
89
+ }
90
+
75
91
  export declare namespace Interfaces {
76
92
  interface ProtocolBase {
77
93
  id: ProtocolIdentifiers.StrategiesAutomation | ProtocolIdentifiers.LegacyAutomation,
@@ -369,10 +385,18 @@ export type StrategyOrBundleIds =
369
385
  | typeof Bundles.ArbitrumIds[keyof typeof Bundles.ArbitrumIds]
370
386
  | typeof Bundles.BaseIds[keyof typeof Bundles.BaseIds];
371
387
 
388
+ /** Fields of the Subscribe event that parsing relies on */
389
+ export interface SubscriptionEventData {
390
+ subId: string,
391
+ proxy: EthereumAddress,
392
+ subHash: string,
393
+ subStruct: StrategyModel.StrategySubStructOutputStruct,
394
+ }
395
+
372
396
  export interface ParseData {
373
397
  chainId: ChainId,
374
398
  blockNumber: BlockNumber,
375
- subscriptionEventData: Subscribe['returnValues']
399
+ subscriptionEventData: SubscriptionEventData,
376
400
  strategiesSubsData: StrategyModel.StoredSubDataStructOutputStruct,
377
401
  }
378
402