Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow disabling dynamic univ3 fee fetching #147

Merged
merged 1 commit into from
Apr 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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