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 Ambient Swell adapter #50

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion constants/ambient.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
AMBIENT_SCROLL_DEPLOYMENT_BLOCK = 267408
AMBIENT_SCROLL_API_URL = "https://ethena.liquidity.tools"
AMBIENT_SWELL_DEPLOYMENT_BLOCK = 334175
AMBIENT_API_URL = "https://ethena.liquidity.tools"
1 change: 1 addition & 0 deletions constants/chains.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ class Chain(Enum):
MODE = "Mode"
OPTIMISM = "Optimism"
Lyra = "Lyra"
SWELL = "Swell"
1 change: 1 addition & 0 deletions constants/summary_columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class SummaryColumn(Enum):
)

AMBIENT_SCROLL_SHARDS = ("ambient_scroll_shards", SummaryColumnType.ETHENA_PTS)
AMBIENT_SWELL_SHARDS = ("ambient_swell_shards", SummaryColumnType.ETHENA_PTS)

NURI_SHARDS = ("nuri_shards", SummaryColumnType.ETHENA_PTS)
LENDLE_MANTLE_SHARDS = ("lendle_mantle_shards", SummaryColumnType.ETHENA_PTS)
Expand Down
6 changes: 3 additions & 3 deletions integrations/ambient_scroll.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from integrations.integration_ids import IntegrationID
from integrations.integration import Integration
from constants.summary_columns import SummaryColumn
from constants.ambient import AMBIENT_SCROLL_DEPLOYMENT_BLOCK, AMBIENT_SCROLL_API_URL
from constants.ambient import AMBIENT_SCROLL_DEPLOYMENT_BLOCK, AMBIENT_API_URL


class Ambient(Integration):
Expand All @@ -21,7 +21,7 @@ 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"
url = f"{AMBIENT_API_URL}/sats/scroll/balance"
params = {"user": str(user), "block": str(block)}
response = requests.get(url, params=params) # type: ignore
data = response.json()
Expand All @@ -32,7 +32,7 @@ def get_participants(self, blocks: list[int] | None) -> set[str]:
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"
url = f"{AMBIENT_API_URL}/sats/scroll/participants"
response = requests.get(url)
data = response.json()
return data["data"]
Expand Down
46 changes: 46 additions & 0 deletions integrations/ambient_swell.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import requests
from constants.chains import Chain
from integrations.integration_ids import IntegrationID
from integrations.integration import Integration
from constants.summary_columns import SummaryColumn
from constants.ambient import AMBIENT_SWELL_DEPLOYMENT_BLOCK, AMBIENT_API_URL


class Ambient(Integration):
def __init__(self):
super().__init__(
IntegrationID.AMBIENT_SWELL_LP,
AMBIENT_SWELL_DEPLOYMENT_BLOCK,
Chain.SWELL,
[SummaryColumn.AMBIENT_SWELL_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_API_URL}/sats/swell/balance"
params = {"user": str(user), "block": str(block)}
response = requests.get(url, params=params) # type: ignore
data = response.json()
return data["data"]

def get_participants(self, blocks: list[int] | None) -> set[str]:
"""
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_API_URL}/sats/swell/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(None))
print(ambient.get_balance(
list(ambient.get_participants(None))[2], 978000))
1 change: 1 addition & 0 deletions integrations/integration_ids.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ class IntegrationID(Enum):
VELODROME_MODE_SUSDE = ("velodrome_mode_susde", "Velodrome Mode sUSDe", Token.SUSDE)
# Ambient
AMBIENT_SCROLL_LP = ("ambient_usde_scroll_lp_bal", "Ambient Scroll LP", Token.USDE)
AMBIENT_SWELL_LP = ("ambient_usde_swell_lp_bal", "Ambient Swell LP", Token.USDE)

# Balancer
BALANCER_ARBITRUM_GHO_USDE = (
Expand Down
Loading