Skip to content

Commit

Permalink
Merge pull request #449 from binayak9932/hastack_remove
Browse files Browse the repository at this point in the history
[DataHandler] Clean up Hashtack
  • Loading branch information
djeck1432 authored Feb 22, 2025
2 parents 027034a + 55dcc4e commit 5a68ad2
Show file tree
Hide file tree
Showing 22 changed files with 8 additions and 2,483 deletions.
12 changes: 2 additions & 10 deletions apps/data_handler/celery_app/celery_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
Celery configuration for scheduling periodic tasks.
"""

# run_loan_states_computation_for_hashtack_v0,;
# run_loan_states_computation_for_hashtack_v1,; run_loan_states_computation_for_nostra_alpha,;

# run_loan_states_computation_for_nostra_mainnet,; run_loan_states_computation_for_zklend,;
# run_liquidable_debt_computation_for_nostra_alpha,;
# run_liquidable_debt_computation_for_nostra_mainnet,;
Expand Down Expand Up @@ -36,13 +35,6 @@
CRONTAB_TIME = os.environ.get("CRONTAB_TIME", "5")

app.conf.beat_schedule = {
# f'run_loan_states_computation_for_hashtack_v0_every_{CRONTAB_TIME}_mins': {
# 'task': 'run_loan_states_computation_for_hashtack_v0',
# 'schedule': crontab(minute=f'*/{CRONTAB_TIME}'),
# },
# f'run_loan_states_computation_for_hashtack_v1_every_{CRONTAB_TIME}_mins': {
# 'task': 'run_loan_states_computation_for_hashtack_v1',
# 'schedule': crontab(minute=f'*/{CRONTAB_TIME}'),
# },
# f'run_loan_states_computation_for_zklend_every_{CRONTAB_TIME}_mins': {
# 'task': 'run_loan_states_computation_for_zklend',
Expand Down Expand Up @@ -81,7 +73,7 @@
from data_handler.celery_app.order_books_tasks import ekubo_order_book
from data_handler.celery_app.tasks import run_liquidable_debt_computation_for_zklend

# run_loan_states_computation_for_hashtack_v0,; run_loan_states_computation_for_hashtack_v1,;

# run_loan_states_computation_for_nostra_alpha,; run_loan_states_computation_for_nostra_mainnet,;
# run_loan_states_computation_for_zklend,; run_liquidable_debt_computation_for_nostra_alpha,;
# run_liquidable_debt_computation_for_nostra_mainnet,;
Expand Down
29 changes: 0 additions & 29 deletions apps/data_handler/celery_app/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
zklend,
)

# from data_handler.handlers.loan_states.hashtack_v0.run import HashtackV0StateComputation
# from data_handler.handlers.loan_states.hashtack_v1.run import HashtackV1StateComputation
# from data_handler.handlers.loan_states.zklend.run import ZkLendLoanStateComputation
from data_handler.handlers.loan_states.nostra_alpha.run import (
NostraAlphaStateComputation,
Expand All @@ -30,33 +28,6 @@

connector = DBConnector()

# @app.task(name="run_loan_states_computation_for_hashtack_v0")
# def run_loan_states_computation_for_hashtack_v0():
# start = monotonic()
# logging.basicConfig(level=logging.INFO)
#
# logging.info("Starting Hashtack V0 loan state computation")
# computation = HashtackV0StateComputation()
# computation.run()
#
# logging.info(
# "Finished Hashtack V0 loan state computation, Time taken: %s seconds",
# monotonic() - start,
# )

# @app.task(name="run_loan_states_computation_for_hashtack_v1")
# def run_loan_states_computation_for_hashtack_v1():
# start = monotonic()
# logging.basicConfig(level=logging.INFO)
#
# logging.info("Starting Hashtack V1 loan state computation")
# computation = HashtackV1StateComputation()
# computation.run()
#
# logging.info(
# "Finished Hashtack V1 loan state computation, Time taken: %s seconds",
# monotonic() - start,
# )

# @app.task(name="run_loan_states_computation_for_zklend")
# def run_loan_states_computation_for_zklend():
Expand Down
105 changes: 0 additions & 105 deletions apps/data_handler/db/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from data_handler.db.database import SQLALCHEMY_DATABASE_URL
from data_handler.db.models import (
Base,
HashtackCollateralDebt,
InterestRate,
LoanState,
OrderBookModel,
Expand Down Expand Up @@ -195,23 +194,6 @@ def get_loans(
finally:
db.close()

def get_last_hashstack_loan_state(self, user_id: str) -> HashtackCollateralDebt:
"""
Retrieves the last loan state for a given user_id.
:param user_id: str - The user ID to filter by.
:return: HashtackCollateralDebt | None
"""
db = self.Session()
try:
return (
db.query(HashtackCollateralDebt)
.filter(HashtackCollateralDebt.user_id == user_id)
.order_by(HashtackCollateralDebt.loan_id.desc())
.first()
)
finally:
db.close()

def get_last_block(self, protocol_id: ProtocolIDs) -> int:
"""
Retrieves the last (highest) block number from the database filtered by protocol_id.
Expand Down Expand Up @@ -496,26 +478,6 @@ def get_zklend_by_user_ids(self, user_ids: List[str]) -> List[ZkLendCollateralDe
finally:
session.close()

def get_hashtack_by_loan_ids(
self, loan_ids: List[str], version: int
) -> List[HashtackCollateralDebt]:
"""
Retrieve HashtackCollateralDebt records by loan_ids.
:param loan_ids: A list of user IDs to filter by.
:param version: The version of the hashtack.
:return: A list of HashtackCollateralDebt objects.
"""
session = self.Session()
try:
return (
session.query(HashtackCollateralDebt)
.filter(HashtackCollateralDebt.loan_id.in_(loan_ids))
.filter(HashtackCollateralDebt.version == version)
.all()
)
finally:
session.close()

@staticmethod
def _convert_decimal_to_float(data: dict | None) -> dict | None:
"""
Expand Down Expand Up @@ -572,73 +534,6 @@ def save_collateral_enabled_by_user(
finally:
session.close()

def save_debt_category(
self,
user_id: str,
loan_id: str,
debt_category: str,
collateral: dict,
debt: dict,
original_collateral: dict,
borrowed_collateral: dict,
version: int,
) -> None:
"""
Update the debt category for a given user_id.
:param user_id: The user ID to update.
:param loan_id: The loan ID to update.
:param debt_category: The new debt category.
:param collateral: The new collateral data.
:param debt: The new debt data.
:param original_collateral: The new original collateral data.
:param borrowed_collateral: The new borrowed collateral data.
:param version: The version of the hashtack.
:return: None
"""
session = self.Session()
# convert Decimal to float for JSON serialization
collateral = self._convert_decimal_to_float(collateral)
debt = self._convert_decimal_to_float(debt)
original_collateral = self._convert_decimal_to_float(original_collateral)
borrowed_collateral = self._convert_decimal_to_float(borrowed_collateral)

try:
record = (
session.query(HashtackCollateralDebt).filter_by(loan_id=loan_id).first()
)
logger.info(f"Going to save loan_id {loan_id}")
# if debt category is the same, update the record
if record and record.debt_category == debt_category:
return
# if record exists, and debt category is different, update the record
elif record and record.debt_category != debt_category:
record.loan_id = loan_id
record.debt_category = debt_category
record.collateral = collateral
record.debt = debt
record.original_collateral = original_collateral
record.borrowed_collateral = borrowed_collateral
else:
# Create new record if not yet created for this user
new_record = HashtackCollateralDebt(
user_id=user_id,
loan_id=loan_id,
# collateral
collateral=collateral,
original_collateral=original_collateral,
# debt
debt=debt,
borrowed_collateral=borrowed_collateral,
debt_category=debt_category,
version=version,
)
session.add(new_record)
session.commit()
logger.info(f"Saved debt category for loan_id {loan_id}")
finally:
session.close()


class ZkLendEventDBConnector(DBConnector):
"""
Provides CRUD operations specifically for ZkLend events, such as accumulator sync
Expand Down
1 change: 0 additions & 1 deletion apps/data_handler/db/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from .base import Base
from .liquidable_debt import HealthRatioLevel, LiquidableDebt
from .loan_states import (
HashtackCollateralDebt,
InterestRate,
LoanState,
ZkLendCollateralDebt,
Expand Down
18 changes: 0 additions & 18 deletions apps/data_handler/db/models/loan_states.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,3 @@ class ZkLendCollateralDebt(Base):
deposit = Column(JSON, nullable=True)
collateral_enabled = Column(JSON, nullable=False)


class HashtackCollateralDebt(Base):
"""
SQLAlchemy model for the liquidable debt table for Hashtack.
"""

__tablename__ = "hashtack_collateral_debt"

user_id = Column(String, nullable=False, index=True)
loan_id = Column(Integer, nullable=False)
collateral = Column(JSON, nullable=True)
debt = Column(JSON, nullable=True)
debt_category = Column(Integer, nullable=False)
original_collateral = Column(JSON, nullable=False)
borrowed_collateral = Column(JSON, nullable=False)
version = Column(
Integer, nullable=False, index=True
) # we have two versions of Hashtack V0 and V1
37 changes: 0 additions & 37 deletions apps/data_handler/handler_tools/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,6 @@ class ProtocolAddresses:
"""

ZKLEND_MARKET_ADDRESSES: str = "0x04c0a5193d58f74fbace4b74dcf65481e734ed1714121bdc571da345540efa05"
HASHSTACK_V0_ADDRESSES: Set[str] = field(
default_factory=lambda:
{"0x03dcf5c72ba60eb7b2fe151032769d49dd3df6b04fa3141dffd6e2aa162b7a6e"}
)
HASHSTACK_V1_R_TOKENS: Set[str] = field(
default_factory=lambda: {
"0x00436d8d078de345c11493bd91512eae60cd2713e05bcaa0bb9f0cba90358c6e", # ETH
"0x03bcecd40212e9b91d92bbe25bb3643ad93f0d230d93237c675f46fac5187e8c", # USDC
"0x05fa6cc6185eab4b0264a4134e2d4e74be11205351c7c91196cb27d5d97f8d21", # USDT
"0x019c981ec23aa9cbac1cc1eb7f92cf09ea2816db9cbd932e251c86a2e8fb725f", # DAI
"0x01320a9910e78afc18be65e4080b51ecc0ee5c0a8b6cc7ef4e685e02b50e57ef", # wBTC
"0x07514ee6fa12f300ce293c60d60ecce0704314defdb137301dae78a7e5abbdd7", # STRK
}
)
HASHSTACK_V1_D_TOKENS: Set[str] = field(
default_factory=lambda: {
"0x01ef7f9f8bf01678dc6d27e2c26fb7e8eac3812a24752e6a1d6a49d153bec9f3", # ETH
"0x021d8d8519f5464ec63c6b9a80a5229c5ddeed57ecded4c8a9dfc34e31b49990", # USDC
"0x012b8185e237dd0340340faeb3351dbe53f8a42f5a9bf974ddf90ced56e301c7", # USDT
"0x07eeed99c095f83716e465e2c52a3ec8f47b323041ddc4f97778ac0393b7f358", # DAI
"0x02614c784267d2026042ab98588f90efbffaade8982567e93530db4ed41201cf", # wBTC
"0x01bdbaaa456c7d6bbba9ff740af3cfcd40bec0e85cd5cefc3fbb05a552fd14df", # STRK
}
)
NOSTRA_ALPHA_ADDRESSES: Set[str] = field(
default_factory=lambda: {
"0x0553cea5d1dc0e0157ffcd36a51a0ced717efdadd5ef1b4644352bb45bd35453",
Expand Down Expand Up @@ -122,19 +98,6 @@ class ProtocolAddresses:
FIRST_RUNNING_MAPPING = {
# zkLend
"0x04c0a5193d58f74fbace4b74dcf65481e734ed1714121bdc571da345540efa05": 48668,
# Hashstack_v0
"0x03dcf5c72ba60eb7b2fe151032769d49dd3df6b04fa3141dffd6e2aa162b7a6e": 21000,
# Hashstack_v1_r
"0x00436d8d078de345c11493bd91512eae60cd2713e05bcaa0bb9f0cba90358c6e": 268062, # ETH
"0x03bcecd40212e9b91d92bbe25bb3643ad93f0d230d93237c675f46fac5187e8c": 268067, # USDC
"0x05fa6cc6185eab4b0264a4134e2d4e74be11205351c7c91196cb27d5d97f8d21": 268064, # USDT
"0x019c981ec23aa9cbac1cc1eb7f92cf09ea2816db9cbd932e251c86a2e8fb725f": 268070, # DAI
# Hashstack_v1_d
"0x01ef7f9f8bf01678dc6d27e2c26fb7e8eac3812a24752e6a1d6a49d153bec9f3": 268063, # ETH
"0x021d8d8519f5464ec63c6b9a80a5229c5ddeed57ecded4c8a9dfc34e31b49990": 268068, # USDC
"0x012b8185e237dd0340340faeb3351dbe53f8a42f5a9bf974ddf90ced56e301c7": 268065, # USDT
"0x07eeed99c095f83716e465e2c52a3ec8f47b323041ddc4f97778ac0393b7f358": 268071, # DAI
"0x02614c784267d2026042ab98588f90efbffaade8982567e93530db4ed41201cf": 268060, # wBTC
# Nostra_alpha
"0x0553cea5d1dc0e0157ffcd36a51a0ced717efdadd5ef1b4644352bb45bd35453": 10854,
"0x047e794d7c49c49fd2104a724cfa69a92c5a4b50a5753163802617394e973833": 10892,
Expand Down

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions apps/data_handler/handlers/liquidable_debt/values.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@

class LendingProtocolNames(Enum):
"""class docstring"""
HASHSTACK_V0: str = "Hashstack_v0"
HASHSTACK_V1: str = "Hashstack_v1"
NOSTRA_ALPHA: str = "Nostra_alpha"
NOSTRA_MAINNET: str = "Nostra_mainnet"
ZKLEND: str = "zkLend"
2 changes: 0 additions & 2 deletions apps/data_handler/handlers/loan_states/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""Module docstring placeholder."""

from data_handler.handlers.loan_states.hashtack_v0.events import HashstackV0State
from data_handler.handlers.loan_states.hashtack_v1.events import HashstackV1State
from data_handler.handlers.loan_states.nostra_alpha.events import NostraAlphaState
from data_handler.handlers.loan_states.nostra_mainnet.events import NostraMainnetState
from data_handler.handlers.loan_states.zklend.events import ZkLendState
4 changes: 2 additions & 2 deletions apps/data_handler/handlers/loan_states/abstractions.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ def set_interest_rate(
"""
Sets the interest rate for the zkLend protocol.
:param instance_state: The zkLend|HashtackV0|HashtackV1 state object.
:type instance_state: zkLend|HashtackV0|HashtackV1
:param instance_state: The zkLend state object.
:type instance_state: zkLend
:param protocol_type: The protocol type.
:type protocol_type: str
:param block: block_number
Expand Down
Loading

0 comments on commit 5a68ad2

Please sign in to comment.