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::*,
|
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]
|
#[substreams::handlers::map]
|
||||||
pub fn map_components(block: eth::v2::Block) -> Result<BlockTransactionProtocolComponents> {
|
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(),
|
call.call.address.as_slice(),
|
||||||
log,
|
log,
|
||||||
call.call,
|
call.call,
|
||||||
&(tx.into()),
|
tx,
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
@@ -160,48 +160,26 @@ pub fn map_protocol_changes(
|
|||||||
.or_insert_with(|| TransactionChanges::new(tx))
|
.or_insert_with(|| TransactionChanges::new(tx))
|
||||||
.component_changes
|
.component_changes
|
||||||
.extend_from_slice(&tx_component.components);
|
.extend_from_slice(&tx_component.components);
|
||||||
});
|
tx_component
|
||||||
|
.components
|
||||||
block
|
.iter()
|
||||||
.transactions()
|
.for_each(|component| {
|
||||||
.flat_map(|tx| {
|
transaction_changes
|
||||||
let components = tx
|
.entry(tx.index)
|
||||||
.logs_with_calls()
|
.or_insert_with(|| TransactionChanges::new(tx))
|
||||||
.filter(|(log, _)| log.address == VAULT_ADDRESS)
|
.entity_changes
|
||||||
.filter_map(|(log, _)| {
|
.push(EntityChanges {
|
||||||
let registered = abi::vault::events::PoolRegistered::match_and_decode(log)?;
|
component_id: component.id.clone(),
|
||||||
Some((
|
attributes: vec![Attribute {
|
||||||
tx.clone(),
|
name: "balance_owner".to_string(),
|
||||||
EntityChanges {
|
value: "0xBA12222222228d8Ba445958a75a0704d566BF2C8"
|
||||||
component_id: hex::encode(registered.pool_address),
|
.to_string()
|
||||||
attributes: vec![
|
.as_bytes()
|
||||||
Attribute {
|
.to_vec(),
|
||||||
name: "pool_id".to_string(),
|
change: ChangeType::Creation.into(),
|
||||||
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(),
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
))
|
|
||||||
});
|
});
|
||||||
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
|
// 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::{hex, scalar::BigInt};
|
||||||
use substreams_ethereum::{
|
use substreams_ethereum::{
|
||||||
pb::eth::v2::{Call, Log},
|
pb::eth::v2::{Call, Log, TransactionTrace},
|
||||||
Event, Function,
|
Event, Function,
|
||||||
};
|
};
|
||||||
use tycho_substreams::prelude::*;
|
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
|
/// 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:
|
/// based on the specific factory address. There's 3 factory groups that are represented here:
|
||||||
/// - Weighted Pool Factories
|
/// - Weighted Pool Factories
|
||||||
@@ -45,7 +58,7 @@ pub fn address_map(
|
|||||||
pool_factory_address: &[u8],
|
pool_factory_address: &[u8],
|
||||||
log: &Log,
|
log: &Log,
|
||||||
call: &Call,
|
call: &Call,
|
||||||
tx: &Transaction,
|
tx: &TransactionTrace,
|
||||||
) -> Option<ProtocolComponent> {
|
) -> Option<ProtocolComponent> {
|
||||||
match *pool_factory_address {
|
match *pool_factory_address {
|
||||||
hex!("897888115Ada5773E02aA29F775430BFB5F34c51") => {
|
hex!("897888115Ada5773E02aA29F775430BFB5F34c51") => {
|
||||||
@@ -53,9 +66,10 @@ pub fn address_map(
|
|||||||
abi::weighted_pool_factory::functions::Create::match_and_decode(call)?;
|
abi::weighted_pool_factory::functions::Create::match_and_decode(call)?;
|
||||||
let pool_created =
|
let pool_created =
|
||||||
abi::weighted_pool_factory::events::PoolCreated::match_and_decode(log)?;
|
abi::weighted_pool_factory::events::PoolCreated::match_and_decode(log)?;
|
||||||
|
let pool_registered = get_pool_registered(tx, &pool_created.pool);
|
||||||
|
|
||||||
Some(
|
Some(
|
||||||
ProtocolComponent::at_contract(&pool_created.pool, tx)
|
ProtocolComponent::at_contract(&pool_created.pool, &(tx.into()))
|
||||||
.with_tokens(&create_call.tokens)
|
.with_tokens(&create_call.tokens)
|
||||||
.with_attributes(&[
|
.with_attributes(&[
|
||||||
("pool_type", "WeightedPoolFactory".as_bytes()),
|
("pool_type", "WeightedPoolFactory".as_bytes()),
|
||||||
@@ -65,6 +79,10 @@ pub fn address_map(
|
|||||||
.normalized_weights
|
.normalized_weights
|
||||||
.serialize_bytes(),
|
.serialize_bytes(),
|
||||||
),
|
),
|
||||||
|
(
|
||||||
|
"pool_id",
|
||||||
|
format!("0x{}", hex::encode(pool_registered.pool_id)).as_bytes(),
|
||||||
|
),
|
||||||
])
|
])
|
||||||
.as_swap_type("balancer_pool", ImplementationType::Vm),
|
.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)?;
|
abi::composable_stable_pool_factory::functions::Create::match_and_decode(call)?;
|
||||||
let pool_created =
|
let pool_created =
|
||||||
abi::composable_stable_pool_factory::events::PoolCreated::match_and_decode(log)?;
|
abi::composable_stable_pool_factory::events::PoolCreated::match_and_decode(log)?;
|
||||||
|
let pool_registered = get_pool_registered(tx, &pool_created.pool);
|
||||||
|
|
||||||
Some(
|
Some(
|
||||||
ProtocolComponent::at_contract(&pool_created.pool, tx)
|
ProtocolComponent::at_contract(&pool_created.pool, &(tx.into()))
|
||||||
.with_tokens(&create_call.tokens)
|
.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),
|
.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)?;
|
abi::erc_linear_pool_factory::functions::Create::match_and_decode(call)?;
|
||||||
let pool_created =
|
let pool_created =
|
||||||
abi::erc_linear_pool_factory::events::PoolCreated::match_and_decode(log)?;
|
abi::erc_linear_pool_factory::events::PoolCreated::match_and_decode(log)?;
|
||||||
|
let pool_registered = get_pool_registered(tx, &pool_created.pool);
|
||||||
|
|
||||||
Some(
|
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_tokens(&[create_call.main_token, create_call.wrapped_token])
|
||||||
.with_attributes(&[
|
.with_attributes(&[
|
||||||
("pool_type", "ERC4626LinearPoolFactory".as_bytes()),
|
("pool_type", "ERC4626LinearPoolFactory".as_bytes()),
|
||||||
@@ -99,6 +125,10 @@ pub fn address_map(
|
|||||||
.upper_target
|
.upper_target
|
||||||
.to_signed_bytes_be(),
|
.to_signed_bytes_be(),
|
||||||
),
|
),
|
||||||
|
(
|
||||||
|
"pool_id",
|
||||||
|
format!("0x{}", hex::encode(pool_registered.pool_id)).as_bytes(),
|
||||||
|
),
|
||||||
])
|
])
|
||||||
.as_swap_type("balancer_pool", ImplementationType::Vm),
|
.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)?;
|
abi::euler_linear_pool_factory::functions::Create::match_and_decode(call)?;
|
||||||
let pool_created =
|
let pool_created =
|
||||||
abi::euler_linear_pool_factory::events::PoolCreated::match_and_decode(log)?;
|
abi::euler_linear_pool_factory::events::PoolCreated::match_and_decode(log)?;
|
||||||
|
let pool_registered = get_pool_registered(tx, &pool_created.pool);
|
||||||
|
|
||||||
Some(
|
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_tokens(&[create_call.main_token, create_call.wrapped_token])
|
||||||
.with_attributes(&[
|
.with_attributes(&[
|
||||||
("pool_type", "EulerLinearPoolFactory".as_bytes()),
|
("pool_type", "EulerLinearPoolFactory".as_bytes()),
|
||||||
@@ -120,6 +151,10 @@ pub fn address_map(
|
|||||||
.upper_target
|
.upper_target
|
||||||
.to_signed_bytes_be(),
|
.to_signed_bytes_be(),
|
||||||
),
|
),
|
||||||
|
(
|
||||||
|
"pool_id",
|
||||||
|
format!("0x{}", hex::encode(pool_registered.pool_id)).as_bytes(),
|
||||||
|
),
|
||||||
])
|
])
|
||||||
.as_swap_type("balancer_pool", ImplementationType::Vm),
|
.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)?;
|
abi::silo_linear_pool_factory::functions::Create::match_and_decode(call)?;
|
||||||
let pool_created =
|
let pool_created =
|
||||||
abi::silo_linear_pool_factory::events::PoolCreated::match_and_decode(log)?;
|
abi::silo_linear_pool_factory::events::PoolCreated::match_and_decode(log)?;
|
||||||
|
let pool_registered = get_pool_registered(tx, &pool_created.pool);
|
||||||
|
|
||||||
Some(
|
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_tokens(&[create_call.main_token, create_call.wrapped_token])
|
||||||
.with_attributes(&[
|
.with_attributes(&[
|
||||||
("pool_type", "SiloLinearPoolFactory".as_bytes()),
|
("pool_type", "SiloLinearPoolFactory".as_bytes()),
|
||||||
@@ -189,6 +225,10 @@ pub fn address_map(
|
|||||||
.upper_target
|
.upper_target
|
||||||
.to_signed_bytes_be(),
|
.to_signed_bytes_be(),
|
||||||
),
|
),
|
||||||
|
(
|
||||||
|
"pool_id",
|
||||||
|
format!("0x{}", hex::encode(pool_registered.pool_id)).as_bytes(),
|
||||||
|
),
|
||||||
])
|
])
|
||||||
.as_swap_type("balancer_pool", ImplementationType::Vm),
|
.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)?;
|
abi::yearn_linear_pool_factory::functions::Create::match_and_decode(call)?;
|
||||||
let pool_created =
|
let pool_created =
|
||||||
abi::yearn_linear_pool_factory::events::PoolCreated::match_and_decode(log)?;
|
abi::yearn_linear_pool_factory::events::PoolCreated::match_and_decode(log)?;
|
||||||
|
let pool_registered = get_pool_registered(tx, &pool_created.pool);
|
||||||
|
|
||||||
Some(
|
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_tokens(&[create_call.main_token, create_call.wrapped_token])
|
||||||
.with_attributes(&[
|
.with_attributes(&[
|
||||||
("pool_type", "YearnLinearPoolFactory".as_bytes()),
|
("pool_type", "YearnLinearPoolFactory".as_bytes()),
|
||||||
@@ -210,6 +251,10 @@ pub fn address_map(
|
|||||||
.upper_target
|
.upper_target
|
||||||
.to_signed_bytes_be(),
|
.to_signed_bytes_be(),
|
||||||
),
|
),
|
||||||
|
(
|
||||||
|
"pool_id",
|
||||||
|
format!("0x{}", hex::encode(pool_registered.pool_id)).as_bytes(),
|
||||||
|
),
|
||||||
])
|
])
|
||||||
.as_swap_type("balancer_pool", ImplementationType::Vm),
|
.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)?;
|
abi::weighted_pool_tokens_factory::functions::Create::match_and_decode(call)?;
|
||||||
let pool_created =
|
let pool_created =
|
||||||
abi::weighted_pool_tokens_factory::events::PoolCreated::match_and_decode(log)?;
|
abi::weighted_pool_tokens_factory::events::PoolCreated::match_and_decode(log)?;
|
||||||
|
let pool_registered = get_pool_registered(tx, &pool_created.pool);
|
||||||
|
|
||||||
Some(
|
Some(
|
||||||
ProtocolComponent::at_contract(&pool_created.pool, tx)
|
ProtocolComponent::at_contract(&pool_created.pool, &(tx.into()))
|
||||||
.with_tokens(&create_call.tokens)
|
.with_tokens(&create_call.tokens)
|
||||||
.with_attributes(&[
|
.with_attributes(&[
|
||||||
("pool_type", "WeightedPool2TokensFactory".as_bytes()),
|
("pool_type", "WeightedPool2TokensFactory".as_bytes()),
|
||||||
("weights", &create_call.weights.serialize_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),
|
.as_swap_type("balancer_pool", ImplementationType::Vm),
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user