fix: only emit balance changes if the component is tracked
This commit is contained in:
@@ -89,7 +89,10 @@ pub fn store_pools_created(map: tycho::GroupedTransactionProtocolComponents, sto
|
|||||||
/// Since the `PoolBalanceChanged` events administer only deltas, we need to leverage a map and a
|
/// Since the `PoolBalanceChanged` events administer only deltas, we need to leverage a map and a
|
||||||
/// store to be able to tally up final balances for tokens in a pool.
|
/// store to be able to tally up final balances for tokens in a pool.
|
||||||
#[substreams::handlers::map]
|
#[substreams::handlers::map]
|
||||||
pub fn map_balance_deltas(block: eth::v2::Block) -> Result<tycho::BalanceDeltas, anyhow::Error> {
|
pub fn map_balance_deltas(
|
||||||
|
block: eth::v2::Block,
|
||||||
|
store: StoreGetInt64,
|
||||||
|
) -> Result<tycho::BalanceDeltas, anyhow::Error> {
|
||||||
Ok(tycho::BalanceDeltas {
|
Ok(tycho::BalanceDeltas {
|
||||||
balance_deltas: block
|
balance_deltas: block
|
||||||
.events::<abi::vault::events::PoolBalanceChanged>(&[&VAULT_ADDRESS])
|
.events::<abi::vault::events::PoolBalanceChanged>(&[&VAULT_ADDRESS])
|
||||||
@@ -98,7 +101,17 @@ pub fn map_balance_deltas(block: eth::v2::Block) -> Result<tycho::BalanceDeltas,
|
|||||||
.tokens
|
.tokens
|
||||||
.iter()
|
.iter()
|
||||||
.zip(event.deltas.iter())
|
.zip(event.deltas.iter())
|
||||||
.map(|(token, delta)| tycho::BalanceDelta {
|
.filter_map(|(token, delta)| {
|
||||||
|
let component_id: Vec<_> = event.pool_id.into();
|
||||||
|
|
||||||
|
if store
|
||||||
|
.get_last(format!("pool:{0}", hex::encode(&component_id)))
|
||||||
|
.is_none()
|
||||||
|
{
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
Some(tycho::BalanceDelta {
|
||||||
ord: log.log.ordinal,
|
ord: log.log.ordinal,
|
||||||
tx: Some(tycho::Transaction {
|
tx: Some(tycho::Transaction {
|
||||||
hash: log.receipt.transaction.hash.clone(),
|
hash: log.receipt.transaction.hash.clone(),
|
||||||
@@ -108,7 +121,8 @@ pub fn map_balance_deltas(block: eth::v2::Block) -> Result<tycho::BalanceDeltas,
|
|||||||
}),
|
}),
|
||||||
token: token.clone(),
|
token: token.clone(),
|
||||||
delta: delta.to_signed_bytes_be(),
|
delta: delta.to_signed_bytes_be(),
|
||||||
component_id: event.pool_id.into(),
|
component_id: component_id.clone(),
|
||||||
|
})
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ modules:
|
|||||||
initialBlock: 12369300 # An arbitrary block that should change based on your requirements
|
initialBlock: 12369300 # An arbitrary block that should change based on your requirements
|
||||||
inputs:
|
inputs:
|
||||||
- source: sf.ethereum.type.v2.Block
|
- source: sf.ethereum.type.v2.Block
|
||||||
|
- store: store_pools_created
|
||||||
output:
|
output:
|
||||||
type: proto:tycho.evm.v1.BalanceDeltas
|
type: proto:tycho.evm.v1.BalanceDeltas
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user