Skip to content

Commit

Permalink
debug tracing during sync
Browse files Browse the repository at this point in the history
  • Loading branch information
0xOsiris committed Feb 19, 2024
1 parent f47984b commit d203d0e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/amm/erc_4626/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,14 @@ impl AutomatedMarketMaker for ERC4626Vault {
let event_signature = log.topics[0];
if event_signature == DEPOSIT_EVENT_SIGNATURE {
let deposit_event = DepositFilter::decode_log(&RawLog::from(log))?;

self.asset_reserve += deposit_event.assets;
self.vault_reserve += deposit_event.shares;
tracing::debug!("Syncing Vault data from Deposit event - asset_reserve {:?} vault_reserve {:?}", self.asset_reserve, self.vault_reserve);
} else if event_signature == WITHDRAW_EVENT_SIGNATURE {
let withdraw_filter = WithdrawFilter::decode_log(&RawLog::from(log))?;
self.asset_reserve -= withdraw_filter.assets;
self.vault_reserve -= withdraw_filter.shares;
tracing::debug!("Syncing Vault data from Withdraw event - asset_reserve {:?} vault_reserve {:?}", self.asset_reserve, self.vault_reserve);
} else {
return Err(EventLogError::InvalidEventSignature);
}
Expand All @@ -101,6 +102,7 @@ impl AutomatedMarketMaker for ERC4626Vault {
_block_number: Option<u64>,
middleware: Arc<M>,
) -> Result<(), AMMError<M>> {
tracing::debug!("Populating ERC4626 Vault data via batch request");
batch_request::get_4626_vault_data_batch_request(self, middleware.clone()).await?;

Ok(())
Expand Down
2 changes: 2 additions & 0 deletions src/amm/uniswap_v2/factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ impl AutomatedMarketMakerFactory for UniswapV2Factory {
middleware: Arc<M>,
_step: u64,
) -> Result<Vec<AMM>, AMMError<M>> {
tracing::debug!("Getting all uniswap v2 pairs via batched calls");
self.get_all_pairs_via_batched_calls(middleware).await
}

Expand All @@ -158,6 +159,7 @@ impl AutomatedMarketMakerFactory for UniswapV2Factory {
) -> Result<(), AMMError<M>> {
let step = 127; //Max batch size for call
for amm_chunk in amms.chunks_mut(step) {
tracing::debug!("Populating amm data for chunk of size {}", amm_chunk.len());
batch_request::get_amm_data_batch_request(amm_chunk, middleware.clone()).await?;
}
Ok(())
Expand Down
5 changes: 4 additions & 1 deletion src/amm/uniswap_v3/factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ impl AutomatedMarketMakerFactory for UniswapV3Factory {
if let Some(block_number) = block_number {
let step = 127; //Max batch size for call
for amm_chunk in amms.chunks_mut(step) {
tracing::debug!("Populating data for uniswap v3 pools via batched calls for chunk of size {}", amm_chunk.len());
batch_request::get_amm_data_batch_request(
amm_chunk,
block_number,
Expand Down Expand Up @@ -203,7 +204,7 @@ impl UniswapV3Factory {
if event_signature == POOL_CREATED_EVENT_SIGNATURE {
if log.address == self.address {
let mut new_pool = self.new_empty_amm_from_log(log)?;

tracing::debug!("New v3 pool created: {:?}", new_pool.address());
if let AMM::UniswapV3Pool(ref mut pool) = new_pool {
pool.tick_spacing = pool.get_tick_spacing(middleware.clone()).await?;
}
Expand All @@ -213,10 +214,12 @@ impl UniswapV3Factory {
} else if event_signature == BURN_EVENT_SIGNATURE {
//If the event sig is the BURN_EVENT_SIGNATURE log is coming from the pool
if let Some(AMM::UniswapV3Pool(pool)) = aggregated_amms.get_mut(&log.address) {
tracing::debug!("Syncing burn event for pool: {:?}", pool.address());
pool.sync_from_burn_log(log)?;
}
} else if event_signature == MINT_EVENT_SIGNATURE {
if let Some(AMM::UniswapV3Pool(pool)) = aggregated_amms.get_mut(&log.address) {
tracing::debug!("Syncing burn event for pool: {:?}", pool.address());
pool.sync_from_mint_log(log)?;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/sync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub mod checkpoint;
/// middleware - A middleware to use for syncing AMMs.
/// checkpoint_path - A path to save a checkpoint of the synced AMMs.
/// step - The step size for batched RPC requests.
/// Returns a tuple of the synced AMMs and the last synced block number.
pub async fn sync_amms<M: 'static + Middleware>(
factories: Vec<Factory>,
middleware: Arc<M>,
Expand Down

0 comments on commit d203d0e

Please sign in to comment.