Skip to content

Commit

Permalink
feature: usde token amount -> full usd value of position
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregory Ivantov committed Jan 25, 2025
1 parent 984f5b0 commit 84462f5
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions integrations/stonfi_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,12 @@

STONFI_ENDPOINT = "https://api.ston.fi"

STONFI_LP_TOKEN_DECIMALS = 9

TOKEN_SYMBOL_ADDRESS_MAP = {
Token.USDE: "EQA2kCVNwVsil2EM2mB0SkXytxCqQjS4mttjDpnXmwG9T6bO", # FIXME: replace with real USDe address
}

TOKEN_DECIMALS_MAP = {
Token.USDE: 9, # FIXME: replace with real USDe decimals
}


class StonFiIntegration(L2DelegationIntegration):
def __init__(
self,
Expand Down Expand Up @@ -75,8 +72,7 @@ def get_participants_data(self, block: int) -> Dict[str, float]:
)

token_address = TOKEN_SYMBOL_ADDRESS_MAP[self.get_token_symbol()]
token_decimals = TOKEN_DECIMALS_MAP[self.get_token_symbol()]
token_decimals_base = 10 ** token_decimals
lp_token_decimals_base = 10 ** STONFI_LP_TOKEN_DECIMALS

block_data: Dict[str, float] = {}
try:
Expand All @@ -91,10 +87,20 @@ def get_participants_data(self, block: int) -> Dict[str, float]:
)
payload = res.json()

pools_data = payload["pools"]

if "holders" in payload and len(payload["holders"]) > 0:
for holder in payload["holders"]:
wallet_address = holder["wallet_address"]
block_data[wallet_address] = int(holder["total_amount"]) / token_decimals_base

total_amount_usd = 0
for pool in holder["pools"]:
pool_data = pools_data[pool["pool_address"]]
pool_lp_token_amount = int(pool.get("lp_amount", "0")) + int(pool.get("staked_lp_amount", "0"))
total_amount_usd += pool_data["lp_price_usd"] * pool_lp_token_amount / lp_token_decimals_base

block_data[wallet_address] = total_amount_usd

except Exception as e:
# pylint: disable=line-too-long
err_msg = f"Error getting participants data for STON.fi L2 delegation at block {block}: {e}"
Expand Down

0 comments on commit 84462f5

Please sign in to comment.