Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bal_tools/graphql/apiv3/get_pool_preferential_gauge.gql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
query PoolPreferentialGauge($chain: GqlChain, $poolId: String!) {
query PoolPreferentialGauge($chain: GqlChain!, $poolId: String!) {
poolGetPool(chain: $chain, id: $poolId) {
staking {
gauge {
Expand Down
2 changes: 1 addition & 1 deletion bal_tools/graphql/apiv3/get_pool_tvl.gql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
query PoolTVL($chain: GqlChain, $poolId: String!) {
query PoolTVL($chain: GqlChain!, $poolId: String!) {
poolGetPool(chain: $chain, id: $poolId) {
dynamicData {
totalLiquidity
Expand Down
2 changes: 1 addition & 1 deletion bal_tools/graphql/apiv3/get_prices.gql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
query GetPrices($chains: [GqlChain!]) {
query GetPrices($chains: [GqlChain!]!) {
tokenGetCurrentPrices(chains: $chains) {
address
price
Expand Down
25 changes: 11 additions & 14 deletions bal_tools/graphql/core/pool_snapshots.gql
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
query PoolsSnapshots($first: Int, $skip: Int, $block: Int) {
poolSnapshots(
query PoolsAtBlock($first: Int, $skip: Int, $block: Int) {
pools(
first: $first
skip: $skip
orderBy: timestamp
orderDirection: desc
orderBy: id
orderDirection: asc
block: { number: $block }
) {
pool {
address
id
address
id
symbol
totalProtocolFeePaidInBPT
tokens {
symbol
totalProtocolFeePaidInBPT
tokens {
symbol
address
paidProtocolFees
}
address
paidProtocolFees
}
timestamp
}
}
2 changes: 1 addition & 1 deletion bal_tools/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def validate_symbol(cls, v):


class PoolSnapshot(BaseModel):
timestamp: int
timestamp: int = 0
address: str
id: str
symbol: str
Expand Down
11 changes: 3 additions & 8 deletions bal_tools/subgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from gql.transport.exceptions import TransportServerError
from web3 import Web3

from .utils import get_abi, flatten_nested_dict, chain_ids_by_name
from .utils import get_abi, chain_ids_by_name
from .models import *
from .errors import NoPricesFoundError
from .ts_config_loader import ts_config_loader
Expand Down Expand Up @@ -597,16 +597,11 @@ def get_balancer_pool_snapshots(
"pool_snapshots",
{"first": pools_per_req, "skip": offset, "block": block},
)
all_pools.extend(
[
PoolSnapshot(**flatten_nested_dict(pool))
for pool in result["poolSnapshots"]
]
)
all_pools.extend([PoolSnapshot(**pool) for pool in result["pools"]])
offset += pools_per_req
if offset >= limit:
break
if len(result["poolSnapshots"]) < pools_per_req:
if len(result["pools"]) < pools_per_req:
break
return all_pools

Expand Down
41 changes: 19 additions & 22 deletions tests/mock/mock_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,29 +89,26 @@
}

MOCK_POOL_SNAPSHOTS = {
"poolSnapshots": [
"pools": [
{
"pool": {
"address": "0xff4ce5aaab5a627bf82f4a571ab1ce94aa365ea6",
"id": (
"0xff4ce5aaab5a627bf82f4a571ab1ce94aa365ea6000200000000000000000426"
),
"symbol": "DOLA-USDC BSP",
"totalProtocolFeePaidInBPT": None,
"tokens": [
{
"symbol": "DOLA",
"address": "0x865377367054516e17014ccded1e7d814edc9ce4",
"paidProtocolFees": "16082.944140240944392276",
},
{
"symbol": "USDC",
"address": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
"paidProtocolFees": "4706.131322",
},
],
},
"timestamp": 1713744000,
"address": "0xff4ce5aaab5a627bf82f4a571ab1ce94aa365ea6",
"id": (
"0xff4ce5aaab5a627bf82f4a571ab1ce94aa365ea6000200000000000000000426"
),
"symbol": "DOLA-USDC BSP",
"totalProtocolFeePaidInBPT": None,
"tokens": [
{
"symbol": "DOLA",
"address": "0x865377367054516e17014ccded1e7d814edc9ce4",
"paidProtocolFees": "16082.944140240944392276",
},
{
"symbol": "USDC",
"address": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
"paidProtocolFees": "4706.131322",
},
],
}
]
}
Expand Down
1 change: 0 additions & 1 deletion tests/mock/test_mock_subgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,3 @@ def test_get_balancer_pool_snapshots(subgraph):
assert snapshot.symbol == "DOLA-USDC BSP"
assert snapshot.tokens[0].symbol == "DOLA"
assert snapshot.tokens[1].symbol == "USDC"
assert snapshot.timestamp == 1713744000
16 changes: 11 additions & 5 deletions tests/test_subgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,29 +159,35 @@ def test_find_all_subgraph_urls(
def test_warning_configuration(monkeypatch):
monkeypatch.setenv("GRAPH_API_KEY", "")

# Should emit warning
# Should emit warning (vault-v3 requires GRAPH_API_KEY)
with pytest.warns(UserWarning):
subgraph = Subgraph(silence_warnings=False)
subgraph.get_subgraph_url("core")
subgraph.get_subgraph_url("vault-v3")

# Should not emit warning
with warnings.catch_warnings():
warnings.simplefilter("error")
subgraph = Subgraph(silence_warnings=True)
subgraph.get_subgraph_url("core")
subgraph.get_subgraph_url("vault-v3")


def test_get_swap_fees(subgraph):
from datetime import datetime, timedelta, timezone

now = datetime.now(timezone.utc)
end_ts = int((now - timedelta(days=7)).timestamp())
start_ts = int((now - timedelta(days=21)).timestamp())

v3_pools = [
"0x85b2b559bc2d21104c4defdd6efca8a20343361d",
"0xc4ce391d82d164c166df9c8336ddf84206b2f812",
"0x64b84023cfe8397df83c67eaccc2c03ecda4aee5",
]
for pool in v3_pools:
total_fees = subgraph.get_v3_protocol_fees(
pool, GqlChain.MAINNET, (1739244628, 1740080000)
pool, GqlChain.MAINNET, (start_ts, end_ts)
)
assert total_fees > Decimal(0)
assert total_fees >= Decimal(0)


def test_get_pool_protocol_version(subgraph):
Expand Down
Loading