feat(balancer): Add rate providers to static attributes.

Adds the rate providers and additional attributes to balancers static attributes. These will help in the future to migrate some of the components to use the DCI.

Adds a small attributes module to tycho-substreams to make json encoding a bit easier.
This commit is contained in:
kayibal
2024-07-22 18:57:38 +01:00
parent 2eb41d82f0
commit 148fac276c
6 changed files with 127 additions and 39 deletions

View File

@@ -1,33 +1,13 @@
use crate::{abi, modules::VAULT_ADDRESS};
use substreams::{hex, scalar::BigInt};
use substreams::hex;
use substreams_ethereum::{
pb::eth::v2::{Call, Log, TransactionTrace},
Event, Function,
};
use tycho_substreams::prelude::*;
/// This trait defines some helpers for serializing and deserializing `Vec<BigInt` which is needed
/// to be able to encode the `normalized_weights` and `weights` `Attribute`s. This should also be
/// handled by any downstream application.
trait SerializableVecBigInt {
fn serialize_bytes(&self) -> Vec<u8>;
#[allow(dead_code)]
fn deserialize_bytes(bytes: &[u8]) -> Vec<BigInt>;
}
impl SerializableVecBigInt for Vec<BigInt> {
fn serialize_bytes(&self) -> Vec<u8> {
self.iter()
.flat_map(|big_int| big_int.to_signed_bytes_be())
.collect()
}
fn deserialize_bytes(bytes: &[u8]) -> Vec<BigInt> {
bytes
.chunks_exact(32)
.map(BigInt::from_signed_bytes_be)
.collect::<Vec<BigInt>>()
}
}
use tycho_substreams::{
attributes::{json_serialize_address_list, json_serialize_bigint_list},
prelude::*,
};
/// Helper function to get pool_registered event
fn get_pool_registered(
@@ -76,14 +56,13 @@ pub fn address_map(
("pool_type", "WeightedPoolFactory".as_bytes()),
(
"normalized_weights",
&create_call
.normalized_weights
.serialize_bytes(),
&json_serialize_bigint_list(&create_call.normalized_weights),
),
(
"pool_id",
format!("0x{}", hex::encode(pool_registered.pool_id)).as_bytes(),
),
("manual_updates", &[1u8]),
])
.as_swap_type("balancer_pool", ImplementationType::Vm),
)
@@ -105,6 +84,11 @@ pub fn address_map(
"pool_id",
format!("0x{}", hex::encode(pool_registered.pool_id)).as_bytes(),
),
("manual_updates", &[1u8]),
(
"rate_providers",
&json_serialize_address_list(&create_call.rate_providers),
),
])
.as_swap_type("balancer_pool", ImplementationType::Vm),
)
@@ -119,7 +103,10 @@ pub fn address_map(
Some(
ProtocolComponent::at_contract(&pool_created.pool, &(tx.into()))
.with_contracts(&[pool_created.pool, VAULT_ADDRESS.to_vec()])
.with_tokens(&[create_call.main_token, create_call.wrapped_token])
.with_tokens(&[
create_call.main_token.clone(),
create_call.wrapped_token.clone(),
])
.with_attributes(&[
("pool_type", "ERC4626LinearPoolFactory".as_bytes()),
(
@@ -132,6 +119,15 @@ pub fn address_map(
"pool_id",
format!("0x{}", hex::encode(pool_registered.pool_id)).as_bytes(),
),
("manual_updates", &[1u8]),
("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),
)
@@ -146,7 +142,10 @@ pub fn address_map(
Some(
ProtocolComponent::at_contract(&pool_created.pool, &(tx.into()))
.with_contracts(&[pool_created.pool, VAULT_ADDRESS.to_vec()])
.with_tokens(&[create_call.main_token, create_call.wrapped_token])
.with_tokens(&[
create_call.main_token.clone(),
create_call.wrapped_token.clone(),
])
.with_attributes(&[
("pool_type", "EulerLinearPoolFactory".as_bytes()),
(
@@ -159,6 +158,15 @@ pub fn address_map(
"pool_id",
format!("0x{}", hex::encode(pool_registered.pool_id)).as_bytes(),
),
("manual_updates", &[1u8]),
("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),
)
@@ -221,7 +229,10 @@ pub fn address_map(
Some(
ProtocolComponent::at_contract(&pool_created.pool, &(tx.into()))
.with_contracts(&[pool_created.pool, VAULT_ADDRESS.to_vec()])
.with_tokens(&[create_call.main_token, create_call.wrapped_token])
.with_tokens(&[
create_call.main_token.clone(),
create_call.wrapped_token.clone(),
])
.with_attributes(&[
("pool_type", "SiloLinearPoolFactory".as_bytes()),
(
@@ -234,6 +245,15 @@ pub fn address_map(
"pool_id",
format!("0x{}", hex::encode(pool_registered.pool_id)).as_bytes(),
),
("manual_updates", &[1u8]),
("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),
)
@@ -248,7 +268,10 @@ pub fn address_map(
Some(
ProtocolComponent::at_contract(&pool_created.pool, &(tx.into()))
.with_contracts(&[pool_created.pool, VAULT_ADDRESS.to_vec()])
.with_tokens(&[create_call.main_token, create_call.wrapped_token])
.with_tokens(&[
create_call.main_token.clone(),
create_call.wrapped_token.clone(),
])
.with_attributes(&[
("pool_type", "YearnLinearPoolFactory".as_bytes()),
(
@@ -261,6 +284,15 @@ pub fn address_map(
"pool_id",
format!("0x{}", hex::encode(pool_registered.pool_id)).as_bytes(),
),
("manual_updates", &[1u8]),
("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),
)
@@ -280,11 +312,12 @@ pub fn address_map(
.with_tokens(&create_call.tokens)
.with_attributes(&[
("pool_type", "WeightedPool2TokensFactory".as_bytes()),
("weights", &create_call.weights.serialize_bytes()),
("weights", &json_serialize_bigint_list(&create_call.weights)),
(
"pool_id",
format!("0x{}", hex::encode(pool_registered.pool_id)).as_bytes(),
),
("manual_updates", &[1u8]),
])
.as_swap_type("balancer_pool", ImplementationType::Vm),
)