Skip to content

Commit

Permalink
Merge #1561
Browse files Browse the repository at this point in the history
1561: Add eth to token allowed for fees r=Deniallugo a=Deniallugo

Signed-off-by: deniallugo <[email protected]>

Co-authored-by: deniallugo <[email protected]>
  • Loading branch information
bors-matterlabs-dev[bot] and Deniallugo authored Apr 27, 2021
2 parents 22fe686 + 03f7886 commit a35486f
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions core/bin/zksync_api/src/api_server/rest/v01/api_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use actix_web::{web, HttpResponse, Result as ActixResult};
use num::{rational::Ratio, BigUint, FromPrimitive};
use std::time::Instant;
use zksync_storage::chain::operations_ext::SearchDirection;
use zksync_types::{Address, BlockNumber};
use zksync_types::{Address, BlockNumber, Token, TokenId};

/// Helper macro which wraps the serializable object into `Ok(HttpResponse::Ok().json(...))`.
macro_rules! ok_json {
Expand Down Expand Up @@ -64,13 +64,23 @@ impl ApiV01 {
);

let mut storage = self_.access_storage().await?;
let tokens = storage
let mut tokens = storage
.tokens_schema()
.load_tokens_by_market_volume(liquidity_volume)
.await
.map_err(Self::db_error)?;

// Add ETH for tokens allowed for fee
// Different APIs have different views on how to represent ETH in their system.
// But ETH is always allowed to pay fee, and in all cases it should be on the list.

if tokens.get(&TokenId(0)).is_none() {
let eth = Token::new(TokenId(0), Default::default(), "ETH", 18);
tokens.insert(eth.id, eth);
}

let mut tokens = tokens.values().cloned().collect::<Vec<_>>();

tokens.sort_by_key(|t| t.id);

metrics::histogram!("api.v01.tokens_acceptable_for_fees", start.elapsed());
Expand Down

0 comments on commit a35486f

Please sign in to comment.