@defisaver/automation-sdk 3.3.16 → 3.3.17

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.
@@ -652,6 +652,44 @@ export const crvUSDEncode = {
652
652
  },
653
653
  };
654
654
 
655
+ export type MorphoBlueBundleStrategy = 'repay' | 'boost' | 'repayOnPrice' | 'boostOnPrice' | 'close';
656
+
657
+ function getMorphoBlueBundlesIds(network: ChainId) {
658
+ switch (network) {
659
+ case ChainId.Ethereum:
660
+ return Bundles.MainnetIds;
661
+ case ChainId.Base:
662
+ return Bundles.BaseIds;
663
+ case ChainId.Arbitrum:
664
+ return Bundles.ArbitrumIds;
665
+ default:
666
+ throw new Error(`Morpho Blue strategies are not supported on chain ${network}`);
667
+ }
668
+ }
669
+
670
+ export function getMorphoBlueBundleId(
671
+ network: ChainId,
672
+ strategy: MorphoBlueBundleStrategy,
673
+ isEOA: boolean,
674
+ ): number {
675
+ const bundlesIds = getMorphoBlueBundlesIds(network);
676
+
677
+ switch (strategy) {
678
+ case 'repay':
679
+ return isEOA ? bundlesIds.MORPHO_BLUE_EOA_REPAY : bundlesIds.MORPHO_BLUE_REPAY;
680
+ case 'boost':
681
+ return isEOA ? bundlesIds.MORPHO_BLUE_EOA_BOOST : bundlesIds.MORPHO_BLUE_BOOST;
682
+ case 'repayOnPrice':
683
+ return isEOA ? bundlesIds.MORPHO_BLUE_EOA_REPAY_ON_PRICE : bundlesIds.MORPHO_BLUE_REPAY_ON_PRICE;
684
+ case 'boostOnPrice':
685
+ return isEOA ? bundlesIds.MORPHO_BLUE_EOA_BOOST_ON_PRICE : bundlesIds.MORPHO_BLUE_BOOST_ON_PRICE;
686
+ case 'close':
687
+ return isEOA ? bundlesIds.MORPHO_BLUE_EOA_CLOSE : bundlesIds.MORPHO_BLUE_CLOSE;
688
+ default:
689
+ throw new Error(`Unknown Morpho Blue strategy: ${strategy}`);
690
+ }
691
+ }
692
+
655
693
  export const morphoBlueEncode = {
656
694
  leverageManagement(
657
695
  marketId: string,
@@ -673,19 +711,10 @@ export const morphoBlueEncode = {
673
711
 
674
712
  // over is boost, under is repay
675
713
  const isBoost = ratioState === RatioState.OVER;
676
- let strategyOrBundleId;
677
-
678
- if (network === ChainId.Base) {
679
- return [isBoost ? Bundles.BaseIds.MORPHO_BLUE_BOOST : Bundles.BaseIds.MORPHO_BLUE_REPAY, true, triggerData, subData];
680
- }
681
-
682
- const bundlesIds = network === ChainId.Arbitrum ? Bundles.ArbitrumIds : Bundles.MainnetIds;
683
-
684
- if (isBoost) strategyOrBundleId = isEOA ? bundlesIds.MORPHO_BLUE_EOA_BOOST : bundlesIds.MORPHO_BLUE_BOOST;
685
- else strategyOrBundleId = isEOA ? bundlesIds.MORPHO_BLUE_EOA_REPAY : bundlesIds.MORPHO_BLUE_REPAY;
714
+ const bundleId = getMorphoBlueBundleId(network, isBoost ? 'boost' : 'repay', isEOA);
686
715
  const isBundle = true;
687
716
 
688
- return [strategyOrBundleId, isBundle, triggerData, subData];
717
+ return [bundleId, isBundle, triggerData, subData];
689
718
  },
690
719
  leverageManagementOnPrice(
691
720
  strategyOrBundleId: number,
@@ -704,6 +733,28 @@ export const morphoBlueEncode = {
704
733
  const triggerData = triggerService.morphoBluePriceTrigger.encode(oracle, collToken, loanToken, price, priceState);
705
734
  return [strategyOrBundleId, isBundle, triggerData, subData];
706
735
  },
736
+ leverageManagementOnPriceGeneric(
737
+ loanToken: EthereumAddress,
738
+ collToken: EthereumAddress,
739
+ oracle: EthereumAddress,
740
+ irm: EthereumAddress,
741
+ lltv: string,
742
+ user: EthereumAddress,
743
+ targetRatio: number,
744
+ price: number,
745
+ priceState: RatioState,
746
+ isBoost: boolean,
747
+ isEOA: boolean,
748
+ network: ChainId,
749
+ ) {
750
+ const subData = subDataService.morphoBlueLeverageManagementOnPriceSubData.encode(loanToken, collToken, oracle, irm, lltv, targetRatio, user);
751
+ const triggerData = triggerService.morphoBluePriceTrigger.encode(oracle, collToken, loanToken, price, priceState);
752
+
753
+ const bundleId = getMorphoBlueBundleId(network, isBoost ? 'boostOnPrice' : 'repayOnPrice', isEOA);
754
+ const isBundle = true;
755
+
756
+ return [bundleId, isBundle, triggerData, subData];
757
+ },
707
758
  closeOnPrice(
708
759
  strategyOrBundleId: number,
709
760
  loanToken: EthereumAddress,
@@ -725,6 +776,30 @@ export const morphoBlueEncode = {
725
776
 
726
777
  return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
727
778
  },
779
+ closeOnPriceGeneric(
780
+ loanToken: EthereumAddress,
781
+ collToken: EthereumAddress,
782
+ oracle: EthereumAddress,
783
+ irm: EthereumAddress,
784
+ lltv: string,
785
+ user: EthereumAddress,
786
+ stopLossPrice: number = 0,
787
+ stopLossType: CloseToAssetType = CloseToAssetType.DEBT,
788
+ takeProfitPrice: number = 0,
789
+ takeProfitType: CloseToAssetType = CloseToAssetType.COLLATERAL,
790
+ isEOA: boolean,
791
+ network: ChainId,
792
+ ) {
793
+ const isBundle = true;
794
+ const closeType = getCloseStrategyType(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
795
+
796
+ const subDataEncoded = subDataService.morphoBlueCloseOnPriceSubData.encode(loanToken, collToken, oracle, irm, lltv, user, closeType);
797
+ const triggerDataEncoded = triggerService.morphoBluePriceRangeTrigger.encode(oracle, collToken, loanToken, stopLossPrice, takeProfitPrice);
798
+
799
+ const bundleId = getMorphoBlueBundleId(network, 'close', isEOA);
800
+
801
+ return [bundleId, isBundle, triggerDataEncoded, subDataEncoded];
802
+ },
728
803
  };
729
804
 
730
805
  export const liquityV2Encode = {
@@ -241,6 +241,9 @@ export namespace Bundles {
241
241
  AAVE_V4_EOA_BOOST_ON_PRICE = 69,
242
242
  AAVE_V4_EOA_CLOSE = 70,
243
243
  MORPHO_BLUE_REPAY_ON_PRICE = 84,
244
+ MORPHO_BLUE_EOA_BOOST_ON_PRICE = 85,
245
+ MORPHO_BLUE_EOA_REPAY_ON_PRICE = 86,
246
+ MORPHO_BLUE_EOA_CLOSE = 87,
244
247
  }
245
248
 
246
249
  export enum OptimismIds {
@@ -286,6 +289,11 @@ export namespace Bundles {
286
289
  AAVE_V3_EOA_CLOSE = 27,
287
290
  MORPHO_BLUE_CLOSE = 28,
288
291
  MORPHO_BLUE_REPAY_ON_PRICE = 36,
292
+ MORPHO_BLUE_EOA_REPAY = 37,
293
+ MORPHO_BLUE_EOA_BOOST = 38,
294
+ MORPHO_BLUE_EOA_BOOST_ON_PRICE = 39,
295
+ MORPHO_BLUE_EOA_REPAY_ON_PRICE = 40,
296
+ MORPHO_BLUE_EOA_CLOSE = 41,
289
297
  }
290
298
 
291
299
  export enum ArbitrumIds {
@@ -319,6 +327,9 @@ export namespace Bundles {
319
327
  MORPHO_BLUE_EOA_BOOST = 27,
320
328
  MORPHO_BLUE_CLOSE = 28,
321
329
  MORPHO_BLUE_REPAY_ON_PRICE = 36,
330
+ MORPHO_BLUE_EOA_BOOST_ON_PRICE = 37,
331
+ MORPHO_BLUE_EOA_REPAY_ON_PRICE = 38,
332
+ MORPHO_BLUE_EOA_CLOSE = 39,
322
333
  }
323
334
  }
324
335