Skip to main content

Agent Entry Points

Starting Agents


Startup Flow

Both agents follow the same startup pattern:
The catch-up scan ensures the agent is stateless — it can restart from any point without losing track of markets.

Event Listener Pattern

All event listeners follow a safe wrapper that prevents unhandled rejections from crashing the agent:

Transaction Queue Pattern

The market-maker uses a FIFO transaction queue to prevent nonce collisions when multiple events arrive simultaneously:
All market-maker transactions go through enqueue(). The oracle has fewer concurrent operations but uses the same pattern for safety.

Adding a New Oracle Data Source

To add a new approved data source that the oracle can reference:

1. Update the validation prompt in compute.ts

2. Include it in market metadata at creation

The frontend already allows market creators to specify up to 5 custom sources. These get stored in the 0G Storage metadata blob and are read by the oracle at resolution time.

3. No contract changes needed

Sources are entirely off-chain data stored in 0G Storage. The contracts only store the metadata root hash.

Testing Compute and Storage Integrations

Manual testing with test scripts

Unit testing agent logic

Agent logic (excluding 0G dependencies) can be tested with mocks:

Logging Format

All log output uses structured JSON via the logger module. Every entry includes:
Control log level via environment variable:

Config System

The cfg() helper in agent/src/shared/config.ts provides typed, validated env var access:
All configuration is loaded at startup and validated before any connections are made. A missing required variable causes the agent to exit immediately with a clear error message, rather than failing silently later.

Common Development Tasks

Add a new event handler to the oracle

Add a new market-maker strategy

Extend the storage schema

If you need to store new data in 0G Storage, just add fields to the JSON object. There is no schema enforcement — 0G Storage stores arbitrary bytes.