From ac30aa63bf206616fa98f29e0a1f33f8bc82466c Mon Sep 17 00:00:00 2001 From: Gosuto Inzasheru Date: Wed, 18 Sep 2024 12:19:04 +0200 Subject: [PATCH 01/11] feat: query all gauges --- bal_tools/graphql/apiv3/get_gauges.gql | 14 ++++++++++++++ bal_tools/pools_gauges.py | 13 +++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 bal_tools/graphql/apiv3/get_gauges.gql diff --git a/bal_tools/graphql/apiv3/get_gauges.gql b/bal_tools/graphql/apiv3/get_gauges.gql new file mode 100644 index 0000000..1857a78 --- /dev/null +++ b/bal_tools/graphql/apiv3/get_gauges.gql @@ -0,0 +1,14 @@ +query AllGauges($chain: GqlChain!) { + poolGetPools(where: { chainIn: [$chain] }) { + staking { + gauge { + gaugeAddress + otherGauges { + id + } + } + } + chain + symbol + } +} diff --git a/bal_tools/pools_gauges.py b/bal_tools/pools_gauges.py index 61b03b1..b8357c9 100644 --- a/bal_tools/pools_gauges.py +++ b/bal_tools/pools_gauges.py @@ -118,6 +118,19 @@ def query_root_gauges(self, skip=0, step_size=100) -> list: result += self.query_root_gauges(skip + step_size, step_size) return result + def query_all_gauges(self) -> list: + """ + query all gauges from the apiv3 subgraph + """ + data = self.subgraph.fetch_graphql_data("apiv3", "get_gauges", {"chain": self.chain.upper()}) + all_gauges = [] + for gauge in data["poolGetPools"]: + if gauge['staking'] is not None: + all_gauges.append({"id": gauge['staking']['gauge']['gaugeAddress'], "symbol": f"{gauge['symbol']}-gauge"}) + for other_gauge in gauge['staking']['gauge']['otherGauges']: + all_gauges.append({"id": other_gauge['id'], "symbol": f"{gauge['symbol']}-gauge"}) + return all_gauges + def get_last_join_exit(self, pool_id: int) -> int: """ Returns a timestamp of the last join/exit for a given pool id From 1af004198f479b0492b5592deb2702f9f03dd307 Mon Sep 17 00:00:00 2001 From: Gosuto Inzasheru Date: Wed, 18 Sep 2024 13:01:28 +0200 Subject: [PATCH 02/11] fix: 80bal20weth pool has empty gauge entry --- bal_tools/pools_gauges.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bal_tools/pools_gauges.py b/bal_tools/pools_gauges.py index b8357c9..8b9a8c1 100644 --- a/bal_tools/pools_gauges.py +++ b/bal_tools/pools_gauges.py @@ -126,9 +126,10 @@ def query_all_gauges(self) -> list: all_gauges = [] for gauge in data["poolGetPools"]: if gauge['staking'] is not None: - all_gauges.append({"id": gauge['staking']['gauge']['gaugeAddress'], "symbol": f"{gauge['symbol']}-gauge"}) - for other_gauge in gauge['staking']['gauge']['otherGauges']: - all_gauges.append({"id": other_gauge['id'], "symbol": f"{gauge['symbol']}-gauge"}) + if gauge['staking']['gauge'] is not None: # this is an edge case for the 80bal20weth pool + all_gauges.append({"id": gauge['staking']['gauge']['gaugeAddress'], "symbol": f"{gauge['symbol']}-gauge"}) + for other_gauge in gauge['staking']['gauge']['otherGauges']: + all_gauges.append({"id": other_gauge['id'], "symbol": f"{gauge['symbol']}-gauge"}) return all_gauges def get_last_join_exit(self, pool_id: int) -> int: From 6128880d4dda24b7105287d0c4b9674609fa9b35 Mon Sep 17 00:00:00 2001 From: Gosuto Inzasheru Date: Wed, 18 Sep 2024 14:10:11 +0200 Subject: [PATCH 03/11] feat: query all pools --- bal_tools/graphql/apiv3/get_pools.gql | 9 +++++++++ bal_tools/pools_gauges.py | 12 ++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 bal_tools/graphql/apiv3/get_pools.gql diff --git a/bal_tools/graphql/apiv3/get_pools.gql b/bal_tools/graphql/apiv3/get_pools.gql new file mode 100644 index 0000000..f3acb83 --- /dev/null +++ b/bal_tools/graphql/apiv3/get_pools.gql @@ -0,0 +1,9 @@ +query AllPools($chain: GqlChain!) { + poolGetPools(where: { chainIn: [$chain] }) { + id + symbol + dynamicData { + swapEnabled + } + } +} diff --git a/bal_tools/pools_gauges.py b/bal_tools/pools_gauges.py index 8b9a8c1..b2b1cd6 100644 --- a/bal_tools/pools_gauges.py +++ b/bal_tools/pools_gauges.py @@ -132,6 +132,18 @@ def query_all_gauges(self) -> list: all_gauges.append({"id": other_gauge['id'], "symbol": f"{gauge['symbol']}-gauge"}) return all_gauges + def query_all_pools(self) -> list: + """ + query all pools from the apiv3 subgraph + filters out disabled pools + """ + data = self.subgraph.fetch_graphql_data("apiv3", "get_pools", {"chain": self.chain.upper()}) + all_pools = [] + for pool in data["poolGetPools"]: + if pool['dynamicData']['swapEnabled']: + all_pools.append({"address": pool['id'], "symbol": pool['symbol']}) + return all_pools + def get_last_join_exit(self, pool_id: int) -> int: """ Returns a timestamp of the last join/exit for a given pool id From 83c2cd5a7108506ce352179e5c837b541f3ba8a8 Mon Sep 17 00:00:00 2001 From: Gosuto Inzasheru Date: Wed, 18 Sep 2024 14:28:06 +0200 Subject: [PATCH 04/11] feat: make including non pref gauges optional --- bal_tools/pools_gauges.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bal_tools/pools_gauges.py b/bal_tools/pools_gauges.py index b2b1cd6..fcc816f 100644 --- a/bal_tools/pools_gauges.py +++ b/bal_tools/pools_gauges.py @@ -118,7 +118,7 @@ def query_root_gauges(self, skip=0, step_size=100) -> list: result += self.query_root_gauges(skip + step_size, step_size) return result - def query_all_gauges(self) -> list: + def query_all_gauges(self, include_other_gauges=True) -> list: """ query all gauges from the apiv3 subgraph """ @@ -128,8 +128,9 @@ def query_all_gauges(self) -> list: if gauge['staking'] is not None: if gauge['staking']['gauge'] is not None: # this is an edge case for the 80bal20weth pool all_gauges.append({"id": gauge['staking']['gauge']['gaugeAddress'], "symbol": f"{gauge['symbol']}-gauge"}) - for other_gauge in gauge['staking']['gauge']['otherGauges']: - all_gauges.append({"id": other_gauge['id'], "symbol": f"{gauge['symbol']}-gauge"}) + if include_other_gauges: + for other_gauge in gauge['staking']['gauge']['otherGauges']: + all_gauges.append({"id": other_gauge['id'], "symbol": f"{gauge['symbol']}-gauge"}) return all_gauges def query_all_pools(self) -> list: From e31f24ca798bf594005ceb6efaff8aff4bd54373 Mon Sep 17 00:00:00 2001 From: Gosuto Inzasheru Date: Wed, 18 Sep 2024 15:07:48 +0200 Subject: [PATCH 05/11] fix: adjust twap test precision --- tests/test_subgraph.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_subgraph.py b/tests/test_subgraph.py index 6286ffb..d5f69e1 100644 --- a/tests/test_subgraph.py +++ b/tests/test_subgraph.py @@ -45,7 +45,7 @@ def test_get_twap_price_token(subgraph, date_range): date_range=date_range, ) assert isinstance(res.twap_price, Decimal) - assert pytest.approx(res.twap_price, rel=Decimal(1e-2)) == Decimal(3743.80) + assert pytest.approx(res.twap_price, rel=Decimal(0.05)) == Decimal(3743.80) def test_get_twap_prices(subgraph, date_range): @@ -55,7 +55,7 @@ def test_get_twap_prices(subgraph, date_range): date_range=date_range, ) assert isinstance(prices.bpt_price, Decimal) - assert pytest.approx(prices.bpt_price, rel=Decimal(1e-2)) == Decimal(4149.46) + assert pytest.approx(prices.bpt_price, rel=Decimal(0.05)) == Decimal(4149.46) assert all(isinstance(price.twap_price, Decimal) for price in prices.token_prices) @@ -68,7 +68,7 @@ def test_get_twap_prices_custom_price_logic(subgraph, date_range, web3): block=20059322, ) assert isinstance(prices.bpt_price, Decimal) - assert pytest.approx(prices.bpt_price, rel=Decimal(1e-2)) == Decimal(3707.99) + assert pytest.approx(prices.bpt_price, rel=Decimal(0.05)) == Decimal(3707.99) assert all(isinstance(price.twap_price, Decimal) for price in prices.token_prices) From c38c0288f2a1880579920fb8ae3d3259b0012502 Mon Sep 17 00:00:00 2001 From: jalbrekt85 Date: Thu, 19 Sep 2024 16:05:56 -0500 Subject: [PATCH 06/11] models for new queries, tests --- bal_tools/models.py | 27 +++++++++++++++++- bal_tools/pools_gauges.py | 56 ++++++++++++++++++++++++-------------- bal_tools/utils.py | 10 ++++--- tests/test_pools_gauges.py | 20 ++++++++++++++ 4 files changed, 87 insertions(+), 26 deletions(-) diff --git a/bal_tools/models.py b/bal_tools/models.py index 5673e67..913189b 100644 --- a/bal_tools/models.py +++ b/bal_tools/models.py @@ -129,4 +129,29 @@ def validate_model(cls, values): for field in ["protocolFee", "swapFees", "swapVolume", "liquidity"]: if field in values: values[field] = cls.str_to_decimal(values[field]) - return values \ No newline at end of file + return values + + +class DynamicData(BaseModel): + swapEnabled: bool + + +class PoolData(BaseModel): + id: str + symbol: str + dynamicData: DynamicData + + +class GaugeData(BaseModel): + gaugeAddress: Optional[str] = None + otherGauges: List[dict] = Field(default_factory=list) + + +class StakingData(BaseModel): + gauge: Optional[GaugeData] = None + + +class GaugePoolData(BaseModel): + staking: Optional[StakingData] = None + chain: str + symbol: str \ No newline at end of file diff --git a/bal_tools/pools_gauges.py b/bal_tools/pools_gauges.py index fcc816f..a884f65 100644 --- a/bal_tools/pools_gauges.py +++ b/bal_tools/pools_gauges.py @@ -1,10 +1,11 @@ -from typing import Dict +from typing import Dict, List import requests -from .utils import to_checksum_address +from .utils import to_checksum_address, flatten_nested_dict from gql.transport.exceptions import TransportQueryError from bal_tools.subgraph import Subgraph from bal_tools.errors import NoResultError +from bal_tools.models import PoolData, GaugePoolData, GaugeData, StakingData GITHUB_RAW_OUTPUTS = ( "https://raw.githubusercontent.com/BalancerMaxis/bal_addresses/main/outputs" @@ -118,33 +119,46 @@ def query_root_gauges(self, skip=0, step_size=100) -> list: result += self.query_root_gauges(skip + step_size, step_size) return result - def query_all_gauges(self, include_other_gauges=True) -> list: + def query_all_pools(self) -> List[PoolData]: + """ + query all pools from the apiv3 subgraph + filters out disabled pools + """ + data = self.subgraph.fetch_graphql_data("apiv3", "get_pools", {"chain": self.chain.upper()}) + pools = [PoolData(**flatten_nested_dict(pool)) for pool in data["poolGetPools"]] + return [ + pool for pool in pools + if pool.dynamicData.swapEnabled + ] + + def query_all_gauges(self, include_other_gauges=True) -> List[GaugePoolData]: """ query all gauges from the apiv3 subgraph """ data = self.subgraph.fetch_graphql_data("apiv3", "get_gauges", {"chain": self.chain.upper()}) + pools = [GaugePoolData(**flatten_nested_dict(pool)) for pool in data["poolGetPools"]] all_gauges = [] - for gauge in data["poolGetPools"]: - if gauge['staking'] is not None: - if gauge['staking']['gauge'] is not None: # this is an edge case for the 80bal20weth pool - all_gauges.append({"id": gauge['staking']['gauge']['gaugeAddress'], "symbol": f"{gauge['symbol']}-gauge"}) + for pool in pools: + if pool.staking and pool.staking.gauge: + gauge_address = pool.staking.gauge.gaugeAddress + if gauge_address: + all_gauges.append(pool) if include_other_gauges: - for other_gauge in gauge['staking']['gauge']['otherGauges']: - all_gauges.append({"id": other_gauge['id'], "symbol": f"{gauge['symbol']}-gauge"}) + other_gauges = pool.staking.gauge.otherGauges + for other_gauge in other_gauges: + other_pool = GaugePoolData( + staking=StakingData( + gauge=GaugeData( + gaugeAddress=other_gauge['id'], + otherGauges=[] + ) + ), + chain=pool.chain, + symbol=f"{pool.symbol}-other" + ) + all_gauges.append(other_pool) return all_gauges - def query_all_pools(self) -> list: - """ - query all pools from the apiv3 subgraph - filters out disabled pools - """ - data = self.subgraph.fetch_graphql_data("apiv3", "get_pools", {"chain": self.chain.upper()}) - all_pools = [] - for pool in data["poolGetPools"]: - if pool['dynamicData']['swapEnabled']: - all_pools.append({"address": pool['id'], "symbol": pool['symbol']}) - return all_pools - def get_last_join_exit(self, pool_id: int) -> int: """ Returns a timestamp of the last join/exit for a given pool id diff --git a/bal_tools/utils.py b/bal_tools/utils.py index 1cbb692..95a46ec 100644 --- a/bal_tools/utils.py +++ b/bal_tools/utils.py @@ -27,8 +27,10 @@ def get_abi(contract_name: str) -> Union[Dict, List[Dict]]: def flatten_nested_dict(d): - for key, value in list(d.items()): + result = d.copy() + for key, value in list(result.items()): if isinstance(value, dict): - d.pop(key) - d.update(value) - return d + if key not in ['dynamicData', 'staking']: + result.pop(key) + result.update(value) + return result diff --git a/tests/test_pools_gauges.py b/tests/test_pools_gauges.py index cfb44dc..c0bb311 100644 --- a/tests/test_pools_gauges.py +++ b/tests/test_pools_gauges.py @@ -1,5 +1,6 @@ import pytest from gql.transport.exceptions import TransportQueryError +from bal_tools.models import PoolData, GaugePoolData EXAMPLE_PREFERENTIAL_GAUGES = { @@ -128,3 +129,22 @@ def test_get_preferential_gauge(bal_pools_gauges): pytest.skip(f"Skipping {bal_pools_gauges.chain}, no example preferential gauge") assert bal_pools_gauges.get_preferential_gauge(example[0]) == example[1] + + +def test_query_all_pools(bal_pools_gauges): + """ + test return data of v3 AllGauges query + """ + response = bal_pools_gauges.query_all_pools() + + if len(response) > 0: + assert isinstance(response[0], PoolData) + +def test_query_all_gauges(bal_pools_gauges): + """ + test return data of v3 AllPools query + """ + response = bal_pools_gauges.query_all_gauges() + + if len(response) > 0: + assert isinstance(response[0], GaugePoolData) From 1f0aad246de62788950b14374389b68bd4db03b6 Mon Sep 17 00:00:00 2001 From: jalbrekt85 Date: Thu, 19 Sep 2024 16:23:06 -0500 Subject: [PATCH 07/11] use original symbol naming --- bal_tools/pools_gauges.py | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/bal_tools/pools_gauges.py b/bal_tools/pools_gauges.py index a884f65..cf9d4f2 100644 --- a/bal_tools/pools_gauges.py +++ b/bal_tools/pools_gauges.py @@ -136,27 +136,19 @@ def query_all_gauges(self, include_other_gauges=True) -> List[GaugePoolData]: query all gauges from the apiv3 subgraph """ data = self.subgraph.fetch_graphql_data("apiv3", "get_gauges", {"chain": self.chain.upper()}) - pools = [GaugePoolData(**flatten_nested_dict(pool)) for pool in data["poolGetPools"]] all_gauges = [] - for pool in pools: - if pool.staking and pool.staking.gauge: - gauge_address = pool.staking.gauge.gaugeAddress - if gauge_address: - all_gauges.append(pool) - if include_other_gauges: - other_gauges = pool.staking.gauge.otherGauges - for other_gauge in other_gauges: - other_pool = GaugePoolData( - staking=StakingData( - gauge=GaugeData( - gaugeAddress=other_gauge['id'], - otherGauges=[] - ) - ), - chain=pool.chain, - symbol=f"{pool.symbol}-other" - ) - all_gauges.append(other_pool) + for gauge in data["poolGetPools"]: + pool = GaugePoolData(**flatten_nested_dict(gauge)) + if pool.staking is not None and pool.staking.gauge is not None: + gauge_pool = pool.model_copy(deep=True) + gauge_pool.symbol = f"{pool.symbol}-gauge" + all_gauges.append(gauge_pool) + if include_other_gauges and pool.staking.gauge.otherGauges: + for other_gauge in pool.staking.gauge.otherGauges: + other_pool = pool.model_copy(deep=True) + other_pool.symbol = f"{pool.symbol}-gauge" + other_pool.staking.gauge.gaugeAddress = other_gauge['id'] + all_gauges.append(other_pool) return all_gauges def get_last_join_exit(self, pool_id: int) -> int: From 7ff24404268ae297c3a61b178c16fd92ff91e412 Mon Sep 17 00:00:00 2001 From: jalbrekt85 Date: Mon, 23 Sep 2024 00:18:03 -0500 Subject: [PATCH 08/11] remove nested models, return relevant gauge data at top level --- bal_tools/models.py | 23 ++++++---------- bal_tools/pools_gauges.py | 55 ++++++++++++++++++++------------------ tests/test_pools_gauges.py | 4 +-- 3 files changed, 39 insertions(+), 43 deletions(-) diff --git a/bal_tools/models.py b/bal_tools/models.py index e06fb1f..80a0f68 100644 --- a/bal_tools/models.py +++ b/bal_tools/models.py @@ -156,26 +156,19 @@ def validate_model(cls, values): return values -class DynamicData(BaseModel): - swapEnabled: bool - - class PoolData(BaseModel): id: str symbol: str - dynamicData: DynamicData - - -class GaugeData(BaseModel): - gaugeAddress: Optional[str] = None - otherGauges: List[dict] = Field(default_factory=list) - - -class StakingData(BaseModel): - gauge: Optional[GaugeData] = None + dynamicData: dict class GaugePoolData(BaseModel): - staking: Optional[StakingData] = None + staking: Optional[dict] chain: str symbol: str + + +@dataclass +class GaugeData: + id: str + symbol: str diff --git a/bal_tools/pools_gauges.py b/bal_tools/pools_gauges.py index 5afb0ea..06c4e3c 100644 --- a/bal_tools/pools_gauges.py +++ b/bal_tools/pools_gauges.py @@ -5,7 +5,7 @@ from gql.transport.exceptions import TransportQueryError from bal_tools.subgraph import Subgraph from bal_tools.errors import NoResultError -from bal_tools.models import PoolData, GaugePoolData, GaugeData, StakingData, CorePools, PoolId, Symbol +from bal_tools.models import PoolData, GaugePoolData, GaugeData, CorePools, PoolId, Symbol GITHUB_RAW_OUTPUTS = ( "https://raw.githubusercontent.com/BalancerMaxis/bal_addresses/main/outputs" @@ -116,38 +116,41 @@ def query_root_gauges(self, skip=0, step_size=100) -> list: result += self.query_root_gauges(skip + step_size, step_size) return result - def query_all_pools(self) -> List[PoolData]: - """ - query all pools from the apiv3 subgraph - filters out disabled pools - """ - data = self.subgraph.fetch_graphql_data("apiv3", "get_pools", {"chain": self.chain.upper()}) - pools = [PoolData(**flatten_nested_dict(pool)) for pool in data["poolGetPools"]] - return [ - pool for pool in pools - if pool.dynamicData.swapEnabled - ] - - def query_all_gauges(self, include_other_gauges=True) -> List[GaugePoolData]: + def query_all_gauges(self, include_other_gauges=True) -> List[GaugeData]: """ query all gauges from the apiv3 subgraph """ data = self.subgraph.fetch_graphql_data("apiv3", "get_gauges", {"chain": self.chain.upper()}) all_gauges = [] - for gauge in data["poolGetPools"]: - pool = GaugePoolData(**flatten_nested_dict(gauge)) - if pool.staking is not None and pool.staking.gauge is not None: - gauge_pool = pool.model_copy(deep=True) - gauge_pool.symbol = f"{pool.symbol}-gauge" - all_gauges.append(gauge_pool) - if include_other_gauges and pool.staking.gauge.otherGauges: - for other_gauge in pool.staking.gauge.otherGauges: - other_pool = pool.model_copy(deep=True) - other_pool.symbol = f"{pool.symbol}-gauge" - other_pool.staking.gauge.gaugeAddress = other_gauge['id'] - all_gauges.append(other_pool) + for pool in data["poolGetPools"]: + gauge_pool = GaugePoolData(**flatten_nested_dict(pool)) + if gauge_pool.staking is not None and gauge_pool.staking.get('gauge') is not None: + gauge = gauge_pool.staking['gauge'] + all_gauges.append(GaugeData( + id=gauge['gaugeAddress'], + symbol=f"{gauge_pool.symbol}-gauge" + )) + if include_other_gauges: + for other_gauge in gauge.get('otherGauges', []): + all_gauges.append(GaugeData( + id=other_gauge['id'], + symbol=f"{gauge_pool.symbol}-gauge" + )) return all_gauges + def query_all_pools(self) -> List[PoolData]: + """ + query all pools from the apiv3 subgraph + filters out disabled pools + """ + data = self.subgraph.fetch_graphql_data("apiv3", "get_pools", {"chain": self.chain.upper()}) + all_pools = [] + for pool in data["poolGetPools"]: + pool_data = PoolData(**flatten_nested_dict(pool)) + if pool_data.dynamicData['swapEnabled']: + all_pools.append(pool_data) + return all_pools + def get_last_join_exit(self, pool_id: int) -> int: """ Returns a timestamp of the last join/exit for a given pool id diff --git a/tests/test_pools_gauges.py b/tests/test_pools_gauges.py index 3f9bfef..568654a 100644 --- a/tests/test_pools_gauges.py +++ b/tests/test_pools_gauges.py @@ -1,6 +1,6 @@ import pytest from gql.transport.exceptions import TransportQueryError -from bal_tools.models import PoolData, GaugePoolData +from bal_tools.models import PoolData, GaugeData from bal_tools.models import CorePools import json @@ -149,4 +149,4 @@ def test_query_all_gauges(bal_pools_gauges): response = bal_pools_gauges.query_all_gauges() if len(response) > 0: - assert isinstance(response[0], GaugePoolData) + assert isinstance(response[0], GaugeData) From 0a3e8d3fd2b5d01b49ae6135bcdabc1b2971262c Mon Sep 17 00:00:00 2001 From: jalbrekt85 Date: Tue, 24 Sep 2024 18:33:02 -0500 Subject: [PATCH 09/11] add json serialization to CorePools --- bal_tools/models.py | 5 ++++- bal_tools/pools_gauges.py | 1 - bal_tools/requirements.txt | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/bal_tools/models.py b/bal_tools/models.py index 80a0f68..36dd64e 100644 --- a/bal_tools/models.py +++ b/bal_tools/models.py @@ -3,6 +3,7 @@ from dataclasses import dataclass, fields from enum import Enum from pydantic import BaseModel, field_validator, model_validator, Field +import json_fix class GqlChain(Enum): @@ -42,7 +43,9 @@ def __iter__(self): def __len__(self): return len(self.pools) - + + def __json__(self): + return self.pools @dataclass diff --git a/bal_tools/pools_gauges.py b/bal_tools/pools_gauges.py index 06c4e3c..fcddc68 100644 --- a/bal_tools/pools_gauges.py +++ b/bal_tools/pools_gauges.py @@ -170,7 +170,6 @@ def get_pool_tvl(self, pool_id: str) -> float: """ Returns the TVL of a pool as per the API V3 subgraph """ - print(pool_id) try: data = self.subgraph.fetch_graphql_data( "apiv3", "get_pool_tvl", {"chain": self.chain.upper(), "poolId": pool_id} diff --git a/bal_tools/requirements.txt b/bal_tools/requirements.txt index 701f740..71a1953 100644 --- a/bal_tools/requirements.txt +++ b/bal_tools/requirements.txt @@ -7,5 +7,6 @@ munch==4.0.0 gql[requests] python-dotenv pydantic==2.7.4 +json-fix git+https://github.com/BalancerMaxis/bal_addresses@0.9.9 From 3b37a7ca814d74d636b42620cce0360427d9210c Mon Sep 17 00:00:00 2001 From: Gosuto Inzasheru Date: Wed, 25 Sep 2024 11:37:44 +0200 Subject: [PATCH 10/11] fix: query pool address instead of id --- bal_tools/graphql/apiv3/get_pools.gql | 2 +- bal_tools/pools_gauges.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bal_tools/graphql/apiv3/get_pools.gql b/bal_tools/graphql/apiv3/get_pools.gql index f3acb83..4516018 100644 --- a/bal_tools/graphql/apiv3/get_pools.gql +++ b/bal_tools/graphql/apiv3/get_pools.gql @@ -1,6 +1,6 @@ query AllPools($chain: GqlChain!) { poolGetPools(where: { chainIn: [$chain] }) { - id + address symbol dynamicData { swapEnabled diff --git a/bal_tools/pools_gauges.py b/bal_tools/pools_gauges.py index b6894c3..ceec385 100644 --- a/bal_tools/pools_gauges.py +++ b/bal_tools/pools_gauges.py @@ -140,7 +140,7 @@ def query_all_pools(self) -> list: all_pools = [] for pool in data["poolGetPools"]: if pool['dynamicData']['swapEnabled']: - all_pools.append({"address": pool['id'], "symbol": pool['symbol']}) + all_pools.append({"address": pool['address'], "symbol": pool['symbol']}) return all_pools def get_last_join_exit(self, pool_id: int) -> int: From 90061d008afcaf1d8bfa6d50a433f9941e4250ff Mon Sep 17 00:00:00 2001 From: Gosuto Inzasheru Date: Wed, 25 Sep 2024 12:01:19 +0200 Subject: [PATCH 11/11] fix: unify both pools and gauge models to use `address` --- bal_tools/graphql/apiv3/get_pools.gql | 2 +- bal_tools/models.py | 8 ++++---- bal_tools/pools_gauges.py | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/bal_tools/graphql/apiv3/get_pools.gql b/bal_tools/graphql/apiv3/get_pools.gql index f3acb83..4516018 100644 --- a/bal_tools/graphql/apiv3/get_pools.gql +++ b/bal_tools/graphql/apiv3/get_pools.gql @@ -1,6 +1,6 @@ query AllPools($chain: GqlChain!) { poolGetPools(where: { chainIn: [$chain] }) { - id + address symbol dynamicData { swapEnabled diff --git a/bal_tools/models.py b/bal_tools/models.py index 36dd64e..a2734d9 100644 --- a/bal_tools/models.py +++ b/bal_tools/models.py @@ -43,7 +43,7 @@ def __iter__(self): def __len__(self): return len(self.pools) - + def __json__(self): return self.pools @@ -158,9 +158,9 @@ def validate_model(cls, values): values[field] = cls.str_to_decimal(values[field]) return values - + class PoolData(BaseModel): - id: str + address: str symbol: str dynamicData: dict @@ -173,5 +173,5 @@ class GaugePoolData(BaseModel): @dataclass class GaugeData: - id: str + address: str symbol: str diff --git a/bal_tools/pools_gauges.py b/bal_tools/pools_gauges.py index fcddc68..6eb75f7 100644 --- a/bal_tools/pools_gauges.py +++ b/bal_tools/pools_gauges.py @@ -127,13 +127,13 @@ def query_all_gauges(self, include_other_gauges=True) -> List[GaugeData]: if gauge_pool.staking is not None and gauge_pool.staking.get('gauge') is not None: gauge = gauge_pool.staking['gauge'] all_gauges.append(GaugeData( - id=gauge['gaugeAddress'], + address=gauge['gaugeAddress'], symbol=f"{gauge_pool.symbol}-gauge" )) if include_other_gauges: for other_gauge in gauge.get('otherGauges', []): all_gauges.append(GaugeData( - id=other_gauge['id'], + address=other_gauge['id'], symbol=f"{gauge_pool.symbol}-gauge" )) return all_gauges