Skip to content

Commit

Permalink
Update liquidity calculation
Browse files Browse the repository at this point in the history
Signed-off-by: deniallugo <[email protected]>
  • Loading branch information
Deniallugo committed Sep 2, 2022
1 parent 5d4c3c0 commit 349e156
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
3 changes: 2 additions & 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 @@ -110,7 +110,8 @@ async fn handle_graphql(
let response = GraphqlResponse {
data: GraphqlTokenResponse {
token: Some(TokenResponse {
untracked_volume_usd: volume.to_string(),
total_liquidity: volume.to_string(),
derived_eth: "1.0".to_string(),
}),
},
};
Expand Down
18 changes: 13 additions & 5 deletions core/bin/zksync_api/src/fee_ticker/validator/watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ impl UniswapTokenWatcher {
// Uniswap has graphql API, using full graphql client for one query is overkill for current task
let start = Instant::now();

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

let raw_response = self
.client
Expand Down Expand Up @@ -63,7 +66,9 @@ impl UniswapTokenWatcher {
metrics::histogram!("ticker.uniswap_watcher.get_market_volume", start.elapsed());

let volume = if let Some(token) = response.data.token {
token.untracked_volume_usd.parse()?
let total_liquidity: BigDecimal = token.total_liquidity.parse()?;
let derived_eth: BigDecimal = token.derived_eth.parse()?;
total_liquidity * derived_eth
} else {
BigDecimal::zero()
};
Expand Down Expand Up @@ -91,9 +96,12 @@ pub struct GraphqlTokenResponse {

#[derive(Serialize, Deserialize, Debug)]
pub struct TokenResponse {
/// Total amount swapped all time in token pair stored in USD, no minimum liquidity threshold.
#[serde(rename = "untrackedVolumeUSD")]
pub untracked_volume_usd: String,
/// Total liquidity in token it self
#[serde(rename = "totalLiquidity")]
pub total_liquidity: String,
/// Price of token in eth
#[serde(rename = "derivedETH")]
pub derived_eth: String,
}

#[async_trait::async_trait]
Expand Down

0 comments on commit 349e156

Please sign in to comment.