Skip to content

Commit

Permalink
Allow disabling dynamic univ3 fee fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
vkgnosis committed Apr 12, 2022
1 parent 2c2e66e commit 1f60047
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
6 changes: 5 additions & 1 deletion crates/orderbook/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use shared::{
instrumented::InstrumentedBadTokenDetectorExt,
list_based::{ListBasedDetector, UnknownTokenStrategy},
trace_call::{
BalancerVaultFinder, TokenOwnerFinding, TraceCallDetector,
BalancerVaultFinder, FeeValues, TokenOwnerFinding, TraceCallDetector,
UniswapLikePairProviderFinder, UniswapV3Finder,
},
},
Expand Down Expand Up @@ -244,6 +244,9 @@ struct Arguments {
/// will not have any further effect.
#[clap(long, env, default_value = "2")]
fast_price_estimation_results_required: NonZeroUsize,

#[clap(long, env, default_value = "static", arg_enum)]
token_detector_fee_values: FeeValues,
}

pub async fn database_metrics(metrics: Arc<Metrics>, database: Postgres) -> ! {
Expand Down Expand Up @@ -410,6 +413,7 @@ async fn main() {
contract,
base_tokens.tokens().iter().copied().collect(),
current_block,
args.token_detector_fee_values,
)
.await
.expect("create uniswapv3 finder"),
Expand Down
21 changes: 17 additions & 4 deletions crates/shared/src/bad_token/trace_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,28 @@ pub struct UniswapV3Finder {
fee_values: Vec<u32>,
}

#[derive(Debug, Clone, Copy, clap::ArgEnum)]
pub enum FeeValues {
/// Use hardcoded list
Static,
/// Fetch on creation based on events queried from node.
/// Some nodes struggle with the request and take a long time to respond leading to timeouts.
Dynamic,
}

impl UniswapV3Finder {
pub async fn new(
factory: IUniswapV3Factory,
base_tokens: Vec<H160>,
current_block: u64,
fee_values: FeeValues,
) -> Result<Self> {
// We fetch these once at start up because we don't expect them to change often.
// Alternatively could use a time based cache.
let fee_values = Self::fee_values(&factory, current_block).await?;
let fee_values = match fee_values {
FeeValues::Static => vec![500, 3000, 10000, 100],
// We fetch these once at start up because we don't expect them to change often.
// Alternatively could use a time based cache.
FeeValues::Dynamic => Self::fee_values(&factory, current_block).await?,
};
tracing::debug!(?fee_values);
Ok(Self {
factory,
Expand Down Expand Up @@ -679,7 +692,7 @@ mod tests {
let settlement = contracts::GPv2Settlement::deployed(&web3).await.unwrap();
let factory = IUniswapV3Factory::deployed(&web3).await.unwrap();
let current_block = web3.eth().block_number().await.unwrap().as_u64();
let univ3 = UniswapV3Finder::new(factory, base_tokens, current_block)
let univ3 = UniswapV3Finder::new(factory, base_tokens, current_block, FeeValues::Dynamic)
.await
.unwrap();
let token_cache = TraceCallDetector {
Expand Down

0 comments on commit 1f60047

Please sign in to comment.