Skip to content

Commit

Permalink
Merge pull request #50 from 0xStrobe/main
Browse files Browse the repository at this point in the history
Add Ambient Swell adapter
  • Loading branch information
deHB6 authored Dec 22, 2024
2 parents 364e3e6 + 7d1a4f7 commit b80cd6e
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 4 deletions.
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/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

0 comments on commit b80cd6e

Please sign in to comment.