fix(ci): clippy, fmt and remove substreams logs

This commit is contained in:
Florian Pellissier
2024-06-14 19:41:08 +02:00
parent c7d18d447a
commit 127a0c5cb7
9 changed files with 1062 additions and 1255 deletions

View File

@@ -8,6 +8,8 @@ fn main() -> Result<()> {
let files = fs::read_dir(abi_folder)?;
let mut mod_rs_content = String::new();
mod_rs_content.push_str("#![allow(clippy::all)]\n");
mod_rs_content.push_str("#[allow(non_snake_case)]\n");
for file in files {
let file = file?;

File diff suppressed because it is too large Load Diff

View File

@@ -1,3 +1,5 @@
#![allow(clippy::all)]
#[allow(non_snake_case)]
pub mod crypto_pool_factory;
pub mod stableswap_factory;
pub mod susd;

View File

@@ -1,3 +1,4 @@
#![allow(clippy::not_unsafe_ptr_arg_deref)]
mod abi;
mod consts;
pub mod modules;

View File

@@ -45,7 +45,7 @@ pub fn map_components(
.logs_with_calls()
.filter(|(_, call)| !call.call.state_reverted)
.filter_map(|(log, call)| {
Some(pool_factories::address_map(
pool_factories::address_map(
call.call
.address
.as_slice()
@@ -54,11 +54,11 @@ pub fn map_components(
log,
call.call,
tx,
)?)
)
})
.collect::<Vec<_>>();
if let Some(component) = emit_specific_pools(&params, &tx).expect(
if let Some(component) = emit_specific_pools(&params, tx).expect(
"An unexpected error occured when parsing params for emitting specific pools",
) {
components.push(component)
@@ -95,8 +95,8 @@ pub fn store_component_tokens(map: BlockTransactionProtocolComponents, store: St
&component
.tokens
.iter()
.map(|token| hex::encode(token))
.join(":".into()),
.map(hex::encode)
.join(":"),
);
});
}
@@ -112,11 +112,10 @@ pub fn map_relative_balances(
balance_deltas: {
let mut deltas: Vec<_> = block
.transactions()
.into_iter()
.flat_map(|tx| {
emit_eth_deltas(&tx, &tokens_store)
emit_eth_deltas(tx, &tokens_store)
.into_iter()
.chain(emit_deltas(&tx, &tokens_store))
.chain(emit_deltas(tx, &tokens_store))
})
.collect();
@@ -268,7 +267,7 @@ pub fn map_protocol_changes(
}),
changes: transaction_contract_changes
.drain()
.sorted_unstable_by_key(|(index, _)| index.clone())
.sorted_unstable_by_key(|(index, _)| *index)
.filter_map(|(_, change)| {
if change.contract_changes.is_empty() &&
change.component_changes.is_empty() &&

View File

@@ -11,7 +11,7 @@ use crate::{
};
fn get_pool_tokens(pool_address: &Vec<u8>, tokens_store: &StoreGetString) -> Option<Vec<String>> {
let pool_key = format!("pool:{}", hex::encode(&pool_address));
let pool_key = format!("pool:{}", hex::encode(pool_address));
Some(
tokens_store
.get_last(pool_key)?
@@ -24,10 +24,8 @@ fn get_pool_tokens(pool_address: &Vec<u8>, tokens_store: &StoreGetString) -> Opt
/// Tracks `Transfers` in and out of tracked pools if it matches the specific tokens.
pub fn emit_deltas(tx: &TransactionTrace, tokens_store: &StoreGetString) -> Vec<BalanceDelta> {
tx.logs_with_calls()
.into_iter()
.filter_map(|(log, _)| {
let transfer = abi::erc20::events::Transfer::match_and_decode(log)?;
let (component_id, pool_tokens, is_incoming) =
if let Some(pool_tokens) = get_pool_tokens(&transfer.to, tokens_store) {
(hex::encode(&transfer.to), pool_tokens, true)
@@ -53,7 +51,6 @@ pub fn emit_deltas(tx: &TransactionTrace, tokens_store: &StoreGetString) -> Vec<
component_id: component_id.into(),
})
} else {
substreams::log::info!("Token {:?} not in pool: {:?}", token_id, &component_id);
None
}
})
@@ -69,7 +66,6 @@ pub fn emit_deltas(tx: &TransactionTrace, tokens_store: &StoreGetString) -> Vec<
/// - If neither, it's likely an erroneous ETH transactions that many older pools don't reject.
pub fn emit_eth_deltas(tx: &TransactionTrace, tokens_store: &StoreGetString) -> Vec<BalanceDelta> {
tx.calls()
.into_iter()
.flat_map(|call| {
call.call
.balance_changes

View File

@@ -28,7 +28,7 @@ impl SerializableVecBigInt for Vec<BigInt> {
fn deserialize_bytes(bytes: &[u8]) -> Vec<BigInt> {
bytes
.chunks_exact(32)
.map(|chunk| BigInt::from_signed_bytes_be(chunk))
.map(BigInt::from_signed_bytes_be)
.collect::<Vec<BigInt>>()
}
}
@@ -381,7 +381,7 @@ pub fn address_map(
hash: tx.hash.clone(),
index: tx.index.into(),
}),
tokens: pool_added.coins.into(),
tokens: pool_added.coins,
contracts: vec![component_id.into()],
static_att: vec![
Attribute {
@@ -487,7 +487,7 @@ pub fn address_map(
index: tx.index.into(),
}),
tokens,
contracts: vec![pool_added.pool.into()],
contracts: vec![pool_added.pool],
static_att: vec![
Attribute {
name: "pool_type".into(),
@@ -701,8 +701,7 @@ fn get_token_from_pool(pool: &Vec<u8>) -> Vec<u8> {
.call(META_REGISTRY.to_vec())
})
.or_else(|| {
substreams::log::info!(format!("Using pool tree with pool {}", hex::encode(&pool)));
match hex::encode(&pool).as_str() {
match hex::encode(pool).as_str() {
// Curve.fi DAI/USDC/USDT (3Crv)
"bebc44782c7db0a1a60cb6fe97d0b483032ff1c7" => {
hex::decode("6c3F90f043a72FA612cbac8115EE7e52BDe6E490").ok()

View File

@@ -29,7 +29,7 @@ struct PoolQueryParams {
/// This function can error based on some basic parsing errors and deeper down hex decoding errors
/// if various addresses are not formatted properly.
pub fn emit_specific_pools(
params: &String,
params: &str,
tx: &TransactionTrace,
) -> Result<Option<ProtocolComponent>> {
let pools = parse_params(params)?;
@@ -60,12 +60,10 @@ fn create_component(
static_att: zip(
pool.attribute_keys
.clone()
.unwrap_or(vec![])
.into_iter(),
.unwrap_or(vec![]),
pool.attribute_vals
.clone()
.unwrap_or(vec![])
.into_iter(),
.unwrap_or(vec![]),
)
.clone()
.map(|(key, value)| Attribute {