diff --git a/core/bin/zksync_api/src/fee_ticker/ticker_info.rs b/core/bin/zksync_api/src/fee_ticker/ticker_info.rs index f87d96631..adab68c39 100644 --- a/core/bin/zksync_api/src/fee_ticker/ticker_info.rs +++ b/core/bin/zksync_api/src/fee_ticker/ticker_info.rs @@ -20,6 +20,8 @@ use zksync_types::{Address, Token, TokenId, TokenLike, TokenPrice}; // Local deps use crate::fee_ticker::PriceError; +const TICKET_INFO_GET_LAST_TOKEN_PRICE: &str = "ticker_info.get_last_token_price"; + pub trait FeeTickerClone { fn clone_box(&self) -> Box; } @@ -192,13 +194,15 @@ impl FeeTickerInfo for TickerInfo { } }; - // TODO: remove hardcode for RDOC token - if token.symbol == "RDOC" { - metrics::histogram!("ticker_info.get_last_token_price", start.elapsed(), "type" => "RDOC"); - return Ok(TokenPrice { - usd_price: Ratio::from_integer(1u32.into()), - last_updated: Utc::now(), - }); + let price_1_usd = TokenPrice { + usd_price: Ratio::from_integer(1u32.into()), + last_updated: Utc::now(), + }; + + // TODO: remove hardcode for tokens + if ["RDOC", "USDRIF"].contains(&token.symbol.as_str()) { + metrics::histogram!(TICKET_INFO_GET_LAST_TOKEN_PRICE, start.elapsed(), "type" => token.symbol); + return Ok(price_1_usd); } let historical_price = self @@ -210,7 +214,7 @@ impl FeeTickerInfo for TickerInfo { return Ok(historical_price); } - metrics::histogram!("ticker_info.get_last_token_price", start.elapsed(), "type" => "error"); + metrics::histogram!(TICKET_INFO_GET_LAST_TOKEN_PRICE, start.elapsed(), "type" => "error"); Err(PriceError::db_error("No price stored in database")) } @@ -310,6 +314,23 @@ mod tests { assert_eq!(actual_quote.usd_price.to_u32().unwrap(), RDOC_VALUE); } + #[tokio::test] + async fn should_return_one_for_usdrif() { + const USDRIF_SYMBOL: &str = "USDRIF"; + const USDRIF_VALUE: u32 = 1; + + let usdrif_token_like = TokenLike::Symbol(String::from(USDRIF_SYMBOL)); + + let connection_pool = ConnectionPool::new(Some(1)); + let ticker_api = TickerInfo::new(connection_pool); + + let actual_quote = FeeTickerInfo::get_last_token_price(&ticker_api, usdrif_token_like) + .await + .unwrap(); + + assert_eq!(actual_quote.usd_price.to_u32().unwrap(), USDRIF_VALUE); + } + #[tokio::test] async fn should_return_value_from_cache() { const TEST_TOKEN_SYMBOL: &str = "TEST"; diff --git a/infrastructure/zk/src/run/run.ts b/infrastructure/zk/src/run/run.ts index 6a1f080b0..0503235a9 100644 --- a/infrastructure/zk/src/run/run.ts +++ b/infrastructure/zk/src/run/run.ts @@ -30,6 +30,7 @@ export async function deployERC20(command: 'dev' | 'new', name?: string, symbol? await utils.spawn(`yarn --silent --cwd contracts deploy-erc20 add-multi '[ { "name": "wBTC", "symbol": "wBTC", "decimals": 8, "implementation": "RevertTransferERC20" }, { "name": "RDOC", "symbol": "RDOC", "decimals": 18 }, + { "name": "USDRIF", "symbol": "USDRIF", "decimals": 18 }, { "name": "RSK Infrastructure Framework", "symbol": "RIF", "decimals": 18 } ]' > ./etc/tokens/localhost.json`); @@ -38,7 +39,9 @@ export async function deployERC20(command: 'dev' | 'new', name?: string, symbol? const tokens: Token[] = localhostTokensFile && JSON.parse(localhostTokensFile); const deployedUnconditionallyValidAddresses = (tokens && - tokens.filter((token) => ['RDOC', 'RIF'].includes(token.symbol)).map(({ address }) => address)) || + tokens + .filter((token) => ['USDRIF', 'RDOC', 'RIF'].includes(token.symbol)) + .map(({ address }) => address)) || []; const feeTickerConfigFile = fs.readFileSync('./etc/env/dev/fee_ticker.toml', 'utf-8');