Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add zerolend #46

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions integrations/integration_ids.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
63 changes: 63 additions & 0 deletions integrations/zerolend_susde_integration.py
Original file line number Diff line number Diff line change
@@ -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
)
)
58 changes: 58 additions & 0 deletions integrations/zerolend_usde_integration.py
Original file line number Diff line number Diff line change
@@ -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))