forked from Vatix-Protocol/vatix-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.prisma
More file actions
229 lines (194 loc) · 7.19 KB
/
Copy pathschema.prisma
File metadata and controls
229 lines (194 loc) · 7.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
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
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init
generator client {
provider = "prisma-client-js"
output = "../src/generated/prisma/client"
previewFeatures = ["partialIndexes"]
}
datasource db {
provider = "postgresql"
}
enum MarketStatus {
ACTIVE
RESOLVED
CANCELLED
}
enum OrderSide {
BUY
SELL
}
enum OrderStatus {
OPEN
FILLED
CANCELLED
PARTIALLY_FILLED
}
enum Outcome {
YES
NO
}
enum ResolutionCandidateStatus {
PROPOSED
CHALLENGED
ACCEPTED
REJECTED
}
enum ResolutionStatus {
ACTIVE
CORRECTED
OVERRIDDEN
}
enum OracleSource {
CHAINLINK
PYTH
UMA
API3
INTERNAL
MANUAL
}
model Market {
id String @id @default(uuid())
question String
endTime DateTime @map("end_time")
resolutionTime DateTime? @map("resolution_time")
oracleAddress String @map("oracle_address") @db.VarChar(56)
status MarketStatus @default(ACTIVE)
outcome Boolean?
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
orders Order[]
positions UserPosition[]
positionSnapshots Position[]
oracleReports OracleReport[]
resolutionCandidates ResolutionCandidate[]
resolutions Resolution[]
@@index([status])
@@index([endTime])
@@index([status, endTime])
@@index([status, createdAt(sort: Desc)])
@@map("markets")
}
model Order {
id String @id @default(uuid())
marketId String @map("market_id")
userAddress String @map("user_address") @db.VarChar(56)
side OrderSide
outcome Outcome
price Decimal @db.Decimal(10, 8)
quantity Int
filledQuantity Int @default(0) @map("filled_quantity")
status OrderStatus @default(OPEN)
createdAt DateTime @default(now()) @map("created_at")
market Market @relation(fields: [marketId], references: [id], onDelete: Cascade)
@@index([marketId])
@@index([userAddress])
@@index([userAddress, marketId])
@@index([status])
@@index([marketId, outcome, price, createdAt])
@@map("orders")
}
model OracleReport {
id String @id @default(uuid())
source String @db.VarChar(256)
payloadHash String @map("payload_hash") @db.VarChar(64)
confidence Decimal @db.Decimal(5, 4)
marketId String? @map("market_id")
candidateResolution Boolean? @map("candidate_resolution")
createdAt DateTime @default(now()) @map("created_at")
market Market? @relation(fields: [marketId], references: [id], onDelete: SetNull)
@@index([marketId])
@@index([source])
@@index([createdAt])
@@map("oracle_reports")
}
model UserPosition {
id String @id @default(uuid())
marketId String @map("market_id")
userAddress String @map("user_address") @db.VarChar(56)
yesShares Int @default(0) @map("yes_shares")
noShares Int @default(0) @map("no_shares")
lockedCollateral Decimal @default(0) @map("locked_collateral") @db.Decimal(20, 8)
isSettled Boolean @default(false) @map("is_settled")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
market Market @relation(fields: [marketId], references: [id], onDelete: Cascade)
@@unique([marketId, userAddress])
@@index([marketId])
@@index([userAddress])
@@index([userAddress, marketId])
@@map("user_positions")
}
model ResolutionCandidate {
id String @id @default(uuid())
marketId String @map("market_id")
proposedOutcome Boolean @map("proposed_outcome")
source String
status ResolutionCandidateStatus @default(PROPOSED)
/// Confidence score for this resolution candidate, expressed as a decimal in the range 0.0–1.0
/// where 0.0 = no confidence and 1.0 = full confidence. Null if not reported by the source.
confidenceScore Decimal? @map("confidence_score") @db.Decimal(5, 4)
operatorAddress String @map("operator_address") @db.VarChar(56)
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
market Market @relation(fields: [marketId], references: [id], onDelete: Cascade)
@@index([marketId])
@@index([status])
@@index([marketId, status])
@@index([source])
@@map("resolution_candidates")
}
model Resolution {
id String @id @default(uuid())
marketId String @map("market_id")
outcome Boolean
finalizedAt DateTime @map("finalized_at")
provenance String
status ResolutionStatus @default(ACTIVE)
/// JSONB field tracking correction and override history
/// Example: { "corrected_at": "2026-04-28T00:00:00Z", "previous_outcome": false, "reason": "..." }
correctionOverrideMetadata Json? @map("correction_override_metadata")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
market Market @relation(fields: [marketId], references: [id], onDelete: Cascade, map: "resolutions_market_id_fkey")
@@unique([marketId], map: "resolutions_market_id_active_idx", where: { status: "ACTIVE" })
@@index([marketId])
@@index([status])
@@index([finalizedAt])
@@index([marketId, status])
@@index([createdAt(sort: Desc)])
@@map("resolutions")
}
model Position {
id String @id @default(uuid())
walletAddress String @map("wallet_address") @db.VarChar(56)
marketId String @map("market_id")
outcome Outcome?
quantity Int @default(0)
valuation Decimal @default(0) @map("valuation") @db.Decimal(20, 8)
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
market Market @relation(fields: [marketId], references: [id], onDelete: Cascade)
@@unique([walletAddress, marketId, outcome], map: "positions_wallet_market_outcome_key")
@@index([walletAddress])
@@index([marketId])
@@map("positions")
}
model IndexerCursor {
networkId String @map("network_id")
cursorKey String @map("cursor_key")
cursorValue String? @map("cursor_value")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
@@id([networkId, cursorKey])
@@index([networkId])
@@map("indexer_cursors")
}
model OracleSourceAlias {
id Int @id @default(autoincrement())
alias String @unique
canonicalSource OracleSource @map("canonical_source")
createdAt DateTime @default(now()) @map("created_at")
@@index([canonicalSource])
@@map("oracle_source_aliases")
}