@defisaver/automation-sdk 3.3.14-strategies-refactor-dev → 3.3.15-liq-prot-dev

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.
@@ -164,6 +164,9 @@ export const makerLeverageManagementSubData = {
164
164
  return { vaultId, targetRatio };
165
165
  },
166
166
  };
167
+
168
+ // ! Any change here will PROBABLY require a change in makerLiquidationProtectionSubData as well, since it is copy paste
169
+ // ! Double check before changing
167
170
  export const makerLeverageManagementWithoutSubProxy = {
168
171
  encode(
169
172
  vaultId: number,
@@ -184,6 +187,28 @@ export const makerLeverageManagementWithoutSubProxy = {
184
187
  },
185
188
  };
186
189
 
190
+ export const makerLiquidationProtectionSubData = {
191
+ encode(
192
+ vaultId: number,
193
+ targetRatio: number,
194
+ daiAddr?: EthereumAddress,
195
+ ): SubData {
196
+ const encodedVaultId = AbiCoder.encodeParameter('uint256', vaultId);
197
+ const encodedTargetRatio = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
198
+ const encodedDaiAddr = AbiCoder.encodeParameter('address', daiAddr || getAssetInfo('DAI', 1).address);
199
+
200
+ return [encodedVaultId, encodedTargetRatio, encodedDaiAddr];
201
+ },
202
+ decode(subData: SubData): { vaultId: number, targetRatio: number, daiAddr: string } {
203
+ const vaultId = +AbiCoder.decodeParameter('uint256', subData[0])!.toString();
204
+ const targetRatio = weiToRatioPercentage(AbiCoder.decodeParameter('uint256', subData[1]) as any as string);
205
+ const daiAddr = AbiCoder.decodeParameter('address', subData[2])!.toString();
206
+
207
+ return { vaultId, targetRatio, daiAddr };
208
+ },
209
+ };
210
+
211
+
187
212
  /**
188
213
  __ __ ______ __ __ __ .___________.____ ____ ____ ____ __
189
214
  | | | | / __ \ | | | | | | | |\ \ / / \ \ / / /_ |
@@ -578,6 +603,9 @@ export const aaveV3LeverageManagementSubData = {
578
603
  return { targetRatio };
579
604
  },
580
605
  };
606
+
607
+ // ! Any change here will PROBABLY require a change in aaveV3LiquidationProtectionSubData as well
608
+ // ! Double check before changing. Liquidation protection is using Generic encoding for both - EOA and SW
581
609
  export const aaveV3LeverageManagementSubDataWithoutSubProxy = {
582
610
  encode(
583
611
  targetRatio: number,
@@ -605,6 +633,30 @@ export const aaveV3LeverageManagementSubDataWithoutSubProxy = {
605
633
  return { targetRatio, ratioState };
606
634
  },
607
635
  };
636
+
637
+ export const aaveV3LiquidationProtectionSubData = {
638
+ encode(
639
+ targetRatio: number,
640
+ ratioState: RatioState,
641
+ market: EthereumAddress,
642
+ user: EthereumAddress,
643
+ ): SubData {
644
+ const encodedTargetRatio = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
645
+ const encodedRatioState = AbiCoder.encodeParameter('uint8', ratioState);
646
+ const encodedMarket = AbiCoder.encodeParameter('address', market);
647
+ const encodedUser = AbiCoder.encodeParameter('address', user);
648
+
649
+ return [encodedTargetRatio, encodedRatioState, encodedMarket, encodedUser];
650
+ },
651
+ decode(subData: SubData): { targetRatio: number, ratioState: RatioState } {
652
+ const targetRatio = weiToRatioPercentage(AbiCoder.decodeParameter('uint256', subData[0]) as any as string);
653
+ const ratioState = AbiCoder.decodeParameter('uint8', subData[1]) as any as RatioState;
654
+
655
+ return { targetRatio, ratioState };
656
+ },
657
+ };
658
+
659
+
608
660
  export const aaveV3LeverageManagementOnPriceGeneric = {
609
661
  encode(
610
662
  collAsset: EthereumAddress,
@@ -851,6 +903,9 @@ export const aaveV3LeverageManagementOnPriceSubData = {
851
903
  / _____ \ / _____ \ \ / | |____ \ / | |
852
904
  /__/ \__\ /__/ \__\ \__/ |_______| \__/ |_|
853
905
  */
906
+
907
+ // ! Any change here will PROBABLY require a change in aaveV4LiquidationProtectionSubData as well, since it is copy paste
908
+ // ! Double check before changing
854
909
  export const aaveV4LeverageManagementSubData = {
855
910
  encode: (
856
911
  spoke: EthereumAddress,
@@ -882,6 +937,39 @@ export const aaveV4LeverageManagementSubData = {
882
937
  };
883
938
  },
884
939
  };
940
+
941
+ export const aaveV4LiquidationProtectionSubData = {
942
+ encode: (
943
+ spoke: EthereumAddress,
944
+ owner: EthereumAddress,
945
+ ratioState: RatioState,
946
+ targetRatio: number,
947
+ ) => {
948
+ const spokeEncoded = AbiCoder.encodeParameter('address', spoke);
949
+ const ownerEncoded = AbiCoder.encodeParameter('address', owner);
950
+ const ratioStateEncoded = AbiCoder.encodeParameter('uint8', ratioState);
951
+ const targetRatioEncoded = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
952
+ // Add two empty slots for future addons (e.g tsi or slippage settings)
953
+ return [
954
+ spokeEncoded,
955
+ ownerEncoded,
956
+ ratioStateEncoded,
957
+ targetRatioEncoded,
958
+ EMPTY_SLOT,
959
+ EMPTY_SLOT,
960
+ ];
961
+ },
962
+ decode: (subData: SubData) => {
963
+ const spoke = AbiCoder.decodeParameter('address', subData[0]) as unknown as EthereumAddress;
964
+ const owner = AbiCoder.decodeParameter('address', subData[1]) as unknown as EthereumAddress;
965
+ const ratioState = Number(AbiCoder.decodeParameter('uint8', subData[2])) as RatioState;
966
+ const targetRatio = weiToRatioPercentage(AbiCoder.decodeParameter('uint256', subData[3]) as any as string);
967
+ return {
968
+ spoke, owner, ratioState, targetRatio,
969
+ };
970
+ },
971
+ };
972
+
885
973
  export const aaveV4LeverageManagementOnPriceSubData = {
886
974
  encode: (
887
975
  spoke: EthereumAddress,
@@ -1081,6 +1169,9 @@ export const compoundV2LeverageManagementSubDataWithoutSubProxy = {
1081
1169
  | `----.| `--' | | | | | | | \ / ___) |
1082
1170
  \______| \______/ |__| |__| | _| \__/ |____/
1083
1171
  */
1172
+
1173
+ // ! Any change here will PROBABLY require a change in compoundV3LiquidationProtectionSubData as well, since it is copy paste
1174
+ // ! Double check before changing
1084
1175
  export const compoundV3LeverageManagementSubData = {
1085
1176
  encode(
1086
1177
  market: EthereumAddress,
@@ -1110,6 +1201,9 @@ export const compoundV3LeverageManagementSubData = {
1110
1201
  return { targetRatio };
1111
1202
  },
1112
1203
  };
1204
+
1205
+ // ! Any change here will PROBABLY require a change in compoundV3L2LiquidationProtectionSubData as well, since it is copy paste
1206
+ // ! Double check before changing
1113
1207
  export const compoundV3LeverageManagementSubDataWithoutSubProxy = {
1114
1208
  encode(
1115
1209
  market: EthereumAddress,
@@ -1134,6 +1228,74 @@ export const compoundV3LeverageManagementSubDataWithoutSubProxy = {
1134
1228
  };
1135
1229
  },
1136
1230
  };
1231
+
1232
+ export const compoundV3LiquidationProtectionSubData = {
1233
+ encode(
1234
+ market: EthereumAddress,
1235
+ baseToken: EthereumAddress,
1236
+ triggerRepayRatio: number,
1237
+ // TODO -> can remove boost stuff ? Not sure if want it to be compatible or not.
1238
+ triggerBoostRatio: number,
1239
+ targetBoostRatio: number,
1240
+ targetRepayRatio: number,
1241
+ boostEnabled: boolean,
1242
+ isEOA: boolean,
1243
+ ): SubData {
1244
+ return [
1245
+ market,
1246
+ baseToken,
1247
+ new Dec(triggerRepayRatio).mul(1e16).toString(),
1248
+ new Dec(triggerBoostRatio).mul(1e16).toString(),
1249
+ new Dec(targetBoostRatio).mul(1e16).toString(),
1250
+ new Dec(targetRepayRatio).mul(1e16).toString(),
1251
+ // @ts-ignore // TODO
1252
+ boostEnabled, isEOA,
1253
+ ];
1254
+ },
1255
+ decode(subData: SubData): { targetRatio: number } {
1256
+ const weiRatio = AbiCoder.decodeParameter('uint256', subData[3]) as any as string;
1257
+ const targetRatio = weiToRatioPercentage(weiRatio);
1258
+
1259
+ return { targetRatio };
1260
+ },
1261
+ };
1262
+ export const compoundV3L2LiquidationProtectionSubData = {
1263
+ encode(
1264
+ market: EthereumAddress,
1265
+ baseToken: EthereumAddress,
1266
+ triggerRepayRatio: number,
1267
+ // TODO -> can remove boost stuff ? Not sure if want it to be compatible or not.
1268
+ triggerBoostRatio: number,
1269
+ targetBoostRatio: number,
1270
+ targetRepayRatio: number,
1271
+ boostEnabled: boolean,
1272
+ isEOA: boolean,
1273
+ ): string {
1274
+ let subInput = '0x';
1275
+
1276
+ subInput = subInput.concat(market.slice(2));
1277
+ subInput = subInput.concat(baseToken.slice(2));
1278
+ subInput = subInput.concat(new Dec(triggerRepayRatio).mul(1e16).toHex().slice(2)
1279
+ .padStart(32, '0'));
1280
+ subInput = subInput.concat(new Dec(triggerBoostRatio).mul(1e16).toHex().slice(2)
1281
+ .padStart(32, '0'));
1282
+ subInput = subInput.concat(new Dec(targetBoostRatio).mul(1e16).toHex().slice(2)
1283
+ .padStart(32, '0'));
1284
+ subInput = subInput.concat(new Dec(targetRepayRatio).mul(1e16).toHex().slice(2)
1285
+ .padStart(32, '0'));
1286
+ subInput = subInput.concat(boostEnabled ? '01' : '00');
1287
+ subInput = subInput.concat(isEOA ? '01' : '00');
1288
+
1289
+ return subInput;
1290
+ },
1291
+ decode(subData: SubData): { targetRatio: number } {
1292
+ const ratioWei = AbiCoder.decodeParameter('uint256', subData[3]) as any as string;
1293
+ const targetRatio = weiToRatioPercentage(ratioWei);
1294
+
1295
+ return { targetRatio };
1296
+ },
1297
+ };
1298
+
1137
1299
  export const compoundV3LeverageManagementOnPriceSubData = {
1138
1300
  encode(
1139
1301
  market: EthereumAddress,
@@ -1301,6 +1463,9 @@ export const sparkLeverageManagementSubData = {
1301
1463
  return { targetRatio };
1302
1464
  },
1303
1465
  };
1466
+
1467
+ // ! Any change here will PROBABLY require a change in sparkLiquidationProtectionSubData as well, since it is copy paste
1468
+ // ! Double check before changing
1304
1469
  export const sparkLeverageManagementSubDataWithoutSubProxy = {
1305
1470
  encode(
1306
1471
  targetRatio: number,
@@ -1320,6 +1485,28 @@ export const sparkLeverageManagementSubDataWithoutSubProxy = {
1320
1485
  return { targetRatio, ratioState };
1321
1486
  },
1322
1487
  };
1488
+
1489
+ export const sparkLiquidationProtectionSubData = {
1490
+ encode(
1491
+ targetRatio: number,
1492
+ ratioState: RatioState,
1493
+ ): SubData {
1494
+ const encodedTargetRatio = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
1495
+ const encodedRatioState = AbiCoder.encodeParameter('uint8', ratioState);
1496
+ const encodedUseDefaultMarket = AbiCoder.encodeParameter('bool', true);
1497
+ const encodedUseOnBehalf = AbiCoder.encodeParameter('bool', false);
1498
+
1499
+ return [encodedTargetRatio, encodedRatioState, encodedUseDefaultMarket, encodedUseOnBehalf];
1500
+ },
1501
+ decode(subData: SubData): { targetRatio: number, ratioState: RatioState } {
1502
+ const targetRatio = weiToRatioPercentage(AbiCoder.decodeParameter('uint256', subData[0]) as any as string);
1503
+ const ratioState = AbiCoder.decodeParameter('uint8', subData[1]) as any as RatioState;
1504
+
1505
+ return { targetRatio, ratioState };
1506
+ },
1507
+ };
1508
+
1509
+
1323
1510
  export const sparkCloseGenericSubData = {
1324
1511
  encode(
1325
1512
  collAsset: EthereumAddress,
@@ -1534,6 +1721,9 @@ export const crvUSDPaybackSubData = {
1534
1721
  | | | | | `--' | | |\ \----.| | | | | | | `--' |
1535
1722
  |__| |__| \______/ | _| `._____|| _| |__| |__| \______/
1536
1723
  */
1724
+
1725
+ // ! Any change here will PROBABLY require a change in morphoBlueLiquidationProtectionSubData as well, since it is copy paste
1726
+ // ! Double check before changing
1537
1727
  export const morphoBlueLeverageManagementSubData = {
1538
1728
  encode: (
1539
1729
  loanToken: EthereumAddress,
@@ -1578,6 +1768,53 @@ export const morphoBlueLeverageManagementSubData = {
1578
1768
  };
1579
1769
  },
1580
1770
  };
1771
+
1772
+ export const morphoBlueLiquidationProtectionSubData = {
1773
+ encode: (
1774
+ loanToken: EthereumAddress,
1775
+ collToken: EthereumAddress,
1776
+ oracle: EthereumAddress,
1777
+ irm: EthereumAddress,
1778
+ lltv: string,
1779
+ ratioState: RatioState,
1780
+ targetRatio: number,
1781
+ user: EthereumAddress,
1782
+ isEOA: boolean,
1783
+ ) => {
1784
+ const loanTokenEncoded = AbiCoder.encodeParameter('address', loanToken);
1785
+ const collTokenEncoded = AbiCoder.encodeParameter('address', collToken);
1786
+ const oracleEncoded = AbiCoder.encodeParameter('address', oracle);
1787
+ const irmEncoded = AbiCoder.encodeParameter('address', irm);
1788
+ const lltvEncoded = AbiCoder.encodeParameter('uint256', lltv);
1789
+ const ratioStateEncoded = AbiCoder.encodeParameter('uint8', ratioState);
1790
+ const targetRatioEncoded = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
1791
+ const userEncoded = AbiCoder.encodeParameter('address', user);
1792
+ const isEOAEncoded = AbiCoder.encodeParameter('bool', isEOA);
1793
+ return [loanTokenEncoded, collTokenEncoded, oracleEncoded, irmEncoded, lltvEncoded, ratioStateEncoded, targetRatioEncoded, userEncoded, isEOAEncoded];
1794
+ },
1795
+ decode: (subData: SubData) => {
1796
+ const loanToken = AbiCoder.decodeParameter('address', subData[0]) as unknown as EthereumAddress;
1797
+ const collToken = AbiCoder.decodeParameter('address', subData[1]) as any as EthereumAddress;
1798
+ const oracle = AbiCoder.decodeParameter('address', subData[2]) as any as EthereumAddress;
1799
+ const irm = AbiCoder.decodeParameter('address', subData[3]) as any as EthereumAddress;
1800
+ const lltv = AbiCoder.decodeParameter('uint256', subData[4]) as any as EthereumAddress;
1801
+ const weiRatio = AbiCoder.decodeParameter('uint256', subData[6]) as any as EthereumAddress;
1802
+ const user = AbiCoder.decodeParameter('address', subData[7]) as any as EthereumAddress;
1803
+ const targetRatio = weiToRatioPercentage(weiRatio);
1804
+
1805
+ return {
1806
+ loanToken,
1807
+ collToken,
1808
+ oracle,
1809
+ irm,
1810
+ lltv,
1811
+ user,
1812
+ targetRatio,
1813
+ };
1814
+ },
1815
+ };
1816
+
1817
+
1581
1818
  export const morphoBlueLeverageManagementOnPriceSubData = {
1582
1819
  encode(
1583
1820
  loanToken: EthereumAddress,
@@ -1666,6 +1903,8 @@ _______ __ __ __ __ _______
1666
1903
  | | | `----.| `--' | | | | '--' |
1667
1904
  |__| |_______| \______/ |__| |_______/
1668
1905
  */
1906
+ // ! Any change here will PROBABLY require a change in fluidLeverageManagementSubData as well, since it is copy paste
1907
+ // ! Double check before changing
1669
1908
  export const fluidLeverageManagementSubData = {
1670
1909
  encode: (
1671
1910
  nftId: string,
@@ -1679,9 +1918,50 @@ export const fluidLeverageManagementSubData = {
1679
1918
  const targetRatioEncoded = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
1680
1919
  const wrapEthEncoded = AbiCoder.encodeParameter('bool', true);
1681
1920
 
1682
- const isRepay = ratioState === RatioState.UNDER;
1683
- const collActionType = isRepay ? CollActionType.WITHDRAW : CollActionType.SUPPLY;
1684
- const debtActionType = isRepay ? DebtActionType.PAYBACK : DebtActionType.BORROW;
1921
+ const collActionType = CollActionType.WITHDRAW;
1922
+ const debtActionType = DebtActionType.PAYBACK;
1923
+
1924
+ const collActionTypeEncoded = AbiCoder.encodeParameter('uint8', collActionType);
1925
+ const debtActionTypeEncoded = AbiCoder.encodeParameter('uint8', debtActionType);
1926
+
1927
+ return [
1928
+ nftIdEncoded,
1929
+ vaultEncoded,
1930
+ ratioStateEncoded,
1931
+ targetRatioEncoded,
1932
+ wrapEthEncoded,
1933
+ collActionTypeEncoded,
1934
+ debtActionTypeEncoded,
1935
+ ];
1936
+ },
1937
+ decode: (subData: SubData) => {
1938
+ const nftId = AbiCoder.decodeParameter('uint256', subData[0]) as any as string;
1939
+ const vault = AbiCoder.decodeParameter('address', subData[1]) as unknown as EthereumAddress;
1940
+ const ratioState = AbiCoder.decodeParameter('uint8', subData[2]) as any as RatioState;
1941
+ const weiRatio = AbiCoder.decodeParameter('uint256', subData[3]) as any as string;
1942
+ const targetRatio = weiToRatioPercentage(weiRatio);
1943
+
1944
+ return {
1945
+ nftId, vault, ratioState, targetRatio,
1946
+ };
1947
+ },
1948
+ };
1949
+
1950
+ export const fluidLiquidationProtectionSubData = {
1951
+ encode: (
1952
+ nftId: string,
1953
+ vault: EthereumAddress,
1954
+ ratioState: RatioState,
1955
+ targetRatio: number,
1956
+ ) => {
1957
+ const nftIdEncoded = AbiCoder.encodeParameter('uint256', nftId);
1958
+ const vaultEncoded = AbiCoder.encodeParameter('address', vault);
1959
+ const ratioStateEncoded = AbiCoder.encodeParameter('uint8', ratioState);
1960
+ const targetRatioEncoded = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
1961
+ const wrapEthEncoded = AbiCoder.encodeParameter('bool', true);
1962
+
1963
+ const collActionType = CollActionType.WITHDRAW;
1964
+ const debtActionType = DebtActionType.PAYBACK;
1685
1965
 
1686
1966
  const collActionTypeEncoded = AbiCoder.encodeParameter('uint8', collActionType);
1687
1967
  const debtActionTypeEncoded = AbiCoder.encodeParameter('uint8', debtActionType);
@@ -2,7 +2,7 @@ import { expect } from 'chai';
2
2
  import { getAssetInfo } from '@defisaver/tokens';
3
3
 
4
4
  import type { EthereumAddress } from '../types';
5
- import { ChainId, ProtocolIdentifiers, RatioState } from '../types/enums';
5
+ import { Bundles, ChainId, ProtocolIdentifiers, RatioState } from '../types/enums';
6
6
 
7
7
  import '../configuration';
8
8
  import {
@@ -11,6 +11,7 @@ import {
11
11
  compareAddresses,
12
12
  encodeSubId,
13
13
  ethToWeth,
14
+ getCompoundV3LeverageManagementBundleId,
14
15
  getRatioStateInfoForAaveCloseStrategy,
15
16
  isAddress,
16
17
  isDefined,
@@ -369,4 +370,34 @@ describe('Feature: utils.ts', () => {
369
370
  });
370
371
  });
371
372
  });
373
+
374
+ describe('When testing utils.getCompoundV3LeverageManagementBundleId()', () => {
375
+ // Mainnet uses the V2 bundle ids; L2s use the original bundle ids.
376
+ const examples: Array<[number, [network: ChainId, isEOA: boolean, isBoost: boolean]]> = [
377
+ [Bundles.MainnetIds.COMP_V3_SW_REPAY_V2_BUNDLE, [ChainId.Ethereum, false, false]],
378
+ [Bundles.MainnetIds.COMP_V3_SW_BOOST_V2_BUNDLE, [ChainId.Ethereum, false, true]],
379
+ [Bundles.MainnetIds.COMP_V3_EOA_REPAY_V2_BUNDLE, [ChainId.Ethereum, true, false]],
380
+ [Bundles.MainnetIds.COMP_V3_EOA_BOOST_V2_BUNDLE, [ChainId.Ethereum, true, true]],
381
+
382
+ [Bundles.BaseIds.COMP_V3_SW_REPAY_BUNDLE, [ChainId.Base, false, false]],
383
+ [Bundles.BaseIds.COMP_V3_SW_BOOST_BUNDLE, [ChainId.Base, false, true]],
384
+ [Bundles.BaseIds.COMP_V3_EOA_REPAY, [ChainId.Base, true, false]],
385
+ [Bundles.BaseIds.COMP_V3_EOA_BOOST, [ChainId.Base, true, true]],
386
+
387
+ [Bundles.ArbitrumIds.COMP_V3_SW_REPAY_BUNDLE, [ChainId.Arbitrum, false, false]],
388
+ [Bundles.ArbitrumIds.COMP_V3_SW_BOOST_BUNDLE, [ChainId.Arbitrum, false, true]],
389
+ [Bundles.ArbitrumIds.COMP_V3_EOA_REPAY, [ChainId.Arbitrum, true, false]],
390
+ [Bundles.ArbitrumIds.COMP_V3_EOA_BOOST, [ChainId.Arbitrum, true, true]],
391
+ ];
392
+
393
+ examples.forEach(([expected, actual]) => {
394
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
395
+ expect(getCompoundV3LeverageManagementBundleId(...actual)).to.equal(expected);
396
+ });
397
+ });
398
+
399
+ it(`Given ${ChainId.Optimism} (unsupported) should throw an error`, () => {
400
+ expect(() => getCompoundV3LeverageManagementBundleId(ChainId.Optimism, false, false)).to.throw(Error);
401
+ });
402
+ });
372
403
  });
@@ -5,6 +5,7 @@ import { getAssetInfo, getAssetInfoByAddress } from '@defisaver/tokens';
5
5
 
6
6
  import type { EthereumAddress } from '../types';
7
7
  import {
8
+ Bundles,
8
9
  ChainId, CloseStrategyType, CloseToAssetType, RatioState,
9
10
  } from '../types/enums';
10
11
 
@@ -171,4 +172,34 @@ export function getStopLossAndTakeProfitTypeByCloseStrategyType(
171
172
  default:
172
173
  throw new Error('CloseStrategyType not supported');
173
174
  }
174
- }
175
+ }
176
+
177
+ export function getBundleIdsByNetwork(network: ChainId) {
178
+ switch (network) {
179
+ case ChainId.Arbitrum:
180
+ return Bundles.ArbitrumIds;
181
+ case ChainId.Base:
182
+ return Bundles.BaseIds;
183
+ case ChainId.Optimism:
184
+ return Bundles.OptimismIds;
185
+ default:
186
+ return Bundles.MainnetIds;
187
+ }
188
+ }
189
+
190
+ // Mainnet uses the V2 bundle ids; L2s use the original bundle ids.
191
+ export function getCompoundV3LeverageManagementBundleId(network: ChainId, isEOA: boolean, isBoost: boolean): number {
192
+ switch (Number(network)) {
193
+ case ChainId.Ethereum:
194
+ if (isEOA) return isBoost ? Bundles.MainnetIds.COMP_V3_EOA_BOOST_V2_BUNDLE : Bundles.MainnetIds.COMP_V3_EOA_REPAY_V2_BUNDLE;
195
+ return isBoost ? Bundles.MainnetIds.COMP_V3_SW_BOOST_V2_BUNDLE : Bundles.MainnetIds.COMP_V3_SW_REPAY_V2_BUNDLE;
196
+ case ChainId.Base:
197
+ if (isEOA) return isBoost ? Bundles.BaseIds.COMP_V3_EOA_BOOST : Bundles.BaseIds.COMP_V3_EOA_REPAY;
198
+ return isBoost ? Bundles.BaseIds.COMP_V3_SW_BOOST_BUNDLE : Bundles.BaseIds.COMP_V3_SW_REPAY_BUNDLE;
199
+ case ChainId.Arbitrum:
200
+ if (isEOA) return isBoost ? Bundles.ArbitrumIds.COMP_V3_EOA_BOOST : Bundles.ArbitrumIds.COMP_V3_EOA_REPAY;
201
+ return isBoost ? Bundles.ArbitrumIds.COMP_V3_SW_BOOST_BUNDLE : Bundles.ArbitrumIds.COMP_V3_SW_REPAY_BUNDLE;
202
+ default:
203
+ throw new Error(`Compound V3 leverage management is not supported on network ${network}`);
204
+ }
205
+ }
@@ -153,6 +153,8 @@ export namespace Strategies {
153
153
  EoaRepayOnPrice = 'eoa-repay-on-price',
154
154
  CollateralSwitch = 'collateral-switch',
155
155
  EoaCollateralSwitch = 'eoa-collateral-switch',
156
+ LiquidationProtection = 'liquidation-protection',
157
+ EoaLiquidationProtection = 'eoa-liquidation-protection',
156
158
  }
157
159
  export enum IdOverrides {
158
160
  TakeProfit = 'take-profit',
@@ -164,6 +166,8 @@ export namespace Strategies {
164
166
  EoaLeverageManagement = 'leverage-management-eoa',
165
167
  LeverageManagementOnPrice = 'leverage-management-on-price',
166
168
  EoaLeverageManagementOnPrice = 'leverage-management-on-price-eoa',
169
+ LiquidationProtection = 'liquidation-protection',
170
+ EoaLiquidationProtection = 'liquidation-protection-eoa',
167
171
  }
168
172
  }
169
173
 
@@ -240,6 +244,14 @@ export namespace Bundles {
240
244
  AAVE_V4_EOA_REPAY_ON_PRICE = 68,
241
245
  AAVE_V4_EOA_BOOST_ON_PRICE = 69,
242
246
  AAVE_V4_EOA_CLOSE = 70,
247
+ AAVE_V3_LIQUIDATION_PROTECTION = 71,
248
+ SPARK_LIQUIDATION_PROTECTION = 72,
249
+ COMP_V3_SW_LIQUIDATION_PROTECTION = 73,
250
+ COMP_V3_EOA_LIQUIDATION_PROTECTION = 74,
251
+ MAKER_LIQUIDATION_PROTECTION = 75,
252
+ FLUID_T1_LIQUIDATION_PROTECTION = 76,
253
+ AAVE_V4_LIQUIDATION_PROTECTION = 77,
254
+ MORPHO_BLUE_LIQUIDATION_PROTECTION = 78,
243
255
  }
244
256
 
245
257
  export enum OptimismIds {
@@ -254,6 +266,7 @@ export namespace Bundles {
254
266
  AAVE_V3_EOA_REPAY_ON_PRICE = 8,
255
267
  AAVE_V3_EOA_BOOST_ON_PRICE = 9,
256
268
  AAVE_V3_EOA_CLOSE = 10,
269
+ AAVE_V3_LIQUIDATION_PROTECTION = 11,
257
270
  }
258
271
 
259
272
  export enum BaseIds {
@@ -284,6 +297,11 @@ export namespace Bundles {
284
297
  AAVE_V3_EOA_BOOST_ON_PRICE = 26,
285
298
  AAVE_V3_EOA_CLOSE = 27,
286
299
  MORPHO_BLUE_CLOSE = 28,
300
+ AAVE_V3_LIQUIDATION_PROTECTION = 29,
301
+ FLUID_T1_LIQUIDATION_PROTECTION = 30,
302
+ MORPHO_BLUE_LIQUIDATION_PROTECTION = 31,
303
+ COMP_V3_SW_LIQUIDATION_PROTECTION = 32,
304
+ COMP_V3_EOA_LIQUIDATION_PROTECTION = 33,
287
305
  }
288
306
 
289
307
  export enum ArbitrumIds {
@@ -316,6 +334,11 @@ export namespace Bundles {
316
334
  MORPHO_BLUE_EOA_REPAY = 26,
317
335
  MORPHO_BLUE_EOA_BOOST = 27,
318
336
  MORPHO_BLUE_CLOSE = 28,
337
+ AAVE_V3_LIQUIDATION_PROTECTION = 29,
338
+ FLUID_T1_LIQUIDATION_PROTECTION = 30,
339
+ MORPHO_BLUE_LIQUIDATION_PROTECTION = 31,
340
+ COMP_V3_SW_LIQUIDATION_PROTECTION = 32,
341
+ COMP_V3_EOA_LIQUIDATION_PROTECTION = 33,
319
342
  }
320
343
  }
321
344