Skip to content

Commit

Permalink
update database
Browse files Browse the repository at this point in the history
  • Loading branch information
fhenneke committed Jan 15, 2024
1 parent fe9e5aa commit 6cea067
Showing 1 changed file with 50 additions and 10 deletions.
60 changes: 50 additions & 10 deletions populate_test_db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ DROP TABLE IF EXISTS auction_transaction;
DROP TABLE IF EXISTS auction_participants;
DROP TABLE IF EXISTS settlement_scores;
DROP TABLE IF EXISTS settlement_observations;
DROP TABLE IF EXISTS auction_prices;
DROP TABLE IF EXISTS orders;
DROP TYPE IF EXISTS OrderKind;
DROP TYPE IF EXISTS SigningScheme;
DROP TYPE IF EXISTS TokenBalance;
DROP TYPE IF EXISTS OrderClass;
DROP TABLE IF EXISTS order_quotes;
DROP TABLE IF EXISTS trades;
DROP TABLE IF EXISTS order_executions;
DROP TABLE IF EXISTS fee_policies;
DROP TYPE IF EXISTS PolicyKind;

Expand Down Expand Up @@ -64,6 +66,15 @@ CREATE TABLE IF NOT EXISTS settlement_observations
PRIMARY KEY (block_number, log_index)
);

CREATE TABLE IF NOT EXISTS auction_prices
(
auction_id bigint NOT NULL,
token bytea NOT NULL,
price numeric(78, 0) NOT NULL,

PRIMARY KEY (auction_id, token)
);

-- orders table
CREATE TYPE OrderKind AS ENUM ('buy', 'sell');
CREATE TYPE SigningScheme AS ENUM ('presign', 'eip712', 'ethsign');
Expand Down Expand Up @@ -117,6 +128,17 @@ CREATE TABLE IF NOT EXISTS trades
PRIMARY KEY (block_number, log_index)
);

CREATE TABLE IF NOT EXISTS order_executions
(
order_uid bytea NOT NULL,
auction_id bigint NOT NULL,
reward double precision NOT NULL,
surplus_fee numeric(78, 0) NOT NULL,
solver_fee numeric(78, 0),

PRIMARY KEY (order_uid, auction_id)
);

CREATE TYPE PolicyKind AS ENUM ('priceimprovement', 'volume');

CREATE TABLE fee_policies (
Expand All @@ -140,6 +162,7 @@ TRUNCATE auction_transaction;
TRUNCATE auction_participants;
TRUNCATE settlement_scores;
TRUNCATE settlement_observations;
TRUNCATE auction_prices;
TRUNCATE orders;
TRUNCATE order_quotes;
TRUNCATE trades;
Expand Down Expand Up @@ -210,19 +233,30 @@ VALUES (1, 10, 100000, 2000000000, 6000000000000000000, 200000000000000),
(25, 10, 100000, 2000000000, 6000000000000000000, 200000000000000),
(26, 10, 100000, 2000000000, 0, 400000000000000);


INSERT INTO auction_prices (auction_id, token, price)
VALUES (1, '\x11', 1000000000000000000),
(1, '\x22', 1200000000000000000),
(2, '\x11', 1000000000000000000),
(2, '\x22', 1200000000000000000),
(5, '\x11', 1000000000000000000),
(5, '\x22', 1200000000000000000),
(6, '\x11', 1000000000000000000),
(6, '\x22', 1200000000000000000);

INSERT INTO orders (uid, owner, creation_timestamp, sell_token, buy_token, sell_amount, buy_amount, valid_to, fee_amount, kind, partially_fillable, signature, cancellation_timestamp, receiver, app_data, signing_scheme, settlement_contract, sell_token_balance, buy_token_balance, full_fee_amount, class)
VALUES ('\x1111'::bytea, '\x1111111111'::bytea, '2024-01-01 00:00:00.000000+00
', '\x11'::bytea, '\x22'::bytea, 6000000000000000000, 4000000000000000000, 1700000000, 200000000000000000, 'sell', 'f', '\x987987987987'::bytea, NULL, '\x12341234'::bytea, '\x1234512345'::bytea, 'presign', '\x123456123456'::bytea, 'erc20', 'external', 200000000000000000, 'market'), -- sell market order
', '\x11'::bytea, '\x22'::bytea, 6000000000000000000, 4000000000000000000, 1700000000, 20000000000000000, 'sell', 'f', '\x987987987987'::bytea, NULL, '\x12341234'::bytea, '\x1234512345'::bytea, 'presign', '\x123456123456'::bytea, 'erc20', 'external', 20000000000000000, 'market'), -- sell market order
('\x2222'::bytea, '\x1111111111'::bytea, '2024-01-01 00:00:00.000000+00
', '\x11'::bytea, '\x22'::bytea, 6000000000000000000, 4000000000000000000, 1700000000, 200000000000000000, 'buy', 'f', '\x987987987987'::bytea, NULL, '\x12341234'::bytea, '\x1234512345'::bytea, 'presign', '\x123456123456'::bytea, 'erc20', 'external', 200000000000000000, 'market'), -- buy market order
', '\x11'::bytea, '\x22'::bytea, 6000000000000000000, 4000000000000000000, 1700000000, 20000000000000000, 'buy', 'f', '\x987987987987'::bytea, NULL, '\x12341234'::bytea, '\x1234512345'::bytea, 'presign', '\x123456123456'::bytea, 'erc20', 'external', 20000000000000000, 'market'), -- buy market order
('\x3333'::bytea, '\x1111111111'::bytea, '2024-01-01 00:00:00.000000+00
', '\x11'::bytea, '\x22'::bytea, 6200000000000000000, 4000000000000000000, 1700000000, 0, 'sell', 't', '\x987987987987'::bytea, NULL, '\x12341234'::bytea, '\x1234512345'::bytea, 'presign', '\x123456123456'::bytea, 'erc20', 'external', 0, 'limit'), -- partially fillable sell limit order
', '\x11'::bytea, '\x22'::bytea, 6020000000000000000, 4000000000000000000, 1700000000, 0, 'sell', 't', '\x987987987987'::bytea, NULL, '\x12341234'::bytea, '\x1234512345'::bytea, 'presign', '\x123456123456'::bytea, 'erc20', 'external', 0, 'limit'), -- partially fillable sell limit order
('\x4444'::bytea, '\x1111111111'::bytea, '2024-01-01 00:00:00.000000+00
', '\x11'::bytea, '\x22'::bytea, 6200000000000000000, 4000000000000000000, 1700000000, 0, 'buy', 't', '\x987987987987'::bytea, NULL, '\x12341234'::bytea, '\x1234512345'::bytea, 'presign', '\x123456123456'::bytea, 'erc20', 'external', 0, 'limit'), -- partially fillable buy limit order
', '\x11'::bytea, '\x22'::bytea, 6020000000000000000, 4000000000000000000, 1700000000, 0, 'buy', 't', '\x987987987987'::bytea, NULL, '\x12341234'::bytea, '\x1234512345'::bytea, 'presign', '\x123456123456'::bytea, 'erc20', 'external', 0, 'limit'), -- partially fillable buy limit order
('\x5555'::bytea, '\x1111111111'::bytea, '2024-01-01 00:00:00.000000+00
', '\x11'::bytea, '\x22'::bytea, 6200000000000000000, 4000000000000000000, 1700000000, 0, 'sell', 'f', '\x987987987987'::bytea, NULL, '\x12341234'::bytea, '\x1234512345'::bytea, 'presign', '\x123456123456'::bytea, 'erc20', 'external', 0, 'limit'), -- in market sell limit order
', '\x11'::bytea, '\x22'::bytea, 6020000000000000000, 4000000000000000000, 1700000000, 0, 'sell', 'f', '\x987987987987'::bytea, NULL, '\x12341234'::bytea, '\x1234512345'::bytea, 'presign', '\x123456123456'::bytea, 'erc20', 'external', 0, 'limit'), -- in market sell limit order
('\x6666'::bytea, '\x1111111111'::bytea, '2024-01-01 00:00:00.000000+00
', '\x11'::bytea, '\x22'::bytea, 6200000000000000000, 4000000000000000000, 1700000000, 0, 'buy', 'f', '\x987987987987'::bytea, NULL, '\x12341234'::bytea, '\x1234512345'::bytea, 'presign', '\x123456123456'::bytea, 'erc20', 'external', 0, 'limit'); -- in market buy limit order
', '\x11'::bytea, '\x22'::bytea, 6020000000000000000, 4000000000000000000, 1700000000, 0, 'buy', 'f', '\x987987987987'::bytea, NULL, '\x12341234'::bytea, '\x1234512345'::bytea, 'presign', '\x123456123456'::bytea, 'erc20', 'external', 0, 'limit'); -- in market buy limit order

INSERT INTO order_quotes (order_uid, gas_amount, gas_price, sell_token_price, sell_amount, buy_amount, solver)
VALUES ('\x1111'::bytea, 200000, 100000000000, 0.123, 6000000000000000000, 4500000000000000000, '\x5111111111111111111111111111111111111111'::bytea),
Expand All @@ -233,13 +267,19 @@ VALUES ('\x1111'::bytea, 200000, 100000000000, 0.123, 6000000000000000000, 45000
('\x6666'::bytea, 200000, 100000000000, 0.123, 5500000000000000000, 4000000000000000000, '\x5444444444444444444444444444444444444444'::bytea);

INSERT INTO trades (block_number, log_index, order_uid, sell_amount, buy_amount, fee_amount)
VALUES (1, 0, '\x1111'::bytea, 6200000000000000000, 4600000000000000000, 200000000000000000),
(2, 0, '\x2222'::bytea, 5600000000000000000, 4000000000000000000, 200000000000000000),
(2, 1, '\x3333'::bytea, 6200000000000000000, 4600000000000000000, 0),
VALUES (1, 0, '\x1111'::bytea, 6020000000000000000, 4600000000000000000, 20000000000000000),
(2, 0, '\x2222'::bytea, 5600000000000000000, 4000000000000000000, 20000000000000000),
(2, 1, '\x3333'::bytea, 6020000000000000000, 4600000000000000000, 0),
(5, 0, '\x4444'::bytea, 5600000000000000000, 4000000000000000000, 0),
(5, 1, '\x5555'::bytea, 6200000000000000000, 4600000000000000000, 0),
(5, 1, '\x5555'::bytea, 6020000000000000000, 4600000000000000000, 0),
(20, 0, '\x6666'::bytea, 5600000000000000000, 4000000000000000000, 0);

INSERT INTO order_executions (order_uid, auction_id, reward, surplus_fee, solver_fee)
VALUES ('\x3333'::bytea, 2, 0, 66464646464646470, NULL),
('\x4444'::bytea, 5, 0, 125000000000000000, NULL),
('\x5555'::bytea, 5, 0, 29043565348022034, NULL),
('\x6666'::bytea, 6, 0, 20000000000000000, NULL);

INSERT INTO fee_policies (auction_id, order_uid, application_order, kind, price_improvement_factor, max_volume_factor, volume_factor)
VALUES (2, '\x3333'::bytea, 3, 'priceimprovement', 0.5, 0.01, NULL),
(5, '\x4444'::bytea, 4, 'priceimprovement', 0.2, 0.1, NULL),
Expand Down

0 comments on commit 6cea067

Please sign in to comment.