Проверенный контрактТочноеMIT
CFHelpersGov
Адрес0x332e0ee8d11e8bc67c67ee3fbb72e092e2f4ed78
- Баланс
0 ETH
- Транзакций
22
- Компилятор
solc 0.8.28
- Тот же код
Только этот контракт
Подробности
- Компилятор
- solc 0.8.28+commit.7893614a
- Язык
- solidity
- Оптимизация
- Да, 200 прогонов
- Версия EVM
- paris
- Через IR
- да
- Лицензия
- MIT
- Совпадение
- Точноекод создания: да, код в сети: да
- Проверен на Sourcify
- Создан в блоке
- 24 930 036
- Транзакция создания
- 0x0b0ad3093a…d6782c6db6
3 файла
contracts/CFHelpersGov.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
import "@openzeppelin/contracts/metatx/ERC2771Context.sol";
/// @notice Interface for reading Cofund Admin state
interface ICFHelpersState {
function isCofundAdmin(address) external view returns (bool);
function cofundAdminCount() external view returns (uint256);
}
/// @notice Interface for writing Cofund Admin state
interface ICFHelpersStateGov is ICFHelpersState {
function setCofundAdmin(address admin, bool status) external;
function incrementCofundAdminCount() external;
function decrementCofundAdminCount() external;
function setHelperContract(
string memory contractType,
address contractAddress
) external;
function helperContracts(string calldata) external view returns (address);
}
/// @notice Interface for the sponsor guard contract (see CFSponsorGuard.sol)
interface ICFSponsorGuard {
function addSponsor(address) external;
function removeSponsor(address) external;
function pause() external;
function unpause() external;
function setStateSelectorAllowed(bytes4 selector, bool allowed) external;
function setVaultSelectorAllowed(bytes4 selector, bool allowed) external;
}
/// @title CFHelpersGov
/// @notice Governance helper for Cofund Admin (sponsor) management
/// @dev Supports add, remove, and rotate operations for sponsor keys
/// @dev This contract manages ONLY Cofund Admins (sponsors), NOT vault admins
contract CFHelpersGov is ERC2771Context {
// Errors
error UnauthorizedCaller();
error InvalidAddress();
error InvalidType();
error AdminExists();
error NotAdmin();
error LastAdmin();
error SelfRemoval();
error SponsorGuardNotSet();
// EVENTS
event CofundAdminAdded(address indexed newAdmin, address indexed addedBy);
event CofundAdminRemoved(address indexed admin, address indexed removedBy);
event CofundAdminRotated(
address indexed oldAdmin,
address indexed newAdmin
);
event HelperContractSet(
string contractType,
address indexed contractAddress,
address indexed setBy
);
event SponsorAdded(address indexed sponsor, address indexed by);
event SponsorRemoved(address indexed sponsor, address indexed by);
event SponsorGuardPaused(address indexed by);
event SponsorGuardUnpaused(address indexed by);
event SponsorGuardStateSelectorSet(bytes4 indexed selector, bool allowed, address indexed by);
event SponsorGuardVaultSelectorSet(bytes4 indexed selector, bool allowed, address indexed by);
// STATE
/// @notice State reference (pointer to CFHelpersStatev0)
ICFHelpersStateGov public immutable stateContract;
constructor(
address _stateContract,
address _trustedForwarder
) ERC2771Context(_trustedForwarder) {
stateContract = ICFHelpersStateGov(_stateContract);
}
/// @notice Restricts to Cofund admin (sponsor)
modifier onlyCofundAdmin() {
if (!stateContract.isCofundAdmin(_msgSender()))
revert UnauthorizedCaller();
_;
}
/// @notice Enforce EOA or trusted forwarder (prevent contract calls)
function _enforceEOA() private view {
// Allow calls only from EOAs or the trusted forwarder
if (!isTrustedForwarder(msg.sender) && msg.sender.code.length != 0) {
revert UnauthorizedCaller();
}
}
/// @notice Add a new Cofund admin (sponsor)
/// @param newAdmin Address to grant Cofund admin privileges
function addCofundAdmin(address newAdmin) external onlyCofundAdmin {
_enforceEOA();
// Validation
if (newAdmin == address(0)) revert InvalidAddress();
if (stateContract.isCofundAdmin(newAdmin)) revert AdminExists();
// Update state
stateContract.setCofundAdmin(newAdmin, true);
stateContract.incrementCofundAdminCount();
emit CofundAdminAdded(newAdmin, _msgSender());
}
/// @notice Remove an existing Cofund admin (sponsor)
/// @param admin Address to revoke Cofund admin privileges
/// @dev Cannot remove self, cannot remove last admin
function removeCofundAdmin(address admin) external onlyCofundAdmin {
_enforceEOA();
// Validation
if (admin == _msgSender()) revert SelfRemoval();
if (!stateContract.isCofundAdmin(admin)) revert NotAdmin();
if (stateContract.cofundAdminCount() <= 1) revert LastAdmin();
// Update state
stateContract.setCofundAdmin(admin, false);
stateContract.decrementCofundAdminCount();
emit CofundAdminRemoved(admin, _msgSender());
}
/// @notice Rotate own admin key to a new address
/// @param newAdmin New address to transfer admin privileges to
/// @dev Caller's admin status is revoked, newAdmin gains admin status
function rotateCofundAdmin(address newAdmin) external onlyCofundAdmin {
_enforceEOA();
address oldAdmin = _msgSender();
// Validation
if (newAdmin == address(0)) revert InvalidAddress();
if (stateContract.isCofundAdmin(newAdmin)) revert AdminExists();
// Update state: revoke old, grant new (count unchanged)
stateContract.setCofundAdmin(oldAdmin, false);
stateContract.setCofundAdmin(newAdmin, true);
emit CofundAdminRotated(oldAdmin, newAdmin);
}
/// @notice Check if address is a Cofund admin (sponsor)
function isAdmin(address addr) external view returns (bool) {
return stateContract.isCofundAdmin(addr);
}
/// @notice Get total number of Cofund admins
function adminCount() external view returns (uint256) {
return stateContract.cofundAdminCount();
}
// ═══════════════════════════════════════════════════════════════════
// HELPER CONTRACT MANAGEMENT
// ═══════════════════════════════════════════════════════════════════
/// @notice Set helper contract address in state
/// @param contractType The helper type key (e.g., "policies", "users", "vaults")
/// @param contractAddress The helper contract address
function setHelperContract(
string memory contractType,
address contractAddress
) external onlyCofundAdmin {
_enforceEOA();
// Validation
if (bytes(contractType).length == 0) revert InvalidType();
if (contractAddress == address(0)) revert InvalidAddress();
// Update state
stateContract.setHelperContract(contractType, contractAddress);
emit HelperContractSet(contractType, contractAddress, _msgSender());
}
// ═══════════════════════════════════════════════════════════════════
// SPONSOR GUARD MANAGEMENT
// ═══════════════════════════════════════════════════════════════════
function _guard() private view returns (ICFSponsorGuard) {
address a = stateContract.helperContracts("sponsorGuard");
if (a == address(0)) revert SponsorGuardNotSet();
return ICFSponsorGuard(a);
}
/// @notice Authorize a new sponsor EOA to relay meta-txs through the guard
function addSponsor(address sponsor) external onlyCofundAdmin {
_enforceEOA();
_guard().addSponsor(sponsor);
emit SponsorAdded(sponsor, _msgSender());
}
/// @notice Revoke a sponsor EOA's authorization to relay via the guard
function removeSponsor(address sponsor) external onlyCofundAdmin {
_enforceEOA();
_guard().removeSponsor(sponsor);
emit SponsorRemoved(sponsor, _msgSender());
}
/// @notice Emergency pause of all sponsored relaying through the guard
function pauseSponsorGuard() external onlyCofundAdmin {
_enforceEOA();
_guard().pause();
emit SponsorGuardPaused(_msgSender());
}
/// @notice Resume sponsored relaying through the guard
function unpauseSponsorGuard() external onlyCofundAdmin {
_enforceEOA();
_guard().unpause();
emit SponsorGuardUnpaused(_msgSender());
}
/// @notice Whitelist / unwhitelist a selector the sponsor fleet may invoke
/// on the state contract through `guard.relay`.
function setGuardStateSelectorAllowed(bytes4 selector, bool allowed) external onlyCofundAdmin {
_enforceEOA();
_guard().setStateSelectorAllowed(selector, allowed);
emit SponsorGuardStateSelectorSet(selector, allowed, _msgSender());
}
/// @notice Whitelist / unwhitelist a selector the sponsor fleet may invoke
/// on any known client vault through `guard.relay`.
function setGuardVaultSelectorAllowed(bytes4 selector, bool allowed) external onlyCofundAdmin {
_enforceEOA();
_guard().setVaultSelectorAllowed(selector, allowed);
emit SponsorGuardVaultSelectorSet(selector, allowed, _msgSender());
}
}
@openzeppelin/contracts/metatx/ERC2771Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (metatx/ERC2771Context.sol)
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.sol";
/**
* @dev Context variant with ERC-2771 support.
*
* WARNING: Avoid using this pattern in contracts that rely in a specific calldata length as they'll
* be affected by any forwarder whose `msg.data` is suffixed with the `from` address according to the ERC-2771
* specification adding the address size in bytes (20) to the calldata size. An example of an unexpected
* behavior could be an unintended fallback (or another function) invocation while trying to invoke the `receive`
* function only accessible if `msg.data.length == 0`.
*
* WARNING: The usage of `delegatecall` in this contract is dangerous and may result in context corruption.
* Any forwarded request to this contract triggering a `delegatecall` to itself will result in an invalid {_msgSender}
* recovery.
*/
abstract contract ERC2771Context is Context {
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
address private immutable _trustedForwarder;
/**
* @dev Initializes the contract with a trusted forwarder, which will be able to
* invoke functions on this contract on behalf of other accounts.
*
* NOTE: The trusted forwarder can be replaced by overriding {trustedForwarder}.
*/
/// @custom:oz-upgrades-unsafe-allow constructor
constructor(address trustedForwarder_) {
_trustedForwarder = trustedForwarder_;
}
/**
* @dev Returns the address of the trusted forwarder.
*/
function trustedForwarder() public view virtual returns (address) {
return _trustedForwarder;
}
/**
* @dev Indicates whether any particular address is the trusted forwarder.
*/
function isTrustedForwarder(address forwarder) public view virtual returns (bool) {
return forwarder == trustedForwarder();
}
/**
* @dev Override for `msg.sender`. Defaults to the original `msg.sender` whenever
* a call is not performed by the trusted forwarder or the calldata length is less than
* 20 bytes (an address length).
*/
function _msgSender() internal view virtual override returns (address) {
uint256 calldataLength = msg.data.length;
uint256 contextSuffixLength = _contextSuffixLength();
if (isTrustedForwarder(msg.sender) && calldataLength >= contextSuffixLength) {
return address(bytes20(msg.data[calldataLength - contextSuffixLength:]));
} else {
return super._msgSender();
}
}
/**
* @dev Override for `msg.data`. Defaults to the original `msg.data` whenever
* a call is not performed by the trusted forwarder or the calldata length is less than
* 20 bytes (an address length).
*/
function _msgData() internal view virtual override returns (bytes calldata) {
uint256 calldataLength = msg.data.length;
uint256 contextSuffixLength = _contextSuffixLength();
if (isTrustedForwarder(msg.sender) && calldataLength >= contextSuffixLength) {
return msg.data[:calldataLength - contextSuffixLength];
} else {
return super._msgData();
}
}
/**
* @dev ERC-2771 specifies the context as being a single address (20 bytes).
*/
function _contextSuffixLength() internal view virtual override returns (uint256) {
return 20;
}
}
@openzeppelin/contracts/utils/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;
}
}
Настройки компилятораПоказать
{
"viaIR": true,
"metadata": {
"bytecodeHash": "ipfs"
},
"libraries": {},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "paris",
"remappings": []
}Исходный код и метаданные: Sourcify.
Исходный код принадлежит авторам контракта.