Skip to content

Commit

Permalink
Added sUSDe to Lendle protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
ivdznk committed Dec 18, 2024
1 parent 3a60ce2 commit 88fcfa6
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 1 deletion.
4 changes: 3 additions & 1 deletion constants/lendle.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
LENDLE_USDE_DEPLOYMENT_BLOCK = 63215472
LENDLE_SUSDE_DEPLOYMENT_BLOCK = 72987582

LENDLE_USDE_TOKEN = "0x2CfA1e69C8A8083Aa52CfCF22d8caFF7521E1E7E"
LENDLE_USDE_TOKEN = "0x2CfA1e69C8A8083Aa52CfCF22d8caFF7521E1E7E"
LENDLE_SUSDE_TOKEN = "0x8e3f5e745a030a384fbd19c97a56da5337147376"
1 change: 1 addition & 0 deletions integrations/integration_ids.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down
59 changes: 59 additions & 0 deletions integrations/lendle_susde.py
Original file line number Diff line number Diff line change
@@ -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"))
5 changes: 5 additions & 0 deletions utils/lendle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
)

0 comments on commit 88fcfa6

Please sign in to comment.