refactor: make pool_id a static attribute
This commit is contained in:
committed by
Thales Lima
parent
47e6f08338
commit
a2e951aff3
@@ -12,7 +12,7 @@ use tycho_substreams::{
|
||||
balances::aggregate_balances_changes, contract::extract_contract_changes, prelude::*,
|
||||
};
|
||||
|
||||
const VAULT_ADDRESS: &[u8] = &hex!("BA12222222228d8Ba445958a75a0704d566BF2C8");
|
||||
pub const VAULT_ADDRESS: &[u8] = &hex!("BA12222222228d8Ba445958a75a0704d566BF2C8");
|
||||
|
||||
#[substreams::handlers::map]
|
||||
pub fn map_components(block: eth::v2::Block) -> Result<BlockTransactionProtocolComponents> {
|
||||
@@ -29,7 +29,7 @@ pub fn map_components(block: eth::v2::Block) -> Result<BlockTransactionProtocolC
|
||||
call.call.address.as_slice(),
|
||||
log,
|
||||
call.call,
|
||||
&(tx.into()),
|
||||
tx,
|
||||
)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
@@ -160,48 +160,26 @@ pub fn map_protocol_changes(
|
||||
.or_insert_with(|| TransactionChanges::new(tx))
|
||||
.component_changes
|
||||
.extend_from_slice(&tx_component.components);
|
||||
});
|
||||
|
||||
block
|
||||
.transactions()
|
||||
.flat_map(|tx| {
|
||||
let components = tx
|
||||
.logs_with_calls()
|
||||
.filter(|(log, _)| log.address == VAULT_ADDRESS)
|
||||
.filter_map(|(log, _)| {
|
||||
let registered = abi::vault::events::PoolRegistered::match_and_decode(log)?;
|
||||
Some((
|
||||
tx.clone(),
|
||||
EntityChanges {
|
||||
component_id: hex::encode(registered.pool_address),
|
||||
attributes: vec![
|
||||
Attribute {
|
||||
name: "pool_id".to_string(),
|
||||
value: format!("0x{}", hex::encode(registered.pool_id))
|
||||
.as_bytes()
|
||||
.to_vec(),
|
||||
change: ChangeType::Creation.into(),
|
||||
},
|
||||
Attribute {
|
||||
name: "balance_owner".to_string(),
|
||||
value: "0xBA12222222228d8Ba445958a75a0704d566BF2C8"
|
||||
.to_string()
|
||||
.as_bytes()
|
||||
.to_vec(),
|
||||
change: ChangeType::Creation.into(),
|
||||
},
|
||||
],
|
||||
},
|
||||
))
|
||||
tx_component
|
||||
.components
|
||||
.iter()
|
||||
.for_each(|component| {
|
||||
transaction_changes
|
||||
.entry(tx.index)
|
||||
.or_insert_with(|| TransactionChanges::new(tx))
|
||||
.entity_changes
|
||||
.push(EntityChanges {
|
||||
component_id: component.id.clone(),
|
||||
attributes: vec![Attribute {
|
||||
name: "balance_owner".to_string(),
|
||||
value: "0xBA12222222228d8Ba445958a75a0704d566BF2C8"
|
||||
.to_string()
|
||||
.as_bytes()
|
||||
.to_vec(),
|
||||
change: ChangeType::Creation.into(),
|
||||
}],
|
||||
});
|
||||
});
|
||||
components
|
||||
})
|
||||
.for_each(|(tx, state_change)| {
|
||||
transaction_changes
|
||||
.entry(tx.index.into())
|
||||
.or_insert_with(|| TransactionChanges::new(&(&tx).into()))
|
||||
.entity_changes
|
||||
.push(state_change);
|
||||
});
|
||||
|
||||
// Balance changes are gathered by the `StoreDelta` based on `PoolBalanceChanged` creating
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::abi;
|
||||
use crate::{abi, modules::VAULT_ADDRESS};
|
||||
use substreams::{hex, scalar::BigInt};
|
||||
use substreams_ethereum::{
|
||||
pb::eth::v2::{Call, Log},
|
||||
pb::eth::v2::{Call, Log, TransactionTrace},
|
||||
Event, Function,
|
||||
};
|
||||
use tycho_substreams::prelude::*;
|
||||
@@ -29,6 +29,19 @@ impl SerializableVecBigInt for Vec<BigInt> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Helper function to get pool_registered event
|
||||
fn get_pool_registered(
|
||||
tx: &TransactionTrace,
|
||||
pool_address: &Vec<u8>,
|
||||
) -> abi::vault::events::PoolRegistered {
|
||||
tx.logs_with_calls()
|
||||
.filter(|(log, _)| log.address == VAULT_ADDRESS)
|
||||
.filter_map(|(log, _)| abi::vault::events::PoolRegistered::match_and_decode(log))
|
||||
.find(|pool| pool.pool_address == *pool_address)
|
||||
.unwrap()
|
||||
.clone()
|
||||
}
|
||||
|
||||
/// This is the main function that handles the creation of `ProtocolComponent`s with `Attribute`s
|
||||
/// based on the specific factory address. There's 3 factory groups that are represented here:
|
||||
/// - Weighted Pool Factories
|
||||
@@ -45,7 +58,7 @@ pub fn address_map(
|
||||
pool_factory_address: &[u8],
|
||||
log: &Log,
|
||||
call: &Call,
|
||||
tx: &Transaction,
|
||||
tx: &TransactionTrace,
|
||||
) -> Option<ProtocolComponent> {
|
||||
match *pool_factory_address {
|
||||
hex!("897888115Ada5773E02aA29F775430BFB5F34c51") => {
|
||||
@@ -53,9 +66,10 @@ pub fn address_map(
|
||||
abi::weighted_pool_factory::functions::Create::match_and_decode(call)?;
|
||||
let pool_created =
|
||||
abi::weighted_pool_factory::events::PoolCreated::match_and_decode(log)?;
|
||||
let pool_registered = get_pool_registered(tx, &pool_created.pool);
|
||||
|
||||
Some(
|
||||
ProtocolComponent::at_contract(&pool_created.pool, tx)
|
||||
ProtocolComponent::at_contract(&pool_created.pool, &(tx.into()))
|
||||
.with_tokens(&create_call.tokens)
|
||||
.with_attributes(&[
|
||||
("pool_type", "WeightedPoolFactory".as_bytes()),
|
||||
@@ -65,6 +79,10 @@ pub fn address_map(
|
||||
.normalized_weights
|
||||
.serialize_bytes(),
|
||||
),
|
||||
(
|
||||
"pool_id",
|
||||
format!("0x{}", hex::encode(pool_registered.pool_id)).as_bytes(),
|
||||
),
|
||||
])
|
||||
.as_swap_type("balancer_pool", ImplementationType::Vm),
|
||||
)
|
||||
@@ -74,11 +92,18 @@ pub fn address_map(
|
||||
abi::composable_stable_pool_factory::functions::Create::match_and_decode(call)?;
|
||||
let pool_created =
|
||||
abi::composable_stable_pool_factory::events::PoolCreated::match_and_decode(log)?;
|
||||
let pool_registered = get_pool_registered(tx, &pool_created.pool);
|
||||
|
||||
Some(
|
||||
ProtocolComponent::at_contract(&pool_created.pool, tx)
|
||||
ProtocolComponent::at_contract(&pool_created.pool, &(tx.into()))
|
||||
.with_tokens(&create_call.tokens)
|
||||
.with_attributes(&[("pool_type", "ComposableStablePoolFactory".as_bytes())])
|
||||
.with_attributes(&[
|
||||
("pool_type", "ComposableStablePoolFactory".as_bytes()),
|
||||
(
|
||||
"pool_id",
|
||||
format!("0x{}", hex::encode(pool_registered.pool_id)).as_bytes(),
|
||||
),
|
||||
])
|
||||
.as_swap_type("balancer_pool", ImplementationType::Vm),
|
||||
)
|
||||
}
|
||||
@@ -87,9 +112,10 @@ pub fn address_map(
|
||||
abi::erc_linear_pool_factory::functions::Create::match_and_decode(call)?;
|
||||
let pool_created =
|
||||
abi::erc_linear_pool_factory::events::PoolCreated::match_and_decode(log)?;
|
||||
let pool_registered = get_pool_registered(tx, &pool_created.pool);
|
||||
|
||||
Some(
|
||||
ProtocolComponent::at_contract(&pool_created.pool, tx)
|
||||
ProtocolComponent::at_contract(&pool_created.pool, &(tx.into()))
|
||||
.with_tokens(&[create_call.main_token, create_call.wrapped_token])
|
||||
.with_attributes(&[
|
||||
("pool_type", "ERC4626LinearPoolFactory".as_bytes()),
|
||||
@@ -99,6 +125,10 @@ pub fn address_map(
|
||||
.upper_target
|
||||
.to_signed_bytes_be(),
|
||||
),
|
||||
(
|
||||
"pool_id",
|
||||
format!("0x{}", hex::encode(pool_registered.pool_id)).as_bytes(),
|
||||
),
|
||||
])
|
||||
.as_swap_type("balancer_pool", ImplementationType::Vm),
|
||||
)
|
||||
@@ -108,9 +138,10 @@ pub fn address_map(
|
||||
abi::euler_linear_pool_factory::functions::Create::match_and_decode(call)?;
|
||||
let pool_created =
|
||||
abi::euler_linear_pool_factory::events::PoolCreated::match_and_decode(log)?;
|
||||
let pool_registered = get_pool_registered(tx, &pool_created.pool);
|
||||
|
||||
Some(
|
||||
ProtocolComponent::at_contract(&pool_created.pool, tx)
|
||||
ProtocolComponent::at_contract(&pool_created.pool, &(tx.into()))
|
||||
.with_tokens(&[create_call.main_token, create_call.wrapped_token])
|
||||
.with_attributes(&[
|
||||
("pool_type", "EulerLinearPoolFactory".as_bytes()),
|
||||
@@ -120,6 +151,10 @@ pub fn address_map(
|
||||
.upper_target
|
||||
.to_signed_bytes_be(),
|
||||
),
|
||||
(
|
||||
"pool_id",
|
||||
format!("0x{}", hex::encode(pool_registered.pool_id)).as_bytes(),
|
||||
),
|
||||
])
|
||||
.as_swap_type("balancer_pool", ImplementationType::Vm),
|
||||
)
|
||||
@@ -177,9 +212,10 @@ pub fn address_map(
|
||||
abi::silo_linear_pool_factory::functions::Create::match_and_decode(call)?;
|
||||
let pool_created =
|
||||
abi::silo_linear_pool_factory::events::PoolCreated::match_and_decode(log)?;
|
||||
let pool_registered = get_pool_registered(tx, &pool_created.pool);
|
||||
|
||||
Some(
|
||||
ProtocolComponent::at_contract(&pool_created.pool, tx)
|
||||
ProtocolComponent::at_contract(&pool_created.pool, &(tx.into()))
|
||||
.with_tokens(&[create_call.main_token, create_call.wrapped_token])
|
||||
.with_attributes(&[
|
||||
("pool_type", "SiloLinearPoolFactory".as_bytes()),
|
||||
@@ -189,6 +225,10 @@ pub fn address_map(
|
||||
.upper_target
|
||||
.to_signed_bytes_be(),
|
||||
),
|
||||
(
|
||||
"pool_id",
|
||||
format!("0x{}", hex::encode(pool_registered.pool_id)).as_bytes(),
|
||||
),
|
||||
])
|
||||
.as_swap_type("balancer_pool", ImplementationType::Vm),
|
||||
)
|
||||
@@ -198,9 +238,10 @@ pub fn address_map(
|
||||
abi::yearn_linear_pool_factory::functions::Create::match_and_decode(call)?;
|
||||
let pool_created =
|
||||
abi::yearn_linear_pool_factory::events::PoolCreated::match_and_decode(log)?;
|
||||
let pool_registered = get_pool_registered(tx, &pool_created.pool);
|
||||
|
||||
Some(
|
||||
ProtocolComponent::at_contract(&pool_created.pool, tx)
|
||||
ProtocolComponent::at_contract(&pool_created.pool, &(tx.into()))
|
||||
.with_tokens(&[create_call.main_token, create_call.wrapped_token])
|
||||
.with_attributes(&[
|
||||
("pool_type", "YearnLinearPoolFactory".as_bytes()),
|
||||
@@ -210,6 +251,10 @@ pub fn address_map(
|
||||
.upper_target
|
||||
.to_signed_bytes_be(),
|
||||
),
|
||||
(
|
||||
"pool_id",
|
||||
format!("0x{}", hex::encode(pool_registered.pool_id)).as_bytes(),
|
||||
),
|
||||
])
|
||||
.as_swap_type("balancer_pool", ImplementationType::Vm),
|
||||
)
|
||||
@@ -221,13 +266,18 @@ pub fn address_map(
|
||||
abi::weighted_pool_tokens_factory::functions::Create::match_and_decode(call)?;
|
||||
let pool_created =
|
||||
abi::weighted_pool_tokens_factory::events::PoolCreated::match_and_decode(log)?;
|
||||
let pool_registered = get_pool_registered(tx, &pool_created.pool);
|
||||
|
||||
Some(
|
||||
ProtocolComponent::at_contract(&pool_created.pool, tx)
|
||||
ProtocolComponent::at_contract(&pool_created.pool, &(tx.into()))
|
||||
.with_tokens(&create_call.tokens)
|
||||
.with_attributes(&[
|
||||
("pool_type", "WeightedPool2TokensFactory".as_bytes()),
|
||||
("weights", &create_call.weights.serialize_bytes()),
|
||||
(
|
||||
"pool_id",
|
||||
format!("0x{}", hex::encode(pool_registered.pool_id)).as_bytes(),
|
||||
),
|
||||
])
|
||||
.as_swap_type("balancer_pool", ImplementationType::Vm),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user