-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/lendle-xyz/ethena_sats_adap…
- Loading branch information
Showing
22 changed files
with
1,748 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
AMBIENT_SCROLL_DEPLOYMENT_BLOCK = 267408 | ||
AMBIENT_SCROLL_API_URL = "https://ethena.liquidity.tools" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
NURI_NFP_MANAGER_ADDRESS = "0xAAA78E8C4241990B4ce159E105dA08129345946A" | ||
NURI_POOL_ADDRESS = "0x93b77EABf65921477EE1FbC1B3833D7071DB1797" | ||
NURI_DEPLOYMENT_BLOCK = 7055711 | ||
|
||
SCROLL_USDE_TOKEN_ADDRESS = "0x5d3a1Ff2b6BAb83b63cd9AD0787074081a52ef34" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
PENDLE_LOCKER_ETHEREUM = "0x6E799758CEE75DAe3d84e09D40dc416eCf713652" | ||
PENDLE_LOCKER_ARBITRUM = "0x6DB96BBEB081d2a85E0954C252f2c1dC108b3f81" | ||
master_penpie_ethereum="0x16296859C15289731521F199F0a5f762dF6347d0" | ||
master_penpie_arbitrum="0x0776C06907CE6Ff3d9Dbf84bA9B3422d7225942D" | ||
|
||
|
||
SUSDE_JULY = "0xae52ec79F2444D642B7E855DfF67bA4849D365eB" | ||
SUSDE_JULY_DEPLOYMENT_BLOCK = 19717752 | ||
|
||
Karak_sUSDe_26SEP2024_PRT="0x1c055D8081CA3B2bE0DD00ABe784b142C608219E" | ||
Karak_sUSDe_26SEP2024_PRT_DEPLOYMENT_BLOCK=19967918 | ||
|
||
|
||
|
||
Karak_USDE_26SEP2024_PRT="0x0980Be7cC405ae7C31CC39E1dd1ee77483C1a430" | ||
Karak_USDE_26SEP2024_PRT_DEPLOYMENT_BLOCK=19967899 | ||
|
||
|
||
sUSDe25APR2024_PRT="0xD35B5F85aeec81ba3A9BFa26478b2C43B8889C91" | ||
sUSDe25APR2024_PRT_DEPLOYMENT_BLOCK=19367010 | ||
|
||
|
||
sUSDe26SEP2024_PRT="0xA60f87Eac3877dFCE688Df40AeBba20030E0eb75" | ||
sUSDe26SEP2024_PRT_DEPLOYMENT_BLOCK=19909022 | ||
|
||
USDe25JUL2024_PRT="0x3984E25AF3EbcfB4ca8925e9fA8855e17DC1D240" | ||
USDe25JUL2024_PRT_DEPLOYMENT_BLOCK=19564654 | ||
|
||
|
||
Zircuit_USDe27JUN2024_PRT="0x15254c0CD69cD5c92D6A8D66De487370E146b17d" | ||
Zircuit_USDe27JUN2024_PRT_DEPLOYMENT_BLOCK=19588125 | ||
|
||
|
||
ENA29AUG2024_PRT="0xF65d42E30C15E861bc410a94e01f0CbADC0356C2" | ||
ENA29AUG2024_PRT_DEPLOYMENT_BLOCK=19644726 | ||
|
||
USDE_ARB_AUG2024="0x51FF42a579EBfC18EF9e92050494028B4aF34FA5" | ||
USDE_ARB_AUG2024_DEPLOYMENT_BLOCK=197776131 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import requests | ||
from constants.chains import Chain | ||
from constants.integration_ids import IntegrationID | ||
from models.integration import Integration | ||
from constants.summary_columns import SummaryColumn | ||
from constants.ambient import AMBIENT_SCROLL_DEPLOYMENT_BLOCK, AMBIENT_SCROLL_API_URL | ||
|
||
|
||
class Ambient(Integration): | ||
def __init__(self): | ||
super().__init__( | ||
IntegrationID.AMBIENT_SCROLL_LP, | ||
AMBIENT_SCROLL_DEPLOYMENT_BLOCK, | ||
Chain.SCROLL, | ||
[SummaryColumn.AMBIENT_SCROLL_SHARDS], | ||
20, # TODO: Change 20 to the sats multiplier for the protocol that has been agreed upon | ||
1, | ||
) | ||
|
||
def get_balance(self, user: str, block: int) -> float: | ||
""" | ||
Get the balance of a user at a given block | ||
""" | ||
url = f"{AMBIENT_SCROLL_API_URL}/sats/scroll/balance" | ||
params = {"user": user, "block": block} | ||
response = requests.get(url, params=params) | ||
data = response.json() | ||
return data["data"] | ||
|
||
def get_participants(self) -> list: | ||
""" | ||
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"{AMBIENT_SCROLL_API_URL}/sats/scroll/participants" | ||
response = requests.get(url) | ||
data = response.json() | ||
return data["data"] | ||
|
||
|
||
if __name__ == "__main__": | ||
# Simple tests for the integration | ||
ambient = Ambient() | ||
print(ambient.get_participants()) | ||
print(ambient.get_balance(list(ambient.get_participants())[2], 7372500)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
from constants.chains import Chain | ||
from constants.integration_ids import IntegrationID | ||
from models.integration import Integration | ||
from constants.nuri import NURI_NFP_MANAGER_ADDRESS, NURI_POOL_ADDRESS, NURI_DEPLOYMENT_BLOCK, SCROLL_USDE_TOKEN_ADDRESS | ||
from constants.summary_columns import SummaryColumn | ||
from utils.nuri import nfp_manager, pool | ||
from utils.web3_utils import w3_scroll, fetch_events_logs_with_retry, call_with_retry | ||
from web3 import Web3 | ||
import math | ||
|
||
class Nuri(Integration): | ||
def __init__(self): | ||
super().__init__( | ||
IntegrationID.NURI_USDE_LP, | ||
NURI_DEPLOYMENT_BLOCK, | ||
Chain.SCROLL, | ||
[SummaryColumn.NURI_SHARDS], | ||
20, | ||
1, | ||
) | ||
|
||
def calculate_sqrt_price(self, tick): | ||
return math.sqrt(1.0001**tick) * (2**96) | ||
|
||
def calculate_token_amounts(self, liquidity, current_tick, lower_tick, upper_tick, sqrt_price_x96, decimals0, decimals1): | ||
sqrt_price_current = sqrt_price_x96 | ||
sqrt_price_lower = self.calculate_sqrt_price(lower_tick) | ||
sqrt_price_upper = self.calculate_sqrt_price(upper_tick) | ||
|
||
amount0 = liquidity * (sqrt_price_upper - sqrt_price_current) / (sqrt_price_current * sqrt_price_upper) * (2**96) | ||
amount1 = liquidity * (sqrt_price_current - sqrt_price_lower) / (2**96) | ||
|
||
amount0_adjusted = amount0 / (10**decimals0) | ||
amount1_adjusted = amount1 / (10**decimals1) | ||
|
||
return amount0_adjusted, amount1_adjusted | ||
|
||
def get_balance(self, user: str, block: int) -> float: | ||
# get pool current tick | ||
current_tick = call_with_retry( | ||
pool.functions.slot0(), | ||
block, | ||
) | ||
|
||
sqrtPriceX96 = current_tick[0] | ||
tick = current_tick[1] | ||
|
||
balance = call_with_retry( | ||
nfp_manager.functions.balanceOf(user), | ||
block, | ||
) | ||
|
||
print(f"User NFT balance: {balance}") | ||
|
||
positions = [] | ||
|
||
for i in range(balance): | ||
tokenOfOwnerByIndex = call_with_retry( | ||
nfp_manager.functions.tokenOfOwnerByIndex(user, i), | ||
block, | ||
) | ||
|
||
positions.append(tokenOfOwnerByIndex) | ||
|
||
print(f"User positions: {positions}") | ||
|
||
total_balance = 0 | ||
|
||
for position in positions: | ||
position_info = call_with_retry( | ||
nfp_manager.functions.positions(position), | ||
block, | ||
) | ||
print(f"Position info: {position_info}") | ||
token0 = position_info[2] | ||
token1 = position_info[3] | ||
tickLower = position_info[5] | ||
tickUpper = position_info[6] | ||
liquidity = position_info[7] | ||
|
||
if token0 == SCROLL_USDE_TOKEN_ADDRESS: | ||
# Calculate token amounts for this position | ||
amount0, amount1 = self.calculate_token_amounts( | ||
liquidity, tick, tickLower, tickUpper, sqrtPriceX96, 18, 6 # Assuming USDe is 18 decimals and USDT is 6 | ||
) | ||
|
||
# Assuming we want to sum up the USDe amounts | ||
total_balance += amount0 | ||
|
||
return total_balance | ||
|
||
def get_participants(self) -> list: | ||
page_size = 999 | ||
start_block = NURI_DEPLOYMENT_BLOCK | ||
target_block = w3_scroll.eth.get_block_number() | ||
|
||
all_users = set() | ||
while start_block < target_block: | ||
to_block = min(start_block + page_size, target_block) | ||
try: | ||
mint_events = fetch_events_logs_with_retry( | ||
f"USDe pool Mint events from {start_block} to {to_block}", | ||
pool.events.Mint(), | ||
start_block, | ||
to_block, | ||
) | ||
print(f"Fetched {len(mint_events)} Mint events") | ||
|
||
for event in mint_events: | ||
tx_hash = event['transactionHash'] | ||
tx = w3_scroll.eth.get_transaction(tx_hash) | ||
user_address = tx['from'] | ||
all_users.add(user_address) | ||
|
||
except Exception as e: | ||
print(f"Error fetching events from block {start_block} to {to_block}: {e}") | ||
|
||
start_block += page_size | ||
|
||
self.participants = list(all_users) | ||
return self.participants | ||
|
||
if __name__ == "__main__": | ||
nuri = Nuri() | ||
#print(nuri.get_balance(Web3.to_checksum_address("0xCE29ECB0D2d8c8f0126ED923C50A35cFb0B613A8"), 7249275)) | ||
#print(nuri.get_participants()) | ||
#print(nuri.get_balance(nuri.participants[0], 7249275)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from constants.integration_ids import IntegrationID | ||
from utils.penpie import PENPIEIntegration | ||
from constants.penpie import ENA29AUG2024_PRT, ENA29AUG2024_PRT_DEPLOYMENT_BLOCK | ||
from constants.chains import Chain | ||
from constants.penpie import PENDLE_LOCKER_ETHEREUM | ||
|
||
if __name__ == "__main__": | ||
penpie_integration = PENPIEIntegration( | ||
IntegrationID.PENPIE_ENA29AUG2024_LPT, | ||
ENA29AUG2024_PRT_DEPLOYMENT_BLOCK, | ||
ENA29AUG2024_PRT, | ||
Chain.ETHEREUM, | ||
30, | ||
1, | ||
[PENDLE_LOCKER_ETHEREUM] | ||
|
||
) | ||
# print(penpie_integration.get_participants()) | ||
print(penpie_integration.get_balance("0xb60c9094FF0DFfF6aA266063A4C176B00Ad07fE8", "latest")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from constants.integration_ids import IntegrationID | ||
from utils.penpie import PENPIEIntegration | ||
from constants.penpie import Karak_sUSDe_26SEP2024_PRT, Karak_sUSDe_26SEP2024_PRT_DEPLOYMENT_BLOCK | ||
from constants.chains import Chain | ||
from constants.penpie import PENDLE_LOCKER_ETHEREUM | ||
|
||
if __name__ == "__main__": | ||
penpie_integration = PENPIEIntegration( | ||
IntegrationID.PENPIE_Karak_sUSDe_26SEP2024_LPT, | ||
Karak_sUSDe_26SEP2024_PRT_DEPLOYMENT_BLOCK, | ||
Karak_sUSDe_26SEP2024_PRT, | ||
Chain.ETHEREUM, | ||
5, | ||
1, | ||
[PENDLE_LOCKER_ETHEREUM] | ||
|
||
) | ||
# print(penpie_integration.get_participants()) | ||
print(penpie_integration.get_balance("0xb873BCF80afA89c2A9e5182f5792d64a03Eb4311", "latest")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from constants.integration_ids import IntegrationID | ||
from utils.penpie import PENPIEIntegration | ||
from constants.penpie import Karak_USDE_26SEP2024_PRT, Karak_USDE_26SEP2024_PRT_DEPLOYMENT_BLOCK | ||
from constants.chains import Chain | ||
from constants.penpie import PENDLE_LOCKER_ETHEREUM | ||
|
||
if __name__ == "__main__": | ||
penpie_integration = PENPIEIntegration( | ||
IntegrationID.PENPIE_Karak_USDE_26SEP2024_LPT, | ||
Karak_USDE_26SEP2024_PRT_DEPLOYMENT_BLOCK, | ||
Karak_USDE_26SEP2024_PRT, | ||
Chain.ETHEREUM, | ||
20, | ||
1, | ||
[PENDLE_LOCKER_ETHEREUM] | ||
|
||
) | ||
# print(penpie_integration.get_participants()) | ||
print(penpie_integration.get_balance("0x404581FA706E4E0d649A40eA503f9bCee3D2d76c", "latest")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from constants.integration_ids import IntegrationID | ||
from utils.penpie import PENPIEIntegration | ||
from constants.penpie import sUSDe25APR2024_PRT, sUSDe25APR2024_PRT_DEPLOYMENT_BLOCK | ||
from constants.chains import Chain | ||
from constants.penpie import PENDLE_LOCKER_ETHEREUM | ||
|
||
if __name__ == "__main__": | ||
penpie_integration = PENPIEIntegration( | ||
IntegrationID.PENPIE_sUSDe25APR2024_LPT, | ||
sUSDe25APR2024_PRT_DEPLOYMENT_BLOCK, | ||
sUSDe25APR2024_PRT, | ||
Chain.ETHEREUM, | ||
20, | ||
1, | ||
[PENDLE_LOCKER_ETHEREUM] | ||
|
||
) | ||
# print(penpie_integration.get_participants()) | ||
print(penpie_integration.get_balance("0x48553662B61D9B246206fdC5Ee06C643ED85cb00", "latest")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from constants.integration_ids import IntegrationID | ||
from utils.penpie import PENPIEIntegration | ||
from constants.penpie import SUSDE_JULY, SUSDE_JULY_DEPLOYMENT_BLOCK | ||
from constants.chains import Chain | ||
from constants.penpie import PENDLE_LOCKER_ETHEREUM | ||
|
||
if __name__ == "__main__": | ||
penpie_integration = PENPIEIntegration( | ||
IntegrationID.PENPIE_SUSDE_JULY_LPT, | ||
SUSDE_JULY_DEPLOYMENT_BLOCK, | ||
SUSDE_JULY, | ||
Chain.ETHEREUM, | ||
20, | ||
1, | ||
[PENDLE_LOCKER_ETHEREUM] | ||
|
||
) | ||
# print(penpie_integration.get_participants()) | ||
print(penpie_integration.get_balance("0x79E40Ab4BAc23E2910C03E2Fc24819fE498A9491", "latest")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from constants.integration_ids import IntegrationID | ||
from utils.penpie import PENPIEIntegration | ||
from constants.penpie import sUSDe26SEP2024_PRT, sUSDe26SEP2024_PRT_DEPLOYMENT_BLOCK | ||
from constants.chains import Chain | ||
from constants.penpie import PENDLE_LOCKER_ETHEREUM | ||
|
||
if __name__ == "__main__": | ||
penpie_integration = PENPIEIntegration( | ||
IntegrationID.PENPIE_sUSDe26SEP2024_LPT, | ||
sUSDe26SEP2024_PRT_DEPLOYMENT_BLOCK, | ||
sUSDe26SEP2024_PRT, | ||
Chain.ETHEREUM, | ||
20, | ||
1, | ||
[PENDLE_LOCKER_ETHEREUM] | ||
|
||
) | ||
# print(penpie_integration.get_participants()) | ||
print(penpie_integration.get_balance("0xe95176DF139a93D706655B32Df087a97e212B78E", "latest")) |
Oops, something went wrong.