-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
110 lines (98 loc) 路 3.29 KB
/
Copy pathindex.ts
File metadata and controls
110 lines (98 loc) 路 3.29 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
import { sql } from "drizzle-orm"
import {
bigint,
boolean,
integer,
jsonb,
pgTable,
text,
timestamp,
varchar,
} from "drizzle-orm/pg-core"
/**
* INDEXING METADATA
* Used for Optimistic Concurrency Control (OCC).
* Ensures that out-of-order webhooks never overwrite newer data.
*/
const indexingMetadata = {
lastBlockNumber: bigint("last_block_number", { mode: "bigint" })
.default(sql`0`)
.notNull(),
lastLogIndex: integer("last_log_index").default(0).notNull(),
}
const timestamps = {
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at")
.defaultNow()
.notNull()
.$onUpdate(() => new Date()),
}
export const memberDbSchema = pgTable("member", {
id: text("id").primaryKey(), // "chainId-address"
address: varchar("address", { length: 42 }).notNull(),
chainId: integer("chain_id").notNull(),
availableStake: bigint("available_stake", { mode: "bigint" })
.default(sql`0`)
.notNull(),
lockedStake: bigint("locked_stake", { mode: "bigint" })
.default(sql`0`)
.notNull(),
reputation: bigint("reputation", { mode: "bigint" })
.default(sql`0`)
.notNull(),
isAvailable: boolean("is_available").default(false).notNull(),
activeReviewsCount: integer("active_reviews_count").default(0).notNull(),
submittedPublicationsIds: bigint("submitted_publications_ids", {
mode: "bigint",
})
.array()
.default(sql`'{}'`),
// Actions counters
rewardsCount: integer("rewards_count").default(0).notNull(),
slashesCount: integer("slashes_count").default(0).notNull(),
...timestamps,
...indexingMetadata,
})
export const publicationDbSchema = pgTable("publication", {
id: text("id").primaryKey(), // "chainId-pubId"
pubId: bigint("pub_id", { mode: "bigint" }),
chainId: integer("chain_id"),
publisher: varchar("publisher", { length: 42 }),
cid: text("cid"),
paidSubmissionFee: bigint("paid_submission_fee", { mode: "bigint" })
.default(sql`0`)
.notNull(),
reviewersStatus: jsonb("reviewers_status")
.$type<Record<string, boolean>>()
.default({})
.notNull(),
reviewers: text("reviewers").array().default(sql`'{}'`),
seniorReviewer: varchar("senior_reviewer", { length: 42 }),
lockedStake: bigint("locked_stake", { mode: "bigint" })
.default(sql`0`)
.notNull(),
verdictCid: text("verdict_cid"),
status: integer("status").default(0).notNull(),
...timestamps,
...indexingMetadata,
})
export const protocolDbSchema = pgTable("protocol", {
id: text("id").primaryKey(), // "chainId"
chainId: integer("chain_id").notNull(),
// Dynamic Pools (Updated by Webhooks)
rewardPool: bigint("reward_pool", { mode: "bigint" })
.default(sql`0`)
.notNull(),
slashPool: bigint("slash_pool", { mode: "bigint" }).default(sql`0`).notNull(),
// Protocol Constants (Populated by Seed Script)
aiAgent: varchar("ai_agent", { length: 42 }).notNull(),
treasury: varchar("treasury", { length: 42 }).notNull(),
vrfNumWords: integer("vrf_num_words").notNull(),
reputationBoost: bigint("reputation_boost", { mode: "bigint" }).notNull(),
publisherMinFee: bigint("publisher_min_fee", { mode: "bigint" }).notNull(),
publisherStake: bigint("publisher_stake", { mode: "bigint" }).notNull(),
reviewerStake: bigint("reviewer_stake", { mode: "bigint" }).notNull(),
reviewerReward: bigint("reviewer_reward", { mode: "bigint" }).notNull(),
...timestamps,
...indexingMetadata,
})