How magicblock-labs/super-smart-contracts works
Purpose and Entry Points
This is an Anchor/Solana example of “Super Smart Contracts”: on-chain agents delegate natural-language reasoning to an off-chain OpenAI-backed oracle, then receive an on-chain callback to act on the result. The main deployable surfaces are the oracle program, example agent programs, the oracle worker, and a React UI.
• programs/solana-gpt-oracle/src/lib.rs
• llm_oracle/src/main.rs
• app/src/index.tsx
On-Chain Oracle Interface
The solana-gpt-oracle Anchor program is the protocol boundary between agent contracts and the off-chain LLM executor. Agents create LLM context accounts and submit interactions through CPI, supplying their own callback program/instruction information. It owns the request/context state needed to correlate asynchronous oracle work with a destination callback.
• programs/solana-gpt-oracle/src/lib.rs
• programs/solana-gpt-oracle/Cargo.toml
Off-Chain LLM Oracle Worker
The Rust llm_oracle binary is the trusted off-chain execution stage: it observes or retrieves pending oracle interactions, maintains relevant memory/state, calls OpenAI, and returns results to Solana so the requesting program’s callback can run. This is the material trust and availability boundary: OpenAI output is not produced or verified by deterministic on-chain execution.
• llm_oracle/src/main.rs
• llm_oracle/src/memory.rs
• llm_oracle/Cargo.toml
Agent Programs and Callback Policy
Two Anchor programs demonstrate how application-specific policy is layered above the generic oracle. Each creates/configures an LLM context, invokes the oracle with CPI, and exposes a callback that consumes the response. simple-agent primarily demonstrates response handling; agent-minter demonstrates an LLM-gated token-dispensing action, making callback validation and authority checks architecturally critical.
• programs/simple-agent/src/lib.rs
• programs/agent-minter/src/lib.rs
• programs/agent-minter/Cargo.toml
Primary Interaction Flow
1. A user or client initializes an agent/context on Solana.
2. The client submits text to an agent instruction.
3. The agent CPIs into solana-gpt-oracle, creating an interaction linked to its callback.
4. The off-chain oracle worker obtains the interaction/context, invokes OpenAI, and submits a Solana transaction carrying the response.
5. The oracle invokes the agent callback; the agent logs the result or applies its domain policy, such as minting/dispensing tokens.
The callback must treat the oracle-controlled signer/identity as the authorization boundary rather than trusting arbitrary callers.
User Interface
The React application is a focused client for interacting with the token-dispensing agent. It contains wallet connectivity/signing UI, input/response presentation, and transaction-feedback components; it is not the oracle itself.
• app/src/App.tsx
• app/src/components/Wallet.tsx
• app/src/components/Signature.tsx
• app/src/components/Response.tsx
Runtime and Deployment Boundaries
On-chain code is Rust/Anchor and targets Solana; the UI is TypeScript/React; the oracle is a separate Rust process requiring Solana RPC/network access and OpenAI API access. Docker and Fly configuration indicate deployable service infrastructure for the off-chain worker, while Anchor migration code supports program deployment/setup.
• Dockerfile
• fly.toml
• fly-mainnet.toml
• migrations/deploy.ts
Main entry points: src/lib.rs GPT oracle program · main.rs LLM oracle worker · App.tsx React UI · src/lib.rs Agent minter
Components 15
Solana / Anchor
Programs execute on-chain and communicate through instructions and CPI.
- Agent minter · Applies callback policy before token-dispensing actions.
programs/agent-minter/src/lib.rs - Simple agent · Demonstrates LLM response handling.
programs/simple-agent/src/lib.rs - GPT oracle program · Creates correlated interaction/context state and routes callbacks.
programs/solana-gpt-oracle/src/lib.rs - Interaction context · Stores pending request, context, and callback destination.
programs/solana-gpt-oracle/src/lib.rs - Agent callback · Must authorize the oracle-controlled signer or identity.
programs/agent-minter/src/lib.rs - Anchor deployment · Supports Solana program deployment and setup.
migrations/deploy.ts
Oracle Service
Trusted off-chain LLM execution boundary.
- LLM oracle worker · Retrieves pending interactions and submits response transactions.
llm_oracle/src/main.rs - Oracle memory · Maintains relevant off-chain context for LLM requests.
llm_oracle/src/memory.rs - Worker deployment · Deploys the separate oracle worker service.
Dockerfile
Client
React client for the token-dispensing agent.
- React UI · Wallet-connected interface for agent-minter interactions.
app/src/App.tsx - Wallet UI
app/src/components/Wallet.tsx - Transaction feedback · Displays transaction signatures and oracle responses.
app/src/components/Signature.tsx
Other components
- User
- OpenAI · Non-deterministic external reasoning provider.
- Solana RPC · Worker reads chain state and submits signed transactions.
Connections 18
- User → React UI: uses
- React UI → Wallet UI: connects and signs
- React UI → Agent minter: submits text transaction
- React UI → Transaction feedback: renders result
- Agent minter → GPT oracle program: CPI request
- Simple agent → GPT oracle program: CPI request
- GPT oracle program → Interaction context: creates pending interaction
- LLM oracle worker → Solana RPC: reads and submits transactions
- Solana RPC → Interaction context: retrieves pending request
- LLM oracle worker → Oracle memory: maintains context
- LLM oracle worker → OpenAI: invokes LLM
- LLM oracle worker → GPT oracle program: submits LLM response
- GPT oracle program → Agent callback: invokes configured callback
- Agent callback → Agent minter: authorizes and dispenses
- Worker deployment → LLM oracle worker: deploys
- Anchor deployment → GPT oracle program: deploys
- Anchor deployment → Agent minter: deploys
- Anchor deployment → Simple agent: deploys