From 88fcfa6f7b73c525249132242c92a9b21f482f74 Mon Sep 17 00:00:00 2001 From: ivdznk Date: Wed, 18 Dec 2024 09:18:17 +0200 Subject: [PATCH] Added sUSDe to Lendle protocol --- constants/lendle.py | 4 ++- integrations/integration_ids.py | 1 + integrations/lendle_susde.py | 59 +++++++++++++++++++++++++++++++++ utils/lendle.py | 5 +++ 4 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 integrations/lendle_susde.py diff --git a/constants/lendle.py b/constants/lendle.py index 5064135..429330a 100644 --- a/constants/lendle.py +++ b/constants/lendle.py @@ -1,3 +1,5 @@ LENDLE_USDE_DEPLOYMENT_BLOCK = 63215472 +LENDLE_SUSDE_DEPLOYMENT_BLOCK = 72987582 -LENDLE_USDE_TOKEN = "0x2CfA1e69C8A8083Aa52CfCF22d8caFF7521E1E7E" \ No newline at end of file +LENDLE_USDE_TOKEN = "0x2CfA1e69C8A8083Aa52CfCF22d8caFF7521E1E7E" +LENDLE_SUSDE_TOKEN = "0x8e3f5e745a030a384fbd19c97a56da5337147376" \ No newline at end of file diff --git a/integrations/integration_ids.py b/integrations/integration_ids.py index 86e9618..1cb8dfc 100644 --- a/integrations/integration_ids.py +++ b/integrations/integration_ids.py @@ -223,6 +223,7 @@ class IntegrationID(Enum): # Lendle LENDLE_USDE_LPT = ("lendle_usde_lpt_bal", "Lendle Mantle USDe LPT", Token.USDE) + LENDLE_SUSDE_LPT = ("lendle_susde_lpt_bal", "Lendle Mantle sUSDe LPT", Token.SUSDE) # Lyra LYRA_SUSDE_BULL_MAINNET = ( diff --git a/integrations/lendle_susde.py b/integrations/lendle_susde.py new file mode 100644 index 0000000..30de9ff --- /dev/null +++ b/integrations/lendle_susde.py @@ -0,0 +1,59 @@ +from constants.chains import Chain +from integrations.integration_ids import IntegrationID +from integrations.integration import Integration +from constants.summary_columns import SummaryColumn +from constants.lendle import LENDLE_SUSDE_DEPLOYMENT_BLOCK +from utils.web3_utils import w3_mantle, fetch_events_logs_with_retry, call_with_retry +from utils.lendle import lendle_susde_contract + + +class LendleIntegration(Integration): + def __init__(self): + super().__init__( + IntegrationID.LENDLE_SUSDE_LPT, + LENDLE_SUSDE_DEPLOYMENT_BLOCK, + Chain.MANTLE, + [SummaryColumn.LENDLE_MANTLE_SHARDS], + 20, + 1, + None, + None, + ) + + def get_balance(self, user: str, block: int | str) -> float: + bal = call_with_retry( + lendle_susde_contract.functions.balanceOf(user), + block, + ) + if bal == 0: + return 0 + + return round((bal / 10**18), 4) + + # Important: This function should only be called once and should cache the results by setting self.participants + def get_participants(self, blocks: list[int] | None) -> set[str]: + page_size = 1900 + start_block = LENDLE_SUSDE_DEPLOYMENT_BLOCK + target_block = w3_mantle.eth.get_block_number() + + all_users = set() + while start_block < target_block: + to_block = min(start_block + page_size, target_block) + transfers = fetch_events_logs_with_retry( + f"Lendle users from {start_block} to {to_block}", + lendle_susde_contract.events.Transfer(), + start_block, + to_block, + ) + for transfer in transfers: + all_users.add(transfer["args"]["to"]) + start_block += page_size + + return set(all_users) + + +if __name__ == "__main__": + lendle_integration = LendleIntegration() + participants = lendle_integration.get_participants(None) + print(participants) + print(lendle_integration.get_balance(list(participants)[0], "latest")) diff --git a/utils/lendle.py b/utils/lendle.py index fe99d33..a25df38 100644 --- a/utils/lendle.py +++ b/utils/lendle.py @@ -6,6 +6,7 @@ ) from constants.lendle import LENDLE_USDE_TOKEN +from constants.lendle import LENDLE_SUSDE_TOKEN with open("abi/ERC20_abi.json") as f: erc20_abi = json.load(f) @@ -14,3 +15,7 @@ lendle_usde_contract: Contract = w3_mantle.eth.contract( address=Web3.to_checksum_address(LENDLE_USDE_TOKEN), abi=erc20_abi ) + +lendle_susde_contract: Contract = w3_mantle.eth.contract( + address=Web3.to_checksum_address(LENDLE_SUSDE_TOKEN), abi=erc20_abi +)