CREATE TABLE "offer_collaterals" (
	"id" serial PRIMARY KEY NOT NULL,
	"offer_hash" varchar(66) NOT NULL,
	"asset" varchar(42) NOT NULL,
	"oracle" varchar(42) NOT NULL,
	"lltv" bigint NOT NULL
);
--> statement-breakpoint
CREATE TABLE "offers" (
	"hash" varchar(66) PRIMARY KEY NOT NULL,
	"address" varchar(42) NOT NULL,
	"assets" bigint NOT NULL,
	"price" bigint NOT NULL,
	"maturity" integer NOT NULL,
	"expiry" integer NOT NULL,
	"nonce" bigint NOT NULL,
	"is_buy" boolean NOT NULL,
	"chain_id" bigint NOT NULL,
	"loan_asset" varchar(42) NOT NULL,
	"callback_address" varchar(42) NOT NULL,
	"callback_data" text NOT NULL,
	"callback_gas_limit" bigint NOT NULL,
	"signature" varchar(132),
	"created_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
ALTER TABLE "offer_collaterals" ADD CONSTRAINT "offer_collaterals_offer_hash_offers_hash_fk" FOREIGN KEY ("offer_hash") REFERENCES "public"."offers"("hash") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
CREATE INDEX "offer_collaterals_offer_hash_idx" ON "offer_collaterals" USING btree ("offer_hash");--> statement-breakpoint
CREATE INDEX "offer_collaterals_asset_idx" ON "offer_collaterals" USING btree ("asset");--> statement-breakpoint
CREATE INDEX "offer_collaterals_oracle_idx" ON "offer_collaterals" USING btree ("oracle");--> statement-breakpoint
CREATE INDEX "offer_collaterals_tuple_idx" ON "offer_collaterals" USING btree ("asset","oracle","lltv");--> statement-breakpoint
CREATE INDEX "offers_address_idx" ON "offers" USING btree ("address");--> statement-breakpoint
CREATE INDEX "offers_is_buy_idx" ON "offers" USING btree ("is_buy");--> statement-breakpoint
CREATE INDEX "offers_chain_id_idx" ON "offers" USING btree ("chain_id");--> statement-breakpoint
CREATE INDEX "offers_loan_asset_idx" ON "offers" USING btree ("loan_asset");--> statement-breakpoint
CREATE INDEX "offers_maturity_idx" ON "offers" USING btree ("maturity");--> statement-breakpoint
CREATE INDEX "offers_expiry_idx" ON "offers" USING btree ("expiry");