-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from 0xStrobe/main
Add Ambient Swell adapter
- Loading branch information
Showing
5 changed files
with
53 additions
and
4 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -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" |
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
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,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)) |
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