From f281a5d8cbd34f9faa97ca7197305daa19a90b80 Mon Sep 17 00:00:00 2001 From: YellowSnowMann Date: Fri, 29 Nov 2024 17:58:17 +0530 Subject: [PATCH 1/2] integrate zerolend --- integrations/integration_ids.py | 4 ++ integrations/zerolend_susde_integration.py | 63 ++++++++++++++++++++++ integrations/zerolend_usde_integration.py | 58 ++++++++++++++++++++ 3 files changed, 125 insertions(+) create mode 100644 integrations/zerolend_susde_integration.py create mode 100644 integrations/zerolend_usde_integration.py diff --git a/integrations/integration_ids.py b/integrations/integration_ids.py index aa89852..8f0bb8b 100644 --- a/integrations/integration_ids.py +++ b/integrations/integration_ids.py @@ -394,6 +394,10 @@ class IntegrationID(Enum): Token.USDE, ) + # Zerolend + ZEROLEND_SUSDE = ("zerolend_susde_deposit","Zerolend sUSDe",Token.SUSDE) + ZEROLEND_USDE = ("zerolend_usde_deposit", "Zerolend USDe", Token.USDE) + def __init__(self, column_name: str, description: str, token: Token = Token.USDE): self.column_name = column_name self.description = description diff --git a/integrations/zerolend_susde_integration.py b/integrations/zerolend_susde_integration.py new file mode 100644 index 0000000..bb1df5b --- /dev/null +++ b/integrations/zerolend_susde_integration.py @@ -0,0 +1,63 @@ +from typing import Callable, Dict, List, Optional, Set +from constants.chains import Chain +from utils.web3_utils import w3 +from constants.summary_columns import SummaryColumn +from integrations.cached_balances_integration import CachedBalancesIntegration +from integrations.integration_ids import IntegrationID +import requests + +ZEOLEND_API_URL = "https://api.zerolend.xyz" + + +class ZerolendIntegration(CachedBalancesIntegration): + def __init__( + self, + ): + super().__init__( + IntegrationID.ZEROLEND_SUSDE, + 20000000, # not used + Chain.ETHEREUM, + None, + 5, + 1, + None, + None, + None, + ) + + def get_balance(self, user: str, block: int) -> float: + try: + url = f"{ZEOLEND_API_URL}/ethena" # TODO: add api url + params = {"token": "susde", "address": str(user), "blockNo": str(block)} + response = requests.get(url, params=params) # type: ignore + print(response.json()) + data = response.json() + asset_balance = data["data"] + return asset_balance + except Exception as ex: + print("Error getting balance for user %s: %s", user, ex) + return 0 + + def get_participants(self, blocks: list[int] | None) -> set[str]: + """ + Get all participants of the protocol, ever. + This function should only be called once and should cache the results by setting self.participants + """ + url = f"{ZEOLEND_API_URL}/ethena/participants" + params = {"token": "susde"} + response = requests.get(url, params=params) + data = response.json() + return data["data"] + + +if __name__ == "__main__": + zerolend = ZerolendIntegration() + participants = zerolend.get_participants(None) + print("participants", participants) + currentBlock = w3.eth.get_block_number() + if len(participants) > 0: + print( + zerolend.get_balance( + list(participants)[len(participants) - 1], currentBlock-5 + ) + ) diff --git a/integrations/zerolend_usde_integration.py b/integrations/zerolend_usde_integration.py new file mode 100644 index 0000000..d6f34b9 --- /dev/null +++ b/integrations/zerolend_usde_integration.py @@ -0,0 +1,58 @@ +from typing import Callable, Dict, List, Optional, Set +from constants.chains import Chain +from constants.summary_columns import SummaryColumn +from utils.web3_utils import w3 +from integrations.cached_balances_integration import CachedBalancesIntegration +from integrations.integration_ids import IntegrationID +import requests + +ZEOLEND_API_URL = "https://api.zerolend.xyz" + +class ZerolendIntegration(CachedBalancesIntegration): + def __init__( + self, + ): + super().__init__( + IntegrationID.ZEROLEND_USDE, + 20000000, # not used + Chain.ETHEREUM, + None, + 20, + 1, + None, + None, + None, + ) + + def get_balance(self, user: str, block: int) -> float: + try: + url = f"{ZEOLEND_API_URL}/ethena" + params = {"token":"usde","address": str(user), "blockNo": str(block)} + response = requests.get(url, params=params) + print(response.json()) + data = response.json() + asset_balance = data["data"] + return asset_balance + except Exception as ex: + print("Error getting balance for user %s: %s", user, ex) + return 0 + + def get_participants(self, blocks: list[int] | None) -> set[str]: + """ + Get all participants of the protocol, ever. + This function should only be called once and should cache the results by setting self.participants + """ + url = f"{ZEOLEND_API_URL}/ethena/participants" + params = {"token": "usde"} + response = requests.get(url, params=params) + data = response.json() + return data["data"] + + +if __name__ == "__main__": + zerolend = ZerolendIntegration() + participants = zerolend.get_participants(None) + print("participants", participants) + currentBlock = w3.eth.get_block_number() + if len(participants) > 0: + print(zerolend.get_balance(list(participants)[len(participants) - 1], currentBlock-5)) From 8a6f1b08023951f67c7735f1f8e6fe260d78e86f Mon Sep 17 00:00:00 2001 From: YellowSnowMann Date: Mon, 2 Dec 2024 21:21:57 +0530 Subject: [PATCH 2/2] get data for exact block --- integrations/zerolend_susde_integration.py | 2 +- integrations/zerolend_usde_integration.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/integrations/zerolend_susde_integration.py b/integrations/zerolend_susde_integration.py index bb1df5b..c38597c 100644 --- a/integrations/zerolend_susde_integration.py +++ b/integrations/zerolend_susde_integration.py @@ -58,6 +58,6 @@ def get_participants(self, blocks: list[int] | None) -> set[str]: if len(participants) > 0: print( zerolend.get_balance( - list(participants)[len(participants) - 1], currentBlock-5 + list(participants)[len(participants) - 1], currentBlock ) ) diff --git a/integrations/zerolend_usde_integration.py b/integrations/zerolend_usde_integration.py index d6f34b9..90eb098 100644 --- a/integrations/zerolend_usde_integration.py +++ b/integrations/zerolend_usde_integration.py @@ -55,4 +55,4 @@ def get_participants(self, blocks: list[int] | None) -> set[str]: print("participants", participants) currentBlock = w3.eth.get_block_number() if len(participants) > 0: - print(zerolend.get_balance(list(participants)[len(participants) - 1], currentBlock-5)) + print(zerolend.get_balance(list(participants)[len(participants) - 1], currentBlock))