delphi.market/init.sql
ekzyis 7094438152 Use cost function
With this cost function, buying and selling is a lot easier since it uses the same function.

Also, shares are now always integers which is also easier to grasp.

Reference: http://blog.oddhead.com/2006/10/30/implementing-hansons-market-maker/
2023-09-09 22:52:50 +02:00

38 lines
1.1 KiB
SQL

CREATE TABLE lnauth(
k1 VARCHAR(64) NOT NULL PRIMARY KEY,
lnurl TEXT NOT NULL,
created TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
session_id VARCHAR(48) NOT NULL DEFAULT encode(gen_random_uuid()::text::bytea, 'base64')
);
CREATE TABLE users(
pubkey TEXT PRIMARY KEY,
last_seen TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE sessions(
pubkey TEXT NOT NULL REFERENCES users(pubkey),
session_id VARCHAR(48)
);
CREATE TABLE markets(
id SERIAL PRIMARY KEY,
description TEXT NOT NULL,
funding BIGINT NOT NULL,
active BOOLEAN DEFAULT true
);
CREATE EXTENSION "uuid-ossp";
CREATE TABLE shares(
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
market_id INTEGER REFERENCES markets(id),
description TEXT NOT NULL,
quantity BIGINT NOT NULL DEFAULT 0
);
CREATE TYPE order_side AS ENUM ('BUY', 'SELL');
CREATE TABLE trades(
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
share_id UUID NOT NULL REFERENCES shares(id),
pubkey TEXT NOT NULL REFERENCES users(pubkey),
side ORDER_SIDE NOT NULL,
quantity BIGINT NOT NULL,
msats BIGINT NOT NULL
);