Repository navigation
Expand file tree
/
Copy pathneon-schema.sql
More file actions
56 lines (47 loc) · 2.19 KB
/
Copy pathneon-schema.sql
File metadata and controls
56 lines (47 loc) · 2.19 KB
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
-- BagsWorld Global Tokens Schema (Neon)
-- The app auto-creates tables on first connection, but you can run this manually if needed
CREATE TABLE IF NOT EXISTS tokens (
id SERIAL PRIMARY KEY,
mint TEXT UNIQUE NOT NULL,
name TEXT NOT NULL,
symbol TEXT NOT NULL,
description TEXT,
image_url TEXT,
creator_wallet TEXT NOT NULL,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
-- Fee shares stored as JSONB array
-- Format: [{"provider": "twitter", "username": "user", "bps": 500}, ...]
fee_shares JSONB DEFAULT '[]',
-- Live data (updated by world-state API)
lifetime_fees DECIMAL DEFAULT 0,
market_cap DECIMAL DEFAULT 0,
volume_24h DECIMAL DEFAULT 0,
last_updated TIMESTAMP WITH TIME ZONE,
-- Metadata
is_featured BOOLEAN DEFAULT FALSE,
is_verified BOOLEAN DEFAULT FALSE,
-- Admin controls
level_override INTEGER -- Override building level (1-5), null = use market cap
);
-- Indexes for faster queries
CREATE INDEX IF NOT EXISTS idx_tokens_mint ON tokens(mint);
CREATE INDEX IF NOT EXISTS idx_tokens_creator ON tokens(creator_wallet);
CREATE INDEX IF NOT EXISTS idx_tokens_featured ON tokens(is_featured);
CREATE INDEX IF NOT EXISTS idx_tokens_created ON tokens(created_at DESC);
-- ============================================
-- Creator Rewards State Persistence
-- ============================================
-- Stores the rewards agent state so it persists across server restarts
CREATE TABLE IF NOT EXISTS rewards_state (
id SERIAL PRIMARY KEY,
cycle_start_time BIGINT NOT NULL, -- Unix timestamp when current cycle started
total_distributed DECIMAL DEFAULT 0, -- Total SOL ever distributed
distribution_count INTEGER DEFAULT 0, -- Number of distributions completed
last_distribution BIGINT DEFAULT 0, -- Unix timestamp of last distribution
recent_distributions JSONB DEFAULT '[]', -- Recent distribution history (last 10)
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
-- Insert initial row if empty
INSERT INTO rewards_state (cycle_start_time, total_distributed, distribution_count, last_distribution, recent_distributions)
SELECT extract(epoch from now()) * 1000, 0, 0, 0, '[]'
WHERE NOT EXISTS (SELECT 1 FROM rewards_state);