File size: 2,007 Bytes
6da08bc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from fastapi import FastAPI, Header, Response
from pydantic import BaseModel
from typing import Dict, Optional
import random
import time

app = FastAPI(
    title="AgentOracle x402",
    description="Real-time sentiment and price data for agent-native tokens. Pay $0.05 per query."
)

# Config
RECEIVER_WALLET = "0x2d44fc27a616606b42448309F4d8e3F423d93267"
PRICE_USDC = 0.05
PRICE_ATOMIC = int(PRICE_USDC * 1_000_000)

class OracleResponse(BaseModel):
    token: str
    price_usd: float
    sentiment: str
    trend: str
    timestamp: str

@app.get("/")
async def root():
    return {"message": "AgentOracle is ONLINE. POST /query to get market intel."}

@app.post("/query", response_model=OracleResponse)
async def get_intel(
    token_name: str,
    response: Response,
    x_payment: Optional[str] = Header(None)
):
    # x402 Payment Gate
    if not x_payment or not x_payment.startswith("pay_"):
        response.status_code = 402
        response.headers["WWW-Authenticate"] = f'Token realm="x402", as_id="{RECEIVER_WALLET}", min_amount="{PRICE_ATOMIC}", currency="USDC", network="base"'
        return {
            "error": "Payment Required",
            "message": f"Send {PRICE_USDC} USDC to {RECEIVER_WALLET} on Base to unlock this oracle data.",
            "payment_details": {
                "address": RECEIVER_WALLET,
                "amount": PRICE_ATOMIC,
                "chain": "base"
            }
        }

    # Market Intel Logic (Simulated for MVP)
    prices = {"VIRTUAL": 1.24, "PROMPT": 0.85, "MOLT": 0.12, "SIM": 0.05}
    sentiments = ["BULLISH", "BEARISH", "NEUTRAL", "EXTREME GREED"]
    
    return OracleResponse(
        token=token_name.upper(),
        price_usd=prices.get(token_name.upper(), random.uniform(0.1, 2.0)),
        sentiment=random.choice(sentiments),
        trend="UP" if random.random() > 0.5 else "DOWN",
        timestamp=str(int(time.time()))
    )

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=7860)