Skip to content

Commit

Permalink
Rollup-411: usdrif pay fees (#102)
Browse files Browse the repository at this point in the history
* feat: add support for USDRIF

* refactor: extracted common TokenPrice definition
  • Loading branch information
Iago Lluque authored Sep 29, 2023
1 parent a42fdf1 commit 986d6b9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
37 changes: 29 additions & 8 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 @@ -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
Expand All @@ -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"))
}

Expand Down Expand Up @@ -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";
Expand Down
5 changes: 4 additions & 1 deletion infrastructure/zk/src/run/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`);

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 986d6b9

Please sign in to comment.