-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsupabase-operation-receipts.sql
More file actions
706 lines (635 loc) · 20.7 KB
/
supabase-operation-receipts.sql
File metadata and controls
706 lines (635 loc) · 20.7 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
create extension if not exists "pgcrypto";
create table if not exists public.operation_receipts (
id uuid primary key default gen_random_uuid(),
created_at timestamptz not null default now(),
operation_type text not null,
proposal_id text not null,
dao_address text,
approval_state text not null,
execution_reference text not null,
private_settlement_rail text not null,
stablecoin_symbol text not null,
audit_mode text not null,
recipient_visibility text not null,
metadata jsonb not null default '{}'::jsonb
);
alter table public.operation_receipts
add column if not exists updated_at timestamptz not null default now(),
add column if not exists operation_type text not null default 'operation_receipt',
add column if not exists proposal_id text not null default 'unknown-proposal',
add column if not exists dao_address text,
add column if not exists approval_state text not null default 'confirmed',
add column if not exists execution_reference text not null default 'manual-intake',
add column if not exists private_settlement_rail text not null default 'testnet-receipt-rail',
add column if not exists stablecoin_symbol text not null default 'SOL',
add column if not exists audit_mode text not null default 'scoped-viewing-key',
add column if not exists recipient_visibility text not null default 'recipient-private',
add column if not exists metadata jsonb not null default '{}'::jsonb,
add column if not exists rail text,
add column if not exists asset text,
add column if not exists amount text,
add column if not exists recipient text,
add column if not exists memo text,
add column if not exists status text;
create table if not exists public.governance_receipts (
id uuid primary key default gen_random_uuid(),
proposal_id text not null,
operation_type text not null,
asset text not null,
amount text not null,
recipient text not null,
rail text not null,
tx_hash text not null,
status text not null,
created_at timestamptz not null default now()
);
alter table public.governance_receipts
add column if not exists proposal_id text not null default 'unknown-proposal',
add column if not exists operation_type text not null default 'governance_operation',
add column if not exists asset text not null default 'SOL',
add column if not exists amount text not null default '0',
add column if not exists recipient text not null default 'testnet-recipient',
add column if not exists rail text not null default 'browser-direct-supabase',
add column if not exists tx_hash text not null default 'pending-testnet-signature',
add column if not exists status text not null default 'confirmed',
add column if not exists voter text not null default 'browser-direct-supabase',
add column if not exists vote_direction text not null default 'abstain';
alter table public.governance_receipts
alter column proposal_id set default 'unknown-proposal',
alter column operation_type set default 'governance_operation',
alter column asset set default 'SOL',
alter column amount set default '0',
alter column recipient set default 'testnet-recipient',
alter column rail set default 'browser-direct-supabase',
alter column tx_hash set default 'pending-testnet-signature',
alter column status set default 'confirmed';
alter table public.governance_receipts
alter column voter set default 'browser-direct-supabase',
alter column vote_direction set default 'abstain';
create table if not exists public.cloak_delivery_state (
id uuid primary key default gen_random_uuid(),
rail text not null,
operation_type text not null,
asset text not null,
amount text not null,
recipient text not null,
memo text not null,
audit_mode text not null,
recipient_visibility text not null,
response_status text not null,
created_at timestamptz not null default now()
);
create table if not exists public.freshness_pings (
id uuid primary key default gen_random_uuid(),
tx_signature text not null unique,
slot bigint not null,
timestamp timestamptz not null default now(),
visitor_ua text
);
create table if not exists public.visitor_sessions (
id uuid primary key default gen_random_uuid(),
session_id text not null,
page text not null default '/',
timestamp timestamptz not null default now(),
country_hint text
);
create table if not exists public.live_transactions (
sig text primary key,
instruction text not null default 'program-interaction',
wallet text not null default 'unknown-wallet',
slot bigint not null,
timestamp timestamptz not null default now(),
wallet_type text not null default 'wallet-signed-testnet'
);
create table if not exists public.visitor_transactions (
id uuid primary key default gen_random_uuid(),
tx_signature text not null unique,
session_id text not null,
wallet_address text,
wallet_name text,
action text not null default 'testnet-transaction',
page text not null default '/',
status text not null default 'submitted',
slot bigint,
created_at timestamptz not null default now()
);
create table if not exists public.onboarding_requests (
id uuid primary key default gen_random_uuid(),
created_at timestamptz not null default now(),
tier text not null,
profile text not null,
challenges text[] not null default '{}'::text[],
other_challenge text,
treasury_size text not null,
voting_members text not null,
monthly_decisions text not null,
current_setup text[] not null default '{}'::text[],
preferred_chain text not null,
developer_context text not null,
name text not null,
email text not null,
organization text,
website text,
telegram text,
timeline text not null,
source text,
notes text,
utm_source text,
status text not null default 'new'
);
create table if not exists public.operation_execution_events (
id uuid primary key default gen_random_uuid(),
created_at timestamptz not null default now(),
operation_id text not null,
operation_label text not null,
session_id text not null,
page text not null default '/',
status text not null default 'success',
source text not null default 'visitor-browser',
receipt_hash text,
network text,
metadata jsonb not null default '{}'::jsonb
);
alter table public.operation_execution_events
add column if not exists created_at timestamptz not null default now(),
add column if not exists operation_id text not null default 'unknown-operation',
add column if not exists operation_label text not null default 'Unknown operation',
add column if not exists session_id text not null default 'anonymous-session',
add column if not exists page text not null default '/',
add column if not exists status text not null default 'success',
add column if not exists source text not null default 'visitor-browser',
add column if not exists receipt_hash text,
add column if not exists network text,
add column if not exists metadata jsonb not null default '{}'::jsonb;
create index if not exists operation_execution_events_created_at_idx
on public.operation_execution_events (created_at desc);
create index if not exists operation_execution_events_operation_idx
on public.operation_execution_events (operation_id);
create index if not exists operation_execution_events_session_idx
on public.operation_execution_events (session_id);
create table if not exists public.proof_stats (
id text primary key default 'global',
last_tx_signature text,
last_tx_time timestamptz,
last_tx_slot bigint,
total_proposals integer not null default 0,
total_daos integer not null default 0,
total_payouts integer not null default 0,
wallet_coverage_count integer not null default 0,
freshness_seconds integer not null default 0,
updated_at timestamptz not null default now()
);
insert into public.proof_stats (id)
values ('global')
on conflict (id) do nothing;
alter table public.cloak_delivery_state
add column if not exists updated_at timestamptz not null default now(),
add column if not exists operation_id text,
add column if not exists cloak_status text,
add column if not exists relayer_endpoint text,
add column if not exists relayer_response jsonb,
add column if not exists attempts integer not null default 0,
add column if not exists last_attempt_at timestamptz,
add column if not exists delivered_at timestamptz,
add column if not exists stealth_address text,
add column if not exists ephemeral_pubkey text,
add column if not exists rail text not null default 'umbra-devnet-relayer',
add column if not exists operation_type text not null default 'private_settlement',
add column if not exists asset text not null default 'USDC',
add column if not exists amount text not null default '0',
add column if not exists recipient text not null default 'testnet-recipient-private',
add column if not exists memo text not null default 'manual-intake',
add column if not exists audit_mode text not null default 'scoped-viewing-key',
add column if not exists recipient_visibility text not null default 'recipient-private',
add column if not exists response_status text not null default 'prepared';
create index if not exists operation_receipts_created_at_idx
on public.operation_receipts (created_at desc);
create index if not exists operation_receipts_proposal_id_idx
on public.operation_receipts (proposal_id);
create index if not exists governance_receipts_created_at_idx
on public.governance_receipts (created_at desc);
create index if not exists governance_receipts_proposal_id_idx
on public.governance_receipts (proposal_id);
create index if not exists cloak_delivery_state_created_at_idx
on public.cloak_delivery_state (created_at desc);
create index if not exists freshness_pings_timestamp_idx
on public.freshness_pings (timestamp desc);
create index if not exists visitor_sessions_timestamp_idx
on public.visitor_sessions (timestamp desc);
create index if not exists visitor_sessions_session_idx
on public.visitor_sessions (session_id);
create index if not exists visitor_sessions_page_idx
on public.visitor_sessions (page);
create index if not exists live_transactions_timestamp_idx
on public.live_transactions (timestamp desc);
create index if not exists live_transactions_instruction_idx
on public.live_transactions (instruction);
create index if not exists visitor_transactions_created_at_idx
on public.visitor_transactions (created_at desc);
create index if not exists visitor_transactions_session_idx
on public.visitor_transactions (session_id);
create index if not exists onboarding_requests_created_at_idx
on public.onboarding_requests (created_at desc);
create index if not exists onboarding_requests_tier_idx
on public.onboarding_requests (tier);
do $$
begin
begin
alter publication supabase_realtime add table public.operation_receipts;
exception
when duplicate_object then null;
when undefined_object then null;
end;
begin
alter publication supabase_realtime add table public.governance_receipts;
exception
when duplicate_object then null;
when undefined_object then null;
end;
begin
alter publication supabase_realtime add table public.cloak_delivery_state;
exception
when duplicate_object then null;
when undefined_object then null;
end;
begin
alter publication supabase_realtime add table public.freshness_pings;
exception
when duplicate_object then null;
when undefined_object then null;
end;
begin
alter publication supabase_realtime add table public.visitor_sessions;
exception
when duplicate_object then null;
when undefined_object then null;
end;
begin
alter publication supabase_realtime add table public.live_transactions;
exception
when duplicate_object then null;
when undefined_object then null;
end;
begin
alter publication supabase_realtime add table public.operation_execution_events;
exception
when duplicate_object then null;
when undefined_object then null;
end;
begin
alter publication supabase_realtime add table public.proof_stats;
exception
when duplicate_object then null;
when undefined_object then null;
end;
begin
alter publication supabase_realtime add table public.visitor_transactions;
exception
when duplicate_object then null;
when undefined_object then null;
end;
begin
alter publication supabase_realtime add table public.onboarding_requests;
exception
when duplicate_object then null;
when undefined_object then null;
end;
end $$;
alter table public.operation_receipts enable row level security;
alter table public.governance_receipts enable row level security;
alter table public.cloak_delivery_state enable row level security;
alter table public.freshness_pings enable row level security;
alter table public.visitor_sessions enable row level security;
alter table public.live_transactions enable row level security;
alter table public.operation_execution_events enable row level security;
alter table public.proof_stats enable row level security;
alter table public.visitor_transactions enable row level security;
alter table public.onboarding_requests enable row level security;
grant select, insert on public.operation_receipts to anon;
grant select, insert on public.governance_receipts to anon;
grant select, insert on public.cloak_delivery_state to anon;
grant select, insert on public.freshness_pings to anon;
grant select, insert on public.visitor_sessions to anon;
grant select, insert on public.live_transactions to anon;
grant select, insert on public.operation_execution_events to anon;
grant select, update on public.proof_stats to anon;
grant select, insert on public.visitor_transactions to anon;
grant select, insert on public.onboarding_requests to anon;
do $$
begin
if not exists (
select 1
from pg_policies
where schemaname = 'public'
and tablename = 'operation_receipts'
and policyname = 'operation_receipts_select'
) then
create policy operation_receipts_select
on public.operation_receipts
for select
to anon, authenticated
using (true);
end if;
end $$;
do $$
begin
if not exists (
select 1
from pg_policies
where schemaname = 'public'
and tablename = 'live_transactions'
and policyname = 'live_transactions_select'
) then
create policy live_transactions_select
on public.live_transactions
for select
to anon, authenticated
using (true);
end if;
end $$;
do $$
begin
if not exists (
select 1
from pg_policies
where schemaname = 'public'
and tablename = 'live_transactions'
and policyname = 'live_transactions_insert'
) then
create policy live_transactions_insert
on public.live_transactions
for insert
to anon, authenticated
with check (true);
end if;
end $$;
do $$
begin
if not exists (
select 1
from pg_policies
where schemaname = 'public'
and tablename = 'operation_execution_events'
and policyname = 'operation_execution_events_select'
) then
create policy operation_execution_events_select
on public.operation_execution_events
for select
to anon, authenticated
using (true);
end if;
end $$;
do $$
begin
if not exists (
select 1
from pg_policies
where schemaname = 'public'
and tablename = 'operation_execution_events'
and policyname = 'operation_execution_events_insert'
) then
create policy operation_execution_events_insert
on public.operation_execution_events
for insert
to anon, authenticated
with check (true);
end if;
end $$;
do $$
begin
if not exists (
select 1
from pg_policies
where schemaname = 'public'
and tablename = 'proof_stats'
and policyname = 'proof_stats_select'
) then
create policy proof_stats_select
on public.proof_stats
for select
to anon, authenticated
using (true);
end if;
end $$;
do $$
begin
if not exists (
select 1 from pg_policies
where schemaname = 'public'
and tablename = 'governance_receipts'
and policyname = 'governance_receipts_select'
) then
create policy governance_receipts_select
on public.governance_receipts
for select
to anon, authenticated
using (true);
end if;
end $$;
do $$
begin
if not exists (
select 1 from pg_policies
where schemaname = 'public'
and tablename = 'governance_receipts'
and policyname = 'governance_receipts_insert'
) then
create policy governance_receipts_insert
on public.governance_receipts
for insert
to anon, authenticated
with check (true);
end if;
end $$;
do $$
begin
if not exists (
select 1 from pg_policies
where schemaname = 'public'
and tablename = 'cloak_delivery_state'
and policyname = 'cloak_delivery_state_select'
) then
create policy cloak_delivery_state_select
on public.cloak_delivery_state
for select
to anon, authenticated
using (true);
end if;
end $$;
do $$
begin
if not exists (
select 1 from pg_policies
where schemaname = 'public'
and tablename = 'cloak_delivery_state'
and policyname = 'cloak_delivery_state_insert'
) then
create policy cloak_delivery_state_insert
on public.cloak_delivery_state
for insert
to anon, authenticated
with check (true);
end if;
end $$;
do $$
begin
if not exists (
select 1
from pg_policies
where schemaname = 'public'
and tablename = 'operation_receipts'
and policyname = 'operation_receipts_insert'
) then
create policy operation_receipts_insert
on public.operation_receipts
for insert
to anon, authenticated
with check (true);
end if;
end $$;
do $$
begin
if not exists (
select 1
from pg_policies
where schemaname = 'public'
and tablename = 'freshness_pings'
and policyname = 'freshness_pings_select'
) then
create policy freshness_pings_select
on public.freshness_pings
for select
to anon, authenticated
using (true);
end if;
end $$;
do $$
begin
if not exists (
select 1
from pg_policies
where schemaname = 'public'
and tablename = 'freshness_pings'
and policyname = 'freshness_pings_insert'
) then
create policy freshness_pings_insert
on public.freshness_pings
for insert
to anon, authenticated
with check (true);
end if;
end $$;
do $$
begin
if not exists (
select 1
from pg_policies
where schemaname = 'public'
and tablename = 'visitor_sessions'
and policyname = 'visitor_sessions_select'
) then
create policy visitor_sessions_select
on public.visitor_sessions
for select
to anon, authenticated
using (true);
end if;
end $$;
do $$
begin
if not exists (
select 1
from pg_policies
where schemaname = 'public'
and tablename = 'visitor_sessions'
and policyname = 'visitor_sessions_insert'
) then
create policy visitor_sessions_insert
on public.visitor_sessions
for insert
to anon, authenticated
with check (true);
end if;
end $$;
do $$
begin
if not exists (
select 1
from pg_policies
where schemaname = 'public'
and tablename = 'proof_stats'
and policyname = 'proof_stats_update'
) then
create policy proof_stats_update
on public.proof_stats
for update
to anon, authenticated
using (true)
with check (true);
end if;
end $$;
do $$
begin
if not exists (
select 1
from pg_policies
where schemaname = 'public'
and tablename = 'visitor_transactions'
and policyname = 'visitor_transactions_select'
) then
create policy visitor_transactions_select
on public.visitor_transactions
for select
to anon, authenticated
using (true);
end if;
end $$;
do $$
begin
if not exists (
select 1
from pg_policies
where schemaname = 'public'
and tablename = 'visitor_transactions'
and policyname = 'visitor_transactions_insert'
) then
create policy visitor_transactions_insert
on public.visitor_transactions
for insert
to anon, authenticated
with check (true);
end if;
end $$;
do $$
begin
if not exists (
select 1
from pg_policies
where schemaname = 'public'
and tablename = 'onboarding_requests'
and policyname = 'onboarding_requests_select'
) then
create policy onboarding_requests_select
on public.onboarding_requests
for select
to anon, authenticated
using (true);
end if;
end $$;
do $$
begin
if not exists (
select 1
from pg_policies
where schemaname = 'public'
and tablename = 'onboarding_requests'
and policyname = 'onboarding_requests_insert'
) then
create policy onboarding_requests_insert
on public.onboarding_requests
for insert
to anon, authenticated
with check (true);
end if;
end $$;
notify pgrst, 'reload schema';