new error column

This commit is contained in:
Taarush Vemulapalli 2021-12-21 17:57:07 -05:00
parent bb0420fd78
commit b59daa8269
7 changed files with 54 additions and 1 deletions

View File

@ -0,0 +1,23 @@
"""error column
Revision ID: 99d376cb93cc
Revises: c4a7620a2d33
Create Date: 2021-12-21 21:26:12.142484
"""
import sqlalchemy as sa
from alembic import op
# revision identifiers, used by Alembic.
revision = "99d376cb93cc"
down_revision = "c4a7620a2d33"
branch_labels = None
depends_on = None
def upgrade():
op.add_column("arbitrages", sa.Column("error", sa.String(256), nullable=True))
def downgrade():
op.drop_column("arbitrages", "error")

View File

@ -52,6 +52,11 @@ def _get_arbitrages_from_swaps(swaps: List[Swap]) -> List[Arbitrage]:
] ]
routes = _get_all_routes(start, end, potential_intermediate_swaps) routes = _get_all_routes(start, end, potential_intermediate_swaps)
error = ""
for swap in swaps:
if swap.error is not None:
error = swap.error
for route in routes: for route in routes:
start_amount = route[0].token_in_amount start_amount = route[0].token_in_amount
end_amount = route[-1].token_out_amount end_amount = route[-1].token_out_amount
@ -66,6 +71,7 @@ def _get_arbitrages_from_swaps(swaps: List[Swap]) -> List[Arbitrage]:
start_amount=start_amount, start_amount=start_amount,
end_amount=end_amount, end_amount=end_amount,
profit_amount=profit_amount, profit_amount=profit_amount,
error=error,
) )
all_arbitrages.append(arb) all_arbitrages.append(arb)
if len(all_arbitrages) == 1: if len(all_arbitrages) == 1:

View File

@ -40,6 +40,7 @@ def write_arbitrages(
start_amount=arbitrage.start_amount, start_amount=arbitrage.start_amount,
end_amount=arbitrage.end_amount, end_amount=arbitrage.end_amount,
profit_amount=arbitrage.profit_amount, profit_amount=arbitrage.profit_amount,
error=arbitrage.error,
) )
) )

View File

@ -14,3 +14,4 @@ class ArbitrageModel(Base):
start_amount = Column(Numeric, nullable=False) start_amount = Column(Numeric, nullable=False)
end_amount = Column(Numeric, nullable=False) end_amount = Column(Numeric, nullable=False)
profit_amount = Column(Numeric, nullable=False) profit_amount = Column(Numeric, nullable=False)
error = Column(String, nullable=True)

View File

@ -1,4 +1,4 @@
from typing import List from typing import List, Optional
from pydantic import BaseModel from pydantic import BaseModel
@ -14,3 +14,4 @@ class Arbitrage(BaseModel):
start_amount: int start_amount: int
end_amount: int end_amount: int
profit_amount: int profit_amount: int
error: Optional[str]

File diff suppressed because one or more lines are too long

View File

@ -57,3 +57,23 @@ def test_arbitrage_real_block(trace_classifier: TraceClassifier):
== "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48" == "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"
) )
assert arbitrage_2.profit_amount == 53560707941943273628 assert arbitrage_2.profit_amount == 53560707941943273628
def test_reverting_arbitrage(trace_classifier: TraceClassifier):
block = load_test_block(11473321)
classified_traces = trace_classifier.classify(block.traces)
swaps = get_swaps(classified_traces)
assert len(swaps) == 38
arbitrages = get_arbitrages(list(swaps))
assert len(arbitrages) == 21
arbitrage_1 = [
arb
for arb in arbitrages
if arb.transaction_hash
== "0x565146ec57af69208b4a37e3a138ab85c6a6ff358fffb0077824a7378a67c4d6"
][0]
assert arbitrage_1.error == "Reverted"