-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.sql
More file actions
82 lines (73 loc) · 3.3 KB
/
Copy pathschema.sql
File metadata and controls
82 lines (73 loc) · 3.3 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
-- AegisGuard.init Supabase Schema
-- Designed for DoraHacks Liquify Indexer Hacks
-- Optimized for Realtime SOC Analytics
-- Enable UUID Extension
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
-- Mock Supabase roles for local Postgres deployment
DO $$
BEGIN
IF NOT EXISTS (SELECT FROM pg_catalog.pg_roles WHERE rolname = 'anon') THEN
CREATE ROLE anon NOLOGIN;
END IF;
IF NOT EXISTS (SELECT FROM pg_catalog.pg_roles WHERE rolname = 'service_role') THEN
CREATE ROLE service_role NOLOGIN;
END IF;
END
$$;
-- Table: chains
-- Purpose: Tracks monitored rollups/L2s integrated via InterwovenKit
CREATE TABLE chains (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
chain_id VARCHAR(255) UNIQUE NOT NULL,
name VARCHAR(255) NOT NULL,
rpc_url TEXT NOT NULL,
liquify_rpc_url TEXT,
created_at TIMESTAMP WITH TIME ZONE DEFAULT timezone('utc', now())
);
-- Table: alerts
-- Purpose: Core SOC detections and heartbeat logs
CREATE TABLE alerts (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
session_id VARCHAR(255) NOT NULL,
threat_type VARCHAR(255) NOT NULL,
severity VARCHAR(50) CHECK (severity IN ('CRITICAL', 'HIGH', 'MEDIUM', 'LOW', 'NONE')),
target_user_address VARCHAR(255) NOT NULL,
action_payload TEXT,
intercepted BOOLEAN DEFAULT false,
confidence_score DECIMAL(5, 4),
gas_saved BIGINT DEFAULT 0,
created_at TIMESTAMP WITH TIME ZONE DEFAULT timezone('utc', now())
);
-- Table: benchmarks
-- Purpose: Latency metrics proving Liquify API superiority
CREATE TABLE benchmarks (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
chain_id VARCHAR(255) REFERENCES chains(chain_id),
standard_latency_ms DECIMAL(8, 2) NOT NULL,
liquify_latency_ms DECIMAL(8, 2) NOT NULL,
measured_at TIMESTAMP WITH TIME ZONE DEFAULT timezone('utc', now())
);
-- Table: exploits
-- Purpose: Catalog of known historical signatures for AI scanning
CREATE TABLE exploits (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
signature_hash VARCHAR(255) UNIQUE NOT NULL,
exploit_family VARCHAR(255) NOT NULL, -- e.g., 'Flash Loan', 'Reentrancy'
description TEXT,
added_at TIMESTAMP WITH TIME ZONE DEFAULT timezone('utc', now())
);
-- Enable Row Level Security (RLS)
ALTER TABLE chains ENABLE ROW LEVEL SECURITY;
ALTER TABLE alerts ENABLE ROW LEVEL SECURITY;
ALTER TABLE benchmarks ENABLE ROW LEVEL SECURITY;
ALTER TABLE exploits ENABLE ROW LEVEL SECURITY;
-- Policies for anon reads (SOC Dashboard view)
CREATE POLICY "Enable read access for all users on chains" ON chains FOR SELECT USING (true);
CREATE POLICY "Enable read access for all users on alerts" ON alerts FOR SELECT USING (true);
CREATE POLICY "Enable read access for all users on benchmarks" ON benchmarks FOR SELECT USING (true);
CREATE POLICY "Enable read access for all users on exploits" ON exploits FOR SELECT USING (true);
-- Polices for service_role writes (Python Backend insertion)
-- These allow the backend to insert without exposing write access to the client.
-- Note: Service_role bypasses RLS by default, but defining them explicitly is good practice.
CREATE POLICY "Enable insert access for service_role on alerts" ON alerts FOR INSERT TO service_role WITH CHECK (true);
CREATE POLICY "Enable insert access for service_role on benchmarks" ON benchmarks FOR INSERT TO service_role WITH CHECK (true);