Skip to content

Commit

Permalink
formatting & lints
Browse files Browse the repository at this point in the history
  • Loading branch information
kayibal authored and kayibal committed Feb 6, 2025
1 parent 5eb08ac commit 22f70ca
Show file tree
Hide file tree
Showing 10 changed files with 2,023 additions and 2,414 deletions.
1 change: 0 additions & 1 deletion substreams/crates/tycho-substreams/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ pub mod balances;
pub mod contract;
mod mock_store;
pub mod models;
#[allow(clippy::too_long_first_doc_paragraph)]
mod pb;

pub mod prelude {
Expand Down
2 changes: 1 addition & 1 deletion substreams/ethereum-balancer-v2/src/modules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ pub fn map_protocol_changes(
let id = components_store
.get_last(format!("pool:0x{}", hex::encode(address)))
.unwrap(); // Shouldn't happen because we filter by known components in
// `extract_contract_changes_builder`
// `extract_contract_changes_builder`
change.mark_component_as_updated(&id);
}
})
Expand Down
2,145 changes: 977 additions & 1,168 deletions substreams/ethereum-template-factory/src/abi/erc20.rs

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion substreams/ethereum-template-factory/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
mod abi;
mod modules;
mod pool_factories;

52 changes: 25 additions & 27 deletions substreams/ethereum-template-factory/src/modules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,22 @@
//! Adjustments to the template may include:
//! - Handling native ETH balances alongside token balances.
//! - Customizing indexing logic for specific factory contract behavior.
use std::collections::HashMap;
use crate::pool_factories;
use anyhow::Result;
use substreams::pb::substreams::StoreDeltas;
use substreams::prelude::*;
use substreams_ethereum::Event;
use substreams_ethereum::pb::eth;
use tycho_substreams::balances::aggregate_balances_changes;
use tycho_substreams::contract::extract_contract_changes_builder;
use tycho_substreams::prelude::*;
use itertools::Itertools;
use crate::pool_factories;
use std::collections::HashMap;
use substreams::{pb::substreams::StoreDeltas, prelude::*};
use substreams_ethereum::{pb::eth, Event};
use tycho_substreams::{
balances::aggregate_balances_changes, contract::extract_contract_changes_builder, prelude::*,
};

/// Find and create all relevant protocol components
///
/// This method maps over blocks and instantiates ProtocolComponents with a unique ids
/// as well as all necessary metadata for routing and encoding.
#[substreams::handlers::map]
fn map_protocol_components(
block: eth::v2::Block
) -> Result<BlockTransactionProtocolComponents> {
fn map_protocol_components(block: eth::v2::Block) -> Result<BlockTransactionProtocolComponents> {
Ok(BlockTransactionProtocolComponents {
tx_components: block
.transactions()
Expand All @@ -55,11 +51,7 @@ fn map_protocol_components(
.logs_with_calls()
.filter_map(|(log, call)| {
// TODO: ensure this method is implemented correctly
pool_factories::maybe_create_component(
call.call,
log,
tx,
)
pool_factories::maybe_create_component(call.call, log, tx)
})
.collect::<Vec<_>>();

Expand All @@ -79,17 +71,21 @@ fn map_protocol_components(
/// you need to access the whole set of components within your indexing logic.
///
/// Popular use cases are:
/// - Checking if a contract belongs to a component. In this case suggest to use an
/// address as the store key so lookup operations are O(1).
/// - Tallying up relative balances changes to calcualte absolute erc20 token balances
/// per component.
/// - Checking if a contract belongs to a component. In this case suggest to use an address as the
/// store key so lookup operations are O(1).
/// - Tallying up relative balances changes to calcualte absolute erc20 token balances per
/// component.
///
/// Usually you can skip this step if:
/// - You are interested in a static set of components only
/// - Your protocol emits balance change events with absolute values
#[substreams::handlers::store]
fn store_protocol_components(map_protocol_components: BlockTransactionProtocolComponents, store: StoreSetRaw) {
map_protocol_components.tx_components
fn store_protocol_components(
map_protocol_components: BlockTransactionProtocolComponents,
store: StoreSetRaw,
) {
map_protocol_components
.tx_components
.into_iter()
.for_each(|tx_pc| {
tx_pc
Expand Down Expand Up @@ -120,8 +116,12 @@ fn store_protocol_components(map_protocol_components: BlockTransactionProtocolCo
/// You may want to ignore LP tokens if your protocol emits transfer events for these
/// here.
#[substreams::handlers::map]
fn map_relative_component_balance(block: eth::v2::Block, store: StoreGetRaw) -> Result<BlockBalanceDeltas> {
let res = block.logs()
fn map_relative_component_balance(
block: eth::v2::Block,
store: StoreGetRaw,
) -> Result<BlockBalanceDeltas> {
let res = block
.logs()
.filter_map(|log| {
crate::abi::erc20::events::Transfer::match_and_decode(log).map(|transfer| {
let to_addr = hex::encode(transfer.to.as_slice());
Expand Down Expand Up @@ -235,7 +235,6 @@ fn map_protocol_changes(
});
});


// Extract and insert any storage changes that happened for any of the components.
extract_contract_changes_builder(
&block,
Expand All @@ -251,7 +250,6 @@ fn map_protocol_changes(
&mut transaction_changes,
);


// Process all `transaction_changes` for final output in the `BlockChanges`,
// sorted by transaction index (the key).
Ok(BlockChanges {
Expand Down
7 changes: 4 additions & 3 deletions substreams/ethereum-template-factory/src/pool_factories.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use substreams::hex;
use substreams_ethereum::pb::eth::v2::{Call, Log, TransactionTrace};
use tycho_substreams::models::{ChangeType, FinancialType, ImplementationType, ProtocolComponent, ProtocolType};

use tycho_substreams::models::{
ChangeType, FinancialType, ImplementationType, ProtocolComponent, ProtocolType,
};

/// Potentially constructs a new ProtocolComponent given a call
///
Expand Down Expand Up @@ -40,4 +41,4 @@ pub fn maybe_create_component(
}
_ => None,
}
}
}
Loading

0 comments on commit 22f70ca

Please sign in to comment.