MetaOrchestrator

Description:

Smart contract deployed on Ethereum with Factory features.

Blockchain: Ethereum

Source Code: View Code On The Blockchain

Solidity Source Code:

{{
  "language": "Solidity",
  "sources": {
    "src/MetaOrchestrator.sol": {
      "content": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

contract MetaOrchestrator {
    struct Task {
        uint256 taskId;
        address executor;
        string taskType;
        bytes taskData;
        bool completed;
        uint256 timestamp;
        uint256 gasUsed;
    }
    
    struct Agent {
        address agentAddress;
        string agentType;
        uint256 tasksCompleted;
        bool active;
    }
    
    mapping(uint256 => Task) public tasks;
    mapping(address => Agent) public agents;
    mapping(address => uint256[]) public agentTasks;
    
    uint256 public taskCount;
    uint256 public agentCount;
    address public owner;
    uint256 public totalGasUsed;
    bool public paused;
    
    event TaskExecuted(uint256 indexed taskId, address indexed executor, string taskType);
    event TaskCompleted(uint256 indexed taskId, bool success, uint256 gasUsed);
    event AgentRegistered(address indexed agent, string agentType);
    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
    
    error OnlyOwner();
    error ZeroAddress();
    error ContractPaused();
    error InvalidTask();
    error InvalidAgent();
    
    modifier onlyOwner() {
        if (msg.sender != owner) revert OnlyOwner();
        _;
    }
    
    modifier whenNotPaused() {
        if (paused) revert ContractPaused();
        _;
    }
    
    modifier onlyActiveAgent() {
        if (!agents[msg.sender].active) revert InvalidAgent();
        _;
    }
    
    constructor() {
        owner = msg.sender;
        emit OwnershipTransferred(address(0), msg.sender);
    }
    
    function registerAgent(string calldata _agentType) external whenNotPaused {
        if (bytes(_agentType).length == 0) revert InvalidTask();
        
        agents[msg.sender] = Agent({
            agentAddress: msg.sender,
            agentType: _agentType,
            tasksCompleted: 0,
            active: true
        });
        
        unchecked {
            ++agentCount;
        }
        
        emit AgentRegistered(msg.sender, _agentType);
    }
    
    function executeTask(
        string calldata _taskType,
        bytes calldata _taskData
    ) external onlyActiveAgent whenNotPaused returns (uint256) {
        if (bytes(_taskType).length == 0) revert InvalidTask();
        
        uint256 taskId;
        unchecked {
            taskId = taskCount++;
        }
        
        uint256 gasStart = gasleft();
        
        tasks[taskId] = Task({
            taskId: taskId,
            executor: msg.sender,
            taskType: _taskType,
            taskData: _taskData,
            completed: false,
            timestamp: block.timestamp,
            gasUsed: 0
        });
        
        agentTasks[msg.sender].push(taskId);
        
        emit TaskExecuted(taskId, msg.sender, _taskType);
        
        bool success = _taskData.length > 0;
        uint256 gasUsed = gasStart - gasleft();
        
        tasks[taskId].completed = success;
        tasks[taskId].gasUsed = gasUsed;
        
        Agent storage agent = agents[msg.sender];
        unchecked {
            ++agent.tasksCompleted;
            totalGasUsed += gasUsed;
        }
        
        emit TaskCompleted(taskId, success, gasUsed);
        return taskId;
    }
    
    function getAgentTasks(address _agent) external view returns (uint256[] memory) {
        return agentTasks[_agent];
    }
    
    function setPaused(bool _paused) external onlyOwner {
        paused = _paused;
    }
    
    function transferOwnership(address newOwner) external onlyOwner {
        if (newOwner == address(0)) revert ZeroAddress();
        emit OwnershipTransferred(owner, newOwner);
        owner = newOwner;
    }
    
    function getTask(uint256 _taskId) external view returns (Task memory) {
        return tasks[_taskId];
    }
    
    function getAgent(address _agent) external view returns (Agent memory) {
        return agents[_agent];
    }
    
    function getTotalGasUsed() external view returns (uint256) {
        return totalGasUsed;
    }
}"
    }
  },
  "settings": {
    "remappings": [
      "forge-std/=lib/forge-std/src/"
    ],
    "optimizer": {
      "enabled": true,
      "runs": 200
    },
    "metadata": {
      "useLiteralContent": false,
      "bytecodeHash": "ipfs",
      "appendCBOR": true
    },
    "outputSelection": {
      "*": {
        "*": [
          "evm.bytecode",
          "evm.deployedBytecode",
          "devdoc",
          "userdoc",
          "metadata",
          "abi"
        ]
      }
    },
    "evmVersion": "paris",
    "viaIR": true
  }
}}

Tags:
Factory|addr:0xac9cf2c35658ecc804cc77271a7efe1098fa209c|verified:true|block:23465381|tx:0x10f37a0f83d8bdf92496ea62dc53f97555413c32246273fe6f1d9b18c51dac67|first_check:1759136952

Submitted on: 2025-09-29 11:09:14

Comments

Log in to comment.

No comments yet.