Skip to content

Commit

Permalink
Merge pull request #36 from BalancerMaxis/feat/get_preferential_gauge
Browse files Browse the repository at this point in the history
feat: get preferential gauge for given pool id
  • Loading branch information
gosuto-inzasheru authored Sep 9, 2024
2 parents edf7c5b + 3ce6514 commit c39ae32
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
9 changes: 9 additions & 0 deletions bal_tools/graphql/apiv3/get_pool_preferential_gauge.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
query PoolPreferentialGauge($chain: GqlChain, $poolId: String!) {
poolGetPool(chain: $chain, id: $poolId) {
staking {
gauge {
gaugeAddress
}
}
}
}
8 changes: 8 additions & 0 deletions bal_tools/pools_gauges.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ def get_gauge_deposit_shares(self, gauge_address: str, block: int) -> Dict[str,
results[user_address] = float(share["balance"])
return results

def get_preferential_gauge(self, pool_id: str) -> bool:
try:
return to_checksum_address(self.subgraph.fetch_graphql_data(
"apiv3", "get_pool_preferential_gauge", {"chain": self.chain.upper(), "poolId": pool_id}
)["poolGetPool"]["staking"]["gauge"]["gaugeAddress"])
except:
return None

def is_core_pool(self, pool_id: str) -> bool:
"""
check if a pool is a core pool using a fresh query to the subgraph
Expand Down
25 changes: 23 additions & 2 deletions tests/test_pools_gauges.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,17 @@

EXAMPLE_PREFERENTIAL_GAUGES = {
"mainnet": ( # wsteTH-WETH
"0x93d199263632a4ef4bb438f1feb99e57b4b5f0bd0000000000000000000005c2"
"0x93d199263632a4ef4bb438f1feb99e57b4b5f0bd0000000000000000000005c2",
"0x5C0F23A5c1be65Fa710d385814a7Fd1Bda480b1C"
),
"gnosis": ( # wstETH-GNO
"0x4683e340a8049261057d5ab1b29c8d840e75695e00020000000000000000005a",
"0xB812249d60b80c7Cbc9398E382eD6DFDF82E23D2"
),
"arbitrum": ( # RDNT-WETH
"0x32df62dc3aed2cd6224193052ce665dc181658410002000000000000000003bd",
"0xcf9f895296F5e1D66a7D4dcf1d92e1B435E9f999"
)
}
EXAMPLE_CORE_POOLS = {
"mainnet": ( # wsteTH-WETH
Expand All @@ -31,7 +40,7 @@ def test_has_alive_preferential_gauge(bal_pools_gauges):
confirm example alive preferential gauge can be found
"""
try:
example = EXAMPLE_PREFERENTIAL_GAUGES[bal_pools_gauges.chain]
example = EXAMPLE_PREFERENTIAL_GAUGES[bal_pools_gauges.chain][0]
except KeyError:
pytest.skip(f"Skipping {bal_pools_gauges.chain}, no example preferential gauge")

Expand Down Expand Up @@ -107,3 +116,15 @@ def test_build_core_pools(bal_pools_gauges):
except TransportQueryError as e:
if "Too Many Requests" in str(e):
pytest.skip(f"Skipping {bal_pools_gauges.chain}, too many requests")


def test_get_preferential_gauge(bal_pools_gauges):
"""
confirm we can correctly determine the preferential gauge for some given pools
"""
try:
example = EXAMPLE_PREFERENTIAL_GAUGES[bal_pools_gauges.chain]
except KeyError:
pytest.skip(f"Skipping {bal_pools_gauges.chain}, no example preferential gauge")

assert bal_pools_gauges.get_preferential_gauge(example[0]) == example[1]

1 comment on commit c39ae32

@Xeonus
Copy link

@Xeonus Xeonus commented on c39ae32 Sep 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gosuto-inzasheru logic, query and tests lgtm

Please sign in to comment.