diff --git a/alembic/versions/a5a44a7c854d_create_total_profit_by_block_table.py b/alembic/versions/a5a44a7c854d_create_total_profit_by_block_table.py new file mode 100644 index 0000000..c88b154 --- /dev/null +++ b/alembic/versions/a5a44a7c854d_create_total_profit_by_block_table.py @@ -0,0 +1,31 @@ +"""create total profit by block table + +Revision ID: a5a44a7c854d +Revises: 5c5375de15fd +Create Date: 2022-12-12 02:46:57.125040 + +""" +import sqlalchemy as sa +from alembic import op + +# revision identifiers, used by Alembic. +revision = "a5a44a7c854d" +down_revision = "5c5375de15fd" +branch_labels = None +depends_on = None + + +def upgrade(): + op.create_table( + "total_profit_by_block", + sa.Column("block_number", sa.Numeric, primary_key=True), + sa.Column("transaction_hash", sa.String(66), nullable=False), + sa.Column("token_debt", sa.String(66), nullable=True), + sa.Column("amount_debt", sa.Numeric, nullable=False), + sa.Column("token_received", sa.String(66), nullable=False), + sa.Column("amount_received", sa.Numeric, nullable=False), + ) + + +def downgrade(): + op.drop_table("total_profit_by_block") diff --git a/mev_inspect/crud/total_profits.py b/mev_inspect/crud/total_profits.py new file mode 100644 index 0000000..0d418b8 --- /dev/null +++ b/mev_inspect/crud/total_profits.py @@ -0,0 +1,22 @@ +from typing import List + +from mev_inspect.db import write_as_csv +from mev_inspect.schemas.total_profits import TotalProfits + + +def write_total_profits_for_blocks( + inspect_db_session, + total_profits_for_blocks: List[TotalProfits], +) -> None: + items_generator = ( + ( + total_profits_for_unique_block.block_number, + total_profits_for_unique_block.transaction_hash, + total_profits_for_unique_block.token_debt, + total_profits_for_unique_block.amount_debt, + total_profits_for_unique_block.token_received, + total_profits_for_unique_block.amount_received, + ) + for total_profits_for_unique_block in total_profits_for_blocks + ) + write_as_csv(inspect_db_session, "total_profit_by_block", items_generator) diff --git a/mev_inspect/schemas/total_profits.py b/mev_inspect/schemas/total_profits.py new file mode 100644 index 0000000..13c536c --- /dev/null +++ b/mev_inspect/schemas/total_profits.py @@ -0,0 +1,10 @@ +from pydantic import BaseModel + + +class TotalProfits(BaseModel): + block_number: int + transaction_hash: str + token_debt: str + amount_debt: int + token_received: str + amount_received: int