Skip to content

Commit

Permalink
Hopefully a final fix for Lagoon interest tracker
Browse files Browse the repository at this point in the history
  • Loading branch information
miohtama committed Feb 20, 2025
1 parent 2fb63e7 commit c44a5c5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
11 changes: 7 additions & 4 deletions tradeexecutor/state/position.py
Original file line number Diff line number Diff line change
Expand Up @@ -1499,12 +1499,15 @@ def get_last_valued_at(self) -> datetime.datetime:
"""Get the timestamp when this position was last valued"""

if self.is_loan_based():
# Loan-based positions are updated by update_interest()
# and it does not always update the token price (e.g. aUSDC).
# The timestamp for these positions must be thus taken from the interest update events.
timestamps = []
if self.loan.collateral and self.loan.collateral.last_pricing_at:
timestamps.append(self.loan.collateral.last_pricing_at)
if self.loan.borrowed and self.loan.borrowed.last_pricing_at:
if self.loan.collateral and self.loan.collateral_interest.last_updated_at:
timestamps.append(self.loan.collateral_interest.last_updated_at)
if self.loan.borrowed and self.loan.borrowed_interest.last_updated_at:
# Credit position does not have borrowed part of the loan
timestamps.append(self.loan.borrowed.last_pricing_at)
timestamps.append(self.loan.borrowed_interest.last_updated_at)
return min(timestamps)
else:
# Spot tokens
Expand Down
5 changes: 3 additions & 2 deletions tradeexecutor/strategy/interest.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,15 @@ def update_interest(

logger.log(
log_level,
f"update_interest(), block {block_number or 0:,}, new token amount: %s, old balance: %s, gained interest tokens: %s, position new USD value: %s, previous update at %s, previous block at %s",
f"update_interest(), block {block_number or 0:,}, new token amount: %s, old balance: %s, gained interest tokens: %s, position new USD value: %s, previous update at %s, previous block at %s, current block %s, block time %s",
new_token_amount,
old_balance,
gained_interest,
usd_value,
previous_update_at,
f"{previous_block or 0:,}",
block_number,
event_at,
)

gained_interest_percent = gained_interest / old_balance
Expand Down Expand Up @@ -152,7 +154,6 @@ def update_interest(
interest.last_event_at = event_at
interest.last_updated_block_number = block_number
interest.last_token_amount = new_token_amount

return evt


Expand Down

0 comments on commit c44a5c5

Please sign in to comment.