refactor(balancer-substreams): remove pool_id static attr and use ProtocolComponent.id instead
This commit is contained in:
@@ -5,7 +5,7 @@ use std::collections::HashMap;
|
||||
use substreams::{
|
||||
hex,
|
||||
pb::substreams::StoreDeltas,
|
||||
store::{StoreAdd, StoreAddBigInt, StoreAddInt64, StoreGet, StoreGetInt64, StoreNew},
|
||||
store::{StoreAddBigInt, StoreGet, StoreGetString, StoreNew, StoreSet, StoreSetString},
|
||||
};
|
||||
use substreams_ethereum::{pb::eth, Event};
|
||||
use tycho_substreams::{
|
||||
@@ -44,18 +44,17 @@ pub fn map_components(block: eth::v2::Block) -> Result<BlockTransactionProtocolC
|
||||
})
|
||||
}
|
||||
|
||||
/// Simply stores the `ProtocolComponent`s with the pool id as the key
|
||||
/// Simply stores the `ProtocolComponent`s with the pool address as the key and the pool id as value
|
||||
#[substreams::handlers::store]
|
||||
pub fn store_components(map: BlockTransactionProtocolComponents, store: StoreAddInt64) {
|
||||
store.add_many(
|
||||
0,
|
||||
&map.tx_components
|
||||
.iter()
|
||||
.flat_map(|tx_components| &tx_components.components)
|
||||
.map(|component| format!("pool:{0}", component.id))
|
||||
.collect::<Vec<_>>(),
|
||||
1,
|
||||
);
|
||||
pub fn store_components(map: BlockTransactionProtocolComponents, store: StoreSetString) {
|
||||
map.tx_components
|
||||
.into_iter()
|
||||
.for_each(|tx_pc| {
|
||||
tx_pc
|
||||
.components
|
||||
.into_iter()
|
||||
.for_each(|pc| store.set(0, format!("pool:{0}", &pc.id[..42]), &pc.id))
|
||||
});
|
||||
}
|
||||
|
||||
/// Since the `PoolBalanceChanged` and `Swap` events administer only deltas, we need to leverage a
|
||||
@@ -63,7 +62,7 @@ pub fn store_components(map: BlockTransactionProtocolComponents, store: StoreAdd
|
||||
#[substreams::handlers::map]
|
||||
pub fn map_relative_balances(
|
||||
block: eth::v2::Block,
|
||||
store: StoreGetInt64,
|
||||
store: StoreGetString,
|
||||
) -> Result<BlockBalanceDeltas, anyhow::Error> {
|
||||
let balance_deltas = block
|
||||
.logs()
|
||||
@@ -74,10 +73,10 @@ pub fn map_relative_balances(
|
||||
if let Some(ev) =
|
||||
abi::vault::events::PoolBalanceChanged::match_and_decode(vault_log.log)
|
||||
{
|
||||
let component_id = format!("0x{}", hex::encode(&ev.pool_id[..20]));
|
||||
let component_id = format!("0x{}", hex::encode(ev.pool_id));
|
||||
|
||||
if store
|
||||
.get_last(format!("pool:{}", component_id))
|
||||
.get_last(format!("pool:{}", &component_id[..42]))
|
||||
.is_some()
|
||||
{
|
||||
for (token, delta) in ev.tokens.iter().zip(ev.deltas.iter()) {
|
||||
@@ -141,7 +140,7 @@ pub fn map_protocol_changes(
|
||||
block: eth::v2::Block,
|
||||
grouped_components: BlockTransactionProtocolComponents,
|
||||
deltas: BlockBalanceDeltas,
|
||||
components_store: StoreGetInt64,
|
||||
components_store: StoreGetString,
|
||||
balance_store: StoreDeltas, // Note, this map module is using the `deltas` mode for the store.
|
||||
) -> Result<BlockChanges> {
|
||||
// We merge contract changes by transaction (identified by transaction index) making it easy to
|
||||
@@ -226,7 +225,11 @@ pub fn map_protocol_changes(
|
||||
.for_each(|address| {
|
||||
if address != VAULT_ADDRESS {
|
||||
// We reconstruct the component_id from the address here
|
||||
change.mark_component_as_updated(&format!("0x{}", hex::encode(address)))
|
||||
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`
|
||||
change.mark_component_as_updated(&id);
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
@@ -61,32 +61,28 @@ pub fn address_map(
|
||||
let pool_registered = get_pool_registered(tx, &pool_created.pool);
|
||||
|
||||
Some(
|
||||
ProtocolComponent::at_contract(&pool_created.pool, &(tx.into()))
|
||||
.with_contracts(&[pool_created.pool, VAULT_ADDRESS.to_vec()])
|
||||
.with_tokens(&create_call.tokens)
|
||||
.with_attributes(&[
|
||||
("pool_type", "WeightedPoolFactory".as_bytes()),
|
||||
(
|
||||
"normalized_weights",
|
||||
&json_serialize_bigint_list(&create_call.normalized_weights),
|
||||
),
|
||||
(
|
||||
"pool_id",
|
||||
format!("0x{}", hex::encode(pool_registered.pool_id)).as_bytes(),
|
||||
),
|
||||
(
|
||||
"rate_providers",
|
||||
&json_serialize_address_list(&create_call.rate_providers),
|
||||
),
|
||||
(
|
||||
"fee",
|
||||
&create_call
|
||||
.swap_fee_percentage
|
||||
.to_signed_bytes_be(),
|
||||
),
|
||||
("manual_updates", &[1u8]),
|
||||
])
|
||||
.as_swap_type("balancer_pool", ImplementationType::Vm),
|
||||
ProtocolComponent::new(
|
||||
&format!("0x{}", hex::encode(pool_registered.pool_id)),
|
||||
&(tx.into()),
|
||||
)
|
||||
.with_contracts(&[pool_created.pool, VAULT_ADDRESS.to_vec()])
|
||||
.with_tokens(&create_call.tokens)
|
||||
.with_attributes(&[
|
||||
("pool_type", "WeightedPoolFactory".as_bytes()),
|
||||
(
|
||||
"normalized_weights",
|
||||
&json_serialize_bigint_list(&create_call.normalized_weights),
|
||||
),
|
||||
("rate_providers", &json_serialize_address_list(&create_call.rate_providers)),
|
||||
(
|
||||
"fee",
|
||||
&create_call
|
||||
.swap_fee_percentage
|
||||
.to_signed_bytes_be(),
|
||||
),
|
||||
("manual_updates", &[1u8]),
|
||||
])
|
||||
.as_swap_type("balancer_pool", ImplementationType::Vm),
|
||||
)
|
||||
}
|
||||
hex!("DB8d758BCb971e482B2C45f7F8a7740283A1bd3A") => {
|
||||
@@ -98,29 +94,25 @@ pub fn address_map(
|
||||
let tokens_registered = get_token_registered(tx, &pool_registered.pool_id);
|
||||
|
||||
Some(
|
||||
ProtocolComponent::at_contract(&pool_created.pool, &(tx.into()))
|
||||
.with_contracts(&[pool_created.pool.clone(), VAULT_ADDRESS.to_vec()])
|
||||
.with_tokens(&tokens_registered.tokens)
|
||||
.with_attributes(&[
|
||||
("pool_type", "ComposableStablePoolFactory".as_bytes()),
|
||||
(
|
||||
"pool_id",
|
||||
format!("0x{}", hex::encode(pool_registered.pool_id)).as_bytes(),
|
||||
),
|
||||
("bpt", &pool_created.pool),
|
||||
(
|
||||
"fee",
|
||||
&create_call
|
||||
.swap_fee_percentage
|
||||
.to_signed_bytes_be(),
|
||||
),
|
||||
(
|
||||
"rate_providers",
|
||||
&json_serialize_address_list(&create_call.rate_providers),
|
||||
),
|
||||
("manual_updates", &[1u8]),
|
||||
])
|
||||
.as_swap_type("balancer_pool", ImplementationType::Vm),
|
||||
ProtocolComponent::new(
|
||||
&format!("0x{}", hex::encode(pool_registered.pool_id)),
|
||||
&(tx.into()),
|
||||
)
|
||||
.with_contracts(&[pool_created.pool.clone(), VAULT_ADDRESS.to_vec()])
|
||||
.with_tokens(&tokens_registered.tokens)
|
||||
.with_attributes(&[
|
||||
("pool_type", "ComposableStablePoolFactory".as_bytes()),
|
||||
("bpt", &pool_created.pool),
|
||||
(
|
||||
"fee",
|
||||
&create_call
|
||||
.swap_fee_percentage
|
||||
.to_signed_bytes_be(),
|
||||
),
|
||||
("rate_providers", &json_serialize_address_list(&create_call.rate_providers)),
|
||||
("manual_updates", &[1u8]),
|
||||
])
|
||||
.as_swap_type("balancer_pool", ImplementationType::Vm),
|
||||
)
|
||||
}
|
||||
hex!("813EE7a840CE909E7Fea2117A44a90b8063bd4fd") => {
|
||||
@@ -132,33 +124,32 @@ pub fn address_map(
|
||||
let tokens_registered = get_token_registered(tx, &pool_registered.pool_id);
|
||||
|
||||
Some(
|
||||
ProtocolComponent::at_contract(&pool_created.pool, &(tx.into()))
|
||||
.with_contracts(&[pool_created.pool.clone(), VAULT_ADDRESS.to_vec()])
|
||||
.with_tokens(&tokens_registered.tokens)
|
||||
.with_attributes(&[
|
||||
("pool_type", "ERC4626LinearPoolFactory".as_bytes()),
|
||||
(
|
||||
"upper_target",
|
||||
&create_call
|
||||
.upper_target
|
||||
.to_signed_bytes_be(),
|
||||
),
|
||||
(
|
||||
"pool_id",
|
||||
format!("0x{}", hex::encode(pool_registered.pool_id)).as_bytes(),
|
||||
),
|
||||
("manual_updates", &[1u8]),
|
||||
("bpt", &pool_created.pool),
|
||||
("main_token", &create_call.main_token),
|
||||
("wrapped_token", &create_call.wrapped_token),
|
||||
(
|
||||
"fee",
|
||||
&create_call
|
||||
.swap_fee_percentage
|
||||
.to_signed_bytes_be(),
|
||||
),
|
||||
])
|
||||
.as_swap_type("balancer_pool", ImplementationType::Vm),
|
||||
ProtocolComponent::new(
|
||||
&format!("0x{}", hex::encode(pool_registered.pool_id)),
|
||||
&(tx.into()),
|
||||
)
|
||||
.with_contracts(&[pool_created.pool.clone(), VAULT_ADDRESS.to_vec()])
|
||||
.with_tokens(&tokens_registered.tokens)
|
||||
.with_attributes(&[
|
||||
("pool_type", "ERC4626LinearPoolFactory".as_bytes()),
|
||||
(
|
||||
"upper_target",
|
||||
&create_call
|
||||
.upper_target
|
||||
.to_signed_bytes_be(),
|
||||
),
|
||||
("manual_updates", &[1u8]),
|
||||
("bpt", &pool_created.pool),
|
||||
("main_token", &create_call.main_token),
|
||||
("wrapped_token", &create_call.wrapped_token),
|
||||
(
|
||||
"fee",
|
||||
&create_call
|
||||
.swap_fee_percentage
|
||||
.to_signed_bytes_be(),
|
||||
),
|
||||
])
|
||||
.as_swap_type("balancer_pool", ImplementationType::Vm),
|
||||
)
|
||||
}
|
||||
hex!("5F43FBa61f63Fa6bFF101a0A0458cEA917f6B347") => {
|
||||
@@ -170,33 +161,32 @@ pub fn address_map(
|
||||
let tokens_registered = get_token_registered(tx, &pool_registered.pool_id);
|
||||
|
||||
Some(
|
||||
ProtocolComponent::at_contract(&pool_created.pool, &(tx.into()))
|
||||
.with_contracts(&[pool_created.pool.clone(), VAULT_ADDRESS.to_vec()])
|
||||
.with_tokens(&tokens_registered.tokens)
|
||||
.with_attributes(&[
|
||||
("pool_type", "EulerLinearPoolFactory".as_bytes()),
|
||||
(
|
||||
"upper_target",
|
||||
&create_call
|
||||
.upper_target
|
||||
.to_signed_bytes_be(),
|
||||
),
|
||||
(
|
||||
"pool_id",
|
||||
format!("0x{}", hex::encode(pool_registered.pool_id)).as_bytes(),
|
||||
),
|
||||
("manual_updates", &[1u8]),
|
||||
("bpt", &pool_created.pool),
|
||||
("main_token", &create_call.main_token),
|
||||
("wrapped_token", &create_call.wrapped_token),
|
||||
(
|
||||
"fee",
|
||||
&create_call
|
||||
.swap_fee_percentage
|
||||
.to_signed_bytes_be(),
|
||||
),
|
||||
])
|
||||
.as_swap_type("balancer_pool", ImplementationType::Vm),
|
||||
ProtocolComponent::new(
|
||||
&format!("0x{}", hex::encode(pool_registered.pool_id)),
|
||||
&(tx.into()),
|
||||
)
|
||||
.with_contracts(&[pool_created.pool.clone(), VAULT_ADDRESS.to_vec()])
|
||||
.with_tokens(&tokens_registered.tokens)
|
||||
.with_attributes(&[
|
||||
("pool_type", "EulerLinearPoolFactory".as_bytes()),
|
||||
(
|
||||
"upper_target",
|
||||
&create_call
|
||||
.upper_target
|
||||
.to_signed_bytes_be(),
|
||||
),
|
||||
("manual_updates", &[1u8]),
|
||||
("bpt", &pool_created.pool),
|
||||
("main_token", &create_call.main_token),
|
||||
("wrapped_token", &create_call.wrapped_token),
|
||||
(
|
||||
"fee",
|
||||
&create_call
|
||||
.swap_fee_percentage
|
||||
.to_signed_bytes_be(),
|
||||
),
|
||||
])
|
||||
.as_swap_type("balancer_pool", ImplementationType::Vm),
|
||||
)
|
||||
}
|
||||
// ❌ Reading the deployed factory for Gearbox showcases that it's currently disabled
|
||||
@@ -256,33 +246,32 @@ pub fn address_map(
|
||||
let tokens_registered = get_token_registered(tx, &pool_registered.pool_id);
|
||||
|
||||
Some(
|
||||
ProtocolComponent::at_contract(&pool_created.pool, &(tx.into()))
|
||||
.with_contracts(&[pool_created.pool.clone(), VAULT_ADDRESS.to_vec()])
|
||||
.with_tokens(&tokens_registered.tokens)
|
||||
.with_attributes(&[
|
||||
("pool_type", "SiloLinearPoolFactory".as_bytes()),
|
||||
(
|
||||
"upper_target",
|
||||
&create_call
|
||||
.upper_target
|
||||
.to_signed_bytes_be(),
|
||||
),
|
||||
(
|
||||
"pool_id",
|
||||
format!("0x{}", hex::encode(pool_registered.pool_id)).as_bytes(),
|
||||
),
|
||||
("manual_updates", &[1u8]),
|
||||
("bpt", &pool_created.pool),
|
||||
("main_token", &create_call.main_token),
|
||||
("wrapped_token", &create_call.wrapped_token),
|
||||
(
|
||||
"fee",
|
||||
&create_call
|
||||
.swap_fee_percentage
|
||||
.to_signed_bytes_be(),
|
||||
),
|
||||
])
|
||||
.as_swap_type("balancer_pool", ImplementationType::Vm),
|
||||
ProtocolComponent::new(
|
||||
&format!("0x{}", hex::encode(pool_registered.pool_id)),
|
||||
&(tx.into()),
|
||||
)
|
||||
.with_contracts(&[pool_created.pool.clone(), VAULT_ADDRESS.to_vec()])
|
||||
.with_tokens(&tokens_registered.tokens)
|
||||
.with_attributes(&[
|
||||
("pool_type", "SiloLinearPoolFactory".as_bytes()),
|
||||
(
|
||||
"upper_target",
|
||||
&create_call
|
||||
.upper_target
|
||||
.to_signed_bytes_be(),
|
||||
),
|
||||
("manual_updates", &[1u8]),
|
||||
("bpt", &pool_created.pool),
|
||||
("main_token", &create_call.main_token),
|
||||
("wrapped_token", &create_call.wrapped_token),
|
||||
(
|
||||
"fee",
|
||||
&create_call
|
||||
.swap_fee_percentage
|
||||
.to_signed_bytes_be(),
|
||||
),
|
||||
])
|
||||
.as_swap_type("balancer_pool", ImplementationType::Vm),
|
||||
)
|
||||
}
|
||||
hex!("5F5222Ffa40F2AEd6380D022184D6ea67C776eE0") => {
|
||||
@@ -294,33 +283,32 @@ pub fn address_map(
|
||||
let tokens_registered = get_token_registered(tx, &pool_registered.pool_id);
|
||||
|
||||
Some(
|
||||
ProtocolComponent::at_contract(&pool_created.pool, &(tx.into()))
|
||||
.with_contracts(&[pool_created.pool.clone(), VAULT_ADDRESS.to_vec()])
|
||||
.with_tokens(&tokens_registered.tokens)
|
||||
.with_attributes(&[
|
||||
("pool_type", "YearnLinearPoolFactory".as_bytes()),
|
||||
(
|
||||
"upper_target",
|
||||
&create_call
|
||||
.upper_target
|
||||
.to_signed_bytes_be(),
|
||||
),
|
||||
(
|
||||
"pool_id",
|
||||
format!("0x{}", hex::encode(pool_registered.pool_id)).as_bytes(),
|
||||
),
|
||||
("manual_updates", &[1u8]),
|
||||
("bpt", &pool_created.pool),
|
||||
("main_token", &create_call.main_token),
|
||||
("wrapped_token", &create_call.wrapped_token),
|
||||
(
|
||||
"fee",
|
||||
&create_call
|
||||
.swap_fee_percentage
|
||||
.to_signed_bytes_be(),
|
||||
),
|
||||
])
|
||||
.as_swap_type("balancer_pool", ImplementationType::Vm),
|
||||
ProtocolComponent::new(
|
||||
&format!("0x{}", hex::encode(pool_registered.pool_id)),
|
||||
&(tx.into()),
|
||||
)
|
||||
.with_contracts(&[pool_created.pool.clone(), VAULT_ADDRESS.to_vec()])
|
||||
.with_tokens(&tokens_registered.tokens)
|
||||
.with_attributes(&[
|
||||
("pool_type", "YearnLinearPoolFactory".as_bytes()),
|
||||
(
|
||||
"upper_target",
|
||||
&create_call
|
||||
.upper_target
|
||||
.to_signed_bytes_be(),
|
||||
),
|
||||
("manual_updates", &[1u8]),
|
||||
("bpt", &pool_created.pool),
|
||||
("main_token", &create_call.main_token),
|
||||
("wrapped_token", &create_call.wrapped_token),
|
||||
(
|
||||
"fee",
|
||||
&create_call
|
||||
.swap_fee_percentage
|
||||
.to_signed_bytes_be(),
|
||||
),
|
||||
])
|
||||
.as_swap_type("balancer_pool", ImplementationType::Vm),
|
||||
)
|
||||
}
|
||||
// The `WeightedPool2TokenFactory` is a deprecated contract, but we've included
|
||||
@@ -333,25 +321,24 @@ pub fn address_map(
|
||||
let pool_registered = get_pool_registered(tx, &pool_created.pool);
|
||||
|
||||
Some(
|
||||
ProtocolComponent::at_contract(&pool_created.pool, &(tx.into()))
|
||||
.with_contracts(&[pool_created.pool, VAULT_ADDRESS.to_vec()])
|
||||
.with_tokens(&create_call.tokens)
|
||||
.with_attributes(&[
|
||||
("pool_type", "WeightedPool2TokensFactory".as_bytes()),
|
||||
("weights", &json_serialize_bigint_list(&create_call.weights)),
|
||||
(
|
||||
"pool_id",
|
||||
format!("0x{}", hex::encode(pool_registered.pool_id)).as_bytes(),
|
||||
),
|
||||
(
|
||||
"fee",
|
||||
&create_call
|
||||
.swap_fee_percentage
|
||||
.to_signed_bytes_be(),
|
||||
),
|
||||
("manual_updates", &[1u8]),
|
||||
])
|
||||
.as_swap_type("balancer_pool", ImplementationType::Vm),
|
||||
ProtocolComponent::new(
|
||||
&format!("0x{}", hex::encode(pool_registered.pool_id)),
|
||||
&(tx.into()),
|
||||
)
|
||||
.with_contracts(&[pool_created.pool, VAULT_ADDRESS.to_vec()])
|
||||
.with_tokens(&create_call.tokens)
|
||||
.with_attributes(&[
|
||||
("pool_type", "WeightedPool2TokensFactory".as_bytes()),
|
||||
("weights", &json_serialize_bigint_list(&create_call.weights)),
|
||||
(
|
||||
"fee",
|
||||
&create_call
|
||||
.swap_fee_percentage
|
||||
.to_signed_bytes_be(),
|
||||
),
|
||||
("manual_updates", &[1u8]),
|
||||
])
|
||||
.as_swap_type("balancer_pool", ImplementationType::Vm),
|
||||
)
|
||||
}
|
||||
_ => None,
|
||||
|
||||
Reference in New Issue
Block a user