@defisaver/automation-sdk 3.3.12-strategies-refactor-5-dev → 3.3.13-strategies-refactor-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.
@@ -117,6 +117,11 @@ exports.MAINNET_STRATEGIES_INFO = {
117
117
  strategyId: enums_1.Strategies.Identifiers.EoaCollateralSwitch,
118
118
  protocol: exports.PROTOCOLS.AaveV4,
119
119
  },
120
+ [enums_1.Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH]: {
121
+ strategyOrBundleId: enums_1.Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
122
+ strategyId: enums_1.Strategies.Identifiers.CollateralSwitch,
123
+ protocol: exports.PROTOCOLS.Spark,
124
+ },
120
125
  };
121
126
  exports.OPTIMISM_STRATEGIES_INFO = {
122
127
  [enums_1.Strategies.OptimismIds.EXCHANGE_DCA]: {
@@ -318,6 +318,16 @@ function parseAaveV3CollateralSwitch(position, parseData) {
318
318
  _position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, subData.marketAddr);
319
319
  return _position;
320
320
  }
321
+ function parseSparkCollateralSwitch(position, parseData) {
322
+ const _position = (0, lodash_1.cloneDeep)(position);
323
+ const { subStruct } = parseData.subscriptionEventData;
324
+ const triggerData = triggerService.sparkQuotePriceTrigger.decode(subStruct.triggerData);
325
+ const subData = subDataService.sparkCollateralSwitchSubData.decode(subStruct.subData);
326
+ _position.strategyData.decoded.triggerData = triggerData;
327
+ _position.strategyData.decoded.subData = subData;
328
+ _position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, subData.marketAddr);
329
+ return _position;
330
+ }
321
331
  function parseAaveV4LeverageManagement(position, parseData) {
322
332
  const _position = (0, lodash_1.cloneDeep)(position);
323
333
  const { subStruct, subId, subHash } = parseData.subscriptionEventData;
@@ -1116,6 +1126,7 @@ const parsingMethodsMapping = {
1116
1126
  [enums_1.Strategies.Identifiers.RepayOnPrice]: parseSparkLeverageManagementOnPrice,
1117
1127
  [enums_1.Strategies.Identifiers.BoostOnPrice]: parseSparkLeverageManagementOnPrice,
1118
1128
  [enums_1.Strategies.Identifiers.CloseOnPrice]: parseSparkCloseOnPrice,
1129
+ [enums_1.Strategies.Identifiers.CollateralSwitch]: parseSparkCollateralSwitch,
1119
1130
  },
1120
1131
  [enums_1.ProtocolIdentifiers.StrategiesAutomation.CrvUSD]: {
1121
1132
  [enums_1.Strategies.Identifiers.Repay]: parseCrvUSDLeverageManagement,
@@ -95,6 +95,7 @@ export declare const sparkEncode: {
95
95
  }): (number | boolean | string[])[];
96
96
  closeOnPriceGeneric(strategyOrBundleId: number, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, marketAddr: EthereumAddress, user: EthereumAddress, stopLossPrice?: number, stopLossType?: CloseToAssetType, takeProfitPrice?: number, takeProfitType?: CloseToAssetType): (number | boolean | string[])[];
97
97
  leverageManagementWithoutSubProxy(strategyOrBundleId: number, market: EthereumAddress, user: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number): (number | boolean | string[])[];
98
+ collateralSwitch(strategyOrBundleId: number, fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, marketAddr: EthereumAddress, amountToSwitch: string, baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: number, state: RatioState): (number | boolean | string[])[];
98
99
  };
99
100
  export declare const crvUSDEncode: {
100
101
  leverageManagement(owner: EthereumAddress, controllerAddr: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number, collTokenAddr: EthereumAddress, crvUSDAddr: EthereumAddress): (boolean | string[] | Bundles.MainnetIds)[];
@@ -257,6 +257,12 @@ exports.sparkEncode = {
257
257
  const triggerData = triggerService.sparkRatioTrigger.encode(user, market, triggerRatio, ratioState);
258
258
  return [strategyOrBundleId, isBundle, triggerData, subData];
259
259
  },
260
+ collateralSwitch(strategyOrBundleId, fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, baseTokenAddress, quoteTokenAddress, price, state) {
261
+ const isBundle = false;
262
+ const subDataEncoded = subDataService.sparkCollateralSwitchSubData.encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch);
263
+ const triggerDataEncoded = triggerService.sparkQuotePriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, state);
264
+ return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
265
+ },
260
266
  };
261
267
  exports.crvUSDEncode = {
262
268
  leverageManagement(owner, controllerAddr, ratioState, targetRatio, triggerRatio, collTokenAddr, crvUSDAddr) {
@@ -1379,6 +1379,105 @@ describe('Feature: strategySubService.ts', () => {
1379
1379
  });
1380
1380
  });
1381
1381
  });
1382
+ describe('collateralSwitch()', () => {
1383
+ const examples = [
1384
+ // WETH -> cbBTC, price 0.025 WETH/cbBTC, state UNDER
1385
+ [
1386
+ [
1387
+ enums_1.Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
1388
+ false,
1389
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf00000000000000000000000000000000000000000000000000000000002625a00000000000000000000000000000000000000000000000000000000000000001'],
1390
+ [
1391
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1392
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1393
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
1394
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
1395
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
1396
+ '0x0000000000000000000000000000000000000000000000008ac7230489e80000',
1397
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1398
+ ],
1399
+ ],
1400
+ [
1401
+ enums_1.Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
1402
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
1403
+ 0,
1404
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('cbBTC', enums_1.ChainId.Ethereum).address),
1405
+ 7,
1406
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
1407
+ '10000000000000000000',
1408
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
1409
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('cbBTC', enums_1.ChainId.Ethereum).address),
1410
+ 0.025,
1411
+ enums_1.RatioState.UNDER,
1412
+ ]
1413
+ ],
1414
+ // cbBTC -> WETH, price 25 cbBTC/WETH, state UNDER
1415
+ [
1416
+ [
1417
+ enums_1.Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
1418
+ false,
1419
+ ['0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000009502f9000000000000000000000000000000000000000000000000000000000000000001'],
1420
+ [
1421
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
1422
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
1423
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1424
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1425
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
1426
+ '0x0000000000000000000000000000000000000000000000000000000005f5e100',
1427
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1428
+ ],
1429
+ ],
1430
+ [
1431
+ enums_1.Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
1432
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('cbBTC', enums_1.ChainId.Ethereum).address),
1433
+ 7,
1434
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
1435
+ 0,
1436
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
1437
+ '100000000',
1438
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('cbBTC', enums_1.ChainId.Ethereum).address),
1439
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
1440
+ 25,
1441
+ enums_1.RatioState.UNDER,
1442
+ ]
1443
+ ],
1444
+ // cbBTC -> WETH, price 40 cbBTC/WETH, state OVER
1445
+ [
1446
+ [
1447
+ enums_1.Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
1448
+ false,
1449
+ ['0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000ee6b28000000000000000000000000000000000000000000000000000000000000000000'],
1450
+ [
1451
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
1452
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
1453
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1454
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1455
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
1456
+ '0x0000000000000000000000000000000000000000000000000000000005f5e100',
1457
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1458
+ ],
1459
+ ],
1460
+ [
1461
+ enums_1.Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
1462
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('cbBTC', enums_1.ChainId.Ethereum).address),
1463
+ 7,
1464
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
1465
+ 0,
1466
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
1467
+ '100000000',
1468
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('cbBTC', enums_1.ChainId.Ethereum).address),
1469
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
1470
+ 40,
1471
+ enums_1.RatioState.OVER,
1472
+ ]
1473
+ ],
1474
+ ];
1475
+ examples.forEach(([expected, actual]) => {
1476
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1477
+ (0, chai_1.expect)(strategySubService_1.sparkEncode.collateralSwitch(...actual)).to.eql(expected);
1478
+ });
1479
+ });
1480
+ });
1382
1481
  });
1383
1482
  describe('When testing strategySubService.aaveV4Encode', () => {
1384
1483
  describe('leverageManagement()', () => {
@@ -462,6 +462,17 @@ export declare const sparkLeverageManagementOnPriceSubData: {
462
462
  targetRatio: number;
463
463
  };
464
464
  };
465
+ export declare const sparkCollateralSwitchSubData: {
466
+ encode(fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, marketAddr: EthereumAddress, amountToSwitch: string, useOnBehalf?: boolean): string[];
467
+ decode(subData: string[]): {
468
+ fromAsset: EthereumAddress;
469
+ fromAssetId: number;
470
+ toAsset: EthereumAddress;
471
+ toAssetId: number;
472
+ marketAddr: EthereumAddress;
473
+ amountToSwitch: string;
474
+ };
475
+ };
465
476
  /**
466
477
  ______ .______ ____ ____ __ __ _______. _______
467
478
  / || _ \ \ \ / / | | | | / || \
@@ -3,7 +3,8 @@ 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.fluidLeverageManagementSubData = exports.morphoBlueCloseOnPriceSubData = exports.morphoBlueLeverageManagementOnPriceSubData = exports.morphoBlueLeverageManagementSubData = exports.crvUSDPaybackSubData = exports.crvUSDLeverageManagementSubData = exports.sparkLeverageManagementOnPriceSubData = exports.sparkCloseGenericSubData = exports.sparkLeverageManagementSubDataWithoutSubProxy = exports.sparkLeverageManagementSubData = exports.exchangeLimitOrderSubDataWithoutSubProxy = exports.exchangeLimitOrderSubData = exports.exchangeDcaSubData = exports.compoundV3CloseSubData = exports.compoundV3LeverageManagementOnPriceSubData = exports.compoundV3LeverageManagementSubDataWithoutSubProxy = exports.compoundV3LeverageManagementSubData = exports.compoundV2LeverageManagementSubDataWithoutSubProxy = exports.compoundV2LeverageManagementSubData = exports.aaveV4CollateralSwitchSubData = exports.aaveV4CloseSubData = exports.aaveV4LeverageManagementOnPriceSubData = exports.aaveV4LeverageManagementSubData = exports.aaveV3LeverageManagementOnPriceSubData = exports.aaveV3QuotePriceSubData = exports.aaveV3CollateralSwitchSubData = exports.aaveV3CloseGenericSubData = exports.aaveV3LeverageManagementOnPriceGeneric = exports.aaveV3LeverageManagementSubDataWithoutSubProxy = exports.aaveV3LeverageManagementSubData = exports.aaveV2LeverageManagementSubDataWithoutSubProxy = exports.aaveV2LeverageManagementSubData = exports.liquityV2PaybackSubData = exports.liquityV2LeverageManagementOnPriceSubData = exports.liquityV2CloseSubData = exports.liquityV2LeverageManagementSubData = exports.liquityDebtInFrontRepaySubData = exports.liquityDsrSupplySubData = exports.liquityDsrPaybackSubData = exports.liquityCloseSubData = exports.liquityLeverageManagementSubDataWithoutSubProxy = exports.liquityLeverageManagementSubData = exports.liquityRepayFromSavingsSubData = exports.makerLeverageManagementWithoutSubProxy = exports.makerLeverageManagementSubData = exports.makerCloseSubData = exports.makerRepayFromSavingsSubData = exports.liquityPaybackUsingChickenBondSubData = exports.cBondsRebondSubData = exports.morphoAaveV2LeverageManagementSubData = void 0;
6
+ exports.morphoBlueCloseOnPriceSubData = exports.morphoBlueLeverageManagementOnPriceSubData = exports.morphoBlueLeverageManagementSubData = exports.crvUSDPaybackSubData = exports.crvUSDLeverageManagementSubData = exports.sparkCollateralSwitchSubData = exports.sparkLeverageManagementOnPriceSubData = exports.sparkCloseGenericSubData = exports.sparkLeverageManagementSubDataWithoutSubProxy = exports.sparkLeverageManagementSubData = exports.exchangeLimitOrderSubDataWithoutSubProxy = exports.exchangeLimitOrderSubData = exports.exchangeDcaSubData = exports.compoundV3CloseSubData = exports.compoundV3LeverageManagementOnPriceSubData = exports.compoundV3LeverageManagementSubDataWithoutSubProxy = exports.compoundV3LeverageManagementSubData = exports.compoundV2LeverageManagementSubDataWithoutSubProxy = exports.compoundV2LeverageManagementSubData = exports.aaveV4CollateralSwitchSubData = exports.aaveV4CloseSubData = exports.aaveV4LeverageManagementOnPriceSubData = exports.aaveV4LeverageManagementSubData = exports.aaveV3LeverageManagementOnPriceSubData = exports.aaveV3QuotePriceSubData = exports.aaveV3CollateralSwitchSubData = exports.aaveV3CloseGenericSubData = exports.aaveV3LeverageManagementOnPriceGeneric = exports.aaveV3LeverageManagementSubDataWithoutSubProxy = exports.aaveV3LeverageManagementSubData = exports.aaveV2LeverageManagementSubDataWithoutSubProxy = exports.aaveV2LeverageManagementSubData = exports.liquityV2PaybackSubData = exports.liquityV2LeverageManagementOnPriceSubData = exports.liquityV2CloseSubData = exports.liquityV2LeverageManagementSubData = exports.liquityDebtInFrontRepaySubData = exports.liquityDsrSupplySubData = exports.liquityDsrPaybackSubData = exports.liquityCloseSubData = exports.liquityLeverageManagementSubDataWithoutSubProxy = exports.liquityLeverageManagementSubData = exports.liquityRepayFromSavingsSubData = exports.makerLeverageManagementWithoutSubProxy = exports.makerLeverageManagementSubData = exports.makerCloseSubData = exports.makerRepayFromSavingsSubData = exports.liquityPaybackUsingChickenBondSubData = exports.cBondsRebondSubData = exports.morphoAaveV2LeverageManagementSubData = void 0;
7
+ exports.fluidLeverageManagementSubData = void 0;
7
8
  const decimal_js_1 = __importDefault(require("decimal.js"));
8
9
  const web3_eth_abi_1 = __importDefault(require("web3-eth-abi"));
9
10
  const web3_utils_1 = require("web3-utils");
@@ -1053,6 +1054,37 @@ exports.sparkLeverageManagementOnPriceSubData = {
1053
1054
  };
1054
1055
  },
1055
1056
  };
1057
+ exports.sparkCollateralSwitchSubData = {
1058
+ encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, useOnBehalf = false) {
1059
+ const encodedFromAsset = web3_eth_abi_1.default.encodeParameter('address', fromAsset);
1060
+ const encodedFromAssetId = web3_eth_abi_1.default.encodeParameter('uint8', fromAssetId);
1061
+ const encodedToAsset = web3_eth_abi_1.default.encodeParameter('address', toAsset);
1062
+ const encodedToAssetId = web3_eth_abi_1.default.encodeParameter('uint8', toAssetId);
1063
+ const encodedMarketAddr = web3_eth_abi_1.default.encodeParameter('address', marketAddr);
1064
+ const encodedAmountToSwitch = web3_eth_abi_1.default.encodeParameter('uint256', amountToSwitch);
1065
+ const encodedUseOnBehalf = web3_eth_abi_1.default.encodeParameter('bool', useOnBehalf);
1066
+ return [
1067
+ encodedFromAsset,
1068
+ encodedFromAssetId,
1069
+ encodedToAsset,
1070
+ encodedToAssetId,
1071
+ encodedMarketAddr,
1072
+ encodedAmountToSwitch,
1073
+ encodedUseOnBehalf,
1074
+ ];
1075
+ },
1076
+ decode(subData) {
1077
+ const fromAsset = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
1078
+ const fromAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[1]));
1079
+ const toAsset = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
1080
+ const toAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[3]));
1081
+ const marketAddr = web3_eth_abi_1.default.decodeParameter('address', subData[4]);
1082
+ const amountToSwitch = web3_eth_abi_1.default.decodeParameter('uint256', subData[5]);
1083
+ return {
1084
+ fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch,
1085
+ };
1086
+ },
1087
+ };
1056
1088
  /**
1057
1089
  ______ .______ ____ ____ __ __ _______. _______
1058
1090
  / || _ \ \ \ / / | | | | / || \
@@ -556,6 +556,127 @@ describe('Feature: subDataService.ts', () => {
556
556
  });
557
557
  });
558
558
  });
559
+ describe('When testing subDataService.sparkCollateralSwitchSubData', () => {
560
+ describe('encode()', () => {
561
+ const examples = [
562
+ // WETH -> cbBTC
563
+ [
564
+ [
565
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
566
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
567
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
568
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
569
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
570
+ '0x0000000000000000000000000000000000000000000000008ac7230489e80000',
571
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
572
+ ],
573
+ [
574
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
575
+ 0,
576
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('cbBTC', enums_1.ChainId.Ethereum).address),
577
+ 7,
578
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
579
+ '10000000000000000000',
580
+ false,
581
+ ]
582
+ ],
583
+ // cbBTC -> WETH (MaxUint256)
584
+ [
585
+ [
586
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
587
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
588
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
589
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
590
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
591
+ '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
592
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
593
+ ],
594
+ [
595
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('cbBTC', enums_1.ChainId.Ethereum).address),
596
+ 7,
597
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
598
+ 0,
599
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
600
+ tokens_2.MAXUINT,
601
+ ]
602
+ ],
603
+ // WETH -> cbBTC (5 WETH)
604
+ [
605
+ [
606
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
607
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
608
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
609
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
610
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
611
+ '0x0000000000000000000000000000000000000000000000004563918244f40000',
612
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
613
+ ],
614
+ [
615
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
616
+ 0,
617
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('cbBTC', enums_1.ChainId.Ethereum).address),
618
+ 7,
619
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
620
+ '5000000000000000000', // 5 WETH
621
+ ]
622
+ ],
623
+ ];
624
+ examples.forEach(([expected, actual]) => {
625
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
626
+ (0, chai_1.expect)(subDataService.sparkCollateralSwitchSubData.encode(...actual)).to.eql(expected);
627
+ });
628
+ });
629
+ });
630
+ describe('decode()', () => {
631
+ const examples = [
632
+ // WETH -> cbBTC
633
+ [
634
+ {
635
+ fromAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
636
+ fromAssetId: 0,
637
+ toAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('cbBTC', enums_1.ChainId.Ethereum).address),
638
+ toAssetId: 7,
639
+ marketAddr: web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
640
+ amountToSwitch: '10000000000000000000',
641
+ },
642
+ [
643
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
644
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
645
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
646
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
647
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
648
+ '0x0000000000000000000000000000000000000000000000008ac7230489e80000',
649
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
650
+ ],
651
+ ],
652
+ // cbBTC -> WETH (MaxUint256)
653
+ [
654
+ {
655
+ fromAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('cbBTC', enums_1.ChainId.Ethereum).address),
656
+ fromAssetId: 7,
657
+ toAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
658
+ toAssetId: 0,
659
+ marketAddr: web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
660
+ amountToSwitch: tokens_2.MAXUINT,
661
+ },
662
+ [
663
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
664
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
665
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
666
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
667
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
668
+ '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
669
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
670
+ ],
671
+ ],
672
+ ];
673
+ examples.forEach(([expected, actual]) => {
674
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
675
+ (0, chai_1.expect)(subDataService.sparkCollateralSwitchSubData.decode(actual)).to.eql(expected);
676
+ });
677
+ });
678
+ });
679
+ });
559
680
  describe('When testing subDataService.compoundV2LeverageManagementSubData', () => {
560
681
  describe('encode()', () => {
561
682
  const examples = [
@@ -89,7 +89,8 @@ export declare namespace Strategies {
89
89
  LIQUITY_V2_PAYBACK = 113,
90
90
  AAVE_V3_COLLATERAL_SWITCH = 135,
91
91
  AAVE_V4_COLLATERAL_SWITCH = 154,
92
- AAVE_V4_COLLATERAL_SWITCH_EOA = 155
92
+ AAVE_V4_COLLATERAL_SWITCH_EOA = 155,
93
+ SPARK_COLLATERAL_SWITCH = 156
93
94
  }
94
95
  enum OptimismIds {
95
96
  EXCHANGE_DCA = 8,
@@ -106,6 +106,7 @@ var Strategies;
106
106
  MainnetIds[MainnetIds["AAVE_V3_COLLATERAL_SWITCH"] = 135] = "AAVE_V3_COLLATERAL_SWITCH";
107
107
  MainnetIds[MainnetIds["AAVE_V4_COLLATERAL_SWITCH"] = 154] = "AAVE_V4_COLLATERAL_SWITCH";
108
108
  MainnetIds[MainnetIds["AAVE_V4_COLLATERAL_SWITCH_EOA"] = 155] = "AAVE_V4_COLLATERAL_SWITCH_EOA";
109
+ MainnetIds[MainnetIds["SPARK_COLLATERAL_SWITCH"] = 156] = "SPARK_COLLATERAL_SWITCH";
109
110
  })(MainnetIds = Strategies.MainnetIds || (Strategies.MainnetIds = {}));
110
111
  let OptimismIds;
111
112
  (function (OptimismIds) {
@@ -111,6 +111,11 @@ export const MAINNET_STRATEGIES_INFO = {
111
111
  strategyId: Strategies.Identifiers.EoaCollateralSwitch,
112
112
  protocol: PROTOCOLS.AaveV4,
113
113
  },
114
+ [Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH]: {
115
+ strategyOrBundleId: Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
116
+ strategyId: Strategies.Identifiers.CollateralSwitch,
117
+ protocol: PROTOCOLS.Spark,
118
+ },
114
119
  };
115
120
  export const OPTIMISM_STRATEGIES_INFO = {
116
121
  [Strategies.OptimismIds.EXCHANGE_DCA]: {
@@ -289,6 +289,16 @@ function parseAaveV3CollateralSwitch(position, parseData) {
289
289
  _position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, subData.marketAddr);
290
290
  return _position;
291
291
  }
292
+ function parseSparkCollateralSwitch(position, parseData) {
293
+ const _position = cloneDeep(position);
294
+ const { subStruct } = parseData.subscriptionEventData;
295
+ const triggerData = triggerService.sparkQuotePriceTrigger.decode(subStruct.triggerData);
296
+ const subData = subDataService.sparkCollateralSwitchSubData.decode(subStruct.subData);
297
+ _position.strategyData.decoded.triggerData = triggerData;
298
+ _position.strategyData.decoded.subData = subData;
299
+ _position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, subData.marketAddr);
300
+ return _position;
301
+ }
292
302
  function parseAaveV4LeverageManagement(position, parseData) {
293
303
  const _position = cloneDeep(position);
294
304
  const { subStruct, subId, subHash } = parseData.subscriptionEventData;
@@ -1087,6 +1097,7 @@ const parsingMethodsMapping = {
1087
1097
  [Strategies.Identifiers.RepayOnPrice]: parseSparkLeverageManagementOnPrice,
1088
1098
  [Strategies.Identifiers.BoostOnPrice]: parseSparkLeverageManagementOnPrice,
1089
1099
  [Strategies.Identifiers.CloseOnPrice]: parseSparkCloseOnPrice,
1100
+ [Strategies.Identifiers.CollateralSwitch]: parseSparkCollateralSwitch,
1090
1101
  },
1091
1102
  [ProtocolIdentifiers.StrategiesAutomation.CrvUSD]: {
1092
1103
  [Strategies.Identifiers.Repay]: parseCrvUSDLeverageManagement,
@@ -95,6 +95,7 @@ export declare const sparkEncode: {
95
95
  }): (number | boolean | string[])[];
96
96
  closeOnPriceGeneric(strategyOrBundleId: number, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, marketAddr: EthereumAddress, user: EthereumAddress, stopLossPrice?: number, stopLossType?: CloseToAssetType, takeProfitPrice?: number, takeProfitType?: CloseToAssetType): (number | boolean | string[])[];
97
97
  leverageManagementWithoutSubProxy(strategyOrBundleId: number, market: EthereumAddress, user: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number): (number | boolean | string[])[];
98
+ collateralSwitch(strategyOrBundleId: number, fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, marketAddr: EthereumAddress, amountToSwitch: string, baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: number, state: RatioState): (number | boolean | string[])[];
98
99
  };
99
100
  export declare const crvUSDEncode: {
100
101
  leverageManagement(owner: EthereumAddress, controllerAddr: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number, collTokenAddr: EthereumAddress, crvUSDAddr: EthereumAddress): (boolean | string[] | Bundles.MainnetIds)[];
@@ -231,6 +231,12 @@ export const sparkEncode = {
231
231
  const triggerData = triggerService.sparkRatioTrigger.encode(user, market, triggerRatio, ratioState);
232
232
  return [strategyOrBundleId, isBundle, triggerData, subData];
233
233
  },
234
+ collateralSwitch(strategyOrBundleId, fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, baseTokenAddress, quoteTokenAddress, price, state) {
235
+ const isBundle = false;
236
+ const subDataEncoded = subDataService.sparkCollateralSwitchSubData.encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch);
237
+ const triggerDataEncoded = triggerService.sparkQuotePriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, state);
238
+ return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
239
+ },
234
240
  };
235
241
  export const crvUSDEncode = {
236
242
  leverageManagement(owner, controllerAddr, ratioState, targetRatio, triggerRatio, collTokenAddr, crvUSDAddr) {
@@ -1351,6 +1351,105 @@ describe('Feature: strategySubService.ts', () => {
1351
1351
  });
1352
1352
  });
1353
1353
  });
1354
+ describe('collateralSwitch()', () => {
1355
+ const examples = [
1356
+ // WETH -> cbBTC, price 0.025 WETH/cbBTC, state UNDER
1357
+ [
1358
+ [
1359
+ Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
1360
+ false,
1361
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf00000000000000000000000000000000000000000000000000000000002625a00000000000000000000000000000000000000000000000000000000000000001'],
1362
+ [
1363
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1364
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1365
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
1366
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
1367
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
1368
+ '0x0000000000000000000000000000000000000000000000008ac7230489e80000',
1369
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1370
+ ],
1371
+ ],
1372
+ [
1373
+ Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
1374
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1375
+ 0,
1376
+ web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
1377
+ 7,
1378
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
1379
+ '10000000000000000000',
1380
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1381
+ web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
1382
+ 0.025,
1383
+ RatioState.UNDER,
1384
+ ]
1385
+ ],
1386
+ // cbBTC -> WETH, price 25 cbBTC/WETH, state UNDER
1387
+ [
1388
+ [
1389
+ Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
1390
+ false,
1391
+ ['0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000009502f9000000000000000000000000000000000000000000000000000000000000000001'],
1392
+ [
1393
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
1394
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
1395
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1396
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1397
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
1398
+ '0x0000000000000000000000000000000000000000000000000000000005f5e100',
1399
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1400
+ ],
1401
+ ],
1402
+ [
1403
+ Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
1404
+ web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
1405
+ 7,
1406
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1407
+ 0,
1408
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
1409
+ '100000000',
1410
+ web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
1411
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1412
+ 25,
1413
+ RatioState.UNDER,
1414
+ ]
1415
+ ],
1416
+ // cbBTC -> WETH, price 40 cbBTC/WETH, state OVER
1417
+ [
1418
+ [
1419
+ Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
1420
+ false,
1421
+ ['0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000ee6b28000000000000000000000000000000000000000000000000000000000000000000'],
1422
+ [
1423
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
1424
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
1425
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1426
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1427
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
1428
+ '0x0000000000000000000000000000000000000000000000000000000005f5e100',
1429
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1430
+ ],
1431
+ ],
1432
+ [
1433
+ Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
1434
+ web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
1435
+ 7,
1436
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1437
+ 0,
1438
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
1439
+ '100000000',
1440
+ web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
1441
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1442
+ 40,
1443
+ RatioState.OVER,
1444
+ ]
1445
+ ],
1446
+ ];
1447
+ examples.forEach(([expected, actual]) => {
1448
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1449
+ expect(sparkEncode.collateralSwitch(...actual)).to.eql(expected);
1450
+ });
1451
+ });
1452
+ });
1354
1453
  });
1355
1454
  describe('When testing strategySubService.aaveV4Encode', () => {
1356
1455
  describe('leverageManagement()', () => {
@@ -462,6 +462,17 @@ export declare const sparkLeverageManagementOnPriceSubData: {
462
462
  targetRatio: number;
463
463
  };
464
464
  };
465
+ export declare const sparkCollateralSwitchSubData: {
466
+ encode(fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, marketAddr: EthereumAddress, amountToSwitch: string, useOnBehalf?: boolean): string[];
467
+ decode(subData: string[]): {
468
+ fromAsset: EthereumAddress;
469
+ fromAssetId: number;
470
+ toAsset: EthereumAddress;
471
+ toAssetId: number;
472
+ marketAddr: EthereumAddress;
473
+ amountToSwitch: string;
474
+ };
475
+ };
465
476
  /**
466
477
  ______ .______ ____ ____ __ __ _______. _______
467
478
  / || _ \ \ \ / / | | | | / || \
@@ -1047,6 +1047,37 @@ export const sparkLeverageManagementOnPriceSubData = {
1047
1047
  };
1048
1048
  },
1049
1049
  };
1050
+ export const sparkCollateralSwitchSubData = {
1051
+ encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, useOnBehalf = false) {
1052
+ const encodedFromAsset = AbiCoder.encodeParameter('address', fromAsset);
1053
+ const encodedFromAssetId = AbiCoder.encodeParameter('uint8', fromAssetId);
1054
+ const encodedToAsset = AbiCoder.encodeParameter('address', toAsset);
1055
+ const encodedToAssetId = AbiCoder.encodeParameter('uint8', toAssetId);
1056
+ const encodedMarketAddr = AbiCoder.encodeParameter('address', marketAddr);
1057
+ const encodedAmountToSwitch = AbiCoder.encodeParameter('uint256', amountToSwitch);
1058
+ const encodedUseOnBehalf = AbiCoder.encodeParameter('bool', useOnBehalf);
1059
+ return [
1060
+ encodedFromAsset,
1061
+ encodedFromAssetId,
1062
+ encodedToAsset,
1063
+ encodedToAssetId,
1064
+ encodedMarketAddr,
1065
+ encodedAmountToSwitch,
1066
+ encodedUseOnBehalf,
1067
+ ];
1068
+ },
1069
+ decode(subData) {
1070
+ const fromAsset = AbiCoder.decodeParameter('address', subData[0]);
1071
+ const fromAssetId = Number(AbiCoder.decodeParameter('uint8', subData[1]));
1072
+ const toAsset = AbiCoder.decodeParameter('address', subData[2]);
1073
+ const toAssetId = Number(AbiCoder.decodeParameter('uint8', subData[3]));
1074
+ const marketAddr = AbiCoder.decodeParameter('address', subData[4]);
1075
+ const amountToSwitch = AbiCoder.decodeParameter('uint256', subData[5]);
1076
+ return {
1077
+ fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch,
1078
+ };
1079
+ },
1080
+ };
1050
1081
  /**
1051
1082
  ______ .______ ____ ____ __ __ _______. _______
1052
1083
  / || _ \ \ \ / / | | | | / || \
@@ -528,6 +528,127 @@ describe('Feature: subDataService.ts', () => {
528
528
  });
529
529
  });
530
530
  });
531
+ describe('When testing subDataService.sparkCollateralSwitchSubData', () => {
532
+ describe('encode()', () => {
533
+ const examples = [
534
+ // WETH -> cbBTC
535
+ [
536
+ [
537
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
538
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
539
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
540
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
541
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
542
+ '0x0000000000000000000000000000000000000000000000008ac7230489e80000',
543
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
544
+ ],
545
+ [
546
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
547
+ 0,
548
+ web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
549
+ 7,
550
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
551
+ '10000000000000000000',
552
+ false,
553
+ ]
554
+ ],
555
+ // cbBTC -> WETH (MaxUint256)
556
+ [
557
+ [
558
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
559
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
560
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
561
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
562
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
563
+ '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
564
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
565
+ ],
566
+ [
567
+ web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
568
+ 7,
569
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
570
+ 0,
571
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
572
+ MAXUINT,
573
+ ]
574
+ ],
575
+ // WETH -> cbBTC (5 WETH)
576
+ [
577
+ [
578
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
579
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
580
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
581
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
582
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
583
+ '0x0000000000000000000000000000000000000000000000004563918244f40000',
584
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
585
+ ],
586
+ [
587
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
588
+ 0,
589
+ web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
590
+ 7,
591
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
592
+ '5000000000000000000', // 5 WETH
593
+ ]
594
+ ],
595
+ ];
596
+ examples.forEach(([expected, actual]) => {
597
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
598
+ expect(subDataService.sparkCollateralSwitchSubData.encode(...actual)).to.eql(expected);
599
+ });
600
+ });
601
+ });
602
+ describe('decode()', () => {
603
+ const examples = [
604
+ // WETH -> cbBTC
605
+ [
606
+ {
607
+ fromAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
608
+ fromAssetId: 0,
609
+ toAsset: web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
610
+ toAssetId: 7,
611
+ marketAddr: web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
612
+ amountToSwitch: '10000000000000000000',
613
+ },
614
+ [
615
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
616
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
617
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
618
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
619
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
620
+ '0x0000000000000000000000000000000000000000000000008ac7230489e80000',
621
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
622
+ ],
623
+ ],
624
+ // cbBTC -> WETH (MaxUint256)
625
+ [
626
+ {
627
+ fromAsset: web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
628
+ fromAssetId: 7,
629
+ toAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
630
+ toAssetId: 0,
631
+ marketAddr: web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
632
+ amountToSwitch: MAXUINT,
633
+ },
634
+ [
635
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
636
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
637
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
638
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
639
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
640
+ '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
641
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
642
+ ],
643
+ ],
644
+ ];
645
+ examples.forEach(([expected, actual]) => {
646
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
647
+ expect(subDataService.sparkCollateralSwitchSubData.decode(actual)).to.eql(expected);
648
+ });
649
+ });
650
+ });
651
+ });
531
652
  describe('When testing subDataService.compoundV2LeverageManagementSubData', () => {
532
653
  describe('encode()', () => {
533
654
  const examples = [
@@ -89,7 +89,8 @@ export declare namespace Strategies {
89
89
  LIQUITY_V2_PAYBACK = 113,
90
90
  AAVE_V3_COLLATERAL_SWITCH = 135,
91
91
  AAVE_V4_COLLATERAL_SWITCH = 154,
92
- AAVE_V4_COLLATERAL_SWITCH_EOA = 155
92
+ AAVE_V4_COLLATERAL_SWITCH_EOA = 155,
93
+ SPARK_COLLATERAL_SWITCH = 156
93
94
  }
94
95
  enum OptimismIds {
95
96
  EXCHANGE_DCA = 8,
@@ -103,6 +103,7 @@ export var Strategies;
103
103
  MainnetIds[MainnetIds["AAVE_V3_COLLATERAL_SWITCH"] = 135] = "AAVE_V3_COLLATERAL_SWITCH";
104
104
  MainnetIds[MainnetIds["AAVE_V4_COLLATERAL_SWITCH"] = 154] = "AAVE_V4_COLLATERAL_SWITCH";
105
105
  MainnetIds[MainnetIds["AAVE_V4_COLLATERAL_SWITCH_EOA"] = 155] = "AAVE_V4_COLLATERAL_SWITCH_EOA";
106
+ MainnetIds[MainnetIds["SPARK_COLLATERAL_SWITCH"] = 156] = "SPARK_COLLATERAL_SWITCH";
106
107
  })(MainnetIds = Strategies.MainnetIds || (Strategies.MainnetIds = {}));
107
108
  let OptimismIds;
108
109
  (function (OptimismIds) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defisaver/automation-sdk",
3
- "version": "3.3.12-strategies-refactor-5-dev",
3
+ "version": "3.3.13-strategies-refactor-dev",
4
4
  "description": "",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./esm/index.js",
@@ -135,6 +135,11 @@ export const MAINNET_STRATEGIES_INFO: MainnetStrategiesInfo = {
135
135
  strategyId: Strategies.Identifiers.EoaCollateralSwitch,
136
136
  protocol: PROTOCOLS.AaveV4,
137
137
  },
138
+ [Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH]: {
139
+ strategyOrBundleId: Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
140
+ strategyId: Strategies.Identifiers.CollateralSwitch,
141
+ protocol: PROTOCOLS.Spark,
142
+ },
138
143
  };
139
144
 
140
145
  export const OPTIMISM_STRATEGIES_INFO: OptimismStrategiesInfo = {
@@ -389,6 +389,17 @@ function parseAaveV3CollateralSwitch(position: Position.Automated, parseData: Pa
389
389
  return _position;
390
390
  }
391
391
 
392
+ function parseSparkCollateralSwitch(position: Position.Automated, parseData: ParseData): Position.Automated {
393
+ const _position = cloneDeep(position);
394
+ const { subStruct } = parseData.subscriptionEventData;
395
+ const triggerData = triggerService.sparkQuotePriceTrigger.decode(subStruct.triggerData);
396
+ const subData = subDataService.sparkCollateralSwitchSubData.decode(subStruct.subData);
397
+ _position.strategyData.decoded.triggerData = triggerData;
398
+ _position.strategyData.decoded.subData = subData;
399
+ _position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, subData.marketAddr);
400
+ return _position;
401
+ }
402
+
392
403
  function parseAaveV4LeverageManagement(position: Position.Automated, parseData: ParseData): Position.Automated {
393
404
  const _position = cloneDeep(position);
394
405
  const { subStruct, subId, subHash } = parseData.subscriptionEventData;
@@ -1399,6 +1410,7 @@ const parsingMethodsMapping: StrategiesToProtocolVersionMapping = {
1399
1410
  [Strategies.Identifiers.RepayOnPrice]: parseSparkLeverageManagementOnPrice,
1400
1411
  [Strategies.Identifiers.BoostOnPrice]: parseSparkLeverageManagementOnPrice,
1401
1412
  [Strategies.Identifiers.CloseOnPrice]: parseSparkCloseOnPrice,
1413
+ [Strategies.Identifiers.CollateralSwitch]: parseSparkCollateralSwitch,
1402
1414
  },
1403
1415
  [ProtocolIdentifiers.StrategiesAutomation.CrvUSD]: {
1404
1416
  [Strategies.Identifiers.Repay]: parseCrvUSDLeverageManagement,
@@ -1613,7 +1613,124 @@ describe('Feature: strategySubService.ts', () => {
1613
1613
  });
1614
1614
  });
1615
1615
  });
1616
+
1617
+ describe('collateralSwitch()', () => {
1618
+ const examples: Array<[
1619
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
1620
+ [
1621
+ strategyOrBundleId: number,
1622
+ fromAsset: EthereumAddress,
1623
+ fromAssetId: number,
1624
+ toAsset: EthereumAddress,
1625
+ toAssetId: number,
1626
+ marketAddr: EthereumAddress,
1627
+ amountToSwitch: string,
1628
+ baseTokenAddress: EthereumAddress,
1629
+ quoteTokenAddress: EthereumAddress,
1630
+ price: number,
1631
+ state: RatioState,
1632
+ ]
1633
+ ]> = [
1634
+ // WETH -> cbBTC, price 0.025 WETH/cbBTC, state UNDER
1635
+ [
1636
+ [
1637
+ Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
1638
+ false,
1639
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf00000000000000000000000000000000000000000000000000000000002625a00000000000000000000000000000000000000000000000000000000000000001'],
1640
+ [
1641
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1642
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1643
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
1644
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
1645
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
1646
+ '0x0000000000000000000000000000000000000000000000008ac7230489e80000',
1647
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1648
+ ],
1649
+ ],
1650
+ [
1651
+ Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
1652
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1653
+ 0,
1654
+ web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
1655
+ 7,
1656
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
1657
+ '10000000000000000000', // 10 WETH
1658
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1659
+ web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
1660
+ 0.025,
1661
+ RatioState.UNDER,
1662
+ ]
1663
+ ],
1664
+ // cbBTC -> WETH, price 25 cbBTC/WETH, state UNDER
1665
+ [
1666
+ [
1667
+ Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
1668
+ false,
1669
+ ['0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000009502f9000000000000000000000000000000000000000000000000000000000000000001'],
1670
+ [
1671
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
1672
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
1673
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1674
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1675
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
1676
+ '0x0000000000000000000000000000000000000000000000000000000005f5e100',
1677
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1678
+ ],
1679
+ ],
1680
+ [
1681
+ Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
1682
+ web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
1683
+ 7,
1684
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1685
+ 0,
1686
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
1687
+ '100000000', // 1 cbBTC (8 decimals)
1688
+ web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
1689
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1690
+ 25,
1691
+ RatioState.UNDER,
1692
+ ]
1693
+ ],
1694
+ // cbBTC -> WETH, price 40 cbBTC/WETH, state OVER
1695
+ [
1696
+ [
1697
+ Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
1698
+ false,
1699
+ ['0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000ee6b28000000000000000000000000000000000000000000000000000000000000000000'],
1700
+ [
1701
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
1702
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
1703
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1704
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1705
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
1706
+ '0x0000000000000000000000000000000000000000000000000000000005f5e100',
1707
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1708
+ ],
1709
+ ],
1710
+ [
1711
+ Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
1712
+ web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
1713
+ 7,
1714
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1715
+ 0,
1716
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
1717
+ '100000000', // 1 cbBTC (8 decimals)
1718
+ web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
1719
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1720
+ 40,
1721
+ RatioState.OVER,
1722
+ ]
1723
+ ],
1724
+ ];
1725
+
1726
+ examples.forEach(([expected, actual]) => {
1727
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1728
+ expect(sparkEncode.collateralSwitch(...actual)).to.eql(expected);
1729
+ });
1730
+ });
1731
+ });
1616
1732
  });
1733
+
1617
1734
  describe('When testing strategySubService.aaveV4Encode', () => {
1618
1735
  describe('leverageManagement()', () => {
1619
1736
  const examples: Array<[
@@ -591,6 +591,27 @@ export const sparkEncode = {
591
591
 
592
592
  return [strategyOrBundleId, isBundle, triggerData, subData];
593
593
  },
594
+ collateralSwitch(
595
+ strategyOrBundleId: number,
596
+ fromAsset: EthereumAddress,
597
+ fromAssetId: number,
598
+ toAsset: EthereumAddress,
599
+ toAssetId: number,
600
+ marketAddr: EthereumAddress,
601
+ amountToSwitch: string,
602
+ baseTokenAddress: EthereumAddress,
603
+ quoteTokenAddress: EthereumAddress,
604
+ price: number,
605
+ state: RatioState,
606
+ ) {
607
+ const isBundle = false;
608
+
609
+ const subDataEncoded = subDataService.sparkCollateralSwitchSubData.encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch);
610
+ const triggerDataEncoded = triggerService.sparkQuotePriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, state);
611
+
612
+ return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
613
+ },
614
+
594
615
  };
595
616
 
596
617
  export const crvUSDEncode = {
@@ -569,6 +569,131 @@ describe('Feature: subDataService.ts', () => {
569
569
  });
570
570
  });
571
571
 
572
+ describe('When testing subDataService.sparkCollateralSwitchSubData', () => {
573
+ describe('encode()', () => {
574
+ const examples: Array<[SubData, [fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, marketAddr: EthereumAddress, amountToSwitch: string, useOnBehalf?: boolean]]> = [
575
+ // WETH -> cbBTC
576
+ [
577
+ [
578
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
579
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
580
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
581
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
582
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
583
+ '0x0000000000000000000000000000000000000000000000008ac7230489e80000',
584
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
585
+ ],
586
+ [
587
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
588
+ 0,
589
+ web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
590
+ 7,
591
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
592
+ '10000000000000000000', // 10 WETH
593
+ false,
594
+ ]
595
+ ],
596
+ // cbBTC -> WETH (MaxUint256)
597
+ [
598
+ [
599
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
600
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
601
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
602
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
603
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
604
+ '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
605
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
606
+ ],
607
+ [
608
+ web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
609
+ 7,
610
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
611
+ 0,
612
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
613
+ MAXUINT,
614
+ ]
615
+ ],
616
+ // WETH -> cbBTC (5 WETH)
617
+ [
618
+ [
619
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
620
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
621
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
622
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
623
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
624
+ '0x0000000000000000000000000000000000000000000000004563918244f40000',
625
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
626
+ ],
627
+ [
628
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
629
+ 0,
630
+ web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
631
+ 7,
632
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
633
+ '5000000000000000000', // 5 WETH
634
+ ]
635
+ ],
636
+ ];
637
+
638
+ examples.forEach(([expected, actual]) => {
639
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
640
+ expect(subDataService.sparkCollateralSwitchSubData.encode(...actual)).to.eql(expected);
641
+ });
642
+ });
643
+ });
644
+
645
+ describe('decode()', () => {
646
+ const examples: Array<[{ fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, marketAddr: EthereumAddress, amountToSwitch: string }, SubData]> = [
647
+ // WETH -> cbBTC
648
+ [
649
+ {
650
+ fromAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
651
+ fromAssetId: 0,
652
+ toAsset: web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
653
+ toAssetId: 7,
654
+ marketAddr: web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
655
+ amountToSwitch: '10000000000000000000',
656
+ },
657
+ [
658
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
659
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
660
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
661
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
662
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
663
+ '0x0000000000000000000000000000000000000000000000008ac7230489e80000',
664
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
665
+ ],
666
+ ],
667
+ // cbBTC -> WETH (MaxUint256)
668
+ [
669
+ {
670
+ fromAsset: web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
671
+ fromAssetId: 7,
672
+ toAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
673
+ toAssetId: 0,
674
+ marketAddr: web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
675
+ amountToSwitch: MAXUINT,
676
+ },
677
+ [
678
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
679
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
680
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
681
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
682
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
683
+ '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
684
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
685
+ ],
686
+ ],
687
+ ];
688
+
689
+ examples.forEach(([expected, actual]) => {
690
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
691
+ expect(subDataService.sparkCollateralSwitchSubData.decode(actual)).to.eql(expected);
692
+ });
693
+ });
694
+ });
695
+ });
696
+
572
697
  describe('When testing subDataService.compoundV2LeverageManagementSubData', () => {
573
698
  describe('encode()', () => {
574
699
  const examples: Array<[[string, string, string, string, boolean], [triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean]]> = [
@@ -1409,6 +1409,55 @@ export const sparkLeverageManagementOnPriceSubData = {
1409
1409
  };
1410
1410
  },
1411
1411
  };
1412
+ export const sparkCollateralSwitchSubData = {
1413
+ encode(
1414
+ fromAsset: EthereumAddress,
1415
+ fromAssetId: number,
1416
+ toAsset: EthereumAddress,
1417
+ toAssetId: number,
1418
+ marketAddr: EthereumAddress,
1419
+ amountToSwitch: string,
1420
+ useOnBehalf: boolean = false,
1421
+ ): SubData {
1422
+ const encodedFromAsset = AbiCoder.encodeParameter('address', fromAsset);
1423
+ const encodedFromAssetId = AbiCoder.encodeParameter('uint8', fromAssetId);
1424
+ const encodedToAsset = AbiCoder.encodeParameter('address', toAsset);
1425
+ const encodedToAssetId = AbiCoder.encodeParameter('uint8', toAssetId);
1426
+ const encodedMarketAddr = AbiCoder.encodeParameter('address', marketAddr);
1427
+ const encodedAmountToSwitch = AbiCoder.encodeParameter('uint256', amountToSwitch);
1428
+ const encodedUseOnBehalf = AbiCoder.encodeParameter('bool', useOnBehalf);
1429
+
1430
+ return [
1431
+ encodedFromAsset,
1432
+ encodedFromAssetId,
1433
+ encodedToAsset,
1434
+ encodedToAssetId,
1435
+ encodedMarketAddr,
1436
+ encodedAmountToSwitch,
1437
+ encodedUseOnBehalf,
1438
+ ];
1439
+ },
1440
+ decode(subData: SubData): {
1441
+ fromAsset: EthereumAddress,
1442
+ fromAssetId: number,
1443
+ toAsset: EthereumAddress,
1444
+ toAssetId: number,
1445
+ marketAddr: EthereumAddress,
1446
+ amountToSwitch: string,
1447
+ } {
1448
+ const fromAsset = AbiCoder.decodeParameter('address', subData[0]) as unknown as EthereumAddress;
1449
+ const fromAssetId = Number(AbiCoder.decodeParameter('uint8', subData[1]));
1450
+ const toAsset = AbiCoder.decodeParameter('address', subData[2]) as unknown as EthereumAddress;
1451
+ const toAssetId = Number(AbiCoder.decodeParameter('uint8', subData[3]));
1452
+ const marketAddr = AbiCoder.decodeParameter('address', subData[4]) as unknown as EthereumAddress;
1453
+ const amountToSwitch = AbiCoder.decodeParameter('uint256', subData[5]) as unknown as string;
1454
+
1455
+ return {
1456
+ fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch,
1457
+ };
1458
+ },
1459
+ };
1460
+
1412
1461
 
1413
1462
  /**
1414
1463
  ______ .______ ____ ____ __ __ _______. _______
@@ -100,6 +100,7 @@ export namespace Strategies {
100
100
  AAVE_V3_COLLATERAL_SWITCH = 135,
101
101
  AAVE_V4_COLLATERAL_SWITCH = 154,
102
102
  AAVE_V4_COLLATERAL_SWITCH_EOA = 155,
103
+ SPARK_COLLATERAL_SWITCH = 156,
103
104
  }
104
105
 
105
106
  export enum OptimismIds {