formatting & lints
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
})
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,3 @@
|
||||
mod abi;
|
||||
mod modules;
|
||||
mod pool_factories;
|
||||
|
||||
|
||||
@@ -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 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 anyhow::Result;
|
||||
use itertools::Itertools;
|
||||
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()
|
||||
@@ -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<_>>();
|
||||
|
||||
@@ -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
|
||||
@@ -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());
|
||||
@@ -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,
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
///
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,3 @@
|
||||
mod abi;
|
||||
mod pool_factories;
|
||||
mod modules;
|
||||
|
||||
mod pool_factories;
|
||||
|
||||
@@ -14,21 +14,16 @@
|
||||
//! likely that you will need to adapt the steps to suit your specific use case. Use the
|
||||
//! provided code with care and ensure you fully understand each step before proceeding
|
||||
//! with your implementation
|
||||
//!
|
||||
use std::collections::HashMap;
|
||||
use crate::{pool_factories, pool_factories::DeploymentConfig};
|
||||
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 prost::Message;
|
||||
use substreams_ethereum::block_view::CallView;
|
||||
use crate::pool_factories;
|
||||
use crate::pool_factories::DeploymentConfig;
|
||||
use std::collections::HashMap;
|
||||
use substreams::{pb::substreams::StoreDeltas, prelude::*};
|
||||
use substreams_ethereum::{block_view::CallView, pb::eth, Event};
|
||||
use tycho_substreams::{
|
||||
balances::aggregate_balances_changes, contract::extract_contract_changes_builder, prelude::*,
|
||||
};
|
||||
|
||||
/// Find and create all relevant protocol components
|
||||
///
|
||||
@@ -48,12 +43,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,
|
||||
&config,
|
||||
)
|
||||
pool_factories::maybe_create_component(call.call, log, tx, &config)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
@@ -68,8 +58,12 @@ fn map_protocol_components(
|
||||
}
|
||||
|
||||
#[substreams::handlers::store]
|
||||
fn store_protocol_tokens(map_protocol_components: BlockTransactionProtocolComponents, store: StoreSetInt64) {
|
||||
map_protocol_components.tx_components
|
||||
fn store_protocol_tokens(
|
||||
map_protocol_components: BlockTransactionProtocolComponents,
|
||||
store: StoreSetInt64,
|
||||
) {
|
||||
map_protocol_components
|
||||
.tx_components
|
||||
.into_iter()
|
||||
.for_each(|tx_pc| {
|
||||
tx_pc
|
||||
@@ -92,20 +86,22 @@ fn store_protocol_tokens(map_protocol_components: BlockTransactionProtocolCompon
|
||||
/// is decreased.
|
||||
///
|
||||
/// ## Note:
|
||||
/// - If your protocol emits events that let you calculate balance deltas more
|
||||
/// efficiently you may want to use those instead of raw transfers.
|
||||
/// - Changes are necessary if your protocol uses native ETH or your component burns or
|
||||
/// mints tokens without emitting transfer events.
|
||||
/// - You may want to ignore LP tokens if your protocol emits transfer events for these
|
||||
/// here.
|
||||
/// - If your protocol emits events that let you calculate balance deltas more efficiently you may
|
||||
/// want to use those instead of raw transfers.
|
||||
/// - Changes are necessary if your protocol uses native ETH or your component burns or mints tokens
|
||||
/// without emitting transfer events.
|
||||
/// - You may want to ignore LP tokens if your protocol emits transfer events for these here.
|
||||
#[substreams::handlers::map]
|
||||
fn map_relative_component_balance(params: String, block: eth::v2::Block, store: StoreGetInt64) -> Result<BlockBalanceDeltas> {
|
||||
fn map_relative_component_balance(
|
||||
params: String,
|
||||
block: eth::v2::Block,
|
||||
store: StoreGetInt64,
|
||||
) -> Result<BlockBalanceDeltas> {
|
||||
let config: DeploymentConfig = serde_qs::from_str(params.as_str())?;
|
||||
let res = block
|
||||
.transactions()
|
||||
.flat_map(|tx| {
|
||||
tx
|
||||
.logs_with_calls()
|
||||
tx.logs_with_calls()
|
||||
.filter_map(|(log, call)| {
|
||||
let token_addr_hex = hex::encode(&log.address);
|
||||
if !store.has_last(&token_addr_hex) {
|
||||
@@ -222,19 +218,17 @@ fn map_protocol_changes(
|
||||
balances
|
||||
.values()
|
||||
.for_each(|token_bc_map| {
|
||||
token_bc_map
|
||||
.values()
|
||||
.for_each(|bc| {
|
||||
// track component balance
|
||||
builder.add_balance_change(bc);
|
||||
// track vault contract balance
|
||||
contract_changes.upsert_token_balance(bc.token.as_slice(), bc.balance.as_slice())
|
||||
})
|
||||
token_bc_map.values().for_each(|bc| {
|
||||
// track component balance
|
||||
builder.add_balance_change(bc);
|
||||
// track vault contract balance
|
||||
contract_changes
|
||||
.upsert_token_balance(bc.token.as_slice(), bc.balance.as_slice())
|
||||
})
|
||||
});
|
||||
builder.add_contract_changes(&contract_changes);
|
||||
});
|
||||
|
||||
|
||||
// Extract and insert any storage changes that happened for any of the components.
|
||||
extract_contract_changes_builder(
|
||||
&block,
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
use serde::Deserialize;
|
||||
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,
|
||||
};
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct DeploymentConfig {
|
||||
@@ -48,7 +49,6 @@ pub fn maybe_create_component(
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user