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

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 +90 -0
  2. package/cjs/services/strategiesService.js +48 -1
  3. package/cjs/services/strategySubService.d.ts +2 -0
  4. package/cjs/services/strategySubService.js +13 -0
  5. package/cjs/services/strategySubService.test.js +108 -0
  6. package/cjs/services/subDataService.d.ts +18 -0
  7. package/cjs/services/subDataService.js +48 -1
  8. package/cjs/services/subDataService.test.js +124 -48
  9. package/cjs/services/triggerService.d.ts +33 -0
  10. package/cjs/services/triggerService.js +62 -1
  11. package/cjs/services/triggerService.test.js +211 -0
  12. package/cjs/types/enums.d.ts +28 -5
  13. package/cjs/types/enums.js +23 -0
  14. package/cjs/types/index.d.ts +17 -1
  15. package/esm/constants/index.js +90 -0
  16. package/esm/services/strategiesService.js +48 -1
  17. package/esm/services/strategySubService.d.ts +2 -0
  18. package/esm/services/strategySubService.js +13 -0
  19. package/esm/services/strategySubService.test.js +109 -1
  20. package/esm/services/subDataService.d.ts +18 -0
  21. package/esm/services/subDataService.js +47 -0
  22. package/esm/services/subDataService.test.js +124 -48
  23. package/esm/services/triggerService.d.ts +33 -0
  24. package/esm/services/triggerService.js +61 -0
  25. package/esm/services/triggerService.test.js +212 -1
  26. package/esm/types/enums.d.ts +28 -5
  27. package/esm/types/enums.js +23 -0
  28. package/esm/types/index.d.ts +17 -1
  29. package/package.json +2 -2
  30. package/src/constants/index.ts +90 -1
  31. package/src/services/strategiesService.ts +62 -1
  32. package/src/services/strategySubService.test.ts +115 -1
  33. package/src/services/strategySubService.ts +33 -0
  34. package/src/services/subDataService.test.ts +128 -73
  35. package/src/services/subDataService.ts +73 -0
  36. package/src/services/triggerService.test.ts +229 -1
  37. package/src/services/triggerService.ts +83 -0
  38. package/src/types/enums.ts +23 -0
  39. package/src/types/index.ts +22 -1
@@ -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, curveUsdBorrowRateTrigger, curveUsdSoftLiquidationTrigger, exchangeOffchainPriceTrigger, exchangeTimestampTrigger, liquityDebtInFrontTrigger, makerRatioTrigger, morphoAaveV2RatioTrigger, sparkQuotePriceTrigger, sparkRatioTrigger, trailingStopTrigger, liquityDebtInFrontWithLimitTrigger, crvUSDRatioTrigger, morphoBlueRatioTrigger, crvUsdHealthRatioTrigger, } from './triggerService';
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';
7
7
  describe('Feature: triggerService.ts', () => {
8
8
  describe('When testing triggerService.chainlinkPriceTrigger', () => {
9
9
  describe('encode()', () => {
@@ -423,6 +423,125 @@ describe('Feature: triggerService.ts', () => {
423
423
  });
424
424
  });
425
425
  });
426
+ describe('When testing triggerService.liquityV2DebtInFrontTrigger', () => {
427
+ describe('encode()', () => {
428
+ const examples = [
429
+ [
430
+ ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434ad94e2c00000000000000000000000000000000000000000000000000000000075bcd1500000000000000000000000000000000000000000000006e0be8c4995af80000'],
431
+ [web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434Ad94E2c'), '123456789', '2030']
432
+ ],
433
+ [
434
+ ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434a192e2c000000000000000000000000000000000000000000000000000000003ade68b1000000000000000000000000000000000000000000004697f83e6356dd440000'],
435
+ [web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434A192E2c'), '987654321', '333369']
436
+ ],
437
+ [
438
+ ['0x00000000000000000000000030462ad9d8f01a20a2ec7e7f1a8f1b303662aebf00000000000000000000000000000000000000000000000000000000075bd924000000000000000000000000000000000000000000084595161401484a000000'],
439
+ [web3Utils.toChecksumAddress('0x30462AD9D8F01A20A2EC7E7F1A8F1B303662AEBF'), '123459876', '10000000']
440
+ ],
441
+ [
442
+ ['0x00000000000000000000000030462ad9d8f01a20a2ec7e7f1a8f1b303662aebf000000000000000000000000000000000000000000000000000000002060d4950000000000000000000000000000000000000000000000000000000000989680'],
443
+ [web3Utils.toChecksumAddress('0x30462AD9D8F01A20A2EC7E7F1A8F1B303662AEBF'), '543216789', '0.00000000001']
444
+ ],
445
+ [
446
+ ['0x000000000000000000000000235d6a8db3c57c3f7b4eba749e1738db6093732a000000000000000000000000000000000000000000000000000000003ade5ca20000000000000000000000000000000000000000019d971e4fe8401e74000000'],
447
+ [web3Utils.toChecksumAddress('0x235d6A8DB3C57c3f7b4ebA749E1738Db6093732a'), '987651234', '500000000']
448
+ ],
449
+ ];
450
+ examples.forEach(([expected, actual]) => {
451
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
452
+ expect(liquityV2DebtInFrontTrigger.encode(...actual)).to.eql(expected);
453
+ });
454
+ });
455
+ });
456
+ describe('decode()', () => {
457
+ const examples = [
458
+ [
459
+ {
460
+ market: web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434Ad94E2c'),
461
+ troveId: '123456789',
462
+ debtInFrontMin: '2030',
463
+ },
464
+ ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434ad94e2c00000000000000000000000000000000000000000000000000000000075bcd1500000000000000000000000000000000000000000000006e0be8c4995af80000'],
465
+ ],
466
+ [
467
+ {
468
+ market: web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434A192E2c'),
469
+ troveId: '987654321',
470
+ debtInFrontMin: '333369',
471
+ },
472
+ ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434a192e2c000000000000000000000000000000000000000000000000000000003ade68b1000000000000000000000000000000000000000000004697f83e6356dd440000'],
473
+ ], [
474
+ {
475
+ market: web3Utils.toChecksumAddress('0x30462AD9D8F01A20A2EC7E7F1A8F1B303662AEBF'),
476
+ troveId: '123459876',
477
+ debtInFrontMin: '10000000',
478
+ },
479
+ ['0x00000000000000000000000030462ad9d8f01a20a2ec7e7f1a8f1b303662aebf00000000000000000000000000000000000000000000000000000000075bd924000000000000000000000000000000000000000000084595161401484a000000'],
480
+ ], [
481
+ {
482
+ market: web3Utils.toChecksumAddress('0x30462AD9D8F01A20A2EC7E7F1A8F1B303662AEBF'),
483
+ troveId: '543216789',
484
+ debtInFrontMin: '0.00000000001',
485
+ },
486
+ ['0x00000000000000000000000030462ad9d8f01a20a2ec7e7f1a8f1b303662aebf000000000000000000000000000000000000000000000000000000002060d4950000000000000000000000000000000000000000000000000000000000989680'],
487
+ ], [
488
+ {
489
+ market: web3Utils.toChecksumAddress('0x235d6A8DB3C57c3f7b4ebA749E1738Db6093732a'),
490
+ troveId: '987651234',
491
+ debtInFrontMin: '500000000',
492
+ },
493
+ ['0x000000000000000000000000235d6a8db3c57c3f7b4eba749e1738db6093732a000000000000000000000000000000000000000000000000000000003ade5ca20000000000000000000000000000000000000000019d971e4fe8401e74000000'],
494
+ ]
495
+ ];
496
+ examples.forEach(([expected, actual]) => {
497
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
498
+ expect(liquityV2DebtInFrontTrigger.decode(actual)).to.eql(expected);
499
+ });
500
+ });
501
+ });
502
+ });
503
+ describe('When testing triggerService.liquityV2AdjustTimeTrigger', () => {
504
+ describe('encode()', () => {
505
+ const examples = [
506
+ [
507
+ ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434ad94e2c00000000000000000000000000000000000000000000000000000000075bcd15'],
508
+ [web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434Ad94E2c'), '123456789']
509
+ ],
510
+ [
511
+ ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434a192e2c000000000000000000000000000000000000000000000000000000003ade68b1'],
512
+ [web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434A192E2c'), '987654321']
513
+ ],
514
+ ];
515
+ examples.forEach(([expected, actual]) => {
516
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
517
+ expect(liquityV2AdjustTimeTrigger.encode(...actual)).to.eql(expected);
518
+ });
519
+ });
520
+ });
521
+ describe('decode()', () => {
522
+ const examples = [
523
+ [
524
+ {
525
+ market: web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434Ad94E2c'),
526
+ troveId: '123456789',
527
+ },
528
+ ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434ad94e2c00000000000000000000000000000000000000000000000000000000075bcd15'],
529
+ ],
530
+ [
531
+ {
532
+ market: web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434A192E2c'),
533
+ troveId: '987654321',
534
+ },
535
+ ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434a192e2c000000000000000000000000000000000000000000000000000000003ade68b1'],
536
+ ]
537
+ ];
538
+ examples.forEach(([expected, actual]) => {
539
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
540
+ expect(liquityV2AdjustTimeTrigger.decode(actual)).to.eql(expected);
541
+ });
542
+ });
543
+ });
544
+ });
426
545
  describe('When testing triggerService.aaveV2RatioTrigger', () => {
427
546
  describe('encode()', () => {
428
547
  const examples = [
@@ -898,4 +1017,96 @@ describe('Feature: triggerService.ts', () => {
898
1017
  });
899
1018
  });
900
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
+ });
901
1112
  });
@@ -114,6 +114,7 @@ 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",
117
118
  TrailingStopToColl = "trailing-stop-to-collateral",
118
119
  TrailingStopToDebt = "trailing-stop-to-debt",
119
120
  Rebond = "rebond",
@@ -125,7 +126,9 @@ export declare namespace Strategies {
125
126
  OpenOrderFromCollateral = "open-order-from-collateral",
126
127
  OpenOrderFromDebt = "open-order-from-debt",
127
128
  BoostOnPrice = "boost-on-price",
128
- RepayOnPrice = "repay-on-price"
129
+ RepayOnPrice = "repay-on-price",
130
+ EoaBoostOnPrice = "eoa-boost-on-price",
131
+ EoaRepayOnPrice = "eoa-repay-on-price"
129
132
  }
130
133
  enum IdOverrides {
131
134
  TakeProfit = "take-profit",
@@ -134,7 +137,9 @@ export declare namespace Strategies {
134
137
  StopLossWithGasPrice = "stop-loss-with-gas-price",
135
138
  TrailingStop = "trailing-stop",
136
139
  LeverageManagement = "leverage-management",
137
- EoaLeverageManagement = "leverage-management-eoa"
140
+ EoaLeverageManagement = "leverage-management-eoa",
141
+ LeverageManagementOnPrice = "leverage-management-on-price",
142
+ EoaLeverageManagementOnPrice = "leverage-management-on-price-eoa"
138
143
  }
139
144
  }
140
145
  export declare namespace Bundles {
@@ -186,7 +191,13 @@ export declare namespace Bundles {
186
191
  LIQUITY_V2_REPAY_ON_PRICE = 42,
187
192
  LIQUITY_V2_BOOST_ON_PRICE = 43,
188
193
  FLUID_T1_REPAY = 44,
189
- FLUID_T1_BOOST = 45
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
190
201
  }
191
202
  enum OptimismIds {
192
203
  AAVE_V3_REPAY = 0,
@@ -209,7 +220,13 @@ export declare namespace Bundles {
209
220
  AAVE_V3_REPAY_ON_PRICE = 11,
210
221
  MORPHO_BLUE_BOOST_ON_PRICE = 12,
211
222
  FLUID_T1_REPAY = 13,
212
- FLUID_T1_BOOST = 14
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
213
230
  }
214
231
  enum ArbitrumIds {
215
232
  AAVE_V3_REPAY = 0,
@@ -221,6 +238,12 @@ export declare namespace Bundles {
221
238
  AAVE_V3_OPEN_ORDER_FROM_COLLATERAL = 6,
222
239
  AAVE_V3_REPAY_ON_PRICE = 7,
223
240
  FLUID_T1_REPAY = 8,
224
- FLUID_T1_BOOST = 9
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
225
248
  }
226
249
  }
@@ -131,6 +131,7 @@ 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";
134
135
  Identifiers["TrailingStopToColl"] = "trailing-stop-to-collateral";
135
136
  Identifiers["TrailingStopToDebt"] = "trailing-stop-to-debt";
136
137
  Identifiers["Rebond"] = "rebond";
@@ -143,6 +144,8 @@ export var Strategies;
143
144
  Identifiers["OpenOrderFromDebt"] = "open-order-from-debt";
144
145
  Identifiers["BoostOnPrice"] = "boost-on-price";
145
146
  Identifiers["RepayOnPrice"] = "repay-on-price";
147
+ Identifiers["EoaBoostOnPrice"] = "eoa-boost-on-price";
148
+ Identifiers["EoaRepayOnPrice"] = "eoa-repay-on-price";
146
149
  })(Identifiers = Strategies.Identifiers || (Strategies.Identifiers = {}));
147
150
  let IdOverrides;
148
151
  (function (IdOverrides) {
@@ -153,6 +156,8 @@ export var Strategies;
153
156
  IdOverrides["TrailingStop"] = "trailing-stop";
154
157
  IdOverrides["LeverageManagement"] = "leverage-management";
155
158
  IdOverrides["EoaLeverageManagement"] = "leverage-management-eoa";
159
+ IdOverrides["LeverageManagementOnPrice"] = "leverage-management-on-price";
160
+ IdOverrides["EoaLeverageManagementOnPrice"] = "leverage-management-on-price-eoa";
156
161
  })(IdOverrides = Strategies.IdOverrides || (Strategies.IdOverrides = {}));
157
162
  })(Strategies || (Strategies = {}));
158
163
  export var Bundles;
@@ -207,6 +212,12 @@ export var Bundles;
207
212
  MainnetIds[MainnetIds["LIQUITY_V2_BOOST_ON_PRICE"] = 43] = "LIQUITY_V2_BOOST_ON_PRICE";
208
213
  MainnetIds[MainnetIds["FLUID_T1_REPAY"] = 44] = "FLUID_T1_REPAY";
209
214
  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";
210
221
  })(MainnetIds = Bundles.MainnetIds || (Bundles.MainnetIds = {}));
211
222
  let OptimismIds;
212
223
  (function (OptimismIds) {
@@ -232,6 +243,12 @@ export var Bundles;
232
243
  BaseIds[BaseIds["MORPHO_BLUE_BOOST_ON_PRICE"] = 12] = "MORPHO_BLUE_BOOST_ON_PRICE";
233
244
  BaseIds[BaseIds["FLUID_T1_REPAY"] = 13] = "FLUID_T1_REPAY";
234
245
  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";
235
252
  })(BaseIds = Bundles.BaseIds || (Bundles.BaseIds = {}));
236
253
  let ArbitrumIds;
237
254
  (function (ArbitrumIds) {
@@ -245,5 +262,11 @@ export var Bundles;
245
262
  ArbitrumIds[ArbitrumIds["AAVE_V3_REPAY_ON_PRICE"] = 7] = "AAVE_V3_REPAY_ON_PRICE";
246
263
  ArbitrumIds[ArbitrumIds["FLUID_T1_REPAY"] = 8] = "FLUID_T1_REPAY";
247
264
  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";
248
271
  })(ArbitrumIds = Bundles.ArbitrumIds || (Bundles.ArbitrumIds = {}));
249
272
  })(Bundles || (Bundles = {}));
@@ -171,8 +171,24 @@ 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
+ }
174
190
  }
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;
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;
176
192
  interface Automated {
177
193
  chainId: ChainId;
178
194
  positionId: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defisaver/automation-sdk",
3
- "version": "3.2.3",
3
+ "version": "3.2.4-dev-1",
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.7",
27
+ "@defisaver/tokens": "^1.6.19",
28
28
  "@ethersproject/address": "^5.0.10",
29
29
  "@ethersproject/solidity": "^5.0.9",
30
30
  "decimal.js": "^10.4.3",
@@ -421,6 +421,36 @@ 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
+ },
424
454
  };
425
455
 
426
456
  export const OPTIMISM_BUNDLES_INFO: OptimismBundleInfo = {
@@ -522,6 +552,36 @@ export const BASE_BUNDLES_INFO: BaseBundleInfo = {
522
552
  strategyId: Strategies.Identifiers.Boost,
523
553
  protocol: PROTOCOLS.FluidT1,
524
554
  },
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
+ },
525
585
  };
526
586
 
527
587
  export const ARBITRUM_BUNDLES_INFO: ArbitrumBundleInfo = {
@@ -575,6 +635,36 @@ export const ARBITRUM_BUNDLES_INFO: ArbitrumBundleInfo = {
575
635
  strategyId: Strategies.Identifiers.Boost,
576
636
  protocol: PROTOCOLS.FluidT1,
577
637
  },
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
+ },
578
668
  };
579
669
 
580
670
  export const BUNDLES_INFO: BundlesInfo = {
@@ -589,5 +679,4 @@ export const BUNDLE_IDS = {
589
679
  [ChainId.Optimism]: Bundles.OptimismIds,
590
680
  [ChainId.Arbitrum]: Bundles.ArbitrumIds,
591
681
  [ChainId.Base]: Bundles.BaseIds,
592
-
593
682
  };
@@ -466,6 +466,62 @@ 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
+
469
525
  function parseChickenBondsRebond(position: Position.Automated, parseData: ParseData): Position.Automated {
470
526
  const _position = cloneDeep(position);
471
527
 
@@ -909,7 +965,6 @@ function parseLiquityV2CloseOnPrice(position: Position.Automated, parseData: Par
909
965
  // - Only TakeProfit
910
966
  // - Only StopLoss
911
967
  // - Both
912
- // TODO: see on frontend what specific data we need here because stop-loss and take-profit is one bundle now
913
968
  _position.strategy.strategyId = Strategies.Identifiers.CloseOnPrice;
914
969
  _position.specific = {
915
970
  market: subData.market,
@@ -1067,6 +1122,12 @@ const parsingMethodsMapping: StrategiesToProtocolVersionMapping = {
1067
1122
  [Strategies.Identifiers.Boost]: parseCompoundV3LeverageManagement,
1068
1123
  [Strategies.Identifiers.EoaRepay]: parseCompoundV3LeverageManagement,
1069
1124
  [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,
1070
1131
  },
1071
1132
  [ProtocolIdentifiers.StrategiesAutomation.ChickenBonds]: {
1072
1133
  [Strategies.Identifiers.Rebond]: parseChickenBondsRebond,