Skip to content

Commit

Permalink
Merge #1699
Browse files Browse the repository at this point in the history
1699: Add coefficient for changing fee r=Deniallugo a=Deniallugo

We need to have an opportunity to increase or decrease fee

Co-authored-by: deniallugo <[email protected]>
  • Loading branch information
bors-matterlabs-dev[bot] and Deniallugo authored Jun 10, 2021
2 parents bf376f3 + c463913 commit 59d3b69
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
11 changes: 9 additions & 2 deletions core/bin/zksync_api/src/fee_ticker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ pub struct TickerConfig {
gas_cost_tx: GasOperationsCost,
tokens_risk_factors: HashMap<TokenId, Ratio<BigUint>>,
not_subsidized_tokens: HashSet<Address>,
scale_fee_coefficient: Ratio<BigUint>,
}

#[derive(Debug, PartialEq, Eq)]
Expand Down Expand Up @@ -356,6 +357,10 @@ pub fn run_ticker_task(
gas_cost_tx: GasOperationsCost::from_constants(config.ticker.fast_processing_coeff),
tokens_risk_factors: HashMap::new(),
not_subsidized_tokens: HashSet::from_iter(config.ticker.not_subsidized_tokens.clone()),
scale_fee_coefficient: Ratio::new(
BigUint::from(config.ticker.scale_fee_percent),
BigUint::from(100u32),
),
};

let cache = (db_pool.clone(), TokenDBCache::new());
Expand Down Expand Up @@ -538,6 +543,7 @@ impl<API: FeeTickerAPI, INFO: FeeTickerInfo, WATCHER: TokenWatcher> FeeTicker<AP
let zkp_fee = (zkp_cost_chunk * op_chunks) * &token_usd_risk;
let normal_gas_fee =
(&wei_price_usd * normal_gas_tx_amount.clone() * scale_gas_price.clone())
* self.config.scale_fee_coefficient.clone()
* &token_usd_risk;
let subsidy_gas_fee =
(wei_price_usd * subsidy_gas_tx_amount.clone() * scale_gas_price.clone())
Expand Down Expand Up @@ -594,8 +600,9 @@ impl<API: FeeTickerAPI, INFO: FeeTickerInfo, WATCHER: TokenWatcher> FeeTicker<AP
}

let total_zkp_fee = (zkp_cost_chunk * total_op_chunks) * token_usd_risk.clone();
let total_normal_gas_fee =
(&wei_price_usd * total_normal_gas_tx_amount * &scale_gas_price) * &token_usd_risk;
let total_normal_gas_fee = (&wei_price_usd * total_normal_gas_tx_amount * &scale_gas_price)
* &token_usd_risk
* self.config.scale_fee_coefficient.clone();
let total_subsidy_gas_fee =
(wei_price_usd * total_subsidy_gas_tx_amount * scale_gas_price) * &token_usd_risk;
let normal_fee = BatchFee::new(&total_zkp_fee, &total_normal_gas_fee);
Expand Down
1 change: 1 addition & 0 deletions core/bin/zksync_api/src/fee_ticker/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ fn get_test_ticker_config() -> TickerConfig {
]
.into_iter()
.collect(),
scale_fee_coefficient: Ratio::new(BigUint::from(150u32), BigUint::from(100u32)),
}
}

Expand Down
4 changes: 4 additions & 0 deletions core/lib/config/src/configs/ticker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ pub struct TickerConfig {
pub coinmarketcap_base_url: String,
/// URL of CoinGecko API. Can be set to the mock server for local development.
pub coingecko_base_url: String,
/// Coefficient for scaling all fees in percent.
pub scale_fee_percent: u32,
/// Coefficient for the fee price for fast withdrawal requests.
pub fast_processing_coeff: f64,
/// Url to uniswap api
Expand Down Expand Up @@ -90,6 +92,7 @@ mod tests {
token_price_source: TokenPriceSource::CoinGecko,
coinmarketcap_base_url: "http://127.0.0.1:9876".into(),
coingecko_base_url: "http://127.0.0.1:9876".into(),
scale_fee_percent: 100,
fast_processing_coeff: 10.0f64,
uniswap_url: "http://127.0.0.1:9975/graphql".to_string(),
liquidity_volume: 100.0,
Expand Down Expand Up @@ -122,6 +125,7 @@ FEE_TICKER_LIQUIDITY_VOLUME=100
FEE_TICKER_NUMBER_OF_TICKER_ACTORS="4"
FEE_TICKER_SUBSIDIZED_TOKENS="0x0bc529c00c6401aef6d220be8c6ea1667f6ad93e"
FEE_TICKER_SUBSIDIZED_TOKENS_LIMITS=156
FEE_TICKER_SCALE_FEE_PERCENT=100
"#;
set_env(config);

Expand Down
1 change: 1 addition & 0 deletions etc/env/base/fee_ticker.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ not_subsidized_tokens=[

subsidized_tokens=[]
subsidized_tokens_limits=[]
scale_fee_percent=100

0 comments on commit 59d3b69

Please sign in to comment.