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:
@@ -11,3 +11,5 @@ hex.workspace = true
|
||||
itertools = "0.12.0"
|
||||
ethabi.workspace = true
|
||||
num-bigint = "0.4.4"
|
||||
serde.workspace = true
|
||||
serde_json.workspace = true
|
||||
|
||||
48
substreams/crates/tycho-substreams/src/attributes.rs
Normal file
48
substreams/crates/tycho-substreams/src/attributes.rs
Normal file
@@ -0,0 +1,48 @@
|
||||
use std::fmt::Debug;
|
||||
use substreams::prelude::BigInt;
|
||||
|
||||
/// Encodes a value to bytes using json.
|
||||
///
|
||||
/// ## Panics
|
||||
/// In case the serialisation to json fails.
|
||||
pub fn json_serialize_value<T: serde::Serialize + Debug>(v: T) -> Vec<u8> {
|
||||
serde_json::to_value(v)
|
||||
.unwrap_or_else(|e| panic!("Failed to encode value as json {e}"))
|
||||
.to_string()
|
||||
.as_bytes()
|
||||
.to_vec()
|
||||
}
|
||||
|
||||
|
||||
/// Encodes a list of addresses (in byte representation) into json.
|
||||
///
|
||||
/// Converts each address to a 0x prefixed hex string and then serializes
|
||||
/// the list of strings as a json.
|
||||
///
|
||||
/// ## Panics
|
||||
/// In case the serialisation to json fails.
|
||||
pub fn json_serialize_address_list(addresses: &[Vec<u8>]) -> Vec<u8> {
|
||||
json_serialize_value(
|
||||
addresses
|
||||
.iter()
|
||||
.map(|a| format!("0x{}", hex::encode(a)))
|
||||
.collect::<Vec<_>>(),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
/// Encodes a list of BigInt values into json.
|
||||
///
|
||||
/// Converts each integer to a 0x prefixed hex string and then serializes
|
||||
/// the list of strings as a json.
|
||||
///
|
||||
/// ## Panics
|
||||
/// In case the serialisation to json fails.
|
||||
pub fn json_serialize_bigint_list(values: &[BigInt]) -> Vec<u8> {
|
||||
json_serialize_value(
|
||||
values
|
||||
.iter()
|
||||
.map(|v| format!("0x{}", hex::encode(v.to_signed_bytes_be())))
|
||||
.collect::<Vec<_>>(),
|
||||
)
|
||||
}
|
||||
@@ -4,6 +4,7 @@ pub mod contract;
|
||||
mod mock_store;
|
||||
pub mod models;
|
||||
mod pb;
|
||||
pub mod attributes;
|
||||
|
||||
pub mod prelude {
|
||||
pub use super::models::*;
|
||||
|
||||
Reference in New Issue
Block a user