Skip to content

Commit

Permalink
Merge #1406
Browse files Browse the repository at this point in the history
1406: Fix getting trading volume from uniswap API r=popzxc a=vladbochok

according to[ Uniswap documentation](https://github.com/Uniswap/uniswap-org/blob/master/src/pages/docs/v2/10-API/02-entities.md):
```
| tradeVolumeUSD     | BigDecimal | amount of token in USD traded all time across pairs (only for tokens with liquidity above minimum threshold) |
| untrackedVolumeUSD | BigDecimal | amount of token in USD traded all time across pairs (no minimum liquidity threshold)                         |
```


Co-authored-by: Vladyslav-Bochok <[email protected]>
Co-authored-by: Vlad Bochok <[email protected]>
Co-authored-by: Danil Lugovskoy <[email protected]>
  • Loading branch information
4 people authored Feb 18, 2021
2 parents 5173b6b + 9dca68f commit c4f7244
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion core/bin/zksync_api/src/bin/dev-liquidity-token-watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ async fn handle_graphql(
let response = GraphqlResponse {
data: GraphqlTokenResponse {
token: Some(TokenResponse {
trade_volume_usd: volume.to_string(),
untracked_volume_usd: volume.to_string(),
}),
},
};
Expand Down
9 changes: 5 additions & 4 deletions core/bin/zksync_api/src/fee_ticker/validator/watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl UniswapTokenWatcher {
// TODO https://linear.app/matterlabs/issue/ZKS-413/support-full-version-of-graphql-for-tokenvalidator
let start = Instant::now();

let query = format!("{{token(id: \"{:#x}\"){{tradeVolumeUSD}}}}", address);
let query = format!("{{token(id: \"{:#x}\"){{untrackedVolumeUSD}}}}", address);

let response = self
.client
Expand All @@ -54,7 +54,7 @@ impl UniswapTokenWatcher {
metrics::histogram!("ticker.uniswap_watcher.get_market_volume", start.elapsed());

let volume = if let Some(token) = response.data.token {
token.trade_volume_usd.parse()?
token.untracked_volume_usd.parse()?
} else {
BigDecimal::zero()
};
Expand Down Expand Up @@ -82,8 +82,9 @@ pub struct GraphqlTokenResponse {

#[derive(Serialize, Deserialize, Debug)]
pub struct TokenResponse {
#[serde(rename = "tradeVolumeUSD")]
pub trade_volume_usd: String,
/// Total amount swapped all time in token pair stored in USD, no minimum liquidity threshold.
#[serde(rename = "untrackedVolumeUSD")]
pub untracked_volume_usd: String,
}

#[async_trait::async_trait]
Expand Down
2 changes: 2 additions & 0 deletions docker-compose-runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ services:

dev-liquidity-token-watcher:
image: "matterlabs/dev-liquidity-token-watcher:latest"
env_file:
- ./etc/env/docker.env
volumes:
- ./etc/tokens/:/etc/tokens

Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ services:
target: /var/lib/geth/data
dev-liquidity-token-watcher:
image: "matterlabs/dev-liquidity-token-watcher:latest"
env_file:
- ./etc/env/docker.env
ports:
- "9975:9975"
volumes:
Expand Down
2 changes: 1 addition & 1 deletion docker/dev-liquidity-token-watcher/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# syntax=docker/dockerfile:experimental
FROM rust:1.45 as builder
FROM rust:1.48 as builder
RUN --mount=type=cache,target=/usr/local/cargo/registry \
cargo install sccache
WORKDIR /usr/src/zksync
Expand Down
2 changes: 1 addition & 1 deletion docker/dev-ticker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# syntax=docker/dockerfile:experimental
FROM rust:1.45 as builder
FROM rust:1.48 as builder
RUN --mount=type=cache,target=/usr/local/cargo/registry \
cargo install sccache
WORKDIR /usr/src/zksync
Expand Down
4 changes: 3 additions & 1 deletion etc/env/docker.env
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ FEE_TICKER_COINMARKETCAP_BASE_URL=http://dev-ticker:9876
FEE_TICKER_COINGECKO_BASE_URL=http://dev-ticker:9876
DATABASE_URL=postgres://postgres@postgres/plasma
FEE_TICKER_UNISWAP_URL=http://dev-liquidity-token-watcher:9975/graphql

DEV_LIQUIDITY_TOKEN_WATCHER_BLACKLISTED_TOKENS=0x0000000000000000000000000000000000000001
DEV_LIQUIDITY_TOKEN_WATCHER_DEFAULT_VOLUME=500
DEV_LIQUIDITY_TOKEN_WATCHER_REGIME=whitelist

# Time to process one miniblock (in ms)
CHAIN_STATE_KEEPER_MINIBLOCK_ITERATION_INTERVAL=50

0 comments on commit c4f7244

Please sign in to comment.