
Renamed 'pool_metadata' to 'extra_data' in Pool model, schema, and migrations to avoid conflicts with SQLAlchemy's reserved 'metadata' attribute name. Generated with BackendIM... (backend.im)
45 lines
2.0 KiB
Python
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)
|
|
extra_data = 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})>" |