@defisaver/automation-sdk 2.1.2 → 2.1.4

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.
@@ -163,3 +163,12 @@ export declare const curveUsdSoftLiquidationTrigger: {
163
163
  percentage: string;
164
164
  };
165
165
  };
166
+ export declare const crvUSDRatioTrigger: {
167
+ encode(owner: EthereumAddress, controller: EthereumAddress, ratioPercentage: number, ratioState: RatioState): string[];
168
+ decode(triggerData: string[]): {
169
+ owner: string;
170
+ controller: string;
171
+ ratio: number;
172
+ ratioState: number;
173
+ };
174
+ };
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.curveUsdSoftLiquidationTrigger = exports.curveUsdBorrowRateTrigger = exports.sparkQuotePriceTrigger = exports.sparkRatioTrigger = exports.exchangeOffchainPriceTrigger = exports.exchangeTimestampTrigger = exports.compoundV3RatioTrigger = exports.cBondsRebondTrigger = exports.aaveV2RatioTrigger = exports.liquityDebtInFrontWithLimitTrigger = exports.liquityDebtInFrontTrigger = exports.liquityRatioTrigger = exports.compoundV2RatioTrigger = exports.aaveV3QuotePriceWithMaximumGasPriceTrigger = exports.aaveV3QuotePriceTrigger = exports.morphoAaveV2RatioTrigger = exports.aaveV3RatioTrigger = exports.makerRatioTrigger = exports.trailingStopTrigger = exports.chainlinkPriceTrigger = void 0;
29
+ exports.crvUSDRatioTrigger = exports.curveUsdSoftLiquidationTrigger = exports.curveUsdBorrowRateTrigger = exports.sparkQuotePriceTrigger = exports.sparkRatioTrigger = exports.exchangeOffchainPriceTrigger = exports.exchangeTimestampTrigger = exports.compoundV3RatioTrigger = exports.cBondsRebondTrigger = exports.aaveV2RatioTrigger = exports.liquityDebtInFrontWithLimitTrigger = exports.liquityDebtInFrontTrigger = exports.liquityRatioTrigger = exports.compoundV2RatioTrigger = exports.aaveV3QuotePriceWithMaximumGasPriceTrigger = exports.aaveV3QuotePriceTrigger = exports.morphoAaveV2RatioTrigger = exports.aaveV3RatioTrigger = exports.makerRatioTrigger = exports.trailingStopTrigger = exports.chainlinkPriceTrigger = void 0;
30
30
  const decimal_js_1 = __importDefault(require("decimal.js"));
31
31
  const tokens_1 = require("@defisaver/tokens");
32
32
  const web3_eth_abi_1 = __importDefault(require("web3-eth-abi"));
@@ -320,3 +320,18 @@ exports.curveUsdSoftLiquidationTrigger = {
320
320
  };
321
321
  },
322
322
  };
323
+ exports.crvUSDRatioTrigger = {
324
+ encode(owner, controller, ratioPercentage, ratioState) {
325
+ const ratioWei = (0, utils_1.ratioPercentageToWei)(ratioPercentage);
326
+ return [web3_eth_abi_1.default.encodeParameters(['address', 'address', 'uint256', 'uint8'], [owner, controller, ratioWei, ratioState])];
327
+ },
328
+ decode(triggerData) {
329
+ const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'address', 'uint256', 'uint8'], triggerData[0]);
330
+ return {
331
+ owner: decodedData[0],
332
+ controller: decodedData[1],
333
+ ratio: (0, utils_1.weiToRatioPercentage)(decodedData[2]),
334
+ ratioState: Number(decodedData[3]),
335
+ };
336
+ },
337
+ };
@@ -822,4 +822,40 @@ describe('Feature: triggerService.ts', () => {
822
822
  });
823
823
  });
824
824
  });
825
+ describe('When testing triggerService.crvUSDRatioTrigger', () => {
826
+ describe('encode()', () => {
827
+ const examples = [
828
+ [
829
+ ['0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d421963500000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000001'],
830
+ [web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'), web3Utils.toChecksumAddress('0xa920de414ea4ab66b97da1bfe9e6eca7d4219635'), 120, enums_1.RatioState.UNDER]
831
+ ],
832
+ [
833
+ ['0x0000000000000000000000000043d218133afab8f2b829b106633e434ad94e2c000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d42196350000000000000000000000000000000000000000000000001bc16d674ec800000000000000000000000000000000000000000000000000000000000000000000'],
834
+ [web3Utils.toChecksumAddress('0x0043d218133AFaB8F2B829B106633E434Ad94E2c'), web3Utils.toChecksumAddress('0xa920de414ea4ab66b97da1bfe9e6eca7d4219635'), 200, enums_1.RatioState.OVER]
835
+ ],
836
+ ];
837
+ examples.forEach(([expected, actual]) => {
838
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
839
+ (0, chai_1.expect)(triggerService_1.crvUSDRatioTrigger.encode(...actual)).to.eql(expected);
840
+ });
841
+ });
842
+ });
843
+ describe('decode()', () => {
844
+ const examples = [
845
+ [
846
+ { owner: web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'), controller: web3Utils.toChecksumAddress('0xa920de414ea4ab66b97da1bfe9e6eca7d4219635'), ratio: 120, ratioState: enums_1.RatioState.UNDER },
847
+ ['0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d421963500000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000001'],
848
+ ],
849
+ [
850
+ { owner: web3Utils.toChecksumAddress('0x0043d218133AFaB8F2B829B106633E434Ad94E2c'), controller: web3Utils.toChecksumAddress('0xa920de414ea4ab66b97da1bfe9e6eca7d4219635'), ratio: 200, ratioState: enums_1.RatioState.OVER },
851
+ ['0x0000000000000000000000000043d218133afab8f2b829b106633e434ad94e2c000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d42196350000000000000000000000000000000000000000000000001bc16d674ec800000000000000000000000000000000000000000000000000000000000000000000'],
852
+ ],
853
+ ];
854
+ examples.forEach(([expected, actual]) => {
855
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
856
+ (0, chai_1.expect)(triggerService_1.crvUSDRatioTrigger.decode(actual)).to.eql(expected);
857
+ });
858
+ });
859
+ });
860
+ });
825
861
  });
@@ -34,7 +34,8 @@ export declare namespace ProtocolIdentifiers {
34
34
  AaveV3 = "Aave__V3",
35
35
  MorphoAaveV2 = "Morpho-Aave__V2",
36
36
  Exchange = "Exchange",
37
- Spark = "Spark"
37
+ Spark = "Spark",
38
+ CrvUSD = "CurveUSD"
38
39
  }
39
40
  enum LegacyAutomation {
40
41
  MakerDAO = "MakerDAO",
@@ -127,7 +128,9 @@ export declare namespace Bundles {
127
128
  AAVE_V2_REPAY = 22,
128
129
  AAVE_V2_BOOST = 23,
129
130
  COMP_V2_REPAY = 20,
130
- COMP_V2_BOOST = 21
131
+ COMP_V2_BOOST = 21,
132
+ CRVUSD_REPAY = 26,
133
+ CRVUSD_BOOST = 27
131
134
  }
132
135
  enum OptimismIds {
133
136
  AAVE_V3_REPAY = 0,
@@ -139,6 +142,8 @@ export declare namespace Bundles {
139
142
  AAVE_V3_REPAY = 0,
140
143
  AAVE_V3_BOOST = 1,
141
144
  AAVE_V3_CLOSE_TO_DEBT = 2,
142
- AAVE_V3_CLOSE_TO_COLLATERAL = 3
145
+ AAVE_V3_CLOSE_TO_COLLATERAL = 3,
146
+ COMP_V3_SW_REPAY_BUNDLE = 4,
147
+ COMP_V3_SW_BOOST_BUNDLE = 5
143
148
  }
144
149
  }
@@ -44,6 +44,7 @@ var ProtocolIdentifiers;
44
44
  StrategiesAutomation["MorphoAaveV2"] = "Morpho-Aave__V2";
45
45
  StrategiesAutomation["Exchange"] = "Exchange";
46
46
  StrategiesAutomation["Spark"] = "Spark";
47
+ StrategiesAutomation["CrvUSD"] = "CurveUSD";
47
48
  })(StrategiesAutomation = ProtocolIdentifiers.StrategiesAutomation || (ProtocolIdentifiers.StrategiesAutomation = {}));
48
49
  let LegacyAutomation;
49
50
  (function (LegacyAutomation) {
@@ -146,6 +147,8 @@ var Bundles;
146
147
  MainnetIds[MainnetIds["AAVE_V2_BOOST"] = 23] = "AAVE_V2_BOOST";
147
148
  MainnetIds[MainnetIds["COMP_V2_REPAY"] = 20] = "COMP_V2_REPAY";
148
149
  MainnetIds[MainnetIds["COMP_V2_BOOST"] = 21] = "COMP_V2_BOOST";
150
+ MainnetIds[MainnetIds["CRVUSD_REPAY"] = 26] = "CRVUSD_REPAY";
151
+ MainnetIds[MainnetIds["CRVUSD_BOOST"] = 27] = "CRVUSD_BOOST";
149
152
  })(MainnetIds = Bundles.MainnetIds || (Bundles.MainnetIds = {}));
150
153
  let OptimismIds;
151
154
  (function (OptimismIds) {
@@ -160,5 +163,7 @@ var Bundles;
160
163
  ArbitrumIds[ArbitrumIds["AAVE_V3_BOOST"] = 1] = "AAVE_V3_BOOST";
161
164
  ArbitrumIds[ArbitrumIds["AAVE_V3_CLOSE_TO_DEBT"] = 2] = "AAVE_V3_CLOSE_TO_DEBT";
162
165
  ArbitrumIds[ArbitrumIds["AAVE_V3_CLOSE_TO_COLLATERAL"] = 3] = "AAVE_V3_CLOSE_TO_COLLATERAL";
166
+ ArbitrumIds[ArbitrumIds["COMP_V3_SW_REPAY_BUNDLE"] = 4] = "COMP_V3_SW_REPAY_BUNDLE";
167
+ ArbitrumIds[ArbitrumIds["COMP_V3_SW_BOOST_BUNDLE"] = 5] = "COMP_V3_SW_BOOST_BUNDLE";
163
168
  })(ArbitrumIds = Bundles.ArbitrumIds || (Bundles.ArbitrumIds = {}));
164
169
  })(Bundles = exports.Bundles || (exports.Bundles = {}));
@@ -139,8 +139,12 @@ export declare namespace Position {
139
139
  debtInFrontMin: string;
140
140
  targetRepayRatioIncrease: number;
141
141
  }
142
+ interface LeverageManagementCrvUSD extends Base {
143
+ subHashBoost?: string;
144
+ subHashRepay?: string;
145
+ }
142
146
  }
143
- type SpecificAny = Specific.CloseOnPrice | Specific.TrailingStop | Specific.RatioProtection | Specific.CloseOnPriceAave | Specific.CloseOnPriceWithMaximumGasPriceAave | Specific.DebtInFrontRepay;
147
+ type SpecificAny = Specific.CloseOnPrice | Specific.TrailingStop | Specific.RatioProtection | Specific.CloseOnPriceAave | Specific.CloseOnPriceWithMaximumGasPriceAave | Specific.DebtInFrontRepay | Specific.LeverageManagementCrvUSD;
144
148
  interface Automated {
145
149
  chainId: ChainId;
146
150
  positionId: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defisaver/automation-sdk",
3
- "version": "2.1.2",
3
+ "version": "2.1.4",
4
4
  "description": "",
5
5
  "main": "./umd/index.js",
6
6
  "module": "./esm/index.js",
@@ -22,7 +22,7 @@
22
22
  "license": "ISC",
23
23
  "dependencies": {
24
24
  "@defisaver/eslint-config": "^1.0.1",
25
- "@defisaver/sdk": "^1.0.55",
25
+ "@defisaver/sdk": "^1.0.61",
26
26
  "@defisaver/tokens": "^1.5.3",
27
27
  "@ethersproject/address": "^5.0.10",
28
28
  "@ethersproject/solidity": "^5.0.9",
@@ -169,6 +169,10 @@ export default class StrategiesAutomation extends Automation {
169
169
  s.protocol.id !== ProtocolIdentifiers.StrategiesAutomation.MakerDAO // reflexer needs to get added if we have it
170
170
  || s.strategyData.decoded.subData.vaultId === current.strategyData.decoded.triggerData.vaultId
171
171
  )
172
+ && (
173
+ s.protocol.id !== ProtocolIdentifiers.StrategiesAutomation.CrvUSD // merge only crvUSD leverage management for the same market
174
+ || s.strategyData.decoded.subData.controller.toLowerCase() === current.strategyData.decoded.triggerData.controller.toLowerCase()
175
+ )
172
176
  ));
173
177
 
174
178
  if (mergePairIndex !== -1) {
@@ -283,6 +283,16 @@ export const MAINNET_BUNDLES_INFO: MainnetBundleInfo = {
283
283
  strategyId: Strategies.Identifiers.Boost,
284
284
  protocol: PROTOCOLS.CompoundV2,
285
285
  },
286
+ [Bundles.MainnetIds.CRVUSD_REPAY]: {
287
+ strategyOrBundleId: Bundles.MainnetIds.CRVUSD_REPAY,
288
+ strategyId: Strategies.Identifiers.Repay,
289
+ protocol: PROTOCOLS.CrvUSD,
290
+ },
291
+ [Bundles.MainnetIds.CRVUSD_BOOST]: {
292
+ strategyOrBundleId: Bundles.MainnetIds.CRVUSD_BOOST,
293
+ strategyId: Strategies.Identifiers.Boost,
294
+ protocol: PROTOCOLS.CrvUSD,
295
+ },
286
296
  };
287
297
 
288
298
  export const OPTIMISM_BUNDLES_INFO: OptimismBundleInfo = {
@@ -329,6 +339,16 @@ export const ARBITRUM_BUNDLES_INFO: ArbitrumBundleInfo = {
329
339
  strategyId: Strategies.Identifiers.CloseToCollateral,
330
340
  protocol: PROTOCOLS.AaveV3,
331
341
  },
342
+ [Bundles.ArbitrumIds.COMP_V3_SW_BOOST_BUNDLE]: {
343
+ strategyOrBundleId: Bundles.ArbitrumIds.COMP_V3_SW_BOOST_BUNDLE,
344
+ strategyId: Strategies.Identifiers.Boost,
345
+ protocol: PROTOCOLS.CompoundV3,
346
+ },
347
+ [Bundles.ArbitrumIds.COMP_V3_SW_REPAY_BUNDLE]: {
348
+ strategyOrBundleId: Bundles.ArbitrumIds.COMP_V3_SW_REPAY_BUNDLE,
349
+ strategyId: Strategies.Identifiers.Repay,
350
+ protocol: PROTOCOLS.CompoundV3,
351
+ },
332
352
  };
333
353
 
334
354
  export const BUNDLES_INFO: BundlesInfo = {
@@ -417,8 +417,12 @@ function parseCompoundV3LeverageManagement(position: Position.Automated, parseDa
417
417
  const { subStruct, subId } = parseData.subscriptionEventData;
418
418
  const { isEnabled } = parseData.strategiesSubsData;
419
419
 
420
+ const subDataDecoder = position.chainId !== 1
421
+ ? subDataService.compoundV3L2LeverageManagementSubData
422
+ : subDataService.compoundV3LeverageManagementSubData;
423
+
420
424
  const triggerData = triggerService.compoundV3RatioTrigger.decode(subStruct.triggerData);
421
- const subData = subDataService.compoundV3LeverageManagementSubData.decode(subStruct.subData);
425
+ const subData = subDataDecoder.decode(subStruct.subData);
422
426
 
423
427
  _position.strategyData.decoded.triggerData = triggerData;
424
428
  _position.strategyData.decoded.subData = subData;
@@ -669,6 +673,43 @@ function parseLiquityDebtInFrontRepay(position: Position.Automated, parseData: P
669
673
  return _position;
670
674
  }
671
675
 
676
+ function parseCrvUSDLeverageManagement(position: Position.Automated, parseData: ParseData): Position.Automated {
677
+ const _position = cloneDeep(position);
678
+
679
+ const { subStruct, subId, subHash } = parseData.subscriptionEventData;
680
+ const { isEnabled } = parseData.strategiesSubsData;
681
+ const triggerData = triggerService.crvUSDRatioTrigger.decode(subStruct.triggerData);
682
+ const subData = subDataService.crvUSDLeverageManagementSubData.decode(subStruct.subData);
683
+
684
+ _position.strategyData.decoded.triggerData = triggerData;
685
+ _position.strategyData.decoded.subData = subData;
686
+
687
+ const isRepay = _position.strategy.strategyId === Strategies.Identifiers.Repay;
688
+ if (isRepay) {
689
+ _position.specific = {
690
+ triggerRepayRatio: triggerData.ratio,
691
+ targetRepayRatio: subData.targetRatio,
692
+ repayEnabled: isEnabled,
693
+ subId1: Number(subId),
694
+ subHashRepay: subHash,
695
+ };
696
+ } else {
697
+ _position.specific = {
698
+ triggerBoostRatio: triggerData.ratio,
699
+ targetBoostRatio: subData.targetRatio,
700
+ boostEnabled: isEnabled,
701
+ subId2: Number(subId),
702
+ subHashBoost: subHash,
703
+ };
704
+ }
705
+
706
+ _position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, triggerData.controller);
707
+ _position.strategy.strategyId = Strategies.IdOverrides.LeverageManagement;
708
+ _position.specific.mergeWithSameId = true;
709
+
710
+ return _position;
711
+ }
712
+
672
713
  const parsingMethodsMapping: StrategiesToProtocolVersionMapping = {
673
714
  [ProtocolIdentifiers.StrategiesAutomation.MakerDAO]: {
674
715
  [Strategies.Identifiers.SavingsLiqProtection]: parseMakerSavingsLiqProtection,
@@ -728,6 +769,10 @@ const parsingMethodsMapping: StrategiesToProtocolVersionMapping = {
728
769
  [Strategies.Identifiers.CloseToDebt]: parseSparkCloseOnPrice,
729
770
  [Strategies.Identifiers.CloseToCollateral]: parseSparkCloseOnPrice,
730
771
  },
772
+ [ProtocolIdentifiers.StrategiesAutomation.CrvUSD]: {
773
+ [Strategies.Identifiers.Repay]: parseCrvUSDLeverageManagement,
774
+ [Strategies.Identifiers.Boost]: parseCrvUSDLeverageManagement,
775
+ },
731
776
  };
732
777
 
733
778
  function getParsingMethod(id: ProtocolIdentifiers.StrategiesAutomation, strategy: BundleOrStrategy) {
@@ -18,6 +18,7 @@ import {
18
18
  morphoAaveV2Encode,
19
19
  exchangeEncode,
20
20
  sparkEncode,
21
+ crvUSDEncode, compoundV3L2Encode,
21
22
  } from './strategySubService';
22
23
 
23
24
  describe('Feature: strategySubService.ts', () => {
@@ -363,7 +364,7 @@ describe('Feature: strategySubService.ts', () => {
363
364
  [bondId: number],
364
365
  ]> = [
365
366
  [
366
- ["0x00000000000000000000000000000000000000000000000000000000000005e3"],
367
+ ['0x00000000000000000000000000000000000000000000000000000000000005e3'],
367
368
  [1507]
368
369
  ]
369
370
  ];
@@ -832,4 +833,101 @@ describe('Feature: strategySubService.ts', () => {
832
833
  });
833
834
  });
834
835
  });
836
+
837
+ describe('When testing strategySubService.crvUSDEncode', () => {
838
+ describe('leverageManagement()', () => {
839
+ const examples: Array<[
840
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
841
+ [owner: EthereumAddress, controllerAddr: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number, collTokenAddr: EthereumAddress, crvUSDAddr: EthereumAddress],
842
+ ]> = [
843
+ [
844
+ [
845
+ Bundles.MainnetIds.CRVUSD_REPAY,
846
+ true,
847
+ [
848
+ '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635000000000000000000000000000000000000000000000000136dcc951d8c00000000000000000000000000000000000000000000000000000000000000000001',
849
+ ],
850
+ [
851
+ '0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635',
852
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
853
+ '0x0000000000000000000000000000000000000000000000001a5e27eef13e0000',
854
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
855
+ '0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e',
856
+ ],
857
+ ],
858
+ [
859
+ web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
860
+ web3Utils.toChecksumAddress('0xa920de414ea4ab66b97da1bfe9e6eca7d4219635'),
861
+ RatioState.UNDER,
862
+ 190,
863
+ 140,
864
+ '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
865
+ '0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E',
866
+ ]
867
+ ],
868
+ [
869
+ [
870
+ Bundles.MainnetIds.CRVUSD_BOOST,
871
+ true,
872
+ [
873
+ '0x0000000000000000000000000043d218133afab8f2b829b106633e434ad94e2c000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d42196350000000000000000000000000000000000000000000000001bc16d674ec800000000000000000000000000000000000000000000000000000000000000000000'
874
+ ],
875
+ [
876
+ '0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635',
877
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
878
+ '0x00000000000000000000000000000000000000000000000016345785d8a00000',
879
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
880
+ '0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e',
881
+ ],
882
+ ],
883
+ [
884
+ web3Utils.toChecksumAddress('0x0043d218133AFaB8F2B829B106633E434Ad94E2c'),
885
+ web3Utils.toChecksumAddress('0xa920de414ea4ab66b97da1bfe9e6eca7d4219635'),
886
+ RatioState.OVER,
887
+ 160,
888
+ 200,
889
+ '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
890
+ '0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E',
891
+ ]
892
+ ],
893
+ ];
894
+
895
+ examples.forEach(([expected, actual]) => {
896
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
897
+ expect(crvUSDEncode.leverageManagement(...actual)).to.eql(expected);
898
+ });
899
+ });
900
+ });
901
+ });
902
+
903
+ describe('When testing strategySubService.compoundV3L2Encode', () => {
904
+ describe('leverageManagement()', () => {
905
+ const examples: Array<[string, [EthereumAddress, EthereumAddress, number, number, number, number, boolean]]> = [
906
+ [
907
+ '0x0313D212133AFab8F2b829B1066c7e43caD94e2c0213D212133AfaB8F2b829B1066C7E43cAD94E2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000001a5e27eef13e000001',
908
+ [
909
+ web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'),
910
+ web3Utils.toChecksumAddress('0x0213d212133AFaB8F2B829B1066c7E43cAd94E2c'),
911
+ 160, 220, 180, 190,
912
+ true
913
+ ],
914
+ ],
915
+ [
916
+ '0x0313D212133AFab8F2b829B1066c7e43caD94e2c0413d212133afAb8F2B829b1066C7e43cAd94e2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000000f43fc2c04ee000000',
917
+ [
918
+ web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'),
919
+ web3Utils.toChecksumAddress('0x0413d212133AFaB8F2B829B1066c7E43cAd94E2c'),
920
+ 160, 220, 180, 110,
921
+ false
922
+ ],
923
+ ],
924
+ ];
925
+ examples.forEach(([expected, actual]) => {
926
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
927
+ expect(compoundV3L2Encode.leverageManagement(...actual)).to.eql(expected);
928
+ });
929
+ });
930
+ });
931
+ });
932
+
835
933
  });
@@ -327,6 +327,20 @@ export const compoundV3Encode = {
327
327
  },
328
328
  };
329
329
 
330
+ export const compoundV3L2Encode = {
331
+ leverageManagement(
332
+ market: EthereumAddress,
333
+ baseToken: EthereumAddress,
334
+ triggerRepayRatio: number,
335
+ triggerBoostRatio: number,
336
+ targetBoostRatio: number,
337
+ targetRepayRatio: number,
338
+ boostEnabled: boolean,
339
+ ) {
340
+ return subDataService.compoundV3L2LeverageManagementSubData.encode(market, baseToken, triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled);
341
+ },
342
+ };
343
+
330
344
  export const morphoAaveV2Encode = {
331
345
  leverageManagement(
332
346
  triggerRepayRatio: number,
@@ -413,3 +427,24 @@ export const sparkEncode = {
413
427
  return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
414
428
  },
415
429
  };
430
+
431
+ export const crvUSDEncode = {
432
+ leverageManagement(
433
+ owner: EthereumAddress,
434
+ controllerAddr: EthereumAddress,
435
+ ratioState: RatioState,
436
+ targetRatio: number,
437
+ triggerRatio: number,
438
+ collTokenAddr: EthereumAddress,
439
+ crvUSDAddr: EthereumAddress,
440
+ ) {
441
+ const subData = subDataService.crvUSDLeverageManagementSubData.encode(controllerAddr, ratioState, targetRatio, collTokenAddr, crvUSDAddr);
442
+ const triggerData = triggerService.crvUSDRatioTrigger.encode(owner, controllerAddr, triggerRatio, ratioState);
443
+
444
+ // over is boost, under is repay
445
+ const strategyOrBundleId = ratioState === RatioState.OVER ? Bundles.MainnetIds.CRVUSD_BOOST : Bundles.MainnetIds.CRVUSD_REPAY;
446
+ const isBundle = true;
447
+
448
+ return [strategyOrBundleId, isBundle, triggerData, subData];
449
+ },
450
+ };