Merge pull request #70 from propeller-heads/zz/balancer/remove-pool-id

refactor(balancer-substreams): remove `pool_id` static attr and use `ProtocolComponent.id` instead
This commit is contained in:
Zizou
2024-08-22 12:48:53 +02:00
committed by GitHub
4 changed files with 193 additions and 210 deletions

View File

@@ -29,13 +29,12 @@ tests:
start_block: 20128706
stop_block: 20128806
expected_components:
- id: "0xe96a45f66bdDA121B24F0a861372A72E8889523d"
- id: "0xe96a45f66bdda121b24f0a861372a72e8889523d00020000000000000000069b"
tokens:
- "0x38C2a4a7330b22788374B8Ff70BBa513C8D848cA"
- "0x514910771AF9Ca656af840dff83E8264EcF986CA"
static_attributes:
rate_providers: "0x5b22307830303030303030303030303030303030303030303030303030303030303030303030303030303030222c22307830303030303030303030303030303030303030303030303030303030303030303030303030303030225d"
pool_id: "0x307865393661343566363662646461313231623234663061383631333732613732653838383935323364303030323030303030303030303030303030303030363962"
normalized_weights: "0x5b22307830623161326263326563353030303030222c22307830326336386166306262313430303030225d"
fee: "0x11c37937e08000"
manual_updates: "0x01"
@@ -47,12 +46,11 @@ tests:
start_block: 13148365
stop_block: 13148465
expected_components:
- id: "0xBF96189Eee9357a95C7719f4F5047F76bdE804E5"
- id: "0xbf96189eee9357a95c7719f4f5047f76bde804e5000200000000000000000087"
tokens:
- "0x5A98FcBEA516Cf06857215779Fd812CA3beF1B32"
- "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
static_attributes:
pool_id: "0x307862663936313839656565393335376139356337373139663466353034376637366264653830346535303030323030303030303030303030303030303030303837"
weights: "0x5b22307830623161326263326563353030303030222c22307830326336386166306262313430303030225d"
fee: "0x08e1bc9bf04000"
manual_updates: "0x01"
@@ -64,7 +62,7 @@ tests:
start_block: 17677300
stop_block: 17678400
expected_components:
- id: "0x42ED016F826165C2e5976fe5bC3df540C5aD0Af7"
- id: "0x42ed016f826165c2e5976fe5bc3df540c5ad0af700000000000000000000058b"
tokens:
- "0x42ed016f826165c2e5976fe5bc3df540c5ad0af7"
- "0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0"
@@ -72,7 +70,6 @@ tests:
- "0xae78736Cd615f374D3085123A210448E74Fc6393"
static_attributes:
rate_providers: "0x5b22307837326430376437646361363762386134303661643165633334636539363963393062666565373638222c22307833303230313365373933366133396333353864303761336466353564633934656334313765336131222c22307831613866383163323536616565396336343065313462623034353363653234376561306466653666225d"
pool_id: "0x307834326564303136663832363136356332653539373666653562633364663534306335616430616637303030303030303030303030303030303030303030353862"
bpt: "0x42ed016f826165c2e5976fe5bc3df540c5ad0af7"
fee: "0x5af3107a4000"
manual_updates: "0x01"
@@ -85,13 +82,12 @@ tests:
start_block: 17480142
stop_block: 17480242
expected_components:
- id: "0x3fCb7085B8F2F473F80bF6D879cAe99eA4DE9344"
- id: "0x3fcb7085b8f2f473f80bf6d879cae99ea4de934400000000000000000000056d"
tokens:
- "0x39Dd7790e75C6F663731f7E1FdC0f35007D3879b"
- "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
- "0x3fcb7085b8f2f473f80bf6d879cae99ea4de9344"
static_attributes:
pool_id: "0x307833666362373038356238663266343733663830626636643837396361653939656134646539333434303030303030303030303030303030303030303030353664"
wrapped_token: "0x39dd7790e75c6f663731f7e1fdc0f35007d3879b"
fee: "0x00b5e620f48000"
manual_updates: "0x01"
@@ -107,13 +103,12 @@ tests:
start_block: 16588117
stop_block: 16588217
expected_components:
- id: "0xD4e7C1F3DA1144c9E2CfD1b015eDA7652b4a4399"
- id: "0xd4e7c1f3da1144c9e2cfd1b015eda7652b4a439900000000000000000000046a"
tokens:
- "0xD4e7C1F3DA1144c9E2CfD1b015eDA7652b4a4399"
- "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
- "0xEb91861f8A4e1C12333F42DCE8fB0Ecdc28dA716"
static_attributes:
pool_id: "0x307864346537633166336461313134346339653263666431623031356564613736353262346134333939303030303030303030303030303030303030303030343661"
wrapped_token: "0xeb91861f8a4e1c12333f42dce8fb0ecdc28da716"
fee: "0x00b5e620f48000"
manual_updates: "0x01"
@@ -129,13 +124,12 @@ tests:
start_block: 17173185
stop_block: 17173187
expected_components:
- id: "0x74CBfAF94A3577c539a9dCEE9870A6349a33b34f"
- id: "0x74cbfaf94a3577c539a9dcee9870a6349a33b34f000000000000000000000534"
tokens:
- "0x192E67544694a7bAA2DeA94f9B1Df58BB3395A12"
- "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
- "0x74cbfaf94a3577c539a9dcee9870a6349a33b34f"
static_attributes:
pool_id: "0x307837346362666166393461333537376335333961396463656539383730613633343961333362333466303030303030303030303030303030303030303030353334"
wrapped_token: "0x192e67544694a7baa2dea94f9b1df58bb3395a12"
fee: "0x00e8d4a51000"
manual_updates: "0x01"
@@ -151,13 +145,12 @@ tests:
start_block: 17052601
stop_block: 17052605
expected_components:
- id: "0xac5b4ef7ede2f2843a704e96dcaa637f4ba3dc3f"
- id: "0xac5b4ef7ede2f2843a704e96dcaa637f4ba3dc3f00000000000000000000051d"
tokens:
- "0x806E02Dea8d4a0882caD9fA3Fa75B212328692dE"
- "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
- "0xac5b4ef7ede2f2843a704e96dcaa637f4ba3dc3f"
static_attributes:
pool_id: "0x307861633562346566376564653266323834336137303465393664636161363337663462613364633366303030303030303030303030303030303030303030353164"
wrapped_token: "0x806e02dea8d4a0882cad9fa3fa75b212328692de"
fee: "0x00e8d4a51000"
manual_updates: "0x01"
@@ -166,4 +159,4 @@ tests:
bpt: "0xac5b4ef7ede2f2843a704e96dcaa637f4ba3dc3f"
main_token: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"
skip_simulation: true
creation_tx: "0x497aa03ce84d236c183204ddfc6762c8e4158da1ebc5e7e18e7f6cceaa497a2a"
creation_tx: "0x497aa03ce84d236c183204ddfc6762c8e4158da1ebc5e7e18e7f6cceaa497a2a"

View File

@@ -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);
}
})
});

View File

@@ -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,

View File

@@ -28,8 +28,8 @@ modules:
- name: store_components
kind: store
initialBlock: 12272146
updatePolicy: add
valueType: int64
updatePolicy: set
valueType: string
inputs:
- map: map_components