// SPDX-License-Identifier: MIT pragma solidity =0.8.24; import { ISubStorage } from "../../interfaces/core/ISubStorage.sol"; import { StrategyExecutorCommon } from "./StrategyExecutorCommon.sol"; /// @title Main entry point for executing automated strategies contract StrategyExecutor is StrategyExecutorCommon { /// Subscription data hash must match stored subData hash error SubDatHashMismatch(uint256, bytes32, bytes32); /// @notice Checks all the triggers and executes actions /// @dev Only authorized callers can execute it /// @param _subId Id of the subscription /// @param _strategyIndex Which strategy in a bundle, need to specify because when sub is part of a bundle /// @param _triggerCallData All input data needed to execute triggers /// @param _actionsCallData All input data needed to execute actions /// @param _sub StrategySub struct needed because on-chain we store only the hash function executeStrategy( uint256 _subId, uint256 _strategyIndex, bytes[] calldata _triggerCallData, bytes[] calldata _actionsCallData, StrategySub memory _sub ) external { // check bot auth if (!_checkCallerAuth(_subId)) { revert BotNotApproved(msg.sender, _subId); } StoredSubData memory storedSubData = ISubStorage(SUB_STORAGE_ADDR).getSub(_subId); bytes32 subDataHash = keccak256(abi.encode(_sub)); // data sent from the caller must match the stored hash of the data if (subDataHash != storedSubData.strategySubHash) { revert SubDatHashMismatch(_subId, subDataHash, storedSubData.strategySubHash); } // subscription must be enabled if (!storedSubData.isEnabled) { revert SubNotEnabled(_subId); } // execute actions _callActions( _subId, _actionsCallData, _triggerCallData, _strategyIndex, _sub, address(storedSubData.walletAddr) ); } }