Skip to content

Commit

Permalink
add new method
Browse files Browse the repository at this point in the history
  • Loading branch information
djeck1432 committed Sep 26, 2024
1 parent a74603e commit 1bc390f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
14 changes: 14 additions & 0 deletions web_app/contract_tools/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down
26 changes: 26 additions & 0 deletions web_app/contract_tools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:

Expand Down

0 comments on commit 1bc390f

Please sign in to comment.