forked from Astrea-Payouts/astrea
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.prisma
More file actions
202 lines (172 loc) · 5.95 KB
/
Copy pathschema.prisma
File metadata and controls
202 lines (172 loc) · 5.95 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
// Astrea data model — mirrors on-chain escrow state for UX/querying.
// The chain is the source of truth (see docs/architecture.md, Principle 2);
// this schema is a mirror kept honest by a reconciliation job (E04).
generator client {
provider = "prisma-client"
output = "../src/generated/prisma"
}
datasource db {
provider = "postgresql"
}
enum StellarNetwork {
TESTNET
MAINNET
}
/// Event lifecycle — see docs/product-flows.md "Event state machine".
enum EventStatus {
DRAFT
CREATED
FUNDED
LIVE
JUDGING
COMPLETED
CANCELLED
}
/// Prize (milestone) lifecycle — see docs/product-flows.md "Prize (milestone) states".
/// RELEASED means funds landed in the judge's wallet; PAID_OUT means the
/// judge's forward payment to the winner is confirmed on-chain (ADR-007).
enum PrizeStatus {
PENDING
ASSIGNED
APPROVED
RELEASED
PAID_OUT
DISPUTED
}
enum JudgeStatus {
ACTIVE
REMOVED
}
/// Idempotency + outbox for every escrow-mutating operation (docs/architecture.md, Principle 4).
enum OpStatus {
PENDING
SUCCEEDED
FAILED
}
/// A person on the platform. Not yet tied to a specific auth mechanism —
/// wallet-based auth is designed in S05; kept minimal and independent until then.
model User {
id String @id @default(uuid())
createdAt DateTime @default(now())
wallets Wallet[]
organizedEvents Event[] @relation("EventOrganizer")
@@map("users")
}
/// A Stellar address associated with a user. Judges are stored as raw addresses
/// on Judge.walletAddress instead (they may be a multisig the platform has no
/// Wallet row for — see docs/architecture.md ADR-003, multi-judge note).
model Wallet {
id String @id @default(uuid())
userId String
address String @unique
usdcTrustlineVerifiedAt DateTime?
createdAt DateTime @default(now())
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
organizedEvents Event[] @relation("EventOrganizerWallet")
wonPrizes Prize[] @relation("PrizeWinner")
submissions Submission[]
@@index([userId])
@@map("wallets")
}
model Event {
id String @id @default(uuid())
organizerId String
organizerWalletId String
name String
description String?
startsAt DateTime?
endsAt DateTime?
status EventStatus @default(DRAFT)
network StellarNetwork @default(TESTNET)
escrowContractId String? @unique
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
organizer User @relation("EventOrganizer", fields: [organizerId], references: [id])
organizerWallet Wallet @relation("EventOrganizerWallet", fields: [organizerWalletId], references: [id])
prizes Prize[]
judges Judge[]
submissions Submission[]
@@index([organizerId])
@@index([organizerWalletId])
@@index([status])
@@map("events")
}
model Prize {
id String @id @default(uuid())
eventId String
rank Int
amountUsdc Decimal @db.Decimal(18, 7)
milestoneIndex Int
status PrizeStatus @default(PENDING)
winnerWalletId String?
releaseTxHash String?
releasedAt DateTime?
/// ADR-007: the judge's forward-to-winner payment — a plain Stellar tx,
/// not a Trustless Work call. Set together with paidOutAt.
forwardTxHash String?
paidOutAt DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
event Event @relation(fields: [eventId], references: [id], onDelete: Cascade)
winnerWallet Wallet? @relation("PrizeWinner", fields: [winnerWalletId], references: [id])
payouts Payout[]
@@unique([eventId, milestoneIndex])
@@index([eventId])
@@index([winnerWalletId])
@@index([status])
@@map("prizes")
}
/// Judges hold the on-chain `approver` + `releaseSigner` role (ADR-003).
/// walletAddress is a raw Stellar address, not a Wallet FK — it may be a
/// multisig account the platform has no user/Wallet row for.
model Judge {
id String @id @default(uuid())
eventId String
walletAddress String
displayName String
status JudgeStatus @default(ACTIVE)
createdAt DateTime @default(now())
event Event @relation(fields: [eventId], references: [id], onDelete: Cascade)
@@unique([eventId, walletAddress])
@@index([eventId])
@@map("judges")
}
model Submission {
id String @id @default(uuid())
eventId String
participantWalletId String
url String
submittedAt DateTime @default(now())
event Event @relation(fields: [eventId], references: [id], onDelete: Cascade)
participantWallet Wallet @relation(fields: [participantWalletId], references: [id])
@@index([eventId])
@@index([participantWalletId])
@@map("submissions")
}
/// Append-only audit log. amountUsdc here is the NET amount actually
/// transferred (post protocol + platform fee — see ADR-005), distinct from
/// Prize.amountUsdc which is the gross configured amount.
model Payout {
id String @id @default(uuid())
prizeId String
txHash String @unique
amountUsdc Decimal @db.Decimal(18, 7)
confirmedAt DateTime @default(now())
prize Prize @relation(fields: [prizeId], references: [id], onDelete: Cascade)
@@index([prizeId])
@@map("payouts")
}
/// Idempotency key + outbox record for every escrow-mutating call to
/// Trustless Work. Read by the reconciliation job (E04) to heal drift
/// between confirmed on-chain transactions and mirror table state.
model OpLog {
id String @id @default(uuid())
idempotencyKey String @unique
operation String
payload Json
status OpStatus @default(PENDING)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@index([status])
@@map("op_log")
}