-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSightCoreAgent.sol
More file actions
165 lines (140 loc) · 7.56 KB
/
SightCoreAgent.sol
File metadata and controls
165 lines (140 loc) · 7.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
contract SightCoreAgent {
// ─── Agent Metadata ───────────────────────────────────────────────────────
string public constant NAME = "SightCore";
string public constant DESCRIPTION = "AI Crypto Technical Analysis Agent";
string public constant VERSION = "1.0.0";
string public agentUrl = "https://sightcore.ai";
address public owner;
// ─── Inference Config ─────────────────────────────────────────────────────
uint256 public queryFee = 0;
uint256 public requestCount;
// ─── Structs ──────────────────────────────────────────────────────────────
struct InferenceRequest {
address requester;
string prompt;
uint256 fee;
uint256 timestamp;
bool fulfilled;
}
struct InferenceResult {
bytes32 requestId;
string result;
bytes32 proofHash;
uint256 timestamp;
}
// ─── Storage ──────────────────────────────────────────────────────────────
mapping(bytes32 => InferenceRequest) public requests;
mapping(bytes32 => InferenceResult) public results;
bytes32[] public requestIds;
// ─── Events ───────────────────────────────────────────────────────────────
event AgentDeployed(address indexed owner, string agentUrl);
event InferenceRequested(bytes32 indexed requestId, address indexed requester, string prompt, uint256 fee);
event InferenceFulfilled(bytes32 indexed requestId, bytes32 proofHash, uint256 timestamp);
event PaymentReceived(address indexed from, uint256 amount);
event Withdrawn(address indexed owner, uint256 amount);
event FeeUpdated(uint256 oldFee, uint256 newFee);
event AgentUrlUpdated(string oldUrl, string newUrl);
// ─── Modifiers ────────────────────────────────────────────────────────────
modifier onlyOwner() {
require(msg.sender == owner, "Not owner");
_;
}
// ─── Constructor ──────────────────────────────────────────────────────────
constructor() {
owner = msg.sender;
emit AgentDeployed(msg.sender, agentUrl);
}
// ─── Core: Request Inference ──────────────────────────────────────────────
function requestInference(string calldata prompt) external payable returns (bytes32 requestId) {
require(msg.value >= queryFee, "Insufficient fee");
require(bytes(prompt).length > 0, "Empty prompt");
requestId = keccak256(
abi.encodePacked(msg.sender, prompt, block.timestamp, requestCount)
);
requests[requestId] = InferenceRequest({
requester: msg.sender,
prompt: prompt,
fee: msg.value,
timestamp: block.timestamp,
fulfilled: false
});
requestIds.push(requestId);
requestCount++;
emit InferenceRequested(requestId, msg.sender, prompt, msg.value);
emit PaymentReceived(msg.sender, msg.value);
}
// ─── Core: Submit Inference Result ────────────────────────────────────────
function submitInference(
bytes32 requestId,
string calldata result,
bytes32 proofHash
) external onlyOwner {
require(requests[requestId].requester != address(0), "Request not found");
require(!requests[requestId].fulfilled, "Already fulfilled");
requests[requestId].fulfilled = true;
results[requestId] = InferenceResult({
requestId: requestId,
result: result,
proofHash: proofHash,
timestamp: block.timestamp
});
emit InferenceFulfilled(requestId, proofHash, block.timestamp);
}
// ─── Read: Get Inference Result ───────────────────────────────────────────
function getInferenceResult(bytes32 requestId) external view returns (
string memory result,
bytes32 proofHash,
uint256 timestamp,
bool fulfilled
) {
return (
results[requestId].result,
results[requestId].proofHash,
results[requestId].timestamp,
requests[requestId].fulfilled
);
}
// ─── Read: Get Agent Info ─────────────────────────────────────────────────
function getAgentInfo() external view returns (
string memory name,
string memory agentUrl_,
address owner_,
uint256 totalRequests,
uint256 balance,
uint256 fee
) {
return (NAME, agentUrl, owner, requestCount, address(this).balance, queryFee);
}
// ─── Read: Quote ──────────────────────────────────────────────────────────
function quoteDispatch() external view returns (uint256) {
return queryFee;
}
// ─── Owner: Withdraw ──────────────────────────────────────────────────────
function withdraw() external onlyOwner {
uint256 balance = address(this).balance;
require(balance > 0, "Nothing to withdraw");
(bool ok, ) = owner.call{value: balance}("");
require(ok, "Transfer failed");
emit Withdrawn(owner, balance);
}
// ─── Owner: Set Fee ───────────────────────────────────────────────────────
function setQueryFee(uint256 newFee) external onlyOwner {
emit FeeUpdated(queryFee, newFee);
queryFee = newFee;
}
// ─── Owner: Set Agent URL ─────────────────────────────────────────────────
function setAgentUrl(string calldata newUrl) external onlyOwner {
emit AgentUrlUpdated(agentUrl, newUrl);
agentUrl = newUrl;
}
// ─── Owner: Transfer Ownership ────────────────────────────────────────────
function transferOwnership(address newOwner) external onlyOwner {
require(newOwner != address(0), "Zero address");
owner = newOwner;
}
receive() external payable {
emit PaymentReceived(msg.sender, msg.value);
}
}