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.

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