@defisaver/automation-sdk 3.1.3 → 3.1.4-dev-2

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 (49) hide show
  1. package/cjs/automation/private/StrategiesAutomation.d.ts +2 -2
  2. package/cjs/automation/public/Strategies.test.d.ts +1 -0
  3. package/cjs/automation/public/Strategies.test.js +61 -0
  4. package/cjs/constants/index.js +35 -15
  5. package/cjs/services/strategiesService.js +68 -3
  6. package/cjs/services/strategySubService.d.ts +6 -2
  7. package/cjs/services/strategySubService.js +25 -3
  8. package/cjs/services/strategySubService.test.js +2 -2
  9. package/cjs/services/subDataService.d.ts +21 -2
  10. package/cjs/services/subDataService.js +56 -2
  11. package/cjs/services/subDataService.test.js +3 -3
  12. package/cjs/services/triggerService.d.ts +17 -0
  13. package/cjs/services/triggerService.js +33 -1
  14. package/cjs/services/utils.d.ts +6 -1
  15. package/cjs/services/utils.js +52 -1
  16. package/cjs/types/enums.d.ts +40 -11
  17. package/cjs/types/enums.js +37 -4
  18. package/cjs/types/index.d.ts +12 -3
  19. package/esm/automation/private/StrategiesAutomation.d.ts +2 -2
  20. package/esm/automation/public/Strategies.test.d.ts +1 -0
  21. package/esm/automation/public/Strategies.test.js +56 -0
  22. package/esm/constants/index.js +35 -15
  23. package/esm/services/strategiesService.js +69 -4
  24. package/esm/services/strategySubService.d.ts +6 -2
  25. package/esm/services/strategySubService.js +26 -4
  26. package/esm/services/strategySubService.test.js +2 -2
  27. package/esm/services/subDataService.d.ts +21 -2
  28. package/esm/services/subDataService.js +56 -2
  29. package/esm/services/subDataService.test.js +4 -4
  30. package/esm/services/triggerService.d.ts +17 -0
  31. package/esm/services/triggerService.js +32 -0
  32. package/esm/services/utils.d.ts +6 -1
  33. package/esm/services/utils.js +50 -1
  34. package/esm/types/enums.d.ts +40 -11
  35. package/esm/types/enums.js +36 -3
  36. package/esm/types/index.d.ts +12 -3
  37. package/package.json +1 -1
  38. package/src/automation/private/StrategiesAutomation.ts +2 -2
  39. package/src/automation/public/Strategies.test.ts +49 -0
  40. package/src/constants/index.ts +47 -16
  41. package/src/services/strategiesService.ts +89 -4
  42. package/src/services/strategySubService.test.ts +2 -2
  43. package/src/services/strategySubService.ts +52 -3
  44. package/src/services/subDataService.test.ts +4 -4
  45. package/src/services/subDataService.ts +85 -4
  46. package/src/services/triggerService.ts +53 -0
  47. package/src/services/utils.ts +60 -1
  48. package/src/types/enums.ts +36 -3
  49. package/src/types/index.ts +14 -2
@@ -4,7 +4,9 @@ import AbiCoder from 'web3-eth-abi';
4
4
  import { getAssetInfo, getAssetInfoByAddress } from '@defisaver/tokens';
5
5
 
6
6
  import type { EthereumAddress } from '../types';
7
- import { ChainId, RatioState } from '../types/enums';
7
+ import {
8
+ ChainId, CloseStrategyType, CloseToAssetType, RatioState,
9
+ } from '../types/enums';
8
10
 
9
11
  export function isDefined<T>(value: T): value is NonNullable<T> {
10
12
  return value !== undefined && value !== null;
@@ -101,4 +103,61 @@ export function getRatioStateInfoForAaveCloseStrategy(
101
103
 
102
104
  export function getPositionId(...args: (number | string)[]) {
103
105
  return args.map(arg => arg.toString().toLowerCase().split(' ').join('_')).join('-');
106
+ }
107
+
108
+ export function getCloseStrategyType(
109
+ stopLossPrice: number,
110
+ stopLossType: CloseToAssetType,
111
+ takeProfitPrice: number,
112
+ takeProfitType: CloseToAssetType,
113
+ ): CloseStrategyType {
114
+ const isStopLoss = stopLossPrice > 0;
115
+ const isTakeProfit = takeProfitPrice > 0;
116
+
117
+ if (!isStopLoss && !isTakeProfit) {
118
+ throw new Error('CloseOnPrice: At least one price must be defined');
119
+ }
120
+
121
+ if (isStopLoss && isTakeProfit) {
122
+ if (stopLossType === CloseToAssetType.COLLATERAL && takeProfitType === CloseToAssetType.COLLATERAL) {
123
+ return CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_COLLATERAL;
124
+ } if (stopLossType === CloseToAssetType.COLLATERAL) {
125
+ return CloseStrategyType.TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL;
126
+ } if (takeProfitType === CloseToAssetType.COLLATERAL) {
127
+ return CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT;
128
+ }
129
+ return CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT;
130
+ } if (isStopLoss) {
131
+ return stopLossType === CloseToAssetType.COLLATERAL
132
+ ? CloseStrategyType.STOP_LOSS_IN_COLLATERAL
133
+ : CloseStrategyType.STOP_LOSS_IN_DEBT;
134
+ }
135
+ return takeProfitType === CloseToAssetType.COLLATERAL
136
+ ? CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL
137
+ : CloseStrategyType.TAKE_PROFIT_IN_DEBT;
138
+ }
139
+
140
+ export function getStopLossAndTakeProfitTypeByCloseStrategyType(
141
+ closeStrategyType: CloseStrategyType,
142
+ ): { stopLossType: CloseToAssetType | undefined, takeProfitType: CloseToAssetType | undefined } {
143
+ switch (closeStrategyType) {
144
+ case CloseStrategyType.STOP_LOSS_IN_COLLATERAL:
145
+ return { stopLossType: CloseToAssetType.COLLATERAL, takeProfitType: undefined };
146
+ case CloseStrategyType.STOP_LOSS_IN_DEBT:
147
+ return { stopLossType: CloseToAssetType.DEBT, takeProfitType: undefined };
148
+ case CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL:
149
+ return { stopLossType: undefined, takeProfitType: CloseToAssetType.COLLATERAL };
150
+ case CloseStrategyType.TAKE_PROFIT_IN_DEBT:
151
+ return { stopLossType: undefined, takeProfitType: CloseToAssetType.DEBT };
152
+ case CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT:
153
+ return { stopLossType: CloseToAssetType.DEBT, takeProfitType: CloseToAssetType.COLLATERAL };
154
+ case CloseStrategyType.TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL:
155
+ return { stopLossType: CloseToAssetType.COLLATERAL, takeProfitType: CloseToAssetType.DEBT };
156
+ case CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT:
157
+ return { stopLossType: CloseToAssetType.DEBT, takeProfitType: CloseToAssetType.DEBT };
158
+ case CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_COLLATERAL:
159
+ return { stopLossType: CloseToAssetType.COLLATERAL, takeProfitType: CloseToAssetType.COLLATERAL };
160
+ default:
161
+ throw new Error('CloseStrategyType not supported');
162
+ }
104
163
  }
@@ -21,6 +21,32 @@ export enum BundleProtocols {
21
21
  Rari = 'rari',
22
22
  }
23
23
 
24
+ export enum CollActionType {
25
+ SUPPLY = 0,
26
+ WITHDRAW = 1,
27
+ }
28
+
29
+ export enum DebtActionType {
30
+ PAYBACK = 0,
31
+ BORROW = 1,
32
+ }
33
+
34
+ export enum CloseStrategyType {
35
+ TAKE_PROFIT_IN_COLLATERAL = 0,
36
+ STOP_LOSS_IN_COLLATERAL = 1,
37
+ TAKE_PROFIT_IN_DEBT = 2,
38
+ STOP_LOSS_IN_DEBT = 3,
39
+ TAKE_PROFIT_AND_STOP_LOSS_IN_COLLATERAL = 4,
40
+ TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT = 5,
41
+ TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT = 6,
42
+ TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL = 7,
43
+ }
44
+
45
+ export enum CloseToAssetType {
46
+ COLLATERAL = 0,
47
+ DEBT = 1,
48
+ }
49
+
24
50
  /**
25
51
  * @dev Follow the naming convention:
26
52
  * - Enum name consists of two parts, name and version
@@ -32,6 +58,7 @@ export namespace ProtocolIdentifiers {
32
58
  export enum StrategiesAutomation {
33
59
  MakerDAO = 'MakerDAO',
34
60
  Liquity = 'Liquity',
61
+ LiquityV2 = 'Liquity__V2',
35
62
  ChickenBonds = 'Chicken Bonds',
36
63
  CompoundV2 = 'Compound__V2',
37
64
  CompoundV3 = 'Compound__V3',
@@ -67,13 +94,11 @@ export namespace Strategies {
67
94
  LIQUITY_DSR_SUPPLY = 70,
68
95
  LIQUITY_DEBT_IN_FRONT_REPAY = 75,
69
96
  CURVEUSD_PAYBACK = 92,
70
- AAVE_V3_OPEN_ORDER_FROM_DEBT = 96,
71
97
  }
72
98
 
73
99
  export enum OptimismIds {
74
100
  EXCHANGE_DCA = 8,
75
101
  EXCHANGE_LIMIT_ORDER = 9,
76
- AAVE_V3_OPEN_ORDER_FROM_DEBT = 12,
77
102
  }
78
103
 
79
104
  export enum BaseIds {
@@ -84,7 +109,6 @@ export namespace Strategies {
84
109
  export enum ArbitrumIds {
85
110
  EXCHANGE_DCA = 8,
86
111
  EXCHANGE_LIMIT_ORDER = 9,
87
- AAVE_V3_OPEN_ORDER_FROM_DEBT = 16,
88
112
  }
89
113
 
90
114
  export enum Identifiers {
@@ -101,6 +125,7 @@ export namespace Strategies {
101
125
  CloseToCollateralWithGasPrice = 'close-to-collateral-with-gas-price',
102
126
  CloseOnPriceToDebt = 'close-on-price-to-debt',
103
127
  CloseOnPriceToColl = 'close-on-price-to-collateral',
128
+ CloseOnPrice = 'close-on-price',
104
129
  TrailingStopToColl = 'trailing-stop-to-collateral',
105
130
  TrailingStopToDebt = 'trailing-stop-to-debt',
106
131
  Rebond = 'rebond',
@@ -111,6 +136,7 @@ export namespace Strategies {
111
136
  DebtInFrontRepay = 'debt-in-front-repay',
112
137
  OpenOrderFromCollateral = 'open-order-from-collateral',
113
138
  OpenOrderFromDebt = 'open-order-from-debt',
139
+ RepayOnPrice = 'repay-on-price',
114
140
  }
115
141
  export enum IdOverrides {
116
142
  TakeProfit = 'take-profit',
@@ -164,6 +190,10 @@ export namespace Bundles {
164
190
  MORPHO_BLUE_EOA_REPAY = 34,
165
191
  MORPHO_BLUE_EOA_BOOST = 35,
166
192
  AAVE_V3_OPEN_ORDER_FROM_COLLATERAL = 36,
193
+ AAVE_V3_REPAY_ON_PRICE = 37,
194
+ LIQUITY_V2_REPAY = 39,
195
+ LIQUITY_V2_BOOST = 40,
196
+ LIQUITY_V2_CLOSE = 41,
167
197
  }
168
198
 
169
199
  export enum OptimismIds {
@@ -172,6 +202,7 @@ export namespace Bundles {
172
202
  AAVE_V3_CLOSE_TO_DEBT = 2,
173
203
  AAVE_V3_CLOSE_TO_COLLATERAL = 3,
174
204
  AAVE_V3_OPEN_ORDER_FROM_COLLATERAL = 4,
205
+ AAVE_V3_REPAY_ON_PRICE = 5,
175
206
  }
176
207
 
177
208
  export enum BaseIds {
@@ -184,6 +215,7 @@ export namespace Bundles {
184
215
  MORPHO_BLUE_REPAY = 8,
185
216
  MORPHO_BLUE_BOOST = 9,
186
217
  AAVE_V3_OPEN_ORDER_FROM_COLLATERAL = 10,
218
+ AAVE_V3_REPAY_ON_PRICE = 11,
187
219
  }
188
220
 
189
221
  export enum ArbitrumIds {
@@ -194,6 +226,7 @@ export namespace Bundles {
194
226
  COMP_V3_SW_REPAY_BUNDLE = 4,
195
227
  COMP_V3_SW_BOOST_BUNDLE = 5,
196
228
  AAVE_V3_OPEN_ORDER_FROM_COLLATERAL = 6,
229
+ AAVE_V3_REPAY_ON_PRICE = 7,
197
230
  }
198
231
  }
199
232
 
@@ -5,6 +5,7 @@ import type { Subscribe, StrategyModel } from './contracts/generated/SubStorage'
5
5
  import type {
6
6
  ChainId, Strategies, Bundles, ProtocolIdentifiers,
7
7
  RatioState,
8
+ CloseToAssetType,
8
9
  } from './enums';
9
10
 
10
11
  export type PlaceholderType = any; // TODO - fix any types
@@ -90,7 +91,7 @@ export declare namespace Interfaces {
90
91
 
91
92
  interface Automation {
92
93
  provider: Web3,
93
- providerFork: Web3,
94
+ providerFork?: Web3,
94
95
  }
95
96
  interface LegacyAutomation<T extends BaseContract> {
96
97
  provider: Web3,
@@ -161,6 +162,16 @@ export declare namespace Position {
161
162
  ratioState: RatioState,
162
163
  }
163
164
 
165
+ interface CloseOnPriceLiquityV2 extends Base {
166
+ market: EthereumAddress,
167
+ troveId: string,
168
+ stopLossPrice: string,
169
+ takeProfitPrice: string,
170
+ closeToAssetAddr: EthereumAddress,
171
+ stopLossType: CloseToAssetType | undefined,
172
+ takeProfitType: CloseToAssetType | undefined,
173
+ }
174
+
164
175
  interface TrailingStop extends Base {
165
176
  roundId: number,
166
177
  triggerPercentage: number,
@@ -186,7 +197,8 @@ export declare namespace Position {
186
197
  | Specific.BoostOnPriceAave
187
198
  | Specific.CloseOnPriceWithMaximumGasPriceAave
188
199
  | Specific.DebtInFrontRepay
189
- | Specific.LeverageManagementCrvUSD;
200
+ | Specific.LeverageManagementCrvUSD
201
+ | Specific.CloseOnPriceLiquityV2;
190
202
 
191
203
  export interface Automated {
192
204
  chainId: ChainId,