Skip to content
Verified contractExactMIT

AgentLedger

Address0xf1ed0a298c38d5b921b1fb98a41d3edf4f4e58fc
Balance

0 ETH

 

Transactions

1

 

Compiler

solc 0.8.26

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.26+commit.8a97fa7a
Language
solidity
Optimization
Yes, 800 runs
EVM version
cancun
Via IR
yes
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,451,472
Creation transaction
0x1ad22420e9…c9067001c9

src/periphery/AgentLedger.sol

// SPDX-License-Identifier: MIT
//
// ETH Inc. ($ETHINC)
// Website: https://ethincorporated.xyz
// X:       https://x.com/EthIncorporated
//
pragma solidity 0.8.26;

import {AgentRegistry} from "../core/AgentRegistry.sol";

/// @title ETH Inc. Agent Ledger (the minutes)
/// @notice Append-only record of what the agents decided and why. Each entry commits to the hash of a
///         full off-chain report (inputs, model reasoning, resulting transactions), so the published
///         reasoning cannot be edited after the fact.
contract AgentLedger {
    struct Entry {
        address agent;
        uint64 timestamp;
        bytes32 kind; // e.g. "ALLOCATION", "BUYBACK", "RISK", "MINUTES"
        bytes32 contentHash; // keccak256 of the report body
        string uri; // where the report body can be fetched
    }

    AgentRegistry public immutable registry;
    Entry[] public entries;

    event Filed(uint256 indexed id, address indexed agent, bytes32 indexed kind, bytes32 contentHash, string uri);

    error NotAnAgent();

    constructor(AgentRegistry _registry) {
        registry = _registry;
    }

    function file(bytes32 kind, bytes32 contentHash, string calldata uri) external returns (uint256 id) {
        if (!registry.isActive(msg.sender)) revert NotAnAgent();
        id = entries.length;
        entries.push(Entry(msg.sender, uint64(block.timestamp), kind, contentHash, uri));
        emit Filed(id, msg.sender, kind, contentHash, uri);
    }

    function count() external view returns (uint256) {
        return entries.length;
    }

    /// @notice Latest `n` entries, newest first.
    function latest(uint256 n) external view returns (Entry[] memory out) {
        uint256 len = entries.length;
        if (n > len) n = len;
        out = new Entry[](n);
        for (uint256 i; i < n; ++i) {
            out[i] = entries[len - 1 - i];
        }
    }
}

@openzeppelin/contracts/access/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);
    }
}

@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;
    }
}

src/core/AgentRegistry.sol

// SPDX-License-Identifier: MIT
//
// ETH Inc. ($ETHINC)
// Website: https://ethincorporated.xyz
// X:       https://x.com/EthIncorporated
//
pragma solidity 0.8.26;

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

/// @title ETH Inc. Agent Registry (the org chart)
/// @notice Every address allowed to act for ETH Inc. is listed here with its job title and roles.
///         The Board hires and fires. The Risk Officer can halt the company but cannot restart it.
contract AgentRegistry {
    bytes32 public constant TREASURER = keccak256("TREASURER"); // allocates reserve ETH across strategies
    bytes32 public constant BUYBACK_DESK = keccak256("BUYBACK_DESK"); // executes buybacks & burns
    bytes32 public constant RISK_OFFICER = keccak256("RISK_OFFICER"); // can pause, can pull funds home
    bytes32 public constant SCRIBE = keccak256("SCRIBE"); // files reports to the AgentLedger

    struct Agent {
        string name;
        string title;
        string metadataURI; // model, prompt hash, operator, etc.
        uint64 hiredAt;
        bool active;
    }

    Charter public immutable charter;
    bool public paused;

    mapping(address => Agent) public agents;
    mapping(address => mapping(bytes32 => bool)) private _roles;
    address[] public agentList;

    event AgentHired(address indexed agent, string name, string title, bytes32[] roles);
    event AgentFired(address indexed agent);
    event RoleSet(address indexed agent, bytes32 indexed role, bool granted);
    event Paused(address indexed by, string reason);
    event Unpaused(address indexed by);

    error NotBoard();
    error NotAuthorised();
    error AlreadyHired();

    modifier onlyBoard() {
        if (msg.sender != charter.owner()) revert NotBoard();
        _;
    }

    constructor(Charter _charter) {
        charter = _charter;
    }

    function board() external view returns (address) {
        return charter.owner();
    }

    function hire(
        address agent,
        string calldata name,
        string calldata title,
        string calldata metadataURI,
        bytes32[] calldata roles
    ) external onlyBoard {
        if (agents[agent].hiredAt != 0 && agents[agent].active) revert AlreadyHired();
        if (agents[agent].hiredAt == 0) agentList.push(agent);
        agents[agent] = Agent(name, title, metadataURI, uint64(block.timestamp), true);
        for (uint256 i; i < roles.length; ++i) {
            _roles[agent][roles[i]] = true;
            emit RoleSet(agent, roles[i], true);
        }
        emit AgentHired(agent, name, title, roles);
    }

    function fire(address agent) external onlyBoard {
        agents[agent].active = false;
        emit AgentFired(agent);
    }

    function setRole(address agent, bytes32 role, bool granted) external onlyBoard {
        _roles[agent][role] = granted;
        emit RoleSet(agent, role, granted);
    }

    function hasRole(address agent, bytes32 role) public view returns (bool) {
        return agents[agent].active && _roles[agent][role];
    }

    function isActive(address agent) external view returns (bool) {
        return agents[agent].active;
    }

    /// @notice Halt allocations and buybacks. Withdrawals back to the reserve stay possible while paused.
    function pause(string calldata reason) external {
        if (msg.sender != charter.owner() && !hasRole(msg.sender, RISK_OFFICER)) revert NotAuthorised();
        paused = true;
        emit Paused(msg.sender, reason);
    }

    function unpause() external onlyBoard {
        paused = false;
        emit Unpaused(msg.sender);
    }

    function agentCount() external view returns (uint256) {
        return agentList.length;
    }

    function getAgents() external view returns (address[] memory) {
        return agentList;
    }
}

src/core/Charter.sol

// SPDX-License-Identifier: MIT
//
// ETH Inc. ($ETHINC)
// Website: https://ethincorporated.xyz
// X:       https://x.com/EthIncorporated
//
pragma solidity 0.8.26;

import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";

/// @title ETH Inc. Corporate Charter
/// @notice The rulebook every agent operates inside. Agents choose *what* to do; the Charter bounds
///         *how much* they can do. The owner is the Board (a timelock), and even the Board cannot move
///         a parameter outside the hard limits compiled into this contract.
contract Charter is Ownable {
    uint16 public constant BPS = 10_000;

    // ---- hard limits (immutable by construction) ----
    uint16 public constant MIN_FEE_TO_BUYBACK_BPS = 2_500; // at least 25% of swap fees always fund buybacks
    uint16 public constant MIN_YIELD_TO_BUYBACK_BPS = 5_000; // at least 50% of realised yield always funds buybacks
    uint16 public constant MIN_LIQUID_FLOOR_BPS = 500; // reserve always keeps >= 5% in plain ETH
    uint16 public constant MAX_STRATEGY_CAP_BPS = 6_000; // no single desk may hold > 60% of the reserve
    uint16 public constant MAX_BUYBACK_SLIPPAGE_BPS = 1_000; // buybacks can never accept > 10% below spot
    uint32 public constant MIN_BUYBACK_COOLDOWN = 60; // seconds

    // ---- tunable parameters ----
    uint16 public feeToBuybackBps = 5_000; // share of swap-fee income earmarked for buybacks
    uint16 public yieldToBuybackBps = 10_000; // share of realised strategy yield earmarked for buybacks
    uint16 public minLiquidBps = 1_000; // share of reserve principal that must stay un-deployed
    uint16 public maxBuybackSlippageBps = 400; // max shortfall vs pre-trade spot (includes pool + hook fees)
    uint32 public buybackCooldown = 10 minutes;
    uint256 public maxBuybackPerExecution = 0.5 ether;

    struct StrategyConfig {
        bool approved;
        uint16 capBps; // max share of reserve principal this strategy may hold
    }

    mapping(address => StrategyConfig) public strategies;
    address[] public strategyList;

    event SplitUpdated(uint16 feeToBuybackBps, uint16 yieldToBuybackBps);
    event MinLiquidUpdated(uint16 minLiquidBps);
    event BuybackLimitsUpdated(uint256 maxPerExecution, uint32 cooldown, uint16 maxSlippageBps);
    event StrategyUpdated(address indexed strategy, bool approved, uint16 capBps);

    error OutOfBounds();

    constructor(address initialOwner) Ownable(initialOwner) {}

    function setSplit(uint16 feeBps, uint16 yieldBps) external onlyOwner {
        if (feeBps < MIN_FEE_TO_BUYBACK_BPS || feeBps > BPS) revert OutOfBounds();
        if (yieldBps < MIN_YIELD_TO_BUYBACK_BPS || yieldBps > BPS) revert OutOfBounds();
        feeToBuybackBps = feeBps;
        yieldToBuybackBps = yieldBps;
        emit SplitUpdated(feeBps, yieldBps);
    }

    function setMinLiquid(uint16 bps) external onlyOwner {
        if (bps < MIN_LIQUID_FLOOR_BPS || bps > BPS) revert OutOfBounds();
        minLiquidBps = bps;
        emit MinLiquidUpdated(bps);
    }

    function setBuybackLimits(uint256 maxPerExecution, uint32 cooldown, uint16 maxSlippageBps) external onlyOwner {
        if (cooldown < MIN_BUYBACK_COOLDOWN) revert OutOfBounds();
        if (maxSlippageBps == 0 || maxSlippageBps > MAX_BUYBACK_SLIPPAGE_BPS) revert OutOfBounds();
        if (maxPerExecution == 0) revert OutOfBounds();
        maxBuybackPerExecution = maxPerExecution;
        buybackCooldown = cooldown;
        maxBuybackSlippageBps = maxSlippageBps;
        emit BuybackLimitsUpdated(maxPerExecution, cooldown, maxSlippageBps);
    }

    /// @notice Approve, re-cap or retire a strategy. Retiring (approved=false) blocks new deposits only;
    ///         the reserve can always withdraw from a strategy it has funds in.
    function setStrategy(address strategy, bool approved, uint16 capBps) external onlyOwner {
        if (capBps > MAX_STRATEGY_CAP_BPS) revert OutOfBounds();
        if (strategy == address(0)) revert OutOfBounds();
        if (!_known[strategy]) {
            _known[strategy] = true;
            strategyList.push(strategy);
        }
        strategies[strategy] = StrategyConfig(approved, capBps);
        emit StrategyUpdated(strategy, approved, capBps);
    }

    mapping(address => bool) private _known;

    /// @notice True for any strategy the Board has ever configured (approved now or retired).
    function isKnown(address strategy) external view returns (bool) {
        return _known[strategy];
    }

    function strategyCount() external view returns (uint256) {
        return strategyList.length;
    }

    function getStrategies() external view returns (address[] memory) {
        return strategyList;
    }
}
Compiler settingsShow
{
  "viaIR": true,
  "optimizer": {
    "runs": 800,
    "enabled": true
  },
  "evmVersion": "cancun"
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.