@defisaver/automation-sdk 2.1.2 → 2.1.3

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.
@@ -127,7 +127,9 @@ class StrategiesAutomation extends Automation_1.default {
127
127
  && s.strategy.strategyId === current.strategy.strategyId
128
128
  && s.protocol.id === current.protocol.id
129
129
  && (s.protocol.id !== enums_1.ProtocolIdentifiers.StrategiesAutomation.MakerDAO // reflexer needs to get added if we have it
130
- || s.strategyData.decoded.subData.vaultId === current.strategyData.decoded.triggerData.vaultId)));
130
+ || s.strategyData.decoded.subData.vaultId === current.strategyData.decoded.triggerData.vaultId)
131
+ && (s.protocol.id !== enums_1.ProtocolIdentifiers.StrategiesAutomation.CrvUSD // merge only crvUSD leverage management for the same market
132
+ || s.strategyData.decoded.subData.controller.toLowerCase() === current.strategyData.decoded.triggerData.controller.toLowerCase())));
131
133
  if (mergePairIndex !== -1) {
132
134
  const mergePair = copyList[mergePairIndex];
133
135
  if ((0, utils_1.isDefined)(mergePair)) {
@@ -273,6 +273,16 @@ exports.MAINNET_BUNDLES_INFO = {
273
273
  strategyId: enums_1.Strategies.Identifiers.Boost,
274
274
  protocol: exports.PROTOCOLS.CompoundV2,
275
275
  },
276
+ [enums_1.Bundles.MainnetIds.CRVUSD_REPAY]: {
277
+ strategyOrBundleId: enums_1.Bundles.MainnetIds.CRVUSD_REPAY,
278
+ strategyId: enums_1.Strategies.Identifiers.Repay,
279
+ protocol: exports.PROTOCOLS.CrvUSD,
280
+ },
281
+ [enums_1.Bundles.MainnetIds.CRVUSD_BOOST]: {
282
+ strategyOrBundleId: enums_1.Bundles.MainnetIds.CRVUSD_BOOST,
283
+ strategyId: enums_1.Strategies.Identifiers.Boost,
284
+ protocol: exports.PROTOCOLS.CrvUSD,
285
+ },
276
286
  };
277
287
  exports.OPTIMISM_BUNDLES_INFO = {
278
288
  [enums_1.Bundles.OptimismIds.AAVE_V3_REPAY]: {
@@ -501,6 +501,38 @@ function parseLiquityDebtInFrontRepay(position, parseData) {
501
501
  };
502
502
  return _position;
503
503
  }
504
+ function parseCrvUSDLeverageManagement(position, parseData) {
505
+ const _position = (0, lodash_1.cloneDeep)(position);
506
+ const { subStruct, subId, subHash } = parseData.subscriptionEventData;
507
+ const { isEnabled } = parseData.strategiesSubsData;
508
+ const triggerData = triggerService.crvUSDRatioTrigger.decode(subStruct.triggerData);
509
+ const subData = subDataService.crvUSDLeverageManagementSubData.decode(subStruct.subData);
510
+ _position.strategyData.decoded.triggerData = triggerData;
511
+ _position.strategyData.decoded.subData = subData;
512
+ const isRepay = _position.strategy.strategyId === enums_1.Strategies.Identifiers.Repay;
513
+ if (isRepay) {
514
+ _position.specific = {
515
+ triggerRepayRatio: triggerData.ratio,
516
+ targetRepayRatio: subData.targetRatio,
517
+ repayEnabled: isEnabled,
518
+ subId1: Number(subId),
519
+ subHashRepay: subHash,
520
+ };
521
+ }
522
+ else {
523
+ _position.specific = {
524
+ triggerBoostRatio: triggerData.ratio,
525
+ targetBoostRatio: subData.targetRatio,
526
+ boostEnabled: isEnabled,
527
+ subId2: Number(subId),
528
+ subHashBoost: subHash,
529
+ };
530
+ }
531
+ _position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, triggerData.controller);
532
+ _position.strategy.strategyId = enums_1.Strategies.IdOverrides.LeverageManagement;
533
+ _position.specific.mergeWithSameId = true;
534
+ return _position;
535
+ }
504
536
  const parsingMethodsMapping = {
505
537
  [enums_1.ProtocolIdentifiers.StrategiesAutomation.MakerDAO]: {
506
538
  [enums_1.Strategies.Identifiers.SavingsLiqProtection]: parseMakerSavingsLiqProtection,
@@ -560,6 +592,10 @@ const parsingMethodsMapping = {
560
592
  [enums_1.Strategies.Identifiers.CloseToDebt]: parseSparkCloseOnPrice,
561
593
  [enums_1.Strategies.Identifiers.CloseToCollateral]: parseSparkCloseOnPrice,
562
594
  },
595
+ [enums_1.ProtocolIdentifiers.StrategiesAutomation.CrvUSD]: {
596
+ [enums_1.Strategies.Identifiers.Repay]: parseCrvUSDLeverageManagement,
597
+ [enums_1.Strategies.Identifiers.Boost]: parseCrvUSDLeverageManagement,
598
+ },
563
599
  };
564
600
  function getParsingMethod(id, strategy) {
565
601
  return parsingMethodsMapping[id][strategy.strategyId];
@@ -75,3 +75,6 @@ export declare const sparkEncode: {
75
75
  debtAssetId: number;
76
76
  }): (number | boolean | string[])[];
77
77
  };
78
+ export declare const crvUSDEncode: {
79
+ leverageManagement(owner: EthereumAddress, controllerAddr: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number, collTokenAddr: EthereumAddress, crvUSDAddr: EthereumAddress): (boolean | string[] | Bundles.MainnetIds)[];
80
+ };
@@ -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.sparkEncode = exports.exchangeEncode = exports.morphoAaveV2Encode = exports.compoundV3Encode = exports.compoundV2Encode = exports.aaveV3Encode = exports.aaveV2Encode = exports.chickenBondsEncode = exports.liquityEncode = exports.makerEncode = void 0;
29
+ exports.crvUSDEncode = exports.sparkEncode = exports.exchangeEncode = exports.morphoAaveV2Encode = exports.compoundV3Encode = exports.compoundV2Encode = exports.aaveV3Encode = exports.aaveV2Encode = exports.chickenBondsEncode = exports.liquityEncode = exports.makerEncode = void 0;
30
30
  const decimal_js_1 = __importDefault(require("decimal.js"));
31
31
  const tokens_1 = require("@defisaver/tokens");
32
32
  const enums_1 = require("../types/enums");
@@ -218,3 +218,13 @@ exports.sparkEncode = {
218
218
  return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
219
219
  },
220
220
  };
221
+ exports.crvUSDEncode = {
222
+ leverageManagement(owner, controllerAddr, ratioState, targetRatio, triggerRatio, collTokenAddr, crvUSDAddr) {
223
+ const subData = subDataService.crvUSDLeverageManagementSubData.encode(controllerAddr, ratioState, targetRatio, collTokenAddr, crvUSDAddr);
224
+ const triggerData = triggerService.crvUSDRatioTrigger.encode(owner, controllerAddr, triggerRatio, ratioState);
225
+ // over is boost, under is repay
226
+ const strategyOrBundleId = ratioState === enums_1.RatioState.OVER ? enums_1.Bundles.MainnetIds.CRVUSD_BOOST : enums_1.Bundles.MainnetIds.CRVUSD_REPAY;
227
+ const isBundle = true;
228
+ return [strategyOrBundleId, isBundle, triggerData, subData];
229
+ },
230
+ };
@@ -293,7 +293,7 @@ describe('Feature: strategySubService.ts', () => {
293
293
  describe('rebond()', () => {
294
294
  const examples = [
295
295
  [
296
- ["0x00000000000000000000000000000000000000000000000000000000000005e3"],
296
+ ['0x00000000000000000000000000000000000000000000000000000000000005e3'],
297
297
  [1507]
298
298
  ]
299
299
  ];
@@ -689,4 +689,65 @@ describe('Feature: strategySubService.ts', () => {
689
689
  });
690
690
  });
691
691
  });
692
+ describe('When testing strategySubService.crvUSDEncode', () => {
693
+ describe('leverageManagement()', () => {
694
+ const examples = [
695
+ [
696
+ [
697
+ enums_1.Bundles.MainnetIds.CRVUSD_REPAY,
698
+ true,
699
+ [
700
+ '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635000000000000000000000000000000000000000000000000136dcc951d8c00000000000000000000000000000000000000000000000000000000000000000001',
701
+ ],
702
+ [
703
+ '0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635',
704
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
705
+ '0x0000000000000000000000000000000000000000000000001a5e27eef13e0000',
706
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
707
+ '0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e',
708
+ ],
709
+ ],
710
+ [
711
+ web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
712
+ web3Utils.toChecksumAddress('0xa920de414ea4ab66b97da1bfe9e6eca7d4219635'),
713
+ enums_1.RatioState.UNDER,
714
+ 190,
715
+ 140,
716
+ '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
717
+ '0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E',
718
+ ]
719
+ ],
720
+ [
721
+ [
722
+ enums_1.Bundles.MainnetIds.CRVUSD_BOOST,
723
+ true,
724
+ [
725
+ '0x0000000000000000000000000043d218133afab8f2b829b106633e434ad94e2c000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d42196350000000000000000000000000000000000000000000000001bc16d674ec800000000000000000000000000000000000000000000000000000000000000000000'
726
+ ],
727
+ [
728
+ '0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635',
729
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
730
+ '0x00000000000000000000000000000000000000000000000016345785d8a00000',
731
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
732
+ '0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e',
733
+ ],
734
+ ],
735
+ [
736
+ web3Utils.toChecksumAddress('0x0043d218133AFaB8F2B829B106633E434Ad94E2c'),
737
+ web3Utils.toChecksumAddress('0xa920de414ea4ab66b97da1bfe9e6eca7d4219635'),
738
+ enums_1.RatioState.OVER,
739
+ 160,
740
+ 200,
741
+ '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
742
+ '0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E',
743
+ ]
744
+ ],
745
+ ];
746
+ examples.forEach(([expected, actual]) => {
747
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
748
+ (0, chai_1.expect)(strategySubService_1.crvUSDEncode.leverageManagement(...actual)).to.eql(expected);
749
+ });
750
+ });
751
+ });
752
+ });
692
753
  });
@@ -1,6 +1,6 @@
1
1
  import type { EthereumAddress } from '../types';
2
2
  import type { OrderType } from '../types/enums';
3
- import { ChainId } from '../types/enums';
3
+ import { ChainId, RatioState } from '../types/enums';
4
4
  export declare const makerRepayFromSavingsSubData: {
5
5
  encode(vaultId: number, targetRatioPercentage: number, chainId: ChainId, daiAddr?: EthereumAddress, mcdCdpManagerAddr?: EthereumAddress): string[];
6
6
  decode(subData: string[]): {
@@ -145,3 +145,10 @@ export declare const liquityDebtInFrontRepaySubData: {
145
145
  targetRatioIncrease: number;
146
146
  };
147
147
  };
148
+ export declare const crvUSDLeverageManagementSubData: {
149
+ encode: (controllerAddr: EthereumAddress, ratioState: RatioState, targetRatio: number, collTokenAddr: EthereumAddress, crvUSDAddr: EthereumAddress) => string[];
150
+ decode: (subData: string[]) => {
151
+ controller: string;
152
+ targetRatio: number;
153
+ };
154
+ };
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.liquityDebtInFrontRepaySubData = exports.liquityDsrSupplySubData = exports.liquityDsrPaybackSubData = exports.sparkQuotePriceSubData = exports.sparkLeverageManagementSubData = exports.exchangeLimitOrderSubData = exports.exchangeDcaSubData = exports.liquityPaybackUsingChickenBondSubData = exports.cBondsRebondSubData = exports.morphoAaveV2LeverageManagementSubData = exports.compoundV3LeverageManagementSubData = exports.compoundV2LeverageManagementSubData = exports.aaveV3QuotePriceSubData = exports.aaveV3LeverageManagementSubData = exports.aaveV2LeverageManagementSubData = exports.liquityCloseSubData = exports.liquityLeverageManagementSubData = exports.makerLeverageManagementSubData = exports.makerCloseSubData = exports.liquityRepayFromSavingsSubData = exports.makerRepayFromSavingsSubData = void 0;
6
+ exports.crvUSDLeverageManagementSubData = exports.liquityDebtInFrontRepaySubData = exports.liquityDsrSupplySubData = exports.liquityDsrPaybackSubData = exports.sparkQuotePriceSubData = exports.sparkLeverageManagementSubData = exports.exchangeLimitOrderSubData = exports.exchangeDcaSubData = exports.liquityPaybackUsingChickenBondSubData = exports.cBondsRebondSubData = exports.morphoAaveV2LeverageManagementSubData = exports.compoundV3LeverageManagementSubData = exports.compoundV2LeverageManagementSubData = exports.aaveV3QuotePriceSubData = exports.aaveV3LeverageManagementSubData = exports.aaveV2LeverageManagementSubData = exports.liquityCloseSubData = exports.liquityLeverageManagementSubData = exports.makerLeverageManagementSubData = exports.makerCloseSubData = exports.liquityRepayFromSavingsSubData = exports.makerRepayFromSavingsSubData = void 0;
7
7
  const decimal_js_1 = __importDefault(require("decimal.js"));
8
8
  const web3_eth_abi_1 = __importDefault(require("web3-eth-abi"));
9
9
  const tokens_1 = require("@defisaver/tokens");
@@ -340,3 +340,19 @@ exports.liquityDebtInFrontRepaySubData = {
340
340
  return { targetRatioIncrease };
341
341
  },
342
342
  };
343
+ exports.crvUSDLeverageManagementSubData = {
344
+ encode: (controllerAddr, ratioState, targetRatio, collTokenAddr, crvUSDAddr) => {
345
+ const controllerAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', controllerAddr);
346
+ const ratioStateEncoded = web3_eth_abi_1.default.encodeParameter('uint8', ratioState);
347
+ const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
348
+ const collTokenAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', collTokenAddr);
349
+ const crvUSDAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', crvUSDAddr);
350
+ return [controllerAddrEncoded, ratioStateEncoded, targetRatioEncoded, collTokenAddrEncoded, crvUSDAddrEncoded];
351
+ },
352
+ decode: (subData) => {
353
+ const controller = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
354
+ const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[2]);
355
+ const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
356
+ return { controller, targetRatio };
357
+ },
358
+ };
@@ -990,4 +990,58 @@ describe('Feature: subDataService.ts', () => {
990
990
  });
991
991
  });
992
992
  });
993
+ describe('When testing subDataService.crvUSDLeverageManagementSubData', () => {
994
+ describe('encode()', () => {
995
+ const examples = [
996
+ [
997
+ [
998
+ "0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635",
999
+ "0x0000000000000000000000000000000000000000000000000000000000000001",
1000
+ "0x00000000000000000000000000000000000000000000000010a741a462780000",
1001
+ "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
1002
+ "0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e",
1003
+ ],
1004
+ ["0xa920de414ea4ab66b97da1bfe9e6eca7d4219635", enums_1.RatioState.UNDER, 120, "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", "0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E"],
1005
+ ],
1006
+ [
1007
+ [
1008
+ "0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635",
1009
+ "0x0000000000000000000000000000000000000000000000000000000000000000",
1010
+ "0x00000000000000000000000000000000000000000000000018fae27693b40000",
1011
+ "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
1012
+ "0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e",
1013
+ ],
1014
+ ["0xa920de414ea4ab66b97da1bfe9e6eca7d4219635", enums_1.RatioState.OVER, 180, "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", "0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E"]
1015
+ ],
1016
+ ];
1017
+ examples.forEach(([expected, actual]) => {
1018
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
1019
+ (0, chai_1.expect)(subDataService_1.crvUSDLeverageManagementSubData.encode(...actual)).to.eql(expected);
1020
+ });
1021
+ });
1022
+ });
1023
+ describe('decode()', () => {
1024
+ const examples = [
1025
+ [
1026
+ {
1027
+ controller: '0xA920De414eA4Ab66b97dA1bFE9e6EcA7d4219635',
1028
+ targetRatio: 120,
1029
+ },
1030
+ ["0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x00000000000000000000000000000000000000000000000010a741a462780000", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e",],
1031
+ ],
1032
+ [
1033
+ {
1034
+ controller: "0xA920De414eA4Ab66b97dA1bFE9e6EcA7d4219635",
1035
+ targetRatio: 180,
1036
+ },
1037
+ ["0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x00000000000000000000000000000000000000000000000018fae27693b40000", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e",],
1038
+ ],
1039
+ ];
1040
+ examples.forEach(([expected, actual]) => {
1041
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1042
+ (0, chai_1.expect)(subDataService_1.crvUSDLeverageManagementSubData.decode(actual)).to.eql(expected);
1043
+ });
1044
+ });
1045
+ });
1046
+ });
993
1047
  });
@@ -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,
@@ -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) {
@@ -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.3",
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 = {
@@ -669,6 +669,43 @@ function parseLiquityDebtInFrontRepay(position: Position.Automated, parseData: P
669
669
  return _position;
670
670
  }
671
671
 
672
+ function parseCrvUSDLeverageManagement(position: Position.Automated, parseData: ParseData): Position.Automated {
673
+ const _position = cloneDeep(position);
674
+
675
+ const { subStruct, subId, subHash } = parseData.subscriptionEventData;
676
+ const { isEnabled } = parseData.strategiesSubsData;
677
+ const triggerData = triggerService.crvUSDRatioTrigger.decode(subStruct.triggerData);
678
+ const subData = subDataService.crvUSDLeverageManagementSubData.decode(subStruct.subData);
679
+
680
+ _position.strategyData.decoded.triggerData = triggerData;
681
+ _position.strategyData.decoded.subData = subData;
682
+
683
+ const isRepay = _position.strategy.strategyId === Strategies.Identifiers.Repay;
684
+ if (isRepay) {
685
+ _position.specific = {
686
+ triggerRepayRatio: triggerData.ratio,
687
+ targetRepayRatio: subData.targetRatio,
688
+ repayEnabled: isEnabled,
689
+ subId1: Number(subId),
690
+ subHashRepay: subHash,
691
+ };
692
+ } else {
693
+ _position.specific = {
694
+ triggerBoostRatio: triggerData.ratio,
695
+ targetBoostRatio: subData.targetRatio,
696
+ boostEnabled: isEnabled,
697
+ subId2: Number(subId),
698
+ subHashBoost: subHash,
699
+ };
700
+ }
701
+
702
+ _position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, triggerData.controller);
703
+ _position.strategy.strategyId = Strategies.IdOverrides.LeverageManagement;
704
+ _position.specific.mergeWithSameId = true;
705
+
706
+ return _position;
707
+ }
708
+
672
709
  const parsingMethodsMapping: StrategiesToProtocolVersionMapping = {
673
710
  [ProtocolIdentifiers.StrategiesAutomation.MakerDAO]: {
674
711
  [Strategies.Identifiers.SavingsLiqProtection]: parseMakerSavingsLiqProtection,
@@ -728,6 +765,10 @@ const parsingMethodsMapping: StrategiesToProtocolVersionMapping = {
728
765
  [Strategies.Identifiers.CloseToDebt]: parseSparkCloseOnPrice,
729
766
  [Strategies.Identifiers.CloseToCollateral]: parseSparkCloseOnPrice,
730
767
  },
768
+ [ProtocolIdentifiers.StrategiesAutomation.CrvUSD]: {
769
+ [Strategies.Identifiers.Repay]: parseCrvUSDLeverageManagement,
770
+ [Strategies.Identifiers.Boost]: parseCrvUSDLeverageManagement,
771
+ },
731
772
  };
732
773
 
733
774
  function getParsingMethod(id: ProtocolIdentifiers.StrategiesAutomation, strategy: BundleOrStrategy) {
@@ -18,6 +18,7 @@ import {
18
18
  morphoAaveV2Encode,
19
19
  exchangeEncode,
20
20
  sparkEncode,
21
+ crvUSDEncode,
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,69 @@ describe('Feature: strategySubService.ts', () => {
832
833
  });
833
834
  });
834
835
  });
836
+ describe('When testing strategySubService.crvUSDEncode', () => {
837
+ describe('leverageManagement()', () => {
838
+ const examples: Array<[
839
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
840
+ [owner: EthereumAddress, controllerAddr: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number, collTokenAddr: EthereumAddress, crvUSDAddr: EthereumAddress],
841
+ ]> = [
842
+ [
843
+ [
844
+ Bundles.MainnetIds.CRVUSD_REPAY,
845
+ true,
846
+ [
847
+ '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635000000000000000000000000000000000000000000000000136dcc951d8c00000000000000000000000000000000000000000000000000000000000000000001',
848
+ ],
849
+ [
850
+ '0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635',
851
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
852
+ '0x0000000000000000000000000000000000000000000000001a5e27eef13e0000',
853
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
854
+ '0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e',
855
+ ],
856
+ ],
857
+ [
858
+ web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
859
+ web3Utils.toChecksumAddress('0xa920de414ea4ab66b97da1bfe9e6eca7d4219635'),
860
+ RatioState.UNDER,
861
+ 190,
862
+ 140,
863
+ '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
864
+ '0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E',
865
+ ]
866
+ ],
867
+ [
868
+ [
869
+ Bundles.MainnetIds.CRVUSD_BOOST,
870
+ true,
871
+ [
872
+ '0x0000000000000000000000000043d218133afab8f2b829b106633e434ad94e2c000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d42196350000000000000000000000000000000000000000000000001bc16d674ec800000000000000000000000000000000000000000000000000000000000000000000'
873
+ ],
874
+ [
875
+ '0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635',
876
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
877
+ '0x00000000000000000000000000000000000000000000000016345785d8a00000',
878
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
879
+ '0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e',
880
+ ],
881
+ ],
882
+ [
883
+ web3Utils.toChecksumAddress('0x0043d218133AFaB8F2B829B106633E434Ad94E2c'),
884
+ web3Utils.toChecksumAddress('0xa920de414ea4ab66b97da1bfe9e6eca7d4219635'),
885
+ RatioState.OVER,
886
+ 160,
887
+ 200,
888
+ '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
889
+ '0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E',
890
+ ]
891
+ ],
892
+ ];
893
+
894
+ examples.forEach(([expected, actual]) => {
895
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
896
+ expect(crvUSDEncode.leverageManagement(...actual)).to.eql(expected);
897
+ });
898
+ });
899
+ });
900
+ });
835
901
  });