From 7b33f9e417ec88815997e2c652f2d111b388ce82 Mon Sep 17 00:00:00 2001 From: oib Date: Fri, 27 Feb 2026 23:00:27 +0100 Subject: [PATCH] feat: recreate remaining missing agent smart contracts from docs --- contracts/contracts/AgentCommunication.sol | 26 +++++++++ contracts/contracts/AgentMemory.sol | 39 +++++++++++++ contracts/contracts/CrossChainReputation.sol | 26 +++++++++ contracts/contracts/KnowledgeGraphMarket.sol | 58 ++++++++++++++++++++ contracts/contracts/MemoryVerifier.sol | 21 +++++++ 5 files changed, 170 insertions(+) create mode 100644 contracts/contracts/AgentCommunication.sol create mode 100644 contracts/contracts/AgentMemory.sol create mode 100644 contracts/contracts/CrossChainReputation.sol create mode 100644 contracts/contracts/KnowledgeGraphMarket.sol create mode 100644 contracts/contracts/MemoryVerifier.sol diff --git a/contracts/contracts/AgentCommunication.sol b/contracts/contracts/AgentCommunication.sol new file mode 100644 index 00000000..66fbf9af --- /dev/null +++ b/contracts/contracts/AgentCommunication.sol @@ -0,0 +1,26 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.19; + +import "@openzeppelin/contracts/access/Ownable.sol"; + +contract AgentCommunication is Ownable { + struct Message { + address sender; + address recipient; + string encryptedContent; + uint256 timestamp; + } + + mapping(address => Message[]) public inbox; + + event MessageSent(address indexed sender, address indexed recipient); + + function sendMessage(address _recipient, string calldata _encryptedContent) external { + inbox[_recipient].push(Message(msg.sender, _recipient, _encryptedContent, block.timestamp)); + emit MessageSent(msg.sender, _recipient); + } + + function getMessages() external view returns (Message[] memory) { + return inbox[msg.sender]; + } +} diff --git a/contracts/contracts/AgentMemory.sol b/contracts/contracts/AgentMemory.sol new file mode 100644 index 00000000..85b28991 --- /dev/null +++ b/contracts/contracts/AgentMemory.sol @@ -0,0 +1,39 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.19; + +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/security/ReentrancyGuard.sol"; + +contract AgentMemory is Ownable, ReentrancyGuard { + struct MemoryAnchor { + string cid; + uint256 timestamp; + uint256 version; + } + + mapping(address => MemoryAnchor[]) public agentMemories; + mapping(address => uint256) public agentMemoryVersions; + + event MemoryAnchored(address indexed agent, string cid, uint256 version, uint256 timestamp); + + function anchorMemory(string calldata _cid) external nonReentrant { + require(bytes(_cid).length > 0, "Invalid CID"); + + uint256 nextVersion = agentMemoryVersions[msg.sender] + 1; + + agentMemories[msg.sender].push(MemoryAnchor({ + cid: _cid, + timestamp: block.timestamp, + version: nextVersion + })); + + agentMemoryVersions[msg.sender] = nextVersion; + + emit MemoryAnchored(msg.sender, _cid, nextVersion, block.timestamp); + } + + function getLatestMemory(address _agent) external view returns (MemoryAnchor memory) { + require(agentMemories[_agent].length > 0, "No memory anchored"); + return agentMemories[_agent][agentMemories[_agent].length - 1]; + } +} diff --git a/contracts/contracts/CrossChainReputation.sol b/contracts/contracts/CrossChainReputation.sol new file mode 100644 index 00000000..5aed065d --- /dev/null +++ b/contracts/contracts/CrossChainReputation.sol @@ -0,0 +1,26 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.19; + +import "@openzeppelin/contracts/access/Ownable.sol"; + +contract CrossChainReputation is Ownable { + struct Reputation { + uint256 score; + uint256 taskCompleted; + uint256 disputeLost; + uint256 lastUpdated; + } + + mapping(address => Reputation) public reputations; + + event ReputationUpdated(address indexed agent, uint256 newScore); + + function updateReputation(address _agent, uint256 _score, uint256 _tasks, uint256 _disputes) external onlyOwner { + reputations[_agent] = Reputation(_score, _tasks, _disputes, block.timestamp); + emit ReputationUpdated(_agent, _score); + } + + function getReputation(address _agent) external view returns (uint256) { + return reputations[_agent].score; + } +} diff --git a/contracts/contracts/KnowledgeGraphMarket.sol b/contracts/contracts/KnowledgeGraphMarket.sol new file mode 100644 index 00000000..f94ec425 --- /dev/null +++ b/contracts/contracts/KnowledgeGraphMarket.sol @@ -0,0 +1,58 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.19; + +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/security/ReentrancyGuard.sol"; + +contract KnowledgeGraphMarket is Ownable, ReentrancyGuard { + using SafeERC20 for IERC20; + + IERC20 public aitbcToken; + uint256 public graphCounter; + uint256 public platformFeePercentage = 250; // 2.5% + + struct KnowledgeGraph { + uint256 id; + address creator; + string cid; + uint256 price; + uint256 totalSales; + bool isActive; + } + + mapping(uint256 => KnowledgeGraph) public graphs; + mapping(uint256 => mapping(address => bool)) public hasPurchased; + + event GraphListed(uint256 indexed id, address indexed creator, string cid, uint256 price); + event GraphPurchased(uint256 indexed id, address indexed buyer, uint256 price); + + constructor(address _aitbcToken) { + aitbcToken = IERC20(_aitbcToken); + } + + function listGraph(string calldata _cid, uint256 _price) external returns (uint256) { + uint256 id = graphCounter++; + graphs[id] = KnowledgeGraph(id, msg.sender, _cid, _price, 0, true); + emit GraphListed(id, msg.sender, _cid, _price); + return id; + } + + function purchaseGraph(uint256 _id) external nonReentrant { + KnowledgeGraph storage graph = graphs[_id]; + require(graph.isActive, "Graph inactive"); + require(!hasPurchased[_id][msg.sender], "Already purchased"); + + uint256 fee = (graph.price * platformFeePercentage) / 10000; + uint256 creatorAmount = graph.price - fee; + + aitbcToken.safeTransferFrom(msg.sender, address(this), graph.price); + aitbcToken.safeTransfer(graph.creator, creatorAmount); + + graph.totalSales++; + hasPurchased[_id][msg.sender] = true; + + emit GraphPurchased(_id, msg.sender, graph.price); + } +} diff --git a/contracts/contracts/MemoryVerifier.sol b/contracts/contracts/MemoryVerifier.sol new file mode 100644 index 00000000..82ad8980 --- /dev/null +++ b/contracts/contracts/MemoryVerifier.sol @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.19; + +import "@openzeppelin/contracts/access/Ownable.sol"; +import "./ZKReceiptVerifier.sol"; + +contract MemoryVerifier is Ownable { + ZKReceiptVerifier public zkVerifier; + + event MemoryVerified(address indexed agent, string cid, bool isValid); + + constructor(address _zkVerifier) { + zkVerifier = ZKReceiptVerifier(_zkVerifier); + } + + function verifyMemoryIntegrity(address _agent, string calldata _cid, bytes calldata _zkProof) external { + // Pseudo-implementation to fulfill interface requirements + bool isValid = _zkProof.length > 0; + emit MemoryVerified(_agent, _cid, isValid); + } +}