Skip to content

Commit

Permalink
feat: add support for USDRIF
Browse files Browse the repository at this point in the history
  • Loading branch information
Iago Lluque committed Sep 26, 2023
1 parent a42fdf1 commit ff1ba35
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
32 changes: 30 additions & 2 deletions core/bin/zksync_api/src/fee_ticker/ticker_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn FeeTickerInfo>;
}
Expand Down Expand Up @@ -194,7 +196,16 @@ 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");
metrics::histogram!(TICKET_INFO_GET_LAST_TOKEN_PRICE, start.elapsed(), "type" => "RDOC");
return Ok(TokenPrice {
usd_price: Ratio::from_integer(1u32.into()),
last_updated: Utc::now(),
});
}

// TODO: remove hardcode for USDRIF token
if token.symbol == "USDRIF" {
metrics::histogram!(TICKET_INFO_GET_LAST_TOKEN_PRICE, start.elapsed(), "type" => "USDRIF");
return Ok(TokenPrice {
usd_price: Ratio::from_integer(1u32.into()),
last_updated: Utc::now(),
Expand All @@ -210,7 +221,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"))
}

Expand Down Expand Up @@ -310,6 +321,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";
Expand Down
7 changes: 5 additions & 2 deletions infrastructure/zk/src/run/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export async function deployERC20(command: 'dev' | 'new', name?: string, symbol?
if (command == 'dev') {
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": "RDOCs", "symbol": "RDOC", "decimals": 18 },
{ "name": "USDRIF", "symbol": "USDRIF", "decimals": 18 },
{ "name": "RSK Infrastructure Framework", "symbol": "RIF", "decimals": 18 }
]' > ./etc/tokens/localhost.json`);

Expand All @@ -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');
Expand Down

0 comments on commit ff1ba35

Please sign in to comment.