Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ivdznk committed Dec 18, 2024
2 parents b317198 + 237073d commit 3a37183
Show file tree
Hide file tree
Showing 22 changed files with 1,748 additions and 0 deletions.
717 changes: 717 additions & 0 deletions abi/nuri_nfp_manager.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions abi/nuri_pool.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions abi/penpie_master.json

Large diffs are not rendered by default.

412 changes: 412 additions & 0 deletions abi/penpie_tokens.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions constants/ambient.py
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"
18 changes: 18 additions & 0 deletions constants/integration_ids.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ class IntegrationID(Enum):
STAKEDAO_SUSDE_JULY_LPT = ('stakedao_susde_july_effective_lpt_held', 'Stake DAO sUSDe July LPT', Token.SUSDE)
STAKEDAO_SUSDE_SEPT_LPT = ('stakedao_susde_sept_effective_lpt_held', 'Stake DAO sUSDe Sept LPT', Token.SUSDE)
STAKEDAO_USDE_JULY_LPT = ('stakedao_usde_july_effective_lpt_held', 'Stake DAO USDe July LPT', Token.USDE)

#PENPIE
PENPIE_SUSDE_JULY_LPT=('penpie_susde_july_effective_lpt_held', 'PENPIE sUSDe July LPT', Token.SUSDE)
PENPIE_Karak_sUSDe_26SEP2024_LPT= ('PENPIE_Karak_sUSDe_26SEP2024_effective_lpt_held', 'Karak_sUSDe_26SEP2024', Token.SUSDE)
PENPIE_Karak_USDE_26SEP2024_LPT= ('PENPIE_Karak_USDE_26SEP2024_effective_lpt_held', 'Karak_USDE_26SEP2024', Token.USDE)
PENPIE_sUSDe25APR2024_LPT= ('PENPIE_sUSDe25APR2024_effective_lpt_held', 'sUSDe25APR2024', Token.SUSDE)
PENPIE_sUSDe26SEP2024_LPT= ('PENPIE_sUSDe26SEP2024_effective_lpt_held', 'sUSDe26SEP2024', Token.SUSDE)
PENPIE_USDe25JUL2024_LPT= ('PENPIE_USDe25JUL2024_effective_lpt_held', 'USDe25JUL2024', Token.USDE)
PENPIE_Zircuit_USDe27JUN2024_LPT= ('PENPIE_Zircuit_USDe27JUN2024_effective_lpt_held', 'Zircuit_USDe27JUN2024', Token.USDE)
PENPIE_ENA29AUG2024_LPT= ('PENPIE_ENA29AUG2024_effective_lpt_held', 'ENA29AUG2024', Token.ENA)
PENPIE_USDE_ARB_AUG2024_LPT= ('PENPIE_USDE_ARB_AUG2024_effective_lpt_held', 'USDE_ARB_AUG2024', Token.USDE)


# EQUILIBRIA
EQUILIBRIA_SUSDE_SEPT_LPT = ('equilibria_susde_sept_effective_lpt_held', 'Equilibria sUSDe Sept LPT', Token.SUSDE)
Expand All @@ -48,6 +60,12 @@ class IntegrationID(Enum):

# Lendle
LENDLE_USDE_LPT = ('lendle_usde_lpt_bal', 'Lendle Mantle USDe LPT', Token.USDE)

# Ambient
AMBIENT_SCROLL_LP = ('ambient_usde_scroll_lp_bal', 'Ambient Scroll LP', Token.USDE)

# Nuri
NURI_USDE_LP = ('nuri_usde_lp_bal', 'Nuri USDe LP', Token.USDE)

def __init__(self, column_name: str, description: str, token: Token = Token.USDE):
self.column_name = column_name
Expand Down
5 changes: 5 additions & 0 deletions constants/nuri.py
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"
38 changes: 38 additions & 0 deletions constants/penpie.py
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
7 changes: 7 additions & 0 deletions constants/summary_columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,11 @@ class SummaryColumn(Enum):
PENDLE_ARBITRUM_SHARDS = "pendle_arbtrium_shards"
PENDLE_MANTLE_SHARDS = "pendle_mantle_shards"
SYNTHETIX_ARBITRUM_SHARDS = "synthetix_arbitrum_shards"

AMBIENT_SCROLL_SHARDS = "ambient_scroll_shards"

NURI_SHARDS = "nuri_shards"
LENDLE_MANTLE_SHARDS = "lendle_mantle_shards"



45 changes: 45 additions & 0 deletions integrations/ambient_scroll.py
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))
127 changes: 127 additions & 0 deletions integrations/nuri.py
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))
19 changes: 19 additions & 0 deletions integrations/penpie_ena_aug.py
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"))
19 changes: 19 additions & 0 deletions integrations/penpie_karak_susde_sep.py
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"))
19 changes: 19 additions & 0 deletions integrations/penpie_karak_usde_sep.py
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"))
19 changes: 19 additions & 0 deletions integrations/penpie_susde_25apr.py
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"))
19 changes: 19 additions & 0 deletions integrations/penpie_susde_july.py
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"))
19 changes: 19 additions & 0 deletions integrations/penpie_susde_sep.py
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"))
Loading

0 comments on commit 3a37183

Please sign in to comment.