@defisaver/automation-sdk 3.2.4-dev-1 → 3.2.5

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 +0 -90
  2. package/cjs/services/strategiesService.js +1 -48
  3. package/cjs/services/strategySubService.d.ts +1 -2
  4. package/cjs/services/strategySubService.js +6 -13
  5. package/cjs/services/strategySubService.test.js +0 -108
  6. package/cjs/services/subDataService.d.ts +7 -18
  7. package/cjs/services/subDataService.js +15 -48
  8. package/cjs/services/subDataService.test.js +48 -124
  9. package/cjs/services/triggerService.d.ts +0 -18
  10. package/cjs/services/triggerService.js +1 -36
  11. package/cjs/services/triggerService.test.js +0 -92
  12. package/cjs/types/enums.d.ts +5 -28
  13. package/cjs/types/enums.js +0 -23
  14. package/cjs/types/index.d.ts +1 -17
  15. package/esm/constants/index.js +0 -90
  16. package/esm/services/strategiesService.js +1 -48
  17. package/esm/services/strategySubService.d.ts +1 -2
  18. package/esm/services/strategySubService.js +6 -13
  19. package/esm/services/strategySubService.test.js +1 -109
  20. package/esm/services/subDataService.d.ts +7 -18
  21. package/esm/services/subDataService.js +14 -47
  22. package/esm/services/subDataService.test.js +48 -124
  23. package/esm/services/triggerService.d.ts +0 -18
  24. package/esm/services/triggerService.js +0 -35
  25. package/esm/services/triggerService.test.js +1 -93
  26. package/esm/types/enums.d.ts +5 -28
  27. package/esm/types/enums.js +0 -23
  28. package/esm/types/index.d.ts +1 -17
  29. package/package.json +2 -2
  30. package/src/constants/index.ts +1 -90
  31. package/src/services/strategiesService.ts +1 -62
  32. package/src/services/strategySubService.test.ts +1 -115
  33. package/src/services/strategySubService.ts +14 -33
  34. package/src/services/subDataService.test.ts +73 -128
  35. package/src/services/subDataService.ts +20 -73
  36. package/src/services/triggerService.test.ts +0 -102
  37. package/src/services/triggerService.ts +0 -55
  38. package/src/types/enums.ts +0 -23
  39. package/src/types/index.ts +1 -22
@@ -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, sparkQuotePriceTrigger, sparkRatioTrigger, trailingStopTrigger, liquityDebtInFrontWithLimitTrigger, crvUSDRatioTrigger, morphoBlueRatioTrigger, crvUsdHealthRatioTrigger, liquityV2DebtInFrontTrigger, liquityV2AdjustTimeTrigger, compoundV3PriceRangeTrigger, } from './triggerService';
6
+ import { aaveV2RatioTrigger, aaveV3QuotePriceTrigger, aaveV3QuotePriceWithMaximumGasPriceTrigger, aaveV3RatioTrigger, cBondsRebondTrigger, chainlinkPriceTrigger, compoundV2RatioTrigger, compoundV3RatioTrigger, curveUsdBorrowRateTrigger, curveUsdSoftLiquidationTrigger, exchangeOffchainPriceTrigger, exchangeTimestampTrigger, liquityDebtInFrontTrigger, makerRatioTrigger, morphoAaveV2RatioTrigger, sparkQuotePriceTrigger, sparkRatioTrigger, trailingStopTrigger, liquityDebtInFrontWithLimitTrigger, crvUSDRatioTrigger, morphoBlueRatioTrigger, crvUsdHealthRatioTrigger, liquityV2DebtInFrontTrigger, liquityV2AdjustTimeTrigger, } from './triggerService';
7
7
  describe('Feature: triggerService.ts', () => {
8
8
  describe('When testing triggerService.chainlinkPriceTrigger', () => {
9
9
  describe('encode()', () => {
@@ -1017,96 +1017,4 @@ describe('Feature: triggerService.ts', () => {
1017
1017
  });
1018
1018
  });
1019
1019
  });
1020
- describe('When testing triggerService.compoundV3PriceTrigger', () => {
1021
- describe('encode()', () => {
1022
- const examples = [
1023
- [
1024
- ['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000002e90edd0000000000000000000000000000000000000000000000000000000000000000001'],
1025
- [web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'), web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'), 2000, RatioState.UNDER]
1026
- ],
1027
- [
1028
- ['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000045d964b8000000000000000000000000000000000000000000000000000000000000000000'],
1029
- [web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'), web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'), 3000, RatioState.OVER]
1030
- ],
1031
- ];
1032
- examples.forEach(([expected, actual]) => {
1033
- it(`Given ${actual} should return expected value: ${expected}`, () => {
1034
- expect(compoundV3PriceTrigger.encode(...actual)).to.eql(expected);
1035
- });
1036
- });
1037
- });
1038
- describe('decode()', () => {
1039
- const examples = [
1040
- [
1041
- {
1042
- market: web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
1043
- collToken: web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
1044
- price: '2000',
1045
- priceState: RatioState.UNDER,
1046
- },
1047
- ['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000002e90edd0000000000000000000000000000000000000000000000000000000000000000001'],
1048
- ],
1049
- [
1050
- {
1051
- market: web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
1052
- collToken: web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
1053
- price: '3000',
1054
- priceState: RatioState.OVER,
1055
- },
1056
- ['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000045d964b8000000000000000000000000000000000000000000000000000000000000000000'],
1057
- ],
1058
- ];
1059
- examples.forEach(([expected, actual]) => {
1060
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1061
- expect(compoundV3PriceTrigger.decode(actual)).to.eql(expected);
1062
- });
1063
- });
1064
- });
1065
- });
1066
- describe('When testing triggerService.compoundV3PriceRangeTrigger', () => {
1067
- describe('encode()', () => {
1068
- const examples = [
1069
- [
1070
- ['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
1071
- [web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'), web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'), 1500, 4000]
1072
- ],
1073
- [
1074
- ['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000746a528800'],
1075
- [web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'), web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'), 0, 5000]
1076
- ],
1077
- ];
1078
- examples.forEach(([expected, actual]) => {
1079
- it(`Given ${actual} should return expected value: ${expected}`, () => {
1080
- expect(compoundV3PriceRangeTrigger.encode(...actual)).to.eql(expected);
1081
- });
1082
- });
1083
- });
1084
- describe('decode()', () => {
1085
- const examples = [
1086
- [
1087
- {
1088
- market: web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
1089
- collToken: web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
1090
- lowerPrice: '1500',
1091
- upperPrice: '4000',
1092
- },
1093
- ['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
1094
- ],
1095
- [
1096
- {
1097
- market: web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
1098
- collToken: web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
1099
- lowerPrice: '0',
1100
- upperPrice: '5000',
1101
- },
1102
- ['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000746a528800'],
1103
- ],
1104
- ];
1105
- examples.forEach(([expected, actual]) => {
1106
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1107
- expect(compoundV3PriceRangeTrigger.decode(actual)).to.eql(expected);
1108
- });
1109
- });
1110
- });
1111
- });
1112
1020
  });
@@ -114,7 +114,6 @@ export declare namespace Strategies {
114
114
  CloseOnPriceToDebt = "close-on-price-to-debt",
115
115
  CloseOnPriceToColl = "close-on-price-to-collateral",
116
116
  CloseOnPrice = "close-on-price",
117
- EoaCloseOnPrice = "eoa-close-on-price",
118
117
  TrailingStopToColl = "trailing-stop-to-collateral",
119
118
  TrailingStopToDebt = "trailing-stop-to-debt",
120
119
  Rebond = "rebond",
@@ -126,9 +125,7 @@ export declare namespace Strategies {
126
125
  OpenOrderFromCollateral = "open-order-from-collateral",
127
126
  OpenOrderFromDebt = "open-order-from-debt",
128
127
  BoostOnPrice = "boost-on-price",
129
- RepayOnPrice = "repay-on-price",
130
- EoaBoostOnPrice = "eoa-boost-on-price",
131
- EoaRepayOnPrice = "eoa-repay-on-price"
128
+ RepayOnPrice = "repay-on-price"
132
129
  }
133
130
  enum IdOverrides {
134
131
  TakeProfit = "take-profit",
@@ -137,9 +134,7 @@ export declare namespace Strategies {
137
134
  StopLossWithGasPrice = "stop-loss-with-gas-price",
138
135
  TrailingStop = "trailing-stop",
139
136
  LeverageManagement = "leverage-management",
140
- EoaLeverageManagement = "leverage-management-eoa",
141
- LeverageManagementOnPrice = "leverage-management-on-price",
142
- EoaLeverageManagementOnPrice = "leverage-management-on-price-eoa"
137
+ EoaLeverageManagement = "leverage-management-eoa"
143
138
  }
144
139
  }
145
140
  export declare namespace Bundles {
@@ -191,13 +186,7 @@ export declare namespace Bundles {
191
186
  LIQUITY_V2_REPAY_ON_PRICE = 42,
192
187
  LIQUITY_V2_BOOST_ON_PRICE = 43,
193
188
  FLUID_T1_REPAY = 44,
194
- FLUID_T1_BOOST = 45,
195
- COMP_V3_SW_REPAY_ON_PRICE = 46,
196
- COMP_V3_SW_BOOST_ON_PRICE = 47,
197
- COMP_V3_SW_CLOSE = 48,
198
- COMP_V3_EOA_REPAY_ON_PRICE = 49,
199
- COMP_V3_EOA_BOOST_ON_PRICE = 50,
200
- COMP_V3_EOA_CLOSE = 51
189
+ FLUID_T1_BOOST = 45
201
190
  }
202
191
  enum OptimismIds {
203
192
  AAVE_V3_REPAY = 0,
@@ -220,13 +209,7 @@ export declare namespace Bundles {
220
209
  AAVE_V3_REPAY_ON_PRICE = 11,
221
210
  MORPHO_BLUE_BOOST_ON_PRICE = 12,
222
211
  FLUID_T1_REPAY = 13,
223
- FLUID_T1_BOOST = 14,
224
- COMP_V3_SW_REPAY_ON_PRICE = 15,
225
- COMP_V3_SW_BOOST_ON_PRICE = 16,
226
- COMP_V3_SW_CLOSE = 17,
227
- COMP_V3_EOA_REPAY_ON_PRICE = 18,
228
- COMP_V3_EOA_BOOST_ON_PRICE = 19,
229
- COMP_V3_EOA_CLOSE = 20
212
+ FLUID_T1_BOOST = 14
230
213
  }
231
214
  enum ArbitrumIds {
232
215
  AAVE_V3_REPAY = 0,
@@ -238,12 +221,6 @@ export declare namespace Bundles {
238
221
  AAVE_V3_OPEN_ORDER_FROM_COLLATERAL = 6,
239
222
  AAVE_V3_REPAY_ON_PRICE = 7,
240
223
  FLUID_T1_REPAY = 8,
241
- FLUID_T1_BOOST = 9,
242
- COMP_V3_SW_REPAY_ON_PRICE = 10,
243
- COMP_V3_SW_BOOST_ON_PRICE = 11,
244
- COMP_V3_SW_CLOSE = 12,
245
- COMP_V3_EOA_REPAY_ON_PRICE = 13,
246
- COMP_V3_EOA_BOOST_ON_PRICE = 14,
247
- COMP_V3_EOA_CLOSE = 15
224
+ FLUID_T1_BOOST = 9
248
225
  }
249
226
  }
@@ -131,7 +131,6 @@ export var Strategies;
131
131
  Identifiers["CloseOnPriceToDebt"] = "close-on-price-to-debt";
132
132
  Identifiers["CloseOnPriceToColl"] = "close-on-price-to-collateral";
133
133
  Identifiers["CloseOnPrice"] = "close-on-price";
134
- Identifiers["EoaCloseOnPrice"] = "eoa-close-on-price";
135
134
  Identifiers["TrailingStopToColl"] = "trailing-stop-to-collateral";
136
135
  Identifiers["TrailingStopToDebt"] = "trailing-stop-to-debt";
137
136
  Identifiers["Rebond"] = "rebond";
@@ -144,8 +143,6 @@ export var Strategies;
144
143
  Identifiers["OpenOrderFromDebt"] = "open-order-from-debt";
145
144
  Identifiers["BoostOnPrice"] = "boost-on-price";
146
145
  Identifiers["RepayOnPrice"] = "repay-on-price";
147
- Identifiers["EoaBoostOnPrice"] = "eoa-boost-on-price";
148
- Identifiers["EoaRepayOnPrice"] = "eoa-repay-on-price";
149
146
  })(Identifiers = Strategies.Identifiers || (Strategies.Identifiers = {}));
150
147
  let IdOverrides;
151
148
  (function (IdOverrides) {
@@ -156,8 +153,6 @@ export var Strategies;
156
153
  IdOverrides["TrailingStop"] = "trailing-stop";
157
154
  IdOverrides["LeverageManagement"] = "leverage-management";
158
155
  IdOverrides["EoaLeverageManagement"] = "leverage-management-eoa";
159
- IdOverrides["LeverageManagementOnPrice"] = "leverage-management-on-price";
160
- IdOverrides["EoaLeverageManagementOnPrice"] = "leverage-management-on-price-eoa";
161
156
  })(IdOverrides = Strategies.IdOverrides || (Strategies.IdOverrides = {}));
162
157
  })(Strategies || (Strategies = {}));
163
158
  export var Bundles;
@@ -212,12 +207,6 @@ export var Bundles;
212
207
  MainnetIds[MainnetIds["LIQUITY_V2_BOOST_ON_PRICE"] = 43] = "LIQUITY_V2_BOOST_ON_PRICE";
213
208
  MainnetIds[MainnetIds["FLUID_T1_REPAY"] = 44] = "FLUID_T1_REPAY";
214
209
  MainnetIds[MainnetIds["FLUID_T1_BOOST"] = 45] = "FLUID_T1_BOOST";
215
- MainnetIds[MainnetIds["COMP_V3_SW_REPAY_ON_PRICE"] = 46] = "COMP_V3_SW_REPAY_ON_PRICE";
216
- MainnetIds[MainnetIds["COMP_V3_SW_BOOST_ON_PRICE"] = 47] = "COMP_V3_SW_BOOST_ON_PRICE";
217
- MainnetIds[MainnetIds["COMP_V3_SW_CLOSE"] = 48] = "COMP_V3_SW_CLOSE";
218
- MainnetIds[MainnetIds["COMP_V3_EOA_REPAY_ON_PRICE"] = 49] = "COMP_V3_EOA_REPAY_ON_PRICE";
219
- MainnetIds[MainnetIds["COMP_V3_EOA_BOOST_ON_PRICE"] = 50] = "COMP_V3_EOA_BOOST_ON_PRICE";
220
- MainnetIds[MainnetIds["COMP_V3_EOA_CLOSE"] = 51] = "COMP_V3_EOA_CLOSE";
221
210
  })(MainnetIds = Bundles.MainnetIds || (Bundles.MainnetIds = {}));
222
211
  let OptimismIds;
223
212
  (function (OptimismIds) {
@@ -243,12 +232,6 @@ export var Bundles;
243
232
  BaseIds[BaseIds["MORPHO_BLUE_BOOST_ON_PRICE"] = 12] = "MORPHO_BLUE_BOOST_ON_PRICE";
244
233
  BaseIds[BaseIds["FLUID_T1_REPAY"] = 13] = "FLUID_T1_REPAY";
245
234
  BaseIds[BaseIds["FLUID_T1_BOOST"] = 14] = "FLUID_T1_BOOST";
246
- BaseIds[BaseIds["COMP_V3_SW_REPAY_ON_PRICE"] = 15] = "COMP_V3_SW_REPAY_ON_PRICE";
247
- BaseIds[BaseIds["COMP_V3_SW_BOOST_ON_PRICE"] = 16] = "COMP_V3_SW_BOOST_ON_PRICE";
248
- BaseIds[BaseIds["COMP_V3_SW_CLOSE"] = 17] = "COMP_V3_SW_CLOSE";
249
- BaseIds[BaseIds["COMP_V3_EOA_REPAY_ON_PRICE"] = 18] = "COMP_V3_EOA_REPAY_ON_PRICE";
250
- BaseIds[BaseIds["COMP_V3_EOA_BOOST_ON_PRICE"] = 19] = "COMP_V3_EOA_BOOST_ON_PRICE";
251
- BaseIds[BaseIds["COMP_V3_EOA_CLOSE"] = 20] = "COMP_V3_EOA_CLOSE";
252
235
  })(BaseIds = Bundles.BaseIds || (Bundles.BaseIds = {}));
253
236
  let ArbitrumIds;
254
237
  (function (ArbitrumIds) {
@@ -262,11 +245,5 @@ export var Bundles;
262
245
  ArbitrumIds[ArbitrumIds["AAVE_V3_REPAY_ON_PRICE"] = 7] = "AAVE_V3_REPAY_ON_PRICE";
263
246
  ArbitrumIds[ArbitrumIds["FLUID_T1_REPAY"] = 8] = "FLUID_T1_REPAY";
264
247
  ArbitrumIds[ArbitrumIds["FLUID_T1_BOOST"] = 9] = "FLUID_T1_BOOST";
265
- ArbitrumIds[ArbitrumIds["COMP_V3_SW_REPAY_ON_PRICE"] = 10] = "COMP_V3_SW_REPAY_ON_PRICE";
266
- ArbitrumIds[ArbitrumIds["COMP_V3_SW_BOOST_ON_PRICE"] = 11] = "COMP_V3_SW_BOOST_ON_PRICE";
267
- ArbitrumIds[ArbitrumIds["COMP_V3_SW_CLOSE"] = 12] = "COMP_V3_SW_CLOSE";
268
- ArbitrumIds[ArbitrumIds["COMP_V3_EOA_REPAY_ON_PRICE"] = 13] = "COMP_V3_EOA_REPAY_ON_PRICE";
269
- ArbitrumIds[ArbitrumIds["COMP_V3_EOA_BOOST_ON_PRICE"] = 14] = "COMP_V3_EOA_BOOST_ON_PRICE";
270
- ArbitrumIds[ArbitrumIds["COMP_V3_EOA_CLOSE"] = 15] = "COMP_V3_EOA_CLOSE";
271
248
  })(ArbitrumIds = Bundles.ArbitrumIds || (Bundles.ArbitrumIds = {}));
272
249
  })(Bundles || (Bundles = {}));
@@ -171,24 +171,8 @@ export declare namespace Position {
171
171
  subHashBoost?: string;
172
172
  subHashRepay?: string;
173
173
  }
174
- interface CompoundV3Base extends Base {
175
- market: EthereumAddress;
176
- collToken: EthereumAddress;
177
- baseToken: EthereumAddress;
178
- }
179
- interface CompoundV3LeverageManagementOnPrice extends CompoundV3Base {
180
- ratio: number;
181
- price: string;
182
- priceState: RatioState;
183
- }
184
- interface CompoundV3CloseOnPrice extends CompoundV3Base {
185
- stopLossPrice: string;
186
- takeProfitPrice: string;
187
- stopLossType: CloseToAssetType | undefined;
188
- takeProfitType: CloseToAssetType | undefined;
189
- }
190
174
  }
191
- 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;
175
+ 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;
192
176
  interface Automated {
193
177
  chainId: ChainId;
194
178
  positionId: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defisaver/automation-sdk",
3
- "version": "3.2.4-dev-1",
3
+ "version": "3.2.5",
4
4
  "description": "",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./esm/index.js",
@@ -24,7 +24,7 @@
24
24
  "license": "ISC",
25
25
  "dependencies": {
26
26
  "@defisaver/sdk": "^1.2.20",
27
- "@defisaver/tokens": "^1.6.19",
27
+ "@defisaver/tokens": "^1.6.7",
28
28
  "@ethersproject/address": "^5.0.10",
29
29
  "@ethersproject/solidity": "^5.0.9",
30
30
  "decimal.js": "^10.4.3",
@@ -421,36 +421,6 @@ export const MAINNET_BUNDLES_INFO: MainnetBundleInfo = {
421
421
  strategyId: Strategies.Identifiers.Boost,
422
422
  protocol: PROTOCOLS.FluidT1,
423
423
  },
424
- [Bundles.MainnetIds.COMP_V3_SW_REPAY_ON_PRICE]: {
425
- strategyOrBundleId: Bundles.MainnetIds.COMP_V3_SW_REPAY_ON_PRICE,
426
- strategyId: Strategies.Identifiers.RepayOnPrice,
427
- protocol: PROTOCOLS.CompoundV3,
428
- },
429
- [Bundles.MainnetIds.COMP_V3_SW_BOOST_ON_PRICE]: {
430
- strategyOrBundleId: Bundles.MainnetIds.COMP_V3_SW_BOOST_ON_PRICE,
431
- strategyId: Strategies.Identifiers.BoostOnPrice,
432
- protocol: PROTOCOLS.CompoundV3,
433
- },
434
- [Bundles.MainnetIds.COMP_V3_SW_CLOSE]: {
435
- strategyOrBundleId: Bundles.MainnetIds.COMP_V3_SW_CLOSE,
436
- strategyId: Strategies.Identifiers.CloseOnPrice,
437
- protocol: PROTOCOLS.CompoundV3,
438
- },
439
- [Bundles.MainnetIds.COMP_V3_EOA_REPAY_ON_PRICE]: {
440
- strategyOrBundleId: Bundles.MainnetIds.COMP_V3_EOA_REPAY_ON_PRICE,
441
- strategyId: Strategies.Identifiers.EoaRepayOnPrice,
442
- protocol: PROTOCOLS.CompoundV3,
443
- },
444
- [Bundles.MainnetIds.COMP_V3_EOA_BOOST_ON_PRICE]: {
445
- strategyOrBundleId: Bundles.MainnetIds.COMP_V3_EOA_BOOST_ON_PRICE,
446
- strategyId: Strategies.Identifiers.EoaBoostOnPrice,
447
- protocol: PROTOCOLS.CompoundV3,
448
- },
449
- [Bundles.MainnetIds.COMP_V3_EOA_CLOSE]: {
450
- strategyOrBundleId: Bundles.MainnetIds.COMP_V3_EOA_CLOSE,
451
- strategyId: Strategies.Identifiers.EoaCloseOnPrice,
452
- protocol: PROTOCOLS.CompoundV3,
453
- },
454
424
  };
455
425
 
456
426
  export const OPTIMISM_BUNDLES_INFO: OptimismBundleInfo = {
@@ -552,36 +522,6 @@ export const BASE_BUNDLES_INFO: BaseBundleInfo = {
552
522
  strategyId: Strategies.Identifiers.Boost,
553
523
  protocol: PROTOCOLS.FluidT1,
554
524
  },
555
- [Bundles.BaseIds.COMP_V3_SW_REPAY_ON_PRICE]: {
556
- strategyOrBundleId: Bundles.BaseIds.COMP_V3_SW_REPAY_ON_PRICE,
557
- strategyId: Strategies.Identifiers.RepayOnPrice,
558
- protocol: PROTOCOLS.CompoundV3,
559
- },
560
- [Bundles.BaseIds.COMP_V3_SW_BOOST_ON_PRICE]: {
561
- strategyOrBundleId: Bundles.BaseIds.COMP_V3_SW_BOOST_ON_PRICE,
562
- strategyId: Strategies.Identifiers.BoostOnPrice,
563
- protocol: PROTOCOLS.CompoundV3,
564
- },
565
- [Bundles.BaseIds.COMP_V3_SW_CLOSE]: {
566
- strategyOrBundleId: Bundles.BaseIds.COMP_V3_SW_CLOSE,
567
- strategyId: Strategies.Identifiers.CloseOnPrice,
568
- protocol: PROTOCOLS.CompoundV3,
569
- },
570
- [Bundles.BaseIds.COMP_V3_EOA_REPAY_ON_PRICE]: {
571
- strategyOrBundleId: Bundles.BaseIds.COMP_V3_EOA_REPAY_ON_PRICE,
572
- strategyId: Strategies.Identifiers.EoaRepayOnPrice,
573
- protocol: PROTOCOLS.CompoundV3,
574
- },
575
- [Bundles.BaseIds.COMP_V3_EOA_BOOST_ON_PRICE]: {
576
- strategyOrBundleId: Bundles.BaseIds.COMP_V3_EOA_BOOST_ON_PRICE,
577
- strategyId: Strategies.Identifiers.EoaBoostOnPrice,
578
- protocol: PROTOCOLS.CompoundV3,
579
- },
580
- [Bundles.BaseIds.COMP_V3_EOA_CLOSE]: {
581
- strategyOrBundleId: Bundles.BaseIds.COMP_V3_EOA_CLOSE,
582
- strategyId: Strategies.Identifiers.EoaCloseOnPrice,
583
- protocol: PROTOCOLS.CompoundV3,
584
- },
585
525
  };
586
526
 
587
527
  export const ARBITRUM_BUNDLES_INFO: ArbitrumBundleInfo = {
@@ -635,36 +575,6 @@ export const ARBITRUM_BUNDLES_INFO: ArbitrumBundleInfo = {
635
575
  strategyId: Strategies.Identifiers.Boost,
636
576
  protocol: PROTOCOLS.FluidT1,
637
577
  },
638
- [Bundles.ArbitrumIds.COMP_V3_SW_REPAY_ON_PRICE]: {
639
- strategyOrBundleId: Bundles.ArbitrumIds.COMP_V3_SW_REPAY_ON_PRICE,
640
- strategyId: Strategies.Identifiers.RepayOnPrice,
641
- protocol: PROTOCOLS.CompoundV3,
642
- },
643
- [Bundles.ArbitrumIds.COMP_V3_SW_BOOST_ON_PRICE]: {
644
- strategyOrBundleId: Bundles.ArbitrumIds.COMP_V3_SW_BOOST_ON_PRICE,
645
- strategyId: Strategies.Identifiers.BoostOnPrice,
646
- protocol: PROTOCOLS.CompoundV3,
647
- },
648
- [Bundles.ArbitrumIds.COMP_V3_SW_CLOSE]: {
649
- strategyOrBundleId: Bundles.ArbitrumIds.COMP_V3_SW_CLOSE,
650
- strategyId: Strategies.Identifiers.CloseOnPrice,
651
- protocol: PROTOCOLS.CompoundV3,
652
- },
653
- [Bundles.ArbitrumIds.COMP_V3_EOA_REPAY_ON_PRICE]: {
654
- strategyOrBundleId: Bundles.ArbitrumIds.COMP_V3_EOA_REPAY_ON_PRICE,
655
- strategyId: Strategies.Identifiers.EoaRepayOnPrice,
656
- protocol: PROTOCOLS.CompoundV3,
657
- },
658
- [Bundles.ArbitrumIds.COMP_V3_EOA_BOOST_ON_PRICE]: {
659
- strategyOrBundleId: Bundles.ArbitrumIds.COMP_V3_EOA_BOOST_ON_PRICE,
660
- strategyId: Strategies.Identifiers.EoaBoostOnPrice,
661
- protocol: PROTOCOLS.CompoundV3,
662
- },
663
- [Bundles.ArbitrumIds.COMP_V3_EOA_CLOSE]: {
664
- strategyOrBundleId: Bundles.ArbitrumIds.COMP_V3_EOA_CLOSE,
665
- strategyId: Strategies.Identifiers.EoaCloseOnPrice,
666
- protocol: PROTOCOLS.CompoundV3,
667
- },
668
578
  };
669
579
 
670
580
  export const BUNDLES_INFO: BundlesInfo = {
@@ -679,4 +589,5 @@ export const BUNDLE_IDS = {
679
589
  [ChainId.Optimism]: Bundles.OptimismIds,
680
590
  [ChainId.Arbitrum]: Bundles.ArbitrumIds,
681
591
  [ChainId.Base]: Bundles.BaseIds,
592
+
682
593
  };
@@ -466,62 +466,6 @@ function parseCompoundV3LeverageManagement(position: Position.Automated, parseDa
466
466
  return _position;
467
467
  }
468
468
 
469
- function parseCompoundV3LeverageManagementOnPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
470
- const _position = cloneDeep(position);
471
-
472
- const { subStruct } = parseData.subscriptionEventData;
473
-
474
- const triggerData = triggerService.compoundV3PriceTrigger.decode(subStruct.triggerData);
475
- const subData = subDataService.compoundV3LeverageManagementOnPriceSubData.decode(subStruct.subData);
476
-
477
- _position.strategyData.decoded.triggerData = triggerData;
478
- _position.strategyData.decoded.subData = subData;
479
- _position.positionId = getPositionId(_position.chainId, _position.protocol.id, triggerData.market, Math.random());
480
-
481
- _position.specific = {
482
- market: subData.market,
483
- collToken: subData.collToken,
484
- baseToken: subData.baseToken,
485
- ratio: subData.targetRatio,
486
- price: triggerData.price,
487
- priceState: triggerData.priceState,
488
- };
489
-
490
- const isEOA = _position.strategy.strategyId.includes('eoa');
491
- _position.strategy.strategyId = isEOA ? Strategies.IdOverrides.EoaLeverageManagementOnPrice : Strategies.IdOverrides.LeverageManagementOnPrice;
492
-
493
- return _position;
494
- }
495
-
496
- function parseCompoundV3CloseOnPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
497
- const _position = cloneDeep(position);
498
-
499
- const { subStruct } = parseData.subscriptionEventData;
500
-
501
- const triggerData = triggerService.compoundV3PriceRangeTrigger.decode(subStruct.triggerData);
502
- const subData = subDataService.compoundV3CloseSubData.decode(subStruct.subData);
503
-
504
- _position.strategyData.decoded.triggerData = triggerData;
505
- _position.strategyData.decoded.subData = subData;
506
- _position.positionId = getPositionId(_position.chainId, _position.protocol.id, triggerData.market, Math.random());
507
-
508
- const { takeProfitType, stopLossType } = getStopLossAndTakeProfitTypeByCloseStrategyType(+subData.closeType);
509
- const isEOA = _position.strategy.strategyId.includes('eoa');
510
- _position.strategy.strategyId = isEOA ? Strategies.Identifiers.EoaCloseOnPrice : Strategies.Identifiers.CloseOnPrice;
511
-
512
- _position.specific = {
513
- market: subData.market,
514
- collToken: subData.collToken,
515
- baseToken: subData.baseToken,
516
- stopLossPrice: triggerData.lowerPrice,
517
- takeProfitPrice: triggerData.upperPrice,
518
- takeProfitType,
519
- stopLossType,
520
- };
521
-
522
- return _position;
523
- }
524
-
525
469
  function parseChickenBondsRebond(position: Position.Automated, parseData: ParseData): Position.Automated {
526
470
  const _position = cloneDeep(position);
527
471
 
@@ -965,6 +909,7 @@ function parseLiquityV2CloseOnPrice(position: Position.Automated, parseData: Par
965
909
  // - Only TakeProfit
966
910
  // - Only StopLoss
967
911
  // - Both
912
+ // TODO: see on frontend what specific data we need here because stop-loss and take-profit is one bundle now
968
913
  _position.strategy.strategyId = Strategies.Identifiers.CloseOnPrice;
969
914
  _position.specific = {
970
915
  market: subData.market,
@@ -1122,12 +1067,6 @@ const parsingMethodsMapping: StrategiesToProtocolVersionMapping = {
1122
1067
  [Strategies.Identifiers.Boost]: parseCompoundV3LeverageManagement,
1123
1068
  [Strategies.Identifiers.EoaRepay]: parseCompoundV3LeverageManagement,
1124
1069
  [Strategies.Identifiers.EoaBoost]: parseCompoundV3LeverageManagement,
1125
- [Strategies.Identifiers.RepayOnPrice]: parseCompoundV3LeverageManagementOnPrice,
1126
- [Strategies.Identifiers.BoostOnPrice]: parseCompoundV3LeverageManagementOnPrice,
1127
- [Strategies.Identifiers.EoaRepayOnPrice]: parseCompoundV3LeverageManagementOnPrice,
1128
- [Strategies.Identifiers.EoaBoostOnPrice]: parseCompoundV3LeverageManagementOnPrice,
1129
- [Strategies.Identifiers.CloseOnPrice]: parseCompoundV3CloseOnPrice,
1130
- [Strategies.Identifiers.EoaCloseOnPrice]: parseCompoundV3CloseOnPrice,
1131
1070
  },
1132
1071
  [ProtocolIdentifiers.StrategiesAutomation.ChickenBonds]: {
1133
1072
  [Strategies.Identifiers.Rebond]: parseChickenBondsRebond,
@@ -4,7 +4,7 @@ import { otherAddresses } from '@defisaver/sdk';
4
4
  import { getAssetInfo } from '@defisaver/tokens';
5
5
  import * as web3Utils from 'web3-utils';
6
6
 
7
- import { Bundles, ChainId, CloseToAssetType, OrderType, RatioState, Strategies } from '../types/enums';
7
+ import { Bundles, ChainId, OrderType, RatioState, Strategies } from '../types/enums';
8
8
  import type { EthereumAddress, StrategyOrBundleIds, SubData, TriggerData } from '../types';
9
9
 
10
10
  import '../configuration';
@@ -688,120 +688,6 @@ describe('Feature: strategySubService.ts', () => {
688
688
  });
689
689
  });
690
690
  });
691
- describe('leverageManagementOnPrice()', () => {
692
- const examples: Array<[
693
- [StrategyOrBundleIds, boolean, TriggerData, SubData],
694
- [strategyOrBundleId: number, market: EthereumAddress, collToken: EthereumAddress, baseToken: EthereumAddress, targetRatio: number, price: number, priceState: RatioState]
695
- ]> = [
696
- [
697
- [
698
- Bundles.MainnetIds.COMP_V3_SW_REPAY_ON_PRICE,
699
- true,
700
- ['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000002e90edd0000000000000000000000000000000000000000000000000000000000000000001'],
701
- [
702
- '0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3',
703
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
704
- '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
705
- '0x0000000000000000000000000000000000000000000000001bc16d674ec80000'
706
- ],
707
- ],
708
- [
709
- Bundles.MainnetIds.COMP_V3_SW_REPAY_ON_PRICE,
710
- web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
711
- web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
712
- web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
713
- 200,
714
- 2000,
715
- RatioState.UNDER,
716
- ],
717
- ],
718
- [
719
- [
720
- Bundles.MainnetIds.COMP_V3_SW_BOOST_ON_PRICE,
721
- true,
722
- ['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000045d964b8000000000000000000000000000000000000000000000000000000000000000000'],
723
- [
724
- '0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3',
725
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
726
- '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
727
- '0x0000000000000000000000000000000000000000000000001a5e27eef13e0000'
728
- ],
729
- ],
730
- [
731
- Bundles.MainnetIds.COMP_V3_SW_BOOST_ON_PRICE,
732
- web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
733
- web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
734
- web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
735
- 190,
736
- 3000,
737
- RatioState.OVER,
738
- ],
739
- ]
740
- ];
741
- examples.forEach(([expected, actual]) => {
742
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
743
- expect(compoundV3Encode.leverageManagementOnPrice(...actual)).to.eql(expected);
744
- });
745
- });
746
- });
747
- describe('closeOnPrice()', () => {
748
- const examples: Array<[
749
- [StrategyOrBundleIds, boolean, TriggerData, SubData],
750
- [strategyOrBundleId: number, market: EthereumAddress, collToken: EthereumAddress, baseToken: EthereumAddress, stopLossPrice: number, stopLossType: CloseToAssetType, takeProfitPrice: number, takeProfitType: CloseToAssetType]
751
- ]> = [
752
- [
753
- [
754
- Bundles.MainnetIds.COMP_V3_SW_CLOSE,
755
- true,
756
- ['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
757
- [
758
- '0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3',
759
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
760
- '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
761
- '0x0000000000000000000000000000000000000000000000000000000000000006'
762
- ],
763
- ],
764
- [
765
- Bundles.MainnetIds.COMP_V3_SW_CLOSE,
766
- web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
767
- web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
768
- web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
769
- 1500,
770
- CloseToAssetType.DEBT,
771
- 4000,
772
- CloseToAssetType.DEBT,
773
- ],
774
- ],
775
- [
776
- [
777
- Bundles.MainnetIds.COMP_V3_EOA_CLOSE,
778
- true,
779
- ['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000746a528800'],
780
- [
781
- '0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3',
782
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
783
- '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
784
- '0x0000000000000000000000000000000000000000000000000000000000000000'
785
- ],
786
- ],
787
- [
788
- Bundles.MainnetIds.COMP_V3_EOA_CLOSE,
789
- web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
790
- web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
791
- web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
792
- 0,
793
- CloseToAssetType.DEBT,
794
- 5000,
795
- CloseToAssetType.COLLATERAL,
796
- ],
797
- ]
798
- ];
799
- examples.forEach(([expected, actual]) => {
800
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
801
- expect(compoundV3Encode.closeOnPrice(...actual)).to.eql(expected);
802
- });
803
- });
804
- });
805
691
  });
806
692
 
807
693
  describe('When testing strategySubService.morphoAaveV2Encode', () => {