-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #152 from balancer/151-add-api-examples
Add API examples.
- Loading branch information
Showing
9 changed files
with
212 additions
and
83 deletions.
There are no files selected for viewing
83 changes: 0 additions & 83 deletions
83
docs/data-and-analytics/data-and-analytics/balancer-api.md
This file was deleted.
Oops, something went wrong.
37 changes: 37 additions & 0 deletions
37
docs/data-and-analytics/data-and-analytics/balancer-api/balancer-api.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
--- | ||
title: Balancer API | ||
order: 3 | ||
--- | ||
# Balancer API | ||
Balancer's API exposes data on Balancer's smart contracts accessible via graphql. The API is running as a graphql server and is deployed at [https://api-v3.balancer.fi](https://api-v3.balancer.fi). | ||
|
||
:::info Want to keep up with changes to the API? | ||
You can subscribe to the [Telegram channel](https://t.me/BalBeetsApi) or check out the [repo](https://github.com/balancer/backend) stay updated. | ||
::: | ||
|
||
Queries are organised around these main domains: | ||
|
||
- Pools | ||
- Gauges | ||
- Events | ||
- Users | ||
- Tokens | ||
- Prices | ||
- SOR (Smart Order Router used for swaps) | ||
|
||
One of the conventions is to use "dynamicData" for querying changing parts of the state. | ||
|
||
Further documentation is available on the self documented [api server](https://api-v3.balancer.fi). | ||
|
||
# Examples | ||
|
||
* [Pools - Get a pool's details including APRs](./pool-details-with-apr.md) | ||
* [Pools - Pools with TVL greater than $10k](./pools-with-tvl.md) | ||
* [Pools - Top 10 pools ordered by TVL](./pools-top-ordered-tvl.md) | ||
* [Pools - Get swap events for a pool](./pool-swap-events.md) | ||
* [Swap - Query the Smart Order Router (SOR)](./swap-query-sor.md) | ||
* [User - Get pool balances for a user](./user-pool-balance.md) | ||
* [User - Get pool join & exits events for a user](./user-pool-join-exits.md) | ||
|
||
|
||
|
33 changes: 33 additions & 0 deletions
33
docs/data-and-analytics/data-and-analytics/balancer-api/pool-details-with-apr.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
--- | ||
title: Pools - Get details including APRs | ||
--- | ||
|
||
# Get a pool's details including APRs | ||
```graphql | ||
{ | ||
poolGetPool(id: "0x7f2b3b7fbd3226c5be438cde49a519f442ca2eda00020000000000000000067d", chain:MAINNET) { | ||
id | ||
name | ||
type | ||
version | ||
allTokens { | ||
address | ||
name | ||
} | ||
poolTokens { | ||
address | ||
symbol | ||
balance | ||
hasNestedPool | ||
} | ||
dynamicData { | ||
totalLiquidity | ||
aprItems { | ||
title | ||
type | ||
apr | ||
} | ||
} | ||
} | ||
} | ||
``` |
26 changes: 26 additions & 0 deletions
26
docs/data-and-analytics/data-and-analytics/balancer-api/pool-swap-events.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
title: Pools - Swap Events | ||
--- | ||
|
||
# Get swap events for a pool | ||
|
||
As this is a CowAMM pool we also use the expanded `GqlPoolSwapEventCowAmm` type to get CowAMM specific swap data. | ||
|
||
``` | ||
{ | ||
poolEvents( | ||
where: {typeIn: [SWAP], chainIn: [MAINNET], poolIdIn: ["0xf08d4dea369c456d26a3168ff0024b904f2d8b91"]} | ||
) { | ||
type | ||
valueUSD | ||
... on GqlPoolSwapEventCowAmm { | ||
surplus { | ||
address | ||
amount | ||
valueUSD | ||
} | ||
} | ||
} | ||
} | ||
``` |
28 changes: 28 additions & 0 deletions
28
docs/data-and-analytics/data-and-analytics/balancer-api/pools-top-ordered-tvl.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
--- | ||
title: Pools - Top 10 Ordered by TVL | ||
--- | ||
|
||
# Query to find top 10 pools orderered by TVL | ||
|
||
This query also returns the pools APRs and staking gauge. One of the conventions is to use "dynamicData" for querying changing parts of the state. | ||
|
||
```graphql | ||
{ | ||
poolGetPools(first:10, orderBy:totalLiquidity) { | ||
id | ||
name | ||
chain | ||
dynamicData { | ||
totalLiquidity | ||
aprItems { | ||
apr | ||
} | ||
} | ||
staking { | ||
gauge { | ||
gaugeAddress | ||
} | ||
} | ||
} | ||
} | ||
``` |
15 changes: 15 additions & 0 deletions
15
docs/data-and-analytics/data-and-analytics/balancer-api/pools-with-tvl.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
title: Pools - With TVL greater than $10k | ||
--- | ||
|
||
# Query all pools on Arbitrum and Avalanche that have TVL greater than $10k | ||
|
||
```graphql | ||
{ | ||
poolGetPools(where: {chainIn: [AVALANCHE, ARBITRUM], minTvl: 10000}) { | ||
id | ||
address | ||
name | ||
} | ||
} | ||
``` |
26 changes: 26 additions & 0 deletions
26
docs/data-and-analytics/data-and-analytics/balancer-api/swap-query-sor.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
title: Swap - Query the Smart Order Router | ||
--- | ||
|
||
# Swap - Query the Smart Order Router (SOR) | ||
|
||
In this example we query for best paths to swap 1WETH to USDC. Note the use of human scaled amount. | ||
|
||
```graphql | ||
{ | ||
sorGetSwapPaths( | ||
chain: MAINNET | ||
swapAmount: "1" | ||
swapType: EXACT_IN | ||
tokenIn: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2" | ||
tokenOut: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48" | ||
) { | ||
swapAmountRaw | ||
returnAmountRaw | ||
priceImpact { | ||
priceImpact | ||
error | ||
} | ||
} | ||
} | ||
``` |
23 changes: 23 additions & 0 deletions
23
docs/data-and-analytics/data-and-analytics/balancer-api/user-pool-balance.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
title: User - Get pool balances | ||
--- | ||
|
||
# Get pool balances for a user | ||
|
||
As this is a CowAMM pool we also use the expanded `GqlPoolSwapEventCowAmm` type to get CowAMM specific swap data. | ||
|
||
``` | ||
{ | ||
userGetPoolBalances( | ||
address: "0x..." | ||
chains: [MAINNET] | ||
) { | ||
totalBalance | ||
walletBalance | ||
stakedBalance | ||
poolId | ||
tokenAddress | ||
tokenPrice | ||
} | ||
} | ||
``` |
24 changes: 24 additions & 0 deletions
24
docs/data-and-analytics/data-and-analytics/balancer-api/user-pool-join-exits.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
--- | ||
title: User - Get joins & exit events for a pool | ||
--- | ||
|
||
# Get pool join & exits events for a user | ||
|
||
``` | ||
{ | ||
userGetPoolJoinExits( | ||
poolId: "0x3de27efa2f1aa663ae5d458857e731c129069f29000200000000000000000588" | ||
chain: MAINNET | ||
address: "0x741AA7CFB2c7bF2A1E7D4dA2e3Df6a56cA4131F3" | ||
) { | ||
type | ||
tx | ||
valueUSD | ||
amounts { | ||
address | ||
amount | ||
} | ||
} | ||
} | ||
``` |