@morpho-dev/router 0.1.18 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -18
- package/dist/cli.js +3020 -2174
- package/dist/cli.js.map +1 -1
- package/dist/drizzle/VERSION.ts +3 -0
- package/dist/drizzle/drizzle.config.ts +18 -0
- package/dist/drizzle/index.ts +2 -0
- package/dist/drizzle/{router_v1.4/0000_add_obligation_id.sql → router_v1.5/0000_add_block_number_to_liquidity_graph_and_offer_liquidity_pools_relation.sql} +49 -39
- package/dist/drizzle/router_v1.5/0001_create_new_relations_to_prepare_new_liquidity_model.sql +55 -0
- package/dist/drizzle/router_v1.5/0002_add_new_offer_status_relation.sql +9 -0
- package/dist/drizzle/router_v1.5/0003_insert-status-code.sql +1 -0
- package/dist/drizzle/router_v1.5/0004_add_index_for_fast_book_lookup.sql +3 -0
- package/dist/drizzle/router_v1.5/0005_add_group_consumed_events_table.sql +12 -0
- package/dist/drizzle/router_v1.5/0006_add-trigger-for-consumed-events.sql +58 -0
- package/dist/drizzle/router_v1.5/0007_update_index_for_fast_book_lookup.sql +5 -0
- package/dist/drizzle/router_v1.5/0008_rename_consumed_events_table.sql +8 -0
- package/dist/drizzle/{router_v1.4 → router_v1.5}/meta/0000_snapshot.json +83 -27
- package/dist/drizzle/{router_v1.4 → router_v1.5}/meta/0001_snapshot.json +459 -27
- package/dist/drizzle/router_v1.5/meta/0002_snapshot.json +1463 -0
- package/dist/drizzle/router_v1.5/meta/0003_snapshot.json +1463 -0
- package/dist/drizzle/router_v1.5/meta/0004_snapshot.json +1569 -0
- package/dist/drizzle/router_v1.5/meta/0005_snapshot.json +1664 -0
- package/dist/drizzle/router_v1.5/meta/0006_snapshot.json +1664 -0
- package/dist/drizzle/router_v1.5/meta/0007_snapshot.json +1752 -0
- package/dist/drizzle/router_v1.5/meta/0008_snapshot.json +1752 -0
- package/dist/drizzle/router_v1.5/meta/_journal.json +69 -0
- package/dist/drizzle/schema.ts +363 -0
- package/dist/index.browser.d.cts +884 -156
- package/dist/index.browser.d.ts +884 -156
- package/dist/index.browser.js +1433 -1010
- package/dist/index.browser.js.map +1 -1
- package/dist/index.browser.mjs +1426 -1009
- package/dist/index.browser.mjs.map +1 -1
- package/dist/index.node.d.cts +2578 -930
- package/dist/index.node.d.ts +2578 -930
- package/dist/index.node.js +6544 -5459
- package/dist/index.node.js.map +1 -1
- package/dist/index.node.mjs +6769 -5688
- package/dist/index.node.mjs.map +1 -1
- package/package.json +17 -13
- package/dist/drizzle/router_v1.4/0001_update-primary-key-on-link.sql +0 -3
- package/dist/drizzle/router_v1.4/meta/_journal.json +0 -20
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "7",
|
|
3
|
+
"dialect": "postgresql",
|
|
4
|
+
"entries": [
|
|
5
|
+
{
|
|
6
|
+
"idx": 0,
|
|
7
|
+
"version": "7",
|
|
8
|
+
"when": 1761644272102,
|
|
9
|
+
"tag": "0000_add_block_number_to_liquidity_graph_and_offer_liquidity_pools_relation",
|
|
10
|
+
"breakpoints": true
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"idx": 1,
|
|
14
|
+
"version": "7",
|
|
15
|
+
"when": 1761923553610,
|
|
16
|
+
"tag": "0001_create_new_relations_to_prepare_new_liquidity_model",
|
|
17
|
+
"breakpoints": true
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"idx": 2,
|
|
21
|
+
"version": "7",
|
|
22
|
+
"when": 1762158833454,
|
|
23
|
+
"tag": "0002_add_new_offer_status_relation",
|
|
24
|
+
"breakpoints": true
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"idx": 3,
|
|
28
|
+
"version": "7",
|
|
29
|
+
"when": 1762158884867,
|
|
30
|
+
"tag": "0003_insert-status-code",
|
|
31
|
+
"breakpoints": true
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"idx": 4,
|
|
35
|
+
"version": "7",
|
|
36
|
+
"when": 1762167904594,
|
|
37
|
+
"tag": "0004_add_index_for_fast_book_lookup",
|
|
38
|
+
"breakpoints": true
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"idx": 5,
|
|
42
|
+
"version": "7",
|
|
43
|
+
"when": 1762169514894,
|
|
44
|
+
"tag": "0005_add_group_consumed_events_table",
|
|
45
|
+
"breakpoints": true
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"idx": 6,
|
|
49
|
+
"version": "7",
|
|
50
|
+
"when": 1762169538754,
|
|
51
|
+
"tag": "0006_add-trigger-for-consumed-events",
|
|
52
|
+
"breakpoints": true
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"idx": 7,
|
|
56
|
+
"version": "7",
|
|
57
|
+
"when": 1762338625117,
|
|
58
|
+
"tag": "0007_update_index_for_fast_book_lookup",
|
|
59
|
+
"breakpoints": true
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"idx": 8,
|
|
63
|
+
"version": "7",
|
|
64
|
+
"when": 1762340262991,
|
|
65
|
+
"tag": "0008_rename_consumed_events_table",
|
|
66
|
+
"breakpoints": true
|
|
67
|
+
}
|
|
68
|
+
]
|
|
69
|
+
}
|
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
import { asc, desc } from "drizzle-orm";
|
|
2
|
+
import {
|
|
3
|
+
bigint,
|
|
4
|
+
boolean,
|
|
5
|
+
foreignKey,
|
|
6
|
+
index,
|
|
7
|
+
integer,
|
|
8
|
+
numeric,
|
|
9
|
+
pgSchema,
|
|
10
|
+
primaryKey,
|
|
11
|
+
serial,
|
|
12
|
+
text,
|
|
13
|
+
timestamp,
|
|
14
|
+
uniqueIndex,
|
|
15
|
+
varchar,
|
|
16
|
+
} from "drizzle-orm/pg-core";
|
|
17
|
+
import type * as Collector from "#collectors/index.ts";
|
|
18
|
+
import { Offer } from "#core/index.ts";
|
|
19
|
+
import { VERSION } from "./VERSION.ts";
|
|
20
|
+
|
|
21
|
+
const s = pgSchema(VERSION);
|
|
22
|
+
|
|
23
|
+
export const obligations = s.table("obligations", {
|
|
24
|
+
obligationId: varchar("obligation_id", { length: 66 }).primaryKey(),
|
|
25
|
+
chainId: bigint("chain_id", { mode: "bigint" }).notNull(),
|
|
26
|
+
loanToken: varchar("loan_token", { length: 42 }).notNull(),
|
|
27
|
+
maturity: integer("maturity").notNull(),
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
export const groups = s.table(
|
|
31
|
+
"groups",
|
|
32
|
+
{
|
|
33
|
+
chainId: bigint("chain_id", { mode: "bigint" }).notNull(),
|
|
34
|
+
maker: varchar("maker", { length: 42 }).notNull(),
|
|
35
|
+
group: varchar("group", { length: 66 }).notNull(),
|
|
36
|
+
consumed: numeric("consumed", { precision: 78, scale: 0 }).notNull(),
|
|
37
|
+
blockNumber: bigint("block_number", { mode: "number" }).notNull(),
|
|
38
|
+
updatedAt: timestamp("updated_at").defaultNow().notNull(),
|
|
39
|
+
},
|
|
40
|
+
(table) => [
|
|
41
|
+
primaryKey({ columns: [table.chainId, table.maker, table.group], name: "groups_pk" }),
|
|
42
|
+
index("groups_chain_id_maker_group_consumed_idx").on(
|
|
43
|
+
table.chainId,
|
|
44
|
+
table.maker,
|
|
45
|
+
table.group,
|
|
46
|
+
table.consumed,
|
|
47
|
+
),
|
|
48
|
+
],
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
export const consumedEvents = s.table(
|
|
52
|
+
"consumed_events",
|
|
53
|
+
{
|
|
54
|
+
eventId: varchar("event_id", { length: 128 }).primaryKey(),
|
|
55
|
+
chainId: bigint("chain_id", { mode: "bigint" }).notNull(),
|
|
56
|
+
maker: varchar("maker", { length: 42 }).notNull(),
|
|
57
|
+
group: varchar("group", { length: 66 }).notNull(),
|
|
58
|
+
amount: numeric("amount", { precision: 78, scale: 0 }).notNull(),
|
|
59
|
+
blockNumber: bigint("block_number", { mode: "number" }).notNull(),
|
|
60
|
+
createdAt: timestamp("created_at").defaultNow().notNull(),
|
|
61
|
+
},
|
|
62
|
+
(t) => [
|
|
63
|
+
foreignKey({
|
|
64
|
+
columns: [t.chainId, t.maker, t.group],
|
|
65
|
+
foreignColumns: [groups.chainId, groups.maker, groups.group],
|
|
66
|
+
name: "consumed_events_groups_fk",
|
|
67
|
+
}).onDelete("cascade"),
|
|
68
|
+
index("consumed_events_group_idx").on(t.chainId, t.maker, t.group),
|
|
69
|
+
index("consumed_events_block_number_idx").on(t.blockNumber),
|
|
70
|
+
],
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
export const obligationCollateralsV2 = s.table(
|
|
74
|
+
"obligation_collaterals_v2",
|
|
75
|
+
{
|
|
76
|
+
obligationId: varchar("obligation_id", { length: 66 })
|
|
77
|
+
.notNull()
|
|
78
|
+
.references(() => obligations.obligationId, { onDelete: "cascade" }),
|
|
79
|
+
asset: varchar("asset", { length: 42 }).notNull(),
|
|
80
|
+
oracleChainId: bigint("oracle_chain_id", { mode: "bigint" }).notNull(),
|
|
81
|
+
oracleAddress: varchar("oracle_address", { length: 42 }).notNull(),
|
|
82
|
+
lltv: bigint("lltv", { mode: "bigint" }).notNull(),
|
|
83
|
+
blockNumber: bigint("block_number", { mode: "number" }).notNull(),
|
|
84
|
+
updatedAt: timestamp("updated_at").defaultNow().notNull(),
|
|
85
|
+
},
|
|
86
|
+
(table) => [
|
|
87
|
+
primaryKey({
|
|
88
|
+
columns: [table.obligationId, table.asset],
|
|
89
|
+
name: "obligation_collaterals_v2_pk",
|
|
90
|
+
}),
|
|
91
|
+
foreignKey({
|
|
92
|
+
columns: [table.oracleChainId, table.oracleAddress],
|
|
93
|
+
foreignColumns: [oracles.chainId, oracles.address],
|
|
94
|
+
name: "obligation_collaterals_v2_oracles_fk",
|
|
95
|
+
}),
|
|
96
|
+
index("obligation_collaterals_v2_obligation_id_idx").on(table.obligationId),
|
|
97
|
+
index("obligation_collaterals_v2_oracle_fk_idx").on(table.oracleChainId, table.oracleAddress),
|
|
98
|
+
],
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
export const oracles = s.table(
|
|
102
|
+
"oracles",
|
|
103
|
+
{
|
|
104
|
+
chainId: bigint("chain_id", { mode: "bigint" }).notNull(),
|
|
105
|
+
address: varchar("address", { length: 42 }).notNull(),
|
|
106
|
+
blockNumber: bigint("block_number", { mode: "number" }).notNull(),
|
|
107
|
+
updatedAt: timestamp("updated_at").defaultNow().notNull(),
|
|
108
|
+
},
|
|
109
|
+
(table) => [primaryKey({ columns: [table.chainId, table.address], name: "oracles_pk" })],
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
export const statusCode = s.enum<Offer.StatusCode, [Offer.StatusCode, ...Offer.StatusCode[]]>(
|
|
113
|
+
"status_code",
|
|
114
|
+
Object.values(Offer.StatusCode) as [Offer.StatusCode, ...Offer.StatusCode[]],
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
export const status = s.table("status", {
|
|
118
|
+
id: serial("id").primaryKey(),
|
|
119
|
+
code: statusCode("code").unique(),
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
export const offersV2 = s.table(
|
|
123
|
+
"offers_v2",
|
|
124
|
+
{
|
|
125
|
+
hash: varchar("hash", { length: 66 }).primaryKey(),
|
|
126
|
+
obligationId: varchar("obligation_id", { length: 66 })
|
|
127
|
+
.notNull()
|
|
128
|
+
.references(() => obligations.obligationId, { onDelete: "cascade" }),
|
|
129
|
+
assets: numeric("assets", { precision: 78, scale: 0 }).notNull(),
|
|
130
|
+
rate: numeric("rate", { precision: 78, scale: 0 }).notNull(),
|
|
131
|
+
maturity: integer("maturity").notNull(),
|
|
132
|
+
expiry: integer("expiry").notNull(),
|
|
133
|
+
start: integer("start").notNull(),
|
|
134
|
+
groupChainId: bigint("group_chain_id", { mode: "bigint" }).notNull(),
|
|
135
|
+
groupMaker: varchar("group_maker", { length: 42 }).notNull(),
|
|
136
|
+
group: varchar("group_group", { length: 66 }).notNull(),
|
|
137
|
+
nonce: varchar("nonce", { length: 66 }).notNull(),
|
|
138
|
+
buy: boolean("buy").notNull(),
|
|
139
|
+
callbackAddress: varchar("callback_address", { length: 42 }).notNull(),
|
|
140
|
+
callbackData: text("callback_data").notNull(),
|
|
141
|
+
blockNumber: bigint("block_number", { mode: "number" }).notNull(),
|
|
142
|
+
updatedAt: timestamp("updated_at").defaultNow().notNull(),
|
|
143
|
+
},
|
|
144
|
+
(table) => [
|
|
145
|
+
foreignKey({
|
|
146
|
+
columns: [table.groupChainId, table.groupMaker, table.group],
|
|
147
|
+
foreignColumns: [groups.chainId, groups.maker, groups.group],
|
|
148
|
+
name: "offers_v2_groups_fk",
|
|
149
|
+
}).onDelete("cascade"),
|
|
150
|
+
|
|
151
|
+
index("offers_v2_group_fk_idx").on(table.groupChainId, table.groupMaker, table.group),
|
|
152
|
+
|
|
153
|
+
// most important indexes allowing fast lookup of best offers per group
|
|
154
|
+
// order should be respected in ORDER BY clauses to avoid full table scans
|
|
155
|
+
index("offers_v2_group_winner_sell_side_idx").on(
|
|
156
|
+
table.groupChainId,
|
|
157
|
+
table.groupMaker,
|
|
158
|
+
table.group,
|
|
159
|
+
desc(table.rate),
|
|
160
|
+
asc(table.blockNumber),
|
|
161
|
+
desc(table.assets),
|
|
162
|
+
asc(table.hash),
|
|
163
|
+
),
|
|
164
|
+
|
|
165
|
+
index("offers_v2_group_winner_buy_side_idx").on(
|
|
166
|
+
table.groupChainId,
|
|
167
|
+
table.groupMaker,
|
|
168
|
+
table.group,
|
|
169
|
+
asc(table.rate),
|
|
170
|
+
asc(table.blockNumber),
|
|
171
|
+
desc(table.assets),
|
|
172
|
+
asc(table.hash),
|
|
173
|
+
),
|
|
174
|
+
|
|
175
|
+
index("offers_v2_obligation_id_side_idx").on(table.obligationId, table.buy),
|
|
176
|
+
],
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
export const offerStatus = s.table(
|
|
180
|
+
"offer_status",
|
|
181
|
+
{
|
|
182
|
+
offerHash: varchar("offer_hash", { length: 66 })
|
|
183
|
+
.primaryKey()
|
|
184
|
+
.references(() => offersV2.hash, { onDelete: "cascade" }),
|
|
185
|
+
statusId: serial("status_id")
|
|
186
|
+
.notNull()
|
|
187
|
+
.references(() => status.id, { onDelete: "cascade" }),
|
|
188
|
+
blockNumber: bigint("block_number", { mode: "number" }).notNull(),
|
|
189
|
+
updatedAt: timestamp("updated_at").defaultNow().notNull(),
|
|
190
|
+
},
|
|
191
|
+
(table) => [index("offer_status_status_hash_idx").on(table.statusId, table.offerHash)],
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
export const collectors = s.table(
|
|
195
|
+
"collectors",
|
|
196
|
+
{
|
|
197
|
+
chainId: bigint("chain_id", { mode: "bigint" }).notNull(),
|
|
198
|
+
name: text("name").$type<Collector.Name>().notNull(),
|
|
199
|
+
blockNumber: bigint("block_number", { mode: "number" }).notNull(),
|
|
200
|
+
// epoch is used as a fencing token to avoid race conditions when updating the block number
|
|
201
|
+
epoch: numeric("epoch", { precision: 78, scale: 0 }).default("0").notNull(),
|
|
202
|
+
updatedAt: timestamp("updated_at").defaultNow().notNull(),
|
|
203
|
+
},
|
|
204
|
+
(table) => [
|
|
205
|
+
uniqueIndex("collectors_chain_name_epoch_idx").on(table.chainId, table.name, table.epoch),
|
|
206
|
+
],
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
export const chains = s.table(
|
|
210
|
+
"chains",
|
|
211
|
+
{
|
|
212
|
+
chainId: bigint("chain_id", { mode: "bigint" }).notNull(),
|
|
213
|
+
blockNumber: bigint("block_number", { mode: "number" }).notNull(),
|
|
214
|
+
epoch: numeric("epoch", { precision: 78, scale: 0 }).default("0").notNull(),
|
|
215
|
+
updatedAt: timestamp("updated_at").defaultNow().notNull(),
|
|
216
|
+
},
|
|
217
|
+
(table) => [uniqueIndex("chains_id_epoch_idx").on(table.chainId, table.epoch)],
|
|
218
|
+
);
|
|
219
|
+
|
|
220
|
+
// DEPRECATED
|
|
221
|
+
|
|
222
|
+
export const offers = s.table(
|
|
223
|
+
"offers",
|
|
224
|
+
{
|
|
225
|
+
hash: varchar("hash", { length: 66 }).primaryKey(),
|
|
226
|
+
obligationId: varchar("obligation_id", { length: 66 })
|
|
227
|
+
.notNull()
|
|
228
|
+
.references(() => obligations.obligationId, { onDelete: "cascade" }),
|
|
229
|
+
offering: varchar("offering", { length: 42 }).notNull(),
|
|
230
|
+
assets: numeric("assets", { precision: 78, scale: 0 }).notNull(),
|
|
231
|
+
rate: bigint("rate", { mode: "bigint" }).notNull(),
|
|
232
|
+
maturity: integer("maturity").notNull(),
|
|
233
|
+
expiry: integer("expiry").notNull(),
|
|
234
|
+
start: integer("start").notNull(),
|
|
235
|
+
nonce: bigint("nonce", { mode: "bigint" }).notNull(),
|
|
236
|
+
buy: boolean("buy").notNull(),
|
|
237
|
+
chainId: bigint("chain_id", { mode: "bigint" }).notNull(),
|
|
238
|
+
loanToken: varchar("loan_token", { length: 42 }).notNull(),
|
|
239
|
+
callbackAddress: varchar("callback_address", { length: 42 }).notNull(),
|
|
240
|
+
callbackData: text("callback_data").notNull(),
|
|
241
|
+
callbackGasLimit: bigint("callback_gas_limit", { mode: "bigint" }).notNull(),
|
|
242
|
+
signature: varchar("signature", { length: 132 }),
|
|
243
|
+
createdAt: timestamp("created_at").defaultNow().notNull(),
|
|
244
|
+
blockNumber: bigint("block_number", { mode: "number" }).notNull(),
|
|
245
|
+
},
|
|
246
|
+
(table) => [
|
|
247
|
+
index("offers_obligation_id_idx").on(table.obligationId),
|
|
248
|
+
index("offers_offering_idx").on(table.offering),
|
|
249
|
+
index("offers_buy_idx").on(table.buy),
|
|
250
|
+
index("offers_chain_id_idx").on(table.chainId),
|
|
251
|
+
index("offers_loan_token_idx").on(table.loanToken),
|
|
252
|
+
index("offers_maturity_idx").on(table.maturity),
|
|
253
|
+
index("offers_expiry_idx").on(table.expiry),
|
|
254
|
+
index("offers_rate_idx").on(table.rate),
|
|
255
|
+
index("offers_assets_idx").on(table.assets),
|
|
256
|
+
index("offers_created_at_idx").on(table.createdAt),
|
|
257
|
+
index("offers_block_number_idx").on(table.blockNumber),
|
|
258
|
+
// Compound indices for cursor pagination with hash
|
|
259
|
+
index("offers_rate_hash_idx").on(table.rate, table.hash),
|
|
260
|
+
index("offers_maturity_hash_idx").on(table.maturity, table.hash),
|
|
261
|
+
index("offers_expiry_hash_idx").on(table.expiry, table.hash),
|
|
262
|
+
index("offers_assets_hash_idx").on(table.assets, table.hash),
|
|
263
|
+
// Compound index for multi-level sorting optimization (rate, createdAt, assets, hash)
|
|
264
|
+
index("offers_rate_created_at_assets_hash_idx").on(
|
|
265
|
+
table.rate,
|
|
266
|
+
asc(table.createdAt),
|
|
267
|
+
desc(table.assets),
|
|
268
|
+
asc(table.hash),
|
|
269
|
+
),
|
|
270
|
+
],
|
|
271
|
+
);
|
|
272
|
+
|
|
273
|
+
export const obligationCollaterals = s.table(
|
|
274
|
+
"obligation_collaterals",
|
|
275
|
+
{
|
|
276
|
+
obligationId: varchar("obligation_id", { length: 66 })
|
|
277
|
+
.notNull()
|
|
278
|
+
.references(() => obligations.obligationId, { onDelete: "cascade" }),
|
|
279
|
+
asset: varchar("asset", { length: 42 }).notNull(),
|
|
280
|
+
oracle: varchar("oracle", { length: 42 }).notNull(),
|
|
281
|
+
lltv: bigint("lltv", { mode: "bigint" }).notNull(),
|
|
282
|
+
},
|
|
283
|
+
(table) => [
|
|
284
|
+
primaryKey({
|
|
285
|
+
columns: [table.obligationId, table.asset],
|
|
286
|
+
name: "obligation_collaterals_pk",
|
|
287
|
+
}),
|
|
288
|
+
index("obligation_collaterals_obligation_id_idx").on(table.obligationId),
|
|
289
|
+
],
|
|
290
|
+
);
|
|
291
|
+
|
|
292
|
+
export const consumed = s.table(
|
|
293
|
+
"consumed_per_user_and_nonce",
|
|
294
|
+
{
|
|
295
|
+
id: varchar("id", { length: 255 }).primaryKey(),
|
|
296
|
+
chainId: bigint("chain_id", { mode: "bigint" }).notNull(),
|
|
297
|
+
offering: varchar("offering", { length: 42 }).notNull(),
|
|
298
|
+
nonce: bigint("nonce", { mode: "bigint" }).notNull(),
|
|
299
|
+
consumed: numeric("consumed", { precision: 78, scale: 0 }).notNull(),
|
|
300
|
+
blockNumber: bigint("block_number", { mode: "number" }).notNull(),
|
|
301
|
+
createdAt: timestamp("created_at").defaultNow().notNull(),
|
|
302
|
+
},
|
|
303
|
+
(table) => [
|
|
304
|
+
index("consumed_per_user_and_nonce_chain_id_offering_nonce_block_number_idx").on(
|
|
305
|
+
table.chainId,
|
|
306
|
+
table.offering,
|
|
307
|
+
table.nonce,
|
|
308
|
+
desc(table.blockNumber),
|
|
309
|
+
),
|
|
310
|
+
],
|
|
311
|
+
);
|
|
312
|
+
|
|
313
|
+
export const offerLiquidityPools = s.table(
|
|
314
|
+
"offer_liquidity_pools",
|
|
315
|
+
{
|
|
316
|
+
offerHash: varchar("offer_hash", { length: 66 })
|
|
317
|
+
.notNull()
|
|
318
|
+
.references(() => offers.hash, { onDelete: "cascade" }),
|
|
319
|
+
poolId: varchar("pool_id", { length: 255 })
|
|
320
|
+
.notNull()
|
|
321
|
+
.references(() => liquidityPools.id, { onDelete: "cascade" }),
|
|
322
|
+
amount: numeric("amount", { precision: 78, scale: 0 }).notNull(),
|
|
323
|
+
blockNumber: bigint("block_number", { mode: "number" }).notNull(),
|
|
324
|
+
updatedAt: timestamp("updated_at").defaultNow().notNull(),
|
|
325
|
+
},
|
|
326
|
+
(table) => [
|
|
327
|
+
primaryKey({
|
|
328
|
+
columns: [table.offerHash, table.poolId],
|
|
329
|
+
name: "offer_liquidity_pools_pk",
|
|
330
|
+
}),
|
|
331
|
+
index("offer_liquidity_pools_pool_id_idx").on(table.poolId),
|
|
332
|
+
],
|
|
333
|
+
);
|
|
334
|
+
|
|
335
|
+
export const liquidityPools = s.table("liquidity_pools", {
|
|
336
|
+
id: varchar("id", { length: 255 }).primaryKey(),
|
|
337
|
+
amount: numeric("amount", { precision: 78, scale: 0 }).notNull(),
|
|
338
|
+
blockNumber: bigint("block_number", { mode: "number" }).notNull(),
|
|
339
|
+
updatedAt: timestamp("updated_at").defaultNow().notNull(),
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
export const liquidityLinks = s.table(
|
|
343
|
+
"liquidity_links",
|
|
344
|
+
{
|
|
345
|
+
parentPoolId: varchar("parent_pool_id", { length: 255 })
|
|
346
|
+
.notNull()
|
|
347
|
+
.references(() => liquidityPools.id, { onDelete: "cascade" }),
|
|
348
|
+
childPoolId: varchar("child_pool_id", { length: 255 })
|
|
349
|
+
.notNull()
|
|
350
|
+
.references(() => liquidityPools.id, { onDelete: "cascade" }),
|
|
351
|
+
priority: integer("priority").notNull(),
|
|
352
|
+
blockNumber: bigint("block_number", { mode: "number" }).notNull(),
|
|
353
|
+
updatedAt: timestamp("updated_at").defaultNow().notNull(),
|
|
354
|
+
},
|
|
355
|
+
(table) => [
|
|
356
|
+
primaryKey({
|
|
357
|
+
columns: [table.parentPoolId, table.priority],
|
|
358
|
+
name: "liquidity_links_pk",
|
|
359
|
+
}),
|
|
360
|
+
index("liquidity_links_parent_pool_id_idx").on(table.parentPoolId),
|
|
361
|
+
index("liquidity_links_child_pool_id_idx").on(table.childPoolId),
|
|
362
|
+
],
|
|
363
|
+
);
|