diff --git a/crawlers/deploy/deploy-basic.bash b/crawlers/deploy/deploy-basic.bash index 943edd9b..a3303ff1 100755 --- a/crawlers/deploy/deploy-basic.bash +++ b/crawlers/deploy/deploy-basic.bash @@ -148,6 +148,8 @@ if [ ! -d "${SECRETS_DIR}" ]; then echo -e "${PREFIX_WARN} Created new secrets directory" fi AWS_DEFAULT_REGION="${AWS_DEFAULT_REGION}" CHECKENV_AWS_FETCH_LOOP_LIMIT=20 /home/ubuntu/go/bin/checkenv show aws_ssm+moonstream:true > "${PARAMETERS_ENV_PATH}" +MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS_CRAWLERS=$(AWS_DEFAULT_REGION="${AWS_DEFAULT_REGION}" aws ssm get-parameter --name "MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS_CRAWLERS" --output text --query Parameter.Value) +echo "MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS=$MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS_CRAWLERS" >> "${PARAMETERS_ENV_PATH}" chmod 0640 "${PARAMETERS_ENV_PATH}" echo diff --git a/crawlers/deploy/deploy-historical.bash b/crawlers/deploy/deploy-historical.bash index 05ec2f98..d27acc2f 100755 --- a/crawlers/deploy/deploy-historical.bash +++ b/crawlers/deploy/deploy-historical.bash @@ -121,6 +121,8 @@ if [ ! -d "${SECRETS_DIR}" ]; then echo -e "${PREFIX_WARN} Created new secrets directory" fi AWS_DEFAULT_REGION="${AWS_DEFAULT_REGION}" CHECKENV_AWS_FETCH_LOOP_LIMIT=20 /home/ubuntu/go/bin/checkenv show aws_ssm+moonstream:true > "${PARAMETERS_ENV_PATH}" +MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS_CRAWLERS=$(AWS_DEFAULT_REGION="${AWS_DEFAULT_REGION}" aws ssm get-parameter --name "MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS_CRAWLERS" --output text --query Parameter.Value) +echo "MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS=$MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS_CRAWLERS" >> "${PARAMETERS_ENV_PATH}" chmod 0640 "${PARAMETERS_ENV_PATH}" echo diff --git a/crawlers/deploy/deploy-moonworm.bash b/crawlers/deploy/deploy-moonworm.bash index e84f0167..e37949ca 100755 --- a/crawlers/deploy/deploy-moonworm.bash +++ b/crawlers/deploy/deploy-moonworm.bash @@ -69,6 +69,8 @@ if [ ! -d "${SECRETS_DIR}" ]; then echo -e "${PREFIX_WARN} Created new secrets directory" fi AWS_DEFAULT_REGION="${AWS_DEFAULT_REGION}" CHECKENV_AWS_FETCH_LOOP_LIMIT=20 /home/ubuntu/go/bin/checkenv show aws_ssm+moonstream:true > "${PARAMETERS_ENV_PATH}" +MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS_CRAWLERS=$(AWS_DEFAULT_REGION="${AWS_DEFAULT_REGION}" aws ssm get-parameter --name "MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS_CRAWLERS" --output text --query Parameter.Value) +echo "MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS=$MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS_CRAWLERS" >> "${PARAMETERS_ENV_PATH}" chmod 0640 "${PARAMETERS_ENV_PATH}" echo diff --git a/crawlers/deploy/deploy-state.bash b/crawlers/deploy/deploy-state.bash index 3e419372..78818e25 100755 --- a/crawlers/deploy/deploy-state.bash +++ b/crawlers/deploy/deploy-state.bash @@ -88,6 +88,8 @@ if [ ! -d "${SECRETS_DIR}" ]; then echo -e "${PREFIX_WARN} Created new secrets directory" fi AWS_DEFAULT_REGION="${AWS_DEFAULT_REGION}" CHECKENV_AWS_FETCH_LOOP_LIMIT=20 /home/ubuntu/go/bin/checkenv show aws_ssm+moonstream:true > "${PARAMETERS_ENV_PATH}" +MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS_CRAWLERS=$(AWS_DEFAULT_REGION="${AWS_DEFAULT_REGION}" aws ssm get-parameter --name "MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS_CRAWLERS" --output text --query Parameter.Value) +echo "MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS=$MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS_CRAWLERS" >> "${PARAMETERS_ENV_PATH}" chmod 0640 "${PARAMETERS_ENV_PATH}" echo diff --git a/crawlers/deploy/deploy.bash b/crawlers/deploy/deploy.bash index b35ebfad..17c315c9 100755 --- a/crawlers/deploy/deploy.bash +++ b/crawlers/deploy/deploy.bash @@ -242,6 +242,8 @@ if [ ! -d "${SECRETS_DIR}" ]; then echo -e "${PREFIX_WARN} Created new secrets directory" fi AWS_DEFAULT_REGION="${AWS_DEFAULT_REGION}" CHECKENV_AWS_FETCH_LOOP_LIMIT=20 /home/ubuntu/go/bin/checkenv show aws_ssm+moonstream:true > "${PARAMETERS_ENV_PATH}" +MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS_CRAWLERS=$(AWS_DEFAULT_REGION="${AWS_DEFAULT_REGION}" aws ssm get-parameter --name "MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS_CRAWLERS" --output text --query Parameter.Value) +echo "MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS=$MOONSTREAM_DB_STATEMENT_TIMEOUT_MILLIS_CRAWLERS" >> "${PARAMETERS_ENV_PATH}" chmod 0640 "${PARAMETERS_ENV_PATH}" echo diff --git a/moonstreamapi/configs/sample.env b/moonstreamapi/configs/sample.env index 560cfeaa..61cd69ff 100644 --- a/moonstreamapi/configs/sample.env +++ b/moonstreamapi/configs/sample.env @@ -40,6 +40,8 @@ export MOONSTREAM_MANTLE_SEPOLIA_WEB3_PROVIDER_URI="https://=0.4.5", - "moonstreamdb-v3>=0.0.16", + "moonstreamdb-v3>=0.0.18", "humbug", "pydantic==1.10.2", "pyevmasm", diff --git a/moonstreamdb-v3/moonstreamdbv3/alembic/env.py b/moonstreamdb-v3/moonstreamdbv3/alembic/env.py index 966d697a..d4e6837a 100644 --- a/moonstreamdb-v3/moonstreamdbv3/alembic/env.py +++ b/moonstreamdb-v3/moonstreamdbv3/alembic/env.py @@ -31,6 +31,8 @@ from moonstreamdbv3.models import ( ArbitrumSepoliaLabel, AvalancheFujiLabel, AvalancheLabel, + B3Label, + B3SepoliaLabel, BaseLabel, BlastLabel, BlastSepoliaLabel, @@ -84,6 +86,8 @@ def include_symbol(tablename, schema): MantleSepoliaLabel.__tablename__, ImxZkevmLabel.__tablename__, ImxZkevmSepoliaLabel.__tablename__, + B3Label.__tablename__, + B3SepoliaLabel.__tablename__, } diff --git a/moonstreamdb-v3/moonstreamdbv3/alembic/versions/1d53afc1eff4_add_b3.py b/moonstreamdb-v3/moonstreamdbv3/alembic/versions/1d53afc1eff4_add_b3.py new file mode 100644 index 00000000..7145b4b6 --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/alembic/versions/1d53afc1eff4_add_b3.py @@ -0,0 +1,307 @@ +"""add-b3 + +Revision ID: 1d53afc1eff4 +Revises: db9559f9566c +Create Date: 2024-09-11 14:19:12.762655 + +""" + +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects import postgresql + +# revision identifiers, used by Alembic. +revision: str = "1d53afc1eff4" +down_revision: Union[str, None] = "db9559f9566c" +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.create_table( + "b3_labels", + sa.Column("id", sa.UUID(), nullable=False), + sa.Column("label", sa.VARCHAR(length=256), nullable=False), + sa.Column("transaction_hash", sa.VARCHAR(length=128), nullable=False), + sa.Column("log_index", sa.Integer(), nullable=True), + sa.Column("block_number", sa.BigInteger(), nullable=False), + sa.Column("block_hash", sa.VARCHAR(length=256), nullable=False), + sa.Column("block_timestamp", sa.BigInteger(), nullable=False), + sa.Column("caller_address", sa.LargeBinary(), nullable=True), + sa.Column("origin_address", sa.LargeBinary(), nullable=True), + sa.Column("address", sa.LargeBinary(), nullable=False), + sa.Column("label_name", sa.Text(), nullable=True), + sa.Column("label_type", sa.VARCHAR(length=64), nullable=True), + sa.Column("label_data", postgresql.JSONB(astext_type=sa.Text()), nullable=True), + sa.Column( + "created_at", + sa.DateTime(timezone=True), + server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), + nullable=False, + ), + sa.PrimaryKeyConstraint("id", name=op.f("pk_b3_labels")), + sa.UniqueConstraint("id", name=op.f("uq_b3_labels_id")), + ) + op.create_index( + "ix_b3_labels_addr_block_num", + "b3_labels", + ["address", "block_number"], + unique=False, + ) + op.create_index( + "ix_b3_labels_addr_block_ts", + "b3_labels", + ["address", "block_timestamp"], + unique=False, + ) + op.create_index( + op.f("ix_b3_labels_address"), "b3_labels", ["address"], unique=False + ) + op.create_index( + op.f("ix_b3_labels_block_number"), "b3_labels", ["block_number"], unique=False + ) + op.create_index( + op.f("ix_b3_labels_caller_address"), + "b3_labels", + ["caller_address"], + unique=False, + ) + op.create_index(op.f("ix_b3_labels_label"), "b3_labels", ["label"], unique=False) + op.create_index( + op.f("ix_b3_labels_label_name"), "b3_labels", ["label_name"], unique=False + ) + op.create_index( + op.f("ix_b3_labels_label_type"), "b3_labels", ["label_type"], unique=False + ) + op.create_index( + op.f("ix_b3_labels_origin_address"), + "b3_labels", + ["origin_address"], + unique=False, + ) + op.create_index( + op.f("ix_b3_labels_transaction_hash"), + "b3_labels", + ["transaction_hash"], + unique=False, + ) + op.create_index( + "uk_b3_labels_tx_hash_log_idx_evt", + "b3_labels", + ["transaction_hash", "log_index"], + unique=True, + postgresql_where=sa.text("label='seer' and label_type='event'"), + ) + op.create_index( + "uk_b3_labels_tx_hash_log_idx_evt_raw", + "b3_labels", + ["transaction_hash", "log_index"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + op.create_index( + "uk_b3_labels_tx_hash_tx_call", + "b3_labels", + ["transaction_hash"], + unique=True, + postgresql_where=sa.text("label='seer' and label_type='tx_call'"), + ) + op.create_index( + "uk_b3_labels_tx_hash_tx_call_raw", + "b3_labels", + ["transaction_hash"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + op.create_table( + "b3_sepolia_labels", + sa.Column("id", sa.UUID(), nullable=False), + sa.Column("label", sa.VARCHAR(length=256), nullable=False), + sa.Column("transaction_hash", sa.VARCHAR(length=128), nullable=False), + sa.Column("log_index", sa.Integer(), nullable=True), + sa.Column("block_number", sa.BigInteger(), nullable=False), + sa.Column("block_hash", sa.VARCHAR(length=256), nullable=False), + sa.Column("block_timestamp", sa.BigInteger(), nullable=False), + sa.Column("caller_address", sa.LargeBinary(), nullable=True), + sa.Column("origin_address", sa.LargeBinary(), nullable=True), + sa.Column("address", sa.LargeBinary(), nullable=False), + sa.Column("label_name", sa.Text(), nullable=True), + sa.Column("label_type", sa.VARCHAR(length=64), nullable=True), + sa.Column("label_data", postgresql.JSONB(astext_type=sa.Text()), nullable=True), + sa.Column( + "created_at", + sa.DateTime(timezone=True), + server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), + nullable=False, + ), + sa.PrimaryKeyConstraint("id", name=op.f("pk_b3_sepolia_labels")), + sa.UniqueConstraint("id", name=op.f("uq_b3_sepolia_labels_id")), + ) + op.create_index( + "ix_b3_sepolia_labels_addr_block_num", + "b3_sepolia_labels", + ["address", "block_number"], + unique=False, + ) + op.create_index( + "ix_b3_sepolia_labels_addr_block_ts", + "b3_sepolia_labels", + ["address", "block_timestamp"], + unique=False, + ) + op.create_index( + op.f("ix_b3_sepolia_labels_address"), + "b3_sepolia_labels", + ["address"], + unique=False, + ) + op.create_index( + op.f("ix_b3_sepolia_labels_block_number"), + "b3_sepolia_labels", + ["block_number"], + unique=False, + ) + op.create_index( + op.f("ix_b3_sepolia_labels_caller_address"), + "b3_sepolia_labels", + ["caller_address"], + unique=False, + ) + op.create_index( + op.f("ix_b3_sepolia_labels_label"), "b3_sepolia_labels", ["label"], unique=False + ) + op.create_index( + op.f("ix_b3_sepolia_labels_label_name"), + "b3_sepolia_labels", + ["label_name"], + unique=False, + ) + op.create_index( + op.f("ix_b3_sepolia_labels_label_type"), + "b3_sepolia_labels", + ["label_type"], + unique=False, + ) + op.create_index( + op.f("ix_b3_sepolia_labels_origin_address"), + "b3_sepolia_labels", + ["origin_address"], + unique=False, + ) + op.create_index( + op.f("ix_b3_sepolia_labels_transaction_hash"), + "b3_sepolia_labels", + ["transaction_hash"], + unique=False, + ) + op.create_index( + "uk_b3_sepolia_labels_tx_hash_log_idx_evt", + "b3_sepolia_labels", + ["transaction_hash", "log_index"], + unique=True, + postgresql_where=sa.text("label='seer' and label_type='event'"), + ) + op.create_index( + "uk_b3_sepolia_labels_tx_hash_log_idx_evt_raw", + "b3_sepolia_labels", + ["transaction_hash", "log_index"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + op.create_index( + "uk_b3_sepolia_labels_tx_hash_tx_call", + "b3_sepolia_labels", + ["transaction_hash"], + unique=True, + postgresql_where=sa.text("label='seer' and label_type='tx_call'"), + ) + op.create_index( + "uk_b3_sepolia_labels_tx_hash_tx_call_raw", + "b3_sepolia_labels", + ["transaction_hash"], + unique=True, + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_index( + "uk_b3_sepolia_labels_tx_hash_tx_call_raw", + table_name="b3_sepolia_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + op.drop_index( + "uk_b3_sepolia_labels_tx_hash_tx_call", + table_name="b3_sepolia_labels", + postgresql_where=sa.text("label='seer' and label_type='tx_call'"), + ) + op.drop_index( + "uk_b3_sepolia_labels_tx_hash_log_idx_evt_raw", + table_name="b3_sepolia_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + op.drop_index( + "uk_b3_sepolia_labels_tx_hash_log_idx_evt", + table_name="b3_sepolia_labels", + postgresql_where=sa.text("label='seer' and label_type='event'"), + ) + op.drop_index( + op.f("ix_b3_sepolia_labels_transaction_hash"), table_name="b3_sepolia_labels" + ) + op.drop_index( + op.f("ix_b3_sepolia_labels_origin_address"), table_name="b3_sepolia_labels" + ) + op.drop_index( + op.f("ix_b3_sepolia_labels_label_type"), table_name="b3_sepolia_labels" + ) + op.drop_index( + op.f("ix_b3_sepolia_labels_label_name"), table_name="b3_sepolia_labels" + ) + op.drop_index(op.f("ix_b3_sepolia_labels_label"), table_name="b3_sepolia_labels") + op.drop_index( + op.f("ix_b3_sepolia_labels_caller_address"), table_name="b3_sepolia_labels" + ) + op.drop_index( + op.f("ix_b3_sepolia_labels_block_number"), table_name="b3_sepolia_labels" + ) + op.drop_index(op.f("ix_b3_sepolia_labels_address"), table_name="b3_sepolia_labels") + op.drop_index("ix_b3_sepolia_labels_addr_block_ts", table_name="b3_sepolia_labels") + op.drop_index("ix_b3_sepolia_labels_addr_block_num", table_name="b3_sepolia_labels") + op.drop_table("b3_sepolia_labels") + op.drop_index( + "uk_b3_labels_tx_hash_tx_call_raw", + table_name="b3_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'"), + ) + op.drop_index( + "uk_b3_labels_tx_hash_tx_call", + table_name="b3_labels", + postgresql_where=sa.text("label='seer' and label_type='tx_call'"), + ) + op.drop_index( + "uk_b3_labels_tx_hash_log_idx_evt_raw", + table_name="b3_labels", + postgresql_where=sa.text("label='seer-raw' and label_type='event'"), + ) + op.drop_index( + "uk_b3_labels_tx_hash_log_idx_evt", + table_name="b3_labels", + postgresql_where=sa.text("label='seer' and label_type='event'"), + ) + op.drop_index(op.f("ix_b3_labels_transaction_hash"), table_name="b3_labels") + op.drop_index(op.f("ix_b3_labels_origin_address"), table_name="b3_labels") + op.drop_index(op.f("ix_b3_labels_label_type"), table_name="b3_labels") + op.drop_index(op.f("ix_b3_labels_label_name"), table_name="b3_labels") + op.drop_index(op.f("ix_b3_labels_label"), table_name="b3_labels") + op.drop_index(op.f("ix_b3_labels_caller_address"), table_name="b3_labels") + op.drop_index(op.f("ix_b3_labels_block_number"), table_name="b3_labels") + op.drop_index(op.f("ix_b3_labels_address"), table_name="b3_labels") + op.drop_index("ix_b3_labels_addr_block_ts", table_name="b3_labels") + op.drop_index("ix_b3_labels_addr_block_num", table_name="b3_labels") + op.drop_table("b3_labels") + # ### end Alembic commands ### diff --git a/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/env.py b/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/env.py index 0d39ef6c..7cfcc9f0 100644 --- a/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/env.py +++ b/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/env.py @@ -36,6 +36,10 @@ from moonstreamdbv3.models_indexes import ( ArbitrumSepoliaLogIndex, ArbitrumSepoliaReorgs, ArbitrumSepoliaTransactionIndex, + B3BlockIndex, + B3Reorgs, + B3SepoliaBlockIndex, + B3SepoliaReorgs, EthereumBlockIndex, EthereumLogIndex, EthereumReorgs, @@ -131,6 +135,10 @@ def include_symbol(tablename, schema): ImxZkevmSepoliaTransactionIndex.__tablename__, ImxZkevmSepoliaLogIndex.__tablename__, ImxZkevmSepoliaReorgs.__tablename__, + B3BlockIndex.__tablename__, + B3Reorgs.__tablename__, + B3SepoliaBlockIndex.__tablename__, + B3SepoliaReorgs.__tablename__, } diff --git a/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/versions/25b339f55f8f_add_b3.py b/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/versions/25b339f55f8f_add_b3.py new file mode 100644 index 00000000..578d0820 --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/versions/25b339f55f8f_add_b3.py @@ -0,0 +1,139 @@ +"""add-b3 + +Revision ID: 25b339f55f8f +Revises: 48d2562504d1 +Create Date: 2024-09-11 13:58:54.884367 + +""" + +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision: str = "25b339f55f8f" +down_revision: Union[str, None] = "48d2562504d1" +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.create_table( + "b3_blocks", + sa.Column("block_number", sa.BigInteger(), nullable=False), + sa.Column("block_hash", sa.VARCHAR(length=256), nullable=False), + sa.Column("block_timestamp", sa.BigInteger(), nullable=False), + sa.Column("parent_hash", sa.VARCHAR(length=256), nullable=False), + sa.Column("row_id", sa.BigInteger(), nullable=False), + sa.Column("path", sa.Text(), nullable=False), + sa.Column("transactions_indexed_at", sa.DateTime(timezone=True), nullable=True), + sa.Column("logs_indexed_at", sa.DateTime(timezone=True), nullable=True), + sa.Column( + "indexed_at", + sa.DateTime(timezone=True), + server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), + nullable=False, + ), + sa.PrimaryKeyConstraint("block_number", name=op.f("pk_b3_blocks")), + ) + op.create_index( + op.f("ix_b3_blocks_block_number"), "b3_blocks", ["block_number"], unique=False + ) + op.create_index( + op.f("ix_b3_blocks_block_timestamp"), + "b3_blocks", + ["block_timestamp"], + unique=False, + ) + op.create_table( + "b3_reorgs", + sa.Column("id", sa.UUID(), nullable=False), + sa.Column("block_number", sa.BigInteger(), nullable=False), + sa.Column("block_hash", sa.VARCHAR(length=256), nullable=False), + sa.PrimaryKeyConstraint("id", name=op.f("pk_b3_reorgs")), + ) + op.create_index( + op.f("ix_b3_reorgs_block_hash"), "b3_reorgs", ["block_hash"], unique=False + ) + op.create_index( + op.f("ix_b3_reorgs_block_number"), "b3_reorgs", ["block_number"], unique=False + ) + op.create_table( + "b3_sepolia_blocks", + sa.Column("block_number", sa.BigInteger(), nullable=False), + sa.Column("block_hash", sa.VARCHAR(length=256), nullable=False), + sa.Column("block_timestamp", sa.BigInteger(), nullable=False), + sa.Column("parent_hash", sa.VARCHAR(length=256), nullable=False), + sa.Column("row_id", sa.BigInteger(), nullable=False), + sa.Column("path", sa.Text(), nullable=False), + sa.Column("transactions_indexed_at", sa.DateTime(timezone=True), nullable=True), + sa.Column("logs_indexed_at", sa.DateTime(timezone=True), nullable=True), + sa.Column( + "indexed_at", + sa.DateTime(timezone=True), + server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), + nullable=False, + ), + sa.PrimaryKeyConstraint("block_number", name=op.f("pk_b3_sepolia_blocks")), + ) + op.create_index( + op.f("ix_b3_sepolia_blocks_block_number"), + "b3_sepolia_blocks", + ["block_number"], + unique=False, + ) + op.create_index( + op.f("ix_b3_sepolia_blocks_block_timestamp"), + "b3_sepolia_blocks", + ["block_timestamp"], + unique=False, + ) + op.create_table( + "b3_sepolia_reorgs", + sa.Column("id", sa.UUID(), nullable=False), + sa.Column("block_number", sa.BigInteger(), nullable=False), + sa.Column("block_hash", sa.VARCHAR(length=256), nullable=False), + sa.PrimaryKeyConstraint("id", name=op.f("pk_b3_sepolia_reorgs")), + ) + op.create_index( + op.f("ix_b3_sepolia_reorgs_block_hash"), + "b3_sepolia_reorgs", + ["block_hash"], + unique=False, + ) + op.create_index( + op.f("ix_b3_sepolia_reorgs_block_number"), + "b3_sepolia_reorgs", + ["block_number"], + unique=False, + ) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + + op.drop_index( + op.f("ix_b3_sepolia_reorgs_block_number"), table_name="b3_sepolia_reorgs" + ) + op.drop_index( + op.f("ix_b3_sepolia_reorgs_block_hash"), table_name="b3_sepolia_reorgs" + ) + op.drop_table("b3_sepolia_reorgs") + op.drop_index( + op.f("ix_b3_sepolia_blocks_block_timestamp"), table_name="b3_sepolia_blocks" + ) + op.drop_index( + op.f("ix_b3_sepolia_blocks_block_number"), table_name="b3_sepolia_blocks" + ) + op.drop_table("b3_sepolia_blocks") + op.drop_index(op.f("ix_b3_reorgs_block_number"), table_name="b3_reorgs") + op.drop_index(op.f("ix_b3_reorgs_block_hash"), table_name="b3_reorgs") + op.drop_table("b3_reorgs") + op.drop_index(op.f("ix_b3_blocks_block_timestamp"), table_name="b3_blocks") + op.drop_index(op.f("ix_b3_blocks_block_number"), table_name="b3_blocks") + op.drop_table("b3_blocks") + # ### end Alembic commands ### diff --git a/moonstreamdb-v3/moonstreamdbv3/blockchain.py b/moonstreamdb-v3/moonstreamdbv3/blockchain.py index a2b713e3..ecfaa525 100644 --- a/moonstreamdb-v3/moonstreamdbv3/blockchain.py +++ b/moonstreamdb-v3/moonstreamdbv3/blockchain.py @@ -28,6 +28,8 @@ from .models import ( StarknetSepoliaLabel, MantleLabel, MantleSepoliaLabel, + B3Label, + B3SepoliaLabel, ) @@ -57,6 +59,8 @@ class AvailableBlockchainType(Enum): MANTLE_SEPOLIA = "mantle_sepolia" GAME7_ORBIT_ARBITRUM_SEPOLIA = "game7_orbit_arbitrum_sepolia" GAME7_TESTNET = "game7_testnet" + B3 = "b3" + B3_SEPOLIA = "b3_sepolia" def get_label_model(blockchain_type: AvailableBlockchainType) -> Type[ @@ -86,6 +90,8 @@ def get_label_model(blockchain_type: AvailableBlockchainType) -> Type[ StarknetSepoliaLabel, MantleLabel, MantleSepoliaLabel, + B3Label, + B3SepoliaLabel, ] ]: """ @@ -119,6 +125,8 @@ def get_label_model(blockchain_type: AvailableBlockchainType) -> Type[ StarknetSepoliaLabel, MantleLabel, MantleSepoliaLabel, + B3Label, + B3SepoliaLabel, ] ] @@ -170,6 +178,10 @@ def get_label_model(blockchain_type: AvailableBlockchainType) -> Type[ label_model = Game7OrbitArbitrumSepoliaLabel elif blockchain_type == AvailableBlockchainType.GAME7_TESTNET: label_model = Game7TestnetLabel + elif blockchain_type == AvailableBlockchainType.B3: + label_model = B3Label + elif blockchain_type == AvailableBlockchainType.B3_SEPOLIA: + label_model = B3SepoliaLabel else: raise ValueError(f"Unknown blockchain type: {blockchain_type}") diff --git a/moonstreamdb-v3/moonstreamdbv3/models.py b/moonstreamdb-v3/moonstreamdbv3/models.py index 51ad0a48..9164c62d 100644 --- a/moonstreamdb-v3/moonstreamdbv3/models.py +++ b/moonstreamdb-v3/moonstreamdbv3/models.py @@ -1332,3 +1332,93 @@ class Game7TestnetLabel(EvmBasedLabel): # type: ignore postgresql_where=text("label='seer-raw' and label_type='event'"), ), ) + + +class B3Label(EvmBasedLabel): # type: ignore + __tablename__ = "b3_labels" + + __table_args__ = ( + Index( + "ix_b3_labels_addr_block_num", + "address", + "block_number", + unique=False, + ), + Index( + "ix_b3_labels_addr_block_ts", + "address", + "block_timestamp", + unique=False, + ), + Index( + "uk_b3_labels_tx_hash_tx_call", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer' and label_type='tx_call'"), + ), + Index( + "uk_b3_labels_tx_hash_log_idx_evt", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer' and label_type='event'"), + ), + Index( + "uk_b3_labels_tx_hash_tx_call_raw", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='tx_call'"), + ), + Index( + "uk_b3_labels_tx_hash_log_idx_evt_raw", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='event'"), + ), + ) + + +class B3SepoliaLabel(EvmBasedLabel): # type: ignore + __tablename__ = "b3_sepolia_labels" + + __table_args__ = ( + Index( + "ix_b3_sepolia_labels_addr_block_num", + "address", + "block_number", + unique=False, + ), + Index( + "ix_b3_sepolia_labels_addr_block_ts", + "address", + "block_timestamp", + unique=False, + ), + Index( + "uk_b3_sepolia_labels_tx_hash_tx_call", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer' and label_type='tx_call'"), + ), + Index( + "uk_b3_sepolia_labels_tx_hash_log_idx_evt", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer' and label_type='event'"), + ), + Index( + "uk_b3_sepolia_labels_tx_hash_tx_call_raw", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='tx_call'"), + ), + Index( + "uk_b3_sepolia_labels_tx_hash_log_idx_evt_raw", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='event'"), + ), + ) diff --git a/moonstreamdb-v3/moonstreamdbv3/models_indexes.py b/moonstreamdb-v3/moonstreamdbv3/models_indexes.py index e4615caa..ce75bc27 100644 --- a/moonstreamdb-v3/moonstreamdbv3/models_indexes.py +++ b/moonstreamdb-v3/moonstreamdbv3/models_indexes.py @@ -775,6 +775,22 @@ class Game7TestnetReorgs(EvmBasedReorgs): __tablename__ = "game7_testnet_reorgs" +class B3BlockIndex(EvmBasedBlocks): + __tablename__ = "b3_blocks" + + +class B3Reorgs(EvmBasedReorgs): + __tablename__ = "b3_reorgs" + + +class B3SepoliaBlockIndex(EvmBasedBlocks): + __tablename__ = "b3_sepolia_blocks" + + +class B3SepoliaReorgs(EvmBasedReorgs): + __tablename__ = "b3_sepolia_reorgs" + + ### ABI Jobs diff --git a/moonstreamdb-v3/moonstreamdbv3/version.txt b/moonstreamdb-v3/moonstreamdbv3/version.txt index cd231804..32786aa4 100644 --- a/moonstreamdb-v3/moonstreamdbv3/version.txt +++ b/moonstreamdb-v3/moonstreamdbv3/version.txt @@ -1 +1 @@ -0.0.17 +0.0.18 diff --git a/types/python/moonstreamtypes/blockchain.py b/types/python/moonstreamtypes/blockchain.py index 7362e4c6..e549caf6 100644 --- a/types/python/moonstreamtypes/blockchain.py +++ b/types/python/moonstreamtypes/blockchain.py @@ -20,6 +20,8 @@ from moonstreamdb.models import ( AvalancheFujiTransaction, AvalancheLabel, AvalancheTransaction, + B3Block, + B3SepoliaBlock, BlastBlock, BlastLabel, BlastSepoliaBlock, @@ -95,6 +97,8 @@ from moonstreamdbv3.models import XaiSepoliaLabel as XaiSepoliaLabelV3 from moonstreamdbv3.models import XDaiLabel as XDaiLabelV3 from moonstreamdbv3.models import ZkSyncEraLabel as ZkSyncEraLabelV3 from moonstreamdbv3.models import ZkSyncEraSepoliaLabel as ZkSyncEraSepoliaLabelV3 +from moonstreamdbv3.models import B3Label as B3LabelV3 +from moonstreamdbv3.models import B3SepoliaLabel as B3SepoliaLabelV3 class AvailableBlockchainType(Enum): @@ -127,6 +131,8 @@ class AvailableBlockchainType(Enum): MANTLE_SEPOLIA = "mantle_sepolia" IMX_ZKEVM = "imx_zkevm" IMX_ZKEVM_SEPOLIA = "imx_zkevm_sepolia" + B3 = "b3" + B3_SEPOLIA = "b3_sepolia" def get_block_model( @@ -154,6 +160,8 @@ def get_block_model( ProofOfPlayApexBlock, MantleBlock, MantleSepoliaBlock, + B3Block, + B3SepoliaBlock, ] ]: """ @@ -182,6 +190,8 @@ def get_block_model( ProofOfPlayApexBlock, MantleBlock, MantleSepoliaBlock, + B3Block, + B3SepoliaBlock, ] ] if blockchain_type == AvailableBlockchainType.ETHEREUM: @@ -226,6 +236,10 @@ def get_block_model( block_model = MantleBlock elif blockchain_type == AvailableBlockchainType.MANTLE_SEPOLIA: block_model = MantleSepoliaBlock + elif blockchain_type == AvailableBlockchainType.B3: + block_model = B3Block + elif blockchain_type == AvailableBlockchainType.B3_SEPOLIA: + block_model = B3SepoliaBlock else: raise Exception("Unsupported blockchain type provided") @@ -285,6 +299,8 @@ def get_label_model( MantleSepoliaLabelV3, ImxZkevmLabelV3, ImxZkevmSepoliaLabelV3, + B3LabelV3, + B3SepoliaLabelV3, ] ]: """ @@ -344,6 +360,8 @@ def get_label_model( MantleSepoliaLabelV3, ImxZkevmLabelV3, ImxZkevmSepoliaLabelV3, + B3LabelV3, + B3SepoliaLabelV3, ] ] if version == 2: @@ -446,6 +464,10 @@ def get_label_model( label_model = ImxZkevmLabelV3 elif blockchain_type == AvailableBlockchainType.IMX_ZKEVM_SEPOLIA: label_model = ImxZkevmSepoliaLabelV3 + elif blockchain_type == AvailableBlockchainType.B3: + label_model = B3LabelV3 + elif blockchain_type == AvailableBlockchainType.B3_SEPOLIA: + label_model = B3SepoliaLabelV3 else: raise Exception("Unsupported blockchain type provided") else: diff --git a/types/python/moonstreamtypes/networks.py b/types/python/moonstreamtypes/networks.py index 9717ea30..4b0c7179 100644 --- a/types/python/moonstreamtypes/networks.py +++ b/types/python/moonstreamtypes/networks.py @@ -96,6 +96,8 @@ from moonstreamdbv3.models import XaiSepoliaLabel as XaiSepoliaLabelV3 from moonstreamdbv3.models import XDaiLabel as XDaiLabelV3 from moonstreamdbv3.models import ZkSyncEraLabel as ZkSyncEraLabelV3 from moonstreamdbv3.models import ZkSyncEraSepoliaLabel as ZkSyncEraSepoliaLabelV3 +from moonstreamdbv3.models import B3Label as B3LabelV3 +from moonstreamdbv3.models import B3SepoliaLabel as B3SepoliaLabelV3 from .blockchain import AvailableBlockchainType @@ -130,6 +132,8 @@ class Network(Enum): mantle_sepolia = "mantle_sepolia" imx_zkevm = "imx_zkevm" imx_zkevm_sepolia = "imx_zkevm_sepolia" + b3 = "b3" + b3_sepolia = "b3_sepolia" tx_raw_types = Union[ @@ -346,6 +350,12 @@ MODELS_V3: Dict[Network, Dict[str, Base]] = { Network.imx_zkevm_sepolia: { "labels": ImxZkevmSepoliaLabelV3, }, + Network.b3: { + "labels": B3LabelV3, + }, + Network.b3_sepolia: { + "labels": B3SepoliaLabelV3, + }, } @@ -411,5 +421,9 @@ def blockchain_type_to_network_type( return Network.imx_zkevm elif blockchain_type == AvailableBlockchainType.IMX_ZKEVM_SEPOLIA: return Network.imx_zkevm_sepolia + elif blockchain_type == AvailableBlockchainType.B3: + return Network.b3 + elif blockchain_type == AvailableBlockchainType.B3_SEPOLIA: + return Network.b3_sepolia else: raise ValueError(f"Unknown blockchain type: {blockchain_type}") diff --git a/types/python/moonstreamtypes/subscriptions.py b/types/python/moonstreamtypes/subscriptions.py index 4c1393c8..6266e8d6 100644 --- a/types/python/moonstreamtypes/subscriptions.py +++ b/types/python/moonstreamtypes/subscriptions.py @@ -35,6 +35,8 @@ class SubscriptionTypes(Enum): MANTLE_SEPOLIA_BLOCKCHAIN = "mantle_sepolia_smartcontract" IMX_ZKEVM_BLOCKCHAIN = "imx_zkevm_smartcontract" IMX_ZKEVM_SEPOLIA_BLOCKCHAIN = "imx_zkevm_sepolia_smartcontract" + B3_BLOCKCHAIN = "b3_smartcontract" + B3_SEPOLIA_BLOCKCHAIN = "b3_sepolia_smartcontract" def blockchain_type_to_subscription_type( @@ -98,6 +100,10 @@ def blockchain_type_to_subscription_type( return SubscriptionTypes.IMX_ZKEVM_BLOCKCHAIN elif blockchain_type == AvailableBlockchainType.IMX_ZKEVM_SEPOLIA: return SubscriptionTypes.IMX_ZKEVM_SEPOLIA_BLOCKCHAIN + elif blockchain_type == AvailableBlockchainType.B3: + return SubscriptionTypes.B3_BLOCKCHAIN + elif blockchain_type == AvailableBlockchainType.B3_SEPOLIA: + return SubscriptionTypes.B3_SEPOLIA_BLOCKCHAIN else: raise ValueError(f"Unknown blockchain type: {blockchain_type}") @@ -132,6 +138,8 @@ subscription_id_by_blockchain = { "mantle_sepolia": "mantle_sepolia_smartcontract", "imx_zkevm": "imx_zkevm_smartcontract", "imx_zkevm_sepolia": "imx_zkevm_sepolia_smartcontract", + "b3": "b3_smartcontract", + "b3_sepolia": "b3_sepolia_smartcontract", } blockchain_by_subscription_id = { @@ -192,4 +200,6 @@ blockchain_by_subscription_id = { "mantle_sepolia_smartcontract": "mantle_sepolia", "imx_zkevm_smartcontract": "imx_zkevm", "imx_zkevm_sepolia_smartcontract": "imx_zkevm_sepolia", + "b3_smartcontract": "b3", + "b3_sepolia_smartcontract": "b3_sepolia", } diff --git a/types/python/moonstreamtypes/version.txt b/types/python/moonstreamtypes/version.txt index 1750564f..5a5831ab 100644 --- a/types/python/moonstreamtypes/version.txt +++ b/types/python/moonstreamtypes/version.txt @@ -1 +1 @@ -0.0.6 +0.0.7 diff --git a/types/python/setup.py b/types/python/setup.py index fe03945b..1edae0fb 100644 --- a/types/python/setup.py +++ b/types/python/setup.py @@ -34,7 +34,7 @@ setup( zip_safe=False, install_requires=[ "moonstreamdb>=0.4.5", - "moonstreamdb-v3>=0.0.16", + "moonstreamdb-v3>=0.0.18", ], extras_require={ "dev": ["black", "isort", "mypy"],