CREATE TABLE IF NOT EXISTS tx (
  id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
  tx_hash VARCHAR(66) NOT NULL UNIQUE,
  block_number INT NOT NULL,
  date_block TIMESTAMP NOT NULL,
  success BOOLEAN NOT NULL
);

CREATE TABLE IF NOT EXISTS token_transfer (
  id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
  tx_id INT REFERENCES tx(id),
  sender_address VARCHAR(42) NOT NULL,
  recipient_address VARCHAR(42) NOT NULL,
  contract_address VARCHAR(42) NOT NULL DEFAULT '0x0000000000000000000000000000000000000000',
  transfer_value NUMERIC NOT NULL
);

CREATE TABLE IF NOT EXISTS token_mint (
  id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
  tx_id INT REFERENCES tx(id),
  minter_address VARCHAR(42) NOT NULL,
  recipient_address VARCHAR(42) NOT NULL,
  contract_address VARCHAR(42) NOT NULL DEFAULT '0x0000000000000000000000000000000000000000',
  mint_value NUMERIC NOT NULL
);

CREATE TABLE IF NOT EXISTS token_burn (
  id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
  tx_id INT REFERENCES tx(id),
  burner_address VARCHAR(42) NOT NULL,
  contract_address VARCHAR(42) NOT NULL DEFAULT '0x0000000000000000000000000000000000000000',
  burn_value NUMERIC NOT NULL
);

CREATE TABLE IF NOT EXISTS faucet_give (
  id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
  tx_id INT REFERENCES tx(id),
  token_address VARCHAR(42) NOT NULL,
  recipient_address VARCHAR(42) NOT NULL,
  contract_address VARCHAR(42) NOT NULL DEFAULT '0x0000000000000000000000000000000000000000',
  give_value NUMERIC NOT NULL

);

CREATE TABLE IF NOT EXISTS pool_swap (
  id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
  tx_id INT REFERENCES tx(id),
  initiator_address VARCHAR(42) NOT NULL,
  token_in_address VARCHAR(42) NOT NULL,
  token_out_address VARCHAR(42) NOT NULL,
  in_value NUMERIC NOT NULL,
  out_value NUMERIC NOT NULL,
  contract_address VARCHAR(42) NOT NULL DEFAULT '0x0000000000000000000000000000000000000000',
  fee NUMERIC NOT NULL
);

CREATE TABLE IF NOT EXISTS pool_deposit (
  id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
  tx_id INT REFERENCES tx(id),
  initiator_address VARCHAR(42) NOT NULL,
  token_in_address VARCHAR(42) NOT NULL,
  contract_address VARCHAR(42) NOT NULL DEFAULT '0x0000000000000000000000000000000000000000',
  in_value NUMERIC NOT NULL
);

CREATE TABLE IF NOT EXISTS tokens (
  id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
  contract_address VARCHAR(42) NOT NULL DEFAULT '0x0000000000000000000000000000000000000000',
  token_name TEXT NOT NULL,
  token_symbol TEXT NOT NULL,
  token_decimals INT NOT NULL,
  sink_address VARCHAR(42) NOT NULL DEFAULT '0x0000000000000000000000000000000000000000'
);

CREATE TABLE IF NOT EXISTS pools (
  id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
  contract_address VARCHAR(42) NOT NULL DEFAULT '0x0000000000000000000000000000000000000000',
  pool_name TEXT NOT NULL,
  pool_symbol TEXT NOT NULL
);