AegisNet Documentation
Build and run guardrailed AI trading agents: 0G Private Compute strategy planning, AegisExecutionManager on-chain spending limits, ENS Subname Owner Approval Gate for high-value orders, Uniswap V3 (SwapRouter02) atomic execution on Ethereum Sepolia, and 0G Storage immutable audit trails.
Overview
Each agent is registered in AegisSubnameRegistry with an owner, an approved target whitelist, a 24-hour spending limit, and a configurable approval threshold. AegisExecutionManager strictly enforces these permissions onchain on Ethereum Sepolia. Trades at or above the threshold pause onchain until the registered owner authorizes via the ENS Owner Human Approval Gate.
Users sign every onchain transaction with their own wallet. The backend never holds user keys: it plans strategies with 0G Private Compute TEEs, verifies ENS subname owner authorization, signs the relayer attestation trusted by the manager, commits decision records to 0G Storage, and indexes contract events.
Quickstart
1. Install
cd contracts && npm install
cd ../backend && npm install
cp .env.example .env # fill in SEPOLIA_RPC_URL, PRIVATE_KEY, RELAYER_PRIVATE_KEY, ZG_COMPUTE_API_KEY
2. Test
cd contracts && npm test # EVM contract unit tests (10 passing)
cd ../backend && npm run build # TypeScript compilation
3. Run
cd backend
npm run build && npm start
# App, console and API on http://localhost:4000
4. Deploy
docker build -t aegisnet .
docker run -p 4000:4000 --env-file backend/.env -e NODE_ENV=production -v aegis-data:/app/data aegisnet
How a trade flows
1. Plan POST /api/agent/propose → 0G Private Compute plan + encoded Uniswap V3 calldata
2. Submit agent wallet → requestExecution(adapter, calldata, valueUSD)
· under the threshold: executes in the same transaction on Uniswap V3
· at or above: ExecutionRequested(requiresApproval = true)
3. Gate owner authorizes via ENS Owner Approval Gate
POST /api/approval/session → creates verification session
POST /api/approval/verify → validates owner authorization & returns relayer attestation
4. Approve owner wallet → approveWithRelayer(requestId, nullifier, deadline, signature)
5. Execute atomic execution settles on Uniswap V3 on Sepolia
or Cancel owner/agent wallet → cancelExecution(requestId)
6. Record backend publishes decision record to 0G Storage, returning immutable Merkle root
Architecture (ENSv2 Identity, 0G Guardrails & Uniswap V3)
Browser (landing + console)
├─ wallet (EIP-6963) ──── signs ───► AegisSubnameRegistry · AegisExecutionManager · AegisUniswapAdapter
└─ ENS Owner Gate ──── approves ──► Cryptographic Relayer Attestation
│
▼
Backend (Node/Express, one container)
├─ 0G Private Compute ─ TEE-attested strategy planning (0gm-1.0-35b-a3b)
├─ Approval gateway ─ ENS subname owner authorization · single-use nullifiers · relayer attestation
├─ Uniswap V3 service ─ official SwapRouter02 routing & slippage boundaries
├─ 0G Storage SDK ─ immutable Merkle audit records on 0G Galileo testnet
└─ Chain indexer ─ contract events → activity & agent states
REST API
GET /api/health
Chain connectivity, relayer check, contract addresses, approval gate settings, 0G status and indexer cursor.
{
"status": "online",
"protocol": "AegisNet: Guardrailed AI Agent Execution",
"network": "Sepolia",
"relayer": { "address": "0x3C29…", "matchesContract": true },
"approvalGate": "ENS Owner Human Approval Gate",
"ai": { "provider": "0g", "enabled": true, "model": "0gm-1.0-35b-a3b" },
"zg": { "status": "operational", "computeEndpoint": "https://router-api.0g.ai/v1" },
"uniswapRouter": "0x3bFA4769FB09eefC5a80d6E87c3B9C650f7Ae48E",
"indexer": { "cursor": 7234567, "synced": true },
"contracts": {
"AegisSubnameRegistry": "0x6Dbd89B71e8AB7BF93a9200C6fB81951699549FE",
"AegisExecutionManager": "0x13d7b8Add8265AB1Cfdc3a6E8E60D1b3bcD56fa8",
"AegisUniswapAdapter": "0xD855719f7Cc2cD867540F8398E3d2Fa4b2dD8221"
}
}
POST /api/agent/propose
Plans a trade strategy via 0G Private Compute and returns the encoded Uniswap V3 calldata for the agent wallet to submit. Nothing is broadcast onchain. Rate limited.
// Request
{ "agentAddress": "0x…", "goalPrompt": "Swap 2500 USDC to WETH", "amountUSD": 2500 }
// Response
{
"proposal": {
"planner": "0g",
"summary": "Swap $2,500 USDC to WETH via Uniswap V3",
"strategyType": "uniswap_v3_swap",
"requiresApproval": true,
"authorization": { "isAllowed": true, "requiresApproval": true },
"dailyLimit": { "limitUSD": 50000, "remainingUSD": 47500, "exceeds": false }
},
"targetContract": "0xD855719f7Cc2cD867540F8398E3d2Fa4b2dD8221",
"encodedCallData": "0x…",
"zg": { "requestId": "0xb9fed931…", "rootHash": "0xc9d554…" }
}
POST /api/approval/session · /api/approval/verify
Creates an approval session, verifies the registered ENS domain owner, derives the single-use nullifier, and returns the ECDSA relayer attestation for approveWithRelayer. Rate limited.
// Verify Request
{
"sessionId": "session-1730900000-0x1234",
"mockNullifier": "0x…"
}
// Response
{
"sessionId": "session-1730900000-0x1234",
"status": "approved",
"nullifierHash": "0x9876…",
"relayerAttestation": "0x…",
"deadline": 1730903600
}
GET /api/execution/requests?agent=&owner=
Every trade request on the execution manager, indexed from Sepolia chain events, with statuses (PENDING, APPROVED, EXECUTED, CANCELLED) and transaction hashes. POST /api/execution/refresh indexes the latest block immediately.
GET /api/uniswap/info
Official Uniswap V3 router deployment on Sepolia (SwapRouter02: 0x3bFA4769FB09eefC5a80d6E87c3B9C650f7Ae48E), adapter contract address, and pool liquidity details.
GET /api/zg/status · /api/zg/proof
Live health of 0G Private Compute and 0G Storage, latest verifiable TEE Request ID, latest decentralized Merkle root hash, and reproduction test runner (POST /api/zg/prove).
POST Admin routes
For automated bots whose agent key is the backend wallet: /api/agent/execute and /api/execution/:id/execute|cancel. Protected by the x-api-key header (ADMIN_API_KEY).
Smart Contracts
AegisSubnameRegistry.sol
Agent identity registration, owner bindings, allowed target contract whitelists, and daily spending limits.
function registerSubname(string subnameLabel, address agentAddress, uint256 approvalThresholdUSD, uint256 dailySpendingLimit) returns (bytes32);
function setTargetContractWhitelist(bytes32 node, address target, bool allowed); // owner
function updateApprovalThreshold(bytes32 node, uint256 thresholdUSD); // owner (approval threshold setter)
function revokeSubname(bytes32 node); // owner
function isAgentAuthorized(address agent, address target, uint256 valueUSD) view returns (bool, bool, bytes32);
AegisExecutionManager.sol
Verifies caller authorization, queues orders exceeding approval thresholds, and triggers execution upon receiving valid relayer attestations.
function requestExecution(address target, bytes callData, uint256 valueUSD) returns (bytes32 requestId, bool requiresApproval);
function approveWithRelayer(bytes32 requestId, uint256 nullifierHash, bytes signature);
function executeVerifiedTransaction(bytes32 requestId);
function cancelExecution(bytes32 requestId); // owner, agent or protocol owner
AegisUniswapAdapter.sol
Executes exact-input swaps on Uniswap V3 (callable only by the manager): routes directly to the official Sepolia SwapRouter02 (0x3bFA4769FB09eefC5a80d6E87c3B9C650f7Ae48E) with configured slippage protection.
function executeExactInputSingle(address tokenIn, address tokenOut, uint24 fee, uint256 amountIn, uint256 amountOutMinimum, address recipient) returns (uint256 amountOut);
function executeSwap(address tokenIn, address tokenOut, uint256 amountIn, uint256 amountOutMinimum, address recipient) returns (uint256 amountOut);