Automated Action 5bb78bd9be Implement Solana arbitrage analytics backend
- Create project structure with FastAPI
- Add database models for blocks, transactions, arbitrages, pools, and DEXes
- Implement Solana RPC client for fetching blockchain data
- Create arbitrage detection algorithm
- Implement comprehensive API endpoints for analytics
- Set up database migrations with Alembic
- Add detailed project documentation

generated with BackendIM... (backend.im)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-05-12 14:13:06 +00:00

45 lines
2.0 KiB
Python

from datetime import datetime
from sqlalchemy import (
Column, Integer, String, DateTime, Float,
BigInteger, ForeignKey, JSON, Boolean
)
from sqlalchemy.orm import relationship
from app.db.base_class import Base
class Pool(Base):
"""Liquidity pool model."""
id = Column(Integer, primary_key=True, index=True)
dex_id = Column(Integer, ForeignKey("dex.id"), nullable=False)
address = Column(String, unique=True, index=True, nullable=False)
token_a_address = Column(String, index=True, nullable=False)
token_a_symbol = Column(String, nullable=True)
token_a_name = Column(String, nullable=True)
token_a_decimals = Column(Integer, nullable=True)
token_b_address = Column(String, index=True, nullable=False)
token_b_symbol = Column(String, nullable=True)
token_b_name = Column(String, nullable=True)
token_b_decimals = Column(Integer, nullable=True)
token_a_reserve = Column(Float, nullable=True)
token_b_reserve = Column(Float, nullable=True)
last_updated_slot = Column(BigInteger, nullable=True)
volume_24h = Column(Float, nullable=True)
fees_24h = Column(Float, nullable=True)
tvl = Column(Float, nullable=True) # Total Value Locked in USD
fee_rate = Column(Float, nullable=True) # Pool fee percentage
pool_type = Column(String, nullable=True) # Constant product, stable, etc.
is_active = Column(Boolean, default=True, nullable=False)
metadata = Column(JSON, nullable=True) # Additional pool-specific data
created_at = Column(DateTime, default=datetime.utcnow, nullable=False)
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False)
# Relationships
dex = relationship("Dex", back_populates="pools")
arbitrage_legs = relationship("ArbitrageLeg", back_populates="pool")
def __repr__(self):
token_a = self.token_a_symbol or self.token_a_address[:8]
token_b = self.token_b_symbol or self.token_b_address[:8]
return f"<Pool(address={self.address}, pair={token_a}-{token_b})>"