From 409cf158641f8837e50143924c447f4b87652d3b Mon Sep 17 00:00:00 2001 From: Louise Poole Date: Fri, 25 Apr 2025 18:09:38 +0200 Subject: [PATCH] Revert "chore: update format! macro use to satisfy latest clippy version (#194)" (#196) This reverts commit f29de67f1f6345effca6ffc68ca53fd38b51eb03. --- .../crates/substreams-helper/src/hex.rs | 2 +- .../crates/tycho-substreams/src/abi/erc20.rs | 53 +- .../crates/tycho-substreams/src/abi/weth.rs | 2729 +++++++++-------- .../crates/tycho-substreams/src/attributes.rs | 4 +- .../crates/tycho-substreams/src/balances.rs | 40 +- .../crates/tycho-substreams/src/models.rs | 2 +- .../src/modules/2_store_pool_balances.rs | 2 +- .../src/modules/3_map_changes.rs | 2 +- substreams/ethereum-balancer-v2/build.rs | 8 +- .../ethereum-balancer-v2/src/modules.rs | 18 +- substreams/ethereum-curve/build.rs | 8 +- .../ethereum-curve/src/pool_factories.rs | 30 +- substreams/ethereum-curve/src/pools.rs | 4 +- substreams/ethereum-ekubo-v2/build.rs | 8 +- .../src/modules/2_store_pools.rs | 2 +- .../src/modules/3_map_events.rs | 2 +- .../4_map_and_store_balance_changes.rs | 2 +- .../src/modules/4_map_and_store_liquidity.rs | 8 +- .../src/modules/4_map_and_store_ticks.rs | 6 +- .../src/modules/5_map_protocol_changes.rs | 3 +- substreams/ethereum-sfrax/src/modules.rs | 14 +- substreams/ethereum-sfraxeth/src/modules.rs | 26 +- substreams/ethereum-template-factory/build.rs | 8 +- .../ethereum-template-singleton/build.rs | 8 +- .../src/modules/3_map_pool_events.rs | 2 +- .../ethereum-uniswap-v2/src/store_key.rs | 2 +- .../src/modules/2_store_pools.rs | 2 +- .../src/modules/3_map_events.rs | 2 +- .../src/modules/4_map_and_store_liquidity.rs | 2 +- .../src/modules/2_store_pools.rs | 2 +- .../src/modules/3_map_balance_changes.rs | 2 +- .../src/modules/5_map_pool_events.rs | 2 +- .../src/storage/pool_storage.rs | 2 +- .../ethereum-uniswap-v3/src/storage/utils.rs | 20 +- .../src/modules/2_store_pools.rs | 2 +- .../src/modules/3_map_events.rs | 8 +- .../src/modules/4_store_current_sqrtprice.rs | 2 +- .../src/modules/4_store_current_tick.rs | 2 +- 38 files changed, 1680 insertions(+), 1361 deletions(-) diff --git a/substreams/crates/substreams-helper/src/hex.rs b/substreams/crates/substreams-helper/src/hex.rs index fbcf6f0..26ed473 100644 --- a/substreams/crates/substreams-helper/src/hex.rs +++ b/substreams/crates/substreams-helper/src/hex.rs @@ -4,6 +4,6 @@ pub trait Hexable { impl> Hexable for T { fn to_hex(&self) -> String { - format!("0x{encoded}", encoded = hex::encode(self)) + format!("0x{}", hex::encode(self)) } } diff --git a/substreams/crates/tycho-substreams/src/abi/erc20.rs b/substreams/crates/tycho-substreams/src/abi/erc20.rs index b91f72f..5dd70ca 100644 --- a/substreams/crates/tycho-substreams/src/abi/erc20.rs +++ b/substreams/crates/tycho-substreams/src/abi/erc20.rs @@ -19,7 +19,7 @@ pub mod functions { &[ethabi::ParamType::Address, ethabi::ParamType::Address], maybe_data.unwrap(), ) - .map_err(|e| format!("unable to decode call.input: {e:?}"))?; + .map_err(|e| format!("unable to decode call.input: {:?}", e))?; values.reverse(); Ok(Self { owner: values @@ -55,7 +55,7 @@ pub mod functions { } pub fn output(data: &[u8]) -> Result { let mut values = ethabi::decode(&[ethabi::ParamType::Uint(256usize)], data.as_ref()) - .map_err(|e| format!("unable to decode output data: {e:?}"))?; + .map_err(|e| format!("unable to decode output data: {:?}", e))?; Ok({ let mut v = [0 as u8; 32]; values @@ -132,7 +132,7 @@ pub mod functions { &[ethabi::ParamType::Address, ethabi::ParamType::Uint(256usize)], maybe_data.unwrap(), ) - .map_err(|e| format!("unable to decode call.input: {e:?}"))?; + .map_err(|e| format!("unable to decode call.input: {:?}", e))?; values.reverse(); Ok(Self { spender: values @@ -178,7 +178,7 @@ pub mod functions { } pub fn output(data: &[u8]) -> Result { let mut values = ethabi::decode(&[ethabi::ParamType::Bool], data.as_ref()) - .map_err(|e| format!("unable to decode output data: {e:?}"))?; + .map_err(|e| format!("unable to decode output data: {:?}", e))?; Ok(values .pop() .expect("one output data should have existed") @@ -246,7 +246,7 @@ pub mod functions { return Err("no data to decode".to_string()); } let mut values = ethabi::decode(&[ethabi::ParamType::Address], maybe_data.unwrap()) - .map_err(|e| format!("unable to decode call.input: {e:?}"))?; + .map_err(|e| format!("unable to decode call.input: {:?}", e))?; values.reverse(); Ok(Self { owner: values @@ -273,7 +273,7 @@ pub mod functions { } pub fn output(data: &[u8]) -> Result { let mut values = ethabi::decode(&[ethabi::ParamType::Uint(256usize)], data.as_ref()) - .map_err(|e| format!("unable to decode output data: {e:?}"))?; + .map_err(|e| format!("unable to decode output data: {:?}", e))?; Ok({ let mut v = [0 as u8; 32]; values @@ -355,7 +355,7 @@ pub mod functions { } pub fn output(data: &[u8]) -> Result { let mut values = ethabi::decode(&[ethabi::ParamType::Uint(8usize)], data.as_ref()) - .map_err(|e| format!("unable to decode output data: {e:?}"))?; + .map_err(|e| format!("unable to decode output data: {:?}", e))?; Ok({ let mut v = [0 as u8; 32]; values @@ -437,7 +437,7 @@ pub mod functions { } pub fn output(data: &[u8]) -> Result { let mut values = ethabi::decode(&[ethabi::ParamType::String], data.as_ref()) - .map_err(|e| format!("unable to decode output data: {e:?}"))?; + .map_err(|e| format!("unable to decode output data: {:?}", e))?; Ok(values .pop() .expect("one output data should have existed") @@ -514,7 +514,7 @@ pub mod functions { } pub fn output(data: &[u8]) -> Result { let mut values = ethabi::decode(&[ethabi::ParamType::String], data.as_ref()) - .map_err(|e| format!("unable to decode output data: {e:?}"))?; + .map_err(|e| format!("unable to decode output data: {:?}", e))?; Ok(values .pop() .expect("one output data should have existed") @@ -591,7 +591,7 @@ pub mod functions { } pub fn output(data: &[u8]) -> Result { let mut values = ethabi::decode(&[ethabi::ParamType::Uint(256usize)], data.as_ref()) - .map_err(|e| format!("unable to decode output data: {e:?}"))?; + .map_err(|e| format!("unable to decode output data: {:?}", e))?; Ok({ let mut v = [0 as u8; 32]; values @@ -668,7 +668,7 @@ pub mod functions { &[ethabi::ParamType::Address, ethabi::ParamType::Uint(256usize)], maybe_data.unwrap(), ) - .map_err(|e| format!("unable to decode call.input: {e:?}"))?; + .map_err(|e| format!("unable to decode call.input: {:?}", e))?; values.reverse(); Ok(Self { to: values @@ -714,7 +714,7 @@ pub mod functions { } pub fn output(data: &[u8]) -> Result { let mut values = ethabi::decode(&[ethabi::ParamType::Bool], data.as_ref()) - .map_err(|e| format!("unable to decode output data: {e:?}"))?; + .map_err(|e| format!("unable to decode output data: {:?}", e))?; Ok(values .pop() .expect("one output data should have existed") @@ -791,7 +791,7 @@ pub mod functions { ], maybe_data.unwrap(), ) - .map_err(|e| format!("unable to decode call.input: {e:?}"))?; + .map_err(|e| format!("unable to decode call.input: {:?}", e))?; values.reverse(); Ok(Self { from: values @@ -845,7 +845,7 @@ pub mod functions { } pub fn output(data: &[u8]) -> Result { let mut values = ethabi::decode(&[ethabi::ParamType::Bool], data.as_ref()) - .map_err(|e| format!("unable to decode output data: {e:?}"))?; + .map_err(|e| format!("unable to decode output data: {:?}", e))?; Ok(values .pop() .expect("one output data should have existed") @@ -929,19 +929,20 @@ pub mod events { .topics .get(0) .expect("bounds already checked") - .as_ref() - == Self::TOPIC_ID; + .as_ref() == + Self::TOPIC_ID; } pub fn decode(log: &substreams_ethereum::pb::eth::v2::Log) -> Result { let mut values = ethabi::decode(&[ethabi::ParamType::Uint(256usize)], log.data.as_ref()) - .map_err(|e| format!("unable to decode log.data: {e:?}"))?; + .map_err(|e| format!("unable to decode log.data: {:?}", e))?; values.reverse(); Ok(Self { owner: ethabi::decode(&[ethabi::ParamType::Address], log.topics[1usize].as_ref()) .map_err(|e| { format!( - "unable to decode param 'owner' from topic of type 'address': {e:?}" + "unable to decode param 'owner' from topic of type 'address': {:?}", + e ) })? .pop() @@ -953,7 +954,8 @@ pub mod events { spender: ethabi::decode(&[ethabi::ParamType::Address], log.topics[2usize].as_ref()) .map_err(|e| { format!( - "unable to decode param 'spender' from topic of type 'address': {e:?}" + "unable to decode param 'spender' from topic of type 'address': {:?}", + e ) })? .pop() @@ -1007,18 +1009,21 @@ pub mod events { .topics .get(0) .expect("bounds already checked") - .as_ref() - == Self::TOPIC_ID; + .as_ref() == + Self::TOPIC_ID; } pub fn decode(log: &substreams_ethereum::pb::eth::v2::Log) -> Result { let mut values = ethabi::decode(&[ethabi::ParamType::Uint(256usize)], log.data.as_ref()) - .map_err(|e| format!("unable to decode log.data: {e:?}"))?; + .map_err(|e| format!("unable to decode log.data: {:?}", e))?; values.reverse(); Ok(Self { from: ethabi::decode(&[ethabi::ParamType::Address], log.topics[1usize].as_ref()) .map_err(|e| { - format!("unable to decode param 'from' from topic of type 'address': {e:?}") + format!( + "unable to decode param 'from' from topic of type 'address': {:?}", + e + ) })? .pop() .expect(INTERNAL_ERR) @@ -1028,7 +1033,7 @@ pub mod events { .to_vec(), to: ethabi::decode(&[ethabi::ParamType::Address], log.topics[2usize].as_ref()) .map_err(|e| { - format!("unable to decode param 'to' from topic of type 'address': {e:?}") + format!("unable to decode param 'to' from topic of type 'address': {:?}", e) })? .pop() .expect(INTERNAL_ERR) diff --git a/substreams/crates/tycho-substreams/src/abi/weth.rs b/substreams/crates/tycho-substreams/src/abi/weth.rs index bc360f9..50615b1 100644 --- a/substreams/crates/tycho-substreams/src/abi/weth.rs +++ b/substreams/crates/tycho-substreams/src/abi/weth.rs @@ -1,1280 +1,1567 @@ -const INTERNAL_ERR: &'static str = "`ethabi_derive` internal error"; -/// Contract's functions. -#[allow(dead_code, unused_imports, unused_variables)] -pub mod functions { - use super::INTERNAL_ERR; - #[derive(Debug, Clone, PartialEq)] - pub struct Allowance { - pub param0: Vec, - pub param1: Vec, - } - impl Allowance { - const METHOD_ID: [u8; 4] = [221u8, 98u8, 237u8, 62u8]; - pub fn decode(call: &substreams_ethereum::pb::eth::v2::Call) -> Result { - let maybe_data = call.input.get(4..); - if maybe_data.is_none() { - return Err("no data to decode".to_string()); - } - let mut values = ethabi::decode( - &[ethabi::ParamType::Address, ethabi::ParamType::Address], - maybe_data.unwrap(), - ) - .map_err(|e| format!("unable to decode call.input: {e:?}"))?; - values.reverse(); - Ok(Self { - param0: values - .pop() - .expect(INTERNAL_ERR) - .into_address() - .expect(INTERNAL_ERR) - .as_bytes() - .to_vec(), - param1: values - .pop() - .expect(INTERNAL_ERR) - .into_address() - .expect(INTERNAL_ERR) - .as_bytes() - .to_vec(), - }) + const INTERNAL_ERR: &'static str = "`ethabi_derive` internal error"; + /// Contract's functions. + #[allow(dead_code, unused_imports, unused_variables)] + pub mod functions { + use super::INTERNAL_ERR; + #[derive(Debug, Clone, PartialEq)] + pub struct Allowance { + pub param0: Vec, + pub param1: Vec, } - pub fn encode(&self) -> Vec { - let data = ethabi::encode(&[ - ethabi::Token::Address(ethabi::Address::from_slice(&self.param0)), - ethabi::Token::Address(ethabi::Address::from_slice(&self.param1)), - ]); - let mut encoded = Vec::with_capacity(4 + data.len()); - encoded.extend(Self::METHOD_ID); - encoded.extend(data); - encoded - } - pub fn output_call( - call: &substreams_ethereum::pb::eth::v2::Call, - ) -> Result { - Self::output(call.return_data.as_ref()) - } - pub fn output(data: &[u8]) -> Result { - let mut values = ethabi::decode(&[ethabi::ParamType::Uint(256usize)], data.as_ref()) - .map_err(|e| format!("unable to decode output data: {e:?}"))?; - Ok({ - let mut v = [0 as u8; 32]; - values - .pop() - .expect("one output data should have existed") - .into_uint() - .expect(INTERNAL_ERR) - .to_big_endian(v.as_mut_slice()); - substreams::scalar::BigInt::from_unsigned_bytes_be(&v) - }) - } - pub fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { - match call.input.get(0..4) { - Some(signature) => Self::METHOD_ID == signature, - None => false, - } - } - pub fn call(&self, address: Vec) -> Option { - use substreams_ethereum::pb::eth::rpc; - let rpc_calls = rpc::RpcCalls { - calls: vec![rpc::RpcCall { to_addr: address, data: self.encode() }], - }; - let responses = substreams_ethereum::rpc::eth_call(&rpc_calls).responses; - let response = responses - .get(0) - .expect("one response should have existed"); - if response.failed { - return None; - } - match Self::output(response.raw.as_ref()) { - Ok(data) => Some(data), - Err(err) => { - use substreams_ethereum::Function; - substreams::log::info!( - "Call output for function `{}` failed to decode with error: {}", - Self::NAME, - err - ); - None + impl Allowance { + const METHOD_ID: [u8; 4] = [221u8, 98u8, 237u8, 62u8]; + pub fn decode( + call: &substreams_ethereum::pb::eth::v2::Call, + ) -> Result { + let maybe_data = call.input.get(4..); + if maybe_data.is_none() { + return Err("no data to decode".to_string()); } + let mut values = ethabi::decode( + &[ethabi::ParamType::Address, ethabi::ParamType::Address], + maybe_data.unwrap(), + ) + .map_err(|e| format!("unable to decode call.input: {:?}", e))?; + values.reverse(); + Ok(Self { + param0: values + .pop() + .expect(INTERNAL_ERR) + .into_address() + .expect(INTERNAL_ERR) + .as_bytes() + .to_vec(), + param1: values + .pop() + .expect(INTERNAL_ERR) + .into_address() + .expect(INTERNAL_ERR) + .as_bytes() + .to_vec(), + }) } - } - } - impl substreams_ethereum::Function for Allowance { - const NAME: &'static str = "allowance"; - fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { - Self::match_call(call) - } - fn decode(call: &substreams_ethereum::pb::eth::v2::Call) -> Result { - Self::decode(call) - } - fn encode(&self) -> Vec { - self.encode() - } - } - impl substreams_ethereum::rpc::RPCDecodable for Allowance { - fn output(data: &[u8]) -> Result { - Self::output(data) - } - } - #[derive(Debug, Clone, PartialEq)] - pub struct Approve { - pub guy: Vec, - pub wad: substreams::scalar::BigInt, - } - impl Approve { - const METHOD_ID: [u8; 4] = [9u8, 94u8, 167u8, 179u8]; - pub fn decode(call: &substreams_ethereum::pb::eth::v2::Call) -> Result { - let maybe_data = call.input.get(4..); - if maybe_data.is_none() { - return Err("no data to decode".to_string()); + pub fn encode(&self) -> Vec { + let data = ethabi::encode( + &[ + ethabi::Token::Address( + ethabi::Address::from_slice(&self.param0), + ), + ethabi::Token::Address(ethabi::Address::from_slice(&self.param1)), + ], + ); + let mut encoded = Vec::with_capacity(4 + data.len()); + encoded.extend(Self::METHOD_ID); + encoded.extend(data); + encoded } - let mut values = ethabi::decode( - &[ethabi::ParamType::Address, ethabi::ParamType::Uint(256usize)], - maybe_data.unwrap(), - ) - .map_err(|e| format!("unable to decode call.input: {e:?}"))?; - values.reverse(); - Ok(Self { - guy: values - .pop() - .expect(INTERNAL_ERR) - .into_address() - .expect(INTERNAL_ERR) - .as_bytes() - .to_vec(), - wad: { + pub fn output_call( + call: &substreams_ethereum::pb::eth::v2::Call, + ) -> Result { + Self::output(call.return_data.as_ref()) + } + pub fn output(data: &[u8]) -> Result { + let mut values = ethabi::decode( + &[ethabi::ParamType::Uint(256usize)], + data.as_ref(), + ) + .map_err(|e| format!("unable to decode output data: {:?}", e))?; + Ok({ let mut v = [0 as u8; 32]; values .pop() - .expect(INTERNAL_ERR) + .expect("one output data should have existed") .into_uint() .expect(INTERNAL_ERR) .to_big_endian(v.as_mut_slice()); substreams::scalar::BigInt::from_unsigned_bytes_be(&v) - }, - }) - } - pub fn encode(&self) -> Vec { - let data = ethabi::encode(&[ - ethabi::Token::Address(ethabi::Address::from_slice(&self.guy)), - ethabi::Token::Uint(ethabi::Uint::from_big_endian( - match self.wad.clone().to_bytes_be() { - (num_bigint::Sign::Plus, bytes) => bytes, - (num_bigint::Sign::NoSign, bytes) => bytes, - (num_bigint::Sign::Minus, _) => { - panic!("negative numbers are not supported") - } - } - .as_slice(), - )), - ]); - let mut encoded = Vec::with_capacity(4 + data.len()); - encoded.extend(Self::METHOD_ID); - encoded.extend(data); - encoded - } - pub fn output_call(call: &substreams_ethereum::pb::eth::v2::Call) -> Result { - Self::output(call.return_data.as_ref()) - } - pub fn output(data: &[u8]) -> Result { - let mut values = ethabi::decode(&[ethabi::ParamType::Bool], data.as_ref()) - .map_err(|e| format!("unable to decode output data: {e:?}"))?; - Ok(values - .pop() - .expect("one output data should have existed") - .into_bool() - .expect(INTERNAL_ERR)) - } - pub fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { - match call.input.get(0..4) { - Some(signature) => Self::METHOD_ID == signature, - None => false, + }) } - } - pub fn call(&self, address: Vec) -> Option { - use substreams_ethereum::pb::eth::rpc; - let rpc_calls = rpc::RpcCalls { - calls: vec![rpc::RpcCall { to_addr: address, data: self.encode() }], - }; - let responses = substreams_ethereum::rpc::eth_call(&rpc_calls).responses; - let response = responses - .get(0) - .expect("one response should have existed"); - if response.failed { - return None; - } - match Self::output(response.raw.as_ref()) { - Ok(data) => Some(data), - Err(err) => { - use substreams_ethereum::Function; - substreams::log::info!( - "Call output for function `{}` failed to decode with error: {}", - Self::NAME, - err - ); - None + pub fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { + match call.input.get(0..4) { + Some(signature) => Self::METHOD_ID == signature, + None => false, } } - } - } - impl substreams_ethereum::Function for Approve { - const NAME: &'static str = "approve"; - fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { - Self::match_call(call) - } - fn decode(call: &substreams_ethereum::pb::eth::v2::Call) -> Result { - Self::decode(call) - } - fn encode(&self) -> Vec { - self.encode() - } - } - impl substreams_ethereum::rpc::RPCDecodable for Approve { - fn output(data: &[u8]) -> Result { - Self::output(data) - } - } - #[derive(Debug, Clone, PartialEq)] - pub struct BalanceOf { - pub param0: Vec, - } - impl BalanceOf { - const METHOD_ID: [u8; 4] = [112u8, 160u8, 130u8, 49u8]; - pub fn decode(call: &substreams_ethereum::pb::eth::v2::Call) -> Result { - let maybe_data = call.input.get(4..); - if maybe_data.is_none() { - return Err("no data to decode".to_string()); - } - let mut values = ethabi::decode(&[ethabi::ParamType::Address], maybe_data.unwrap()) - .map_err(|e| format!("unable to decode call.input: {e:?}"))?; - values.reverse(); - Ok(Self { - param0: values - .pop() - .expect(INTERNAL_ERR) - .into_address() - .expect(INTERNAL_ERR) - .as_bytes() - .to_vec(), - }) - } - pub fn encode(&self) -> Vec { - let data = ethabi::encode(&[ethabi::Token::Address(ethabi::Address::from_slice( - &self.param0, - ))]); - let mut encoded = Vec::with_capacity(4 + data.len()); - encoded.extend(Self::METHOD_ID); - encoded.extend(data); - encoded - } - pub fn output_call( - call: &substreams_ethereum::pb::eth::v2::Call, - ) -> Result { - Self::output(call.return_data.as_ref()) - } - pub fn output(data: &[u8]) -> Result { - let mut values = ethabi::decode(&[ethabi::ParamType::Uint(256usize)], data.as_ref()) - .map_err(|e| format!("unable to decode output data: {e:?}"))?; - Ok({ - let mut v = [0 as u8; 32]; - values - .pop() - .expect("one output data should have existed") - .into_uint() - .expect(INTERNAL_ERR) - .to_big_endian(v.as_mut_slice()); - substreams::scalar::BigInt::from_unsigned_bytes_be(&v) - }) - } - pub fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { - match call.input.get(0..4) { - Some(signature) => Self::METHOD_ID == signature, - None => false, - } - } - pub fn call(&self, address: Vec) -> Option { - use substreams_ethereum::pb::eth::rpc; - let rpc_calls = rpc::RpcCalls { - calls: vec![rpc::RpcCall { to_addr: address, data: self.encode() }], - }; - let responses = substreams_ethereum::rpc::eth_call(&rpc_calls).responses; - let response = responses - .get(0) - .expect("one response should have existed"); - if response.failed { - return None; - } - match Self::output(response.raw.as_ref()) { - Ok(data) => Some(data), - Err(err) => { - use substreams_ethereum::Function; - substreams::log::info!( - "Call output for function `{}` failed to decode with error: {}", - Self::NAME, - err - ); - None + pub fn call(&self, address: Vec) -> Option { + use substreams_ethereum::pb::eth::rpc; + let rpc_calls = rpc::RpcCalls { + calls: vec![ + rpc::RpcCall { to_addr : address, data : self.encode(), } + ], + }; + let responses = substreams_ethereum::rpc::eth_call(&rpc_calls).responses; + let response = responses + .get(0) + .expect("one response should have existed"); + if response.failed { + return None; } - } - } - } - impl substreams_ethereum::Function for BalanceOf { - const NAME: &'static str = "balanceOf"; - fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { - Self::match_call(call) - } - fn decode(call: &substreams_ethereum::pb::eth::v2::Call) -> Result { - Self::decode(call) - } - fn encode(&self) -> Vec { - self.encode() - } - } - impl substreams_ethereum::rpc::RPCDecodable for BalanceOf { - fn output(data: &[u8]) -> Result { - Self::output(data) - } - } - #[derive(Debug, Clone, PartialEq)] - pub struct Decimals {} - impl Decimals { - const METHOD_ID: [u8; 4] = [49u8, 60u8, 229u8, 103u8]; - pub fn decode(call: &substreams_ethereum::pb::eth::v2::Call) -> Result { - Ok(Self {}) - } - pub fn encode(&self) -> Vec { - let data = ethabi::encode(&[]); - let mut encoded = Vec::with_capacity(4 + data.len()); - encoded.extend(Self::METHOD_ID); - encoded.extend(data); - encoded - } - pub fn output_call( - call: &substreams_ethereum::pb::eth::v2::Call, - ) -> Result { - Self::output(call.return_data.as_ref()) - } - pub fn output(data: &[u8]) -> Result { - let mut values = ethabi::decode(&[ethabi::ParamType::Uint(8usize)], data.as_ref()) - .map_err(|e| format!("unable to decode output data: {e:?}"))?; - Ok({ - let mut v = [0 as u8; 32]; - values - .pop() - .expect("one output data should have existed") - .into_uint() - .expect(INTERNAL_ERR) - .to_big_endian(v.as_mut_slice()); - substreams::scalar::BigInt::from_unsigned_bytes_be(&v) - }) - } - pub fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { - match call.input.get(0..4) { - Some(signature) => Self::METHOD_ID == signature, - None => false, - } - } - pub fn call(&self, address: Vec) -> Option { - use substreams_ethereum::pb::eth::rpc; - let rpc_calls = rpc::RpcCalls { - calls: vec![rpc::RpcCall { to_addr: address, data: self.encode() }], - }; - let responses = substreams_ethereum::rpc::eth_call(&rpc_calls).responses; - let response = responses - .get(0) - .expect("one response should have existed"); - if response.failed { - return None; - } - match Self::output(response.raw.as_ref()) { - Ok(data) => Some(data), - Err(err) => { - use substreams_ethereum::Function; - substreams::log::info!( - "Call output for function `{}` failed to decode with error: {}", - Self::NAME, - err - ); - None - } - } - } - } - impl substreams_ethereum::Function for Decimals { - const NAME: &'static str = "decimals"; - fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { - Self::match_call(call) - } - fn decode(call: &substreams_ethereum::pb::eth::v2::Call) -> Result { - Self::decode(call) - } - fn encode(&self) -> Vec { - self.encode() - } - } - impl substreams_ethereum::rpc::RPCDecodable for Decimals { - fn output(data: &[u8]) -> Result { - Self::output(data) - } - } - #[derive(Debug, Clone, PartialEq)] - pub struct Deposit {} - impl Deposit { - const METHOD_ID: [u8; 4] = [208u8, 227u8, 13u8, 176u8]; - pub fn decode(call: &substreams_ethereum::pb::eth::v2::Call) -> Result { - Ok(Self {}) - } - pub fn encode(&self) -> Vec { - let data = ethabi::encode(&[]); - let mut encoded = Vec::with_capacity(4 + data.len()); - encoded.extend(Self::METHOD_ID); - encoded.extend(data); - encoded - } - pub fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { - match call.input.get(0..4) { - Some(signature) => Self::METHOD_ID == signature, - None => false, - } - } - } - impl substreams_ethereum::Function for Deposit { - const NAME: &'static str = "deposit"; - fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { - Self::match_call(call) - } - fn decode(call: &substreams_ethereum::pb::eth::v2::Call) -> Result { - Self::decode(call) - } - fn encode(&self) -> Vec { - self.encode() - } - } - #[derive(Debug, Clone, PartialEq)] - pub struct Name {} - impl Name { - const METHOD_ID: [u8; 4] = [6u8, 253u8, 222u8, 3u8]; - pub fn decode(call: &substreams_ethereum::pb::eth::v2::Call) -> Result { - Ok(Self {}) - } - pub fn encode(&self) -> Vec { - let data = ethabi::encode(&[]); - let mut encoded = Vec::with_capacity(4 + data.len()); - encoded.extend(Self::METHOD_ID); - encoded.extend(data); - encoded - } - pub fn output_call( - call: &substreams_ethereum::pb::eth::v2::Call, - ) -> Result { - Self::output(call.return_data.as_ref()) - } - pub fn output(data: &[u8]) -> Result { - let mut values = ethabi::decode(&[ethabi::ParamType::String], data.as_ref()) - .map_err(|e| format!("unable to decode output data: {e:?}"))?; - Ok(values - .pop() - .expect("one output data should have existed") - .into_string() - .expect(INTERNAL_ERR)) - } - pub fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { - match call.input.get(0..4) { - Some(signature) => Self::METHOD_ID == signature, - None => false, - } - } - pub fn call(&self, address: Vec) -> Option { - use substreams_ethereum::pb::eth::rpc; - let rpc_calls = rpc::RpcCalls { - calls: vec![rpc::RpcCall { to_addr: address, data: self.encode() }], - }; - let responses = substreams_ethereum::rpc::eth_call(&rpc_calls).responses; - let response = responses - .get(0) - .expect("one response should have existed"); - if response.failed { - return None; - } - match Self::output(response.raw.as_ref()) { - Ok(data) => Some(data), - Err(err) => { - use substreams_ethereum::Function; - substreams::log::info!( - "Call output for function `{}` failed to decode with error: {}", - Self::NAME, - err - ); - None - } - } - } - } - impl substreams_ethereum::Function for Name { - const NAME: &'static str = "name"; - fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { - Self::match_call(call) - } - fn decode(call: &substreams_ethereum::pb::eth::v2::Call) -> Result { - Self::decode(call) - } - fn encode(&self) -> Vec { - self.encode() - } - } - impl substreams_ethereum::rpc::RPCDecodable for Name { - fn output(data: &[u8]) -> Result { - Self::output(data) - } - } - #[derive(Debug, Clone, PartialEq)] - pub struct Symbol {} - impl Symbol { - const METHOD_ID: [u8; 4] = [149u8, 216u8, 155u8, 65u8]; - pub fn decode(call: &substreams_ethereum::pb::eth::v2::Call) -> Result { - Ok(Self {}) - } - pub fn encode(&self) -> Vec { - let data = ethabi::encode(&[]); - let mut encoded = Vec::with_capacity(4 + data.len()); - encoded.extend(Self::METHOD_ID); - encoded.extend(data); - encoded - } - pub fn output_call( - call: &substreams_ethereum::pb::eth::v2::Call, - ) -> Result { - Self::output(call.return_data.as_ref()) - } - pub fn output(data: &[u8]) -> Result { - let mut values = ethabi::decode(&[ethabi::ParamType::String], data.as_ref()) - .map_err(|e| format!("unable to decode output data: {e:?}"))?; - Ok(values - .pop() - .expect("one output data should have existed") - .into_string() - .expect(INTERNAL_ERR)) - } - pub fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { - match call.input.get(0..4) { - Some(signature) => Self::METHOD_ID == signature, - None => false, - } - } - pub fn call(&self, address: Vec) -> Option { - use substreams_ethereum::pb::eth::rpc; - let rpc_calls = rpc::RpcCalls { - calls: vec![rpc::RpcCall { to_addr: address, data: self.encode() }], - }; - let responses = substreams_ethereum::rpc::eth_call(&rpc_calls).responses; - let response = responses - .get(0) - .expect("one response should have existed"); - if response.failed { - return None; - } - match Self::output(response.raw.as_ref()) { - Ok(data) => Some(data), - Err(err) => { - use substreams_ethereum::Function; - substreams::log::info!( - "Call output for function `{}` failed to decode with error: {}", - Self::NAME, - err - ); - None - } - } - } - } - impl substreams_ethereum::Function for Symbol { - const NAME: &'static str = "symbol"; - fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { - Self::match_call(call) - } - fn decode(call: &substreams_ethereum::pb::eth::v2::Call) -> Result { - Self::decode(call) - } - fn encode(&self) -> Vec { - self.encode() - } - } - impl substreams_ethereum::rpc::RPCDecodable for Symbol { - fn output(data: &[u8]) -> Result { - Self::output(data) - } - } - #[derive(Debug, Clone, PartialEq)] - pub struct TotalSupply {} - impl TotalSupply { - const METHOD_ID: [u8; 4] = [24u8, 22u8, 13u8, 221u8]; - pub fn decode(call: &substreams_ethereum::pb::eth::v2::Call) -> Result { - Ok(Self {}) - } - pub fn encode(&self) -> Vec { - let data = ethabi::encode(&[]); - let mut encoded = Vec::with_capacity(4 + data.len()); - encoded.extend(Self::METHOD_ID); - encoded.extend(data); - encoded - } - pub fn output_call( - call: &substreams_ethereum::pb::eth::v2::Call, - ) -> Result { - Self::output(call.return_data.as_ref()) - } - pub fn output(data: &[u8]) -> Result { - let mut values = ethabi::decode(&[ethabi::ParamType::Uint(256usize)], data.as_ref()) - .map_err(|e| format!("unable to decode output data: {e:?}"))?; - Ok({ - let mut v = [0 as u8; 32]; - values - .pop() - .expect("one output data should have existed") - .into_uint() - .expect(INTERNAL_ERR) - .to_big_endian(v.as_mut_slice()); - substreams::scalar::BigInt::from_unsigned_bytes_be(&v) - }) - } - pub fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { - match call.input.get(0..4) { - Some(signature) => Self::METHOD_ID == signature, - None => false, - } - } - pub fn call(&self, address: Vec) -> Option { - use substreams_ethereum::pb::eth::rpc; - let rpc_calls = rpc::RpcCalls { - calls: vec![rpc::RpcCall { to_addr: address, data: self.encode() }], - }; - let responses = substreams_ethereum::rpc::eth_call(&rpc_calls).responses; - let response = responses - .get(0) - .expect("one response should have existed"); - if response.failed { - return None; - } - match Self::output(response.raw.as_ref()) { - Ok(data) => Some(data), - Err(err) => { - use substreams_ethereum::Function; - substreams::log::info!( - "Call output for function `{}` failed to decode with error: {}", - Self::NAME, - err - ); - None - } - } - } - } - impl substreams_ethereum::Function for TotalSupply { - const NAME: &'static str = "totalSupply"; - fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { - Self::match_call(call) - } - fn decode(call: &substreams_ethereum::pb::eth::v2::Call) -> Result { - Self::decode(call) - } - fn encode(&self) -> Vec { - self.encode() - } - } - impl substreams_ethereum::rpc::RPCDecodable for TotalSupply { - fn output(data: &[u8]) -> Result { - Self::output(data) - } - } - #[derive(Debug, Clone, PartialEq)] - pub struct Transfer { - pub dst: Vec, - pub wad: substreams::scalar::BigInt, - } - impl Transfer { - const METHOD_ID: [u8; 4] = [169u8, 5u8, 156u8, 187u8]; - pub fn decode(call: &substreams_ethereum::pb::eth::v2::Call) -> Result { - let maybe_data = call.input.get(4..); - if maybe_data.is_none() { - return Err("no data to decode".to_string()); - } - let mut values = ethabi::decode( - &[ethabi::ParamType::Address, ethabi::ParamType::Uint(256usize)], - maybe_data.unwrap(), - ) - .map_err(|e| format!("unable to decode call.input: {e:?}"))?; - values.reverse(); - Ok(Self { - dst: values - .pop() - .expect(INTERNAL_ERR) - .into_address() - .expect(INTERNAL_ERR) - .as_bytes() - .to_vec(), - wad: { - let mut v = [0 as u8; 32]; - values - .pop() - .expect(INTERNAL_ERR) - .into_uint() - .expect(INTERNAL_ERR) - .to_big_endian(v.as_mut_slice()); - substreams::scalar::BigInt::from_unsigned_bytes_be(&v) - }, - }) - } - pub fn encode(&self) -> Vec { - let data = ethabi::encode(&[ - ethabi::Token::Address(ethabi::Address::from_slice(&self.dst)), - ethabi::Token::Uint(ethabi::Uint::from_big_endian( - match self.wad.clone().to_bytes_be() { - (num_bigint::Sign::Plus, bytes) => bytes, - (num_bigint::Sign::NoSign, bytes) => bytes, - (num_bigint::Sign::Minus, _) => { - panic!("negative numbers are not supported") - } - } - .as_slice(), - )), - ]); - let mut encoded = Vec::with_capacity(4 + data.len()); - encoded.extend(Self::METHOD_ID); - encoded.extend(data); - encoded - } - pub fn output_call(call: &substreams_ethereum::pb::eth::v2::Call) -> Result { - Self::output(call.return_data.as_ref()) - } - pub fn output(data: &[u8]) -> Result { - let mut values = ethabi::decode(&[ethabi::ParamType::Bool], data.as_ref()) - .map_err(|e| format!("unable to decode output data: {e:?}"))?; - Ok(values - .pop() - .expect("one output data should have existed") - .into_bool() - .expect(INTERNAL_ERR)) - } - pub fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { - match call.input.get(0..4) { - Some(signature) => Self::METHOD_ID == signature, - None => false, - } - } - pub fn call(&self, address: Vec) -> Option { - use substreams_ethereum::pb::eth::rpc; - let rpc_calls = rpc::RpcCalls { - calls: vec![rpc::RpcCall { to_addr: address, data: self.encode() }], - }; - let responses = substreams_ethereum::rpc::eth_call(&rpc_calls).responses; - let response = responses - .get(0) - .expect("one response should have existed"); - if response.failed { - return None; - } - match Self::output(response.raw.as_ref()) { - Ok(data) => Some(data), - Err(err) => { - use substreams_ethereum::Function; - substreams::log::info!( - "Call output for function `{}` failed to decode with error: {}", - Self::NAME, - err - ); - None - } - } - } - } - impl substreams_ethereum::Function for Transfer { - const NAME: &'static str = "transfer"; - fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { - Self::match_call(call) - } - fn decode(call: &substreams_ethereum::pb::eth::v2::Call) -> Result { - Self::decode(call) - } - fn encode(&self) -> Vec { - self.encode() - } - } - impl substreams_ethereum::rpc::RPCDecodable for Transfer { - fn output(data: &[u8]) -> Result { - Self::output(data) - } - } - #[derive(Debug, Clone, PartialEq)] - pub struct TransferFrom { - pub src: Vec, - pub dst: Vec, - pub wad: substreams::scalar::BigInt, - } - impl TransferFrom { - const METHOD_ID: [u8; 4] = [35u8, 184u8, 114u8, 221u8]; - pub fn decode(call: &substreams_ethereum::pb::eth::v2::Call) -> Result { - let maybe_data = call.input.get(4..); - if maybe_data.is_none() { - return Err("no data to decode".to_string()); - } - let mut values = ethabi::decode( - &[ - ethabi::ParamType::Address, - ethabi::ParamType::Address, - ethabi::ParamType::Uint(256usize), - ], - maybe_data.unwrap(), - ) - .map_err(|e| format!("unable to decode call.input: {e:?}"))?; - values.reverse(); - Ok(Self { - src: values - .pop() - .expect(INTERNAL_ERR) - .into_address() - .expect(INTERNAL_ERR) - .as_bytes() - .to_vec(), - dst: values - .pop() - .expect(INTERNAL_ERR) - .into_address() - .expect(INTERNAL_ERR) - .as_bytes() - .to_vec(), - wad: { - let mut v = [0 as u8; 32]; - values - .pop() - .expect(INTERNAL_ERR) - .into_uint() - .expect(INTERNAL_ERR) - .to_big_endian(v.as_mut_slice()); - substreams::scalar::BigInt::from_unsigned_bytes_be(&v) - }, - }) - } - pub fn encode(&self) -> Vec { - let data = ethabi::encode(&[ - ethabi::Token::Address(ethabi::Address::from_slice(&self.src)), - ethabi::Token::Address(ethabi::Address::from_slice(&self.dst)), - ethabi::Token::Uint(ethabi::Uint::from_big_endian( - match self.wad.clone().to_bytes_be() { - (num_bigint::Sign::Plus, bytes) => bytes, - (num_bigint::Sign::NoSign, bytes) => bytes, - (num_bigint::Sign::Minus, _) => { - panic!("negative numbers are not supported") - } - } - .as_slice(), - )), - ]); - let mut encoded = Vec::with_capacity(4 + data.len()); - encoded.extend(Self::METHOD_ID); - encoded.extend(data); - encoded - } - pub fn output_call(call: &substreams_ethereum::pb::eth::v2::Call) -> Result { - Self::output(call.return_data.as_ref()) - } - pub fn output(data: &[u8]) -> Result { - let mut values = ethabi::decode(&[ethabi::ParamType::Bool], data.as_ref()) - .map_err(|e| format!("unable to decode output data: {e:?}"))?; - Ok(values - .pop() - .expect("one output data should have existed") - .into_bool() - .expect(INTERNAL_ERR)) - } - pub fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { - match call.input.get(0..4) { - Some(signature) => Self::METHOD_ID == signature, - None => false, - } - } - pub fn call(&self, address: Vec) -> Option { - use substreams_ethereum::pb::eth::rpc; - let rpc_calls = rpc::RpcCalls { - calls: vec![rpc::RpcCall { to_addr: address, data: self.encode() }], - }; - let responses = substreams_ethereum::rpc::eth_call(&rpc_calls).responses; - let response = responses - .get(0) - .expect("one response should have existed"); - if response.failed { - return None; - } - match Self::output(response.raw.as_ref()) { - Ok(data) => Some(data), - Err(err) => { - use substreams_ethereum::Function; - substreams::log::info!( - "Call output for function `{}` failed to decode with error: {}", - Self::NAME, - err - ); - None - } - } - } - } - impl substreams_ethereum::Function for TransferFrom { - const NAME: &'static str = "transferFrom"; - fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { - Self::match_call(call) - } - fn decode(call: &substreams_ethereum::pb::eth::v2::Call) -> Result { - Self::decode(call) - } - fn encode(&self) -> Vec { - self.encode() - } - } - impl substreams_ethereum::rpc::RPCDecodable for TransferFrom { - fn output(data: &[u8]) -> Result { - Self::output(data) - } - } - #[derive(Debug, Clone, PartialEq)] - pub struct Withdraw { - pub wad: substreams::scalar::BigInt, - } - impl Withdraw { - const METHOD_ID: [u8; 4] = [46u8, 26u8, 125u8, 77u8]; - pub fn decode(call: &substreams_ethereum::pb::eth::v2::Call) -> Result { - let maybe_data = call.input.get(4..); - if maybe_data.is_none() { - return Err("no data to decode".to_string()); - } - let mut values = - ethabi::decode(&[ethabi::ParamType::Uint(256usize)], maybe_data.unwrap()) - .map_err(|e| format!("unable to decode call.input: {e:?}"))?; - values.reverse(); - Ok(Self { - wad: { - let mut v = [0 as u8; 32]; - values - .pop() - .expect(INTERNAL_ERR) - .into_uint() - .expect(INTERNAL_ERR) - .to_big_endian(v.as_mut_slice()); - substreams::scalar::BigInt::from_unsigned_bytes_be(&v) - }, - }) - } - pub fn encode(&self) -> Vec { - let data = ethabi::encode(&[ethabi::Token::Uint(ethabi::Uint::from_big_endian( - match self.wad.clone().to_bytes_be() { - (num_bigint::Sign::Plus, bytes) => bytes, - (num_bigint::Sign::NoSign, bytes) => bytes, - (num_bigint::Sign::Minus, _) => { - panic!("negative numbers are not supported") + match Self::output(response.raw.as_ref()) { + Ok(data) => Some(data), + Err(err) => { + use substreams_ethereum::Function; + substreams::log::info!( + "Call output for function `{}` failed to decode with error: {}", + Self::NAME, err + ); + None } } - .as_slice(), - ))]); - let mut encoded = Vec::with_capacity(4 + data.len()); - encoded.extend(Self::METHOD_ID); - encoded.extend(data); - encoded - } - pub fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { - match call.input.get(0..4) { - Some(signature) => Self::METHOD_ID == signature, - None => false, } } - } - impl substreams_ethereum::Function for Withdraw { - const NAME: &'static str = "withdraw"; - fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { - Self::match_call(call) - } - fn decode(call: &substreams_ethereum::pb::eth::v2::Call) -> Result { - Self::decode(call) - } - fn encode(&self) -> Vec { - self.encode() - } - } -} -/// Contract's events. -#[allow(dead_code, unused_imports, unused_variables)] -pub mod events { - use super::INTERNAL_ERR; - #[derive(Debug, Clone, PartialEq)] - pub struct Approval { - pub src: Vec, - pub guy: Vec, - pub wad: substreams::scalar::BigInt, - } - impl Approval { - const TOPIC_ID: [u8; 32] = [ - 140u8, 91u8, 225u8, 229u8, 235u8, 236u8, 125u8, 91u8, 209u8, 79u8, 113u8, 66u8, 125u8, - 30u8, 132u8, 243u8, 221u8, 3u8, 20u8, 192u8, 247u8, 178u8, 41u8, 30u8, 91u8, 32u8, - 10u8, 200u8, 199u8, 195u8, 185u8, 37u8, - ]; - pub fn match_log(log: &substreams_ethereum::pb::eth::v2::Log) -> bool { - if log.topics.len() != 3usize { - return false; + impl substreams_ethereum::Function for Allowance { + const NAME: &'static str = "allowance"; + fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { + Self::match_call(call) } - if log.data.len() != 32usize { - return false; + fn decode( + call: &substreams_ethereum::pb::eth::v2::Call, + ) -> Result { + Self::decode(call) + } + fn encode(&self) -> Vec { + self.encode() } - return log - .topics - .get(0) - .expect("bounds already checked") - .as_ref() - == Self::TOPIC_ID; } - pub fn decode(log: &substreams_ethereum::pb::eth::v2::Log) -> Result { - let mut values = - ethabi::decode(&[ethabi::ParamType::Uint(256usize)], log.data.as_ref()) - .map_err(|e| format!("unable to decode log.data: {e:?}"))?; - values.reverse(); - Ok(Self { - src: ethabi::decode(&[ethabi::ParamType::Address], log.topics[1usize].as_ref()) - .map_err(|e| { - format!("unable to decode param 'src' from topic of type 'address': {e:?}") - })? - .pop() - .expect(INTERNAL_ERR) - .into_address() - .expect(INTERNAL_ERR) - .as_bytes() - .to_vec(), - guy: ethabi::decode(&[ethabi::ParamType::Address], log.topics[2usize].as_ref()) - .map_err(|e| { - format!("unable to decode param 'guy' from topic of type 'address': {e:?}") - })? - .pop() - .expect(INTERNAL_ERR) - .into_address() - .expect(INTERNAL_ERR) - .as_bytes() - .to_vec(), - wad: { + impl substreams_ethereum::rpc::RPCDecodable + for Allowance { + fn output(data: &[u8]) -> Result { + Self::output(data) + } + } + #[derive(Debug, Clone, PartialEq)] + pub struct Approve { + pub guy: Vec, + pub wad: substreams::scalar::BigInt, + } + impl Approve { + const METHOD_ID: [u8; 4] = [9u8, 94u8, 167u8, 179u8]; + pub fn decode( + call: &substreams_ethereum::pb::eth::v2::Call, + ) -> Result { + let maybe_data = call.input.get(4..); + if maybe_data.is_none() { + return Err("no data to decode".to_string()); + } + let mut values = ethabi::decode( + &[ethabi::ParamType::Address, ethabi::ParamType::Uint(256usize)], + maybe_data.unwrap(), + ) + .map_err(|e| format!("unable to decode call.input: {:?}", e))?; + values.reverse(); + Ok(Self { + guy: values + .pop() + .expect(INTERNAL_ERR) + .into_address() + .expect(INTERNAL_ERR) + .as_bytes() + .to_vec(), + wad: { + let mut v = [0 as u8; 32]; + values + .pop() + .expect(INTERNAL_ERR) + .into_uint() + .expect(INTERNAL_ERR) + .to_big_endian(v.as_mut_slice()); + substreams::scalar::BigInt::from_unsigned_bytes_be(&v) + }, + }) + } + pub fn encode(&self) -> Vec { + let data = ethabi::encode( + &[ + ethabi::Token::Address(ethabi::Address::from_slice(&self.guy)), + ethabi::Token::Uint( + ethabi::Uint::from_big_endian( + match self.wad.clone().to_bytes_be() { + (num_bigint::Sign::Plus, bytes) => bytes, + (num_bigint::Sign::NoSign, bytes) => bytes, + (num_bigint::Sign::Minus, _) => { + panic!("negative numbers are not supported") + } + } + .as_slice(), + ), + ), + ], + ); + let mut encoded = Vec::with_capacity(4 + data.len()); + encoded.extend(Self::METHOD_ID); + encoded.extend(data); + encoded + } + pub fn output_call( + call: &substreams_ethereum::pb::eth::v2::Call, + ) -> Result { + Self::output(call.return_data.as_ref()) + } + pub fn output(data: &[u8]) -> Result { + let mut values = ethabi::decode( + &[ethabi::ParamType::Bool], + data.as_ref(), + ) + .map_err(|e| format!("unable to decode output data: {:?}", e))?; + Ok( + values + .pop() + .expect("one output data should have existed") + .into_bool() + .expect(INTERNAL_ERR), + ) + } + pub fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { + match call.input.get(0..4) { + Some(signature) => Self::METHOD_ID == signature, + None => false, + } + } + pub fn call(&self, address: Vec) -> Option { + use substreams_ethereum::pb::eth::rpc; + let rpc_calls = rpc::RpcCalls { + calls: vec![ + rpc::RpcCall { to_addr : address, data : self.encode(), } + ], + }; + let responses = substreams_ethereum::rpc::eth_call(&rpc_calls).responses; + let response = responses + .get(0) + .expect("one response should have existed"); + if response.failed { + return None; + } + match Self::output(response.raw.as_ref()) { + Ok(data) => Some(data), + Err(err) => { + use substreams_ethereum::Function; + substreams::log::info!( + "Call output for function `{}` failed to decode with error: {}", + Self::NAME, err + ); + None + } + } + } + } + impl substreams_ethereum::Function for Approve { + const NAME: &'static str = "approve"; + fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { + Self::match_call(call) + } + fn decode( + call: &substreams_ethereum::pb::eth::v2::Call, + ) -> Result { + Self::decode(call) + } + fn encode(&self) -> Vec { + self.encode() + } + } + impl substreams_ethereum::rpc::RPCDecodable for Approve { + fn output(data: &[u8]) -> Result { + Self::output(data) + } + } + #[derive(Debug, Clone, PartialEq)] + pub struct BalanceOf { + pub param0: Vec, + } + impl BalanceOf { + const METHOD_ID: [u8; 4] = [112u8, 160u8, 130u8, 49u8]; + pub fn decode( + call: &substreams_ethereum::pb::eth::v2::Call, + ) -> Result { + let maybe_data = call.input.get(4..); + if maybe_data.is_none() { + return Err("no data to decode".to_string()); + } + let mut values = ethabi::decode( + &[ethabi::ParamType::Address], + maybe_data.unwrap(), + ) + .map_err(|e| format!("unable to decode call.input: {:?}", e))?; + values.reverse(); + Ok(Self { + param0: values + .pop() + .expect(INTERNAL_ERR) + .into_address() + .expect(INTERNAL_ERR) + .as_bytes() + .to_vec(), + }) + } + pub fn encode(&self) -> Vec { + let data = ethabi::encode( + &[ethabi::Token::Address(ethabi::Address::from_slice(&self.param0))], + ); + let mut encoded = Vec::with_capacity(4 + data.len()); + encoded.extend(Self::METHOD_ID); + encoded.extend(data); + encoded + } + pub fn output_call( + call: &substreams_ethereum::pb::eth::v2::Call, + ) -> Result { + Self::output(call.return_data.as_ref()) + } + pub fn output(data: &[u8]) -> Result { + let mut values = ethabi::decode( + &[ethabi::ParamType::Uint(256usize)], + data.as_ref(), + ) + .map_err(|e| format!("unable to decode output data: {:?}", e))?; + Ok({ let mut v = [0 as u8; 32]; values .pop() - .expect(INTERNAL_ERR) + .expect("one output data should have existed") .into_uint() .expect(INTERNAL_ERR) .to_big_endian(v.as_mut_slice()); substreams::scalar::BigInt::from_unsigned_bytes_be(&v) - }, - }) - } - } - impl substreams_ethereum::Event for Approval { - const NAME: &'static str = "Approval"; - fn match_log(log: &substreams_ethereum::pb::eth::v2::Log) -> bool { - Self::match_log(log) - } - fn decode(log: &substreams_ethereum::pb::eth::v2::Log) -> Result { - Self::decode(log) - } - } - #[derive(Debug, Clone, PartialEq)] - pub struct Deposit { - pub dst: Vec, - pub wad: substreams::scalar::BigInt, - } - impl Deposit { - const TOPIC_ID: [u8; 32] = [ - 225u8, 255u8, 252u8, 196u8, 146u8, 61u8, 4u8, 181u8, 89u8, 244u8, 210u8, 154u8, 139u8, - 252u8, 108u8, 218u8, 4u8, 235u8, 91u8, 13u8, 60u8, 70u8, 7u8, 81u8, 194u8, 64u8, 44u8, - 92u8, 92u8, 201u8, 16u8, 156u8, - ]; - pub fn match_log(log: &substreams_ethereum::pb::eth::v2::Log) -> bool { - if log.topics.len() != 2usize { - return false; + }) } - if log.data.len() != 32usize { - return false; + pub fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { + match call.input.get(0..4) { + Some(signature) => Self::METHOD_ID == signature, + None => false, + } + } + pub fn call(&self, address: Vec) -> Option { + use substreams_ethereum::pb::eth::rpc; + let rpc_calls = rpc::RpcCalls { + calls: vec![ + rpc::RpcCall { to_addr : address, data : self.encode(), } + ], + }; + let responses = substreams_ethereum::rpc::eth_call(&rpc_calls).responses; + let response = responses + .get(0) + .expect("one response should have existed"); + if response.failed { + return None; + } + match Self::output(response.raw.as_ref()) { + Ok(data) => Some(data), + Err(err) => { + use substreams_ethereum::Function; + substreams::log::info!( + "Call output for function `{}` failed to decode with error: {}", + Self::NAME, err + ); + None + } + } } - return log - .topics - .get(0) - .expect("bounds already checked") - .as_ref() - == Self::TOPIC_ID; } - pub fn decode(log: &substreams_ethereum::pb::eth::v2::Log) -> Result { - let mut values = - ethabi::decode(&[ethabi::ParamType::Uint(256usize)], log.data.as_ref()) - .map_err(|e| format!("unable to decode log.data: {e:?}"))?; - values.reverse(); - Ok(Self { - dst: ethabi::decode(&[ethabi::ParamType::Address], log.topics[1usize].as_ref()) - .map_err(|e| { - format!("unable to decode param 'dst' from topic of type 'address': {e:?}") - })? - .pop() - .expect(INTERNAL_ERR) - .into_address() - .expect(INTERNAL_ERR) - .as_bytes() - .to_vec(), - wad: { + impl substreams_ethereum::Function for BalanceOf { + const NAME: &'static str = "balanceOf"; + fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { + Self::match_call(call) + } + fn decode( + call: &substreams_ethereum::pb::eth::v2::Call, + ) -> Result { + Self::decode(call) + } + fn encode(&self) -> Vec { + self.encode() + } + } + impl substreams_ethereum::rpc::RPCDecodable + for BalanceOf { + fn output(data: &[u8]) -> Result { + Self::output(data) + } + } + #[derive(Debug, Clone, PartialEq)] + pub struct Decimals {} + impl Decimals { + const METHOD_ID: [u8; 4] = [49u8, 60u8, 229u8, 103u8]; + pub fn decode( + call: &substreams_ethereum::pb::eth::v2::Call, + ) -> Result { + Ok(Self {}) + } + pub fn encode(&self) -> Vec { + let data = ethabi::encode(&[]); + let mut encoded = Vec::with_capacity(4 + data.len()); + encoded.extend(Self::METHOD_ID); + encoded.extend(data); + encoded + } + pub fn output_call( + call: &substreams_ethereum::pb::eth::v2::Call, + ) -> Result { + Self::output(call.return_data.as_ref()) + } + pub fn output(data: &[u8]) -> Result { + let mut values = ethabi::decode( + &[ethabi::ParamType::Uint(8usize)], + data.as_ref(), + ) + .map_err(|e| format!("unable to decode output data: {:?}", e))?; + Ok({ let mut v = [0 as u8; 32]; values .pop() - .expect(INTERNAL_ERR) + .expect("one output data should have existed") .into_uint() .expect(INTERNAL_ERR) .to_big_endian(v.as_mut_slice()); substreams::scalar::BigInt::from_unsigned_bytes_be(&v) - }, - }) - } - } - impl substreams_ethereum::Event for Deposit { - const NAME: &'static str = "Deposit"; - fn match_log(log: &substreams_ethereum::pb::eth::v2::Log) -> bool { - Self::match_log(log) - } - fn decode(log: &substreams_ethereum::pb::eth::v2::Log) -> Result { - Self::decode(log) - } - } - #[derive(Debug, Clone, PartialEq)] - pub struct Transfer { - pub src: Vec, - pub dst: Vec, - pub wad: substreams::scalar::BigInt, - } - impl Transfer { - const TOPIC_ID: [u8; 32] = [ - 221u8, 242u8, 82u8, 173u8, 27u8, 226u8, 200u8, 155u8, 105u8, 194u8, 176u8, 104u8, - 252u8, 55u8, 141u8, 170u8, 149u8, 43u8, 167u8, 241u8, 99u8, 196u8, 161u8, 22u8, 40u8, - 245u8, 90u8, 77u8, 245u8, 35u8, 179u8, 239u8, - ]; - pub fn match_log(log: &substreams_ethereum::pb::eth::v2::Log) -> bool { - if log.topics.len() != 3usize { - return false; + }) } - if log.data.len() != 32usize { - return false; + pub fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { + match call.input.get(0..4) { + Some(signature) => Self::METHOD_ID == signature, + None => false, + } + } + pub fn call(&self, address: Vec) -> Option { + use substreams_ethereum::pb::eth::rpc; + let rpc_calls = rpc::RpcCalls { + calls: vec![ + rpc::RpcCall { to_addr : address, data : self.encode(), } + ], + }; + let responses = substreams_ethereum::rpc::eth_call(&rpc_calls).responses; + let response = responses + .get(0) + .expect("one response should have existed"); + if response.failed { + return None; + } + match Self::output(response.raw.as_ref()) { + Ok(data) => Some(data), + Err(err) => { + use substreams_ethereum::Function; + substreams::log::info!( + "Call output for function `{}` failed to decode with error: {}", + Self::NAME, err + ); + None + } + } } - return log - .topics - .get(0) - .expect("bounds already checked") - .as_ref() - == Self::TOPIC_ID; } - pub fn decode(log: &substreams_ethereum::pb::eth::v2::Log) -> Result { - let mut values = - ethabi::decode(&[ethabi::ParamType::Uint(256usize)], log.data.as_ref()) - .map_err(|e| format!("unable to decode log.data: {e:?}"))?; - values.reverse(); - Ok(Self { - src: ethabi::decode(&[ethabi::ParamType::Address], log.topics[1usize].as_ref()) - .map_err(|e| { - format!("unable to decode param 'src' from topic of type 'address': {e:?}") - })? - .pop() - .expect(INTERNAL_ERR) - .into_address() - .expect(INTERNAL_ERR) - .as_bytes() - .to_vec(), - dst: ethabi::decode(&[ethabi::ParamType::Address], log.topics[2usize].as_ref()) - .map_err(|e| { - format!("unable to decode param 'dst' from topic of type 'address': {e:?}") - })? - .pop() - .expect(INTERNAL_ERR) - .into_address() - .expect(INTERNAL_ERR) - .as_bytes() - .to_vec(), - wad: { + impl substreams_ethereum::Function for Decimals { + const NAME: &'static str = "decimals"; + fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { + Self::match_call(call) + } + fn decode( + call: &substreams_ethereum::pb::eth::v2::Call, + ) -> Result { + Self::decode(call) + } + fn encode(&self) -> Vec { + self.encode() + } + } + impl substreams_ethereum::rpc::RPCDecodable + for Decimals { + fn output(data: &[u8]) -> Result { + Self::output(data) + } + } + #[derive(Debug, Clone, PartialEq)] + pub struct Deposit {} + impl Deposit { + const METHOD_ID: [u8; 4] = [208u8, 227u8, 13u8, 176u8]; + pub fn decode( + call: &substreams_ethereum::pb::eth::v2::Call, + ) -> Result { + Ok(Self {}) + } + pub fn encode(&self) -> Vec { + let data = ethabi::encode(&[]); + let mut encoded = Vec::with_capacity(4 + data.len()); + encoded.extend(Self::METHOD_ID); + encoded.extend(data); + encoded + } + pub fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { + match call.input.get(0..4) { + Some(signature) => Self::METHOD_ID == signature, + None => false, + } + } + } + impl substreams_ethereum::Function for Deposit { + const NAME: &'static str = "deposit"; + fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { + Self::match_call(call) + } + fn decode( + call: &substreams_ethereum::pb::eth::v2::Call, + ) -> Result { + Self::decode(call) + } + fn encode(&self) -> Vec { + self.encode() + } + } + #[derive(Debug, Clone, PartialEq)] + pub struct Name {} + impl Name { + const METHOD_ID: [u8; 4] = [6u8, 253u8, 222u8, 3u8]; + pub fn decode( + call: &substreams_ethereum::pb::eth::v2::Call, + ) -> Result { + Ok(Self {}) + } + pub fn encode(&self) -> Vec { + let data = ethabi::encode(&[]); + let mut encoded = Vec::with_capacity(4 + data.len()); + encoded.extend(Self::METHOD_ID); + encoded.extend(data); + encoded + } + pub fn output_call( + call: &substreams_ethereum::pb::eth::v2::Call, + ) -> Result { + Self::output(call.return_data.as_ref()) + } + pub fn output(data: &[u8]) -> Result { + let mut values = ethabi::decode( + &[ethabi::ParamType::String], + data.as_ref(), + ) + .map_err(|e| format!("unable to decode output data: {:?}", e))?; + Ok( + values + .pop() + .expect("one output data should have existed") + .into_string() + .expect(INTERNAL_ERR), + ) + } + pub fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { + match call.input.get(0..4) { + Some(signature) => Self::METHOD_ID == signature, + None => false, + } + } + pub fn call(&self, address: Vec) -> Option { + use substreams_ethereum::pb::eth::rpc; + let rpc_calls = rpc::RpcCalls { + calls: vec![ + rpc::RpcCall { to_addr : address, data : self.encode(), } + ], + }; + let responses = substreams_ethereum::rpc::eth_call(&rpc_calls).responses; + let response = responses + .get(0) + .expect("one response should have existed"); + if response.failed { + return None; + } + match Self::output(response.raw.as_ref()) { + Ok(data) => Some(data), + Err(err) => { + use substreams_ethereum::Function; + substreams::log::info!( + "Call output for function `{}` failed to decode with error: {}", + Self::NAME, err + ); + None + } + } + } + } + impl substreams_ethereum::Function for Name { + const NAME: &'static str = "name"; + fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { + Self::match_call(call) + } + fn decode( + call: &substreams_ethereum::pb::eth::v2::Call, + ) -> Result { + Self::decode(call) + } + fn encode(&self) -> Vec { + self.encode() + } + } + impl substreams_ethereum::rpc::RPCDecodable for Name { + fn output(data: &[u8]) -> Result { + Self::output(data) + } + } + #[derive(Debug, Clone, PartialEq)] + pub struct Symbol {} + impl Symbol { + const METHOD_ID: [u8; 4] = [149u8, 216u8, 155u8, 65u8]; + pub fn decode( + call: &substreams_ethereum::pb::eth::v2::Call, + ) -> Result { + Ok(Self {}) + } + pub fn encode(&self) -> Vec { + let data = ethabi::encode(&[]); + let mut encoded = Vec::with_capacity(4 + data.len()); + encoded.extend(Self::METHOD_ID); + encoded.extend(data); + encoded + } + pub fn output_call( + call: &substreams_ethereum::pb::eth::v2::Call, + ) -> Result { + Self::output(call.return_data.as_ref()) + } + pub fn output(data: &[u8]) -> Result { + let mut values = ethabi::decode( + &[ethabi::ParamType::String], + data.as_ref(), + ) + .map_err(|e| format!("unable to decode output data: {:?}", e))?; + Ok( + values + .pop() + .expect("one output data should have existed") + .into_string() + .expect(INTERNAL_ERR), + ) + } + pub fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { + match call.input.get(0..4) { + Some(signature) => Self::METHOD_ID == signature, + None => false, + } + } + pub fn call(&self, address: Vec) -> Option { + use substreams_ethereum::pb::eth::rpc; + let rpc_calls = rpc::RpcCalls { + calls: vec![ + rpc::RpcCall { to_addr : address, data : self.encode(), } + ], + }; + let responses = substreams_ethereum::rpc::eth_call(&rpc_calls).responses; + let response = responses + .get(0) + .expect("one response should have existed"); + if response.failed { + return None; + } + match Self::output(response.raw.as_ref()) { + Ok(data) => Some(data), + Err(err) => { + use substreams_ethereum::Function; + substreams::log::info!( + "Call output for function `{}` failed to decode with error: {}", + Self::NAME, err + ); + None + } + } + } + } + impl substreams_ethereum::Function for Symbol { + const NAME: &'static str = "symbol"; + fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { + Self::match_call(call) + } + fn decode( + call: &substreams_ethereum::pb::eth::v2::Call, + ) -> Result { + Self::decode(call) + } + fn encode(&self) -> Vec { + self.encode() + } + } + impl substreams_ethereum::rpc::RPCDecodable for Symbol { + fn output(data: &[u8]) -> Result { + Self::output(data) + } + } + #[derive(Debug, Clone, PartialEq)] + pub struct TotalSupply {} + impl TotalSupply { + const METHOD_ID: [u8; 4] = [24u8, 22u8, 13u8, 221u8]; + pub fn decode( + call: &substreams_ethereum::pb::eth::v2::Call, + ) -> Result { + Ok(Self {}) + } + pub fn encode(&self) -> Vec { + let data = ethabi::encode(&[]); + let mut encoded = Vec::with_capacity(4 + data.len()); + encoded.extend(Self::METHOD_ID); + encoded.extend(data); + encoded + } + pub fn output_call( + call: &substreams_ethereum::pb::eth::v2::Call, + ) -> Result { + Self::output(call.return_data.as_ref()) + } + pub fn output(data: &[u8]) -> Result { + let mut values = ethabi::decode( + &[ethabi::ParamType::Uint(256usize)], + data.as_ref(), + ) + .map_err(|e| format!("unable to decode output data: {:?}", e))?; + Ok({ let mut v = [0 as u8; 32]; values .pop() - .expect(INTERNAL_ERR) + .expect("one output data should have existed") .into_uint() .expect(INTERNAL_ERR) .to_big_endian(v.as_mut_slice()); substreams::scalar::BigInt::from_unsigned_bytes_be(&v) - }, - }) - } - } - impl substreams_ethereum::Event for Transfer { - const NAME: &'static str = "Transfer"; - fn match_log(log: &substreams_ethereum::pb::eth::v2::Log) -> bool { - Self::match_log(log) - } - fn decode(log: &substreams_ethereum::pb::eth::v2::Log) -> Result { - Self::decode(log) - } - } - #[derive(Debug, Clone, PartialEq)] - pub struct Withdrawal { - pub src: Vec, - pub wad: substreams::scalar::BigInt, - } - impl Withdrawal { - const TOPIC_ID: [u8; 32] = [ - 127u8, 207u8, 83u8, 44u8, 21u8, 240u8, 166u8, 219u8, 11u8, 214u8, 208u8, 224u8, 56u8, - 190u8, 167u8, 29u8, 48u8, 216u8, 8u8, 199u8, 217u8, 140u8, 179u8, 191u8, 114u8, 104u8, - 169u8, 91u8, 245u8, 8u8, 27u8, 101u8, - ]; - pub fn match_log(log: &substreams_ethereum::pb::eth::v2::Log) -> bool { - if log.topics.len() != 2usize { - return false; + }) } - if log.data.len() != 32usize { - return false; + pub fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { + match call.input.get(0..4) { + Some(signature) => Self::METHOD_ID == signature, + None => false, + } + } + pub fn call(&self, address: Vec) -> Option { + use substreams_ethereum::pb::eth::rpc; + let rpc_calls = rpc::RpcCalls { + calls: vec![ + rpc::RpcCall { to_addr : address, data : self.encode(), } + ], + }; + let responses = substreams_ethereum::rpc::eth_call(&rpc_calls).responses; + let response = responses + .get(0) + .expect("one response should have existed"); + if response.failed { + return None; + } + match Self::output(response.raw.as_ref()) { + Ok(data) => Some(data), + Err(err) => { + use substreams_ethereum::Function; + substreams::log::info!( + "Call output for function `{}` failed to decode with error: {}", + Self::NAME, err + ); + None + } + } } - return log - .topics - .get(0) - .expect("bounds already checked") - .as_ref() - == Self::TOPIC_ID; } - pub fn decode(log: &substreams_ethereum::pb::eth::v2::Log) -> Result { - let mut values = - ethabi::decode(&[ethabi::ParamType::Uint(256usize)], log.data.as_ref()) - .map_err(|e| format!("unable to decode log.data: {e:?}"))?; - values.reverse(); - Ok(Self { - src: ethabi::decode(&[ethabi::ParamType::Address], log.topics[1usize].as_ref()) - .map_err(|e| { - format!("unable to decode param 'src' from topic of type 'address': {e:?}") - })? - .pop() - .expect(INTERNAL_ERR) - .into_address() - .expect(INTERNAL_ERR) - .as_bytes() - .to_vec(), - wad: { - let mut v = [0 as u8; 32]; - values + impl substreams_ethereum::Function for TotalSupply { + const NAME: &'static str = "totalSupply"; + fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { + Self::match_call(call) + } + fn decode( + call: &substreams_ethereum::pb::eth::v2::Call, + ) -> Result { + Self::decode(call) + } + fn encode(&self) -> Vec { + self.encode() + } + } + impl substreams_ethereum::rpc::RPCDecodable + for TotalSupply { + fn output(data: &[u8]) -> Result { + Self::output(data) + } + } + #[derive(Debug, Clone, PartialEq)] + pub struct Transfer { + pub dst: Vec, + pub wad: substreams::scalar::BigInt, + } + impl Transfer { + const METHOD_ID: [u8; 4] = [169u8, 5u8, 156u8, 187u8]; + pub fn decode( + call: &substreams_ethereum::pb::eth::v2::Call, + ) -> Result { + let maybe_data = call.input.get(4..); + if maybe_data.is_none() { + return Err("no data to decode".to_string()); + } + let mut values = ethabi::decode( + &[ethabi::ParamType::Address, ethabi::ParamType::Uint(256usize)], + maybe_data.unwrap(), + ) + .map_err(|e| format!("unable to decode call.input: {:?}", e))?; + values.reverse(); + Ok(Self { + dst: values .pop() .expect(INTERNAL_ERR) - .into_uint() + .into_address() .expect(INTERNAL_ERR) - .to_big_endian(v.as_mut_slice()); - substreams::scalar::BigInt::from_unsigned_bytes_be(&v) - }, - }) + .as_bytes() + .to_vec(), + wad: { + let mut v = [0 as u8; 32]; + values + .pop() + .expect(INTERNAL_ERR) + .into_uint() + .expect(INTERNAL_ERR) + .to_big_endian(v.as_mut_slice()); + substreams::scalar::BigInt::from_unsigned_bytes_be(&v) + }, + }) + } + pub fn encode(&self) -> Vec { + let data = ethabi::encode( + &[ + ethabi::Token::Address(ethabi::Address::from_slice(&self.dst)), + ethabi::Token::Uint( + ethabi::Uint::from_big_endian( + match self.wad.clone().to_bytes_be() { + (num_bigint::Sign::Plus, bytes) => bytes, + (num_bigint::Sign::NoSign, bytes) => bytes, + (num_bigint::Sign::Minus, _) => { + panic!("negative numbers are not supported") + } + } + .as_slice(), + ), + ), + ], + ); + let mut encoded = Vec::with_capacity(4 + data.len()); + encoded.extend(Self::METHOD_ID); + encoded.extend(data); + encoded + } + pub fn output_call( + call: &substreams_ethereum::pb::eth::v2::Call, + ) -> Result { + Self::output(call.return_data.as_ref()) + } + pub fn output(data: &[u8]) -> Result { + let mut values = ethabi::decode( + &[ethabi::ParamType::Bool], + data.as_ref(), + ) + .map_err(|e| format!("unable to decode output data: {:?}", e))?; + Ok( + values + .pop() + .expect("one output data should have existed") + .into_bool() + .expect(INTERNAL_ERR), + ) + } + pub fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { + match call.input.get(0..4) { + Some(signature) => Self::METHOD_ID == signature, + None => false, + } + } + pub fn call(&self, address: Vec) -> Option { + use substreams_ethereum::pb::eth::rpc; + let rpc_calls = rpc::RpcCalls { + calls: vec![ + rpc::RpcCall { to_addr : address, data : self.encode(), } + ], + }; + let responses = substreams_ethereum::rpc::eth_call(&rpc_calls).responses; + let response = responses + .get(0) + .expect("one response should have existed"); + if response.failed { + return None; + } + match Self::output(response.raw.as_ref()) { + Ok(data) => Some(data), + Err(err) => { + use substreams_ethereum::Function; + substreams::log::info!( + "Call output for function `{}` failed to decode with error: {}", + Self::NAME, err + ); + None + } + } + } + } + impl substreams_ethereum::Function for Transfer { + const NAME: &'static str = "transfer"; + fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { + Self::match_call(call) + } + fn decode( + call: &substreams_ethereum::pb::eth::v2::Call, + ) -> Result { + Self::decode(call) + } + fn encode(&self) -> Vec { + self.encode() + } + } + impl substreams_ethereum::rpc::RPCDecodable for Transfer { + fn output(data: &[u8]) -> Result { + Self::output(data) + } + } + #[derive(Debug, Clone, PartialEq)] + pub struct TransferFrom { + pub src: Vec, + pub dst: Vec, + pub wad: substreams::scalar::BigInt, + } + impl TransferFrom { + const METHOD_ID: [u8; 4] = [35u8, 184u8, 114u8, 221u8]; + pub fn decode( + call: &substreams_ethereum::pb::eth::v2::Call, + ) -> Result { + let maybe_data = call.input.get(4..); + if maybe_data.is_none() { + return Err("no data to decode".to_string()); + } + let mut values = ethabi::decode( + &[ + ethabi::ParamType::Address, + ethabi::ParamType::Address, + ethabi::ParamType::Uint(256usize), + ], + maybe_data.unwrap(), + ) + .map_err(|e| format!("unable to decode call.input: {:?}", e))?; + values.reverse(); + Ok(Self { + src: values + .pop() + .expect(INTERNAL_ERR) + .into_address() + .expect(INTERNAL_ERR) + .as_bytes() + .to_vec(), + dst: values + .pop() + .expect(INTERNAL_ERR) + .into_address() + .expect(INTERNAL_ERR) + .as_bytes() + .to_vec(), + wad: { + let mut v = [0 as u8; 32]; + values + .pop() + .expect(INTERNAL_ERR) + .into_uint() + .expect(INTERNAL_ERR) + .to_big_endian(v.as_mut_slice()); + substreams::scalar::BigInt::from_unsigned_bytes_be(&v) + }, + }) + } + pub fn encode(&self) -> Vec { + let data = ethabi::encode( + &[ + ethabi::Token::Address(ethabi::Address::from_slice(&self.src)), + ethabi::Token::Address(ethabi::Address::from_slice(&self.dst)), + ethabi::Token::Uint( + ethabi::Uint::from_big_endian( + match self.wad.clone().to_bytes_be() { + (num_bigint::Sign::Plus, bytes) => bytes, + (num_bigint::Sign::NoSign, bytes) => bytes, + (num_bigint::Sign::Minus, _) => { + panic!("negative numbers are not supported") + } + } + .as_slice(), + ), + ), + ], + ); + let mut encoded = Vec::with_capacity(4 + data.len()); + encoded.extend(Self::METHOD_ID); + encoded.extend(data); + encoded + } + pub fn output_call( + call: &substreams_ethereum::pb::eth::v2::Call, + ) -> Result { + Self::output(call.return_data.as_ref()) + } + pub fn output(data: &[u8]) -> Result { + let mut values = ethabi::decode( + &[ethabi::ParamType::Bool], + data.as_ref(), + ) + .map_err(|e| format!("unable to decode output data: {:?}", e))?; + Ok( + values + .pop() + .expect("one output data should have existed") + .into_bool() + .expect(INTERNAL_ERR), + ) + } + pub fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { + match call.input.get(0..4) { + Some(signature) => Self::METHOD_ID == signature, + None => false, + } + } + pub fn call(&self, address: Vec) -> Option { + use substreams_ethereum::pb::eth::rpc; + let rpc_calls = rpc::RpcCalls { + calls: vec![ + rpc::RpcCall { to_addr : address, data : self.encode(), } + ], + }; + let responses = substreams_ethereum::rpc::eth_call(&rpc_calls).responses; + let response = responses + .get(0) + .expect("one response should have existed"); + if response.failed { + return None; + } + match Self::output(response.raw.as_ref()) { + Ok(data) => Some(data), + Err(err) => { + use substreams_ethereum::Function; + substreams::log::info!( + "Call output for function `{}` failed to decode with error: {}", + Self::NAME, err + ); + None + } + } + } + } + impl substreams_ethereum::Function for TransferFrom { + const NAME: &'static str = "transferFrom"; + fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { + Self::match_call(call) + } + fn decode( + call: &substreams_ethereum::pb::eth::v2::Call, + ) -> Result { + Self::decode(call) + } + fn encode(&self) -> Vec { + self.encode() + } + } + impl substreams_ethereum::rpc::RPCDecodable for TransferFrom { + fn output(data: &[u8]) -> Result { + Self::output(data) + } + } + #[derive(Debug, Clone, PartialEq)] + pub struct Withdraw { + pub wad: substreams::scalar::BigInt, + } + impl Withdraw { + const METHOD_ID: [u8; 4] = [46u8, 26u8, 125u8, 77u8]; + pub fn decode( + call: &substreams_ethereum::pb::eth::v2::Call, + ) -> Result { + let maybe_data = call.input.get(4..); + if maybe_data.is_none() { + return Err("no data to decode".to_string()); + } + let mut values = ethabi::decode( + &[ethabi::ParamType::Uint(256usize)], + maybe_data.unwrap(), + ) + .map_err(|e| format!("unable to decode call.input: {:?}", e))?; + values.reverse(); + Ok(Self { + wad: { + let mut v = [0 as u8; 32]; + values + .pop() + .expect(INTERNAL_ERR) + .into_uint() + .expect(INTERNAL_ERR) + .to_big_endian(v.as_mut_slice()); + substreams::scalar::BigInt::from_unsigned_bytes_be(&v) + }, + }) + } + pub fn encode(&self) -> Vec { + let data = ethabi::encode( + &[ + ethabi::Token::Uint( + ethabi::Uint::from_big_endian( + match self.wad.clone().to_bytes_be() { + (num_bigint::Sign::Plus, bytes) => bytes, + (num_bigint::Sign::NoSign, bytes) => bytes, + (num_bigint::Sign::Minus, _) => { + panic!("negative numbers are not supported") + } + } + .as_slice(), + ), + ), + ], + ); + let mut encoded = Vec::with_capacity(4 + data.len()); + encoded.extend(Self::METHOD_ID); + encoded.extend(data); + encoded + } + pub fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { + match call.input.get(0..4) { + Some(signature) => Self::METHOD_ID == signature, + None => false, + } + } + } + impl substreams_ethereum::Function for Withdraw { + const NAME: &'static str = "withdraw"; + fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { + Self::match_call(call) + } + fn decode( + call: &substreams_ethereum::pb::eth::v2::Call, + ) -> Result { + Self::decode(call) + } + fn encode(&self) -> Vec { + self.encode() + } } } - impl substreams_ethereum::Event for Withdrawal { - const NAME: &'static str = "Withdrawal"; - fn match_log(log: &substreams_ethereum::pb::eth::v2::Log) -> bool { - Self::match_log(log) + /// Contract's events. + #[allow(dead_code, unused_imports, unused_variables)] + pub mod events { + use super::INTERNAL_ERR; + #[derive(Debug, Clone, PartialEq)] + pub struct Approval { + pub src: Vec, + pub guy: Vec, + pub wad: substreams::scalar::BigInt, } - fn decode(log: &substreams_ethereum::pb::eth::v2::Log) -> Result { - Self::decode(log) + impl Approval { + const TOPIC_ID: [u8; 32] = [ + 140u8, + 91u8, + 225u8, + 229u8, + 235u8, + 236u8, + 125u8, + 91u8, + 209u8, + 79u8, + 113u8, + 66u8, + 125u8, + 30u8, + 132u8, + 243u8, + 221u8, + 3u8, + 20u8, + 192u8, + 247u8, + 178u8, + 41u8, + 30u8, + 91u8, + 32u8, + 10u8, + 200u8, + 199u8, + 195u8, + 185u8, + 37u8, + ]; + pub fn match_log(log: &substreams_ethereum::pb::eth::v2::Log) -> bool { + if log.topics.len() != 3usize { + return false; + } + if log.data.len() != 32usize { + return false; + } + return log.topics.get(0).expect("bounds already checked").as_ref() + == Self::TOPIC_ID; + } + pub fn decode( + log: &substreams_ethereum::pb::eth::v2::Log, + ) -> Result { + let mut values = ethabi::decode( + &[ethabi::ParamType::Uint(256usize)], + log.data.as_ref(), + ) + .map_err(|e| format!("unable to decode log.data: {:?}", e))?; + values.reverse(); + Ok(Self { + src: ethabi::decode( + &[ethabi::ParamType::Address], + log.topics[1usize].as_ref(), + ) + .map_err(|e| { + format!( + "unable to decode param 'src' from topic of type 'address': {:?}", + e + ) + })? + .pop() + .expect(INTERNAL_ERR) + .into_address() + .expect(INTERNAL_ERR) + .as_bytes() + .to_vec(), + guy: ethabi::decode( + &[ethabi::ParamType::Address], + log.topics[2usize].as_ref(), + ) + .map_err(|e| { + format!( + "unable to decode param 'guy' from topic of type 'address': {:?}", + e + ) + })? + .pop() + .expect(INTERNAL_ERR) + .into_address() + .expect(INTERNAL_ERR) + .as_bytes() + .to_vec(), + wad: { + let mut v = [0 as u8; 32]; + values + .pop() + .expect(INTERNAL_ERR) + .into_uint() + .expect(INTERNAL_ERR) + .to_big_endian(v.as_mut_slice()); + substreams::scalar::BigInt::from_unsigned_bytes_be(&v) + }, + }) + } } - } -} + impl substreams_ethereum::Event for Approval { + const NAME: &'static str = "Approval"; + fn match_log(log: &substreams_ethereum::pb::eth::v2::Log) -> bool { + Self::match_log(log) + } + fn decode( + log: &substreams_ethereum::pb::eth::v2::Log, + ) -> Result { + Self::decode(log) + } + } + #[derive(Debug, Clone, PartialEq)] + pub struct Deposit { + pub dst: Vec, + pub wad: substreams::scalar::BigInt, + } + impl Deposit { + const TOPIC_ID: [u8; 32] = [ + 225u8, + 255u8, + 252u8, + 196u8, + 146u8, + 61u8, + 4u8, + 181u8, + 89u8, + 244u8, + 210u8, + 154u8, + 139u8, + 252u8, + 108u8, + 218u8, + 4u8, + 235u8, + 91u8, + 13u8, + 60u8, + 70u8, + 7u8, + 81u8, + 194u8, + 64u8, + 44u8, + 92u8, + 92u8, + 201u8, + 16u8, + 156u8, + ]; + pub fn match_log(log: &substreams_ethereum::pb::eth::v2::Log) -> bool { + if log.topics.len() != 2usize { + return false; + } + if log.data.len() != 32usize { + return false; + } + return log.topics.get(0).expect("bounds already checked").as_ref() + == Self::TOPIC_ID; + } + pub fn decode( + log: &substreams_ethereum::pb::eth::v2::Log, + ) -> Result { + let mut values = ethabi::decode( + &[ethabi::ParamType::Uint(256usize)], + log.data.as_ref(), + ) + .map_err(|e| format!("unable to decode log.data: {:?}", e))?; + values.reverse(); + Ok(Self { + dst: ethabi::decode( + &[ethabi::ParamType::Address], + log.topics[1usize].as_ref(), + ) + .map_err(|e| { + format!( + "unable to decode param 'dst' from topic of type 'address': {:?}", + e + ) + })? + .pop() + .expect(INTERNAL_ERR) + .into_address() + .expect(INTERNAL_ERR) + .as_bytes() + .to_vec(), + wad: { + let mut v = [0 as u8; 32]; + values + .pop() + .expect(INTERNAL_ERR) + .into_uint() + .expect(INTERNAL_ERR) + .to_big_endian(v.as_mut_slice()); + substreams::scalar::BigInt::from_unsigned_bytes_be(&v) + }, + }) + } + } + impl substreams_ethereum::Event for Deposit { + const NAME: &'static str = "Deposit"; + fn match_log(log: &substreams_ethereum::pb::eth::v2::Log) -> bool { + Self::match_log(log) + } + fn decode( + log: &substreams_ethereum::pb::eth::v2::Log, + ) -> Result { + Self::decode(log) + } + } + #[derive(Debug, Clone, PartialEq)] + pub struct Transfer { + pub src: Vec, + pub dst: Vec, + pub wad: substreams::scalar::BigInt, + } + impl Transfer { + const TOPIC_ID: [u8; 32] = [ + 221u8, + 242u8, + 82u8, + 173u8, + 27u8, + 226u8, + 200u8, + 155u8, + 105u8, + 194u8, + 176u8, + 104u8, + 252u8, + 55u8, + 141u8, + 170u8, + 149u8, + 43u8, + 167u8, + 241u8, + 99u8, + 196u8, + 161u8, + 22u8, + 40u8, + 245u8, + 90u8, + 77u8, + 245u8, + 35u8, + 179u8, + 239u8, + ]; + pub fn match_log(log: &substreams_ethereum::pb::eth::v2::Log) -> bool { + if log.topics.len() != 3usize { + return false; + } + if log.data.len() != 32usize { + return false; + } + return log.topics.get(0).expect("bounds already checked").as_ref() + == Self::TOPIC_ID; + } + pub fn decode( + log: &substreams_ethereum::pb::eth::v2::Log, + ) -> Result { + let mut values = ethabi::decode( + &[ethabi::ParamType::Uint(256usize)], + log.data.as_ref(), + ) + .map_err(|e| format!("unable to decode log.data: {:?}", e))?; + values.reverse(); + Ok(Self { + src: ethabi::decode( + &[ethabi::ParamType::Address], + log.topics[1usize].as_ref(), + ) + .map_err(|e| { + format!( + "unable to decode param 'src' from topic of type 'address': {:?}", + e + ) + })? + .pop() + .expect(INTERNAL_ERR) + .into_address() + .expect(INTERNAL_ERR) + .as_bytes() + .to_vec(), + dst: ethabi::decode( + &[ethabi::ParamType::Address], + log.topics[2usize].as_ref(), + ) + .map_err(|e| { + format!( + "unable to decode param 'dst' from topic of type 'address': {:?}", + e + ) + })? + .pop() + .expect(INTERNAL_ERR) + .into_address() + .expect(INTERNAL_ERR) + .as_bytes() + .to_vec(), + wad: { + let mut v = [0 as u8; 32]; + values + .pop() + .expect(INTERNAL_ERR) + .into_uint() + .expect(INTERNAL_ERR) + .to_big_endian(v.as_mut_slice()); + substreams::scalar::BigInt::from_unsigned_bytes_be(&v) + }, + }) + } + } + impl substreams_ethereum::Event for Transfer { + const NAME: &'static str = "Transfer"; + fn match_log(log: &substreams_ethereum::pb::eth::v2::Log) -> bool { + Self::match_log(log) + } + fn decode( + log: &substreams_ethereum::pb::eth::v2::Log, + ) -> Result { + Self::decode(log) + } + } + #[derive(Debug, Clone, PartialEq)] + pub struct Withdrawal { + pub src: Vec, + pub wad: substreams::scalar::BigInt, + } + impl Withdrawal { + const TOPIC_ID: [u8; 32] = [ + 127u8, + 207u8, + 83u8, + 44u8, + 21u8, + 240u8, + 166u8, + 219u8, + 11u8, + 214u8, + 208u8, + 224u8, + 56u8, + 190u8, + 167u8, + 29u8, + 48u8, + 216u8, + 8u8, + 199u8, + 217u8, + 140u8, + 179u8, + 191u8, + 114u8, + 104u8, + 169u8, + 91u8, + 245u8, + 8u8, + 27u8, + 101u8, + ]; + pub fn match_log(log: &substreams_ethereum::pb::eth::v2::Log) -> bool { + if log.topics.len() != 2usize { + return false; + } + if log.data.len() != 32usize { + return false; + } + return log.topics.get(0).expect("bounds already checked").as_ref() + == Self::TOPIC_ID; + } + pub fn decode( + log: &substreams_ethereum::pb::eth::v2::Log, + ) -> Result { + let mut values = ethabi::decode( + &[ethabi::ParamType::Uint(256usize)], + log.data.as_ref(), + ) + .map_err(|e| format!("unable to decode log.data: {:?}", e))?; + values.reverse(); + Ok(Self { + src: ethabi::decode( + &[ethabi::ParamType::Address], + log.topics[1usize].as_ref(), + ) + .map_err(|e| { + format!( + "unable to decode param 'src' from topic of type 'address': {:?}", + e + ) + })? + .pop() + .expect(INTERNAL_ERR) + .into_address() + .expect(INTERNAL_ERR) + .as_bytes() + .to_vec(), + wad: { + let mut v = [0 as u8; 32]; + values + .pop() + .expect(INTERNAL_ERR) + .into_uint() + .expect(INTERNAL_ERR) + .to_big_endian(v.as_mut_slice()); + substreams::scalar::BigInt::from_unsigned_bytes_be(&v) + }, + }) + } + } + impl substreams_ethereum::Event for Withdrawal { + const NAME: &'static str = "Withdrawal"; + fn match_log(log: &substreams_ethereum::pb::eth::v2::Log) -> bool { + Self::match_log(log) + } + fn decode( + log: &substreams_ethereum::pb::eth::v2::Log, + ) -> Result { + Self::decode(log) + } + } + } \ No newline at end of file diff --git a/substreams/crates/tycho-substreams/src/attributes.rs b/substreams/crates/tycho-substreams/src/attributes.rs index 494f147..da4449e 100644 --- a/substreams/crates/tycho-substreams/src/attributes.rs +++ b/substreams/crates/tycho-substreams/src/attributes.rs @@ -24,7 +24,7 @@ pub fn json_serialize_address_list(addresses: &[Vec]) -> Vec { json_serialize_value( addresses .iter() - .map(|a| format!("0x{encoded}", encoded = hex::encode(a))) + .map(|a| format!("0x{}", hex::encode(a))) .collect::>(), ) } @@ -40,7 +40,7 @@ pub fn json_serialize_bigint_list(values: &[BigInt]) -> Vec { json_serialize_value( values .iter() - .map(|v| format!("0x{encoded}", encoded = hex::encode(v.to_signed_bytes_be()))) + .map(|v| format!("0x{}", hex::encode(v.to_signed_bytes_be()))) .collect::>(), ) } diff --git a/substreams/crates/tycho-substreams/src/balances.rs b/substreams/crates/tycho-substreams/src/balances.rs index bf1c36c..7e7f570 100644 --- a/substreams/crates/tycho-substreams/src/balances.rs +++ b/substreams/crates/tycho-substreams/src/balances.rs @@ -64,9 +64,12 @@ pub fn store_balance_changes(deltas: BlockBalanceDeltas, store: impl StoreAdd= current_ord { panic!( - "Invalid ordinal sequence for {balance_key}: {ord} >= {current_ord}", + "Invalid ordinal sequence for {}: {} >= {}", + balance_key, *ord, current_ord ); } *ord = current_ord; @@ -319,12 +323,17 @@ mod tests { } } fn store_deltas() -> StoreDeltas { - let comp_id = "0x42c0ffee".to_string(); + let comp_id = "0x42c0ffee" + .to_string() + .as_bytes() + .to_vec(); let token_0 = hex::decode("bad999").unwrap(); let token_1 = hex::decode("babe00").unwrap(); - let t0_key = format!("{comp_id}:{token}", token = hex::encode(token_0)); - let t1_key = format!("{comp_id}:{token}", token = hex::encode(token_1)); + let t0_key = + format!("{}:{}", String::from_utf8(comp_id.clone()).unwrap(), hex::encode(token_0)); + let t1_key = + format!("{}:{}", String::from_utf8(comp_id.clone()).unwrap(), hex::encode(token_1)); StoreDeltas { deltas: vec![ StoreDelta { @@ -385,15 +394,26 @@ mod tests { #[test] fn test_store_balances() { - let comp_id = "0x42c0ffee".to_string(); + let comp_id = "0x42c0ffee" + .to_string() + .as_bytes() + .to_vec(); let token_0 = hex::decode("bad999").unwrap(); let token_1 = hex::decode("babe00").unwrap(); let deltas = block_balance_deltas(); let store = ::new(); store_balance_changes(deltas, store.clone()); - let res_0 = store.get_last(format!("{comp_id}:{token}", token = hex::encode(token_0))); - let res_1 = store.get_last(format!("{comp_id}:{token}", token = hex::encode(token_1))); + let res_0 = store.get_last(format!( + "{}:{}", + String::from_utf8(comp_id.clone()).unwrap(), + hex::encode(token_0) + )); + let res_1 = store.get_last(format!( + "{}:{}", + String::from_utf8(comp_id.clone()).unwrap(), + hex::encode(token_1) + )); assert_eq!(res_0, Some(BigInt::from_str("+999").unwrap())); assert_eq!(res_1, Some(BigInt::from_str("+150").unwrap())); diff --git a/substreams/crates/tycho-substreams/src/models.rs b/substreams/crates/tycho-substreams/src/models.rs index 72bcccf..a99949c 100644 --- a/substreams/crates/tycho-substreams/src/models.rs +++ b/substreams/crates/tycho-substreams/src/models.rs @@ -238,7 +238,7 @@ impl ProtocolComponent { /// - `tx`: Reference to the associated transaction. pub fn at_contract(id: &[u8]) -> Self { Self { - id: format!("0x{encoded}", encoded = hex::encode(id)), + id: format!("0x{}", hex::encode(id)), tokens: Vec::new(), contracts: vec![id.to_vec()], static_att: Vec::new(), diff --git a/substreams/ethereum-ambient/src/modules/2_store_pool_balances.rs b/substreams/ethereum-ambient/src/modules/2_store_pool_balances.rs index 656a98b..1359199 100644 --- a/substreams/ethereum-ambient/src/modules/2_store_pool_balances.rs +++ b/substreams/ethereum-ambient/src/modules/2_store_pool_balances.rs @@ -11,7 +11,7 @@ pub fn store_pool_balances(changes: BlockPoolChanges, balance_store: StoreAddBig let pool_hash_hex = hex::encode(&balance_delta.pool_hash); balance_store.add( balance_delta.ordinal, - format!("{pool_hash_hex}:{type}", type = balance_delta.token_type), + format!("{}:{}", pool_hash_hex, balance_delta.token_type), BigInt::from_signed_bytes_be(&balance_delta.token_delta), ); } diff --git a/substreams/ethereum-ambient/src/modules/3_map_changes.rs b/substreams/ethereum-ambient/src/modules/3_map_changes.rs index d4adae6..8199e85 100644 --- a/substreams/ethereum-ambient/src/modules/3_map_changes.rs +++ b/substreams/ethereum-ambient/src/modules/3_map_changes.rs @@ -315,7 +315,7 @@ fn map_changes( let pool_hash_hex = hex::encode(balance_delta.pool_hash); let pool = match pool_store.get_last(pool_hash_hex.clone()) { Some(pool) => pool, - None => panic!("Pool not found in store for given hash: {pool_hash_hex}"), + None => panic!("Pool not found in store for given hash: {}", pool_hash_hex), }; let token_type = substreams::key::segment_at(&store_delta.key, 1); let token_index = if token_type == "quote" { 1 } else { 0 }; diff --git a/substreams/ethereum-balancer-v2/build.rs b/substreams/ethereum-balancer-v2/build.rs index c557d5b..5e7bd34 100644 --- a/substreams/ethereum-balancer-v2/build.rs +++ b/substreams/ethereum-balancer-v2/build.rs @@ -26,10 +26,10 @@ fn main() -> Result<()> { let contract_name = file_name.split('.').next().unwrap(); - let input_path = format!("{abi_folder}/{file_name}"); - let output_path = format!("{output_folder}/{contract_name}.rs"); + let input_path = format!("{}/{}", abi_folder, file_name); + let output_path = format!("{}/{}.rs", output_folder, contract_name); - mod_rs_content.push_str(&format!("pub mod {contract_name};\n")); + mod_rs_content.push_str(&format!("pub mod {};\n", contract_name)); if std::path::Path::new(&output_path).exists() { continue; @@ -40,7 +40,7 @@ fn main() -> Result<()> { .write_to_file(&output_path)?; } - let mod_rs_path = format!("{output_folder}/mod.rs"); + let mod_rs_path = format!("{}/mod.rs", output_folder); let mut mod_rs_file = fs::File::create(mod_rs_path)?; mod_rs_file.write_all(mod_rs_content.as_bytes())?; diff --git a/substreams/ethereum-balancer-v2/src/modules.rs b/substreams/ethereum-balancer-v2/src/modules.rs index 17711d5..d92b112 100644 --- a/substreams/ethereum-balancer-v2/src/modules.rs +++ b/substreams/ethereum-balancer-v2/src/modules.rs @@ -53,7 +53,7 @@ pub fn store_components(map: BlockTransactionProtocolComponents, store: StoreSet tx_pc .components .into_iter() - .for_each(|pc| store.set(0, format!("pool:{id}", id = &pc.id[..42]), &pc.id)) + .for_each(|pc| store.set(0, format!("pool:{0}", &pc.id[..42]), &pc.id)) }); } @@ -73,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{id}", id = hex::encode(ev.pool_id)); + let component_id = format!("0x{}", hex::encode(ev.pool_id)); if store - .get_last(format!("pool:{id}", id = &component_id[..42])) + .get_last(format!("pool:{}", &component_id[..42])) .is_some() { for (token, delta) in ev @@ -95,10 +95,10 @@ pub fn map_relative_balances( } } } else if let Some(ev) = abi::vault::events::Swap::match_and_decode(vault_log.log) { - let component_id = format!("0x{id}", id = hex::encode(ev.pool_id)); + let component_id = format!("0x{}", hex::encode(ev.pool_id)); if store - .get_last(format!("pool:{id}", id = &component_id[..42])) + .get_last(format!("pool:{}", &component_id[..42])) .is_some() { deltas.extend_from_slice(&[ @@ -121,9 +121,9 @@ pub fn map_relative_balances( } else if let Some(ev) = abi::vault::events::PoolBalanceManaged::match_and_decode(vault_log.log) { - let component_id = format!("0x{id}", id = hex::encode(ev.pool_id)); + let component_id = format!("0x{}", hex::encode(ev.pool_id)); if store - .get_last(format!("pool:{id}", id = &component_id[..42])) + .get_last(format!("pool:{}", &component_id[..42])) .is_some() { deltas.extend_from_slice(&[BalanceDelta { @@ -230,7 +230,7 @@ pub fn map_protocol_changes( &block, |addr| { components_store - .get_last(format!("pool:0x{id}", id = hex::encode(addr))) + .get_last(format!("pool:0x{0}", hex::encode(addr))) .is_some() || addr.eq(VAULT_ADDRESS) }, @@ -251,7 +251,7 @@ pub fn map_protocol_changes( if address != VAULT_ADDRESS { // We reconstruct the component_id from the address here let id = components_store - .get_last(format!("pool:0x{id}", id = hex::encode(address))) + .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); diff --git a/substreams/ethereum-curve/build.rs b/substreams/ethereum-curve/build.rs index 32574e6..2e7914f 100644 --- a/substreams/ethereum-curve/build.rs +++ b/substreams/ethereum-curve/build.rs @@ -26,10 +26,10 @@ fn main() -> Result<()> { let contract_name = file_name.split('.').next().unwrap(); - let input_path = format!("{abi_folder}/{file_name}"); - let output_path = format!("{output_folder}/{contract_name}.rs"); + let input_path = format!("{}/{}", abi_folder, file_name); + let output_path = format!("{}/{}.rs", output_folder, contract_name); - mod_rs_content.push_str(&format!("pub mod {contract_name};\n")); + mod_rs_content.push_str(&format!("pub mod {};\n", contract_name)); if std::path::Path::new(&output_path).exists() { continue; @@ -40,7 +40,7 @@ fn main() -> Result<()> { .write_to_file(&output_path)?; } - let mod_rs_path = format!("{output_folder}/mod.rs"); + let mod_rs_path = format!("{}/mod.rs", output_folder); let mut mod_rs_file = fs::File::create(mod_rs_path)?; mod_rs_file.write_all(mod_rs_content.as_bytes())?; diff --git a/substreams/ethereum-curve/src/pool_factories.rs b/substreams/ethereum-curve/src/pool_factories.rs index 0588ed8..721fcf6 100644 --- a/substreams/ethereum-curve/src/pool_factories.rs +++ b/substreams/ethereum-curve/src/pool_factories.rs @@ -39,7 +39,7 @@ fn address_to_bytes_with_0x(address: &[u8; 20]) -> Vec { /// Converts address bytes into a string containing a leading `0x`. fn address_to_string_with_0x(address: &[u8]) -> String { - format!("0x{encoded}", encoded = hex::encode(address)) + format!("0x{}", hex::encode(address)) } /// Function that swaps `WETH` addresses for `ETH` address for specific factory types that decide @@ -499,8 +499,8 @@ pub fn address_map( name: "stateless_contract_addr_0".into(), // Call views_implementation() on CRYPTO_SWAP_NG_FACTORY value: format!( - "call:0x{factory}:views_implementation()", - factory = hex::encode(CRYPTO_SWAP_NG_FACTORY) + "call:0x{}:views_implementation()", + hex::encode(CRYPTO_SWAP_NG_FACTORY) ) .into(), change: ChangeType::Creation.into(), @@ -579,8 +579,8 @@ pub fn address_map( name: "stateless_contract_addr_0".into(), // Call views_implementation() on CRYPTO_SWAP_NG_FACTORY value: format!( - "call:0x{factory}:views_implementation()", - factory = hex::encode(CRYPTO_SWAP_NG_FACTORY) + "call:0x{}:views_implementation()", + hex::encode(CRYPTO_SWAP_NG_FACTORY) ) .into(), change: ChangeType::Creation.into(), @@ -589,8 +589,8 @@ pub fn address_map( name: "stateless_contract_addr_1".into(), // Call math_implementation() on CRYPTO_SWAP_NG_FACTORY value: format!( - "call:0x{factory}:math_implementation()", - factory = hex::encode(CRYPTO_SWAP_NG_FACTORY) + "call:0x{}:math_implementation()", + hex::encode(CRYPTO_SWAP_NG_FACTORY) ) .into(), change: ChangeType::Creation.into(), @@ -651,14 +651,14 @@ pub fn address_map( }), }, vec![EntityChanges { - component_id: format!("0x{id}"), + component_id: format!("0x{}", id), attributes: vec![ Attribute { name: "stateless_contract_addr_0".into(), // Call views_implementation() on TRICRYPTO_FACTORY value: format!( - "call:0x{factory}:views_implementation()", - factory = hex::encode(TRICRYPTO_FACTORY) + "call:0x{}:views_implementation()", + hex::encode(TRICRYPTO_FACTORY) ) .into(), change: ChangeType::Creation.into(), @@ -667,8 +667,8 @@ pub fn address_map( name: "stateless_contract_addr_1".into(), // Call math_implementation() on TRICRYPTO_FACTORY value: format!( - "call:0x{factory}:math_implementation()", - factory = hex::encode(TRICRYPTO_FACTORY) + "call:0x{}:math_implementation()", + hex::encode(TRICRYPTO_FACTORY) ) .into(), change: ChangeType::Creation.into(), @@ -907,14 +907,14 @@ pub fn address_map( }), }, vec![EntityChanges { - component_id: format!("0x{id}"), + component_id: format!("0x{}", id), attributes: vec![ Attribute { name: "stateless_contract_addr_0".into(), // Call views_implementation() on TWOCRYPTO_FACTORY value: format!( - "call:0x{factory}:views_implementation()", - factory = hex::encode(TWOCRYPTO_FACTORY) + "call:0x{}:views_implementation()", + hex::encode(TWOCRYPTO_FACTORY) ) .into(), change: ChangeType::Creation.into(), diff --git a/substreams/ethereum-curve/src/pools.rs b/substreams/ethereum-curve/src/pools.rs index 1ba78a4..a8ca576 100644 --- a/substreams/ethereum-curve/src/pools.rs +++ b/substreams/ethereum-curve/src/pools.rs @@ -99,7 +99,7 @@ fn create_component( }), }, vec![EntityChanges { - component_id: format!("0x{pool_address}", pool_address = pool.address.clone()), + component_id: format!("0x{}", pool.address.clone()), attributes: zip( pool.attribute_keys .clone() @@ -127,7 +127,7 @@ fn parse_params(params: &str) -> Result, anyhow .split(PARAMS_SEPERATOR) .map(|param| { let pool: PoolQueryParams = serde_qs::from_str(param) - .with_context(|| format!("Failed to parse pool query params: {param}"))?; + .with_context(|| format!("Failed to parse pool query params: {0}", param))?; Ok((pool.tx_hash.clone(), pool)) }) .collect::>>() diff --git a/substreams/ethereum-ekubo-v2/build.rs b/substreams/ethereum-ekubo-v2/build.rs index c557d5b..5e7bd34 100644 --- a/substreams/ethereum-ekubo-v2/build.rs +++ b/substreams/ethereum-ekubo-v2/build.rs @@ -26,10 +26,10 @@ fn main() -> Result<()> { let contract_name = file_name.split('.').next().unwrap(); - let input_path = format!("{abi_folder}/{file_name}"); - let output_path = format!("{output_folder}/{contract_name}.rs"); + let input_path = format!("{}/{}", abi_folder, file_name); + let output_path = format!("{}/{}.rs", output_folder, contract_name); - mod_rs_content.push_str(&format!("pub mod {contract_name};\n")); + mod_rs_content.push_str(&format!("pub mod {};\n", contract_name)); if std::path::Path::new(&output_path).exists() { continue; @@ -40,7 +40,7 @@ fn main() -> Result<()> { .write_to_file(&output_path)?; } - let mod_rs_path = format!("{output_folder}/mod.rs"); + let mod_rs_path = format!("{}/mod.rs", output_folder); let mut mod_rs_file = fs::File::create(mod_rs_path)?; mod_rs_file.write_all(mod_rs_content.as_bytes())?; diff --git a/substreams/ethereum-pancakeswap-v3/src/modules/2_store_pools.rs b/substreams/ethereum-pancakeswap-v3/src/modules/2_store_pools.rs index c531a7d..e3b432e 100644 --- a/substreams/ethereum-pancakeswap-v3/src/modules/2_store_pools.rs +++ b/substreams/ethereum-pancakeswap-v3/src/modules/2_store_pools.rs @@ -30,7 +30,7 @@ pub fn store_pools(pools_created: BlockChanges, store: StoreSetIfNotExistsProto< ) .to_u64(), }; - store.set_if_not_exists(0, format!("Pool:{pool_address}"), &pool); + store.set_if_not_exists(0, format!("{}:{}", "Pool", pool_address), &pool); } } } diff --git a/substreams/ethereum-pancakeswap-v3/src/modules/3_map_events.rs b/substreams/ethereum-pancakeswap-v3/src/modules/3_map_events.rs index 5028031..7d573a9 100644 --- a/substreams/ethereum-pancakeswap-v3/src/modules/3_map_events.rs +++ b/substreams/ethereum-pancakeswap-v3/src/modules/3_map_events.rs @@ -41,7 +41,7 @@ pub fn map_events( .logs .iter() .filter_map(|log| { - let key = format!("Pool:{address}", address = log.address.to_hex()); + let key = format!("{}:{}", "Pool", log.address.to_hex()); // Skip if the log is not from a known pool. if let Some(pool) = pools_store.get_last(key) { log_to_event(log, pool, &tx) diff --git a/substreams/ethereum-pancakeswap-v3/src/modules/4_map_and_store_balance_changes.rs b/substreams/ethereum-pancakeswap-v3/src/modules/4_map_and_store_balance_changes.rs index 4ad8d71..b8787dd 100644 --- a/substreams/ethereum-pancakeswap-v3/src/modules/4_map_and_store_balance_changes.rs +++ b/substreams/ethereum-pancakeswap-v3/src/modules/4_map_and_store_balance_changes.rs @@ -29,7 +29,7 @@ pub fn store_pools_balances(balances_deltas: BlockBalanceDeltas, store: StoreAdd } fn event_to_balance_deltas(event: PoolEvent) -> Vec { - let address = format!("0x{addr}", addr = event.pool_address) + let address = format!("0x{}", event.pool_address) .as_bytes() .to_vec(); match event.r#type.unwrap() { diff --git a/substreams/ethereum-pancakeswap-v3/src/modules/4_map_and_store_liquidity.rs b/substreams/ethereum-pancakeswap-v3/src/modules/4_map_and_store_liquidity.rs index db4f939..d1e7bfe 100644 --- a/substreams/ethereum-pancakeswap-v3/src/modules/4_map_and_store_liquidity.rs +++ b/substreams/ethereum-pancakeswap-v3/src/modules/4_map_and_store_liquidity.rs @@ -20,7 +20,7 @@ pub fn store_pool_current_tick(events: Events, store: StoreSetInt64) { .into_iter() .filter_map(event_to_current_tick) .for_each(|(pool, ordinal, new_tick_index)| { - store.set(ordinal, format!("pool:{pool}"), &new_tick_index.into()) + store.set(ordinal, format!("pool:{0}", pool), &new_tick_index.into()) }); } @@ -36,7 +36,7 @@ pub fn map_liquidity_changes( .map(|e| { ( pools_current_tick_store - .get_at(e.log_ordinal, format!("pool:{pool_addr}", pool_addr = &e.pool_address)) + .get_at(e.log_ordinal, format!("pool:{0}", &e.pool_address)) .unwrap_or(0), e, ) @@ -57,14 +57,14 @@ pub fn store_liquidity(ticks_deltas: LiquidityChanges, store: StoreSetSumBigInt) LiquidityChangeType::Delta => { store.sum( changes.ordinal, - format!("pool:{addr}", addr = hex::encode(&changes.pool_address)), + format!("pool:{0}", hex::encode(&changes.pool_address)), BigInt::from_signed_bytes_be(&changes.value), ); } LiquidityChangeType::Absolute => { store.set( changes.ordinal, - format!("pool:{addr}", addr = hex::encode(&changes.pool_address)), + format!("pool:{0}", hex::encode(&changes.pool_address)), BigInt::from_signed_bytes_be(&changes.value), ); } diff --git a/substreams/ethereum-pancakeswap-v3/src/modules/4_map_and_store_ticks.rs b/substreams/ethereum-pancakeswap-v3/src/modules/4_map_and_store_ticks.rs index 826f280..6b48be8 100644 --- a/substreams/ethereum-pancakeswap-v3/src/modules/4_map_and_store_ticks.rs +++ b/substreams/ethereum-pancakeswap-v3/src/modules/4_map_and_store_ticks.rs @@ -34,11 +34,7 @@ pub fn store_ticks_liquidity(ticks_deltas: TickDeltas, store: StoreAddBigInt) { deltas.iter().for_each(|delta| { store.add( delta.ordinal, - format!( - "pool:{addr}:tick:{index}", - addr = hex::encode(&delta.pool_address), - index = delta.tick_index, - ), + format!("pool:{0}:tick:{1}", hex::encode(&delta.pool_address), delta.tick_index,), BigInt::from_signed_bytes_be(&delta.liquidity_net_delta), ); }); diff --git a/substreams/ethereum-pancakeswap-v3/src/modules/5_map_protocol_changes.rs b/substreams/ethereum-pancakeswap-v3/src/modules/5_map_protocol_changes.rs index 3fdf3d2..0e3eebf 100644 --- a/substreams/ethereum-pancakeswap-v3/src/modules/5_map_protocol_changes.rs +++ b/substreams/ethereum-pancakeswap-v3/src/modules/5_map_protocol_changes.rs @@ -86,8 +86,7 @@ pub fn map_protocol_changes( BigInt::from_str(&String::from_utf8(store_delta.old_value).unwrap()) .unwrap() .is_zero(); - let attribute_name = - format!("ticks/{index}/net-liquidity", index = tick_delta.tick_index); + let attribute_name = format!("ticks/{}/net-liquidity", tick_delta.tick_index); let attribute = Attribute { name: attribute_name, value: new_value_bigint.to_signed_bytes_be(), diff --git a/substreams/ethereum-sfrax/src/modules.rs b/substreams/ethereum-sfrax/src/modules.rs index cb86516..3812e10 100644 --- a/substreams/ethereum-sfrax/src/modules.rs +++ b/substreams/ethereum-sfrax/src/modules.rs @@ -85,9 +85,9 @@ pub fn map_relative_balances( abi::stakedfrax_contract::events::Withdraw::match_and_decode(vault_log.log) { let address_bytes_be = vault_log.address(); - let address_hex = format!("0x{encoded}", encoded = hex::encode(address_bytes_be)); + let address_hex = format!("0x{}", hex::encode(address_bytes_be)); if store - .get_last(format!("pool:{address_hex}")) + .get_last(format!("pool:{}", address_hex)) .is_some() { deltas.extend_from_slice(&[ @@ -119,10 +119,10 @@ pub fn map_relative_balances( abi::stakedfrax_contract::events::Deposit::match_and_decode(vault_log.log) { let address_bytes_be = vault_log.address(); - let address_hex = format!("0x{encoded}", encoded = hex::encode(address_bytes_be)); + let address_hex = format!("0x{}", hex::encode(address_bytes_be)); if store - .get_last(format!("pool:{address_hex}")) + .get_last(format!("pool:{}", address_hex)) .is_some() { deltas.extend_from_slice(&[ @@ -154,10 +154,10 @@ pub fn map_relative_balances( abi::stakedfrax_contract::events::DistributeRewards::match_and_decode(vault_log.log) { let address_bytes_be = vault_log.address(); - let address_hex = format!("0x{encoded}", encoded = hex::encode(address_bytes_be)); + let address_hex = format!("0x{}", hex::encode(address_bytes_be)); if store - .get_last(format!("pool:{address_hex}")) + .get_last(format!("pool:{}", address_hex)) .is_some() { deltas.extend_from_slice(&[BalanceDelta { @@ -231,7 +231,7 @@ pub fn map_protocol_changes( &block, |addr| { components_store - .get_last(format!("pool:0x{encoded}", encoded = hex::encode(addr))) + .get_last(format!("pool:0x{0}", hex::encode(addr))) .is_some() }, &mut transaction_contract, diff --git a/substreams/ethereum-sfraxeth/src/modules.rs b/substreams/ethereum-sfraxeth/src/modules.rs index 3303760..dee48c0 100644 --- a/substreams/ethereum-sfraxeth/src/modules.rs +++ b/substreams/ethereum-sfraxeth/src/modules.rs @@ -117,11 +117,10 @@ pub fn store_reward_cycles(block_reward_cycles: BlockRewardCycles, store: StoreS .reward_cycles .into_iter() .for_each(|reward_cycle| { - let address_hex = - format!("0x{encoded}", encoded = hex::encode(&reward_cycle.vault_address)); + let address_hex = format!("0x{}", hex::encode(&reward_cycle.vault_address)); store.set( reward_cycle.ord, - format!("reward_cycle:{address_hex}"), + format!("reward_cycle:{}", address_hex), &reward_cycle.next_reward_amount, ); }); @@ -142,10 +141,10 @@ pub fn map_relative_balances( abi::sfraxeth_contract::events::Withdraw::match_and_decode(vault_log.log) { let address_bytes_be = vault_log.address(); - let address_hex = format!("0x{encoded}", encoded = hex::encode(address_bytes_be)); + let address_hex = format!("0x{}", hex::encode(address_bytes_be)); if store - .get_last(format!("pool:{address_hex}")) + .get_last(format!("pool:{}", address_hex)) .is_some() { substreams::log::info!( @@ -176,9 +175,9 @@ pub fn map_relative_balances( abi::sfraxeth_contract::events::Deposit::match_and_decode(vault_log.log) { let address_bytes_be = vault_log.address(); - let address_hex = format!("0x{encoded}", encoded = hex::encode(address_bytes_be)); + let address_hex = format!("0x{}", hex::encode(address_bytes_be)); if store - .get_last(format!("pool:{address_hex}")) + .get_last(format!("pool:{}", address_hex)) .is_some() { deltas.extend_from_slice(&[ @@ -205,9 +204,9 @@ pub fn map_relative_balances( .is_some() { let address_bytes_be = vault_log.address(); - let address_hex = format!("0x{encoded}", encoded = hex::encode(address_bytes_be)); + let address_hex = format!("0x{}", hex::encode(address_bytes_be)); if store - .get_last(format!("pool:{address_hex}")) + .get_last(format!("pool:{}", address_hex)) .is_some() { // When the NextRewardsCycle event is emitted: @@ -222,12 +221,13 @@ pub fn map_relative_balances( if let Some(last_reward_amount) = reward_store .deltas .iter() - .find(|el| el.key == format!("reward_cycle:{address_hex}")) + .find(|el| el.key == format!("reward_cycle:{}", address_hex)) .map(|el| el.old_value.clone()) { substreams::log::info!( - "Reward cycle balance change: address {address_hex}, sfraxEth amount {amount}", - amount = BigInt::from_signed_bytes_be(&last_reward_amount) + "Reward cycle balance change: address {}, sfraxEth amount {}", + address_hex, + BigInt::from_signed_bytes_be(&last_reward_amount) ); deltas.push(BalanceDelta { ord: vault_log.ordinal(), @@ -319,7 +319,7 @@ pub fn map_protocol_changes( &block, |addr| { components_store - .get_last(format!("pool:0x{encoded}", encoded = hex::encode(addr))) + .get_last(format!("pool:0x{0}", hex::encode(addr))) .is_some() }, &mut transaction_changes, diff --git a/substreams/ethereum-template-factory/build.rs b/substreams/ethereum-template-factory/build.rs index c557d5b..5e7bd34 100644 --- a/substreams/ethereum-template-factory/build.rs +++ b/substreams/ethereum-template-factory/build.rs @@ -26,10 +26,10 @@ fn main() -> Result<()> { let contract_name = file_name.split('.').next().unwrap(); - let input_path = format!("{abi_folder}/{file_name}"); - let output_path = format!("{output_folder}/{contract_name}.rs"); + let input_path = format!("{}/{}", abi_folder, file_name); + let output_path = format!("{}/{}.rs", output_folder, contract_name); - mod_rs_content.push_str(&format!("pub mod {contract_name};\n")); + mod_rs_content.push_str(&format!("pub mod {};\n", contract_name)); if std::path::Path::new(&output_path).exists() { continue; @@ -40,7 +40,7 @@ fn main() -> Result<()> { .write_to_file(&output_path)?; } - let mod_rs_path = format!("{output_folder}/mod.rs"); + let mod_rs_path = format!("{}/mod.rs", output_folder); let mut mod_rs_file = fs::File::create(mod_rs_path)?; mod_rs_file.write_all(mod_rs_content.as_bytes())?; diff --git a/substreams/ethereum-template-singleton/build.rs b/substreams/ethereum-template-singleton/build.rs index c557d5b..5e7bd34 100644 --- a/substreams/ethereum-template-singleton/build.rs +++ b/substreams/ethereum-template-singleton/build.rs @@ -26,10 +26,10 @@ fn main() -> Result<()> { let contract_name = file_name.split('.').next().unwrap(); - let input_path = format!("{abi_folder}/{file_name}"); - let output_path = format!("{output_folder}/{contract_name}.rs"); + let input_path = format!("{}/{}", abi_folder, file_name); + let output_path = format!("{}/{}.rs", output_folder, contract_name); - mod_rs_content.push_str(&format!("pub mod {contract_name};\n")); + mod_rs_content.push_str(&format!("pub mod {};\n", contract_name)); if std::path::Path::new(&output_path).exists() { continue; @@ -40,7 +40,7 @@ fn main() -> Result<()> { .write_to_file(&output_path)?; } - let mod_rs_path = format!("{output_folder}/mod.rs"); + let mod_rs_path = format!("{}/mod.rs", output_folder); let mut mod_rs_file = fs::File::create(mod_rs_path)?; mod_rs_file.write_all(mod_rs_content.as_bytes())?; diff --git a/substreams/ethereum-uniswap-v2/src/modules/3_map_pool_events.rs b/substreams/ethereum-uniswap-v2/src/modules/3_map_pool_events.rs index a3ba041..8584913 100644 --- a/substreams/ethereum-uniswap-v2/src/modules/3_map_pool_events.rs +++ b/substreams/ethereum-uniswap-v2/src/modules/3_map_pool_events.rs @@ -95,7 +95,7 @@ fn handle_sync( }); for (i, reserve_bytes) in reserves_bytes.iter().enumerate() { - let attribute_name = format!("reserve{i}"); + let attribute_name = format!("reserve{}", i); // By using a HashMap, we can overwrite the previous value of the reserve attribute if // it is for the same pool and the same attribute name (reserves). tx_change.entity_changes.insert( diff --git a/substreams/ethereum-uniswap-v2/src/store_key.rs b/substreams/ethereum-uniswap-v2/src/store_key.rs index 701470c..f4ea140 100644 --- a/substreams/ethereum-uniswap-v2/src/store_key.rs +++ b/substreams/ethereum-uniswap-v2/src/store_key.rs @@ -5,7 +5,7 @@ pub enum StoreKey { impl StoreKey { pub fn get_unique_pool_key(&self, key: &str) -> String { - format!("{prefix}:{key}", prefix = self.unique_id()) + format!("{}:{}", self.unique_id(), key) } pub fn unique_id(&self) -> String { diff --git a/substreams/ethereum-uniswap-v3-logs-only/src/modules/2_store_pools.rs b/substreams/ethereum-uniswap-v3-logs-only/src/modules/2_store_pools.rs index eecf7ed..fa769d4 100644 --- a/substreams/ethereum-uniswap-v3-logs-only/src/modules/2_store_pools.rs +++ b/substreams/ethereum-uniswap-v3-logs-only/src/modules/2_store_pools.rs @@ -18,7 +18,7 @@ pub fn store_pools(pools_created: BlockEntityChanges, store: StoreSetIfNotExists token1: component_change.tokens[1].clone(), created_tx_hash: change.tx.as_ref().unwrap().hash.clone(), }; - store.set_if_not_exists(0, format!("Pool:{pool_address}"), &pool); + store.set_if_not_exists(0, format!("{}:{}", "Pool", pool_address), &pool); } } } diff --git a/substreams/ethereum-uniswap-v3-logs-only/src/modules/3_map_events.rs b/substreams/ethereum-uniswap-v3-logs-only/src/modules/3_map_events.rs index 584f19d..9ed264b 100644 --- a/substreams/ethereum-uniswap-v3-logs-only/src/modules/3_map_events.rs +++ b/substreams/ethereum-uniswap-v3-logs-only/src/modules/3_map_events.rs @@ -41,7 +41,7 @@ pub fn map_events( .logs .iter() .filter_map(|log| { - let key = format!("Pool:{address}", address = log.address.to_hex()); + let key = format!("{}:{}", "Pool", log.address.to_hex()); // Skip if the log is not from a known uniswapV3 pool. if let Some(pool) = pools_store.get_last(key) { log_to_event(log, pool, &tx) diff --git a/substreams/ethereum-uniswap-v3-logs-only/src/modules/4_map_and_store_liquidity.rs b/substreams/ethereum-uniswap-v3-logs-only/src/modules/4_map_and_store_liquidity.rs index 7fb7265..b7e6a30 100644 --- a/substreams/ethereum-uniswap-v3-logs-only/src/modules/4_map_and_store_liquidity.rs +++ b/substreams/ethereum-uniswap-v3-logs-only/src/modules/4_map_and_store_liquidity.rs @@ -20,7 +20,7 @@ pub fn store_pool_current_tick(events: Events, store: StoreSetInt64) { .into_iter() .filter_map(event_to_current_tick) .for_each(|(pool, ordinal, new_tick_index)| { - store.set(ordinal, format!("pool:{pool}"), &new_tick_index.into()) + store.set(ordinal, format!("pool:{0}", pool), &new_tick_index.into()) }); } diff --git a/substreams/ethereum-uniswap-v3/src/modules/2_store_pools.rs b/substreams/ethereum-uniswap-v3/src/modules/2_store_pools.rs index 223c0d5..f4bafff 100644 --- a/substreams/ethereum-uniswap-v3/src/modules/2_store_pools.rs +++ b/substreams/ethereum-uniswap-v3/src/modules/2_store_pools.rs @@ -19,7 +19,7 @@ pub fn store_pools(pools_created: BlockChanges, store: StoreSetIfNotExistsProto< token1: component_change.tokens[1].clone(), created_tx_hash: change.tx.as_ref().unwrap().hash.clone(), }; - store.set_if_not_exists(0, format!("Pool:{pool_address}"), &pool); + store.set_if_not_exists(0, format!("{}:{}", "Pool", pool_address), &pool); } } } diff --git a/substreams/ethereum-uniswap-v3/src/modules/3_map_balance_changes.rs b/substreams/ethereum-uniswap-v3/src/modules/3_map_balance_changes.rs index d06eae5..4d888bb 100644 --- a/substreams/ethereum-uniswap-v3/src/modules/3_map_balance_changes.rs +++ b/substreams/ethereum-uniswap-v3/src/modules/3_map_balance_changes.rs @@ -24,7 +24,7 @@ pub fn map_balance_changes( { // Skip if the log is not from a known uniswapV3 pool. if let Some(pool) = - pools_store.get_last(format!("Pool:{address}", address = &log.address.to_hex())) + pools_store.get_last(format!("{}:{}", "Pool", &log.address.to_hex())) { tx_deltas.extend(get_log_changed_balances(log, &pool)) } else { diff --git a/substreams/ethereum-uniswap-v3/src/modules/5_map_pool_events.rs b/substreams/ethereum-uniswap-v3/src/modules/5_map_pool_events.rs index e2f7b3d..32cee7f 100644 --- a/substreams/ethereum-uniswap-v3/src/modules/5_map_pool_events.rs +++ b/substreams/ethereum-uniswap-v3/src/modules/5_map_pool_events.rs @@ -38,7 +38,7 @@ pub fn map_pool_events( for (log, call_view) in trx.logs_with_calls() { // Skip if the log is not from a known uniswapV3 pool. if let Some(pool) = - pools_store.get_last(format!("Pool:{address}", address = &log.address.to_hex())) + pools_store.get_last(format!("{}:{}", "Pool", &log.address.to_hex())) { let changed_attributes = get_log_changed_attributes( log, diff --git a/substreams/ethereum-uniswap-v3/src/storage/pool_storage.rs b/substreams/ethereum-uniswap-v3/src/storage/pool_storage.rs index ded7821..5569ef5 100644 --- a/substreams/ethereum-uniswap-v3/src/storage/pool_storage.rs +++ b/substreams/ethereum-uniswap-v3/src/storage/pool_storage.rs @@ -108,7 +108,7 @@ impl<'a> UniswapPoolStorage<'a> { // We need this to keep the references to the names alive until we call // `get_changed_attributes()` for tick_idx in ticks_idx.iter() { - tick_names.push(format!("ticks/{tick_idx}/net-liquidity")); + tick_names.push(format!("ticks/{}/net-liquidity", tick_idx)); } // Then, iterate over ticks_idx and tick_names simultaneously diff --git a/substreams/ethereum-uniswap-v3/src/storage/utils.rs b/substreams/ethereum-uniswap-v3/src/storage/utils.rs index 47e1eaa..827bd8e 100644 --- a/substreams/ethereum-uniswap-v3/src/storage/utils.rs +++ b/substreams/ethereum-uniswap-v3/src/storage/utils.rs @@ -32,18 +32,30 @@ pub fn left_pad(input: &[u8], padding_value: u8) -> [u8; 32] { pub fn read_bytes(buf: &[u8], offset: usize, number_of_bytes: usize) -> &[u8] { let buf_length = buf.len(); if buf_length < number_of_bytes { - panic!("attempting to read {number_of_bytes} bytes in buffer size {buf_length}",) + panic!( + "attempting to read {number_of_bytes} bytes in buffer size {buf_size}", + number_of_bytes = number_of_bytes, + buf_size = buf.len() + ) } if offset > (buf_length - 1) { - panic!("offset {offset} exceeds buffer size {buf_length}") + panic!( + "offset {offset} exceeds buffer size {buf_size}", + offset = offset, + buf_size = buf.len() + ) } let end = buf_length - 1 - offset; let start_opt = (end + 1).checked_sub(number_of_bytes); if start_opt.is_none() { panic!( - "number of bytes {number_of_bytes} with offset {offset} exceeds buffer size {buf_length}" + "number of bytes {number_of_bytes} with offset {offset} exceeds buffer size +{buf_size}", + number_of_bytes = number_of_bytes, + offset = offset, + buf_size = buf.len() ) } let start = start_opt.unwrap(); @@ -146,7 +158,7 @@ mod tests { fn encode_hex(bytes: &[u8]) -> String { let mut s = String::with_capacity(bytes.len() * 2); for &b in bytes { - write!(&mut s, "{b:02x}").unwrap(); + write!(&mut s, "{:02x}", b).unwrap(); } s } diff --git a/substreams/ethereum-uniswap-v4/src/modules/2_store_pools.rs b/substreams/ethereum-uniswap-v4/src/modules/2_store_pools.rs index a91d96a..27c972b 100644 --- a/substreams/ethereum-uniswap-v4/src/modules/2_store_pools.rs +++ b/substreams/ethereum-uniswap-v4/src/modules/2_store_pools.rs @@ -18,7 +18,7 @@ pub fn store_pools(pools_created: BlockEntityChanges, store: StoreSetIfNotExists currency1: component_change.tokens[1].clone(), created_tx_hash: change.tx.as_ref().unwrap().hash.clone(), }; - store.set_if_not_exists(0, format!("pool:{pool_address}"), &pool); + store.set_if_not_exists(0, format!("{}:{}", "pool", pool_address), &pool); } } } diff --git a/substreams/ethereum-uniswap-v4/src/modules/3_map_events.rs b/substreams/ethereum-uniswap-v4/src/modules/3_map_events.rs index 255830d..63c5b02 100644 --- a/substreams/ethereum-uniswap-v4/src/modules/3_map_events.rs +++ b/substreams/ethereum-uniswap-v4/src/modules/3_map_events.rs @@ -50,7 +50,7 @@ fn log_to_event( // We need to track initialization again to keep track of pool current tick, which is set on // initialization and changed on swaps. let pool_id = init.id.to_vec().to_hex(); - let pool = pools_store.get_last(format!("pool:{pool_id}"))?; + let pool = pools_store.get_last(format!("{}:{}", "pool", &pool_id))?; Some(PoolEvent { log_ordinal: event.ordinal, pool_id, @@ -67,7 +67,7 @@ fn log_to_event( }) } else if let Some(swap) = Swap::match_and_decode(event) { let pool_id = swap.id.to_vec().to_hex(); - let pool = pools_store.get_last(format!("pool:{pool_id}"))?; + let pool = pools_store.get_last(format!("{}:{}", "pool", &pool_id))?; Some(PoolEvent { log_ordinal: event.ordinal, pool_id, @@ -102,7 +102,7 @@ fn log_to_event( // }) } else if let Some(modify_liquidity) = ModifyLiquidity::match_and_decode(event) { let pool_id = modify_liquidity.id.to_vec().to_hex(); - let pool = pools_store.get_last(format!("pool:{pool_id}"))?; + let pool = pools_store.get_last(format!("{}:{}", "pool", &pool_id))?; Some(PoolEvent { log_ordinal: event.ordinal, pool_id, @@ -124,7 +124,7 @@ fn log_to_event( .id .to_vec() .to_hex(); - let pool = pools_store.get_last(format!("pool:{pool_id}"))?; + let pool = pools_store.get_last(format!("{}:{}", "pool", &pool_id))?; Some(PoolEvent { log_ordinal: event.ordinal, pool_id: pool_id.clone(), diff --git a/substreams/ethereum-uniswap-v4/src/modules/4_store_current_sqrtprice.rs b/substreams/ethereum-uniswap-v4/src/modules/4_store_current_sqrtprice.rs index b6aa2cd..9add61c 100644 --- a/substreams/ethereum-uniswap-v4/src/modules/4_store_current_sqrtprice.rs +++ b/substreams/ethereum-uniswap-v4/src/modules/4_store_current_sqrtprice.rs @@ -17,7 +17,7 @@ pub fn store_pool_current_sqrt_price(events: Events, store: StoreSetBigInt) { .into_iter() .filter_map(event_to_current_sqrt_price) .for_each(|(pool, ordinal, new_tick_index)| { - store.set(ordinal, format!("pool:{pool}"), &new_tick_index) + store.set(ordinal, format!("pool:{0}", pool), &new_tick_index) }); } diff --git a/substreams/ethereum-uniswap-v4/src/modules/4_store_current_tick.rs b/substreams/ethereum-uniswap-v4/src/modules/4_store_current_tick.rs index 54ed74f..d81c055 100644 --- a/substreams/ethereum-uniswap-v4/src/modules/4_store_current_tick.rs +++ b/substreams/ethereum-uniswap-v4/src/modules/4_store_current_tick.rs @@ -14,7 +14,7 @@ pub fn store_pool_current_tick(events: Events, store: StoreSetInt64) { .into_iter() .filter_map(event_to_current_tick) .for_each(|(pool, ordinal, new_tick_index)| { - store.set(ordinal, format!("pool:{pool}"), &new_tick_index.into()) + store.set(ordinal, format!("pool:{0}", pool), &new_tick_index.into()) }); } fn event_to_current_tick(event: PoolEvent) -> Option<(String, u64, i32)> {