diff --git a/packages/db/migrations/0013_chain_event_gap.sql b/packages/db/migrations/0013_chain_event_gap.sql new file mode 100644 index 0000000..34a3691 --- /dev/null +++ b/packages/db/migrations/0013_chain_event_gap.sql @@ -0,0 +1,9 @@ +CREATE TABLE IF NOT EXISTS "chain_event_gap" ( + "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, + "from_ledger" integer NOT NULL, + "to_ledger" integer NOT NULL, + "detected_at" timestamp with time zone DEFAULT now() NOT NULL, + "status" text DEFAULT 'open' NOT NULL +); +--> statement-breakpoint +CREATE UNIQUE INDEX IF NOT EXISTS "chain_event_gap_range_uq" ON "chain_event_gap" USING btree ("from_ledger","to_ledger"); \ No newline at end of file diff --git a/packages/db/migrations/meta/0013_snapshot.json b/packages/db/migrations/meta/0013_snapshot.json new file mode 100644 index 0000000..ffaeeb1 --- /dev/null +++ b/packages/db/migrations/meta/0013_snapshot.json @@ -0,0 +1,2494 @@ +{ + "id": "95bccb06-c11a-4b49-903f-fa8f8bce322b", + "prevId": "77c1cf79-3d9a-44a7-9a01-7c7154d747d9", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.api_key_nonce": { + "name": "api_key_nonce", + "schema": "", + "columns": { + "key_id": { + "name": "key_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "nonce": { + "name": "nonce", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": { + "api_key_nonce_key_id_nonce_pk": { + "name": "api_key_nonce_key_id_nonce_pk", + "columns": [ + "key_id", + "nonce" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.asset": { + "name": "asset", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "code": { + "name": "code", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "issuer_g": { + "name": "issuer_g", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "issuer_code": { + "name": "issuer_code", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "contract_c": { + "name": "contract_c", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "standard": { + "name": "standard", + "type": "asset_standard", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "yield_type": { + "name": "yield_type", + "type": "yield_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "custody_mode": { + "name": "custody_mode", + "type": "custody_mode", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "ccy": { + "name": "ccy", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "redemption_lag_days": { + "name": "redemption_lag_days", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "redemption_daily_cap": { + "name": "redemption_daily_cap", + "type": "numeric(32, 7)", + "primaryKey": false, + "notNull": false + }, + "nav_schedule": { + "name": "nav_schedule", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "price_band_bps": { + "name": "price_band_bps", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "daily_move_band_bps": { + "name": "daily_move_band_bps", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "haircut_base_bps": { + "name": "haircut_base_bps", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "haircut_fx_bps": { + "name": "haircut_fx_bps", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'active'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.asset_param_change": { + "name": "asset_param_change", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "asset_id": { + "name": "asset_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "field": { + "name": "field", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "old_value": { + "name": "old_value", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "new_value": { + "name": "new_value", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "queued_at": { + "name": "queued_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "executes_at": { + "name": "executes_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "tx_hash": { + "name": "tx_hash", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "executed_at": { + "name": "executed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "asset_param_change_asset_id_asset_id_fk": { + "name": "asset_param_change_asset_id_asset_id_fk", + "tableFrom": "asset_param_change", + "tableTo": "asset", + "columnsFrom": [ + "asset_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.audit_log": { + "name": "audit_log", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "actor": { + "name": "actor", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "action": { + "name": "action", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "payload": { + "name": "payload", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "tx_hash": { + "name": "tx_hash", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.chain_event": { + "name": "chain_event", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "event_id": { + "name": "event_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "ledger": { + "name": "ledger", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "tx_hash": { + "name": "tx_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "contract": { + "name": "contract", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "topic": { + "name": "topic", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "data": { + "name": "data", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "ingested_at": { + "name": "ingested_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "chain_event_event_id_uq": { + "name": "chain_event_event_id_uq", + "columns": [ + { + "expression": "event_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.chain_event_gap": { + "name": "chain_event_gap", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "from_ledger": { + "name": "from_ledger", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "to_ledger": { + "name": "to_ledger", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "detected_at": { + "name": "detected_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'open'" + } + }, + "indexes": { + "chain_event_gap_range_uq": { + "name": "chain_event_gap_range_uq", + "columns": [ + { + "expression": "from_ledger", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "to_ledger", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.compliance_check": { + "name": "compliance_check", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "party_id": { + "name": "party_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'sanctions'" + }, + "result": { + "name": "result", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "matches": { + "name": "matches", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "list_source": { + "name": "list_source", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "list_loaded_at": { + "name": "list_loaded_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "checked_at": { + "name": "checked_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "compliance_check_party_idx": { + "name": "compliance_check_party_idx", + "columns": [ + { + "expression": "party_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "checked_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "compliance_check_party_id_party_id_fk": { + "name": "compliance_check_party_id_party_id_fk", + "tableFrom": "compliance_check", + "tableTo": "party", + "columnsFrom": [ + "party_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.credit_line": { + "name": "credit_line", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "lender_id": { + "name": "lender_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "borrower_id": { + "name": "borrower_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "loan_ccy": { + "name": "loan_ccy", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "limit_amount": { + "name": "limit_amount", + "type": "numeric(32, 7)", + "primaryKey": false, + "notNull": true + }, + "rate_bps": { + "name": "rate_bps", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "fee_bps": { + "name": "fee_bps", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "cure_window_s": { + "name": "cure_window_s", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'open'" + }, + "contract_line_id": { + "name": "contract_line_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "agreement_hash": { + "name": "agreement_hash", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "opened_at": { + "name": "opened_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "closed_at": { + "name": "closed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "credit_line_lender_id_party_id_fk": { + "name": "credit_line_lender_id_party_id_fk", + "tableFrom": "credit_line", + "tableTo": "party", + "columnsFrom": [ + "lender_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "credit_line_borrower_id_party_id_fk": { + "name": "credit_line_borrower_id_party_id_fk", + "tableFrom": "credit_line", + "tableTo": "party", + "columnsFrom": [ + "borrower_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.draw": { + "name": "draw", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "credit_line_id": { + "name": "credit_line_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "amount": { + "name": "amount", + "type": "numeric(32, 7)", + "primaryKey": false, + "notNull": true + }, + "tx_hash": { + "name": "tx_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "ledger": { + "name": "ledger", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "draw_credit_line_id_credit_line_id_fk": { + "name": "draw_credit_line_id_credit_line_id_fk", + "tableFrom": "draw", + "tableTo": "credit_line", + "columnsFrom": [ + "credit_line_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.exit_fill": { + "name": "exit_fill", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "quote_id": { + "name": "quote_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "tx_hash": { + "name": "tx_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "payout_route": { + "name": "payout_route", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "payout_memo": { + "name": "payout_memo", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "exit_fill_quote_id_exit_quote_id_fk": { + "name": "exit_fill_quote_id_exit_quote_id_fk", + "tableFrom": "exit_fill", + "tableTo": "exit_quote", + "columnsFrom": [ + "quote_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.exit_quote": { + "name": "exit_quote", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "holder_id": { + "name": "holder_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "asset_id": { + "name": "asset_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "units": { + "name": "units", + "type": "numeric(32, 7)", + "primaryKey": false, + "notNull": true + }, + "price": { + "name": "price", + "type": "numeric(32, 7)", + "primaryKey": false, + "notNull": true + }, + "spread_bps": { + "name": "spread_bps", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "usdc_out": { + "name": "usdc_out", + "type": "numeric(32, 7)", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'open'" + } + }, + "indexes": {}, + "foreignKeys": { + "exit_quote_holder_id_party_id_fk": { + "name": "exit_quote_holder_id_party_id_fk", + "tableFrom": "exit_quote", + "tableTo": "party", + "columnsFrom": [ + "holder_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "exit_quote_asset_id_asset_id_fk": { + "name": "exit_quote_asset_id_asset_id_fk", + "tableFrom": "exit_quote", + "tableTo": "asset", + "columnsFrom": [ + "asset_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.indexer_cursor": { + "name": "indexer_cursor", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "last_ledger": { + "name": "last_ledger", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.issuer_idempotency": { + "name": "issuer_idempotency", + "schema": "", + "columns": { + "issuer_code": { + "name": "issuer_code", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "route": { + "name": "route", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "idempotency_key": { + "name": "idempotency_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "request_hash": { + "name": "request_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'in_flight'" + }, + "response": { + "name": "response", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": { + "issuer_idempotency_issuer_code_route_idempotency_key_pk": { + "name": "issuer_idempotency_issuer_code_route_idempotency_key_pk", + "columns": [ + "issuer_code", + "route", + "idempotency_key" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.journal_entry": { + "name": "journal_entry", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "ref_type": { + "name": "ref_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "ref_id": { + "name": "ref_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "account": { + "name": "account", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "debit": { + "name": "debit", + "type": "numeric(32, 7)", + "primaryKey": false, + "notNull": true, + "default": "'0'" + }, + "credit": { + "name": "credit", + "type": "numeric(32, 7)", + "primaryKey": false, + "notNull": true, + "default": "'0'" + }, + "ccy": { + "name": "ccy", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.liquidation": { + "name": "liquidation", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "credit_line_id": { + "name": "credit_line_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "route": { + "name": "route", + "type": "liquidation_route", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "units": { + "name": "units", + "type": "numeric(32, 7)", + "primaryKey": false, + "notNull": true + }, + "proceeds": { + "name": "proceeds", + "type": "numeric(32, 7)", + "primaryKey": false, + "notNull": false + }, + "shortfall": { + "name": "shortfall", + "type": "numeric(32, 7)", + "primaryKey": false, + "notNull": false + }, + "tx_hashes": { + "name": "tx_hashes", + "type": "text[]", + "primaryKey": false, + "notNull": false + }, + "started_at": { + "name": "started_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "liquidation_credit_line_id_credit_line_id_fk": { + "name": "liquidation_credit_line_id_credit_line_id_fk", + "tableFrom": "liquidation", + "tableTo": "credit_line", + "columnsFrom": [ + "credit_line_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "liquidation_credit_line_id_unique": { + "name": "liquidation_credit_line_id_unique", + "nullsNotDistinct": false, + "columns": [ + "credit_line_id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.margin_event": { + "name": "margin_event", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "credit_line_id": { + "name": "credit_line_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "from_state": { + "name": "from_state", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "to_state": { + "name": "to_state", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "ltv_bps": { + "name": "ltv_bps", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "price_snapshot_id": { + "name": "price_snapshot_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "margin_event_credit_line_id_credit_line_id_fk": { + "name": "margin_event_credit_line_id_credit_line_id_fk", + "tableFrom": "margin_event", + "tableTo": "credit_line", + "columnsFrom": [ + "credit_line_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "margin_event_price_snapshot_id_price_snapshot_id_fk": { + "name": "margin_event_price_snapshot_id_price_snapshot_id_fk", + "tableFrom": "margin_event", + "tableTo": "price_snapshot", + "columnsFrom": [ + "price_snapshot_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.party": { + "name": "party", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "kind": { + "name": "kind", + "type": "party_kind", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "legal_name": { + "name": "legal_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "jurisdiction": { + "name": "jurisdiction", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "kyb_status": { + "name": "kyb_status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "kyb_provider": { + "name": "kyb_provider", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "kyb_ref": { + "name": "kyb_ref", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.party_account": { + "name": "party_account", + "schema": "", + "columns": { + "party_id": { + "name": "party_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "stellar_account": { + "name": "stellar_account", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "role": { + "name": "role", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "verified_at": { + "name": "verified_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "party_account_party_id_party_id_fk": { + "name": "party_account_party_id_party_id_fk", + "tableFrom": "party_account", + "tableTo": "party", + "columnsFrom": [ + "party_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "party_account_party_id_stellar_account_pk": { + "name": "party_account_party_id_stellar_account_pk", + "columns": [ + "party_id", + "stellar_account" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.party_api_key": { + "name": "party_api_key", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "party_id": { + "name": "party_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "stellar_account": { + "name": "stellar_account", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "key_id": { + "name": "key_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "secret_ciphertext": { + "name": "secret_ciphertext", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'active'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "last_used_at": { + "name": "last_used_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "revoked_at": { + "name": "revoked_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "party_api_key_key_id_uq": { + "name": "party_api_key_key_id_uq", + "columns": [ + { + "expression": "key_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "party_api_key_party_id_party_id_fk": { + "name": "party_api_key_party_id_party_id_fk", + "tableFrom": "party_api_key", + "tableTo": "party", + "columnsFrom": [ + "party_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.payout_forward": { + "name": "payout_forward", + "schema": "", + "columns": { + "from_tx_hash": { + "name": "from_tx_hash", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "to_account": { + "name": "to_account", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "amount": { + "name": "amount", + "type": "numeric(32, 7)", + "primaryKey": false, + "notNull": true + }, + "memo": { + "name": "memo", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'claimed'" + }, + "tx_hash": { + "name": "tx_hash", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "ref_id": { + "name": "ref_id", + "type": "uuid", + "primaryKey": false, + "notNull": true, + "default": "gen_random_uuid()" + }, + "quote_id": { + "name": "quote_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pledge": { + "name": "pledge", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "credit_line_id": { + "name": "credit_line_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "asset_id": { + "name": "asset_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "units": { + "name": "units", + "type": "numeric(32, 7)", + "primaryKey": false, + "notNull": true + }, + "custody_mode": { + "name": "custody_mode", + "type": "custody_mode", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "contract_position_id": { + "name": "contract_position_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "lien_ref": { + "name": "lien_ref", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'active'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "pledge_credit_line_id_credit_line_id_fk": { + "name": "pledge_credit_line_id_credit_line_id_fk", + "tableFrom": "pledge", + "tableTo": "credit_line", + "columnsFrom": [ + "credit_line_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "pledge_asset_id_asset_id_fk": { + "name": "pledge_asset_id_asset_id_fk", + "tableFrom": "pledge", + "tableTo": "asset", + "columnsFrom": [ + "asset_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.price_observation": { + "name": "price_observation", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "asset_id": { + "name": "asset_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "value": { + "name": "value", + "type": "numeric(32, 7)", + "primaryKey": false, + "notNull": true + }, + "observed_at": { + "name": "observed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "signature": { + "name": "signature", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "stale": { + "name": "stale", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + } + }, + "indexes": { + "price_observation_asset_source_observed_uq": { + "name": "price_observation_asset_source_observed_uq", + "columns": [ + { + "expression": "asset_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "source", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "observed_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "price_observation_asset_id_asset_id_fk": { + "name": "price_observation_asset_id_asset_id_fk", + "tableFrom": "price_observation", + "tableTo": "asset", + "columnsFrom": [ + "asset_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.price_snapshot": { + "name": "price_snapshot", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "asset_id": { + "name": "asset_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "guarded_value": { + "name": "guarded_value", + "type": "numeric(32, 7)", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "sources": { + "name": "sources", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "ledger": { + "name": "ledger", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "price_snapshot_asset_id_asset_id_fk": { + "name": "price_snapshot_asset_id_asset_id_fk", + "tableFrom": "price_snapshot", + "tableTo": "asset", + "columnsFrom": [ + "asset_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.reconciliation_run": { + "name": "reconciliation_run", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "scope": { + "name": "scope", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "started_at": { + "name": "started_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "breaks": { + "name": "breaks", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "report": { + "name": "report", + "type": "jsonb", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.repayment": { + "name": "repayment", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "credit_line_id": { + "name": "credit_line_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "principal": { + "name": "principal", + "type": "numeric(32, 7)", + "primaryKey": false, + "notNull": true + }, + "interest": { + "name": "interest", + "type": "numeric(32, 7)", + "primaryKey": false, + "notNull": true + }, + "tx_hash": { + "name": "tx_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "ledger": { + "name": "ledger", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "repayment_credit_line_id_credit_line_id_fk": { + "name": "repayment_credit_line_id_credit_line_id_fk", + "tableFrom": "repayment", + "tableTo": "credit_line", + "columnsFrom": [ + "credit_line_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.repo_margin_call": { + "name": "repo_margin_call", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "trade_id": { + "name": "trade_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "amount": { + "name": "amount", + "type": "numeric(32, 7)", + "primaryKey": false, + "notNull": true + }, + "ccy": { + "name": "ccy", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "due_at": { + "name": "due_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "cured_at": { + "name": "cured_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "repo_margin_call_trade_id_repo_trade_id_fk": { + "name": "repo_margin_call_trade_id_repo_trade_id_fk", + "tableFrom": "repo_margin_call", + "tableTo": "repo_trade", + "columnsFrom": [ + "trade_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.repo_trade": { + "name": "repo_trade", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "cash_lender_id": { + "name": "cash_lender_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "cash_borrower_id": { + "name": "cash_borrower_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "asset_id": { + "name": "asset_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "units": { + "name": "units", + "type": "numeric(32, 7)", + "primaryKey": false, + "notNull": true + }, + "cash_amount": { + "name": "cash_amount", + "type": "numeric(32, 7)", + "primaryKey": false, + "notNull": true + }, + "rate_bps": { + "name": "rate_bps", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "repo_kind", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "start_ledger": { + "name": "start_ledger", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "maturity_at": { + "name": "maturity_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "agreement_hash": { + "name": "agreement_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'proposed'" + }, + "contract_trade_id": { + "name": "contract_trade_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "leg1_tx": { + "name": "leg1_tx", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "leg2_tx": { + "name": "leg2_tx", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "repo_trade_cash_lender_id_party_id_fk": { + "name": "repo_trade_cash_lender_id_party_id_fk", + "tableFrom": "repo_trade", + "tableTo": "party", + "columnsFrom": [ + "cash_lender_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "repo_trade_cash_borrower_id_party_id_fk": { + "name": "repo_trade_cash_borrower_id_party_id_fk", + "tableFrom": "repo_trade", + "tableTo": "party", + "columnsFrom": [ + "cash_borrower_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "repo_trade_asset_id_asset_id_fk": { + "name": "repo_trade_asset_id_asset_id_fk", + "tableFrom": "repo_trade", + "tableTo": "asset", + "columnsFrom": [ + "asset_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tx_intent": { + "name": "tx_intent", + "schema": "", + "columns": { + "tx_hash": { + "name": "tx_hash", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "ref_id": { + "name": "ref_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "party_id": { + "name": "party_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "payload": { + "name": "payload", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "ledger": { + "name": "ledger", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "error": { + "name": "error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "settled_at": { + "name": "settled_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "tx_intent_party_id_party_id_fk": { + "name": "tx_intent_party_id_party_id_fk", + "tableFrom": "tx_intent", + "tableTo": "party", + "columnsFrom": [ + "party_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.webhook_delivery": { + "name": "webhook_delivery", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "subscription_id": { + "name": "subscription_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "event_key": { + "name": "event_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "event": { + "name": "event", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "payload": { + "name": "payload", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "attempts": { + "name": "attempts", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "next_attempt_at": { + "name": "next_attempt_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "last_error": { + "name": "last_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "delivered_at": { + "name": "delivered_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "webhook_delivery_sub_event_uq": { + "name": "webhook_delivery_sub_event_uq", + "columns": [ + { + "expression": "subscription_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "event_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "webhook_delivery_subscription_id_webhook_subscription_id_fk": { + "name": "webhook_delivery_subscription_id_webhook_subscription_id_fk", + "tableFrom": "webhook_delivery", + "tableTo": "webhook_subscription", + "columnsFrom": [ + "subscription_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.webhook_subscription": { + "name": "webhook_subscription", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "party_id": { + "name": "party_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "url": { + "name": "url", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "events": { + "name": "events", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "secret_ciphertext": { + "name": "secret_ciphertext", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "active": { + "name": "active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "webhook_subscription_party_id_party_id_fk": { + "name": "webhook_subscription_party_id_party_id_fk", + "tableFrom": "webhook_subscription", + "tableTo": "party", + "columnsFrom": [ + "party_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": { + "public.asset_standard": { + "name": "asset_standard", + "schema": "public", + "values": [ + "classic_sac", + "sep57" + ] + }, + "public.custody_mode": { + "name": "custody_mode", + "schema": "public", + "values": [ + "escrow", + "issuer_lien", + "custodian_lien" + ] + }, + "public.liquidation_route": { + "name": "liquidation_route", + "schema": "public", + "values": [ + "redeem", + "transfer", + "rfq" + ] + }, + "public.party_kind": { + "name": "party_kind", + "schema": "public", + "values": [ + "borrower", + "lender", + "holder", + "issuer", + "custodian", + "keeper" + ] + }, + "public.repo_kind": { + "name": "repo_kind", + "schema": "public", + "values": [ + "intraday", + "overnight", + "open", + "term" + ] + }, + "public.yield_type": { + "name": "yield_type", + "schema": "public", + "values": [ + "accumulating", + "distributing" + ] + } + }, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/packages/db/migrations/meta/_journal.json b/packages/db/migrations/meta/_journal.json index a72ecac..3fbe4d9 100644 --- a/packages/db/migrations/meta/_journal.json +++ b/packages/db/migrations/meta/_journal.json @@ -92,6 +92,13 @@ "when": 1792783874569, "tag": "0012_payout_forward_booking", "breakpoints": true + }, + { + "idx": 13, + "version": "7", + "when": 1792888316412, + "tag": "0013_chain_event_gap", + "breakpoints": true } ] } \ No newline at end of file diff --git a/packages/db/src/schema.ts b/packages/db/src/schema.ts index f78227f..0687ead 100644 --- a/packages/db/src/schema.ts +++ b/packages/db/src/schema.ts @@ -355,6 +355,22 @@ export const chainEvent = pgTable( (t) => [uniqueIndex("chain_event_event_id_uq").on(t.eventId)], ); +/** + * A detected gap in indexed ledgers (e.g. after an outage exceeding RPC retention). + * Stores the range of lost ledgers so a future backfill from the S3 data lake knows what to fetch. + */ +export const chainEventGap = pgTable( + "chain_event_gap", + { + id: uuid("id").primaryKey().defaultRandom(), + fromLedger: integer("from_ledger").notNull(), + toLedger: integer("to_ledger").notNull(), + detectedAt: timestamp("detected_at", { withTimezone: true }).notNull().defaultNow(), + status: text("status").notNull().default("open"), + }, + (t) => [uniqueIndex("chain_event_gap_range_uq").on(t.fromLedger, t.toLedger)], +); + /** Scanned-up-to cursor for the event indexer so quiet periods do not re-request already-scanned ledgers. */ export const indexerCursor = pgTable("indexer_cursor", { id: text("id").primaryKey(), diff --git a/services/indexer/src/poller.test.ts b/services/indexer/src/poller.test.ts index dcf5d88..7db99cb 100644 --- a/services/indexer/src/poller.test.ts +++ b/services/indexer/src/poller.test.ts @@ -327,6 +327,29 @@ describe("pollOnce", () => { expect(result.skippedTo).toBe(1199); expect(result.scannedUpTo).toBe(5000); }); + + it("records the lost ledger range in chain_event_gap", async () => { + const inserted: unknown[] = []; + const db = fakeDb({ lastLedger: 1000, inserted }); + const rpc = fakeRpc({ + getHealth: vi + .fn() + .mockResolvedValue({ latestLedger: 5000, oldestLedger: 1200, ledgerRetentionWindow: 120960 }), + }); + + await pollOnce(db, rpc, ["CCONTRACT1"]); + + expect(inserted).toEqual([{ fromLedger: 1001, toLedger: 1199 }]); + }); + + it("records no gap when the resume cursor is still within RPC retention", async () => { + const inserted: unknown[] = []; + const db = fakeDb({ lastLedger: 1000, inserted }); + + await pollOnce(db, fakeRpc(), ["CCONTRACT1"]); + + expect(inserted).toEqual([]); + }); }); describe("computeRpcLag", () => { diff --git a/services/indexer/src/poller.ts b/services/indexer/src/poller.ts index c415d0f..be22ae9 100644 --- a/services/indexer/src/poller.ts +++ b/services/indexer/src/poller.ts @@ -124,7 +124,8 @@ export function computeRpcLag( * The resume cursor can fall outside the RPC's retention window when the indexer has been idle * longer than the node keeps history. `getEvents` rejects that `startLedger` outright, so the * cursor would never advance. We clamp it to the oldest ledger the node still has and report the - * skipped range; those events are gone and the caller must surface the gap. + * skipped range and record it in `chain_event_gap`; those events are gone and the caller must + * surface the gap. */ export async function pollOnce( db: Database, @@ -156,6 +157,12 @@ export async function pollOnce( from: String(skippedFrom), to: String(skippedTo), }); + // Keep the lost range for a later backfill from the data lake. The unique range index makes a + // retried cycle (e.g. `getEvents` failing after this point) record it only once. + await db + .insert(schema.chainEventGap) + .values({ fromLedger: skippedFrom, toLedger: skippedTo }) + .onConflictDoNothing(); } // Drain every page before returning. The next poll resumes from `max(ledger) + 1`, so stopping