Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# ── Supabase ──────────────────────────────────────────────────────────────────
SUPABASE_URL=https://your-project.supabase.co
SUPABASE_SERVICE_ROLE_KEY=your-service-role-key

# ── OpenAI ────────────────────────────────────────────────────────────────────
OPENAI_API_KEY=sk-...

# ── Blockchain / Viem ─────────────────────────────────────────────────────────
VIEM_PRIVATE_KEY=0x... # Operator wallet private key
BASE_RPC_URL=https://mainnet.base.org # Optional: override default Base RPC

# ── Superfluid (Base mainnet) ─────────────────────────────────────────────────
SUPERFLUID_HOST_ADDRESS=0x4C073B8641AB798b3197b8B1E3bb33bB92D16Aa
SUPERFLUID_CFA_ADDRESS=0x19ba78B9cDB05A877718841c574325fdB53601bb
SUPERFLUID_GDA_ADDRESS=0x6DA13Bde224A05a288748d857b9e7DDEffd1dE08
SUPERFLUID_USDCX_ADDRESS=0xD04383398dD2426297da660F9CCA3d439AF9ce1b

# ── Payment ───────────────────────────────────────────────────────────────────
SETTLEMENT_ADDRESS=0x7bEda57074AA917FF0993fb329E16C2c188baF08
X402_PAYMENT_AMOUNT=0.15
X402_FLOW_RATE=1929012345679 # ~$5/month in wei/sec

# ── External APIs ─────────────────────────────────────────────────────────────
GOOGLE_MAPS_API_KEY=AIza...
DUNE_API_KEY=...
ARKHAM_API_KEY=...
# Note: DefiLlama is public — no API key required

# ── Auth ──────────────────────────────────────────────────────────────────────
JWT_SECRET=change-this-to-a-long-random-string-in-production

# ── Server ────────────────────────────────────────────────────────────────────
PORT=3000
NODE_ENV=production
160 changes: 72 additions & 88 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,120 +1,104 @@
import 'dotenv/config';
import express from 'express';
import cors from 'cors';

// ── Middleware ────────────────────────────────────────────────────────────────
import {
corsOptions,
globalRateLimit,
strictRateLimit,
requestLogger,
errorHandler,
} from './src/middleware/index.js';

// ── Route handlers ────────────────────────────────────────────────────────────
import marketRouter from './src/routes/market.js';
import scriptureRouter from './src/routes/scripture.js';
import churchesRouter from './src/routes/churches.js';
import streamsRouter from './src/routes/streams.js';
import x402Router from './src/routes/x402.js';
import mcpRouter from './src/routes/mcp.js';
import a2aRouter from './src/routes/a2a.js';

// ── Background jobs ───────────────────────────────────────────────────────────
import { registerJobs } from './src/jobs/index.js';

const app = express();
const PORT = process.env.PORT || 3000;

app.use(cors());
app.use(express.json());
// ── Core middleware ───────────────────────────────────────────────────────────
app.use(cors(corsOptions));
app.use(express.json({ limit: '1mb' }));
app.use(requestLogger);
app.use(globalRateLimit);

// ── Health / discovery ────────────────────────────────────────────────────────
app.get('/', (req, res) => {
res.json({
agent: 'BWTYAA - Biblical Wisdom To Yield Algorithm Agent',
version: '1.0.0',
version: '2.0.0',
status: 'operational',
operator: 'normancomics.eth',
network: 'base',
chainId: 8453,
timestamp: new Date().toISOString(),
endpoints: {
a2a: '/a2a',
mcp: '/mcp',
x402: '/x402',
market: '/v1/market',
scripture: '/v1/scripture-match',
a2a: '/a2a',
mcp: '/mcp',
x402: '/x402',
market: '/v1/market',
scripture:'/v1/scripture-match',
churches: '/v1/churches',
streams: '/v1/streams',
private: '/v1/private'
}
});
});

app.post('/a2a', (req, res) => {
res.json({
protocol: 'A2A',
status: 'operational',
message: 'Agent-to-Agent communication endpoint'
});
});

app.post('/mcp', (req, res) => {
res.json({
protocol: 'MCP',
status: 'operational',
message: 'Model Context Protocol endpoint'
});
});

app.post('/x402', (req, res) => {
res.status(402).json({
protocol: 'x402',
message: 'Payment Required',
payment_required: true,
accepted_currencies: ['USDC', 'USDCx', 'ETH'],
network: 'base',
settlement_address: '0x7bEda57074AA917FF0993fb329E16C2c188baF08'
});
});

app.post('/v1/market', (req, res) => {
res.json({
capability: 'market_intelligence',
status: 'operational',
pricing: {
model: 'per_request',
amount: '0.15',
currency: 'USDC',
network: 'base'
streams: '/v1/streams',
private: '/v1/private',
},
demo_data: {
base_tvl: '$2.4B',
top_dexs: ['Uniswap V3', 'Aerodrome', 'BaseSwap'],
fear_greed_index: 65
}
protocols: ['A2A', 'MCP', 'x402', 'ERC-8004'],
});
});

app.post('/v1/scripture-match', (req, res) => {
res.json({
capability: 'biblical_defi_correlation',
status: 'operational',
scripture: {
reference: 'Proverbs 21:5',
text: 'The thoughts of the diligent tend only to plenteousness; but of every one that is hasty only to want.',
correlation: 'Warns against hasty trading during volatility',
confidence: 0.87
}
});
});
// ── Protocol endpoints ────────────────────────────────────────────────────────
app.use('/a2a', a2aRouter);
app.use('/mcp', mcpRouter);
app.use('/x402', x402Router);

app.post('/v1/churches', (req, res) => {
res.json({
capability: 'church_database_access',
status: 'coming_soon',
authentication: 'OAuth2 required'
});
});

app.post('/v1/streams', (req, res) => {
res.json({
capability: 'superfluid_streaming',
status: 'operational',
superfluid_links: {
app: 'https://app.superfluid.finance',
console: 'https://console.superfluid.finance'
}
});
});
// ── v1 API endpoints ──────────────────────────────────────────────────────────
app.use('/v1/market', strictRateLimit, marketRouter);
app.use('/v1/scripture-match', strictRateLimit, scriptureRouter);
app.use('/v1/churches', churchesRouter);
app.use('/v1/streams', streamsRouter);

// ── /v1/private (placeholder — ZKP / veil.cash integration) ──────────────────
app.post('/v1/private', (req, res) => {
res.json({
capability: 'privacy_transactions',
status: 'coming_soon',
privacy_tech: {
zkp_language: 'Noir',
protocol: 'veil.cash'
}
protocol: 'veil.cash',
},
});
});

// ── 404 handler ───────────────────────────────────────────────────────────────
app.use((req, res) => {
res.status(404).json({
error: 'Not Found',
message: `${req.method} ${req.path} is not a valid endpoint`,
docs: 'https://biblefi-api-production.up.railway.app/',
});
});

// ── Global error handler ──────────────────────────────────────────────────────
app.use(errorHandler);

// ── Start server ──────────────────────────────────────────────────────────────
app.listen(PORT, '0.0.0.0', () => {
console.log(`🚀 BibleFi BWTYA API running on port ${PORT}`);
console.log(`🚀 BibleFi BWTYA API v2.0.0 running on port ${PORT}`);
console.log(` Network: Base (chainId 8453)`);
console.log(` Supabase: ${process.env.SUPABASE_URL ? '✅ connected' : '⚠️ not configured'}`);
console.log(` OpenAI: ${process.env.OPENAI_API_KEY ? '✅ connected' : '⚠️ not configured'}`);
console.log(` Viem: ${process.env.VIEM_PRIVATE_KEY ? '✅ configured' : '⚠️ not configured'}`);

// Start background jobs
registerJobs();
});
34 changes: 33 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1 +1,33 @@
{"name":"biblefi-api","version":"2.0.0","description":"BibleFi BWTYA Agent API — Sovereign ERC-8004 Registered AGI Swarm on Base Chain","type":"module","main":"index.js","scripts":{"start":"node index.js","dev":"node --watch index.js","seed:bible":"node rag/indexer.js","seed:churches":"node church/seeder.js","register:agents":"node x402/erc8004-registry.js"},"dependencies":{"express":"^4.18.2","cors":"^2.8.5","@supabase/supabase-js":"^2.39.0","openai":"^4.28.0","node-cron":"^3.0.3","viem":"^2.7.0","axios":"^1.6.7","dotenv":"^16.4.1","zod":"^3.22.4","uuid":"^9.0.0","ethers":"^6.10.0","express-rate-limit":"^7.1.5","jsonwebtoken":"^9.0.2","suncalc":"^1.9.0"},"engines":{"node":">=18.0.0"}}
{
"name": "biblefi-api",
"version": "2.0.0",
"description": "BibleFi BWTYA Agent API — Sovereign ERC-8004 Registered AGI Swarm on Base Chain",
"type": "module",
"main": "index.js",
"scripts": {
"start": "node index.js",
"dev": "node --watch index.js",
"seed:bible": "node rag/indexer.js",
"seed:churches": "node church/seeder.js",
"register:agents": "node x402/erc8004-registry.js"
},
"dependencies": {
"@supabase/supabase-js": "^2.39.0",
"axios": "^1.6.7",
"cors": "^2.8.5",
"dotenv": "^16.4.1",
"ethers": "^6.10.0",
"express": "^4.18.2",
"express-rate-limit": "^7.1.5",
"jsonwebtoken": "^9.0.2",
"node-cron": "^3.0.3",
"openai": "^4.28.0",
"suncalc": "^1.9.0",
"uuid": "^9.0.0",
"viem": "^2.7.0",
"zod": "^3.22.4"
},
"engines": {
"node": ">=18.0.0"
}
}
Loading