Skip to content

Commit

Permalink
Merge pull request #6769 from ethereum-optimism/08-12-feat_indexer_Ad…
Browse files Browse the repository at this point in the history
…d_tokens_to_the_db_schema

feat(indexer): Add tokens to the db schema
  • Loading branch information
OptimismBot authored Aug 16, 2023
2 parents f20b8e6 + 00029a2 commit 3ec8337
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
1 change: 1 addition & 0 deletions indexer/database/bridge_transfers.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ l1_bridge_deposits.*,
l1_contract_events.transaction_hash AS l1_transaction_hash,
l1_transaction_deposits.l2_transaction_hash`)

// TODO join with l1_tokens and l2_tokens
depositsQuery = depositsQuery.Joins("INNER JOIN l1_transaction_deposits ON l1_bridge_deposits.transaction_source_hash = l1_transaction_deposits.source_hash")
depositsQuery = depositsQuery.Joins("INNER JOIN l1_contract_events ON l1_transaction_deposits.initiated_l1_event_guid = l1_contract_events.guid")

Expand Down
33 changes: 29 additions & 4 deletions indexer/migrations/20230523_create_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,31 @@ CREATE TABLE IF NOT EXISTS output_proposals (
* BRIDGING DATA
*/

/**
* TOKEN DATA
*/

-- L1 Token table
CREATE TABLE IF NOT EXISTS l1_tokens (
address VARCHAR PRIMARY KEY,
bridge_address VARCHAR NOT NULL,
l2_token_address VARCHAR NOT NULL,
name VARCHAR NOT NULL,
symbol VARCHAR NOT NULL,
decimals INTEGER NOT NULL CHECK (decimals >= 0 AND decimals <= 18)
);

-- L2 Token table
CREATE TABLE IF NOT EXISTS l2_tokens (
address VARCHAR PRIMARY KEY,
bridge_address VARCHAR NOT NULL,
l1_token_address VARCHAR REFERENCES l1_tokens(address),
name VARCHAR NOT NULL,
symbol VARCHAR NOT NULL,
decimals INTEGER NOT NULL CHECK (decimals >= 0 AND decimals <= 18)
);


-- OptimismPortal/L2ToL1MessagePasser
CREATE TABLE IF NOT EXISTS l1_transaction_deposits (
source_hash VARCHAR NOT NULL PRIMARY KEY,
Expand Down Expand Up @@ -170,8 +195,8 @@ CREATE TABLE IF NOT EXISTS l1_bridge_deposits (
-- Deposit information
from_address VARCHAR NOT NULL,
to_address VARCHAR NOT NULL,
l1_token_address VARCHAR NOT NULL,
l2_token_address VARCHAR NOT NULL,
l1_token_address VARCHAR NOT NULL, -- REFERENCES l1_tokens(address), uncomment me in future pr
l2_token_address VARCHAR NOT NULL, -- REFERENCES l2_tokens(address), uncomment me in future pr
amount UINT256 NOT NULL,
data VARCHAR NOT NULL,
timestamp INTEGER NOT NULL CHECK (timestamp > 0)
Expand All @@ -186,8 +211,8 @@ CREATE TABLE IF NOT EXISTS l2_bridge_withdrawals (
-- Withdrawal information
from_address VARCHAR NOT NULL,
to_address VARCHAR NOT NULL,
l1_token_address VARCHAR NOT NULL,
l2_token_address VARCHAR NOT NULL,
l1_token_address VARCHAR NOT NULL, -- REFERENCES l1_tokens(address), uncomment me in future pr
l2_token_address VARCHAR NOT NULL, -- REFERENCES l2_tokens(address), uncomment me in future pr
amount UINT256 NOT NULL,
data VARCHAR NOT NULL,
timestamp INTEGER NOT NULL CHECK (timestamp > 0)
Expand Down

0 comments on commit 3ec8337

Please sign in to comment.