diff --git a/web_app/contract_tools/constants.py b/web_app/contract_tools/constants.py index e1fb35e0..3c37f115 100644 --- a/web_app/contract_tools/constants.py +++ b/web_app/contract_tools/constants.py @@ -64,6 +64,20 @@ def get_token_address(cls, token_name: str) -> str: return token.address raise ValueError(f"Token {token_name} not found") + @classmethod + def get_token_decimals(cls, token_address: str) -> int: + """ + Get the token decimals for a given token address. + :param token_address: Token address + :return: Token decimals + """ + for token in cls.tokens(): + if token.address == token_address: + return token.decimals + raise ValueError(f"Token with address {token_address} not found") + + + class ProtocolAddress(Enum): diff --git a/web_app/contract_tools/utils.py b/web_app/contract_tools/utils.py index 1607c785..53b783b1 100644 --- a/web_app/contract_tools/utils.py +++ b/web_app/contract_tools/utils.py @@ -2,8 +2,12 @@ from web_app.contract_tools.blockchain_call import StarknetClient from web_app.contract_tools.constants import SPOTNET_CORE_ADDRESS, TokenParams +from web_app.contract_tools.api_request import APIRequest +from web_app.api.serializers.dashboard import ZkLendPositionResponse CLIENT = StarknetClient() +# ARGENT_X_POSITION_URL = "https://cloud.argent-api.com/v1/tokens/defi/decomposition/{wallet_id}?chain=starknet" +ARGENT_X_POSITION_URL = "https://cloud.argent-api.com/v1/tokens/defi/" class DashboardMixin: @@ -33,6 +37,28 @@ async def get_wallet_balances(cls, holder_address: str) -> Dict[str, str]: return wallet_balances + @classmethod + async def get_zklend_position(cls, wallet_id: str) -> ZkLendPositionResponse: + """ + Get the zkLend position for the given wallet ID. + :param wallet_id: Wallet ID + :return: zkLend position validated by Pydantic models + """ + # FIXME - This is a dummy wallet ID. Replace it with the actual wallet ID. + wallet_id = "0x020281104e6cb5884dabcdf3be376cf4ff7b680741a7bb20e5e07c26cd4870af" + response = await APIRequest(base_url=ARGENT_X_POSITION_URL).fetch( + f"decomposition/{wallet_id}", + params={"chain": "starknet"} + ) + + if not response: + return ZkLendPositionResponse(dapps=[], nonce=0) + + # Validate the response using Pydantic models + zk_lend_position_response = ZkLendPositionResponse(**response) + + return zk_lend_position_response + class DepositMixin: