You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

129 lines
3.9 KiB

  1. -- +migrate Up
  2. CREATE TABLE block (
  3. eth_block_num BIGINT PRIMARY KEY,
  4. timestamp TIMESTAMP WITHOUT TIME ZONE NOT NULL,
  5. hash BYTEA NOT NULL
  6. );
  7. CREATE TABLE coordianator (
  8. forger_addr BYTEA NOT NULL,
  9. eth_block_num BIGINT NOT NULL REFERENCES block (eth_block_num) ON DELETE CASCADE,
  10. withdraw_addr BYTEA NOT NULL,
  11. url VARCHAR(200) NOT NULL,
  12. PRIMARY KEY (forger_addr, eth_block_num)
  13. );
  14. CREATE TABLE batch (
  15. batch_num BIGINT PRIMARY KEY,
  16. eth_block_num BIGINT REFERENCES block (eth_block_num) ON DELETE CASCADE,
  17. forger_addr BYTEA NOT NULL, -- fake foreign key for coordinator
  18. fees_collected BYTEA NOT NULL,
  19. state_root BYTEA NOT NULL,
  20. num_accounts BIGINT NOT NULL,
  21. exit_root BYTEA NOT NULL,
  22. forge_l1_txs_num BIGINT,
  23. slot_num BIGINT NOT NULL
  24. );
  25. CREATE TABLE exit_tree (
  26. batch_num BIGINT REFERENCES batch (batch_num) ON DELETE CASCADE,
  27. account_idx BIGINT,
  28. merkle_proof BYTEA NOT NULL,
  29. balance NUMERIC NOT NULL,
  30. nullifier BYTEA NOT NULL,
  31. PRIMARY KEY (batch_num, account_idx)
  32. );
  33. CREATE TABLE withdrawal (
  34. batch_num BIGINT,
  35. account_idx BIGINT,
  36. eth_block_num BIGINT REFERENCES block (eth_block_num) ON DELETE CASCADE,
  37. FOREIGN KEY (batch_num, account_idx) REFERENCES exit_tree (batch_num, account_idx) ON DELETE CASCADE,
  38. PRIMARY KEY (batch_num, account_idx)
  39. );
  40. CREATE TABLE bid (
  41. slot_num BIGINT NOT NULL,
  42. bid_value BYTEA NOT NULL, -- (check if we can do a max(), if not add float for order purposes)
  43. eth_block_num BIGINT NOT NULL REFERENCES block (eth_block_num) ON DELETE CASCADE,
  44. forger_addr BYTEA NOT NULL, -- fake foreign key for coordinator
  45. PRIMARY KEY (slot_num, bid_value)
  46. );
  47. CREATE TABLE token (
  48. token_id INT PRIMARY KEY,
  49. eth_block_num BIGINT NOT NULL REFERENCES block (eth_block_num) ON DELETE CASCADE,
  50. eth_addr BYTEA UNIQUE NOT NULL,
  51. name VARCHAR(20) NOT NULL,
  52. symbol VARCHAR(10) NOT NULL,
  53. decimals INT NOT NULL
  54. );
  55. CREATE TABLE l1tx (
  56. tx_id BYTEA PRIMARY KEY,
  57. to_forge_l1_txs_num BIGINT NOT NULL,
  58. position INT NOT NULL,
  59. user_origin BOOLEAN NOT NULL,
  60. from_idx BIGINT NOT NULL,
  61. from_eth_addr BYTEA NOT NULL,
  62. from_bjj BYTEA NOT NULL,
  63. to_idx BIGINT NOT NULL,
  64. token_id INT NOT NULL REFERENCES token (token_id),
  65. amount NUMERIC NOT NULL,
  66. load_amount BYTEA NOT NULL,
  67. eth_block_num BIGINT NOT NULL REFERENCES block (eth_block_num) ON DELETE CASCADE,
  68. tx_type VARCHAR(40) NOT NULL
  69. );
  70. CREATE TABLE l2tx (
  71. tx_id BYTEA PRIMARY KEY,
  72. batch_num BIGINT NOT NULL REFERENCES batch (batch_num) ON DELETE CASCADE,
  73. position INT NOT NULL,
  74. from_idx BIGINT NOT NULL,
  75. to_idx BIGINT NOT NULL,
  76. amount NUMERIC NOT NULL,
  77. fee INT NOT NULL,
  78. nonce BIGINT NOT NULL,
  79. tx_type VARCHAR(40) NOT NULL
  80. );
  81. CREATE TABLE account (
  82. idx BIGINT PRIMARY KEY,
  83. token_id INT NOT NULL REFERENCES token (token_id),
  84. batch_num BIGINT NOT NULL REFERENCES batch (batch_num) ON DELETE CASCADE,
  85. bjj BYTEA NOT NULL,
  86. eth_addr BYTEA NOT NULL
  87. );
  88. CREATE TABLE rollup_vars (
  89. eth_block_num BIGINT PRIMARY KEY REFERENCES block (eth_block_num) ON DELETE CASCADE,
  90. forge_l1_timeout BYTEA NOT NULL,
  91. fee_l1_user_tx BYTEA NOT NULL,
  92. fee_add_token BYTEA NOT NULL,
  93. tokens_hez BYTEA NOT NULL,
  94. governance BYTEA NOT NULL
  95. );
  96. CREATE TABLE consensus_vars (
  97. eth_block_num BIGINT PRIMARY KEY REFERENCES block (eth_block_num) ON DELETE CASCADE,
  98. slot_deadline INT NOT NULL,
  99. close_auction_slots INT NOT NULL,
  100. open_auction_slots INT NOT NULL,
  101. min_bid_slots VARCHAR(200) NOT NULL,
  102. outbidding INT NOT NULL,
  103. donation_address BYTEA NOT NULL,
  104. governance_address BYTEA NOT NULL,
  105. allocation_ratio vARCHAR(200)
  106. );
  107. -- +migrate Down
  108. DROP TABLE consensus_vars;
  109. DROP TABLE rollup_vars;
  110. DROP TABLE account;
  111. DROP TABLE l2tx;
  112. DROP TABLE l1tx;
  113. DROP TABLE token;
  114. DROP TABLE bid;
  115. DROP TABLE exit_tree;
  116. DROP TABLE batch;
  117. DROP TABLE coordianator;
  118. DROP TABLE block;