From f51a862053711429cf0515940354ac4bf97fd661 Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 22 Jul 2024 14:00:22 +0300 Subject: [PATCH 01/11] Add sepolia. --- moonstreamdb-v3/moonstreamdbv3/blockchain.py | 3 ++ .../moonstreamdbv3/models_indexes.py | 53 +++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/moonstreamdb-v3/moonstreamdbv3/blockchain.py b/moonstreamdb-v3/moonstreamdbv3/blockchain.py index 094ff305..fa89db91 100644 --- a/moonstreamdb-v3/moonstreamdbv3/blockchain.py +++ b/moonstreamdb-v3/moonstreamdbv3/blockchain.py @@ -36,6 +36,7 @@ class AvailableBlockchainType(Enum): MUMBAI = "mumbai" AMOY = "amoy" XDAI = "xdai" + SEPOLIA = "sepolia" ZKSYNC_ERA = "zksync_era" ZKSYNC_ERA_TESTNET = "zksync_era_testnet" ZKSYNC_ERA_SEPOLIA = "zksync_era_sepolia" @@ -119,6 +120,8 @@ def get_label_model(blockchain_type: AvailableBlockchainType) -> Type[ if blockchain_type == AvailableBlockchainType.ETHEREUM: label_model = EthereumLabel + elif blockchain_type == AvailableBlockchainType.SEPOLIA: + label_model = SepoliaLabel elif blockchain_type == AvailableBlockchainType.POLYGON: label_model = PolygonLabel elif blockchain_type == AvailableBlockchainType.MUMBAI: diff --git a/moonstreamdb-v3/moonstreamdbv3/models_indexes.py b/moonstreamdb-v3/moonstreamdbv3/models_indexes.py index 439e654b..3a34aec3 100644 --- a/moonstreamdb-v3/moonstreamdbv3/models_indexes.py +++ b/moonstreamdb-v3/moonstreamdbv3/models_indexes.py @@ -153,6 +153,59 @@ class EthereumReorgs(EvmBasedReorgs): __tablename__ = "ethereum_reorgs" +class EthereumSepoliaBlockIndex(EvmBasedBlocks): + __tablename__ = "ethereum_sepolia_blocks" + + +class EthereumSepoliaTransactionIndex(EvmBasedTransactions): + __tablename__ = "ethereum_sepolia_transactions" + + block_number = Column( + BigInteger, + ForeignKey("ethereum_sepolia_blocks.block_number", ondelete="CASCADE"), + nullable=False, + index=True, + ) + + +class EthereumSepoliaLogIndex(EvmBasedLogs): + + __tablename__ = "ethereum_sepolia_logs" + + __table_args__ = ( + Index( + "idx_ethereum_sepolia_logs_address_selector", + "address", + "selector", + unique=False, + ), + Index( + "idx_ethereum_sepolia_logs_block_hash_log_index", + "block_hash", + "log_index", + unique=True, + ), + UniqueConstraint( + "transaction_hash", + "log_index", + name="uq_ethereum_sepolia_log_index_transaction_hash_log_index", + ), + PrimaryKeyConstraint( + "transaction_hash", "log_index", name="pk_ethereum_sepolia_log_index" + ), + ) + transaction_hash = Column( + VARCHAR(256), + ForeignKey("ethereum_sepolia_transactions.hash", ondelete="CASCADE"), + nullable=False, + index=True, + ) + + +class EthereumSepoliaReorgs(EvmBasedReorgs): + __tablename__ = "ethereum_sepolia_reorgs" + + ### Polygon From 72cbf96fc68a247a986095b176e3eef8d46eda91 Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 22 Jul 2024 14:08:21 +0300 Subject: [PATCH 02/11] Add migration. --- .../versions/a1ead76c0470_add_sepolia.py | 288 ++++++++++++++++++ 1 file changed, 288 insertions(+) create mode 100644 moonstreamdb-v3/moonstreamdbv3/alembic_indexes/versions/a1ead76c0470_add_sepolia.py diff --git a/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/versions/a1ead76c0470_add_sepolia.py b/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/versions/a1ead76c0470_add_sepolia.py new file mode 100644 index 00000000..1271322e --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/versions/a1ead76c0470_add_sepolia.py @@ -0,0 +1,288 @@ +"""Add sepolia + +Revision ID: a1ead76c0470 +Revises: f2c6aa92e5d2 +Create Date: 2024-07-22 14:07:22.992523 + +""" + +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision: str = "a1ead76c0470" +down_revision: Union[str, None] = "f2c6aa92e5d2" +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( + "ethereum_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( + "indexed_at", + sa.DateTime(timezone=True), + server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), + nullable=False, + ), + sa.PrimaryKeyConstraint( + "block_number", name=op.f("pk_ethereum_sepolia_blocks") + ), + ) + op.create_index( + op.f("ix_ethereum_sepolia_blocks_block_number"), + "ethereum_sepolia_blocks", + ["block_number"], + unique=False, + ) + op.create_index( + op.f("ix_ethereum_sepolia_blocks_block_timestamp"), + "ethereum_sepolia_blocks", + ["block_timestamp"], + unique=False, + ) + op.create_table( + "ethereum_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_ethereum_sepolia_reorgs")), + ) + op.create_index( + op.f("ix_ethereum_sepolia_reorgs_block_hash"), + "ethereum_sepolia_reorgs", + ["block_hash"], + unique=False, + ) + op.create_index( + op.f("ix_ethereum_sepolia_reorgs_block_number"), + "ethereum_sepolia_reorgs", + ["block_number"], + unique=False, + ) + op.create_table( + "ethereum_sepolia_transactions", + sa.Column("block_number", sa.BigInteger(), nullable=False), + sa.Column("hash", sa.VARCHAR(length=256), nullable=False), + sa.Column("from_address", sa.LargeBinary(length=20), nullable=False), + sa.Column("to_address", sa.LargeBinary(length=20), nullable=False), + sa.Column("selector", sa.VARCHAR(length=256), nullable=True), + sa.Column("type", sa.Integer(), nullable=True), + sa.Column("row_id", sa.BigInteger(), nullable=False), + sa.Column("block_hash", sa.VARCHAR(length=256), nullable=False), + sa.Column("index", sa.BigInteger(), nullable=False), + sa.Column("path", sa.Text(), nullable=False), + sa.Column( + "indexed_at", + sa.DateTime(timezone=True), + server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), + nullable=False, + ), + sa.ForeignKeyConstraint( + ["block_number"], + ["ethereum_sepolia_blocks.block_number"], + name=op.f( + "fk_ethereum_sepolia_transactions_block_number_ethereum_sepolia_blocks" + ), + ondelete="CASCADE", + ), + sa.PrimaryKeyConstraint("hash", name=op.f("pk_ethereum_sepolia_transactions")), + ) + op.create_index( + op.f("ix_ethereum_sepolia_transactions_block_hash"), + "ethereum_sepolia_transactions", + ["block_hash"], + unique=False, + ) + op.create_index( + op.f("ix_ethereum_sepolia_transactions_block_number"), + "ethereum_sepolia_transactions", + ["block_number"], + unique=False, + ) + op.create_index( + op.f("ix_ethereum_sepolia_transactions_from_address"), + "ethereum_sepolia_transactions", + ["from_address"], + unique=False, + ) + op.create_index( + op.f("ix_ethereum_sepolia_transactions_hash"), + "ethereum_sepolia_transactions", + ["hash"], + unique=True, + ) + op.create_index( + op.f("ix_ethereum_sepolia_transactions_index"), + "ethereum_sepolia_transactions", + ["index"], + unique=False, + ) + op.create_index( + op.f("ix_ethereum_sepolia_transactions_selector"), + "ethereum_sepolia_transactions", + ["selector"], + unique=False, + ) + op.create_index( + op.f("ix_ethereum_sepolia_transactions_to_address"), + "ethereum_sepolia_transactions", + ["to_address"], + unique=False, + ) + op.create_index( + op.f("ix_ethereum_sepolia_transactions_type"), + "ethereum_sepolia_transactions", + ["type"], + unique=False, + ) + op.create_table( + "ethereum_sepolia_logs", + sa.Column("transaction_hash", sa.VARCHAR(length=256), nullable=False), + sa.Column("block_hash", sa.VARCHAR(length=256), nullable=False), + sa.Column("address", sa.LargeBinary(length=20), nullable=False), + sa.Column("row_id", sa.BigInteger(), nullable=False), + sa.Column("selector", sa.VARCHAR(length=256), nullable=True), + sa.Column("topic1", sa.VARCHAR(length=256), nullable=True), + sa.Column("topic2", sa.VARCHAR(length=256), nullable=True), + sa.Column("topic3", sa.VARCHAR(length=256), nullable=True), + sa.Column("log_index", sa.BigInteger(), nullable=False), + sa.Column("path", sa.Text(), nullable=False), + sa.Column( + "indexed_at", + sa.DateTime(timezone=True), + server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), + nullable=False, + ), + sa.ForeignKeyConstraint( + ["transaction_hash"], + ["ethereum_sepolia_transactions.hash"], + name=op.f( + "fk_ethereum_sepolia_logs_transaction_hash_ethereum_sepolia_transactions" + ), + ondelete="CASCADE", + ), + sa.PrimaryKeyConstraint( + "transaction_hash", "log_index", name="pk_ethereum_sepolia_log_index" + ), + sa.UniqueConstraint( + "transaction_hash", + "log_index", + name="uq_ethereum_sepolia_log_index_transaction_hash_log_index", + ), + ) + op.create_index( + "idx_ethereum_sepolia_logs_address_selector", + "ethereum_sepolia_logs", + ["address", "selector"], + unique=False, + ) + op.create_index( + "idx_ethereum_sepolia_logs_block_hash_log_index", + "ethereum_sepolia_logs", + ["block_hash", "log_index"], + unique=True, + ) + op.create_index( + op.f("ix_ethereum_sepolia_logs_address"), + "ethereum_sepolia_logs", + ["address"], + unique=False, + ) + op.create_index( + op.f("ix_ethereum_sepolia_logs_block_hash"), + "ethereum_sepolia_logs", + ["block_hash"], + unique=False, + ) + op.create_index( + op.f("ix_ethereum_sepolia_logs_transaction_hash"), + "ethereum_sepolia_logs", + ["transaction_hash"], + unique=False, + ) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_index( + op.f("ix_ethereum_sepolia_logs_transaction_hash"), + table_name="ethereum_sepolia_logs", + ) + op.drop_index( + op.f("ix_ethereum_sepolia_logs_block_hash"), table_name="ethereum_sepolia_logs" + ) + op.drop_index( + op.f("ix_ethereum_sepolia_logs_address"), table_name="ethereum_sepolia_logs" + ) + op.drop_index( + "idx_ethereum_sepolia_logs_block_hash_log_index", + table_name="ethereum_sepolia_logs", + ) + op.drop_index( + "idx_ethereum_sepolia_logs_address_selector", table_name="ethereum_sepolia_logs" + ) + op.drop_table("ethereum_sepolia_logs") + op.drop_index( + op.f("ix_ethereum_sepolia_transactions_type"), + table_name="ethereum_sepolia_transactions", + ) + op.drop_index( + op.f("ix_ethereum_sepolia_transactions_to_address"), + table_name="ethereum_sepolia_transactions", + ) + op.drop_index( + op.f("ix_ethereum_sepolia_transactions_selector"), + table_name="ethereum_sepolia_transactions", + ) + op.drop_index( + op.f("ix_ethereum_sepolia_transactions_index"), + table_name="ethereum_sepolia_transactions", + ) + op.drop_index( + op.f("ix_ethereum_sepolia_transactions_hash"), + table_name="ethereum_sepolia_transactions", + ) + op.drop_index( + op.f("ix_ethereum_sepolia_transactions_from_address"), + table_name="ethereum_sepolia_transactions", + ) + op.drop_index( + op.f("ix_ethereum_sepolia_transactions_block_number"), + table_name="ethereum_sepolia_transactions", + ) + op.drop_index( + op.f("ix_ethereum_sepolia_transactions_block_hash"), + table_name="ethereum_sepolia_transactions", + ) + op.drop_table("ethereum_sepolia_transactions") + op.drop_index( + op.f("ix_ethereum_sepolia_reorgs_block_number"), + table_name="ethereum_sepolia_reorgs", + ) + op.drop_index( + op.f("ix_ethereum_sepolia_reorgs_block_hash"), + table_name="ethereum_sepolia_reorgs", + ) + op.drop_table("ethereum_sepolia_reorgs") + op.drop_index( + op.f("ix_ethereum_sepolia_blocks_block_timestamp"), + table_name="ethereum_sepolia_blocks", + ) + op.drop_index( + op.f("ix_ethereum_sepolia_blocks_block_number"), + table_name="ethereum_sepolia_blocks", + ) + op.drop_table("ethereum_sepolia_blocks") + # ### end Alembic commands ### From d86a6fe4103786e094ee3d0ff62c0e221727b759 Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 22 Jul 2024 14:21:34 +0300 Subject: [PATCH 03/11] Update versions. --- .../moonstreamapi/admin/subscription_types.py | 11 +++++++++++ moonstreamapi/moonstreamapi/version.py | 2 +- moonstreamdb-v3/moonstreamdbv3/version.txt | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/moonstreamapi/moonstreamapi/admin/subscription_types.py b/moonstreamapi/moonstreamapi/admin/subscription_types.py index f79efaad..e41dfd4a 100644 --- a/moonstreamapi/moonstreamapi/admin/subscription_types.py +++ b/moonstreamapi/moonstreamapi/admin/subscription_types.py @@ -29,6 +29,17 @@ stripe_price_id=None, active=True, ), + "ethereum_sepolia_smartcontract": SubscriptionTypeResourceData( + id="ethereum_sepolia_smartcontract", + name="Ethereum Sepolia smartcontracts", + blockchain="ethereum_sepolia", + choices=["input:address", "tag:erc721"], + description="Contracts events and tx_calls of contract of Ethereum Sepolia blockchain", + icon_url="https://static.simiotics.com/moonstream/assets/ethereum/eth-diamond-purple.png", + stripe_product_id=None, + stripe_price_id=None, + active=True, + ), "polygon_smartcontract": SubscriptionTypeResourceData( id="polygon_smartcontract", name="Polygon smartcontracts", diff --git a/moonstreamapi/moonstreamapi/version.py b/moonstreamapi/moonstreamapi/version.py index cc7eaf07..653faa76 100644 --- a/moonstreamapi/moonstreamapi/version.py +++ b/moonstreamapi/moonstreamapi/version.py @@ -2,4 +2,4 @@ Moonstream library and API version. """ -MOONSTREAMAPI_VERSION = "0.4.4" +MOONSTREAMAPI_VERSION = "0.4.5" diff --git a/moonstreamdb-v3/moonstreamdbv3/version.txt b/moonstreamdb-v3/moonstreamdbv3/version.txt index 43b29618..9789c4cc 100644 --- a/moonstreamdb-v3/moonstreamdbv3/version.txt +++ b/moonstreamdb-v3/moonstreamdbv3/version.txt @@ -1 +1 @@ -0.0.13 +0.0.14 From 03323de76eddec110fd4f53a1d248af268ce4400 Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 22 Jul 2024 14:27:18 +0300 Subject: [PATCH 04/11] Add sepolia to types. --- .../moonstreamapi/admin/subscription_types.py | 10 +++++----- moonstreamdb-v3/moonstreamdbv3/models_indexes.py | 8 ++++---- types/python/moonstreamtypes/version.txt | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/moonstreamapi/moonstreamapi/admin/subscription_types.py b/moonstreamapi/moonstreamapi/admin/subscription_types.py index e41dfd4a..3284a9ed 100644 --- a/moonstreamapi/moonstreamapi/admin/subscription_types.py +++ b/moonstreamapi/moonstreamapi/admin/subscription_types.py @@ -29,12 +29,12 @@ stripe_price_id=None, active=True, ), - "ethereum_sepolia_smartcontract": SubscriptionTypeResourceData( - id="ethereum_sepolia_smartcontract", - name="Ethereum Sepolia smartcontracts", - blockchain="ethereum_sepolia", + "sepolia_smartcontract": SubscriptionTypeResourceData( + id="sepolia_smartcontract", + name="Sepolia smartcontracts", + blockchain="sepolia", choices=["input:address", "tag:erc721"], - description="Contracts events and tx_calls of contract of Ethereum Sepolia blockchain", + description="Contracts events and tx_calls of contract of Sepolia blockchain", icon_url="https://static.simiotics.com/moonstream/assets/ethereum/eth-diamond-purple.png", stripe_product_id=None, stripe_price_id=None, diff --git a/moonstreamdb-v3/moonstreamdbv3/models_indexes.py b/moonstreamdb-v3/moonstreamdbv3/models_indexes.py index 3a34aec3..d0802857 100644 --- a/moonstreamdb-v3/moonstreamdbv3/models_indexes.py +++ b/moonstreamdb-v3/moonstreamdbv3/models_indexes.py @@ -153,11 +153,11 @@ class EthereumReorgs(EvmBasedReorgs): __tablename__ = "ethereum_reorgs" -class EthereumSepoliaBlockIndex(EvmBasedBlocks): +class SepoliaBlockIndex(EvmBasedBlocks): __tablename__ = "ethereum_sepolia_blocks" -class EthereumSepoliaTransactionIndex(EvmBasedTransactions): +class SepoliaTransactionIndex(EvmBasedTransactions): __tablename__ = "ethereum_sepolia_transactions" block_number = Column( @@ -168,7 +168,7 @@ class EthereumSepoliaTransactionIndex(EvmBasedTransactions): ) -class EthereumSepoliaLogIndex(EvmBasedLogs): +class SepoliaLogIndex(EvmBasedLogs): __tablename__ = "ethereum_sepolia_logs" @@ -202,7 +202,7 @@ class EthereumSepoliaLogIndex(EvmBasedLogs): ) -class EthereumSepoliaReorgs(EvmBasedReorgs): +class SepoliaReorgs(EvmBasedReorgs): __tablename__ = "ethereum_sepolia_reorgs" diff --git a/types/python/moonstreamtypes/version.txt b/types/python/moonstreamtypes/version.txt index 81340c7e..bbdeab62 100644 --- a/types/python/moonstreamtypes/version.txt +++ b/types/python/moonstreamtypes/version.txt @@ -1 +1 @@ -0.0.4 +0.0.5 From 5ef8d305926e8887bf75a4ff55ebc269a76267db Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 22 Jul 2024 14:50:27 +0300 Subject: [PATCH 05/11] Add Sepolia in moonstream-types. --- types/python/moonstreamtypes/networks.py | 1 + types/python/moonstreamtypes/subscriptions.py | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/types/python/moonstreamtypes/networks.py b/types/python/moonstreamtypes/networks.py index f7738b84..00950fe9 100644 --- a/types/python/moonstreamtypes/networks.py +++ b/types/python/moonstreamtypes/networks.py @@ -334,6 +334,7 @@ class Network(Enum): } +## Used only in crawlers def blockchain_type_to_network_type( blockchain_type: AvailableBlockchainType, ) -> Network: diff --git a/types/python/moonstreamtypes/subscriptions.py b/types/python/moonstreamtypes/subscriptions.py index cdae4826..dd10a9b2 100644 --- a/types/python/moonstreamtypes/subscriptions.py +++ b/types/python/moonstreamtypes/subscriptions.py @@ -39,6 +39,8 @@ def blockchain_type_to_subscription_type( ) -> SubscriptionTypes: if blockchain_type == AvailableBlockchainType.ETHEREUM: return SubscriptionTypes.ETHEREUM_BLOCKCHAIN + elif blockchain_type == AvailableBlockchainType.SEPOLIA: + return SubscriptionTypes.SEPOLIA_BLOCKCHAIN elif blockchain_type == AvailableBlockchainType.POLYGON: return SubscriptionTypes.POLYGON_BLOCKCHAIN elif blockchain_type == AvailableBlockchainType.MUMBAI: @@ -93,6 +95,7 @@ def blockchain_type_to_subscription_type( subscription_id_by_blockchain = { "ethereum": "ethereum_smartcontract", + "sepolia": "sepolia_smartcontract", "polygon": "polygon_smartcontract", "mumbai": "mumbai_smartcontract", "amoy": "amoy_smartcontract", @@ -121,6 +124,7 @@ def blockchain_type_to_subscription_type( blockchain_by_subscription_id = { "ethereum_blockchain": "ethereum", + "sepolia_blockchain": "sepolia", "polygon_blockchain": "polygon", "mumbai_blockchain": "mumbai", "amoy_blockchain": "amoy", From e1c2b0ab983a44f42a29d33c94187c6e4c573111 Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 22 Jul 2024 15:18:12 +0300 Subject: [PATCH 06/11] Update connect information. --- moonstreamapi/configs/sample.env | 1 + moonstreamapi/moonstreamapi/settings.py | 9 +++++++++ moonstreamapi/moonstreamapi/web3_provider.py | 3 +++ 3 files changed, 13 insertions(+) diff --git a/moonstreamapi/configs/sample.env b/moonstreamapi/configs/sample.env index eae85085..5e010987 100644 --- a/moonstreamapi/configs/sample.env +++ b/moonstreamapi/configs/sample.env @@ -16,6 +16,7 @@ export MOONSTREAM_CRAWLERS_SERVER_PORT="" export MOONSTREAM_DATA_JOURNAL_ID="" export HUMBUG_TXPOOL_CLIENT_ID="" export MOONSTREAM_ETHEREUM_WEB3_PROVIDER_URI="https://" +export MOONSTREAM_SEPOLIA_WEB3_PROVIDER_URI="https://" export MOONSTREAM_POLYGON_WEB3_PROVIDER_URI="https://" export MOONSTREAM_PROOFOFPLAY_APEX_WEB3_PROVIDER_URI="https://" export MOONSTREAM_MUMBAI_WEB3_PROVIDER_URI="https://" diff --git a/moonstreamapi/moonstreamapi/settings.py b/moonstreamapi/moonstreamapi/settings.py index 3d1bc7c7..86d81a20 100644 --- a/moonstreamapi/moonstreamapi/settings.py +++ b/moonstreamapi/moonstreamapi/settings.py @@ -107,6 +107,15 @@ raise ValueError( "MOONSTREAM_ETHEREUM_WEB3_PROVIDER_URI environment variable must be set" ) + +MOONSTREAM_SEPOLIA_WEB3_PROVIDER_URI = os.environ.get( + "MOONSTREAM_SEPOLIA_WEB3_PROVIDER_URI", "" +) +if MOONSTREAM_SEPOLIA_WEB3_PROVIDER_URI == "": + raise ValueError( + "MOONSTREAM_SEPOLIA_WEB3_PROVIDER_URI environment variable must be set" + ) + MOONSTREAM_POLYGON_WEB3_PROVIDER_URI = os.environ.get( "MOONSTREAM_POLYGON_WEB3_PROVIDER_URI", "" ) diff --git a/moonstreamapi/moonstreamapi/web3_provider.py b/moonstreamapi/moonstreamapi/web3_provider.py index 7ebc15aa..ad099cea 100644 --- a/moonstreamapi/moonstreamapi/web3_provider.py +++ b/moonstreamapi/moonstreamapi/web3_provider.py @@ -26,6 +26,7 @@ MOONSTREAM_MUMBAI_WEB3_PROVIDER_URI, MOONSTREAM_POLYGON_WEB3_PROVIDER_URI, MOONSTREAM_PROOFOFPLAY_APEX_WEB3_PROVIDER_URI, + MOONSTREAM_SEPOLIA_WEB3_PROVIDER_URI, MOONSTREAM_WYRM_WEB3_PROVIDER_URI, MOONSTREAM_XAI_SEPOLIA_WEB3_PROVIDER_URI, MOONSTREAM_XAI_WEB3_PROVIDER_URI, @@ -75,6 +76,8 @@ def connect( if web3_uri is None: if blockchain_type == AvailableBlockchainType.ETHEREUM: web3_uri = MOONSTREAM_ETHEREUM_WEB3_PROVIDER_URI + elif blockchain_type == AvailableBlockchainType.SEPOLIA: + web3_uri = MOONSTREAM_SEPOLIA_WEB3_PROVIDER_URI elif blockchain_type == AvailableBlockchainType.POLYGON: web3_uri = MOONSTREAM_POLYGON_WEB3_PROVIDER_URI elif blockchain_type == AvailableBlockchainType.MUMBAI: From 6deae0e967a788b905a63ed0daa91f43f94335ef Mon Sep 17 00:00:00 2001 From: kompotkot Date: Thu, 25 Jul 2024 11:29:07 +0000 Subject: [PATCH 07/11] ethereum_sepolia -> sepolia --- .../versions/a1ead76c0470_add_sepolia.py | 176 ++++++++---------- .../moonstreamdbv3/models_indexes.py | 20 +- 2 files changed, 92 insertions(+), 104 deletions(-) diff --git a/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/versions/a1ead76c0470_add_sepolia.py b/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/versions/a1ead76c0470_add_sepolia.py index 1271322e..5bb9c5fa 100644 --- a/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/versions/a1ead76c0470_add_sepolia.py +++ b/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/versions/a1ead76c0470_add_sepolia.py @@ -22,7 +22,7 @@ def upgrade() -> None: # ### commands auto generated by Alembic - please adjust! ### op.create_table( - "ethereum_sepolia_blocks", + "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), @@ -35,43 +35,41 @@ def upgrade() -> None: server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False, ), - sa.PrimaryKeyConstraint( - "block_number", name=op.f("pk_ethereum_sepolia_blocks") - ), + sa.PrimaryKeyConstraint("block_number", name=op.f("pk_sepolia_blocks")), ) op.create_index( - op.f("ix_ethereum_sepolia_blocks_block_number"), - "ethereum_sepolia_blocks", + op.f("ix_sepolia_blocks_block_number"), + "sepolia_blocks", ["block_number"], unique=False, ) op.create_index( - op.f("ix_ethereum_sepolia_blocks_block_timestamp"), - "ethereum_sepolia_blocks", + op.f("ix_sepolia_blocks_block_timestamp"), + "sepolia_blocks", ["block_timestamp"], unique=False, ) op.create_table( - "ethereum_sepolia_reorgs", + "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_ethereum_sepolia_reorgs")), + sa.PrimaryKeyConstraint("id", name=op.f("pk_sepolia_reorgs")), ) op.create_index( - op.f("ix_ethereum_sepolia_reorgs_block_hash"), - "ethereum_sepolia_reorgs", + op.f("ix_sepolia_reorgs_block_hash"), + "sepolia_reorgs", ["block_hash"], unique=False, ) op.create_index( - op.f("ix_ethereum_sepolia_reorgs_block_number"), - "ethereum_sepolia_reorgs", + op.f("ix_sepolia_reorgs_block_number"), + "sepolia_reorgs", ["block_number"], unique=False, ) op.create_table( - "ethereum_sepolia_transactions", + "sepolia_transactions", sa.Column("block_number", sa.BigInteger(), nullable=False), sa.Column("hash", sa.VARCHAR(length=256), nullable=False), sa.Column("from_address", sa.LargeBinary(length=20), nullable=False), @@ -90,64 +88,62 @@ def upgrade() -> None: ), sa.ForeignKeyConstraint( ["block_number"], - ["ethereum_sepolia_blocks.block_number"], - name=op.f( - "fk_ethereum_sepolia_transactions_block_number_ethereum_sepolia_blocks" - ), + ["sepolia_blocks.block_number"], + name=op.f("fk_sepolia_transactions_block_number_sepolia_blocks"), ondelete="CASCADE", ), - sa.PrimaryKeyConstraint("hash", name=op.f("pk_ethereum_sepolia_transactions")), + sa.PrimaryKeyConstraint("hash", name=op.f("pk_sepolia_transactions")), ) op.create_index( - op.f("ix_ethereum_sepolia_transactions_block_hash"), - "ethereum_sepolia_transactions", + op.f("ix_sepolia_transactions_block_hash"), + "sepolia_transactions", ["block_hash"], unique=False, ) op.create_index( - op.f("ix_ethereum_sepolia_transactions_block_number"), - "ethereum_sepolia_transactions", + op.f("ix_sepolia_transactions_block_number"), + "sepolia_transactions", ["block_number"], unique=False, ) op.create_index( - op.f("ix_ethereum_sepolia_transactions_from_address"), - "ethereum_sepolia_transactions", + op.f("ix_sepolia_transactions_from_address"), + "sepolia_transactions", ["from_address"], unique=False, ) op.create_index( - op.f("ix_ethereum_sepolia_transactions_hash"), - "ethereum_sepolia_transactions", + op.f("ix_sepolia_transactions_hash"), + "sepolia_transactions", ["hash"], unique=True, ) op.create_index( - op.f("ix_ethereum_sepolia_transactions_index"), - "ethereum_sepolia_transactions", + op.f("ix_sepolia_transactions_index"), + "sepolia_transactions", ["index"], unique=False, ) op.create_index( - op.f("ix_ethereum_sepolia_transactions_selector"), - "ethereum_sepolia_transactions", + op.f("ix_sepolia_transactions_selector"), + "sepolia_transactions", ["selector"], unique=False, ) op.create_index( - op.f("ix_ethereum_sepolia_transactions_to_address"), - "ethereum_sepolia_transactions", + op.f("ix_sepolia_transactions_to_address"), + "sepolia_transactions", ["to_address"], unique=False, ) op.create_index( - op.f("ix_ethereum_sepolia_transactions_type"), - "ethereum_sepolia_transactions", + op.f("ix_sepolia_transactions_type"), + "sepolia_transactions", ["type"], unique=False, ) op.create_table( - "ethereum_sepolia_logs", + "sepolia_logs", sa.Column("transaction_hash", sa.VARCHAR(length=256), nullable=False), sa.Column("block_hash", sa.VARCHAR(length=256), nullable=False), sa.Column("address", sa.LargeBinary(length=20), nullable=False), @@ -166,48 +162,46 @@ def upgrade() -> None: ), sa.ForeignKeyConstraint( ["transaction_hash"], - ["ethereum_sepolia_transactions.hash"], - name=op.f( - "fk_ethereum_sepolia_logs_transaction_hash_ethereum_sepolia_transactions" - ), + ["sepolia_transactions.hash"], + name=op.f("fk_sepolia_logs_transaction_hash_sepolia_transactions"), ondelete="CASCADE", ), sa.PrimaryKeyConstraint( - "transaction_hash", "log_index", name="pk_ethereum_sepolia_log_index" + "transaction_hash", "log_index", name="pk_sepolia_log_index" ), sa.UniqueConstraint( "transaction_hash", "log_index", - name="uq_ethereum_sepolia_log_index_transaction_hash_log_index", + name="uq_sepolia_log_index_transaction_hash_log_index", ), ) op.create_index( - "idx_ethereum_sepolia_logs_address_selector", - "ethereum_sepolia_logs", + "idx_sepolia_logs_address_selector", + "sepolia_logs", ["address", "selector"], unique=False, ) op.create_index( - "idx_ethereum_sepolia_logs_block_hash_log_index", - "ethereum_sepolia_logs", + "idx_sepolia_logs_block_hash_log_index", + "sepolia_logs", ["block_hash", "log_index"], unique=True, ) op.create_index( - op.f("ix_ethereum_sepolia_logs_address"), - "ethereum_sepolia_logs", + op.f("ix_sepolia_logs_address"), + "sepolia_logs", ["address"], unique=False, ) op.create_index( - op.f("ix_ethereum_sepolia_logs_block_hash"), - "ethereum_sepolia_logs", + op.f("ix_sepolia_logs_block_hash"), + "sepolia_logs", ["block_hash"], unique=False, ) op.create_index( - op.f("ix_ethereum_sepolia_logs_transaction_hash"), - "ethereum_sepolia_logs", + op.f("ix_sepolia_logs_transaction_hash"), + "sepolia_logs", ["transaction_hash"], unique=False, ) @@ -217,72 +211,66 @@ def upgrade() -> None: def downgrade() -> None: # ### commands auto generated by Alembic - please adjust! ### op.drop_index( - op.f("ix_ethereum_sepolia_logs_transaction_hash"), - table_name="ethereum_sepolia_logs", - ) - op.drop_index( - op.f("ix_ethereum_sepolia_logs_block_hash"), table_name="ethereum_sepolia_logs" - ) - op.drop_index( - op.f("ix_ethereum_sepolia_logs_address"), table_name="ethereum_sepolia_logs" - ) - op.drop_index( - "idx_ethereum_sepolia_logs_block_hash_log_index", - table_name="ethereum_sepolia_logs", + op.f("ix_sepolia_logs_transaction_hash"), + table_name="sepolia_logs", ) + op.drop_index(op.f("ix_sepolia_logs_block_hash"), table_name="sepolia_logs") + op.drop_index(op.f("ix_sepolia_logs_address"), table_name="sepolia_logs") op.drop_index( - "idx_ethereum_sepolia_logs_address_selector", table_name="ethereum_sepolia_logs" + "idx_sepolia_logs_block_hash_log_index", + table_name="sepolia_logs", ) - op.drop_table("ethereum_sepolia_logs") + op.drop_index("idx_sepolia_logs_address_selector", table_name="sepolia_logs") + op.drop_table("sepolia_logs") op.drop_index( - op.f("ix_ethereum_sepolia_transactions_type"), - table_name="ethereum_sepolia_transactions", + op.f("ix_sepolia_transactions_type"), + table_name="sepolia_transactions", ) op.drop_index( - op.f("ix_ethereum_sepolia_transactions_to_address"), - table_name="ethereum_sepolia_transactions", + op.f("ix_sepolia_transactions_to_address"), + table_name="sepolia_transactions", ) op.drop_index( - op.f("ix_ethereum_sepolia_transactions_selector"), - table_name="ethereum_sepolia_transactions", + op.f("ix_sepolia_transactions_selector"), + table_name="sepolia_transactions", ) op.drop_index( - op.f("ix_ethereum_sepolia_transactions_index"), - table_name="ethereum_sepolia_transactions", + op.f("ix_sepolia_transactions_index"), + table_name="sepolia_transactions", ) op.drop_index( - op.f("ix_ethereum_sepolia_transactions_hash"), - table_name="ethereum_sepolia_transactions", + op.f("ix_sepolia_transactions_hash"), + table_name="sepolia_transactions", ) op.drop_index( - op.f("ix_ethereum_sepolia_transactions_from_address"), - table_name="ethereum_sepolia_transactions", + op.f("ix_sepolia_transactions_from_address"), + table_name="sepolia_transactions", ) op.drop_index( - op.f("ix_ethereum_sepolia_transactions_block_number"), - table_name="ethereum_sepolia_transactions", + op.f("ix_sepolia_transactions_block_number"), + table_name="sepolia_transactions", ) op.drop_index( - op.f("ix_ethereum_sepolia_transactions_block_hash"), - table_name="ethereum_sepolia_transactions", + op.f("ix_sepolia_transactions_block_hash"), + table_name="sepolia_transactions", ) - op.drop_table("ethereum_sepolia_transactions") + op.drop_table("sepolia_transactions") op.drop_index( - op.f("ix_ethereum_sepolia_reorgs_block_number"), - table_name="ethereum_sepolia_reorgs", + op.f("ix_sepolia_reorgs_block_number"), + table_name="sepolia_reorgs", ) op.drop_index( - op.f("ix_ethereum_sepolia_reorgs_block_hash"), - table_name="ethereum_sepolia_reorgs", + op.f("ix_sepolia_reorgs_block_hash"), + table_name="sepolia_reorgs", ) - op.drop_table("ethereum_sepolia_reorgs") + op.drop_table("sepolia_reorgs") op.drop_index( - op.f("ix_ethereum_sepolia_blocks_block_timestamp"), - table_name="ethereum_sepolia_blocks", + op.f("ix_sepolia_blocks_block_timestamp"), + table_name="sepolia_blocks", ) op.drop_index( - op.f("ix_ethereum_sepolia_blocks_block_number"), - table_name="ethereum_sepolia_blocks", + op.f("ix_sepolia_blocks_block_number"), + table_name="sepolia_blocks", ) - op.drop_table("ethereum_sepolia_blocks") + op.drop_table("sepolia_blocks") # ### end Alembic commands ### diff --git a/moonstreamdb-v3/moonstreamdbv3/models_indexes.py b/moonstreamdb-v3/moonstreamdbv3/models_indexes.py index d0802857..4afb8d2b 100644 --- a/moonstreamdb-v3/moonstreamdbv3/models_indexes.py +++ b/moonstreamdb-v3/moonstreamdbv3/models_indexes.py @@ -154,15 +154,15 @@ class EthereumReorgs(EvmBasedReorgs): class SepoliaBlockIndex(EvmBasedBlocks): - __tablename__ = "ethereum_sepolia_blocks" + __tablename__ = "sepolia_blocks" class SepoliaTransactionIndex(EvmBasedTransactions): - __tablename__ = "ethereum_sepolia_transactions" + __tablename__ = "sepolia_transactions" block_number = Column( BigInteger, - ForeignKey("ethereum_sepolia_blocks.block_number", ondelete="CASCADE"), + ForeignKey("sepolia_blocks.block_number", ondelete="CASCADE"), nullable=False, index=True, ) @@ -170,17 +170,17 @@ class SepoliaTransactionIndex(EvmBasedTransactions): class SepoliaLogIndex(EvmBasedLogs): - __tablename__ = "ethereum_sepolia_logs" + __tablename__ = "sepolia_logs" __table_args__ = ( Index( - "idx_ethereum_sepolia_logs_address_selector", + "idx_sepolia_logs_address_selector", "address", "selector", unique=False, ), Index( - "idx_ethereum_sepolia_logs_block_hash_log_index", + "idx_sepolia_logs_block_hash_log_index", "block_hash", "log_index", unique=True, @@ -188,22 +188,22 @@ class SepoliaLogIndex(EvmBasedLogs): UniqueConstraint( "transaction_hash", "log_index", - name="uq_ethereum_sepolia_log_index_transaction_hash_log_index", + name="uq_sepolia_log_index_transaction_hash_log_index", ), PrimaryKeyConstraint( - "transaction_hash", "log_index", name="pk_ethereum_sepolia_log_index" + "transaction_hash", "log_index", name="pk_sepolia_log_index" ), ) transaction_hash = Column( VARCHAR(256), - ForeignKey("ethereum_sepolia_transactions.hash", ondelete="CASCADE"), + ForeignKey("sepolia_transactions.hash", ondelete="CASCADE"), nullable=False, index=True, ) class SepoliaReorgs(EvmBasedReorgs): - __tablename__ = "ethereum_sepolia_reorgs" + __tablename__ = "sepolia_reorgs" ### Polygon From 484722bd967bdaead1ec69ee133c72d5f5385a5d Mon Sep 17 00:00:00 2001 From: kompotkot Date: Thu, 25 Jul 2024 11:35:45 +0000 Subject: [PATCH 08/11] Immutable zkEvm with it's sepolia migration for indexes --- ...9bc5_immutable_zkevm_with_it_s_sepolia_.py | 198 ++++++++++++++++++ .../moonstreamdbv3/models_indexes.py | 113 ++++++++++ moonstreamdb-v3/moonstreamdbv3/version.txt | 2 +- 3 files changed, 312 insertions(+), 1 deletion(-) create mode 100644 moonstreamdb-v3/moonstreamdbv3/alembic_indexes/versions/f19652e59bc5_immutable_zkevm_with_it_s_sepolia_.py diff --git a/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/versions/f19652e59bc5_immutable_zkevm_with_it_s_sepolia_.py b/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/versions/f19652e59bc5_immutable_zkevm_with_it_s_sepolia_.py new file mode 100644 index 00000000..3848860f --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/versions/f19652e59bc5_immutable_zkevm_with_it_s_sepolia_.py @@ -0,0 +1,198 @@ +"""Immutable zkEvm with it's sepolia blockchains + +Revision ID: f19652e59bc5 +Revises: a1ead76c0470 +Create Date: 2024-07-25 11:34:09.513131 + +""" +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision: str = 'f19652e59bc5' +down_revision: Union[str, None] = 'a1ead76c0470' +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('imx_zkevm_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('indexed_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.PrimaryKeyConstraint('block_number', name=op.f('pk_imx_zkevm_blocks')) + ) + op.create_index(op.f('ix_imx_zkevm_blocks_block_number'), 'imx_zkevm_blocks', ['block_number'], unique=False) + op.create_index(op.f('ix_imx_zkevm_blocks_block_timestamp'), 'imx_zkevm_blocks', ['block_timestamp'], unique=False) + op.create_table('imx_zkevm_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_imx_zkevm_reorgs')) + ) + op.create_index(op.f('ix_imx_zkevm_reorgs_block_hash'), 'imx_zkevm_reorgs', ['block_hash'], unique=False) + op.create_index(op.f('ix_imx_zkevm_reorgs_block_number'), 'imx_zkevm_reorgs', ['block_number'], unique=False) + op.create_table('imx_zkevm_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('indexed_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.PrimaryKeyConstraint('block_number', name=op.f('pk_imx_zkevm_sepolia_blocks')) + ) + op.create_index(op.f('ix_imx_zkevm_sepolia_blocks_block_number'), 'imx_zkevm_sepolia_blocks', ['block_number'], unique=False) + op.create_index(op.f('ix_imx_zkevm_sepolia_blocks_block_timestamp'), 'imx_zkevm_sepolia_blocks', ['block_timestamp'], unique=False) + op.create_table('imx_zkevm_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_imx_zkevm_sepolia_reorgs')) + ) + op.create_index(op.f('ix_imx_zkevm_sepolia_reorgs_block_hash'), 'imx_zkevm_sepolia_reorgs', ['block_hash'], unique=False) + op.create_index(op.f('ix_imx_zkevm_sepolia_reorgs_block_number'), 'imx_zkevm_sepolia_reorgs', ['block_number'], unique=False) + op.create_table('imx_zkevm_sepolia_transactions', + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('from_address', sa.LargeBinary(length=20), nullable=False), + sa.Column('to_address', sa.LargeBinary(length=20), nullable=False), + sa.Column('selector', sa.VARCHAR(length=256), nullable=True), + sa.Column('type', sa.Integer(), nullable=True), + sa.Column('row_id', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('index', sa.BigInteger(), nullable=False), + sa.Column('path', sa.Text(), nullable=False), + sa.Column('indexed_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.ForeignKeyConstraint(['block_number'], ['imx_zkevm_sepolia_blocks.block_number'], name=op.f('fk_imx_zkevm_sepolia_transactions_block_number_imx_zkevm_sepolia_blocks'), ondelete='CASCADE'), + sa.PrimaryKeyConstraint('hash', name=op.f('pk_imx_zkevm_sepolia_transactions')) + ) + op.create_index(op.f('ix_imx_zkevm_sepolia_transactions_block_hash'), 'imx_zkevm_sepolia_transactions', ['block_hash'], unique=False) + op.create_index(op.f('ix_imx_zkevm_sepolia_transactions_block_number'), 'imx_zkevm_sepolia_transactions', ['block_number'], unique=False) + op.create_index(op.f('ix_imx_zkevm_sepolia_transactions_from_address'), 'imx_zkevm_sepolia_transactions', ['from_address'], unique=False) + op.create_index(op.f('ix_imx_zkevm_sepolia_transactions_hash'), 'imx_zkevm_sepolia_transactions', ['hash'], unique=True) + op.create_index(op.f('ix_imx_zkevm_sepolia_transactions_index'), 'imx_zkevm_sepolia_transactions', ['index'], unique=False) + op.create_index(op.f('ix_imx_zkevm_sepolia_transactions_selector'), 'imx_zkevm_sepolia_transactions', ['selector'], unique=False) + op.create_index(op.f('ix_imx_zkevm_sepolia_transactions_to_address'), 'imx_zkevm_sepolia_transactions', ['to_address'], unique=False) + op.create_index(op.f('ix_imx_zkevm_sepolia_transactions_type'), 'imx_zkevm_sepolia_transactions', ['type'], unique=False) + op.create_table('imx_zkevm_transactions', + sa.Column('block_number', sa.BigInteger(), nullable=False), + sa.Column('hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('from_address', sa.LargeBinary(length=20), nullable=False), + sa.Column('to_address', sa.LargeBinary(length=20), nullable=False), + sa.Column('selector', sa.VARCHAR(length=256), nullable=True), + sa.Column('type', sa.Integer(), nullable=True), + sa.Column('row_id', sa.BigInteger(), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('index', sa.BigInteger(), nullable=False), + sa.Column('path', sa.Text(), nullable=False), + sa.Column('indexed_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.ForeignKeyConstraint(['block_number'], ['imx_zkevm_blocks.block_number'], name=op.f('fk_imx_zkevm_transactions_block_number_imx_zkevm_blocks'), ondelete='CASCADE'), + sa.PrimaryKeyConstraint('hash', name=op.f('pk_imx_zkevm_transactions')) + ) + op.create_index(op.f('ix_imx_zkevm_transactions_block_hash'), 'imx_zkevm_transactions', ['block_hash'], unique=False) + op.create_index(op.f('ix_imx_zkevm_transactions_block_number'), 'imx_zkevm_transactions', ['block_number'], unique=False) + op.create_index(op.f('ix_imx_zkevm_transactions_from_address'), 'imx_zkevm_transactions', ['from_address'], unique=False) + op.create_index(op.f('ix_imx_zkevm_transactions_hash'), 'imx_zkevm_transactions', ['hash'], unique=True) + op.create_index(op.f('ix_imx_zkevm_transactions_index'), 'imx_zkevm_transactions', ['index'], unique=False) + op.create_index(op.f('ix_imx_zkevm_transactions_selector'), 'imx_zkevm_transactions', ['selector'], unique=False) + op.create_index(op.f('ix_imx_zkevm_transactions_to_address'), 'imx_zkevm_transactions', ['to_address'], unique=False) + op.create_index(op.f('ix_imx_zkevm_transactions_type'), 'imx_zkevm_transactions', ['type'], unique=False) + op.create_table('imx_zkevm_logs', + sa.Column('transaction_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('address', sa.LargeBinary(length=20), nullable=False), + sa.Column('row_id', sa.BigInteger(), nullable=False), + sa.Column('selector', sa.VARCHAR(length=256), nullable=True), + sa.Column('topic1', sa.VARCHAR(length=256), nullable=True), + sa.Column('topic2', sa.VARCHAR(length=256), nullable=True), + sa.Column('topic3', sa.VARCHAR(length=256), nullable=True), + sa.Column('log_index', sa.BigInteger(), nullable=False), + sa.Column('path', sa.Text(), nullable=False), + sa.Column('indexed_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.ForeignKeyConstraint(['transaction_hash'], ['imx_zkevm_transactions.hash'], name=op.f('fk_imx_zkevm_logs_transaction_hash_imx_zkevm_transactions'), ondelete='CASCADE'), + sa.PrimaryKeyConstraint('transaction_hash', 'log_index', name='pk_imx_zkevm_log_index'), + sa.UniqueConstraint('transaction_hash', 'log_index', name='uq_imx_zkevm_log_index_transaction_hash_log_index') + ) + op.create_index('idx_imx_zkevm_logs_address_selector', 'imx_zkevm_logs', ['address', 'selector'], unique=False) + op.create_index('idx_imx_zkevm_logs_block_hash_log_index', 'imx_zkevm_logs', ['block_hash', 'log_index'], unique=True) + op.create_index(op.f('ix_imx_zkevm_logs_address'), 'imx_zkevm_logs', ['address'], unique=False) + op.create_index(op.f('ix_imx_zkevm_logs_block_hash'), 'imx_zkevm_logs', ['block_hash'], unique=False) + op.create_index(op.f('ix_imx_zkevm_logs_transaction_hash'), 'imx_zkevm_logs', ['transaction_hash'], unique=False) + op.create_table('imx_zkevm_sepolia_logs', + sa.Column('transaction_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('block_hash', sa.VARCHAR(length=256), nullable=False), + sa.Column('address', sa.LargeBinary(length=20), nullable=False), + sa.Column('row_id', sa.BigInteger(), nullable=False), + sa.Column('selector', sa.VARCHAR(length=256), nullable=True), + sa.Column('topic1', sa.VARCHAR(length=256), nullable=True), + sa.Column('topic2', sa.VARCHAR(length=256), nullable=True), + sa.Column('topic3', sa.VARCHAR(length=256), nullable=True), + sa.Column('log_index', sa.BigInteger(), nullable=False), + sa.Column('path', sa.Text(), nullable=False), + sa.Column('indexed_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', statement_timestamp())"), nullable=False), + sa.ForeignKeyConstraint(['transaction_hash'], ['imx_zkevm_sepolia_transactions.hash'], name=op.f('fk_imx_zkevm_sepolia_logs_transaction_hash_imx_zkevm_sepolia_transactions'), ondelete='CASCADE'), + sa.PrimaryKeyConstraint('transaction_hash', 'log_index', name='pk_imx_zkevm_sepolia_log_index'), + sa.UniqueConstraint('transaction_hash', 'log_index', name='uq_imx_zkevm_sepolia_log_index_transaction_hash_log_index') + ) + op.create_index('idx_imx_zkevm_sepolia_logs_address_selector', 'imx_zkevm_sepolia_logs', ['address', 'selector'], unique=False) + op.create_index('idx_imx_zkevm_sepolia_logs_block_hash_log_index', 'imx_zkevm_sepolia_logs', ['block_hash', 'log_index'], unique=True) + op.create_index(op.f('ix_imx_zkevm_sepolia_logs_address'), 'imx_zkevm_sepolia_logs', ['address'], unique=False) + op.create_index(op.f('ix_imx_zkevm_sepolia_logs_block_hash'), 'imx_zkevm_sepolia_logs', ['block_hash'], unique=False) + op.create_index(op.f('ix_imx_zkevm_sepolia_logs_transaction_hash'), 'imx_zkevm_sepolia_logs', ['transaction_hash'], unique=False) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_index(op.f('ix_imx_zkevm_sepolia_logs_transaction_hash'), table_name='imx_zkevm_sepolia_logs') + op.drop_index(op.f('ix_imx_zkevm_sepolia_logs_block_hash'), table_name='imx_zkevm_sepolia_logs') + op.drop_index(op.f('ix_imx_zkevm_sepolia_logs_address'), table_name='imx_zkevm_sepolia_logs') + op.drop_index('idx_imx_zkevm_sepolia_logs_block_hash_log_index', table_name='imx_zkevm_sepolia_logs') + op.drop_index('idx_imx_zkevm_sepolia_logs_address_selector', table_name='imx_zkevm_sepolia_logs') + op.drop_table('imx_zkevm_sepolia_logs') + op.drop_index(op.f('ix_imx_zkevm_logs_transaction_hash'), table_name='imx_zkevm_logs') + op.drop_index(op.f('ix_imx_zkevm_logs_block_hash'), table_name='imx_zkevm_logs') + op.drop_index(op.f('ix_imx_zkevm_logs_address'), table_name='imx_zkevm_logs') + op.drop_index('idx_imx_zkevm_logs_block_hash_log_index', table_name='imx_zkevm_logs') + op.drop_index('idx_imx_zkevm_logs_address_selector', table_name='imx_zkevm_logs') + op.drop_table('imx_zkevm_logs') + op.drop_index(op.f('ix_imx_zkevm_transactions_type'), table_name='imx_zkevm_transactions') + op.drop_index(op.f('ix_imx_zkevm_transactions_to_address'), table_name='imx_zkevm_transactions') + op.drop_index(op.f('ix_imx_zkevm_transactions_selector'), table_name='imx_zkevm_transactions') + op.drop_index(op.f('ix_imx_zkevm_transactions_index'), table_name='imx_zkevm_transactions') + op.drop_index(op.f('ix_imx_zkevm_transactions_hash'), table_name='imx_zkevm_transactions') + op.drop_index(op.f('ix_imx_zkevm_transactions_from_address'), table_name='imx_zkevm_transactions') + op.drop_index(op.f('ix_imx_zkevm_transactions_block_number'), table_name='imx_zkevm_transactions') + op.drop_index(op.f('ix_imx_zkevm_transactions_block_hash'), table_name='imx_zkevm_transactions') + op.drop_table('imx_zkevm_transactions') + op.drop_index(op.f('ix_imx_zkevm_sepolia_transactions_type'), table_name='imx_zkevm_sepolia_transactions') + op.drop_index(op.f('ix_imx_zkevm_sepolia_transactions_to_address'), table_name='imx_zkevm_sepolia_transactions') + op.drop_index(op.f('ix_imx_zkevm_sepolia_transactions_selector'), table_name='imx_zkevm_sepolia_transactions') + op.drop_index(op.f('ix_imx_zkevm_sepolia_transactions_index'), table_name='imx_zkevm_sepolia_transactions') + op.drop_index(op.f('ix_imx_zkevm_sepolia_transactions_hash'), table_name='imx_zkevm_sepolia_transactions') + op.drop_index(op.f('ix_imx_zkevm_sepolia_transactions_from_address'), table_name='imx_zkevm_sepolia_transactions') + op.drop_index(op.f('ix_imx_zkevm_sepolia_transactions_block_number'), table_name='imx_zkevm_sepolia_transactions') + op.drop_index(op.f('ix_imx_zkevm_sepolia_transactions_block_hash'), table_name='imx_zkevm_sepolia_transactions') + op.drop_table('imx_zkevm_sepolia_transactions') + op.drop_index(op.f('ix_imx_zkevm_sepolia_reorgs_block_number'), table_name='imx_zkevm_sepolia_reorgs') + op.drop_index(op.f('ix_imx_zkevm_sepolia_reorgs_block_hash'), table_name='imx_zkevm_sepolia_reorgs') + op.drop_table('imx_zkevm_sepolia_reorgs') + op.drop_index(op.f('ix_imx_zkevm_sepolia_blocks_block_timestamp'), table_name='imx_zkevm_sepolia_blocks') + op.drop_index(op.f('ix_imx_zkevm_sepolia_blocks_block_number'), table_name='imx_zkevm_sepolia_blocks') + op.drop_table('imx_zkevm_sepolia_blocks') + op.drop_index(op.f('ix_imx_zkevm_reorgs_block_number'), table_name='imx_zkevm_reorgs') + op.drop_index(op.f('ix_imx_zkevm_reorgs_block_hash'), table_name='imx_zkevm_reorgs') + op.drop_table('imx_zkevm_reorgs') + op.drop_index(op.f('ix_imx_zkevm_blocks_block_timestamp'), table_name='imx_zkevm_blocks') + op.drop_index(op.f('ix_imx_zkevm_blocks_block_number'), table_name='imx_zkevm_blocks') + op.drop_table('imx_zkevm_blocks') + # ### end Alembic commands ### diff --git a/moonstreamdb-v3/moonstreamdbv3/models_indexes.py b/moonstreamdb-v3/moonstreamdbv3/models_indexes.py index 4afb8d2b..d67d25c0 100644 --- a/moonstreamdb-v3/moonstreamdbv3/models_indexes.py +++ b/moonstreamdb-v3/moonstreamdbv3/models_indexes.py @@ -153,6 +153,9 @@ class EthereumReorgs(EvmBasedReorgs): __tablename__ = "ethereum_reorgs" +### Sepolia + + class SepoliaBlockIndex(EvmBasedBlocks): __tablename__ = "sepolia_blocks" @@ -612,6 +615,116 @@ class MantleSepoliaReorgs(EvmBasedReorgs): __tablename__ = "mantle_sepolia_reorgs" +### Immutable zkEvm + + +class ImxZkevmBlockIndex(EvmBasedBlocks): + __tablename__ = "imx_zkevm_blocks" + + +class ImxZkevmTransactionIndex(EvmBasedTransactions): + __tablename__ = "imx_zkevm_transactions" + + block_number = Column( + BigInteger, + ForeignKey("imx_zkevm_blocks.block_number", ondelete="CASCADE"), + nullable=False, + index=True, + ) + + +class ImxZkevmLogIndex(EvmBasedLogs): + __tablename__ = "imx_zkevm_logs" + + __table_args__ = ( + Index( + "idx_imx_zkevm_logs_address_selector", + "address", + "selector", + unique=False, + ), + Index( + "idx_imx_zkevm_logs_block_hash_log_index", + "block_hash", + "log_index", + unique=True, + ), + UniqueConstraint( + "transaction_hash", + "log_index", + name="uq_imx_zkevm_log_index_transaction_hash_log_index", + ), + PrimaryKeyConstraint( + "transaction_hash", "log_index", name="pk_imx_zkevm_log_index" + ), + ) + transaction_hash = Column( + VARCHAR(256), + ForeignKey("imx_zkevm_transactions.hash", ondelete="CASCADE"), + nullable=False, + index=True, + ) + + +class ImxZkevmReorgs(EvmBasedReorgs): + __tablename__ = "imx_zkevm_reorgs" + + +### Immutable zkEvm Sepolia + + +class ImxZkevmSepoliaBlockIndex(EvmBasedBlocks): + __tablename__ = "imx_zkevm_sepolia_blocks" + + +class ImxZkevmSepoliaTransactionIndex(EvmBasedTransactions): + __tablename__ = "imx_zkevm_sepolia_transactions" + + block_number = Column( + BigInteger, + ForeignKey("imx_zkevm_sepolia_blocks.block_number", ondelete="CASCADE"), + nullable=False, + index=True, + ) + + +class ImxZkevmSepoliaLogIndex(EvmBasedLogs): + __tablename__ = "imx_zkevm_sepolia_logs" + + __table_args__ = ( + Index( + "idx_imx_zkevm_sepolia_logs_address_selector", + "address", + "selector", + unique=False, + ), + Index( + "idx_imx_zkevm_sepolia_logs_block_hash_log_index", + "block_hash", + "log_index", + unique=True, + ), + UniqueConstraint( + "transaction_hash", + "log_index", + name="uq_imx_zkevm_sepolia_log_index_transaction_hash_log_index", + ), + PrimaryKeyConstraint( + "transaction_hash", "log_index", name="pk_imx_zkevm_sepolia_log_index" + ), + ) + transaction_hash = Column( + VARCHAR(256), + ForeignKey("imx_zkevm_sepolia_transactions.hash", ondelete="CASCADE"), + nullable=False, + index=True, + ) + + +class ImxZkevmSepoliaReorgs(EvmBasedReorgs): + __tablename__ = "imx_zkevm_sepolia_reorgs" + + ### ABI Jobs diff --git a/moonstreamdb-v3/moonstreamdbv3/version.txt b/moonstreamdb-v3/moonstreamdbv3/version.txt index 9789c4cc..ceddfb28 100644 --- a/moonstreamdb-v3/moonstreamdbv3/version.txt +++ b/moonstreamdb-v3/moonstreamdbv3/version.txt @@ -1 +1 @@ -0.0.14 +0.0.15 From f40a0779daf1ed822fb168b15fd1d0935c6c4e1e Mon Sep 17 00:00:00 2001 From: kompotkot Date: Thu, 25 Jul 2024 14:21:40 +0000 Subject: [PATCH 09/11] Imx zkevm with it's sepolia migration for customers db --- moonstreamdb-v3/moonstreamdbv3/alembic/env.py | 36 +++--- ...3e9f_immutable_zkevm_with_it_s_sepolia_.py | 122 ++++++++++++++++++ .../moonstreamdbv3/alembic_indexes/env.py | 66 ++++++---- moonstreamdb-v3/moonstreamdbv3/models.py | 92 ++++++++++++- 4 files changed, 272 insertions(+), 44 deletions(-) create mode 100644 moonstreamdb-v3/moonstreamdbv3/alembic/versions/211646463e9f_immutable_zkevm_with_it_s_sepolia_.py diff --git a/moonstreamdb-v3/moonstreamdbv3/alembic/env.py b/moonstreamdb-v3/moonstreamdbv3/alembic/env.py index b44365c1..88c4a2f3 100644 --- a/moonstreamdb-v3/moonstreamdbv3/alembic/env.py +++ b/moonstreamdb-v3/moonstreamdbv3/alembic/env.py @@ -1,9 +1,7 @@ from logging.config import fileConfig -from sqlalchemy import engine_from_config -from sqlalchemy import pool - from alembic import context +from sqlalchemy import engine_from_config, pool # this is the Alembic Config object, which provides # access to the values within the .ini file in use. @@ -27,30 +25,32 @@ # my_important_option = config.get_main_option("my_important_option") # ... etc. from moonstreamdbv3.models import ( - EthereumLabel, - SepoliaLabel, - PolygonLabel, - MumbaiLabel, AmoyLabel, - XDaiLabel, - ZkSyncEraLabel, - ZkSyncEraSepoliaLabel, - BaseLabel, ArbitrumNovaLabel, ArbitrumOneLabel, ArbitrumSepoliaLabel, - Game7OrbitArbitrumSepoliaLabel, - XaiLabel, - XaiSepoliaLabel, - AvalancheLabel, AvalancheFujiLabel, + AvalancheLabel, + BaseLabel, BlastLabel, BlastSepoliaLabel, + EthereumLabel, + Game7OrbitArbitrumSepoliaLabel, + ImxZkevmLabel, + ImxZkevmSepoliaLabel, + MantleLabel, + MantleSepoliaLabel, + MumbaiLabel, + PolygonLabel, ProofOfPlayApexLabel, + SepoliaLabel, StarknetLabel, StarknetSepoliaLabel, - MantleLabel, - MantleSepoliaLabel, + XaiLabel, + XaiSepoliaLabel, + XDaiLabel, + ZkSyncEraLabel, + ZkSyncEraSepoliaLabel, ) @@ -80,6 +80,8 @@ def include_symbol(tablename, schema): StarknetSepoliaLabel.__tablename__, MantleLabel.__tablename__, MantleSepoliaLabel.__tablename__, + ImxZkevmLabel.__tablename__, + ImxZkevmSepoliaLabel.__tablename__, } diff --git a/moonstreamdb-v3/moonstreamdbv3/alembic/versions/211646463e9f_immutable_zkevm_with_it_s_sepolia_.py b/moonstreamdb-v3/moonstreamdbv3/alembic/versions/211646463e9f_immutable_zkevm_with_it_s_sepolia_.py new file mode 100644 index 00000000..d6a3b73e --- /dev/null +++ b/moonstreamdb-v3/moonstreamdbv3/alembic/versions/211646463e9f_immutable_zkevm_with_it_s_sepolia_.py @@ -0,0 +1,122 @@ +"""Immutable zkEvm with it's sepolia blockchains + +Revision ID: 211646463e9f +Revises: 090c247f8618 +Create Date: 2024-07-25 14:14:41.548326 + +""" +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 = '211646463e9f' +down_revision: Union[str, None] = '090c247f8618' +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('imx_zkevm_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_imx_zkevm_labels')), + sa.UniqueConstraint('id', name=op.f('uq_imx_zkevm_labels_id')) + ) + op.create_index('ix_imx_zkevm_labels_addr_block_num', 'imx_zkevm_labels', ['address', 'block_number'], unique=False) + op.create_index('ix_imx_zkevm_labels_addr_block_ts', 'imx_zkevm_labels', ['address', 'block_timestamp'], unique=False) + op.create_index(op.f('ix_imx_zkevm_labels_address'), 'imx_zkevm_labels', ['address'], unique=False) + op.create_index(op.f('ix_imx_zkevm_labels_block_number'), 'imx_zkevm_labels', ['block_number'], unique=False) + op.create_index(op.f('ix_imx_zkevm_labels_caller_address'), 'imx_zkevm_labels', ['caller_address'], unique=False) + op.create_index(op.f('ix_imx_zkevm_labels_label'), 'imx_zkevm_labels', ['label'], unique=False) + op.create_index(op.f('ix_imx_zkevm_labels_label_name'), 'imx_zkevm_labels', ['label_name'], unique=False) + op.create_index(op.f('ix_imx_zkevm_labels_label_type'), 'imx_zkevm_labels', ['label_type'], unique=False) + op.create_index(op.f('ix_imx_zkevm_labels_origin_address'), 'imx_zkevm_labels', ['origin_address'], unique=False) + op.create_index(op.f('ix_imx_zkevm_labels_transaction_hash'), 'imx_zkevm_labels', ['transaction_hash'], unique=False) + op.create_index('uk_imx_zkevm_labels_tx_hash_log_idx_evt', 'imx_zkevm_labels', ['transaction_hash', 'log_index'], unique=True, postgresql_where=sa.text("label='seer' and label_type='event'")) + op.create_index('uk_imx_zkevm_labels_tx_hash_log_idx_evt_raw', 'imx_zkevm_labels', ['transaction_hash', 'log_index'], unique=True, postgresql_where=sa.text("label='seer-raw' and label_type='event'")) + op.create_index('uk_imx_zkevm_labels_tx_hash_tx_call', 'imx_zkevm_labels', ['transaction_hash'], unique=True, postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + op.create_index('uk_imx_zkevm_labels_tx_hash_tx_call_raw', 'imx_zkevm_labels', ['transaction_hash'], unique=True, postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'")) + op.create_table('imx_zkevm_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_imx_zkevm_sepolia_labels')), + sa.UniqueConstraint('id', name=op.f('uq_imx_zkevm_sepolia_labels_id')) + ) + op.create_index('ix_imx_zkevm_sepolia_labels_addr_block_num', 'imx_zkevm_sepolia_labels', ['address', 'block_number'], unique=False) + op.create_index('ix_imx_zkevm_sepolia_labels_addr_block_ts', 'imx_zkevm_sepolia_labels', ['address', 'block_timestamp'], unique=False) + op.create_index(op.f('ix_imx_zkevm_sepolia_labels_address'), 'imx_zkevm_sepolia_labels', ['address'], unique=False) + op.create_index(op.f('ix_imx_zkevm_sepolia_labels_block_number'), 'imx_zkevm_sepolia_labels', ['block_number'], unique=False) + op.create_index(op.f('ix_imx_zkevm_sepolia_labels_caller_address'), 'imx_zkevm_sepolia_labels', ['caller_address'], unique=False) + op.create_index(op.f('ix_imx_zkevm_sepolia_labels_label'), 'imx_zkevm_sepolia_labels', ['label'], unique=False) + op.create_index(op.f('ix_imx_zkevm_sepolia_labels_label_name'), 'imx_zkevm_sepolia_labels', ['label_name'], unique=False) + op.create_index(op.f('ix_imx_zkevm_sepolia_labels_label_type'), 'imx_zkevm_sepolia_labels', ['label_type'], unique=False) + op.create_index(op.f('ix_imx_zkevm_sepolia_labels_origin_address'), 'imx_zkevm_sepolia_labels', ['origin_address'], unique=False) + op.create_index(op.f('ix_imx_zkevm_sepolia_labels_transaction_hash'), 'imx_zkevm_sepolia_labels', ['transaction_hash'], unique=False) + op.create_index('uk_imx_zkevm_sepolia_labels_tx_hash_log_idx_evt', 'imx_zkevm_sepolia_labels', ['transaction_hash', 'log_index'], unique=True, postgresql_where=sa.text("label='seer' and label_type='event'")) + op.create_index('uk_imx_zkevm_sepolia_labels_tx_hash_log_idx_evt_raw', 'imx_zkevm_sepolia_labels', ['transaction_hash', 'log_index'], unique=True, postgresql_where=sa.text("label='seer-raw' and label_type='event'")) + op.create_index('uk_imx_zkevm_sepolia_labels_tx_hash_tx_call', 'imx_zkevm_sepolia_labels', ['transaction_hash'], unique=True, postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + op.create_index('uk_imx_zkevm_sepolia_labels_tx_hash_tx_call_raw', 'imx_zkevm_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_imx_zkevm_sepolia_labels_tx_hash_tx_call_raw', table_name='imx_zkevm_sepolia_labels', postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'")) + op.drop_index('uk_imx_zkevm_sepolia_labels_tx_hash_tx_call', table_name='imx_zkevm_sepolia_labels', postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + op.drop_index('uk_imx_zkevm_sepolia_labels_tx_hash_log_idx_evt_raw', table_name='imx_zkevm_sepolia_labels', postgresql_where=sa.text("label='seer-raw' and label_type='event'")) + op.drop_index('uk_imx_zkevm_sepolia_labels_tx_hash_log_idx_evt', table_name='imx_zkevm_sepolia_labels', postgresql_where=sa.text("label='seer' and label_type='event'")) + op.drop_index(op.f('ix_imx_zkevm_sepolia_labels_transaction_hash'), table_name='imx_zkevm_sepolia_labels') + op.drop_index(op.f('ix_imx_zkevm_sepolia_labels_origin_address'), table_name='imx_zkevm_sepolia_labels') + op.drop_index(op.f('ix_imx_zkevm_sepolia_labels_label_type'), table_name='imx_zkevm_sepolia_labels') + op.drop_index(op.f('ix_imx_zkevm_sepolia_labels_label_name'), table_name='imx_zkevm_sepolia_labels') + op.drop_index(op.f('ix_imx_zkevm_sepolia_labels_label'), table_name='imx_zkevm_sepolia_labels') + op.drop_index(op.f('ix_imx_zkevm_sepolia_labels_caller_address'), table_name='imx_zkevm_sepolia_labels') + op.drop_index(op.f('ix_imx_zkevm_sepolia_labels_block_number'), table_name='imx_zkevm_sepolia_labels') + op.drop_index(op.f('ix_imx_zkevm_sepolia_labels_address'), table_name='imx_zkevm_sepolia_labels') + op.drop_index('ix_imx_zkevm_sepolia_labels_addr_block_ts', table_name='imx_zkevm_sepolia_labels') + op.drop_index('ix_imx_zkevm_sepolia_labels_addr_block_num', table_name='imx_zkevm_sepolia_labels') + op.drop_table('imx_zkevm_sepolia_labels') + op.drop_index('uk_imx_zkevm_labels_tx_hash_tx_call_raw', table_name='imx_zkevm_labels', postgresql_where=sa.text("label='seer-raw' and label_type='tx_call'")) + op.drop_index('uk_imx_zkevm_labels_tx_hash_tx_call', table_name='imx_zkevm_labels', postgresql_where=sa.text("label='seer' and label_type='tx_call'")) + op.drop_index('uk_imx_zkevm_labels_tx_hash_log_idx_evt_raw', table_name='imx_zkevm_labels', postgresql_where=sa.text("label='seer-raw' and label_type='event'")) + op.drop_index('uk_imx_zkevm_labels_tx_hash_log_idx_evt', table_name='imx_zkevm_labels', postgresql_where=sa.text("label='seer' and label_type='event'")) + op.drop_index(op.f('ix_imx_zkevm_labels_transaction_hash'), table_name='imx_zkevm_labels') + op.drop_index(op.f('ix_imx_zkevm_labels_origin_address'), table_name='imx_zkevm_labels') + op.drop_index(op.f('ix_imx_zkevm_labels_label_type'), table_name='imx_zkevm_labels') + op.drop_index(op.f('ix_imx_zkevm_labels_label_name'), table_name='imx_zkevm_labels') + op.drop_index(op.f('ix_imx_zkevm_labels_label'), table_name='imx_zkevm_labels') + op.drop_index(op.f('ix_imx_zkevm_labels_caller_address'), table_name='imx_zkevm_labels') + op.drop_index(op.f('ix_imx_zkevm_labels_block_number'), table_name='imx_zkevm_labels') + op.drop_index(op.f('ix_imx_zkevm_labels_address'), table_name='imx_zkevm_labels') + op.drop_index('ix_imx_zkevm_labels_addr_block_ts', table_name='imx_zkevm_labels') + op.drop_index('ix_imx_zkevm_labels_addr_block_num', table_name='imx_zkevm_labels') + op.drop_table('imx_zkevm_labels') + # ### end Alembic commands ### diff --git a/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/env.py b/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/env.py index 8a31d7f6..d095e166 100644 --- a/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/env.py +++ b/moonstreamdb-v3/moonstreamdbv3/alembic_indexes/env.py @@ -1,9 +1,7 @@ from logging.config import fileConfig -from sqlalchemy import engine_from_config -from sqlalchemy import pool - from alembic import context +from sqlalchemy import engine_from_config, pool # this is the Alembic Config object, which provides # access to the values within the .ini file in use. @@ -28,44 +26,52 @@ # ... etc. from moonstreamdbv3.models_indexes import ( - EthereumBlockIndex, - EthereumTransactionIndex, - EthereumLogIndex, - EthereumReorgs, - PolygonBlockIndex, - PolygonTransactionIndex, - PolygonLogIndex, - PolygonReorgs, - XaiBlockIndex, - XaiTransactionIndex, - XaiLogIndex, - XaiReorgs, - XaiSepoliaBlockIndex, - XaiSepoliaTransactionIndex, - XaiSepoliaLogIndex, - XaiSepoliaReorgs, + AbiJobs, + AbiSubscriptions, ArbitrumOneBlockIndex, - ArbitrumOneTransactionIndex, ArbitrumOneLogIndex, ArbitrumOneReorgs, + ArbitrumOneTransactionIndex, ArbitrumSepoliaBlockIndex, - ArbitrumSepoliaTransactionIndex, ArbitrumSepoliaLogIndex, ArbitrumSepoliaReorgs, + ArbitrumSepoliaTransactionIndex, + EthereumBlockIndex, + EthereumLogIndex, + EthereumReorgs, + EthereumTransactionIndex, Game7OrbitArbitrumSepoliaBlockIndex, - Game7OrbitArbitrumSepoliaTransactionIndex, Game7OrbitArbitrumSepoliaLogIndex, Game7OrbitArbitrumSepoliaReorgs, + Game7OrbitArbitrumSepoliaTransactionIndex, + ImxZkevmBlockIndex, + ImxZkevmLogIndex, + ImxZkevmReorgs, + ImxZkevmSepoliaBlockIndex, + ImxZkevmSepoliaLogIndex, + ImxZkevmSepoliaReorgs, + ImxZkevmSepoliaTransactionIndex, + ImxZkevmTransactionIndex, MantleBlockIndex, - MantleTransactionIndex, MantleLogIndex, MantleReorgs, MantleSepoliaBlockIndex, - MantleSepoliaTransactionIndex, MantleSepoliaLogIndex, MantleSepoliaReorgs, - AbiJobs, - AbiSubscriptions, + MantleSepoliaTransactionIndex, + MantleTransactionIndex, + PolygonBlockIndex, + PolygonLogIndex, + PolygonReorgs, + PolygonTransactionIndex, + XaiBlockIndex, + XaiLogIndex, + XaiReorgs, + XaiSepoliaBlockIndex, + XaiSepoliaLogIndex, + XaiSepoliaReorgs, + XaiSepoliaTransactionIndex, + XaiTransactionIndex, ) @@ -109,6 +115,14 @@ def include_symbol(tablename, schema): MantleSepoliaReorgs.__tablename__, AbiJobs.__tablename__, AbiSubscriptions.__tablename__, + ImxZkevmBlockIndex.__tablename__, + ImxZkevmTransactionIndex.__tablename__, + ImxZkevmLogIndex.__tablename__, + ImxZkevmReorgs.__tablename__, + ImxZkevmSepoliaBlockIndex.__tablename__, + ImxZkevmSepoliaTransactionIndex.__tablename__, + ImxZkevmSepoliaLogIndex.__tablename__, + ImxZkevmSepoliaReorgs.__tablename__, } diff --git a/moonstreamdb-v3/moonstreamdbv3/models.py b/moonstreamdb-v3/moonstreamdbv3/models.py index 99a3f3c5..b7cdcc91 100644 --- a/moonstreamdb-v3/moonstreamdbv3/models.py +++ b/moonstreamdb-v3/moonstreamdbv3/models.py @@ -24,9 +24,9 @@ DateTime, Index, Integer, + LargeBinary, MetaData, Text, - LargeBinary, ) from sqlalchemy.dialects.postgresql import JSONB, UUID from sqlalchemy.ext.compiler import compiles @@ -1197,3 +1197,93 @@ class MantleSepoliaLabel(EvmBasedLabel): # type: ignore postgresql_where=text("label='seer-raw' and label_type='event'"), ), ) + + +class ImxZkevmLabel(EvmBasedLabel): # type: ignore + __tablename__ = "imx_zkevm_labels" + + __table_args__ = ( + Index( + "ix_imx_zkevm_labels_addr_block_num", + "address", + "block_number", + unique=False, + ), + Index( + "ix_imx_zkevm_labels_addr_block_ts", + "address", + "block_timestamp", + unique=False, + ), + Index( + "uk_imx_zkevm_labels_tx_hash_tx_call", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer' and label_type='tx_call'"), + ), + Index( + "uk_imx_zkevm_labels_tx_hash_log_idx_evt", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer' and label_type='event'"), + ), + Index( + "uk_imx_zkevm_labels_tx_hash_tx_call_raw", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='tx_call'"), + ), + Index( + "uk_imx_zkevm_labels_tx_hash_log_idx_evt_raw", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='event'"), + ), + ) + + +class ImxZkevmSepoliaLabel(EvmBasedLabel): # type: ignore + __tablename__ = "imx_zkevm_sepolia_labels" + + __table_args__ = ( + Index( + "ix_imx_zkevm_sepolia_labels_addr_block_num", + "address", + "block_number", + unique=False, + ), + Index( + "ix_imx_zkevm_sepolia_labels_addr_block_ts", + "address", + "block_timestamp", + unique=False, + ), + Index( + "uk_imx_zkevm_sepolia_labels_tx_hash_tx_call", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer' and label_type='tx_call'"), + ), + Index( + "uk_imx_zkevm_sepolia_labels_tx_hash_log_idx_evt", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer' and label_type='event'"), + ), + Index( + "uk_imx_zkevm_sepolia_labels_tx_hash_tx_call_raw", + "transaction_hash", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='tx_call'"), + ), + Index( + "uk_imx_zkevm_sepolia_labels_tx_hash_log_idx_evt_raw", + "transaction_hash", + "log_index", + unique=True, + postgresql_where=text("label='seer-raw' and label_type='event'"), + ), + ) From 3b4fee53cf389a299eb73b558caa33205138c51e Mon Sep 17 00:00:00 2001 From: kompotkot Date: Thu, 25 Jul 2024 14:55:17 +0000 Subject: [PATCH 10/11] Imx zkevm with it's sepolia types --- types/python/moonstreamtypes/blockchain.py | 12 ++++++++++++ types/python/moonstreamtypes/networks.py | 14 ++++++++++++++ types/python/moonstreamtypes/subscriptions.py | 12 ++++++++++++ types/python/setup.py | 2 +- 4 files changed, 39 insertions(+), 1 deletion(-) diff --git a/types/python/moonstreamtypes/blockchain.py b/types/python/moonstreamtypes/blockchain.py index 54a86074..df4116f5 100644 --- a/types/python/moonstreamtypes/blockchain.py +++ b/types/python/moonstreamtypes/blockchain.py @@ -79,6 +79,8 @@ from moonstreamdbv3.models import ( Game7OrbitArbitrumSepoliaLabel as Game7OrbitArbitrumSepoliaLabelV3, ) +from moonstreamdbv3.models import ImxZkevmLabel as ImxZkevmLabelV3 +from moonstreamdbv3.models import ImxZkevmSepoliaLabel as ImxZkevmSepoliaLabelV3 from moonstreamdbv3.models import MantleLabel as MantleLabelV3 from moonstreamdbv3.models import MantleSepoliaLabel as MantleSepoliaLabelV3 from moonstreamdbv3.models import MumbaiLabel as MumbaiLabelV3 @@ -121,6 +123,8 @@ class AvailableBlockchainType(Enum): STARKNET_SEPOLIA = "starknet_sepolia" MANTLE = "mantle" MANTLE_SEPOLIA = "mantle_sepolia" + IMX_ZKEVM = "imx_zkevm" + IMX_ZKEVM_SEPOLIA = "imx_zkevm_sepolia" def get_block_model( @@ -276,6 +280,8 @@ def get_label_model( StarknetSepoliaLabelV3, MantleLabelV3, MantleSepoliaLabelV3, + ImxZkevmLabelV3, + ImxZkevmSepoliaLabelV3, ] ]: """ @@ -332,6 +338,8 @@ def get_label_model( StarknetSepoliaLabelV3, MantleLabelV3, MantleSepoliaLabelV3, + ImxZkevmLabelV3, + ImxZkevmSepoliaLabelV3, ] ] if version == 2: @@ -428,6 +436,10 @@ def get_label_model( label_model = MantleLabelV3 elif blockchain_type == AvailableBlockchainType.MANTLE_SEPOLIA: label_model = MantleSepoliaLabelV3 + elif blockchain_type == AvailableBlockchainType.IMX_ZKEVM: + label_model = ImxZkevmLabelV3 + elif blockchain_type == AvailableBlockchainType.IMX_ZKEVM_SEPOLIA: + label_model = ImxZkevmSepoliaLabelV3 else: raise Exception("Unsupported blockchain type provided") else: diff --git a/types/python/moonstreamtypes/networks.py b/types/python/moonstreamtypes/networks.py index 00950fe9..cd9c65be 100644 --- a/types/python/moonstreamtypes/networks.py +++ b/types/python/moonstreamtypes/networks.py @@ -80,6 +80,8 @@ from moonstreamdbv3.models import ( Game7OrbitArbitrumSepoliaLabel as Game7OrbitArbitrumSepoliaLabelV3, ) +from moonstreamdbv3.models import ImxZkevmLabel as ImxZkevmLabelV3 +from moonstreamdbv3.models import ImxZkevmSepoliaLabel as ImxZkevmSepoliaLabelV3 from moonstreamdbv3.models import MantleLabel as MantleLabelV3 from moonstreamdbv3.models import MantleSepoliaLabel as MantleSepoliaLabelV3 from moonstreamdbv3.models import MumbaiLabel as MumbaiLabelV3 @@ -124,6 +126,8 @@ class Network(Enum): starknet_sepolia = "starknet_sepolia" mantle = "mantle" mantle_sepolia = "mantle_sepolia" + imx_zkevm = "imx_zkevm" + imx_zkevm_sepolia = "imx_zkevm_sepolia" tx_raw_types = Union[ @@ -331,6 +335,12 @@ class Network(Enum): Network.mantle_sepolia: { "labels": MantleSepoliaLabelV3, }, + Network.imx_zkevm: { + "labels": ImxZkevmLabelV3, + }, + Network.imx_zkevm_sepolia: { + "labels": ImxZkevmSepoliaLabelV3, + }, } @@ -390,5 +400,9 @@ def blockchain_type_to_network_type( return Network.mantle elif blockchain_type == AvailableBlockchainType.MANTLE_SEPOLIA: return Network.mantle_sepolia + elif blockchain_type == AvailableBlockchainType.IMX_ZKEVM: + return Network.imx_zkevm + elif blockchain_type == AvailableBlockchainType.IMX_ZKEVM_SEPOLIA: + return Network.imx_zkevm_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 dd10a9b2..07a401f1 100644 --- a/types/python/moonstreamtypes/subscriptions.py +++ b/types/python/moonstreamtypes/subscriptions.py @@ -32,6 +32,8 @@ class SubscriptionTypes(Enum): STARKNET_SEPOLIA_BLOCKCHAIN = "starknet_sepolia_smartcontract" MANTLE_BLOCKCHAIN = "mantle_smartcontract" MANTLE_SEPOLIA_BLOCKCHAIN = "mantle_sepolia_smartcontract" + IMX_ZKEVM_BLOCKCHAIN = "imx_zkevm_smartcontract" + IMX_ZKEVM_SEPOLIA_BLOCKCHAIN = "imx_zkevm_sepolia_smartcontract" def blockchain_type_to_subscription_type( @@ -89,6 +91,10 @@ def blockchain_type_to_subscription_type( return SubscriptionTypes.MANTLE_BLOCKCHAIN elif blockchain_type == AvailableBlockchainType.MANTLE_SEPOLIA: return SubscriptionTypes.MANTLE_SEPOLIA_BLOCKCHAIN + elif blockchain_type == AvailableBlockchainType.IMX_ZKEVM: + return SubscriptionTypes.IMX_ZKEVM_BLOCKCHAIN + elif blockchain_type == AvailableBlockchainType.IMX_ZKEVM_SEPOLIA: + return SubscriptionTypes.IMX_ZKEVM_SEPOLIA_BLOCKCHAIN else: raise ValueError(f"Unknown blockchain type: {blockchain_type}") @@ -120,6 +126,8 @@ def blockchain_type_to_subscription_type( "starknet_sepolia": "starknet_sepolia_smartcontract", "mantle": "mantle_smartcontract", "mantle_sepolia": "mantle_sepolia_smartcontract", + "imx_zkevm": "imx_zkevm_smartcontract", + "imx_zkevm_sepolia": "imx_zkevm_sepolia_smartcontract", } blockchain_by_subscription_id = { @@ -149,6 +157,8 @@ def blockchain_type_to_subscription_type( "starknet_sepolia_blockchain": "starknet_sepolia", "mantle_blockchain": "mantle", "mantle_sepolia_blockchain": "mantle_sepolia", + "imx_zkevm_blockchain": "imx_zkevm", + "imx_zkevm_sepolia_blockchain": "imx_zkevm_sepolia", "ethereum_smartcontract": "ethereum", "polygon_smartcontract": "polygon", "mumbai_smartcontract": "mumbai", @@ -174,4 +184,6 @@ def blockchain_type_to_subscription_type( "starknet_sepolia_smartcontract": "starknet_sepolia", "mantle_smartcontract": "mantle", "mantle_sepolia_smartcontract": "mantle_sepolia", + "imx_zkevm_smartcontract": "imx_zkevm", + "imx_zkevm_sepolia_smartcontract": "imx_zkevm_sepolia", } diff --git a/types/python/setup.py b/types/python/setup.py index f21ab72e..f7a9e351 100644 --- a/types/python/setup.py +++ b/types/python/setup.py @@ -34,7 +34,7 @@ zip_safe=False, install_requires=[ "moonstreamdb>=0.4.5", - "moonstreamdb-v3>=0.0.9", + "moonstreamdb-v3>=0.0.15", ], extras_require={ "dev": ["black", "isort", "mypy"], From ca8425fbfadae878dd21101716f073e573cd70bb Mon Sep 17 00:00:00 2001 From: kompotkot Date: Thu, 25 Jul 2024 15:15:46 +0000 Subject: [PATCH 11/11] Imx zkevm with it's sepolia for mapi --- moonstreamapi/configs/sample.env | 2 + .../moonstreamapi/admin/subscription_types.py | 99 ++++++++++++++----- moonstreamapi/moonstreamapi/settings.py | 17 +++- moonstreamapi/moonstreamapi/web3_provider.py | 6 ++ moonstreamapi/requirements.txt | 2 +- moonstreamapi/setup.py | 2 +- 6 files changed, 103 insertions(+), 25 deletions(-) diff --git a/moonstreamapi/configs/sample.env b/moonstreamapi/configs/sample.env index 5e010987..e9a897fa 100644 --- a/moonstreamapi/configs/sample.env +++ b/moonstreamapi/configs/sample.env @@ -37,6 +37,8 @@ export MOONSTREAM_BLAST_WEB3_PROVIDER_URI="https:// export MOONSTREAM_BLAST_SEPOLIA_WEB3_PROVIDER_URI="https://" export MOONSTREAM_MANTLE_WEB3_PROVIDER_URI="https://" export MOONSTREAM_MANTLE_SEPOLIA_WEB3_PROVIDER_URI="https://" +export MOONSTREAM_IMX_ZKEVM_WEB3_PROVIDER_URI="https://" +export MOONSTREAM_IMX_ZKEVM_SEPOLIA_WEB3_PROVIDER_URI="https://" export MOONSTREAM_QUERIES_JOURNAL_ID="" export MOONSTREAM_USAGE_REPORTS_JOURNAL_ID="" diff --git a/moonstreamapi/moonstreamapi/admin/subscription_types.py b/moonstreamapi/moonstreamapi/admin/subscription_types.py index 3284a9ed..c5e78ee9 100644 --- a/moonstreamapi/moonstreamapi/admin/subscription_types.py +++ b/moonstreamapi/moonstreamapi/admin/subscription_types.py @@ -238,6 +238,50 @@ stripe_price_id=None, active=True, ), + "mantle_smartcontract": SubscriptionTypeResourceData( + id="mantle_smartcontract", + name="Mantle smartcontract", + blockchain="mantle", + choices=["input:address", "tag:erc721"], + description="Contracts events and tx_calls of contract of Mantle blockchain.", + icon_url="https://static.simiotics.com/moonstream/assets/mantle-logo.png", + stripe_product_id=None, + stripe_price_id=None, + active=True, + ), + "mantle_sepolia_smartcontract": SubscriptionTypeResourceData( + id="mantle_sepolia_smartcontract", + name="Mantle Sepolia smartcontract", + blockchain="mantle_sepolia", + choices=["input:address", "tag:erc721"], + description="Contracts events and tx_calls of contract of Mantle Sepolia blockchain.", + icon_url="https://static.simiotics.com/moonstream/assets/mantle-sepolia-logo.png", + stripe_product_id=None, + stripe_price_id=None, + active=True, + ), + "imx_zkevm_smartcontract": SubscriptionTypeResourceData( + id="imx_zkevm_smartcontract", + name="Immutable zkEvm smartcontracts", + blockchain="imx_zkevm", + choices=["input:address", "tag:erc721"], + description="Contracts events and tx_calls of contract of Immutable zkEvm blockchain", + icon_url="https://static.simiotics.com/moonstream/assets/immutable-zkevm-icon-grey.png", + stripe_product_id=None, + stripe_price_id=None, + active=True, + ), + "imx_zkevm_sepolia_smartcontract": SubscriptionTypeResourceData( + id="imx_zkevm_sepolia_smartcontract", + name="Immutable zkEvm Sepolia smartcontracts", + blockchain="imx_zkevm_sepolia", + choices=["input:address", "tag:erc721"], + description="Contracts events and tx_calls of contract of Immutable zkEvm Sepolia blockchain", + icon_url="https://static.simiotics.com/moonstream/assets/immutable-zkevm-icon-grey.png", + stripe_product_id=None, + stripe_price_id=None, + active=True, + ), "ethereum_blockchain": SubscriptionTypeResourceData( id="ethereum_blockchain", name="Ethereum transactions", @@ -271,28 +315,6 @@ stripe_price_id=None, active=False, ), - "mantle_smartcontract": SubscriptionTypeResourceData( - id="mantle_smartcontract", - name="Mantle smartcontract", - blockchain="mantle", - choices=["input:address", "tag:erc721"], - description="Contracts events and tx_calls of contract of Mantle blockchain.", - icon_url="https://static.simiotics.com/moonstream/assets/mantle-logo.png", - stripe_product_id=None, - stripe_price_id=None, - active=True, - ), - "mantle_sepolia_smartcontract": SubscriptionTypeResourceData( - id="mantle_sepolia_smartcontract", - name="Mantle Sepolia smartcontract", - blockchain="mantle_sepolia", - choices=["input:address", "tag:erc721"], - description="Contracts events and tx_calls of contract of Mantle Sepolia blockchain.", - icon_url="https://static.simiotics.com/moonstream/assets/mantle-sepolia-logo.png", - stripe_product_id=None, - stripe_price_id=None, - active=True, - ), "mumbai_blockchain": SubscriptionTypeResourceData( id="mumbai_blockchain", name="Mumbai transactions", @@ -525,6 +547,39 @@ stripe_price_id=None, active=False, ), + "sepolia_blockchain": SubscriptionTypeResourceData( + id="sepolia_blockchain", + name="Sepolia transactions", + blockchain="sepolia", + choices=["input:address", "tag:erc721"], + description="Sepolia chain transactions subscription.", + icon_url="https://static.simiotics.com/moonstream/assets/ethereum/eth-diamond-purple.png", + stripe_product_id=None, + stripe_price_id=None, + active=False, + ), + "imx_zkevm_blockchain": SubscriptionTypeResourceData( + id="imx_zkevm_blockchain", + name="Immutable zkEvm transactions", + blockchain="imx_zkevm", + choices=["input:address", "tag:erc721"], + description="Immutable zkEvm chain transactions subscription.", + icon_url="https://static.simiotics.com/moonstream/assets/immutable-zkevm-icon-grey.png", + stripe_product_id=None, + stripe_price_id=None, + active=False, + ), + "imx_zkevm_sepolia_blockchain": SubscriptionTypeResourceData( + id="imx_zkevm_sepolia_blockchain", + name="Immutable zkEvm Sepolia transactions", + blockchain="imx_zkevm_sepolia", + choices=["input:address", "tag:erc721"], + description="Immutable zkEvm Sepolia chain transactions subscription.", + icon_url="https://static.simiotics.com/moonstream/assets/immutable-zkevm-icon-grey.png", + stripe_product_id=None, + stripe_price_id=None, + active=False, + ), } diff --git a/moonstreamapi/moonstreamapi/settings.py b/moonstreamapi/moonstreamapi/settings.py index 86d81a20..118f538d 100644 --- a/moonstreamapi/moonstreamapi/settings.py +++ b/moonstreamapi/moonstreamapi/settings.py @@ -168,7 +168,6 @@ "MOONSTREAM_ZKSYNC_ERA_SEPOLIA_WEB3_PROVIDER_URI env variable is not set" ) - MOONSTREAM_ARBITRUM_ONE_WEB3_PROVIDER_URI = os.environ.get( "MOONSTREAM_ARBITRUM_ONE_WEB3_PROVIDER_URI", "" ) @@ -252,6 +251,22 @@ "MOONSTREAM_MANTLE_SEPOLIA_WEB3_PROVIDER_URI env variable is not set" ) +MOONSTREAM_IMX_ZKEVM_WEB3_PROVIDER_URI = os.environ.get( + "MOONSTREAM_IMX_ZKEVM_WEB3_PROVIDER_URI", "" +) +if MOONSTREAM_IMX_ZKEVM_WEB3_PROVIDER_URI == "": + raise ValueError( + "MOONSTREAM_IMX_ZKEVM_WEB3_PROVIDER_URI environment variable must be set" + ) + +MOONSTREAM_IMX_ZKEVM_SEPOLIA_WEB3_PROVIDER_URI = os.environ.get( + "MOONSTREAM_IMX_ZKEVM_SEPOLIA_WEB3_PROVIDER_URI", "" +) +if MOONSTREAM_IMX_ZKEVM_SEPOLIA_WEB3_PROVIDER_URI == "": + raise ValueError( + "MOONSTREAM_IMX_ZKEVM_SEPOLIA_WEB3_PROVIDER_URI environment variable must be set" + ) + ## QueryAPI MOONSTREAM_S3_QUERIES_BUCKET = os.environ.get("MOONSTREAM_S3_QUERIES_BUCKET", "") diff --git a/moonstreamapi/moonstreamapi/web3_provider.py b/moonstreamapi/moonstreamapi/web3_provider.py index ad099cea..b4ba719d 100644 --- a/moonstreamapi/moonstreamapi/web3_provider.py +++ b/moonstreamapi/moonstreamapi/web3_provider.py @@ -21,6 +21,8 @@ MOONSTREAM_BLAST_SEPOLIA_WEB3_PROVIDER_URI, MOONSTREAM_BLAST_WEB3_PROVIDER_URI, MOONSTREAM_ETHEREUM_WEB3_PROVIDER_URI, + MOONSTREAM_IMX_ZKEVM_SEPOLIA_WEB3_PROVIDER_URI, + MOONSTREAM_IMX_ZKEVM_WEB3_PROVIDER_URI, MOONSTREAM_MANTLE_SEPOLIA_WEB3_PROVIDER_URI, MOONSTREAM_MANTLE_WEB3_PROVIDER_URI, MOONSTREAM_MUMBAI_WEB3_PROVIDER_URI, @@ -118,6 +120,10 @@ def connect( web3_uri = MOONSTREAM_MANTLE_WEB3_PROVIDER_URI elif blockchain_type == AvailableBlockchainType.MANTLE_SEPOLIA: web3_uri = MOONSTREAM_MANTLE_SEPOLIA_WEB3_PROVIDER_URI + elif blockchain_type == AvailableBlockchainType.IMX_ZKEVM: + web3_uri = MOONSTREAM_IMX_ZKEVM_WEB3_PROVIDER_URI + elif blockchain_type == AvailableBlockchainType.IMX_ZKEVM_SEPOLIA: + web3_uri = MOONSTREAM_IMX_ZKEVM_SEPOLIA_WEB3_PROVIDER_URI else: raise Exception("Wrong blockchain type provided for web3 URI") diff --git a/moonstreamapi/requirements.txt b/moonstreamapi/requirements.txt index 1bb95ee8..d49a32c8 100644 --- a/moonstreamapi/requirements.txt +++ b/moonstreamapi/requirements.txt @@ -38,7 +38,7 @@ Mako==1.2.3 MarkupSafe==2.1.1 moonstream==0.1.1 moonstreamdb==0.4.5 -moonstreamdb-v3==0.0.13 +moonstreamdb-v3==0.0.15 multiaddr==0.0.9 multidict==6.0.2 netaddr==0.8.0 diff --git a/moonstreamapi/setup.py b/moonstreamapi/setup.py index 4983a6cf..79c1f301 100644 --- a/moonstreamapi/setup.py +++ b/moonstreamapi/setup.py @@ -17,7 +17,7 @@ "fastapi", "moonstream", "moonstreamdb>=0.4.5", - "moonstreamdb-v3>=0.0.13", + "moonstreamdb-v3>=0.0.15", "humbug", "pydantic==1.10.2", "pyevmasm",