|
| 1 | +import requests |
| 2 | +from constants.chains import Chain |
| 3 | +from integrations.integration_ids import IntegrationID |
| 4 | +from integrations.integration import Integration |
| 5 | +from constants.summary_columns import SummaryColumn |
| 6 | +from constants.ambient import AMBIENT_SWELL_DEPLOYMENT_BLOCK, AMBIENT_API_URL |
| 7 | + |
| 8 | + |
| 9 | +class Ambient(Integration): |
| 10 | + def __init__(self): |
| 11 | + super().__init__( |
| 12 | + IntegrationID.AMBIENT_SWELL_LP, |
| 13 | + AMBIENT_SWELL_DEPLOYMENT_BLOCK, |
| 14 | + Chain.SWELL, |
| 15 | + [SummaryColumn.AMBIENT_SWELL_SHARDS], |
| 16 | + 20, # TODO: Change 20 to the sats multiplier for the protocol that has been agreed upon |
| 17 | + 1, |
| 18 | + ) |
| 19 | + |
| 20 | + def get_balance(self, user: str, block: int) -> float: |
| 21 | + """ |
| 22 | + Get the balance of a user at a given block |
| 23 | + """ |
| 24 | + url = f"{AMBIENT_API_URL}/sats/swell/balance" |
| 25 | + params = {"user": str(user), "block": str(block)} |
| 26 | + response = requests.get(url, params=params) # type: ignore |
| 27 | + data = response.json() |
| 28 | + return data["data"] |
| 29 | + |
| 30 | + def get_participants(self, blocks: list[int] | None) -> set[str]: |
| 31 | + """ |
| 32 | + Get all participants of the protocol, ever. |
| 33 | + This function should only be called once and should cache the results by setting self.participants |
| 34 | + """ |
| 35 | + url = f"{AMBIENT_API_URL}/sats/swell/participants" |
| 36 | + response = requests.get(url) |
| 37 | + data = response.json() |
| 38 | + return data["data"] |
| 39 | + |
| 40 | + |
| 41 | +if __name__ == "__main__": |
| 42 | + # Simple tests for the integration |
| 43 | + ambient = Ambient() |
| 44 | + print(ambient.get_participants(None)) |
| 45 | + print(ambient.get_balance( |
| 46 | + list(ambient.get_participants(None))[2], 978000)) |
0 commit comments