@defisaver/automation-sdk 3.3.12 → 3.3.14

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]: {
@@ -314,6 +314,16 @@ function parseAaveV3CollateralSwitch(position, parseData) {
314
314
  _position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, subData.marketAddr);
315
315
  return _position;
316
316
  }
317
+ function parseSparkCollateralSwitch(position, parseData) {
318
+ const _position = (0, lodash_1.cloneDeep)(position);
319
+ const { subStruct } = parseData.subscriptionEventData;
320
+ const triggerData = triggerService.sparkQuotePriceTrigger.decode(subStruct.triggerData);
321
+ const subData = subDataService.sparkCollateralSwitchSubData.decode(subStruct.subData);
322
+ _position.strategyData.decoded.triggerData = triggerData;
323
+ _position.strategyData.decoded.subData = subData;
324
+ _position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, subData.marketAddr);
325
+ return _position;
326
+ }
317
327
  function parseAaveV4LeverageManagement(position, parseData) {
318
328
  const _position = (0, lodash_1.cloneDeep)(position);
319
329
  const { subStruct, subId, subHash } = parseData.subscriptionEventData;
@@ -1103,6 +1113,7 @@ const parsingMethodsMapping = {
1103
1113
  [enums_1.Strategies.Identifiers.RepayOnPrice]: parseSparkLeverageManagementOnPrice,
1104
1114
  [enums_1.Strategies.Identifiers.BoostOnPrice]: parseSparkLeverageManagementOnPrice,
1105
1115
  [enums_1.Strategies.Identifiers.CloseOnPrice]: parseSparkCloseOnPrice,
1116
+ [enums_1.Strategies.Identifiers.CollateralSwitch]: parseSparkCollateralSwitch,
1106
1117
  },
1107
1118
  [enums_1.ProtocolIdentifiers.StrategiesAutomation.CrvUSD]: {
1108
1119
  [enums_1.Strategies.Identifiers.Repay]: parseCrvUSDLeverageManagement,
@@ -101,6 +101,7 @@ export declare const sparkEncode: {
101
101
  }): (number | boolean | string[])[];
102
102
  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[])[];
103
103
  leverageManagementWithoutSubProxy(strategyOrBundleId: number, market: EthereumAddress, user: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number): (number | boolean | string[])[];
104
+ 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[])[];
104
105
  };
105
106
  export declare const crvUSDEncode: {
106
107
  leverageManagement(owner: EthereumAddress, controllerAddr: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number, collTokenAddr: EthereumAddress, crvUSDAddr: EthereumAddress): (boolean | string[] | Bundles.MainnetIds)[];
@@ -292,6 +292,12 @@ exports.sparkEncode = {
292
292
  const triggerData = triggerService.sparkRatioTrigger.encode(user, market, triggerRatio, ratioState);
293
293
  return [strategyOrBundleId, isBundle, triggerData, subData];
294
294
  },
295
+ collateralSwitch(strategyOrBundleId, fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, baseTokenAddress, quoteTokenAddress, price, state) {
296
+ const isBundle = false;
297
+ const subDataEncoded = subDataService.sparkCollateralSwitchSubData.encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch);
298
+ const triggerDataEncoded = triggerService.sparkQuotePriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, state);
299
+ return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
300
+ },
295
301
  };
296
302
  exports.crvUSDEncode = {
297
303
  leverageManagement(owner, controllerAddr, ratioState, targetRatio, triggerRatio, collTokenAddr, crvUSDAddr) {
@@ -1613,6 +1613,105 @@ describe('Feature: strategySubService.ts', () => {
1613
1613
  });
1614
1614
  });
1615
1615
  });
1616
+ describe('collateralSwitch()', () => {
1617
+ const examples = [
1618
+ // WETH -> cbBTC, price 0.025 WETH/cbBTC, state UNDER
1619
+ [
1620
+ [
1621
+ enums_1.Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
1622
+ false,
1623
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf00000000000000000000000000000000000000000000000000000000002625a00000000000000000000000000000000000000000000000000000000000000001'],
1624
+ [
1625
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1626
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1627
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
1628
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
1629
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
1630
+ '0x0000000000000000000000000000000000000000000000008ac7230489e80000',
1631
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1632
+ ],
1633
+ ],
1634
+ [
1635
+ enums_1.Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
1636
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
1637
+ 0,
1638
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('cbBTC', enums_1.ChainId.Ethereum).address),
1639
+ 7,
1640
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
1641
+ '10000000000000000000',
1642
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
1643
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('cbBTC', enums_1.ChainId.Ethereum).address),
1644
+ 0.025,
1645
+ enums_1.RatioState.UNDER,
1646
+ ]
1647
+ ],
1648
+ // cbBTC -> WETH, price 25 cbBTC/WETH, state UNDER
1649
+ [
1650
+ [
1651
+ enums_1.Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
1652
+ false,
1653
+ ['0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000009502f9000000000000000000000000000000000000000000000000000000000000000001'],
1654
+ [
1655
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
1656
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
1657
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1658
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1659
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
1660
+ '0x0000000000000000000000000000000000000000000000000000000005f5e100',
1661
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1662
+ ],
1663
+ ],
1664
+ [
1665
+ enums_1.Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
1666
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('cbBTC', enums_1.ChainId.Ethereum).address),
1667
+ 7,
1668
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
1669
+ 0,
1670
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
1671
+ '100000000',
1672
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('cbBTC', enums_1.ChainId.Ethereum).address),
1673
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
1674
+ 25,
1675
+ enums_1.RatioState.UNDER,
1676
+ ]
1677
+ ],
1678
+ // cbBTC -> WETH, price 40 cbBTC/WETH, state OVER
1679
+ [
1680
+ [
1681
+ enums_1.Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
1682
+ false,
1683
+ ['0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000ee6b28000000000000000000000000000000000000000000000000000000000000000000'],
1684
+ [
1685
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
1686
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
1687
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1688
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1689
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
1690
+ '0x0000000000000000000000000000000000000000000000000000000005f5e100',
1691
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1692
+ ],
1693
+ ],
1694
+ [
1695
+ enums_1.Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
1696
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('cbBTC', enums_1.ChainId.Ethereum).address),
1697
+ 7,
1698
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
1699
+ 0,
1700
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
1701
+ '100000000',
1702
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('cbBTC', enums_1.ChainId.Ethereum).address),
1703
+ web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
1704
+ 40,
1705
+ enums_1.RatioState.OVER,
1706
+ ]
1707
+ ],
1708
+ ];
1709
+ examples.forEach(([expected, actual]) => {
1710
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1711
+ (0, chai_1.expect)(strategySubService_1.sparkEncode.collateralSwitch(...actual)).to.eql(expected);
1712
+ });
1713
+ });
1714
+ });
1616
1715
  });
1617
1716
  describe('When testing strategySubService.aaveV4Encode', () => {
1618
1717
  describe('leverageManagement()', () => {
@@ -429,6 +429,17 @@ export declare const sparkLeverageManagementOnPriceSubData: {
429
429
  targetRatio: number;
430
430
  };
431
431
  };
432
+ export declare const sparkCollateralSwitchSubData: {
433
+ encode(fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, marketAddr: EthereumAddress, amountToSwitch: string, useOnBehalf?: boolean): string[];
434
+ decode(subData: string[]): {
435
+ fromAsset: EthereumAddress;
436
+ fromAssetId: number;
437
+ toAsset: EthereumAddress;
438
+ toAssetId: number;
439
+ marketAddr: EthereumAddress;
440
+ amountToSwitch: string;
441
+ };
442
+ };
432
443
  /**
433
444
  ______ .______ ____ ____ __ __ _______. _______
434
445
  / || _ \ \ \ / / | | | | / || \
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.fluidLeverageManagementSubData = exports.morphoBlueCloseOnPriceSubData = exports.morphoBlueLeverageManagementOnPriceSubData = exports.morphoBlueLeverageManagementSubData = exports.crvUSDPaybackSubData = exports.crvUSDLeverageManagementSubData = exports.sparkLeverageManagementOnPriceSubData = exports.sparkCloseGenericSubData = exports.sparkLeverageManagementSubDataWithoutSubProxy = exports.sparkLeverageManagementSubData = exports.exchangeLimitOrderSubData = exports.exchangeDcaSubData = exports.compoundV3CloseSubData = exports.compoundV3LeverageManagementOnPriceSubData = exports.compoundV3L2LeverageManagementSubData = exports.compoundV3LeverageManagementSubData = 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.aaveV2LeverageManagementSubData = exports.liquityV2PaybackSubData = exports.liquityV2LeverageManagementOnPriceSubData = exports.liquityV2CloseSubData = exports.liquityV2LeverageManagementSubData = exports.liquityDebtInFrontRepaySubData = exports.liquityDsrSupplySubData = exports.liquityDsrPaybackSubData = exports.liquityCloseSubData = exports.liquityLeverageManagementSubData = exports.liquityRepayFromSavingsSubData = exports.makerLeverageManagementWithoutSubProxy = exports.makerLeverageManagementSubData = exports.makerCloseSubData = exports.makerRepayFromSavingsSubData = exports.liquityPaybackUsingChickenBondSubData = exports.cBondsRebondSubData = exports.morphoAaveV2LeverageManagementSubData = void 0;
6
+ exports.fluidLeverageManagementSubData = exports.morphoBlueCloseOnPriceSubData = exports.morphoBlueLeverageManagementOnPriceSubData = exports.morphoBlueLeverageManagementSubData = exports.crvUSDPaybackSubData = exports.crvUSDLeverageManagementSubData = exports.sparkCollateralSwitchSubData = exports.sparkLeverageManagementOnPriceSubData = exports.sparkCloseGenericSubData = exports.sparkLeverageManagementSubDataWithoutSubProxy = exports.sparkLeverageManagementSubData = exports.exchangeLimitOrderSubData = exports.exchangeDcaSubData = exports.compoundV3CloseSubData = exports.compoundV3LeverageManagementOnPriceSubData = exports.compoundV3L2LeverageManagementSubData = exports.compoundV3LeverageManagementSubData = 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.aaveV2LeverageManagementSubData = exports.liquityV2PaybackSubData = exports.liquityV2LeverageManagementOnPriceSubData = exports.liquityV2CloseSubData = exports.liquityV2LeverageManagementSubData = exports.liquityDebtInFrontRepaySubData = exports.liquityDsrSupplySubData = exports.liquityDsrPaybackSubData = exports.liquityCloseSubData = exports.liquityLeverageManagementSubData = exports.liquityRepayFromSavingsSubData = exports.makerLeverageManagementWithoutSubProxy = exports.makerLeverageManagementSubData = exports.makerCloseSubData = exports.makerRepayFromSavingsSubData = exports.liquityPaybackUsingChickenBondSubData = exports.cBondsRebondSubData = exports.morphoAaveV2LeverageManagementSubData = void 0;
7
7
  const decimal_js_1 = __importDefault(require("decimal.js"));
8
8
  const web3_eth_abi_1 = __importDefault(require("web3-eth-abi"));
9
9
  const web3_utils_1 = require("web3-utils");
@@ -990,6 +990,37 @@ exports.sparkLeverageManagementOnPriceSubData = {
990
990
  };
991
991
  },
992
992
  };
993
+ exports.sparkCollateralSwitchSubData = {
994
+ encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, useOnBehalf = false) {
995
+ const encodedFromAsset = web3_eth_abi_1.default.encodeParameter('address', fromAsset);
996
+ const encodedFromAssetId = web3_eth_abi_1.default.encodeParameter('uint8', fromAssetId);
997
+ const encodedToAsset = web3_eth_abi_1.default.encodeParameter('address', toAsset);
998
+ const encodedToAssetId = web3_eth_abi_1.default.encodeParameter('uint8', toAssetId);
999
+ const encodedMarketAddr = web3_eth_abi_1.default.encodeParameter('address', marketAddr);
1000
+ const encodedAmountToSwitch = web3_eth_abi_1.default.encodeParameter('uint256', amountToSwitch);
1001
+ const encodedUseOnBehalf = web3_eth_abi_1.default.encodeParameter('bool', useOnBehalf);
1002
+ return [
1003
+ encodedFromAsset,
1004
+ encodedFromAssetId,
1005
+ encodedToAsset,
1006
+ encodedToAssetId,
1007
+ encodedMarketAddr,
1008
+ encodedAmountToSwitch,
1009
+ encodedUseOnBehalf,
1010
+ ];
1011
+ },
1012
+ decode(subData) {
1013
+ const fromAsset = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
1014
+ const fromAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[1]));
1015
+ const toAsset = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
1016
+ const toAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[3]));
1017
+ const marketAddr = web3_eth_abi_1.default.decodeParameter('address', subData[4]);
1018
+ const amountToSwitch = web3_eth_abi_1.default.decodeParameter('uint256', subData[5]);
1019
+ return {
1020
+ fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch,
1021
+ };
1022
+ },
1023
+ };
993
1024
  /**
994
1025
  ______ .______ ____ ____ __ __ _______. _______
995
1026
  / || _ \ \ \ / / | | | | / || \
@@ -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]: {
@@ -285,6 +285,16 @@ function parseAaveV3CollateralSwitch(position, parseData) {
285
285
  _position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, subData.marketAddr);
286
286
  return _position;
287
287
  }
288
+ function parseSparkCollateralSwitch(position, parseData) {
289
+ const _position = cloneDeep(position);
290
+ const { subStruct } = parseData.subscriptionEventData;
291
+ const triggerData = triggerService.sparkQuotePriceTrigger.decode(subStruct.triggerData);
292
+ const subData = subDataService.sparkCollateralSwitchSubData.decode(subStruct.subData);
293
+ _position.strategyData.decoded.triggerData = triggerData;
294
+ _position.strategyData.decoded.subData = subData;
295
+ _position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, subData.marketAddr);
296
+ return _position;
297
+ }
288
298
  function parseAaveV4LeverageManagement(position, parseData) {
289
299
  const _position = cloneDeep(position);
290
300
  const { subStruct, subId, subHash } = parseData.subscriptionEventData;
@@ -1074,6 +1084,7 @@ const parsingMethodsMapping = {
1074
1084
  [Strategies.Identifiers.RepayOnPrice]: parseSparkLeverageManagementOnPrice,
1075
1085
  [Strategies.Identifiers.BoostOnPrice]: parseSparkLeverageManagementOnPrice,
1076
1086
  [Strategies.Identifiers.CloseOnPrice]: parseSparkCloseOnPrice,
1087
+ [Strategies.Identifiers.CollateralSwitch]: parseSparkCollateralSwitch,
1077
1088
  },
1078
1089
  [ProtocolIdentifiers.StrategiesAutomation.CrvUSD]: {
1079
1090
  [Strategies.Identifiers.Repay]: parseCrvUSDLeverageManagement,
@@ -101,6 +101,7 @@ export declare const sparkEncode: {
101
101
  }): (number | boolean | string[])[];
102
102
  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[])[];
103
103
  leverageManagementWithoutSubProxy(strategyOrBundleId: number, market: EthereumAddress, user: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number): (number | boolean | string[])[];
104
+ 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[])[];
104
105
  };
105
106
  export declare const crvUSDEncode: {
106
107
  leverageManagement(owner: EthereumAddress, controllerAddr: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number, collTokenAddr: EthereumAddress, crvUSDAddr: EthereumAddress): (boolean | string[] | Bundles.MainnetIds)[];
@@ -263,6 +263,12 @@ export const sparkEncode = {
263
263
  const triggerData = triggerService.sparkRatioTrigger.encode(user, market, triggerRatio, ratioState);
264
264
  return [strategyOrBundleId, isBundle, triggerData, subData];
265
265
  },
266
+ collateralSwitch(strategyOrBundleId, fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, baseTokenAddress, quoteTokenAddress, price, state) {
267
+ const isBundle = false;
268
+ const subDataEncoded = subDataService.sparkCollateralSwitchSubData.encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch);
269
+ const triggerDataEncoded = triggerService.sparkQuotePriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, state);
270
+ return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
271
+ },
266
272
  };
267
273
  export const crvUSDEncode = {
268
274
  leverageManagement(owner, controllerAddr, ratioState, targetRatio, triggerRatio, collTokenAddr, crvUSDAddr) {
@@ -1585,6 +1585,105 @@ describe('Feature: strategySubService.ts', () => {
1585
1585
  });
1586
1586
  });
1587
1587
  });
1588
+ describe('collateralSwitch()', () => {
1589
+ const examples = [
1590
+ // WETH -> cbBTC, price 0.025 WETH/cbBTC, state UNDER
1591
+ [
1592
+ [
1593
+ Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
1594
+ false,
1595
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf00000000000000000000000000000000000000000000000000000000002625a00000000000000000000000000000000000000000000000000000000000000001'],
1596
+ [
1597
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1598
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1599
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
1600
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
1601
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
1602
+ '0x0000000000000000000000000000000000000000000000008ac7230489e80000',
1603
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1604
+ ],
1605
+ ],
1606
+ [
1607
+ Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
1608
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1609
+ 0,
1610
+ web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
1611
+ 7,
1612
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
1613
+ '10000000000000000000',
1614
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1615
+ web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
1616
+ 0.025,
1617
+ RatioState.UNDER,
1618
+ ]
1619
+ ],
1620
+ // cbBTC -> WETH, price 25 cbBTC/WETH, state UNDER
1621
+ [
1622
+ [
1623
+ Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
1624
+ false,
1625
+ ['0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000009502f9000000000000000000000000000000000000000000000000000000000000000001'],
1626
+ [
1627
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
1628
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
1629
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1630
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1631
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
1632
+ '0x0000000000000000000000000000000000000000000000000000000005f5e100',
1633
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1634
+ ],
1635
+ ],
1636
+ [
1637
+ Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
1638
+ web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
1639
+ 7,
1640
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1641
+ 0,
1642
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
1643
+ '100000000',
1644
+ web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
1645
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1646
+ 25,
1647
+ RatioState.UNDER,
1648
+ ]
1649
+ ],
1650
+ // cbBTC -> WETH, price 40 cbBTC/WETH, state OVER
1651
+ [
1652
+ [
1653
+ Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
1654
+ false,
1655
+ ['0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000ee6b28000000000000000000000000000000000000000000000000000000000000000000'],
1656
+ [
1657
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
1658
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
1659
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1660
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1661
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
1662
+ '0x0000000000000000000000000000000000000000000000000000000005f5e100',
1663
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1664
+ ],
1665
+ ],
1666
+ [
1667
+ Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
1668
+ web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
1669
+ 7,
1670
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1671
+ 0,
1672
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
1673
+ '100000000',
1674
+ web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
1675
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1676
+ 40,
1677
+ RatioState.OVER,
1678
+ ]
1679
+ ],
1680
+ ];
1681
+ examples.forEach(([expected, actual]) => {
1682
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1683
+ expect(sparkEncode.collateralSwitch(...actual)).to.eql(expected);
1684
+ });
1685
+ });
1686
+ });
1588
1687
  });
1589
1688
  describe('When testing strategySubService.aaveV4Encode', () => {
1590
1689
  describe('leverageManagement()', () => {
@@ -429,6 +429,17 @@ export declare const sparkLeverageManagementOnPriceSubData: {
429
429
  targetRatio: number;
430
430
  };
431
431
  };
432
+ export declare const sparkCollateralSwitchSubData: {
433
+ encode(fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, marketAddr: EthereumAddress, amountToSwitch: string, useOnBehalf?: boolean): string[];
434
+ decode(subData: string[]): {
435
+ fromAsset: EthereumAddress;
436
+ fromAssetId: number;
437
+ toAsset: EthereumAddress;
438
+ toAssetId: number;
439
+ marketAddr: EthereumAddress;
440
+ amountToSwitch: string;
441
+ };
442
+ };
432
443
  /**
433
444
  ______ .______ ____ ____ __ __ _______. _______
434
445
  / || _ \ \ \ / / | | | | / || \
@@ -984,6 +984,37 @@ export const sparkLeverageManagementOnPriceSubData = {
984
984
  };
985
985
  },
986
986
  };
987
+ export const sparkCollateralSwitchSubData = {
988
+ encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, useOnBehalf = false) {
989
+ const encodedFromAsset = AbiCoder.encodeParameter('address', fromAsset);
990
+ const encodedFromAssetId = AbiCoder.encodeParameter('uint8', fromAssetId);
991
+ const encodedToAsset = AbiCoder.encodeParameter('address', toAsset);
992
+ const encodedToAssetId = AbiCoder.encodeParameter('uint8', toAssetId);
993
+ const encodedMarketAddr = AbiCoder.encodeParameter('address', marketAddr);
994
+ const encodedAmountToSwitch = AbiCoder.encodeParameter('uint256', amountToSwitch);
995
+ const encodedUseOnBehalf = AbiCoder.encodeParameter('bool', useOnBehalf);
996
+ return [
997
+ encodedFromAsset,
998
+ encodedFromAssetId,
999
+ encodedToAsset,
1000
+ encodedToAssetId,
1001
+ encodedMarketAddr,
1002
+ encodedAmountToSwitch,
1003
+ encodedUseOnBehalf,
1004
+ ];
1005
+ },
1006
+ decode(subData) {
1007
+ const fromAsset = AbiCoder.decodeParameter('address', subData[0]);
1008
+ const fromAssetId = Number(AbiCoder.decodeParameter('uint8', subData[1]));
1009
+ const toAsset = AbiCoder.decodeParameter('address', subData[2]);
1010
+ const toAssetId = Number(AbiCoder.decodeParameter('uint8', subData[3]));
1011
+ const marketAddr = AbiCoder.decodeParameter('address', subData[4]);
1012
+ const amountToSwitch = AbiCoder.decodeParameter('uint256', subData[5]);
1013
+ return {
1014
+ fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch,
1015
+ };
1016
+ },
1017
+ };
987
1018
  /**
988
1019
  ______ .______ ____ ____ __ __ _______. _______
989
1020
  / || _ \ \ \ / / | | | | / || \
@@ -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",
3
+ "version": "3.3.14",
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 = {
@@ -385,6 +385,17 @@ function parseAaveV3CollateralSwitch(position: Position.Automated, parseData: Pa
385
385
  return _position;
386
386
  }
387
387
 
388
+ function parseSparkCollateralSwitch(position: Position.Automated, parseData: ParseData): Position.Automated {
389
+ const _position = cloneDeep(position);
390
+ const { subStruct } = parseData.subscriptionEventData;
391
+ const triggerData = triggerService.sparkQuotePriceTrigger.decode(subStruct.triggerData);
392
+ const subData = subDataService.sparkCollateralSwitchSubData.decode(subStruct.subData);
393
+ _position.strategyData.decoded.triggerData = triggerData;
394
+ _position.strategyData.decoded.subData = subData;
395
+ _position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, subData.marketAddr);
396
+ return _position;
397
+ }
398
+
388
399
  function parseAaveV4LeverageManagement(position: Position.Automated, parseData: ParseData): Position.Automated {
389
400
  const _position = cloneDeep(position);
390
401
  const { subStruct, subId, subHash } = parseData.subscriptionEventData;
@@ -1386,6 +1397,7 @@ const parsingMethodsMapping: StrategiesToProtocolVersionMapping = {
1386
1397
  [Strategies.Identifiers.RepayOnPrice]: parseSparkLeverageManagementOnPrice,
1387
1398
  [Strategies.Identifiers.BoostOnPrice]: parseSparkLeverageManagementOnPrice,
1388
1399
  [Strategies.Identifiers.CloseOnPrice]: parseSparkCloseOnPrice,
1400
+ [Strategies.Identifiers.CollateralSwitch]: parseSparkCollateralSwitch,
1389
1401
  },
1390
1402
  [ProtocolIdentifiers.StrategiesAutomation.CrvUSD]: {
1391
1403
  [Strategies.Identifiers.Repay]: parseCrvUSDLeverageManagement,
@@ -1892,7 +1892,124 @@ describe('Feature: strategySubService.ts', () => {
1892
1892
  });
1893
1893
  });
1894
1894
  });
1895
+
1896
+ describe('collateralSwitch()', () => {
1897
+ const examples: Array<[
1898
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
1899
+ [
1900
+ strategyOrBundleId: number,
1901
+ fromAsset: EthereumAddress,
1902
+ fromAssetId: number,
1903
+ toAsset: EthereumAddress,
1904
+ toAssetId: number,
1905
+ marketAddr: EthereumAddress,
1906
+ amountToSwitch: string,
1907
+ baseTokenAddress: EthereumAddress,
1908
+ quoteTokenAddress: EthereumAddress,
1909
+ price: number,
1910
+ state: RatioState,
1911
+ ]
1912
+ ]> = [
1913
+ // WETH -> cbBTC, price 0.025 WETH/cbBTC, state UNDER
1914
+ [
1915
+ [
1916
+ Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
1917
+ false,
1918
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf00000000000000000000000000000000000000000000000000000000002625a00000000000000000000000000000000000000000000000000000000000000001'],
1919
+ [
1920
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1921
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1922
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
1923
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
1924
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
1925
+ '0x0000000000000000000000000000000000000000000000008ac7230489e80000',
1926
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1927
+ ],
1928
+ ],
1929
+ [
1930
+ Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
1931
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1932
+ 0,
1933
+ web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
1934
+ 7,
1935
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
1936
+ '10000000000000000000', // 10 WETH
1937
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1938
+ web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
1939
+ 0.025,
1940
+ RatioState.UNDER,
1941
+ ]
1942
+ ],
1943
+ // cbBTC -> WETH, price 25 cbBTC/WETH, state UNDER
1944
+ [
1945
+ [
1946
+ Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
1947
+ false,
1948
+ ['0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000009502f9000000000000000000000000000000000000000000000000000000000000000001'],
1949
+ [
1950
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
1951
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
1952
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1953
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1954
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
1955
+ '0x0000000000000000000000000000000000000000000000000000000005f5e100',
1956
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1957
+ ],
1958
+ ],
1959
+ [
1960
+ Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
1961
+ web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
1962
+ 7,
1963
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1964
+ 0,
1965
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
1966
+ '100000000', // 1 cbBTC (8 decimals)
1967
+ web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
1968
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1969
+ 25,
1970
+ RatioState.UNDER,
1971
+ ]
1972
+ ],
1973
+ // cbBTC -> WETH, price 40 cbBTC/WETH, state OVER
1974
+ [
1975
+ [
1976
+ Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
1977
+ false,
1978
+ ['0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000ee6b28000000000000000000000000000000000000000000000000000000000000000000'],
1979
+ [
1980
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
1981
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
1982
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1983
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1984
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
1985
+ '0x0000000000000000000000000000000000000000000000000000000005f5e100',
1986
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1987
+ ],
1988
+ ],
1989
+ [
1990
+ Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
1991
+ web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
1992
+ 7,
1993
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1994
+ 0,
1995
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
1996
+ '100000000', // 1 cbBTC (8 decimals)
1997
+ web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
1998
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1999
+ 40,
2000
+ RatioState.OVER,
2001
+ ]
2002
+ ],
2003
+ ];
2004
+
2005
+ examples.forEach(([expected, actual]) => {
2006
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
2007
+ expect(sparkEncode.collateralSwitch(...actual)).to.eql(expected);
2008
+ });
2009
+ });
2010
+ });
1895
2011
  });
2012
+
1896
2013
  describe('When testing strategySubService.aaveV4Encode', () => {
1897
2014
  describe('leverageManagement()', () => {
1898
2015
  const examples: Array<[
@@ -642,6 +642,27 @@ export const sparkEncode = {
642
642
 
643
643
  return [strategyOrBundleId, isBundle, triggerData, subData];
644
644
  },
645
+ collateralSwitch(
646
+ strategyOrBundleId: number,
647
+ fromAsset: EthereumAddress,
648
+ fromAssetId: number,
649
+ toAsset: EthereumAddress,
650
+ toAssetId: number,
651
+ marketAddr: EthereumAddress,
652
+ amountToSwitch: string,
653
+ baseTokenAddress: EthereumAddress,
654
+ quoteTokenAddress: EthereumAddress,
655
+ price: number,
656
+ state: RatioState,
657
+ ) {
658
+ const isBundle = false;
659
+
660
+ const subDataEncoded = subDataService.sparkCollateralSwitchSubData.encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch);
661
+ const triggerDataEncoded = triggerService.sparkQuotePriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, state);
662
+
663
+ return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
664
+ },
665
+
645
666
  };
646
667
 
647
668
  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]]> = [
@@ -1330,6 +1330,55 @@ export const sparkLeverageManagementOnPriceSubData = {
1330
1330
  };
1331
1331
  },
1332
1332
  };
1333
+ export const sparkCollateralSwitchSubData = {
1334
+ encode(
1335
+ fromAsset: EthereumAddress,
1336
+ fromAssetId: number,
1337
+ toAsset: EthereumAddress,
1338
+ toAssetId: number,
1339
+ marketAddr: EthereumAddress,
1340
+ amountToSwitch: string,
1341
+ useOnBehalf: boolean = false,
1342
+ ): SubData {
1343
+ const encodedFromAsset = AbiCoder.encodeParameter('address', fromAsset);
1344
+ const encodedFromAssetId = AbiCoder.encodeParameter('uint8', fromAssetId);
1345
+ const encodedToAsset = AbiCoder.encodeParameter('address', toAsset);
1346
+ const encodedToAssetId = AbiCoder.encodeParameter('uint8', toAssetId);
1347
+ const encodedMarketAddr = AbiCoder.encodeParameter('address', marketAddr);
1348
+ const encodedAmountToSwitch = AbiCoder.encodeParameter('uint256', amountToSwitch);
1349
+ const encodedUseOnBehalf = AbiCoder.encodeParameter('bool', useOnBehalf);
1350
+
1351
+ return [
1352
+ encodedFromAsset,
1353
+ encodedFromAssetId,
1354
+ encodedToAsset,
1355
+ encodedToAssetId,
1356
+ encodedMarketAddr,
1357
+ encodedAmountToSwitch,
1358
+ encodedUseOnBehalf,
1359
+ ];
1360
+ },
1361
+ decode(subData: SubData): {
1362
+ fromAsset: EthereumAddress,
1363
+ fromAssetId: number,
1364
+ toAsset: EthereumAddress,
1365
+ toAssetId: number,
1366
+ marketAddr: EthereumAddress,
1367
+ amountToSwitch: string,
1368
+ } {
1369
+ const fromAsset = AbiCoder.decodeParameter('address', subData[0]) as unknown as EthereumAddress;
1370
+ const fromAssetId = Number(AbiCoder.decodeParameter('uint8', subData[1]));
1371
+ const toAsset = AbiCoder.decodeParameter('address', subData[2]) as unknown as EthereumAddress;
1372
+ const toAssetId = Number(AbiCoder.decodeParameter('uint8', subData[3]));
1373
+ const marketAddr = AbiCoder.decodeParameter('address', subData[4]) as unknown as EthereumAddress;
1374
+ const amountToSwitch = AbiCoder.decodeParameter('uint256', subData[5]) as unknown as string;
1375
+
1376
+ return {
1377
+ fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch,
1378
+ };
1379
+ },
1380
+ };
1381
+
1333
1382
 
1334
1383
  /**
1335
1384
  ______ .______ ____ ____ __ __ _______. _______
@@ -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 {