账户
0x14...58a7
0x14...58a7

0x14...58a7

$500
此合同的源代码已经过验证!
合同元数据
编译器
0.8.26+commit.8a97fa7a
语言
Solidity
合同源代码
文件 1 的 27:Address.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Address.sol)

pragma solidity ^0.8.20;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev The ETH balance of the account is not enough to perform the operation.
     */
    error AddressInsufficientBalance(address account);

    /**
     * @dev There's no code at `target` (it is not a contract).
     */
    error AddressEmptyCode(address target);

    /**
     * @dev A call to an address target failed. The target may have reverted.
     */
    error FailedInnerCall();

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        if (address(this).balance < amount) {
            revert AddressInsufficientBalance(address(this));
        }

        (bool success, ) = recipient.call{value: amount}("");
        if (!success) {
            revert FailedInnerCall();
        }
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason or custom error, it is bubbled
     * up by this function (like regular Solidity function calls). However, if
     * the call reverted with no returned reason, this function reverts with a
     * {FailedInnerCall} error.
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
        if (address(this).balance < value) {
            revert AddressInsufficientBalance(address(this));
        }
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
     * was not a contract or bubbling up the revert reason (falling back to {FailedInnerCall}) in case of an
     * unsuccessful call.
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata
    ) internal view returns (bytes memory) {
        if (!success) {
            _revert(returndata);
        } else {
            // only check if target is a contract if the call was successful and the return data is empty
            // otherwise we already know that it was a contract
            if (returndata.length == 0 && target.code.length == 0) {
                revert AddressEmptyCode(target);
            }
            return returndata;
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
     * revert reason or with a default {FailedInnerCall} error.
     */
    function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
        if (!success) {
            _revert(returndata);
        } else {
            return returndata;
        }
    }

    /**
     * @dev Reverts with returndata if present. Otherwise reverts with {FailedInnerCall}.
     */
    function _revert(bytes memory returndata) private pure {
        // Look for revert reason and bubble it up if present
        if (returndata.length > 0) {
            // The easiest way to bubble the revert reason is using memory via assembly
            /// @solidity memory-safe-assembly
            assembly {
                let returndata_size := mload(returndata)
                revert(add(32, returndata), returndata_size)
            }
        } else {
            revert FailedInnerCall();
        }
    }
}
合同源代码
文件 2 的 27:Cast.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

library Cast {
    function _toBytes32(address value) internal pure returns (bytes32) {
        return bytes32(uint256(uint160(value)));
    }
}
合同源代码
文件 3 的 27:Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)

pragma solidity ^0.8.20;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }

    function _contextSuffixLength() internal view virtual returns (uint256) {
        return 0;
    }
}
合同源代码
文件 4 的 27:ControlCenter.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

import {IERC165} from "@openzeppelin/contracts/interfaces/IERC165.sol";
import {ControlCenterEventUtils} from "./ControlCenterEventUtils.sol";
import {Errors} from "../error/Errors.sol";
import {IControlCenter} from "../interfaces/IControlCenter.sol";
import {EventEmitter} from "../event/EventEmitter.sol";
import {IKnightSafeAnalyser} from "../interfaces/IKnightSafeAnalyser.sol";
import {SettingSelectors} from "../setting/SettingUtils.sol";

/// @notice inherit Doc {IControlCenter}
contract ControlCenter is IControlCenter, EventEmitter {
    /// @inheritdoc IControlCenter
    string public constant override VERSION = "0.0.0";

    struct AccountLimit {
        uint256 dailyLimit;
        uint256 dailyLimitExpiryDate;
        uint256 volume;
        uint256 volumeExpiryDate;
    }

    mapping(address => bool) private _adminMap;

    address private _priceFeed;
    uint256 public baseTradingVolume = 100_000 * (10 ** 30); // 100,000 USD for Retail plan
    uint256 public _minPolicyAllowed = 3;

    mapping(address => AccountLimit) private _tradingLimitMap;

    mapping(address => bytes32) private _controlCenterVersionMap;
    mapping(address => bytes32) private _knightSafeVersionMap;
    mapping(address => bytes32) private _analyserVersionMap;
    mapping(address => bool) private _spendingLimitMap;
    mapping(address => uint256) private _maxPolicyAllowedMap;
    bytes4[8] private _adminEventAccess = [
        SettingSelectors.CREATE_POLICY,
        SettingSelectors.UPDATE_WHITELIST,
        SettingSelectors.ADD_TRADER,
        SettingSelectors.REMOVE_POLICY,
        SettingSelectors.REMOVE_TRADER,
        SettingSelectors.REMOVE_WHITELIST,
        SettingSelectors.INCREASE_SPENDING_LIMIT,
        SettingSelectors.RESET_SPENDING_LIMIT
    ];

    constructor(address owner) EventEmitter(owner) {
        _adminMap[owner] = true;
        _analyserVersionMap[address(0)] = "0x0";
        _analyserVersionMap[address(1)] = "0x1";
    }

    modifier onlyAdmin() {
        if (owner() != _msgSender() && !_checkAdmin()) revert Errors.Unauthorized(_msgSender(), "ADMIN");
        _;
    }

    function _checkAdmin() private view returns (bool) {
        return _adminMap[_msgSender()];
    }

    /// @inheritdoc IControlCenter
    function setAdmin(address admin, bool isAdmin) public onlyOwner {
        _adminMap[admin] = isAdmin;
        ControlCenterEventUtils.emitSetAdmin(this, admin, isAdmin);
    }

    /// @inheritdoc IControlCenter
    function isOfficialControlCenter(address controlCenterAddress) public view returns (bool) {
        return _controlCenterVersionMap[controlCenterAddress] != 0;
    }

    /// @inheritdoc IControlCenter
    function addOfficialControlCenter(address controlCenterAddress, bytes32 version) public onlyOwner {
        if (isOfficialControlCenter(controlCenterAddress)) revert Errors.AddressAlreadyExist(controlCenterAddress);
        if (version == 0) revert Errors.IsNullValue();
        _controlCenterVersionMap[controlCenterAddress] = version;

        ControlCenterEventUtils.emitAddedOfficialControlCenter(this, controlCenterAddress, version);
    }

    /// @inheritdoc IControlCenter
    function removeOfficialControlCenter(address controlCenterAddress) public onlyOwner {
        if (!isOfficialControlCenter(controlCenterAddress)) revert Errors.AddressNotExist(controlCenterAddress);
        _controlCenterVersionMap[controlCenterAddress] = 0;

        ControlCenterEventUtils.emitRemovedOfficialControlCenter(this, controlCenterAddress);
    }

    /// @inheritdoc IControlCenter
    function isOfficialImplementation(address implementationAddress) public view returns (bool) {
        return _knightSafeVersionMap[implementationAddress] != 0;
    }

    /// @inheritdoc IControlCenter
    function addOfficialImplementation(address implementationAddress, bytes32 version) public onlyOwner {
        if (isOfficialImplementation(implementationAddress)) revert Errors.AddressAlreadyExist(implementationAddress);
        if (version == 0) revert Errors.IsNullValue();
        _knightSafeVersionMap[implementationAddress] = version;

        ControlCenterEventUtils.emitAddedOfficialImplementation(this, implementationAddress, version);
    }

    /// @inheritdoc IControlCenter
    function removeOfficialImplementation(address implementationAddress) public onlyOwner {
        if (!isOfficialImplementation(implementationAddress)) revert Errors.AddressNotExist(implementationAddress);
        _knightSafeVersionMap[implementationAddress] = 0;

        ControlCenterEventUtils.emitRemovedOfficialImplementation(this, implementationAddress);
    }

    /// @inheritdoc IControlCenter
    function isOfficialAnalyser(address analyserAddress) public view returns (bool) {
        return _analyserVersionMap[analyserAddress] != 0;
    }

    /// @inheritdoc IControlCenter
    function addOfficialAnalyser(address analyserAddress, bytes32 version) public onlyAdmin {
        if (isOfficialAnalyser(analyserAddress)) revert Errors.AddressAlreadyExist(analyserAddress);
        if (version == 0) revert Errors.IsNullValue();
        if (!_isKnightSafeAnalyser(analyserAddress)) {
            revert Errors.InterfaceNotSupport(analyserAddress);
        }

        _analyserVersionMap[analyserAddress] = version;

        ControlCenterEventUtils.emitAddedOfficialAnalyser(this, analyserAddress, version);
    }

    /// @inheritdoc IControlCenter
    function removeOfficialAnalyser(address analyserAddress) public onlyAdmin {
        if (!isOfficialAnalyser(analyserAddress)) revert Errors.AddressNotExist(analyserAddress);
        _analyserVersionMap[analyserAddress] = 0;

        ControlCenterEventUtils.emitRemoveOfficialAnalyser(this, analyserAddress);
    }

    /// @inheritdoc IControlCenter
    function isSpendingLimitEnabled(address knightSafeAddress) public view returns (bool) {
        return _spendingLimitMap[knightSafeAddress];
    }

    /// @inheritdoc IControlCenter
    function setSpendingLimitEnabled(address knightSafeAddress, bool isEnabled) public onlyAdmin {
        _spendingLimitMap[knightSafeAddress] = isEnabled;
        ControlCenterEventUtils.emitSetSpendingLimitEnabled(this, knightSafeAddress, isEnabled);
    }

    /// @inheritdoc IControlCenter
    function getMaxPolicyAllowed(address knightSafeAddress) public view returns (uint256) {
        return _maxPolicyAllowedMap[knightSafeAddress] > _minPolicyAllowed
            ? _maxPolicyAllowedMap[knightSafeAddress]
            : _minPolicyAllowed;
    }

    /// @inheritdoc IControlCenter
    function setMaxPolicyAllowed(address knightSafeAddress, uint256 maxPolicyAllowed) public onlyAdmin {
        _maxPolicyAllowedMap[knightSafeAddress] = maxPolicyAllowed;

        ControlCenterEventUtils.emitSetMaxPolicyAllowed(this, knightSafeAddress, maxPolicyAllowed);
    }

    /// @inheritdoc IControlCenter
    function setGlobalMinPolicyAllowed(uint256 minPolicyAllowed) public onlyOwner {
        _minPolicyAllowed = minPolicyAllowed;

        ControlCenterEventUtils.emitSetGlobalMinPolicyAllowed(this, minPolicyAllowed);
    }

    /// @inheritdoc IControlCenter
    function getAdminEventAccess() external view returns (bytes4[] memory) {
        bytes4[] memory eventList = new bytes4[](_adminEventAccess.length);
        for (uint256 i = 0; i < _adminEventAccess.length; i++) {
            eventList[i] = _adminEventAccess[i];
        }
        return eventList;
    }

    /// @inheritdoc IControlCenter
    function getAdminEventAccessCount() external view returns (uint256) {
        return _adminEventAccess.length;
    }

    /// @inheritdoc IControlCenter
    function getAdminEventAccessById(uint8 id) public view returns (bytes4) {
        return _adminEventAccess[id];
    }

    function _isKnightSafeAnalyser(address _address) internal view returns (bool) {
        bytes memory encodedParams = abi.encodeCall(IERC165.supportsInterface, (type(IKnightSafeAnalyser).interfaceId)); // to be updated with constant

        bool success;
        uint256 returnSize;
        uint256 returnValue;

        /* solhint-disable no-inline-assembly */
        assembly {
            success := staticcall(30000, _address, add(encodedParams, 0x20), mload(encodedParams), 0x00, 0x20)
            returnSize := returndatasize()
            returnValue := mload(0x00)
        }

        return success && returnSize >= 0x20 && returnValue > 0;
    }

    /// @inheritdoc IControlCenter
    function setPriceFeed(address priceFeed) public onlyOwner {
        isKnightSafe[_priceFeed] = false;

        _priceFeed = priceFeed;
        isKnightSafe[priceFeed] = true;

        ControlCenterEventUtils.emitSetPriceFeed(this, priceFeed);
    }

    /// @inheritdoc IControlCenter
    function getPriceFeed() public view returns (address) {
        return _priceFeed;
    }

    /// @inheritdoc IControlCenter
    function setBaseVolume(uint256 volume) public onlyOwner {
        if (volume == 0) revert Errors.IsNullValue();
        baseTradingVolume = volume;

        ControlCenterEventUtils.emitSetBaseLimit(this, volume);
    }

    /// @inheritdoc IControlCenter
    function getDailyVolume(address knightSafeAddress) public view returns (uint256) {
        if (
            _tradingLimitMap[knightSafeAddress].dailyLimitExpiryDate < block.timestamp
                || _tradingLimitMap[knightSafeAddress].dailyLimit < baseTradingVolume
        ) {
            return baseTradingVolume;
        }
        return _tradingLimitMap[knightSafeAddress].dailyLimit;
    }

    /// @inheritdoc IControlCenter
    function setDailyVolume(address knightSafeAddress, uint256 volume) public onlyAdmin {
        _tradingLimitMap[knightSafeAddress].dailyLimit = volume;

        ControlCenterEventUtils.emitSetDailyLimit(this, knightSafeAddress, volume);
    }

    /// @inheritdoc IControlCenter
    function setDailyVolumeExpiryDate(address knightSafeAddress, uint256 expiryDate) public onlyAdmin {
        _tradingLimitMap[knightSafeAddress].dailyLimitExpiryDate = expiryDate;

        ControlCenterEventUtils.emitSetDailyLimitExpiry(this, knightSafeAddress, expiryDate);
    }

    /// @inheritdoc IControlCenter
    function setMaxTradingVolume(address knightSafeAddress, uint256 volume) public onlyAdmin {
        _tradingLimitMap[knightSafeAddress].volume = volume;

        ControlCenterEventUtils.emitSetMaxTradingVolume(this, knightSafeAddress, volume);
    }

    /// @inheritdoc IControlCenter
    function setMaxTradingVolumeExpiryDate(address knightSafeAddress, uint256 expiryDate) public onlyAdmin {
        _tradingLimitMap[knightSafeAddress].volumeExpiryDate = expiryDate;

        ControlCenterEventUtils.emitSetMaxTradingVolumeExpiry(this, knightSafeAddress, expiryDate);
    }

    /// @inheritdoc IControlCenter
    function getMaxTradingVolume(address knightSafeAddress) public view returns (uint256) {
        if (_tradingLimitMap[knightSafeAddress].volumeExpiryDate < block.timestamp) {
            return 0;
        }
        return _tradingLimitMap[knightSafeAddress].volume;
    }

    /// @inheritdoc IControlCenter
    function getMaxVolumeExpiryDate(address knightSafeAddress) public view returns (uint256) {
        return _tradingLimitMap[knightSafeAddress].volumeExpiryDate;
    }
}
合同源代码
文件 5 的 27:ControlCenterEventUtils.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

import {EventUtils} from "../event/EventUtils.sol";
import {EventEmitter} from "../event/EventEmitter.sol";
import {Cast} from "../utils/Cast.sol";

library ControlCenterEventUtils {
    using EventUtils for EventUtils.AddressItems;
    using EventUtils for EventUtils.UintItems;
    using EventUtils for EventUtils.BytesItems;
    using EventUtils for EventUtils.Bytes32Items;
    using EventUtils for EventUtils.BoolItems;

    function emitSetAdmin(EventEmitter eventEmitter, address _admin, bool _isAdmin) external {
        EventUtils.EventLogData memory eventData;
        eventData.addressItems.initItems(1);
        eventData.addressItems.setItem(0, "admin", _admin);
        eventData.boolItems.initItems(1);
        eventData.boolItems.setItem(0, "isAdmin", _isAdmin);

        eventEmitter.emitEventLog1("SetAdmin", Cast._toBytes32(_admin), eventData);
    }

    function emitAddedOfficialControlCenter(EventEmitter eventEmitter, address controlCenterAddress, bytes32 version)
        external
    {
        EventUtils.EventLogData memory eventData;
        eventData.bytes32Items.initItems(1);
        eventData.bytes32Items.setItem(0, "version", version);

        eventEmitter.emitEventLog1("AddedOfficialControlCenter", Cast._toBytes32(controlCenterAddress), eventData);
    }

    function emitRemovedOfficialControlCenter(EventEmitter eventEmitter, address controlCenterAddress) external {
        EventUtils.EventLogData memory eventData;

        eventEmitter.emitEventLog1("RemovedOfficialControlCenter", Cast._toBytes32(controlCenterAddress), eventData);
    }

    function emitAddedOfficialImplementation(EventEmitter eventEmitter, address implementationAddress, bytes32 version)
        external
    {
        EventUtils.EventLogData memory eventData;
        eventData.bytes32Items.initItems(1);
        eventData.bytes32Items.setItem(0, "version", version);

        eventEmitter.emitEventLog1("AddedOfficialImplementation", Cast._toBytes32(implementationAddress), eventData);
    }

    function emitRemovedOfficialImplementation(EventEmitter eventEmitter, address implementationAddress) external {
        EventUtils.EventLogData memory eventData;

        eventEmitter.emitEventLog1("RemovedOfficialImplementation", Cast._toBytes32(implementationAddress), eventData);
    }

    function emitAddedOfficialAnalyser(EventEmitter eventEmitter, address analyser, bytes32 version) external {
        EventUtils.EventLogData memory eventData;
        eventData.bytes32Items.initItems(1);
        eventData.bytes32Items.setItem(0, "version", version);

        eventEmitter.emitEventLog1("AddedOfficialAnalyser", Cast._toBytes32(analyser), eventData);
    }

    function emitRemoveOfficialAnalyser(EventEmitter eventEmitter, address analyser) external {
        EventUtils.EventLogData memory eventData;

        eventEmitter.emitEventLog1("RemoveOfficialAnalyser", Cast._toBytes32(analyser), eventData);
    }

    function emitSetSpendingLimitEnabled(EventEmitter eventEmitter, address knightSafeAddress, bool _isSpendingLimit)
        external
    {
        EventUtils.EventLogData memory eventData;
        eventData.addressItems.initItems(1);
        eventData.addressItems.setItem(0, "knightSafeAddress", knightSafeAddress);
        eventData.boolItems.initItems(1);
        eventData.boolItems.setItem(0, "isSpendingLimit", _isSpendingLimit);

        eventEmitter.emitEventLog1("SetSpendingLimitEnabled", Cast._toBytes32(knightSafeAddress), eventData);
    }

    function emitSetMaxPolicyAllowed(EventEmitter eventEmitter, address knightSafeAddress, uint256 _maxPolicyAllowed)
        external
    {
        EventUtils.EventLogData memory eventData;
        eventData.addressItems.initItems(1);
        eventData.addressItems.setItem(0, "knightSafeAddress", knightSafeAddress);
        eventData.uintItems.initItems(1);
        eventData.uintItems.setItem(0, "maxPolicyAllowed", _maxPolicyAllowed);

        eventEmitter.emitEventLog1("SetMaxPolicyAllowed", Cast._toBytes32(knightSafeAddress), eventData);
    }

    function emitSetGlobalMinPolicyAllowed(EventEmitter eventEmitter, uint256 _maxPolicyAllowed) external {
        EventUtils.EventLogData memory eventData;
        eventData.uintItems.initItems(1);
        eventData.uintItems.setItem(0, "maxPolicyAllowed", _maxPolicyAllowed);

        eventEmitter.emitEventLog("SetGlobalMinPolicyAllowed", eventData);
    }

    function emitSetPriceFeed(EventEmitter eventEmitter, address priceFeed) external {
        EventUtils.EventLogData memory eventData;
        eventData.addressItems.initItems(1);
        eventData.addressItems.setItem(0, "priceFeed", priceFeed);

        eventEmitter.emitEventLog("SetPriceFeed", eventData);
    }

    function emitSetBaseLimit(EventEmitter eventEmitter, uint256 volume) external {
        EventUtils.EventLogData memory eventData;
        eventData.uintItems.initItems(1);
        eventData.uintItems.setItem(0, "baseLimit", volume);

        eventEmitter.emitEventLog1("SetBaseLimit", Cast._toBytes32(msg.sender), eventData);
    }

    function emitSetDailyLimit(EventEmitter eventEmitter, address knightSafeAddress, uint256 volume) external {
        EventUtils.EventLogData memory eventData;
        eventData.addressItems.initItems(1);
        eventData.addressItems.setItem(0, "knightSafeAddress", knightSafeAddress);
        eventData.uintItems.initItems(1);
        eventData.uintItems.setItem(0, "dailyLimit", volume);

        eventEmitter.emitEventLog1("SetDailyLimit", Cast._toBytes32(knightSafeAddress), eventData);
    }

    function emitSetDailyLimitExpiry(EventEmitter eventEmitter, address knightSafeAddress, uint256 expirationDate)
        external
    {
        EventUtils.EventLogData memory eventData;
        eventData.addressItems.initItems(1);
        eventData.addressItems.setItem(0, "knightSafeAddress", knightSafeAddress);
        eventData.uintItems.initItems(1);
        eventData.uintItems.setItem(0, "expirationDate", expirationDate);

        eventEmitter.emitEventLog1("SetDailyLimitExpiry", Cast._toBytes32(knightSafeAddress), eventData);
    }

    function emitSetMaxTradingVolume(EventEmitter eventEmitter, address knightSafeAddress, uint256 maxTradingVolume)
        external
    {
        EventUtils.EventLogData memory eventData;
        eventData.addressItems.initItems(1);
        eventData.addressItems.setItem(0, "knightSafeAddress", knightSafeAddress);
        eventData.uintItems.initItems(1);
        eventData.uintItems.setItem(0, "maxTradingVolume", maxTradingVolume);

        eventEmitter.emitEventLog1("SetMaxTradingVolume", Cast._toBytes32(knightSafeAddress), eventData);
    }

    function emitSetMaxTradingVolumeExpiry(EventEmitter eventEmitter, address knightSafeAddress, uint256 expirationDate)
        external
    {
        EventUtils.EventLogData memory eventData;
        eventData.addressItems.initItems(1);
        eventData.addressItems.setItem(0, "knightSafeAddress", knightSafeAddress);
        eventData.uintItems.initItems(1);
        eventData.uintItems.setItem(0, "expirationDate", expirationDate);

        eventEmitter.emitEventLog1("SetMaxTradingVolumeExpiry", Cast._toBytes32(knightSafeAddress), eventData);
    }
}
合同源代码
文件 6 的 27:ControlCenterManager.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.8.20;

import {ControlCenter} from "../controlCenter/ControlCenter.sol";
import {Errors} from "../error/Errors.sol";
import "../common/TokenCallbackHandler.sol";

abstract contract ControlCenterManager {
    ControlCenter internal _controlCenter;

    function _setControlCenter(address addr) internal {
        if (addr == address(0)) revert Errors.InvalidAddress(addr);
        _controlCenter = ControlCenter(addr);
    }

    function getControlCenter() public view returns (address) {
        return address(_controlCenter);
    }
}
合同源代码
文件 7 的 27:ERC1967Utils.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/ERC1967/ERC1967Utils.sol)

pragma solidity ^0.8.20;

import {IBeacon} from "../beacon/IBeacon.sol";
import {Address} from "../../utils/Address.sol";
import {StorageSlot} from "../../utils/StorageSlot.sol";

/**
 * @dev This abstract contract provides getters and event emitting update functions for
 * https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots.
 */
library ERC1967Utils {
    // We re-declare ERC-1967 events here because they can't be used directly from IERC1967.
    // This will be fixed in Solidity 0.8.21. At that point we should remove these events.
    /**
     * @dev Emitted when the implementation is upgraded.
     */
    event Upgraded(address indexed implementation);

    /**
     * @dev Emitted when the admin account has changed.
     */
    event AdminChanged(address previousAdmin, address newAdmin);

    /**
     * @dev Emitted when the beacon is changed.
     */
    event BeaconUpgraded(address indexed beacon);

    /**
     * @dev Storage slot with the address of the current implementation.
     * This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1.
     */
    // solhint-disable-next-line private-vars-leading-underscore
    bytes32 internal constant IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;

    /**
     * @dev The `implementation` of the proxy is invalid.
     */
    error ERC1967InvalidImplementation(address implementation);

    /**
     * @dev The `admin` of the proxy is invalid.
     */
    error ERC1967InvalidAdmin(address admin);

    /**
     * @dev The `beacon` of the proxy is invalid.
     */
    error ERC1967InvalidBeacon(address beacon);

    /**
     * @dev An upgrade function sees `msg.value > 0` that may be lost.
     */
    error ERC1967NonPayable();

    /**
     * @dev Returns the current implementation address.
     */
    function getImplementation() internal view returns (address) {
        return StorageSlot.getAddressSlot(IMPLEMENTATION_SLOT).value;
    }

    /**
     * @dev Stores a new address in the EIP1967 implementation slot.
     */
    function _setImplementation(address newImplementation) private {
        if (newImplementation.code.length == 0) {
            revert ERC1967InvalidImplementation(newImplementation);
        }
        StorageSlot.getAddressSlot(IMPLEMENTATION_SLOT).value = newImplementation;
    }

    /**
     * @dev Performs implementation upgrade with additional setup call if data is nonempty.
     * This function is payable only if the setup call is performed, otherwise `msg.value` is rejected
     * to avoid stuck value in the contract.
     *
     * Emits an {IERC1967-Upgraded} event.
     */
    function upgradeToAndCall(address newImplementation, bytes memory data) internal {
        _setImplementation(newImplementation);
        emit Upgraded(newImplementation);

        if (data.length > 0) {
            Address.functionDelegateCall(newImplementation, data);
        } else {
            _checkNonPayable();
        }
    }

    /**
     * @dev Storage slot with the admin of the contract.
     * This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1.
     */
    // solhint-disable-next-line private-vars-leading-underscore
    bytes32 internal constant ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;

    /**
     * @dev Returns the current admin.
     *
     * TIP: To get this value clients can read directly from the storage slot shown below (specified by EIP1967) using
     * the https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call.
     * `0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103`
     */
    function getAdmin() internal view returns (address) {
        return StorageSlot.getAddressSlot(ADMIN_SLOT).value;
    }

    /**
     * @dev Stores a new address in the EIP1967 admin slot.
     */
    function _setAdmin(address newAdmin) private {
        if (newAdmin == address(0)) {
            revert ERC1967InvalidAdmin(address(0));
        }
        StorageSlot.getAddressSlot(ADMIN_SLOT).value = newAdmin;
    }

    /**
     * @dev Changes the admin of the proxy.
     *
     * Emits an {IERC1967-AdminChanged} event.
     */
    function changeAdmin(address newAdmin) internal {
        emit AdminChanged(getAdmin(), newAdmin);
        _setAdmin(newAdmin);
    }

    /**
     * @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy.
     * This is the keccak-256 hash of "eip1967.proxy.beacon" subtracted by 1.
     */
    // solhint-disable-next-line private-vars-leading-underscore
    bytes32 internal constant BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;

    /**
     * @dev Returns the current beacon.
     */
    function getBeacon() internal view returns (address) {
        return StorageSlot.getAddressSlot(BEACON_SLOT).value;
    }

    /**
     * @dev Stores a new beacon in the EIP1967 beacon slot.
     */
    function _setBeacon(address newBeacon) private {
        if (newBeacon.code.length == 0) {
            revert ERC1967InvalidBeacon(newBeacon);
        }

        StorageSlot.getAddressSlot(BEACON_SLOT).value = newBeacon;

        address beaconImplementation = IBeacon(newBeacon).implementation();
        if (beaconImplementation.code.length == 0) {
            revert ERC1967InvalidImplementation(beaconImplementation);
        }
    }

    /**
     * @dev Change the beacon and trigger a setup call if data is nonempty.
     * This function is payable only if the setup call is performed, otherwise `msg.value` is rejected
     * to avoid stuck value in the contract.
     *
     * Emits an {IERC1967-BeaconUpgraded} event.
     *
     * CAUTION: Invoking this function has no effect on an instance of {BeaconProxy} since v5, since
     * it uses an immutable beacon without looking at the value of the ERC-1967 beacon slot for
     * efficiency.
     */
    function upgradeBeaconToAndCall(address newBeacon, bytes memory data) internal {
        _setBeacon(newBeacon);
        emit BeaconUpgraded(newBeacon);

        if (data.length > 0) {
            Address.functionDelegateCall(IBeacon(newBeacon).implementation(), data);
        } else {
            _checkNonPayable();
        }
    }

    /**
     * @dev Reverts if `msg.value` is not zero. It can be used to avoid `msg.value` stuck in the contract
     * if an upgrade doesn't perform an initialization call.
     */
    function _checkNonPayable() private {
        if (msg.value > 0) {
            revert ERC1967NonPayable();
        }
    }
}
合同源代码
文件 8 的 27:Errors.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

library Errors {
    error FailedDeployment();

    error InvalidOperation();
    error Unauthorized(address msgSender, string role);

    error InvalidAddress(address _address);
    error AddressAlreadyExist(address _address);
    error AddressNotExist(address _address);

    error IsNullValue();
    error InvalidLength();
    error InvalidValue();

    // error PolicyAlreadyExist(uint256 policyId);
    error PolicyNotExist(uint256 policyId);
    error MaxPolicyCountReached(uint256 maxPolicyCount);
    // error PolicyWhitelistAddressNotFound(address _address);

    error InvalidTakeoverStatus(bool inProgress);
    error TakeoverIsNotReady();

    error InvalidReqId(uint256 reqId);
    error InvalidTransactionStatus();
    error InvalidSettingStatus();

    error InterfaceNotSupport(address _address);
    error AddressIsNotKnightSafeImplementation(address _address);
    error AddressIsNotKnightSafeAnalyser(address _address);
    error AddressIsReadOnlyWhitelist(uint256 policyId, address _address);
    error AddressNotInWhitelist(uint256 policyId, address _address);
    error SelectorNotSupport();
    error ExceedMaxTradingVolume(uint256 txnVolume, uint256 maxVolume);
    error ExceedPolicyVolume(uint256 policyId, uint256 volume);

    error ExecutionFailed();
    error ExecutionFailedWith(bytes data);
    error FeatureNotSupport(string plan);
}
合同源代码
文件 9 的 27:EventEmitter.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.8.20;

import {Context} from "@openzeppelin/contracts/utils/Context.sol";
import {Ownable2Step, Ownable} from "@openzeppelin/contracts/access/Ownable2Step.sol";
import {Errors} from "../error/Errors.sol";
import {IEventEmitter, EventUtils} from "../interfaces/IEventEmitter.sol";

/// @notice inherit Doc {IEventEmitter}
abstract contract EventEmitter is IEventEmitter, Context, Ownable2Step {
    mapping(address => bool) private _factory;
    mapping(address => bool) internal isKnightSafe;

    constructor(address owner) Ownable(owner) {}

    modifier onlyKnightSafe() {
        if (!isActiveAccount(_msgSender()) && !isFactory(_msgSender()) && _msgSender() != address(this)) {
            revert Errors.Unauthorized(_msgSender(), "KNIGHTSAFE");
        }
        _;
    }

    /// @inheritdoc IEventEmitter
    function isFactory(address sender) public view returns (bool) {
        return _factory[sender];
    }

    /// @inheritdoc IEventEmitter
    function setFactory(address factory) public onlyOwner {
        _factory[factory] = true;
    }

    /// @inheritdoc IEventEmitter
    function disableFactory(address factory) public onlyOwner {
        _factory[factory] = false;
    }

    /// @inheritdoc IEventEmitter
    function isActiveAccount(address sender) public view returns (bool) {
        return isKnightSafe[sender];
    }

    /// @inheritdoc IEventEmitter
    function setActiveAccount(address sender) public {
        if (!isFactory(_msgSender())) {
            revert Errors.Unauthorized(_msgSender(), "FACTORY");
        }
        isKnightSafe[sender] = true;
    }

    /// @inheritdoc IEventEmitter
    function disableActiveAccount(address sender) public onlyOwner {
        isKnightSafe[sender] = false;
    }

    /// @inheritdoc IEventEmitter
    function emitEventLog(string memory eventName, EventUtils.EventLogData memory eventData) external onlyKnightSafe {
        emit EventLog((address(_msgSender())), eventName, eventName, eventData);
    }

    /// @inheritdoc IEventEmitter
    function emitEventLog1(string memory eventName, bytes32 profile, EventUtils.EventLogData memory eventData)
        external
        onlyKnightSafe
    {
        emit EventLog1((address(_msgSender())), eventName, eventName, profile, eventData);
    }

    /// @inheritdoc IEventEmitter
    function emitEventLog2(
        string memory eventName,
        bytes32 profile,
        bytes32 topic2,
        EventUtils.EventLogData memory eventData
    ) external onlyKnightSafe {
        emit EventLog2((address(_msgSender())), eventName, eventName, profile, topic2, eventData);
    }

    function emitTransactionEventLog(string memory eventName, bytes32 profile, uint256 reqId) external onlyKnightSafe {
        emit TransactionEventLog((address(_msgSender())), eventName, eventName, profile, reqId);
    }

    function emitSettingEventLog(string memory eventName, bytes32 profile, uint256 reqId) external onlyKnightSafe {
        emit SettingEventLog((address(_msgSender())), eventName, eventName, profile, reqId);
    }

    /**
     * @dev Disable owner renounce ownership
     */
    function renounceOwnership() public virtual override onlyOwner {
        // do nothing
    }
}
合同源代码
文件 10 的 27:EventUtils.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.8.0;

/* solhint-disable */
library EventUtils {
    struct EventLogData {
        AddressItems addressItems;
        UintItems uintItems;
        IntItems intItems;
        BoolItems boolItems;
        Bytes32Items bytes32Items;
        BytesItems bytesItems;
        StringItems stringItems;
    }

    struct AddressItems {
        AddressKeyValue[] items;
        AddressArrayKeyValue[] arrayItems;
    }

    struct UintItems {
        UintKeyValue[] items;
        UintArrayKeyValue[] arrayItems;
    }

    struct IntItems {
        IntKeyValue[] items;
        IntArrayKeyValue[] arrayItems;
    }

    struct BoolItems {
        BoolKeyValue[] items;
        BoolArrayKeyValue[] arrayItems;
    }

    struct Bytes32Items {
        Bytes32KeyValue[] items;
        Bytes32ArrayKeyValue[] arrayItems;
    }

    struct BytesItems {
        BytesKeyValue[] items;
        BytesArrayKeyValue[] arrayItems;
    }

    struct StringItems {
        StringKeyValue[] items;
        StringArrayKeyValue[] arrayItems;
    }

    struct AddressKeyValue {
        string key;
        address value;
    }

    struct AddressArrayKeyValue {
        string key;
        address[] value;
    }

    struct UintKeyValue {
        string key;
        uint256 value;
    }

    struct UintArrayKeyValue {
        string key;
        uint256[] value;
    }

    struct IntKeyValue {
        string key;
        int256 value;
    }

    struct IntArrayKeyValue {
        string key;
        int256[] value;
    }

    struct BoolKeyValue {
        string key;
        bool value;
    }

    struct BoolArrayKeyValue {
        string key;
        bool[] value;
    }

    struct Bytes32KeyValue {
        string key;
        bytes32 value;
    }

    struct Bytes32ArrayKeyValue {
        string key;
        bytes32[] value;
    }

    struct BytesKeyValue {
        string key;
        bytes value;
    }

    struct BytesArrayKeyValue {
        string key;
        bytes[] value;
    }

    struct StringKeyValue {
        string key;
        string value;
    }

    struct StringArrayKeyValue {
        string key;
        string[] value;
    }

    function initItems(AddressItems memory items, uint256 size) internal pure {
        items.items = new EventUtils.AddressKeyValue[](size);
    }

    function initArrayItems(AddressItems memory items, uint256 size) internal pure {
        items.arrayItems = new EventUtils.AddressArrayKeyValue[](size);
    }

    function setItem(AddressItems memory items, uint256 index, string memory key, address value) internal pure {
        items.items[index].key = key;
        items.items[index].value = value;
    }

    function setItem(AddressItems memory items, uint256 index, string memory key, address[] memory value)
        internal
        pure
    {
        items.arrayItems[index].key = key;
        items.arrayItems[index].value = value;
    }

    function initItems(UintItems memory items, uint256 size) internal pure {
        items.items = new EventUtils.UintKeyValue[](size);
    }

    function initArrayItems(UintItems memory items, uint256 size) internal pure {
        items.arrayItems = new EventUtils.UintArrayKeyValue[](size);
    }

    function setItem(UintItems memory items, uint256 index, string memory key, uint256 value) internal pure {
        items.items[index].key = key;
        items.items[index].value = value;
    }

    function setItem(UintItems memory items, uint256 index, string memory key, uint256[] memory value) internal pure {
        items.arrayItems[index].key = key;
        items.arrayItems[index].value = value;
    }

    function initItems(IntItems memory items, uint256 size) internal pure {
        items.items = new EventUtils.IntKeyValue[](size);
    }

    function initArrayItems(IntItems memory items, uint256 size) internal pure {
        items.arrayItems = new EventUtils.IntArrayKeyValue[](size);
    }

    function setItem(IntItems memory items, uint256 index, string memory key, int256 value) internal pure {
        items.items[index].key = key;
        items.items[index].value = value;
    }

    function setItem(IntItems memory items, uint256 index, string memory key, int256[] memory value) internal pure {
        items.arrayItems[index].key = key;
        items.arrayItems[index].value = value;
    }

    function initItems(BoolItems memory items, uint256 size) internal pure {
        items.items = new EventUtils.BoolKeyValue[](size);
    }

    function initArrayItems(BoolItems memory items, uint256 size) internal pure {
        items.arrayItems = new EventUtils.BoolArrayKeyValue[](size);
    }

    function setItem(BoolItems memory items, uint256 index, string memory key, bool value) internal pure {
        items.items[index].key = key;
        items.items[index].value = value;
    }

    function setItem(BoolItems memory items, uint256 index, string memory key, bool[] memory value) internal pure {
        items.arrayItems[index].key = key;
        items.arrayItems[index].value = value;
    }

    function initItems(Bytes32Items memory items, uint256 size) internal pure {
        items.items = new EventUtils.Bytes32KeyValue[](size);
    }

    function initArrayItems(Bytes32Items memory items, uint256 size) internal pure {
        items.arrayItems = new EventUtils.Bytes32ArrayKeyValue[](size);
    }

    function setItem(Bytes32Items memory items, uint256 index, string memory key, bytes32 value) internal pure {
        items.items[index].key = key;
        items.items[index].value = value;
    }

    function setItem(Bytes32Items memory items, uint256 index, string memory key, bytes32[] memory value)
        internal
        pure
    {
        items.arrayItems[index].key = key;
        items.arrayItems[index].value = value;
    }

    function initItems(BytesItems memory items, uint256 size) internal pure {
        items.items = new EventUtils.BytesKeyValue[](size);
    }

    function initArrayItems(BytesItems memory items, uint256 size) internal pure {
        items.arrayItems = new EventUtils.BytesArrayKeyValue[](size);
    }

    function setItem(BytesItems memory items, uint256 index, string memory key, bytes memory value) internal pure {
        items.items[index].key = key;
        items.items[index].value = value;
    }

    function setItem(BytesItems memory items, uint256 index, string memory key, bytes[] memory value) internal pure {
        items.arrayItems[index].key = key;
        items.arrayItems[index].value = value;
    }

    function initItems(StringItems memory items, uint256 size) internal pure {
        items.items = new EventUtils.StringKeyValue[](size);
    }

    function initArrayItems(StringItems memory items, uint256 size) internal pure {
        items.arrayItems = new EventUtils.StringArrayKeyValue[](size);
    }

    function setItem(StringItems memory items, uint256 index, string memory key, string memory value) internal pure {
        items.items[index].key = key;
        items.items[index].value = value;
    }

    function setItem(StringItems memory items, uint256 index, string memory key, string[] memory value) internal pure {
        items.arrayItems[index].key = key;
        items.arrayItems[index].value = value;
    }
}
合同源代码
文件 11 的 27:IBeacon.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/beacon/IBeacon.sol)

pragma solidity ^0.8.20;

/**
 * @dev This is the interface that {BeaconProxy} expects of its beacon.
 */
interface IBeacon {
    /**
     * @dev Must return an address that can be used as a delegate call target.
     *
     * {UpgradeableBeacon} will check that this address is a contract.
     */
    function implementation() external view returns (address);
}
合同源代码
文件 12 的 27:IControlCenter.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

import "./IEventEmitter.sol";

/// @dev Interface of the ControlCenter contract
interface IControlCenter is IEventEmitter {
    /* solhint-disable func-name-mixedcase */
    function VERSION() external view returns (string memory);

    /**
     * @notice update Admin access
     * @dev only Owner can call
     * @param admin Address of the admin
     * @param isAdmin toggle admin access
     */
    function setAdmin(address admin, bool isAdmin) external;

    /**
     * @notice Check control center is official or not supported
     * @param controlCenterAddress Address of the  contract
     * @return bool True if the control center is official
     */
    function isOfficialControlCenter(address controlCenterAddress) external view returns (bool);

    /**
     * @notice Add a new official control center contract
     * @dev only Owner can call
     * @dev version  format: [AppName]_[MajorVer.].[MinorVer.]: e.g. CC_1.1
     * @param controlCenterAddress Address of the control center contract
     * @param version Version of the control center contract , format:( [Name]_[MajorVer.].[MinorVer.]: e.g. CC_1.1 )
     */
    function addOfficialControlCenter(address controlCenterAddress, bytes32 version) external;
    /**
     * @notice remove unsupported control center contract
     * @dev only Owner can call
     * @param controlCenterAddress Address of the control center contract
     */
    function removeOfficialControlCenter(address controlCenterAddress) external;
    /**
     * @notice Check implementation is official or not supported
     * @param implementationAddress Address of the implementation contract
     * @return bool True if the implementation is official
     */
    function isOfficialImplementation(address implementationAddress) external view returns (bool);
    /**
     * @notice Add a new official implementation contract
     * @dev only Owner can call
     * @dev version  format: [AppName]_[MajorVer.].[MinorVer.]: e.g. ERC20_1.1
     * @param implementationAddress Address of the implementation contract
     * @param version Version of the implementation contract , format:( [Name]_[MajorVer.].[MinorVer.]: e.g. master_1.1 )
     */
    function addOfficialImplementation(address implementationAddress, bytes32 version) external;
    /**
     * @notice remove unsupported implementation contract
     * @dev only Owner can call
     * @param implementationAddress Address of the implementation contract
     */
    function removeOfficialImplementation(address implementationAddress) external;

    /**
     * @notice Check analyser is official or not supported
     * @param analyserAddress Address of the analyser contract
     * @return bool True if the analyser is official
     */
    function isOfficialAnalyser(address analyserAddress) external view returns (bool);
    /**
     * @notice Add a new official analyser contract
     * @dev only Admin can call
     * @dev version format: [AppName]_[MajorVer.].[MinorVer.]: e.g. ERC20_1.1
     * @param analyserAddress Address of the analyser contract
     * @param version Version of the analyser contract , format:( [AppName]_[MajorVer.].[MinorVer.]: e.g. ERC20_1.1 )
     */
    function addOfficialAnalyser(address analyserAddress, bytes32 version) external;
    /**
     * @notice remove unsupported analyser contract
     * @dev only Admin can call
     * @param analyserAddress Address of the analyser contract
     */
    function removeOfficialAnalyser(address analyserAddress) external;

    /**
     * @notice get available policy count for KnightSafe
     * @param knightSafeAddress Address of the analyser contract
     */
    function getMaxPolicyAllowed(address knightSafeAddress) external view returns (uint256);
    /**
     * @notice set available policy count
     * @dev only Admin can call
     * @param knightSafeAddress Address of the analyser contract
     * @param maxPolicyAllowed Maximum policy count
     */
    function setMaxPolicyAllowed(address knightSafeAddress, uint256 maxPolicyAllowed) external;
    /**
     * @notice set global minimum policy count
     * @dev only Owner can call
     */
    function setGlobalMinPolicyAllowed(uint256 minPolicyAllowed) external;

    /**
     * @notice get admin event access list
     */
    function getAdminEventAccess() external view returns (bytes4[] memory);
    /**
     * @notice get admin event access count
     */
    function getAdminEventAccessCount() external view returns (uint256);
    /**
     * @notice get admin event access by id
     * @param id Event id
     */
    function getAdminEventAccessById(uint8 id) external view returns (bytes4);

    /**
     * @notice Check policy spending limit is enabled or not
     * @param knightSafeAddress Address of the analyser contract
     * @return bool True if the spending limit is enabled
     */
    function isSpendingLimitEnabled(address knightSafeAddress) external view returns (bool);
    /**
     * @notice set spending limit
     * @dev only Admin can call
     * @param knightSafeAddress Address of the analyser contract
     * @param isEnabled True if the spending limit is enabled
     */
    function setSpendingLimitEnabled(address knightSafeAddress, bool isEnabled) external;

    /**
     * @notice get price feed address
     * @return Price feed address
     */
    function getPriceFeed() external view returns (address);
    /**
     * @notice get price feed address
     * @dev only owner can call
     * @param priceFeed Price feed address
     */
    function setPriceFeed(address priceFeed) external;

    /**
     * @notice set global volume limit
     * @dev only Owner can call
     * @param volume global limit with 30 decimals
     */
    function setBaseVolume(uint256 volume) external;

    /**
     * @notice get daily transaction volume limit
     * @param knightSafeAddress  knight safe account
     * @return Limit transaction volume limit as 30 decimals
     */
    function getDailyVolume(address knightSafeAddress) external view returns (uint256);
    /**
     * @notice set daily limit
     * @dev only Admin can call
     * @dev daily Limit must cast to 30 decimals
     * @param knightSafeAddress  knight safe account
     * @param volume daily limit with 30 decimals
     */
    function setDailyVolume(address knightSafeAddress, uint256 volume) external;
    /**
     * @notice set daily limit date due to
     * @dev only Admin can call
     * @param knightSafeAddress  knight safe account
     * @param expiryDate Expiration date of the limit
     */
    function setDailyVolumeExpiryDate(address knightSafeAddress, uint256 expiryDate) external;

    /**
     * @notice get total transaction volume limit
     * @param knightSafeAddress knight safe account
     * @return Limit transaction volume limit with 30 decimals
     */
    function getMaxTradingVolume(address knightSafeAddress) external view returns (uint256);
    /**
     * @notice get volume limit expiration date
     * @dev will return 0 for unset value
     * @param knightSafeAddress knight safe account
     * @return timestamp Expiration date of the limit
     */
    function getMaxVolumeExpiryDate(address knightSafeAddress) external view returns (uint256);
    /**
     * @notice set account volume limit
     * @dev only Admin can call
     * @dev volume Limit must cast to 30 decimals
     * @param knightSafeAddress  knight safe account
     * @param volume transaction volume limit with 30 decimals
     */
    function setMaxTradingVolume(address knightSafeAddress, uint256 volume) external;
    /**
     * @notice set account volume limit date due to
     * @dev only Admin can call
     * @param knightSafeAddress  knight safe account
     * @param expiryDate Expiration date of the limit
     */
    function setMaxTradingVolumeExpiryDate(address knightSafeAddress, uint256 expiryDate) external;
}
合同源代码
文件 13 的 27:IERC1155Receiver.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC1155Receiver.sol)

pragma solidity ^0.8.20;

import {IERC1155Receiver} from "../token/ERC1155/IERC1155Receiver.sol";
合同源代码
文件 14 的 27:IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC165.sol)

pragma solidity ^0.8.20;

import {IERC165} from "../utils/introspection/IERC165.sol";
合同源代码
文件 15 的 27:IERC721Receiver.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/IERC721Receiver.sol)

pragma solidity ^0.8.20;

/**
 * @title ERC721 token receiver interface
 * @dev Interface for any contract that wants to support safeTransfers
 * from ERC721 asset contracts.
 */
interface IERC721Receiver {
    /**
     * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
     * by `operator` from `from`, this function is called.
     *
     * It must return its Solidity selector to confirm the token transfer.
     * If any other value is returned or the interface is not implemented by the recipient, the transfer will be
     * reverted.
     *
     * The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`.
     */
    function onERC721Received(
        address operator,
        address from,
        uint256 tokenId,
        bytes calldata data
    ) external returns (bytes4);
}
合同源代码
文件 16 的 27:IERC777Recipient.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC777Recipient.sol)

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC777TokensRecipient standard as defined in the EIP.
 *
 * Accounts can be notified of {IERC777} tokens being sent to them by having a
 * contract implement this interface (contract holders can be their own
 * implementer) and registering it on the
 * https://eips.ethereum.org/EIPS/eip-1820[ERC1820 global registry].
 *
 * See {IERC1820Registry} and {IERC1820Implementer}.
 */
interface IERC777Recipient {
    /**
     * @dev Called by an {IERC777} token contract whenever tokens are being
     * moved or created into a registered account (`to`). The type of operation
     * is conveyed by `from` being the zero address or not.
     *
     * This call occurs _after_ the token contract's state is updated, so
     * {IERC777-balanceOf}, etc., can be used to query the post-operation state.
     *
     * This function may revert to prevent the operation from being executed.
     */
    function tokensReceived(
        address operator,
        address from,
        address to,
        uint256 amount,
        bytes calldata userData,
        bytes calldata operatorData
    ) external;
}
合同源代码
文件 17 的 27:IEventEmitter.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

import "../event/EventUtils.sol";
import "../transaction/Transaction.sol";
import "../setting/SettingUtils.sol";

/// @notice EventEmitter interface
/// All KnightSafe event will emit through this interface
interface IEventEmitter {
    event TransactionEventLog(
        address msgSender, string eventName, string indexed eventNameHash, bytes32 indexed profile, uint256 reqId
    );

    event SettingEventLog(
        address msgSender, string eventName, string indexed eventNameHash, bytes32 indexed profile, uint256 reqId
    );

    event EventLog(
        address msgSender, string eventName, string indexed eventNameHash, EventUtils.EventLogData eventData
    );

    event EventLog1(
        address msgSender,
        string eventName,
        string indexed eventNameHash,
        bytes32 indexed profile,
        EventUtils.EventLogData eventData
    );

    event EventLog2(
        address msgSender,
        string eventName,
        string indexed eventNameHash,
        bytes32 indexed profile,
        bytes32 indexed topic2,
        EventUtils.EventLogData eventData
    );
    /// @notice check if sender is factory

    function isFactory(address sender) external view returns (bool);
    /// @notice set sender as factory
    function setFactory(address factory) external;
    /// @notice disable factory
    function disableFactory(address factory) external;

    /// @notice check if sender is available to send event
    function isActiveAccount(address sender) external view returns (bool);
    /// @notice set sender as active account
    function setActiveAccount(address sender) external;
    /// @notice disable active account
    function disableActiveAccount(address sender) external;

    /**
     * @notice emit event log
     * @param eventName event name, Topic 0
     * @param eventData event data, data
     */
    function emitEventLog(string memory eventName, EventUtils.EventLogData memory eventData) external;
    /**
     * @notice emit event log with 1 topic
     * @param eventName event name, Topic 0
     * @param profile profile address, Topic 1
     * @param eventData event data, data
     */
    function emitEventLog1(string memory eventName, bytes32 profile, EventUtils.EventLogData memory eventData)
        external;

    /**
     * @notice emit event log with 2 topic
     * @param eventName event name, Topic 0
     * @param profile profile address, Topic 1
     * @param topic2 second topic information , Topic 2
     * @param eventData event data, data
     */
    function emitEventLog2(
        string memory eventName,
        bytes32 profile,
        bytes32 topic2,
        EventUtils.EventLogData memory eventData
    ) external;

    /**
     * @notice emit transaction event log
     * @dev this will trigger on every transaction request
     * @param eventName event name
     * @param profile profile address
     * @param reqId request id
     */
    function emitTransactionEventLog(string memory eventName, bytes32 profile, uint256 reqId) external;

    /**
     * @notice emit setting event log
     * @dev this will trigger on every setting request
     * @param eventName event name
     * @param profile profile address
     * @param reqId request id
     */
    function emitSettingEventLog(string memory eventName, bytes32 profile, uint256 reqId) external;
}
合同源代码
文件 18 的 27:IKnightSafeAnalyser.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

interface IKnightSafeAnalyser {
    /**
     * @dev this function is used to extract addresses and values from transaction data
     * @param to address of the contract
     * @param data transaction data
     */
    function extractAddressesWithValue(address to, bytes memory data)
        external
        view
        returns (address[] memory, uint256[] memory);
}
合同源代码
文件 19 的 27:IOwnerManager.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

interface IOwnerManager {
    /// @notice get owner of the contract
    function getOwner() external view returns (address);
    /**
     * @notice set new backup owner to recovery contract
     * @dev only owner can call
     * @param backupOwner new owner address
     * @param takeoverDelayIsSecond delay time for takeover in seconds
     */
    function setBackupOwner(address backupOwner, uint256 takeoverDelayIsSecond) external;
    /// @notice get recovery is started
    function getIsTakeoverInProgress() external view returns (bool);
    /// @notice get recovery process timestamp
    function getTakeoverTimestamp() external view returns (uint256);
    /// @notice get backup progress status
    function getTakeoverStatus() external view returns (address, bool, uint256, uint256);

    /**
     * @notice request recovery process
     * @dev only backup owner can call
     */
    function requestTakeover() external;
    /**
     * @notice confirm recovery process
     * @dev if owner confirm, takeover will be done instantly;
     * @dev backup owner can confirm takeover after delay time
     */
    function confirmTakeover() external;
    /**
     * @notice instantly takeover
     * @dev if takeover delay set to 0,  backup owner can confirm takeover instantly after requestTakeover()
     */
    function instantTakeover() external;
    /**
     * @notice revoke takeover request
     * @dev owner and backup owner can revoke takeover request
     */
    function revokeTakeover() external;

    /// @notice get admin list
    function getAdmins() external view returns (address[] memory);
    /// @notice check address is admin
    function isAdmin(address admin) external view returns (bool);
    /// @notice set new admin
    function addAdmin(address admin) external;
    /// @notice disable admin
    function removeAdmin(address admin) external;
}
合同源代码
文件 20 的 27:KnightSafeProxy.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

import {Proxy} from "@openzeppelin/contracts/proxy/Proxy.sol";
import {ERC1967Utils} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol";
import {ControlCenterManager} from "../base/ControlCenterManager.sol";
import {IControlCenter} from "../interfaces/IControlCenter.sol";
import {IOwnerManager} from "../interfaces/IOwnerManager.sol";
import "@/error/Errors.sol";

contract KnightSafeProxy is Proxy {
    constructor(address implementation) {
        if (implementation == address(0)) revert Errors.IsNullValue();
        bytes memory _data;
        ERC1967Utils.upgradeToAndCall(implementation, _data);
    }

    function _implementation() internal view virtual override returns (address) {
        return ERC1967Utils.getImplementation();
    }

    function upgradeTo(address implementation) public returns (address) {
        if (implementation == address(0)) revert Errors.IsNullValue();

        if (IOwnerManager(address(this)).getOwner() != msg.sender) {
            revert Errors.Unauthorized(msg.sender, "OWNER");
        }

        address controlCenter = ControlCenterManager(address(this)).getControlCenter();
        if (!IControlCenter(controlCenter).isOfficialImplementation(implementation)) {
            revert Errors.AddressIsNotKnightSafeImplementation(implementation);
        }

        bytes memory _data;
        ERC1967Utils.upgradeToAndCall(implementation, _data);
    }
}
合同源代码
文件 21 的 27:Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)

pragma solidity ^0.8.20;

import {Context} from "../utils/Context.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * The initial owner is set to the address provided by the deployer. This can
 * later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

    /**
     * @dev The caller account is not authorized to perform an operation.
     */
    error OwnableUnauthorizedAccount(address account);

    /**
     * @dev The owner is not a valid owner account. (eg. `address(0)`)
     */
    error OwnableInvalidOwner(address owner);

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the address provided by the deployer as the initial owner.
     */
    constructor(address initialOwner) {
        if (initialOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(initialOwner);
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        if (owner() != _msgSender()) {
            revert OwnableUnauthorizedAccount(_msgSender());
        }
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby disabling any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        if (newOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}
合同源代码
文件 22 的 27:Ownable2Step.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable2Step.sol)

pragma solidity ^0.8.20;

import {Ownable} from "./Ownable.sol";

/**
 * @dev Contract module which provides access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * The initial owner is specified at deployment time in the constructor for `Ownable`. This
 * can later be changed with {transferOwnership} and {acceptOwnership}.
 *
 * This module is used through inheritance. It will make available all functions
 * from parent (Ownable).
 */
abstract contract Ownable2Step is Ownable {
    address private _pendingOwner;

    event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Returns the address of the pending owner.
     */
    function pendingOwner() public view virtual returns (address) {
        return _pendingOwner;
    }

    /**
     * @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual override onlyOwner {
        _pendingOwner = newOwner;
        emit OwnershipTransferStarted(owner(), newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual override {
        delete _pendingOwner;
        super._transferOwnership(newOwner);
    }

    /**
     * @dev The new owner accepts the ownership transfer.
     */
    function acceptOwnership() public virtual {
        address sender = _msgSender();
        if (pendingOwner() != sender) {
            revert OwnableUnauthorizedAccount(sender);
        }
        _transferOwnership(sender);
    }
}
合同源代码
文件 23 的 27:Proxy.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/Proxy.sol)

pragma solidity ^0.8.20;

/**
 * @dev This abstract contract provides a fallback function that delegates all calls to another contract using the EVM
 * instruction `delegatecall`. We refer to the second contract as the _implementation_ behind the proxy, and it has to
 * be specified by overriding the virtual {_implementation} function.
 *
 * Additionally, delegation to the implementation can be triggered manually through the {_fallback} function, or to a
 * different contract through the {_delegate} function.
 *
 * The success and return data of the delegated call will be returned back to the caller of the proxy.
 */
abstract contract Proxy {
    /**
     * @dev Delegates the current call to `implementation`.
     *
     * This function does not return to its internal call site, it will return directly to the external caller.
     */
    function _delegate(address implementation) internal virtual {
        assembly {
            // Copy msg.data. We take full control of memory in this inline assembly
            // block because it will not return to Solidity code. We overwrite the
            // Solidity scratch pad at memory position 0.
            calldatacopy(0, 0, calldatasize())

            // Call the implementation.
            // out and outsize are 0 because we don't know the size yet.
            let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0)

            // Copy the returned data.
            returndatacopy(0, 0, returndatasize())

            switch result
            // delegatecall returns 0 on error.
            case 0 {
                revert(0, returndatasize())
            }
            default {
                return(0, returndatasize())
            }
        }
    }

    /**
     * @dev This is a virtual function that should be overridden so it returns the address to which the fallback
     * function and {_fallback} should delegate.
     */
    function _implementation() internal view virtual returns (address);

    /**
     * @dev Delegates the current call to the address returned by `_implementation()`.
     *
     * This function does not return to its internal call site, it will return directly to the external caller.
     */
    function _fallback() internal virtual {
        _delegate(_implementation());
    }

    /**
     * @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if no other
     * function in the contract matches the call data.
     */
    fallback() external payable virtual {
        _fallback();
    }
}
合同源代码
文件 24 的 27:SettingUtils.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

library SettingUtils {
    enum Status {
        Pending,
        Cancelled,
        Completed,
        Rejected
    }

    struct Request {
        address requester;
        uint8 selector;
        bytes data;
        Status status;
    }
}

library SettingSelectors {
    bytes4 internal constant CREATE_POLICY = 0xa91a0ca3;
    bytes4 internal constant UPDATE_WHITELIST = 0x725d42f5;
    bytes4 internal constant ADD_TRADER = 0xedbdf62b;
    bytes4 internal constant REMOVE_POLICY = 0x6caddcdc;
    bytes4 internal constant REMOVE_TRADER = 0x29953ff5;
    bytes4 internal constant REMOVE_WHITELIST = 0x94008a6e;
    bytes4 internal constant INCREASE_SPENDING_LIMIT = 0xcc19223b;
    bytes4 internal constant RESET_SPENDING_LIMIT = 0x86e43e16;
}
合同源代码
文件 25 的 27:StorageSlot.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/StorageSlot.sol)
// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.

pragma solidity ^0.8.20;

/**
 * @dev Library for reading and writing primitive types to specific storage slots.
 *
 * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
 * This library helps with reading and writing to such slots without the need for inline assembly.
 *
 * The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
 *
 * Example usage to set ERC1967 implementation slot:
 * ```solidity
 * contract ERC1967 {
 *     bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
 *
 *     function _getImplementation() internal view returns (address) {
 *         return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
 *     }
 *
 *     function _setImplementation(address newImplementation) internal {
 *         require(newImplementation.code.length > 0);
 *         StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
 *     }
 * }
 * ```
 */
library StorageSlot {
    struct AddressSlot {
        address value;
    }

    struct BooleanSlot {
        bool value;
    }

    struct Bytes32Slot {
        bytes32 value;
    }

    struct Uint256Slot {
        uint256 value;
    }

    struct StringSlot {
        string value;
    }

    struct BytesSlot {
        bytes value;
    }

    /**
     * @dev Returns an `AddressSlot` with member `value` located at `slot`.
     */
    function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `BooleanSlot` with member `value` located at `slot`.
     */
    function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
     */
    function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `Uint256Slot` with member `value` located at `slot`.
     */
    function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `StringSlot` with member `value` located at `slot`.
     */
    function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `StringSlot` representation of the string storage pointer `store`.
     */
    function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := store.slot
        }
    }

    /**
     * @dev Returns an `BytesSlot` with member `value` located at `slot`.
     */
    function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.
     */
    function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := store.slot
        }
    }
}
合同源代码
文件 26 的 27:TokenCallbackHandler.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

import {IERC721Receiver} from "@openzeppelin/contracts/interfaces/IERC721Receiver.sol";
import {IERC777Recipient} from "@openzeppelin/contracts/interfaces/IERC777Recipient.sol";
import {IERC1155Receiver} from "@openzeppelin/contracts/interfaces/IERC1155Receiver.sol";
import {IERC165} from "@openzeppelin/contracts/interfaces/IERC165.sol";

contract TokenCallbackHandler is IERC1155Receiver, IERC777Recipient, IERC721Receiver {
    /**
     * @notice Handles ERC1155 Token callback.
     * return Standardized onERC1155Received return value.
     */
    function onERC1155Received(address, address, uint256, uint256, bytes calldata)
        external
        pure
        override
        returns (bytes4)
    {
        return 0xf23a6e61;
    }

    /**
     * @notice Handles ERC1155 Token batch callback.
     * return Standardized onERC1155BatchReceived return value.
     */
    function onERC1155BatchReceived(address, address, uint256[] calldata, uint256[] calldata, bytes calldata)
        external
        pure
        override
        returns (bytes4)
    {
        return 0xbc197c81;
    }

    /**
     * @notice Handles ERC721 Token callback.
     *  return Standardized onERC721Received return value.
     */
    function onERC721Received(address, address, uint256, bytes calldata) external pure override returns (bytes4) {
        return 0x150b7a02;
    }

    /**
     * @notice Handles ERC777 Token callback.
     * return nothing (not standardized)
     */
    function tokensReceived(address, address, address, uint256, bytes calldata, bytes calldata)
        external
        pure
        override
    {
        // We implement this for completeness, doesn't really have any value
    }

    /**
     * @notice Implements ERC165 interface support for ERC1155TokenReceiver, ERC721TokenReceiver and IERC165.
     * @param interfaceId Id of the interface.
     * @return if the interface is supported.
     */
    function supportsInterface(bytes4 interfaceId) external view virtual override returns (bool) {
        return interfaceId == type(IERC1155Receiver).interfaceId || interfaceId == type(IERC721Receiver).interfaceId
            || interfaceId == type(IERC165).interfaceId;
    }
}
合同源代码
文件 27 的 27:Transaction.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

library Transaction {
    // using Transaction for Props;
    enum Status {
        Pending,
        Cancelled,
        Completed,
        Rejected
    }

    struct Request {
        address requester;
        uint256 policyId;
        Params params;
        Status status;
    }
    
    struct Params {
        address to;
        uint256 value;
        bytes data;
    }
}
设置
{
  "compilationTarget": {
    "contracts/proxies/KnightSafeProxy.sol": "KnightSafeProxy"
  },
  "evmVersion": "paris",
  "libraries": {},
  "metadata": {
    "bytecodeHash": "ipfs"
  },
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "remappings": [
    ":@/=contracts/",
    ":@chainlink/contracts/=lib/chainlink-brownie-contracts/contracts/src/",
    ":@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
    ":chainlink-brownie-contracts/=lib/chainlink-brownie-contracts/contracts/src/v0.6/vendor/@arbitrum/nitro-contracts/src/",
    ":ds-test/=lib/foundry-chainlink-toolkit/lib/forge-std/lib/ds-test/src/",
    ":eth-gas-reporter/=node_modules/eth-gas-reporter/",
    ":forge-std/=lib/forge-std/src/",
    ":hardhat/=node_modules/hardhat/",
    ":openzeppelin-contracts/=lib/openzeppelin-contracts/"
  ]
}
ABI
[{"inputs":[{"internalType":"address","name":"implementation","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"target","type":"address"}],"name":"AddressEmptyCode","type":"error"},{"inputs":[{"internalType":"address","name":"_address","type":"address"}],"name":"AddressIsNotKnightSafeImplementation","type":"error"},{"inputs":[{"internalType":"address","name":"implementation","type":"address"}],"name":"ERC1967InvalidImplementation","type":"error"},{"inputs":[],"name":"ERC1967NonPayable","type":"error"},{"inputs":[],"name":"FailedInnerCall","type":"error"},{"inputs":[],"name":"IsNullValue","type":"error"},{"inputs":[{"internalType":"address","name":"msgSender","type":"address"},{"internalType":"string","name":"role","type":"string"}],"name":"Unauthorized","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"implementation","type":"address"}],"name":"Upgraded","type":"event"},{"stateMutability":"payable","type":"fallback"},{"inputs":[{"internalType":"address","name":"implementation","type":"address"}],"name":"upgradeTo","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"nonpayable","type":"function"}]