@morpho-dev/router 0.10.0 → 0.12.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 +20 -5
- package/dist/cli.js +14944 -8994
- package/dist/drizzle/migrations/0031_sell-takeable-reindex.sql +254 -0
- package/dist/drizzle/migrations/0032_callback-type.sql +3 -0
- package/dist/drizzle/migrations/0033_obligation-id-bytes20.sql +255 -0
- package/dist/drizzle/migrations/0034_chain-checkpoints.sql +1 -0
- package/dist/drizzle/migrations/0035_chain-tip-hash-cas.sql +1 -0
- package/dist/drizzle/migrations/0036_pending-links.sql +22 -0
- package/dist/drizzle/migrations/0037_chain-finalized-anchor.sql +2 -0
- package/dist/drizzle/migrations/0038_add-obligation-rcf-threshold.sql +2 -0
- package/dist/drizzle/migrations/0039_add-offers-composite-indexes.sql +2 -0
- package/dist/drizzle/migrations/0040_drop-redundant-offers-indexes.sql +2 -0
- package/dist/drizzle/migrations/0041_add-group-winner-expression-index.sql +10 -0
- package/dist/drizzle/migrations/0042_contract-sync-v1.14.sql +284 -0
- package/dist/drizzle/migrations/0043_add-obligation-side-tick-index.sql +1 -0
- package/dist/drizzle/migrations/0044_index-audit-cleanup.sql +27 -0
- package/dist/drizzle/migrations/0045_add-lots-offsets-availability-indexes.sql +5 -0
- package/dist/drizzle/migrations/0046_add-offers-active-tick-index.sql +1 -0
- package/dist/drizzle/migrations/0047_add-offers-book-winners-index.sql +1 -0
- package/dist/drizzle/migrations/0048_covering-indexes-for-winners-queries.sql +34 -0
- package/dist/drizzle/migrations/0049_contract-sync-v1.15.sql +305 -0
- package/dist/drizzle/migrations/meta/0031_snapshot.json +1652 -0
- package/dist/drizzle/migrations/meta/0033_snapshot.json +1658 -0
- package/dist/drizzle/migrations/meta/0036_snapshot.json +1864 -0
- package/dist/drizzle/migrations/meta/0037_snapshot.json +1876 -0
- package/dist/drizzle/migrations/meta/0038_snapshot.json +1882 -0
- package/dist/drizzle/migrations/meta/0039_snapshot.json +1960 -0
- package/dist/drizzle/migrations/meta/0040_snapshot.json +1912 -0
- package/dist/drizzle/migrations/meta/0041_snapshot.json +1912 -0
- package/dist/drizzle/migrations/meta/0042_snapshot.json +1882 -0
- package/dist/drizzle/migrations/meta/0043_snapshot.json +1909 -0
- package/dist/drizzle/migrations/meta/0044_snapshot.json +1853 -0
- package/dist/drizzle/migrations/meta/0045_snapshot.json +1921 -0
- package/dist/drizzle/migrations/meta/0046_snapshot.json +1966 -0
- package/dist/drizzle/migrations/meta/0047_snapshot.json +2005 -0
- package/dist/drizzle/migrations/meta/0048_snapshot.json +2035 -0
- package/dist/drizzle/migrations/meta/0049_snapshot.json +2035 -0
- package/dist/drizzle/migrations/meta/_journal.json +133 -0
- package/dist/evm/bytecode/morpho.txt +1 -1
- package/dist/index.browser.d.mts +784 -282
- package/dist/index.browser.d.mts.map +1 -1
- package/dist/index.browser.mjs +1516 -675
- package/dist/index.browser.mjs.map +1 -1
- package/dist/index.node.d.mts +1676 -602
- package/dist/index.node.d.mts.map +1 -1
- package/dist/index.node.mjs +10121 -5251
- package/dist/index.node.mjs.map +1 -1
- package/dist/register-otel-hook.js +7 -0
- package/dist/server-D4xxddev.js +9573 -0
- package/dist/server.js +9617 -0
- package/docs/integrator.md +14 -24
- package/package.json +36 -29
- package/dist/index.browser.d.ts +0 -5007
- package/dist/index.browser.d.ts.map +0 -1
- package/dist/index.browser.js +0 -5825
- package/dist/index.browser.js.map +0 -1
- package/dist/index.node.d.ts +0 -8263
- package/dist/index.node.d.ts.map +0 -1
- package/dist/index.node.js +0 -12566
- package/dist/index.node.js.map +0 -1
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
CREATE TYPE "router_v1.14"."callback_type" AS ENUM('empty');--> statement-breakpoint
|
|
2
|
+
CREATE TYPE "router_v1.14"."position_type" AS ENUM('erc20', 'vault_v1', 'debtOf', 'collateralOf');--> statement-breakpoint
|
|
3
|
+
CREATE TYPE "router_v1.14"."status_code" AS ENUM('VALID', 'SIMULATION_ERROR');--> statement-breakpoint
|
|
4
|
+
CREATE TABLE "router_v1.14"."callbacks" (
|
|
5
|
+
"id" varchar(66) PRIMARY KEY NOT NULL,
|
|
6
|
+
"position_chain_id" bigint NOT NULL,
|
|
7
|
+
"position_contract" varchar(66) NOT NULL,
|
|
8
|
+
"position_user" varchar(42) NOT NULL,
|
|
9
|
+
"position_type_id" integer NOT NULL,
|
|
10
|
+
"type" "router_v1.14"."callback_type" NOT NULL
|
|
11
|
+
);
|
|
12
|
+
--> statement-breakpoint
|
|
13
|
+
CREATE TABLE "router_v1.14"."chains" (
|
|
14
|
+
"chain_id" bigint NOT NULL,
|
|
15
|
+
"block_number" bigint NOT NULL,
|
|
16
|
+
"epoch" numeric(78, 0) DEFAULT '0' NOT NULL,
|
|
17
|
+
"checkpoints" text DEFAULT '[]' NOT NULL,
|
|
18
|
+
"tip_hash" text,
|
|
19
|
+
"finalized_block_number" bigint,
|
|
20
|
+
"finalized_block_hash" text,
|
|
21
|
+
"updated_at" timestamp DEFAULT now() NOT NULL
|
|
22
|
+
);
|
|
23
|
+
--> statement-breakpoint
|
|
24
|
+
CREATE TABLE "router_v1.14"."collectors" (
|
|
25
|
+
"chain_id" bigint NOT NULL,
|
|
26
|
+
"name" text NOT NULL,
|
|
27
|
+
"block_number" bigint NOT NULL,
|
|
28
|
+
"epoch" numeric(78, 0) DEFAULT '0' NOT NULL,
|
|
29
|
+
"updated_at" timestamp DEFAULT now() NOT NULL
|
|
30
|
+
);
|
|
31
|
+
--> statement-breakpoint
|
|
32
|
+
CREATE TABLE "router_v1.14"."consumed_events" (
|
|
33
|
+
"event_id" varchar(128) PRIMARY KEY NOT NULL,
|
|
34
|
+
"chain_id" bigint NOT NULL,
|
|
35
|
+
"maker" varchar(42) NOT NULL,
|
|
36
|
+
"group" varchar(66) NOT NULL,
|
|
37
|
+
"amount" numeric(78, 0) NOT NULL,
|
|
38
|
+
"block_number" bigint NOT NULL,
|
|
39
|
+
"created_at" timestamp DEFAULT now() NOT NULL
|
|
40
|
+
);
|
|
41
|
+
--> statement-breakpoint
|
|
42
|
+
CREATE TABLE "router_v1.14"."groups" (
|
|
43
|
+
"chain_id" bigint NOT NULL,
|
|
44
|
+
"maker" varchar(42) NOT NULL,
|
|
45
|
+
"group" varchar(66) NOT NULL,
|
|
46
|
+
"consumed" numeric(78, 0) NOT NULL,
|
|
47
|
+
"block_number" bigint NOT NULL,
|
|
48
|
+
"updated_at" timestamp DEFAULT now() NOT NULL,
|
|
49
|
+
CONSTRAINT "groups_pk" PRIMARY KEY("chain_id","maker","group")
|
|
50
|
+
);
|
|
51
|
+
--> statement-breakpoint
|
|
52
|
+
CREATE TABLE "router_v1.14"."lots" (
|
|
53
|
+
"chain_id" bigint NOT NULL,
|
|
54
|
+
"user" varchar(42) NOT NULL,
|
|
55
|
+
"contract" varchar(66) NOT NULL,
|
|
56
|
+
"group" varchar(66) NOT NULL,
|
|
57
|
+
"obligation_id" varchar(66) NOT NULL,
|
|
58
|
+
"lower" numeric(78, 0) NOT NULL,
|
|
59
|
+
"upper" numeric(78, 0) NOT NULL,
|
|
60
|
+
CONSTRAINT "lots_pk" PRIMARY KEY("chain_id","user","contract","group","obligation_id")
|
|
61
|
+
);
|
|
62
|
+
--> statement-breakpoint
|
|
63
|
+
CREATE TABLE "router_v1.14"."lots_positions" (
|
|
64
|
+
"chain_id" bigint NOT NULL,
|
|
65
|
+
"contract" varchar(66) NOT NULL,
|
|
66
|
+
"user" varchar(42) NOT NULL,
|
|
67
|
+
"position_type_id" integer NOT NULL,
|
|
68
|
+
CONSTRAINT "lots_positions_pk" PRIMARY KEY("chain_id","contract","user")
|
|
69
|
+
);
|
|
70
|
+
--> statement-breakpoint
|
|
71
|
+
CREATE TABLE "router_v1.14"."merkle_paths" (
|
|
72
|
+
"offer_hash" varchar(66) NOT NULL,
|
|
73
|
+
"obligation_id" varchar(66) NOT NULL,
|
|
74
|
+
"tree_root" varchar(66) NOT NULL,
|
|
75
|
+
"proof_nodes" text NOT NULL,
|
|
76
|
+
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
77
|
+
CONSTRAINT "merkle_paths_pk" PRIMARY KEY("offer_hash","obligation_id")
|
|
78
|
+
);
|
|
79
|
+
--> statement-breakpoint
|
|
80
|
+
CREATE TABLE "router_v1.14"."obligation_collaterals_v2" (
|
|
81
|
+
"obligation_key" varchar(66) NOT NULL,
|
|
82
|
+
"asset" varchar(42) NOT NULL,
|
|
83
|
+
"oracle_address" varchar(42) NOT NULL,
|
|
84
|
+
"lltv" bigint NOT NULL,
|
|
85
|
+
"max_lif" bigint NOT NULL,
|
|
86
|
+
"collateral_index" integer NOT NULL,
|
|
87
|
+
"updated_at" timestamp DEFAULT now() NOT NULL,
|
|
88
|
+
CONSTRAINT "obligation_collaterals_v2_pk" PRIMARY KEY("obligation_key","asset")
|
|
89
|
+
);
|
|
90
|
+
--> statement-breakpoint
|
|
91
|
+
CREATE TABLE "router_v1.14"."obligation_id_keys" (
|
|
92
|
+
"obligation_id" varchar(66) PRIMARY KEY NOT NULL,
|
|
93
|
+
"obligation_key" varchar(66) NOT NULL,
|
|
94
|
+
"chain_id" bigint NOT NULL,
|
|
95
|
+
"morpho_v2" varchar(42) NOT NULL
|
|
96
|
+
);
|
|
97
|
+
--> statement-breakpoint
|
|
98
|
+
CREATE TABLE "router_v1.14"."obligations" (
|
|
99
|
+
"obligation_key" varchar(66) PRIMARY KEY NOT NULL,
|
|
100
|
+
"loan_token" varchar(42) NOT NULL,
|
|
101
|
+
"maturity" integer NOT NULL,
|
|
102
|
+
"rcf_threshold" numeric(78, 0) NOT NULL
|
|
103
|
+
);
|
|
104
|
+
--> statement-breakpoint
|
|
105
|
+
CREATE TABLE "router_v1.14"."offers" (
|
|
106
|
+
"hash" varchar(66) NOT NULL,
|
|
107
|
+
"obligation_id" varchar(66) NOT NULL,
|
|
108
|
+
"obligation_units" numeric(78, 0) DEFAULT '0' NOT NULL,
|
|
109
|
+
"obligation_shares" numeric(78, 0) DEFAULT '0' NOT NULL,
|
|
110
|
+
"tick" integer NOT NULL,
|
|
111
|
+
"maturity" integer NOT NULL,
|
|
112
|
+
"expiry" integer NOT NULL,
|
|
113
|
+
"start" integer NOT NULL,
|
|
114
|
+
"group_chain_id" bigint NOT NULL,
|
|
115
|
+
"group_maker" varchar(42) NOT NULL,
|
|
116
|
+
"group_group" varchar(66) NOT NULL,
|
|
117
|
+
"session" varchar(66) NOT NULL,
|
|
118
|
+
"buy" boolean NOT NULL,
|
|
119
|
+
"callback_address" varchar(42) NOT NULL,
|
|
120
|
+
"callback_data" text NOT NULL,
|
|
121
|
+
"receiver_if_maker_is_seller" varchar(42),
|
|
122
|
+
"block_number" bigint NOT NULL,
|
|
123
|
+
"updated_at" timestamp DEFAULT now() NOT NULL,
|
|
124
|
+
CONSTRAINT "offers_pk" PRIMARY KEY("hash","obligation_id")
|
|
125
|
+
);
|
|
126
|
+
--> statement-breakpoint
|
|
127
|
+
CREATE TABLE "router_v1.14"."offers_callbacks" (
|
|
128
|
+
"offer_hash" varchar(66) NOT NULL,
|
|
129
|
+
"obligation_id" varchar(66) NOT NULL,
|
|
130
|
+
"callback_id" varchar(66),
|
|
131
|
+
CONSTRAINT "offers_callbacks_pk" PRIMARY KEY("offer_hash","obligation_id","callback_id")
|
|
132
|
+
);
|
|
133
|
+
--> statement-breakpoint
|
|
134
|
+
CREATE TABLE "router_v1.14"."offsets" (
|
|
135
|
+
"chain_id" bigint NOT NULL,
|
|
136
|
+
"user" varchar(42) NOT NULL,
|
|
137
|
+
"contract" varchar(66) NOT NULL,
|
|
138
|
+
"group" varchar(66) NOT NULL,
|
|
139
|
+
"obligation_id" varchar(66) NOT NULL,
|
|
140
|
+
"value" numeric(78, 0) NOT NULL,
|
|
141
|
+
CONSTRAINT "offsets_pk" PRIMARY KEY("chain_id","user","contract","group","obligation_id")
|
|
142
|
+
);
|
|
143
|
+
--> statement-breakpoint
|
|
144
|
+
CREATE TABLE "router_v1.14"."oracles" (
|
|
145
|
+
"chain_id" bigint NOT NULL,
|
|
146
|
+
"address" varchar(42) NOT NULL,
|
|
147
|
+
"price" numeric(78, 0),
|
|
148
|
+
"block_number" bigint NOT NULL,
|
|
149
|
+
"updated_at" timestamp DEFAULT now() NOT NULL,
|
|
150
|
+
CONSTRAINT "oracles_pk" PRIMARY KEY("chain_id","address")
|
|
151
|
+
);
|
|
152
|
+
--> statement-breakpoint
|
|
153
|
+
CREATE TABLE "router_v1.14"."pending_links" (
|
|
154
|
+
"key" varchar(191) PRIMARY KEY NOT NULL,
|
|
155
|
+
"type" text NOT NULL,
|
|
156
|
+
"status" text NOT NULL,
|
|
157
|
+
"chain_id" bigint NOT NULL,
|
|
158
|
+
"event_id" varchar(128) NOT NULL,
|
|
159
|
+
"obligation_id" varchar(66) NOT NULL,
|
|
160
|
+
"collateral_index" integer NOT NULL,
|
|
161
|
+
"user" varchar(42) NOT NULL,
|
|
162
|
+
"amount" numeric(78, 0) NOT NULL,
|
|
163
|
+
"block_number" bigint NOT NULL,
|
|
164
|
+
"first_seen_block" bigint NOT NULL,
|
|
165
|
+
"last_tried_block" bigint,
|
|
166
|
+
"attempts" integer DEFAULT 0 NOT NULL,
|
|
167
|
+
"ignored_reason" text,
|
|
168
|
+
"resolved_at" timestamp,
|
|
169
|
+
"updated_at" timestamp DEFAULT now() NOT NULL
|
|
170
|
+
);
|
|
171
|
+
--> statement-breakpoint
|
|
172
|
+
CREATE TABLE "router_v1.14"."position_types" (
|
|
173
|
+
"id" serial PRIMARY KEY NOT NULL,
|
|
174
|
+
"type" "router_v1.14"."position_type" NOT NULL
|
|
175
|
+
);
|
|
176
|
+
--> statement-breakpoint
|
|
177
|
+
CREATE TABLE "router_v1.14"."positions" (
|
|
178
|
+
"chain_id" bigint NOT NULL,
|
|
179
|
+
"contract" varchar(66) NOT NULL,
|
|
180
|
+
"user" varchar(42) NOT NULL,
|
|
181
|
+
"position_type_id" integer NOT NULL,
|
|
182
|
+
"balance" numeric(78, 0),
|
|
183
|
+
"asset" varchar(42) NOT NULL,
|
|
184
|
+
"block_number" bigint NOT NULL,
|
|
185
|
+
"updated_at" timestamp DEFAULT now() NOT NULL,
|
|
186
|
+
CONSTRAINT "positions_pk" PRIMARY KEY("chain_id","contract","user","position_type_id","asset")
|
|
187
|
+
);
|
|
188
|
+
--> statement-breakpoint
|
|
189
|
+
CREATE TABLE "router_v1.14"."status" (
|
|
190
|
+
"id" serial PRIMARY KEY NOT NULL,
|
|
191
|
+
"code" "router_v1.14"."status_code",
|
|
192
|
+
CONSTRAINT "status_code_unique" UNIQUE("code")
|
|
193
|
+
);
|
|
194
|
+
--> statement-breakpoint
|
|
195
|
+
CREATE TABLE "router_v1.14"."transfers" (
|
|
196
|
+
"event_id" varchar(128) PRIMARY KEY NOT NULL,
|
|
197
|
+
"chain_id" bigint NOT NULL,
|
|
198
|
+
"contract" varchar(66) NOT NULL,
|
|
199
|
+
"from" varchar(42) NOT NULL,
|
|
200
|
+
"to" varchar(42) NOT NULL,
|
|
201
|
+
"value" numeric(78, 0) NOT NULL,
|
|
202
|
+
"position_type_id" integer NOT NULL,
|
|
203
|
+
"asset" varchar(42) NOT NULL,
|
|
204
|
+
"block_number" bigint NOT NULL,
|
|
205
|
+
"created_at" timestamp DEFAULT now() NOT NULL
|
|
206
|
+
);
|
|
207
|
+
--> statement-breakpoint
|
|
208
|
+
CREATE TABLE "router_v1.14"."trees" (
|
|
209
|
+
"root" varchar(66) PRIMARY KEY NOT NULL,
|
|
210
|
+
"root_signature" varchar(132) NOT NULL,
|
|
211
|
+
"created_at" timestamp DEFAULT now() NOT NULL
|
|
212
|
+
);
|
|
213
|
+
--> statement-breakpoint
|
|
214
|
+
CREATE TABLE "router_v1.14"."validations" (
|
|
215
|
+
"offer_hash" varchar(66) NOT NULL,
|
|
216
|
+
"obligation_id" varchar(66) NOT NULL,
|
|
217
|
+
"status_id" integer NOT NULL,
|
|
218
|
+
"updated_at" timestamp DEFAULT now() NOT NULL,
|
|
219
|
+
CONSTRAINT "validations_pk" PRIMARY KEY("offer_hash","obligation_id")
|
|
220
|
+
);
|
|
221
|
+
--> statement-breakpoint
|
|
222
|
+
CREATE UNIQUE INDEX "chains_chain_id_idx" ON "router_v1.14"."chains" USING btree ("chain_id");--> statement-breakpoint
|
|
223
|
+
CREATE UNIQUE INDEX "collectors_chain_name_idx" ON "router_v1.14"."collectors" USING btree ("chain_id","name");--> statement-breakpoint
|
|
224
|
+
DROP TABLE "router_v1.13"."callbacks" CASCADE;--> statement-breakpoint
|
|
225
|
+
DROP TABLE "router_v1.13"."chains" CASCADE;--> statement-breakpoint
|
|
226
|
+
DROP TABLE "router_v1.13"."collectors" CASCADE;--> statement-breakpoint
|
|
227
|
+
DROP TABLE "router_v1.13"."consumed_events" CASCADE;--> statement-breakpoint
|
|
228
|
+
DROP TABLE "router_v1.13"."groups" CASCADE;--> statement-breakpoint
|
|
229
|
+
DROP TABLE "router_v1.13"."lots" CASCADE;--> statement-breakpoint
|
|
230
|
+
DROP TABLE "router_v1.13"."lots_positions" CASCADE;--> statement-breakpoint
|
|
231
|
+
DROP TABLE "router_v1.13"."merkle_paths" CASCADE;--> statement-breakpoint
|
|
232
|
+
DROP TABLE "router_v1.13"."obligation_collaterals_v2" CASCADE;--> statement-breakpoint
|
|
233
|
+
DROP TABLE "router_v1.13"."obligation_id_keys" CASCADE;--> statement-breakpoint
|
|
234
|
+
DROP TABLE "router_v1.13"."obligations" CASCADE;--> statement-breakpoint
|
|
235
|
+
DROP TABLE "router_v1.13"."offers" CASCADE;--> statement-breakpoint
|
|
236
|
+
DROP TABLE "router_v1.13"."offers_callbacks" CASCADE;--> statement-breakpoint
|
|
237
|
+
DROP TABLE "router_v1.13"."offsets" CASCADE;--> statement-breakpoint
|
|
238
|
+
DROP TABLE "router_v1.13"."oracles" CASCADE;--> statement-breakpoint
|
|
239
|
+
DROP TABLE "router_v1.13"."pending_links" CASCADE;--> statement-breakpoint
|
|
240
|
+
DROP TABLE "router_v1.13"."position_types" CASCADE;--> statement-breakpoint
|
|
241
|
+
DROP TABLE "router_v1.13"."positions" CASCADE;--> statement-breakpoint
|
|
242
|
+
DROP TABLE "router_v1.13"."status" CASCADE;--> statement-breakpoint
|
|
243
|
+
DROP TABLE "router_v1.13"."transfers" CASCADE;--> statement-breakpoint
|
|
244
|
+
DROP TABLE "router_v1.13"."trees" CASCADE;--> statement-breakpoint
|
|
245
|
+
DROP TABLE "router_v1.13"."validations" CASCADE;--> statement-breakpoint
|
|
246
|
+
ALTER TABLE "router_v1.14"."callbacks" ADD CONSTRAINT "callbacks_position_type_id_position_types_id_fk" FOREIGN KEY ("position_type_id") REFERENCES "router_v1.14"."position_types"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
247
|
+
ALTER TABLE "router_v1.14"."collectors" ADD CONSTRAINT "collectors_chain_id_chains_chain_id_fk" FOREIGN KEY ("chain_id") REFERENCES "router_v1.14"."chains"("chain_id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
248
|
+
ALTER TABLE "router_v1.14"."consumed_events" ADD CONSTRAINT "consumed_events_groups_fk" FOREIGN KEY ("chain_id","maker","group") REFERENCES "router_v1.14"."groups"("chain_id","maker","group") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
249
|
+
ALTER TABLE "router_v1.14"."lots" ADD CONSTRAINT "lots_lots_positions_fk" FOREIGN KEY ("chain_id","contract","user") REFERENCES "router_v1.14"."lots_positions"("chain_id","contract","user") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
250
|
+
ALTER TABLE "router_v1.14"."lots" ADD CONSTRAINT "lots_groups_fk" FOREIGN KEY ("chain_id","user","group") REFERENCES "router_v1.14"."groups"("chain_id","maker","group") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
251
|
+
ALTER TABLE "router_v1.14"."lots_positions" ADD CONSTRAINT "lots_positions_position_type_id_position_types_id_fk" FOREIGN KEY ("position_type_id") REFERENCES "router_v1.14"."position_types"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
252
|
+
ALTER TABLE "router_v1.14"."merkle_paths" ADD CONSTRAINT "merkle_paths_tree_root_trees_root_fk" FOREIGN KEY ("tree_root") REFERENCES "router_v1.14"."trees"("root") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
253
|
+
ALTER TABLE "router_v1.14"."merkle_paths" ADD CONSTRAINT "merkle_paths_offer_fk" FOREIGN KEY ("offer_hash","obligation_id") REFERENCES "router_v1.14"."offers"("hash","obligation_id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
254
|
+
ALTER TABLE "router_v1.14"."obligation_collaterals_v2" ADD CONSTRAINT "obligation_collaterals_v2_obligation_key_obligations_obligation_key_fk" FOREIGN KEY ("obligation_key") REFERENCES "router_v1.14"."obligations"("obligation_key") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
255
|
+
ALTER TABLE "router_v1.14"."obligation_id_keys" ADD CONSTRAINT "obligation_id_keys_obligation_key_obligations_obligation_key_fk" FOREIGN KEY ("obligation_key") REFERENCES "router_v1.14"."obligations"("obligation_key") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
256
|
+
ALTER TABLE "router_v1.14"."offers" ADD CONSTRAINT "offers_obligation_id_obligation_id_keys_obligation_id_fk" FOREIGN KEY ("obligation_id") REFERENCES "router_v1.14"."obligation_id_keys"("obligation_id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
257
|
+
ALTER TABLE "router_v1.14"."offers" ADD CONSTRAINT "offers_groups_fk" FOREIGN KEY ("group_chain_id","group_maker","group_group") REFERENCES "router_v1.14"."groups"("chain_id","maker","group") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
258
|
+
ALTER TABLE "router_v1.14"."offers_callbacks" ADD CONSTRAINT "offers_callbacks_offer_fk" FOREIGN KEY ("offer_hash","obligation_id") REFERENCES "router_v1.14"."offers"("hash","obligation_id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
259
|
+
ALTER TABLE "router_v1.14"."offsets" ADD CONSTRAINT "offsets_lots_positions_fk" FOREIGN KEY ("chain_id","contract","user") REFERENCES "router_v1.14"."lots_positions"("chain_id","contract","user") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
260
|
+
ALTER TABLE "router_v1.14"."positions" ADD CONSTRAINT "positions_position_type_id_position_types_id_fk" FOREIGN KEY ("position_type_id") REFERENCES "router_v1.14"."position_types"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
261
|
+
ALTER TABLE "router_v1.14"."transfers" ADD CONSTRAINT "transfers_position_type_id_position_types_id_fk" FOREIGN KEY ("position_type_id") REFERENCES "router_v1.14"."position_types"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
262
|
+
ALTER TABLE "router_v1.14"."transfers" ADD CONSTRAINT "transfers_positions_from_fk" FOREIGN KEY ("chain_id","contract","from","position_type_id","asset") REFERENCES "router_v1.14"."positions"("chain_id","contract","user","position_type_id","asset") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
263
|
+
ALTER TABLE "router_v1.14"."transfers" ADD CONSTRAINT "transfers_positions_to_fk" FOREIGN KEY ("chain_id","contract","to","position_type_id","asset") REFERENCES "router_v1.14"."positions"("chain_id","contract","user","position_type_id","asset") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
264
|
+
ALTER TABLE "router_v1.14"."validations" ADD CONSTRAINT "validations_status_id_status_id_fk" FOREIGN KEY ("status_id") REFERENCES "router_v1.14"."status"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
265
|
+
ALTER TABLE "router_v1.14"."validations" ADD CONSTRAINT "validations_offer_fk" FOREIGN KEY ("offer_hash","obligation_id") REFERENCES "router_v1.14"."offers"("hash","obligation_id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
266
|
+
CREATE INDEX "consumed_events_group_idx" ON "router_v1.14"."consumed_events" USING btree ("chain_id","maker","group");--> statement-breakpoint
|
|
267
|
+
CREATE INDEX "consumed_events_block_number_idx" ON "router_v1.14"."consumed_events" USING btree ("block_number");--> statement-breakpoint
|
|
268
|
+
CREATE INDEX "groups_chain_id_maker_group_consumed_idx" ON "router_v1.14"."groups" USING btree ("chain_id","maker","group","consumed");--> statement-breakpoint
|
|
269
|
+
CREATE INDEX "merkle_paths_tree_root_idx" ON "router_v1.14"."merkle_paths" USING btree ("tree_root");--> statement-breakpoint
|
|
270
|
+
CREATE INDEX "obligation_collaterals_v2_obligation_key_idx" ON "router_v1.14"."obligation_collaterals_v2" USING btree ("obligation_key");--> statement-breakpoint
|
|
271
|
+
CREATE INDEX "obligation_collaterals_v2_oracle_address_idx" ON "router_v1.14"."obligation_collaterals_v2" USING btree ("oracle_address");--> statement-breakpoint
|
|
272
|
+
CREATE INDEX "obligation_id_keys_obligation_key_idx" ON "router_v1.14"."obligation_id_keys" USING btree ("obligation_key");--> statement-breakpoint
|
|
273
|
+
CREATE INDEX "obligation_id_keys_chain_id_idx" ON "router_v1.14"."obligation_id_keys" USING btree ("chain_id");--> statement-breakpoint
|
|
274
|
+
CREATE INDEX "offers_group_fk_idx" ON "router_v1.14"."offers" USING btree ("group_chain_id","group_maker","group_group");--> statement-breakpoint
|
|
275
|
+
CREATE INDEX "offers_group_and_hash_idx" ON "router_v1.14"."offers" USING btree ("group_chain_id","group_maker","group_group","hash");--> statement-breakpoint
|
|
276
|
+
CREATE INDEX "offers_obligation_id_side_idx" ON "router_v1.14"."offers" USING btree ("obligation_id","buy");--> statement-breakpoint
|
|
277
|
+
CREATE INDEX "pending_links_chain_type_status_idx" ON "router_v1.14"."pending_links" USING btree ("chain_id","type","status");--> statement-breakpoint
|
|
278
|
+
CREATE INDEX "pending_links_pending_scan_idx" ON "router_v1.14"."pending_links" USING btree ("chain_id","type","status","first_seen_block");--> statement-breakpoint
|
|
279
|
+
CREATE INDEX "pending_links_event_id_idx" ON "router_v1.14"."pending_links" USING btree ("chain_id","event_id");--> statement-breakpoint
|
|
280
|
+
CREATE INDEX "transfers_chain_contract_user_idx" ON "router_v1.14"."transfers" USING btree ("chain_id","contract","from","to","block_number");--> statement-breakpoint
|
|
281
|
+
CREATE INDEX "transfers_chain_type_block_idx" ON "router_v1.14"."transfers" USING btree ("chain_id","position_type_id","block_number");--> statement-breakpoint
|
|
282
|
+
DROP TYPE "router_v1.13"."callback_type";--> statement-breakpoint
|
|
283
|
+
DROP TYPE "router_v1.13"."position_type";--> statement-breakpoint
|
|
284
|
+
DROP TYPE "router_v1.13"."status_code";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
CREATE INDEX "offers_obligation_side_tick_idx" ON "router_v1.14"."offers" USING btree ("obligation_id","buy","tick");
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
-- Drop redundant indexes to reduce write amplification on hot tables.
|
|
2
|
+
-- groups PK already covers (chain_id, maker, group); consumed column adds marginal value.
|
|
3
|
+
DROP INDEX "router_v1.14"."groups_chain_id_maker_group_consumed_idx";--> statement-breakpoint
|
|
4
|
+
-- obligation_collaterals_v2 PK is (obligation_key, asset); obligation_key prefix is already covered.
|
|
5
|
+
DROP INDEX "router_v1.14"."obligation_collaterals_v2_obligation_key_idx";--> statement-breakpoint
|
|
6
|
+
-- oracle_address is only used in JOINs where rows are already filtered by obligation_key; no direct filter.
|
|
7
|
+
DROP INDEX "router_v1.14"."obligation_collaterals_v2_oracle_address_idx";--> statement-breakpoint
|
|
8
|
+
-- offers_group_fk_idx is a subset of offers_group_and_hash_idx.
|
|
9
|
+
DROP INDEX "router_v1.14"."offers_group_fk_idx";--> statement-breakpoint
|
|
10
|
+
-- offers_obligation_id_side_idx is a subset of offers_obligation_side_tick_idx.
|
|
11
|
+
DROP INDEX "router_v1.14"."offers_obligation_id_side_idx";--> statement-breakpoint
|
|
12
|
+
-- pending_links_chain_type_status_idx is an exact prefix of pending_links_pending_scan_idx.
|
|
13
|
+
DROP INDEX "router_v1.14"."pending_links_chain_type_status_idx";--> statement-breakpoint
|
|
14
|
+
-- Index for maker-filtered offers endpoint with cursor pagination.
|
|
15
|
+
CREATE INDEX "offers_group_maker_idx" ON "router_v1.14"."offers" USING btree ("group_maker","hash","obligation_id");--> statement-breakpoint
|
|
16
|
+
-- Expression index for DISTINCT ON group_winners queries (Book, OfferFormulas).
|
|
17
|
+
-- Was on v1.13 (migration 0041) but missing from v1.14.
|
|
18
|
+
CREATE INDEX "offers_group_winner_expr_idx" ON "router_v1.14"."offers" (
|
|
19
|
+
"group_chain_id",
|
|
20
|
+
"group_maker",
|
|
21
|
+
"group_group",
|
|
22
|
+
"obligation_id",
|
|
23
|
+
"buy",
|
|
24
|
+
(CASE WHEN "buy" THEN -"tick" ELSE "tick" END),
|
|
25
|
+
"block_number",
|
|
26
|
+
"hash"
|
|
27
|
+
);
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
-- Index for position_consumed CTE: joins lots on (chain_id, user, group, obligation_id) skipping contract.
|
|
2
|
+
-- PK (chain_id, user, contract, group, obligation_id) has contract between user and group, preventing efficient group filtering.
|
|
3
|
+
CREATE INDEX "lots_position_group_obligation_idx" ON "router_v1.14"."lots" USING btree ("chain_id","user","group","obligation_id");--> statement-breakpoint
|
|
4
|
+
-- Index for position_offsets CTE: filters offsets on (chain_id, contract, user) but PK order is (chain_id, user, contract, ...).
|
|
5
|
+
CREATE INDEX "offsets_position_obligation_idx" ON "router_v1.14"."offsets" USING btree ("chain_id","contract","user","obligation_id");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
CREATE INDEX "offers_obligation_active_tick_idx" ON "router_v1.14"."offers" USING btree ("obligation_id","buy","expiry","maturity","start","tick");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
CREATE INDEX "offers_book_winners_idx" ON "router_v1.14"."offers" USING btree ("obligation_id","buy","group_chain_id","group_maker","group_group");
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
-- Replace offers_book_winners_idx with covering version that includes all ORDER BY
|
|
2
|
+
-- columns for the Book.ts winners CTE. Enables sort-free DISTINCT ON by providing
|
|
3
|
+
-- index entries in (group_cols, expr_tick, block_number, obligation_units, hash) order
|
|
4
|
+
-- after seeking on (obligation_id, buy).
|
|
5
|
+
DROP INDEX "router_v1.14"."offers_book_winners_idx";--> statement-breakpoint
|
|
6
|
+
|
|
7
|
+
CREATE INDEX "offers_book_winners_covering_idx" ON "router_v1.14"."offers" (
|
|
8
|
+
"obligation_id",
|
|
9
|
+
"buy",
|
|
10
|
+
"group_chain_id",
|
|
11
|
+
"group_maker",
|
|
12
|
+
"group_group",
|
|
13
|
+
(CASE WHEN "buy" THEN -"tick" ELSE "tick" END),
|
|
14
|
+
"block_number",
|
|
15
|
+
"obligation_units" DESC,
|
|
16
|
+
"hash"
|
|
17
|
+
);--> statement-breakpoint
|
|
18
|
+
|
|
19
|
+
-- Extend offers_group_winner_expr_idx with obligation_units DESC to cover the full
|
|
20
|
+
-- ORDER BY of the group_winners CTE in OfferFormulas.ts. Without this column the
|
|
21
|
+
-- planner must sort after the index scan.
|
|
22
|
+
DROP INDEX "router_v1.14"."offers_group_winner_expr_idx";--> statement-breakpoint
|
|
23
|
+
|
|
24
|
+
CREATE INDEX "offers_group_winner_expr_idx" ON "router_v1.14"."offers" (
|
|
25
|
+
"group_chain_id",
|
|
26
|
+
"group_maker",
|
|
27
|
+
"group_group",
|
|
28
|
+
"obligation_id",
|
|
29
|
+
"buy",
|
|
30
|
+
(CASE WHEN "buy" THEN -"tick" ELSE "tick" END),
|
|
31
|
+
"block_number",
|
|
32
|
+
"obligation_units" DESC,
|
|
33
|
+
"hash"
|
|
34
|
+
);
|