From 424ef5dd3edf6adcbf5a79ad752adea8bd6dd164 Mon Sep 17 00:00:00 2001 From: gerg Date: Wed, 27 Sep 2023 06:51:45 -0400 Subject: [PATCH 1/3] add query pool and pools --- balpy/balpy.py | 41 ++++++++++++++++++++++++++++++++++- samples/api/apiQuerySample.py | 21 ++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 samples/api/apiQuerySample.py diff --git a/balpy/balpy.py b/balpy/balpy.py index 27337d9..3344d82 100644 --- a/balpy/balpy.py +++ b/balpy/balpy.py @@ -2069,8 +2069,18 @@ def balGetLinkToFrontend(self, poolId): else: return("") + def balGetApiEndpoint(self, endpoint): + return(os.path.join(self.apiEndpoint, endpoint, str(self.networkParams[self.network]["id"]))); + def balGetApiEndpointSor(self): - return(os.path.join(self.apiEndpoint, "sor", str(self.networkParams[self.network]["id"]))); + return(self.balGetApiEndpoint("sor")); + + def balGetApiEndpointPools(self, poolId=None): + endpoint = self.balGetApiEndpoint("pools"); + if poolId is None: + return(endpoint); + else: + return(os.path.join(endpoint, poolId)); def balSorQuery(self, data): query = data["sor"]; @@ -2100,6 +2110,35 @@ def balSorQuery(self, data): return(batch_swap) + def balApiGetPools(self): + url = self.balGetApiEndpointPools() + success = False + resp = None; + maxRetries = 5 + retries = 0 + delay = 3 + while not success or retries > maxRetries: + response = requests.get( + url, + headers={'Content-Type': 'application/json'} + ); + if response.status_code == 200: + success = True + resp = response.json() + else: + retries += 1 + print("Query failed, trying in", delay, "seconds") + time.sleep(delay) + return(resp) + + def balApiGetPool(self, poolId): + url = self.balGetApiEndpointPools(poolId) + response = requests.get( + url, + headers={'Content-Type': 'application/json'} + ); + return(response.json()) + def balSorResponseToBatchSwapFormat(self, query, response): sor = query["sor"]; del query["sor"]; diff --git a/samples/api/apiQuerySample.py b/samples/api/apiQuerySample.py new file mode 100644 index 0000000..69ebf37 --- /dev/null +++ b/samples/api/apiQuerySample.py @@ -0,0 +1,21 @@ +import balpy +import json + +def main(): + + network = "mainnet"; + poolId = "0x5c6ee304399dbdb9c8ef030ab642b10820db8f56000200000000000000000014"; + + bal = balpy.balpy.balpy(network) + + print("Querying single pool", poolId) + pool = bal.balApiGetPool(poolId); + print(json.dumps(pool, indent=4)) + print() + + print("Querying all pools on", network) + pools = bal.balApiGetPools(); + print(json.dumps(pools, indent=4)) + +if __name__ == '__main__': + main(); \ No newline at end of file From acaa727d8dc4779d73591da0004c78f41942354f Mon Sep 17 00:00:00 2001 From: gerg Date: Wed, 27 Sep 2023 06:52:50 -0400 Subject: [PATCH 2/3] bump version --- pyproject.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index d4e02a0..76d4639 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,8 +1,8 @@ [tool.poetry] name = "balpy" -version = "0.0.0a84" +version = "0.0.0a85" description = "Balancer V2 Python API" -authors = ["Greg "] +authors = ["Greg "] license = "GNU GPL 3" [tool.poetry.dependencies] From b3090aeb05be0eae9cb9d7c67fc3f629619a9b7f Mon Sep 17 00:00:00 2001 From: gerg Date: Sun, 10 Dec 2023 15:23:19 -0500 Subject: [PATCH 3/3] add managed the weighted math pool list --- balpy/balpy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/balpy/balpy.py b/balpy/balpy.py index 3344d82..3510677 100644 --- a/balpy/balpy.py +++ b/balpy/balpy.py @@ -2242,7 +2242,7 @@ def getOnchainData(self, pools): pidAndFns.append((poolId, "getPausedState")); # === using weighted math === - if poolType in ["Weighted", "LiquidityBootstrapping", "Investment"]: + if poolType in ["Weighted", "LiquidityBootstrapping", "Investment", "Managed"]: self.mc.addCall(currPool.address, currPool.abi, 'getNormalizedWeights'); pidAndFns.append((poolId, "getNormalizedWeights"));