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 sUSDe to Lendle protocol #48

Merged
merged 6 commits into from
Dec 28, 2024
Merged
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: 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
)
Loading