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

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

View File

@@ -34,6 +34,7 @@ impl SerializableVecBigInt for Vec<BigInt> {
/// - Weighted Pool Factories /// - Weighted Pool Factories
/// - Linear Pool Factories /// - Linear Pool Factories
/// - Stable Pool Factories /// - Stable Pool Factories
///
/// (Balancer does have a bit more (esp. in the deprecated section) that could be implemented as /// (Balancer does have a bit more (esp. in the deprecated section) that could be implemented as
/// desired.) /// desired.)
/// We use the specific ABIs to decode both the log event and corresponding call to gather /// We use the specific ABIs to decode both the log event and corresponding call to gather

View File

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

View File

@@ -10,9 +10,7 @@
} }
impl Allowance { impl Allowance {
const METHOD_ID: [u8; 4] = [221u8, 98u8, 237u8, 62u8]; const METHOD_ID: [u8; 4] = [221u8, 98u8, 237u8, 62u8];
pub fn decode( pub fn decode(call: &substreams_ethereum::pb::eth::v2::Call) -> Result<Self, String> {
call: &substreams_ethereum::pb::eth::v2::Call,
) -> Result<Self, String> {
let maybe_data = call.input.get(4..); let maybe_data = call.input.get(4..);
if maybe_data.is_none() { if maybe_data.is_none() {
return Err("no data to decode".to_string()); return Err("no data to decode".to_string());
@@ -41,14 +39,10 @@
}) })
} }
pub fn encode(&self) -> Vec<u8> { pub fn encode(&self) -> Vec<u8> {
let data = ethabi::encode( let data = ethabi::encode(&[
&[
ethabi::Token::Address(ethabi::Address::from_slice(&self.owner)), ethabi::Token::Address(ethabi::Address::from_slice(&self.owner)),
ethabi::Token::Address( ethabi::Token::Address(ethabi::Address::from_slice(&self.spender)),
ethabi::Address::from_slice(&self.spender), ]);
),
],
);
let mut encoded = Vec::with_capacity(4 + data.len()); let mut encoded = Vec::with_capacity(4 + data.len());
encoded.extend(Self::METHOD_ID); encoded.extend(Self::METHOD_ID);
encoded.extend(data); encoded.extend(data);
@@ -60,10 +54,7 @@
Self::output(call.return_data.as_ref()) Self::output(call.return_data.as_ref())
} }
pub fn output(data: &[u8]) -> Result<substreams::scalar::BigInt, String> { pub fn output(data: &[u8]) -> Result<substreams::scalar::BigInt, String> {
let mut values = ethabi::decode( let mut values = ethabi::decode(&[ethabi::ParamType::Uint(256usize)], data.as_ref())
&[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({ Ok({
let mut v = [0 as u8; 32]; let mut v = [0 as u8; 32];
@@ -85,9 +76,7 @@
pub fn call(&self, address: Vec<u8>) -> Option<substreams::scalar::BigInt> { pub fn call(&self, address: Vec<u8>) -> Option<substreams::scalar::BigInt> {
use substreams_ethereum::pb::eth::rpc; use substreams_ethereum::pb::eth::rpc;
let rpc_calls = rpc::RpcCalls { let rpc_calls = rpc::RpcCalls {
calls: vec![ calls: vec![rpc::RpcCall { to_addr: address, data: self.encode() }],
rpc::RpcCall { to_addr : address, data : self.encode(), }
],
}; };
let responses = substreams_ethereum::rpc::eth_call(&rpc_calls).responses; let responses = substreams_ethereum::rpc::eth_call(&rpc_calls).responses;
let response = responses let response = responses
@@ -102,7 +91,8 @@
use substreams_ethereum::Function; use substreams_ethereum::Function;
substreams::log::info!( substreams::log::info!(
"Call output for function `{}` failed to decode with error: {}", "Call output for function `{}` failed to decode with error: {}",
Self::NAME, err Self::NAME,
err
); );
None None
} }
@@ -114,17 +104,14 @@
fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool {
Self::match_call(call) Self::match_call(call)
} }
fn decode( fn decode(call: &substreams_ethereum::pb::eth::v2::Call) -> Result<Self, String> {
call: &substreams_ethereum::pb::eth::v2::Call,
) -> Result<Self, String> {
Self::decode(call) Self::decode(call)
} }
fn encode(&self) -> Vec<u8> { fn encode(&self) -> Vec<u8> {
self.encode() self.encode()
} }
} }
impl substreams_ethereum::rpc::RPCDecodable<substreams::scalar::BigInt> impl substreams_ethereum::rpc::RPCDecodable<substreams::scalar::BigInt> for Allowance {
for Allowance {
fn output(data: &[u8]) -> Result<substreams::scalar::BigInt, String> { fn output(data: &[u8]) -> Result<substreams::scalar::BigInt, String> {
Self::output(data) Self::output(data)
} }
@@ -136,9 +123,7 @@
} }
impl Approve { impl Approve {
const METHOD_ID: [u8; 4] = [9u8, 94u8, 167u8, 179u8]; const METHOD_ID: [u8; 4] = [9u8, 94u8, 167u8, 179u8];
pub fn decode( pub fn decode(call: &substreams_ethereum::pb::eth::v2::Call) -> Result<Self, String> {
call: &substreams_ethereum::pb::eth::v2::Call,
) -> Result<Self, String> {
let maybe_data = call.input.get(4..); let maybe_data = call.input.get(4..);
if maybe_data.is_none() { if maybe_data.is_none() {
return Err("no data to decode".to_string()); return Err("no data to decode".to_string());
@@ -170,13 +155,9 @@
}) })
} }
pub fn encode(&self) -> Vec<u8> { pub fn encode(&self) -> Vec<u8> {
let data = ethabi::encode( let data = ethabi::encode(&[
&[ ethabi::Token::Address(ethabi::Address::from_slice(&self.spender)),
ethabi::Token::Address( ethabi::Token::Uint(ethabi::Uint::from_big_endian(
ethabi::Address::from_slice(&self.spender),
),
ethabi::Token::Uint(
ethabi::Uint::from_big_endian(
match self.value.clone().to_bytes_be() { match self.value.clone().to_bytes_be() {
(num_bigint::Sign::Plus, bytes) => bytes, (num_bigint::Sign::Plus, bytes) => bytes,
(num_bigint::Sign::NoSign, bytes) => bytes, (num_bigint::Sign::NoSign, bytes) => bytes,
@@ -185,33 +166,24 @@
} }
} }
.as_slice(), .as_slice(),
), )),
), ]);
],
);
let mut encoded = Vec::with_capacity(4 + data.len()); let mut encoded = Vec::with_capacity(4 + data.len());
encoded.extend(Self::METHOD_ID); encoded.extend(Self::METHOD_ID);
encoded.extend(data); encoded.extend(data);
encoded encoded
} }
pub fn output_call( pub fn output_call(call: &substreams_ethereum::pb::eth::v2::Call) -> Result<bool, String> {
call: &substreams_ethereum::pb::eth::v2::Call,
) -> Result<bool, String> {
Self::output(call.return_data.as_ref()) Self::output(call.return_data.as_ref())
} }
pub fn output(data: &[u8]) -> Result<bool, String> { pub fn output(data: &[u8]) -> Result<bool, String> {
let mut values = ethabi::decode( let mut values = ethabi::decode(&[ethabi::ParamType::Bool], data.as_ref())
&[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( Ok(values
values
.pop() .pop()
.expect("one output data should have existed") .expect("one output data should have existed")
.into_bool() .into_bool()
.expect(INTERNAL_ERR), .expect(INTERNAL_ERR))
)
} }
pub fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { pub fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool {
match call.input.get(0..4) { match call.input.get(0..4) {
@@ -222,9 +194,7 @@
pub fn call(&self, address: Vec<u8>) -> Option<bool> { pub fn call(&self, address: Vec<u8>) -> Option<bool> {
use substreams_ethereum::pb::eth::rpc; use substreams_ethereum::pb::eth::rpc;
let rpc_calls = rpc::RpcCalls { let rpc_calls = rpc::RpcCalls {
calls: vec![ calls: vec![rpc::RpcCall { to_addr: address, data: self.encode() }],
rpc::RpcCall { to_addr : address, data : self.encode(), }
],
}; };
let responses = substreams_ethereum::rpc::eth_call(&rpc_calls).responses; let responses = substreams_ethereum::rpc::eth_call(&rpc_calls).responses;
let response = responses let response = responses
@@ -239,7 +209,8 @@
use substreams_ethereum::Function; use substreams_ethereum::Function;
substreams::log::info!( substreams::log::info!(
"Call output for function `{}` failed to decode with error: {}", "Call output for function `{}` failed to decode with error: {}",
Self::NAME, err Self::NAME,
err
); );
None None
} }
@@ -251,9 +222,7 @@
fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool {
Self::match_call(call) Self::match_call(call)
} }
fn decode( fn decode(call: &substreams_ethereum::pb::eth::v2::Call) -> Result<Self, String> {
call: &substreams_ethereum::pb::eth::v2::Call,
) -> Result<Self, String> {
Self::decode(call) Self::decode(call)
} }
fn encode(&self) -> Vec<u8> { fn encode(&self) -> Vec<u8> {
@@ -271,17 +240,12 @@
} }
impl BalanceOf { impl BalanceOf {
const METHOD_ID: [u8; 4] = [112u8, 160u8, 130u8, 49u8]; const METHOD_ID: [u8; 4] = [112u8, 160u8, 130u8, 49u8];
pub fn decode( pub fn decode(call: &substreams_ethereum::pb::eth::v2::Call) -> Result<Self, String> {
call: &substreams_ethereum::pb::eth::v2::Call,
) -> Result<Self, String> {
let maybe_data = call.input.get(4..); let maybe_data = call.input.get(4..);
if maybe_data.is_none() { if maybe_data.is_none() {
return Err("no data to decode".to_string()); return Err("no data to decode".to_string());
} }
let mut values = ethabi::decode( let mut values = ethabi::decode(&[ethabi::ParamType::Address], maybe_data.unwrap())
&[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(); values.reverse();
Ok(Self { Ok(Self {
@@ -295,9 +259,8 @@
}) })
} }
pub fn encode(&self) -> Vec<u8> { pub fn encode(&self) -> Vec<u8> {
let data = ethabi::encode( let data =
&[ethabi::Token::Address(ethabi::Address::from_slice(&self.owner))], ethabi::encode(&[ethabi::Token::Address(ethabi::Address::from_slice(&self.owner))]);
);
let mut encoded = Vec::with_capacity(4 + data.len()); let mut encoded = Vec::with_capacity(4 + data.len());
encoded.extend(Self::METHOD_ID); encoded.extend(Self::METHOD_ID);
encoded.extend(data); encoded.extend(data);
@@ -309,10 +272,7 @@
Self::output(call.return_data.as_ref()) Self::output(call.return_data.as_ref())
} }
pub fn output(data: &[u8]) -> Result<substreams::scalar::BigInt, String> { pub fn output(data: &[u8]) -> Result<substreams::scalar::BigInt, String> {
let mut values = ethabi::decode( let mut values = ethabi::decode(&[ethabi::ParamType::Uint(256usize)], data.as_ref())
&[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({ Ok({
let mut v = [0 as u8; 32]; let mut v = [0 as u8; 32];
@@ -334,9 +294,7 @@
pub fn call(&self, address: Vec<u8>) -> Option<substreams::scalar::BigInt> { pub fn call(&self, address: Vec<u8>) -> Option<substreams::scalar::BigInt> {
use substreams_ethereum::pb::eth::rpc; use substreams_ethereum::pb::eth::rpc;
let rpc_calls = rpc::RpcCalls { let rpc_calls = rpc::RpcCalls {
calls: vec![ calls: vec![rpc::RpcCall { to_addr: address, data: self.encode() }],
rpc::RpcCall { to_addr : address, data : self.encode(), }
],
}; };
let responses = substreams_ethereum::rpc::eth_call(&rpc_calls).responses; let responses = substreams_ethereum::rpc::eth_call(&rpc_calls).responses;
let response = responses let response = responses
@@ -351,7 +309,8 @@
use substreams_ethereum::Function; use substreams_ethereum::Function;
substreams::log::info!( substreams::log::info!(
"Call output for function `{}` failed to decode with error: {}", "Call output for function `{}` failed to decode with error: {}",
Self::NAME, err Self::NAME,
err
); );
None None
} }
@@ -363,17 +322,14 @@
fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool {
Self::match_call(call) Self::match_call(call)
} }
fn decode( fn decode(call: &substreams_ethereum::pb::eth::v2::Call) -> Result<Self, String> {
call: &substreams_ethereum::pb::eth::v2::Call,
) -> Result<Self, String> {
Self::decode(call) Self::decode(call)
} }
fn encode(&self) -> Vec<u8> { fn encode(&self) -> Vec<u8> {
self.encode() self.encode()
} }
} }
impl substreams_ethereum::rpc::RPCDecodable<substreams::scalar::BigInt> impl substreams_ethereum::rpc::RPCDecodable<substreams::scalar::BigInt> for BalanceOf {
for BalanceOf {
fn output(data: &[u8]) -> Result<substreams::scalar::BigInt, String> { fn output(data: &[u8]) -> Result<substreams::scalar::BigInt, String> {
Self::output(data) Self::output(data)
} }
@@ -382,9 +338,7 @@
pub struct Decimals {} pub struct Decimals {}
impl Decimals { impl Decimals {
const METHOD_ID: [u8; 4] = [49u8, 60u8, 229u8, 103u8]; const METHOD_ID: [u8; 4] = [49u8, 60u8, 229u8, 103u8];
pub fn decode( pub fn decode(call: &substreams_ethereum::pb::eth::v2::Call) -> Result<Self, String> {
call: &substreams_ethereum::pb::eth::v2::Call,
) -> Result<Self, String> {
Ok(Self {}) Ok(Self {})
} }
pub fn encode(&self) -> Vec<u8> { pub fn encode(&self) -> Vec<u8> {
@@ -400,10 +354,7 @@
Self::output(call.return_data.as_ref()) Self::output(call.return_data.as_ref())
} }
pub fn output(data: &[u8]) -> Result<substreams::scalar::BigInt, String> { pub fn output(data: &[u8]) -> Result<substreams::scalar::BigInt, String> {
let mut values = ethabi::decode( let mut values = ethabi::decode(&[ethabi::ParamType::Uint(8usize)], data.as_ref())
&[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({ Ok({
let mut v = [0 as u8; 32]; let mut v = [0 as u8; 32];
@@ -425,9 +376,7 @@
pub fn call(&self, address: Vec<u8>) -> Option<substreams::scalar::BigInt> { pub fn call(&self, address: Vec<u8>) -> Option<substreams::scalar::BigInt> {
use substreams_ethereum::pb::eth::rpc; use substreams_ethereum::pb::eth::rpc;
let rpc_calls = rpc::RpcCalls { let rpc_calls = rpc::RpcCalls {
calls: vec![ calls: vec![rpc::RpcCall { to_addr: address, data: self.encode() }],
rpc::RpcCall { to_addr : address, data : self.encode(), }
],
}; };
let responses = substreams_ethereum::rpc::eth_call(&rpc_calls).responses; let responses = substreams_ethereum::rpc::eth_call(&rpc_calls).responses;
let response = responses let response = responses
@@ -442,7 +391,8 @@
use substreams_ethereum::Function; use substreams_ethereum::Function;
substreams::log::info!( substreams::log::info!(
"Call output for function `{}` failed to decode with error: {}", "Call output for function `{}` failed to decode with error: {}",
Self::NAME, err Self::NAME,
err
); );
None None
} }
@@ -454,17 +404,14 @@
fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool {
Self::match_call(call) Self::match_call(call)
} }
fn decode( fn decode(call: &substreams_ethereum::pb::eth::v2::Call) -> Result<Self, String> {
call: &substreams_ethereum::pb::eth::v2::Call,
) -> Result<Self, String> {
Self::decode(call) Self::decode(call)
} }
fn encode(&self) -> Vec<u8> { fn encode(&self) -> Vec<u8> {
self.encode() self.encode()
} }
} }
impl substreams_ethereum::rpc::RPCDecodable<substreams::scalar::BigInt> impl substreams_ethereum::rpc::RPCDecodable<substreams::scalar::BigInt> for Decimals {
for Decimals {
fn output(data: &[u8]) -> Result<substreams::scalar::BigInt, String> { fn output(data: &[u8]) -> Result<substreams::scalar::BigInt, String> {
Self::output(data) Self::output(data)
} }
@@ -473,9 +420,7 @@
pub struct Name {} pub struct Name {}
impl Name { impl Name {
const METHOD_ID: [u8; 4] = [6u8, 253u8, 222u8, 3u8]; const METHOD_ID: [u8; 4] = [6u8, 253u8, 222u8, 3u8];
pub fn decode( pub fn decode(call: &substreams_ethereum::pb::eth::v2::Call) -> Result<Self, String> {
call: &substreams_ethereum::pb::eth::v2::Call,
) -> Result<Self, String> {
Ok(Self {}) Ok(Self {})
} }
pub fn encode(&self) -> Vec<u8> { pub fn encode(&self) -> Vec<u8> {
@@ -491,18 +436,13 @@
Self::output(call.return_data.as_ref()) Self::output(call.return_data.as_ref())
} }
pub fn output(data: &[u8]) -> Result<String, String> { pub fn output(data: &[u8]) -> Result<String, String> {
let mut values = ethabi::decode( let mut values = ethabi::decode(&[ethabi::ParamType::String], data.as_ref())
&[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( Ok(values
values
.pop() .pop()
.expect("one output data should have existed") .expect("one output data should have existed")
.into_string() .into_string()
.expect(INTERNAL_ERR), .expect(INTERNAL_ERR))
)
} }
pub fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { pub fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool {
match call.input.get(0..4) { match call.input.get(0..4) {
@@ -513,9 +453,7 @@
pub fn call(&self, address: Vec<u8>) -> Option<String> { pub fn call(&self, address: Vec<u8>) -> Option<String> {
use substreams_ethereum::pb::eth::rpc; use substreams_ethereum::pb::eth::rpc;
let rpc_calls = rpc::RpcCalls { let rpc_calls = rpc::RpcCalls {
calls: vec![ calls: vec![rpc::RpcCall { to_addr: address, data: self.encode() }],
rpc::RpcCall { to_addr : address, data : self.encode(), }
],
}; };
let responses = substreams_ethereum::rpc::eth_call(&rpc_calls).responses; let responses = substreams_ethereum::rpc::eth_call(&rpc_calls).responses;
let response = responses let response = responses
@@ -530,7 +468,8 @@
use substreams_ethereum::Function; use substreams_ethereum::Function;
substreams::log::info!( substreams::log::info!(
"Call output for function `{}` failed to decode with error: {}", "Call output for function `{}` failed to decode with error: {}",
Self::NAME, err Self::NAME,
err
); );
None None
} }
@@ -542,9 +481,7 @@
fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool {
Self::match_call(call) Self::match_call(call)
} }
fn decode( fn decode(call: &substreams_ethereum::pb::eth::v2::Call) -> Result<Self, String> {
call: &substreams_ethereum::pb::eth::v2::Call,
) -> Result<Self, String> {
Self::decode(call) Self::decode(call)
} }
fn encode(&self) -> Vec<u8> { fn encode(&self) -> Vec<u8> {
@@ -560,9 +497,7 @@
pub struct Symbol {} pub struct Symbol {}
impl Symbol { impl Symbol {
const METHOD_ID: [u8; 4] = [149u8, 216u8, 155u8, 65u8]; const METHOD_ID: [u8; 4] = [149u8, 216u8, 155u8, 65u8];
pub fn decode( pub fn decode(call: &substreams_ethereum::pb::eth::v2::Call) -> Result<Self, String> {
call: &substreams_ethereum::pb::eth::v2::Call,
) -> Result<Self, String> {
Ok(Self {}) Ok(Self {})
} }
pub fn encode(&self) -> Vec<u8> { pub fn encode(&self) -> Vec<u8> {
@@ -578,18 +513,13 @@
Self::output(call.return_data.as_ref()) Self::output(call.return_data.as_ref())
} }
pub fn output(data: &[u8]) -> Result<String, String> { pub fn output(data: &[u8]) -> Result<String, String> {
let mut values = ethabi::decode( let mut values = ethabi::decode(&[ethabi::ParamType::String], data.as_ref())
&[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( Ok(values
values
.pop() .pop()
.expect("one output data should have existed") .expect("one output data should have existed")
.into_string() .into_string()
.expect(INTERNAL_ERR), .expect(INTERNAL_ERR))
)
} }
pub fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { pub fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool {
match call.input.get(0..4) { match call.input.get(0..4) {
@@ -600,9 +530,7 @@
pub fn call(&self, address: Vec<u8>) -> Option<String> { pub fn call(&self, address: Vec<u8>) -> Option<String> {
use substreams_ethereum::pb::eth::rpc; use substreams_ethereum::pb::eth::rpc;
let rpc_calls = rpc::RpcCalls { let rpc_calls = rpc::RpcCalls {
calls: vec![ calls: vec![rpc::RpcCall { to_addr: address, data: self.encode() }],
rpc::RpcCall { to_addr : address, data : self.encode(), }
],
}; };
let responses = substreams_ethereum::rpc::eth_call(&rpc_calls).responses; let responses = substreams_ethereum::rpc::eth_call(&rpc_calls).responses;
let response = responses let response = responses
@@ -617,7 +545,8 @@
use substreams_ethereum::Function; use substreams_ethereum::Function;
substreams::log::info!( substreams::log::info!(
"Call output for function `{}` failed to decode with error: {}", "Call output for function `{}` failed to decode with error: {}",
Self::NAME, err Self::NAME,
err
); );
None None
} }
@@ -629,9 +558,7 @@
fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool {
Self::match_call(call) Self::match_call(call)
} }
fn decode( fn decode(call: &substreams_ethereum::pb::eth::v2::Call) -> Result<Self, String> {
call: &substreams_ethereum::pb::eth::v2::Call,
) -> Result<Self, String> {
Self::decode(call) Self::decode(call)
} }
fn encode(&self) -> Vec<u8> { fn encode(&self) -> Vec<u8> {
@@ -647,9 +574,7 @@
pub struct TotalSupply {} pub struct TotalSupply {}
impl TotalSupply { impl TotalSupply {
const METHOD_ID: [u8; 4] = [24u8, 22u8, 13u8, 221u8]; const METHOD_ID: [u8; 4] = [24u8, 22u8, 13u8, 221u8];
pub fn decode( pub fn decode(call: &substreams_ethereum::pb::eth::v2::Call) -> Result<Self, String> {
call: &substreams_ethereum::pb::eth::v2::Call,
) -> Result<Self, String> {
Ok(Self {}) Ok(Self {})
} }
pub fn encode(&self) -> Vec<u8> { pub fn encode(&self) -> Vec<u8> {
@@ -665,10 +590,7 @@
Self::output(call.return_data.as_ref()) Self::output(call.return_data.as_ref())
} }
pub fn output(data: &[u8]) -> Result<substreams::scalar::BigInt, String> { pub fn output(data: &[u8]) -> Result<substreams::scalar::BigInt, String> {
let mut values = ethabi::decode( let mut values = ethabi::decode(&[ethabi::ParamType::Uint(256usize)], data.as_ref())
&[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({ Ok({
let mut v = [0 as u8; 32]; let mut v = [0 as u8; 32];
@@ -690,9 +612,7 @@
pub fn call(&self, address: Vec<u8>) -> Option<substreams::scalar::BigInt> { pub fn call(&self, address: Vec<u8>) -> Option<substreams::scalar::BigInt> {
use substreams_ethereum::pb::eth::rpc; use substreams_ethereum::pb::eth::rpc;
let rpc_calls = rpc::RpcCalls { let rpc_calls = rpc::RpcCalls {
calls: vec![ calls: vec![rpc::RpcCall { to_addr: address, data: self.encode() }],
rpc::RpcCall { to_addr : address, data : self.encode(), }
],
}; };
let responses = substreams_ethereum::rpc::eth_call(&rpc_calls).responses; let responses = substreams_ethereum::rpc::eth_call(&rpc_calls).responses;
let response = responses let response = responses
@@ -707,7 +627,8 @@
use substreams_ethereum::Function; use substreams_ethereum::Function;
substreams::log::info!( substreams::log::info!(
"Call output for function `{}` failed to decode with error: {}", "Call output for function `{}` failed to decode with error: {}",
Self::NAME, err Self::NAME,
err
); );
None None
} }
@@ -719,17 +640,14 @@
fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool {
Self::match_call(call) Self::match_call(call)
} }
fn decode( fn decode(call: &substreams_ethereum::pb::eth::v2::Call) -> Result<Self, String> {
call: &substreams_ethereum::pb::eth::v2::Call,
) -> Result<Self, String> {
Self::decode(call) Self::decode(call)
} }
fn encode(&self) -> Vec<u8> { fn encode(&self) -> Vec<u8> {
self.encode() self.encode()
} }
} }
impl substreams_ethereum::rpc::RPCDecodable<substreams::scalar::BigInt> impl substreams_ethereum::rpc::RPCDecodable<substreams::scalar::BigInt> for TotalSupply {
for TotalSupply {
fn output(data: &[u8]) -> Result<substreams::scalar::BigInt, String> { fn output(data: &[u8]) -> Result<substreams::scalar::BigInt, String> {
Self::output(data) Self::output(data)
} }
@@ -741,9 +659,7 @@
} }
impl Transfer { impl Transfer {
const METHOD_ID: [u8; 4] = [169u8, 5u8, 156u8, 187u8]; const METHOD_ID: [u8; 4] = [169u8, 5u8, 156u8, 187u8];
pub fn decode( pub fn decode(call: &substreams_ethereum::pb::eth::v2::Call) -> Result<Self, String> {
call: &substreams_ethereum::pb::eth::v2::Call,
) -> Result<Self, String> {
let maybe_data = call.input.get(4..); let maybe_data = call.input.get(4..);
if maybe_data.is_none() { if maybe_data.is_none() {
return Err("no data to decode".to_string()); return Err("no data to decode".to_string());
@@ -775,11 +691,9 @@
}) })
} }
pub fn encode(&self) -> Vec<u8> { pub fn encode(&self) -> Vec<u8> {
let data = ethabi::encode( let data = ethabi::encode(&[
&[
ethabi::Token::Address(ethabi::Address::from_slice(&self.to)), ethabi::Token::Address(ethabi::Address::from_slice(&self.to)),
ethabi::Token::Uint( ethabi::Token::Uint(ethabi::Uint::from_big_endian(
ethabi::Uint::from_big_endian(
match self.value.clone().to_bytes_be() { match self.value.clone().to_bytes_be() {
(num_bigint::Sign::Plus, bytes) => bytes, (num_bigint::Sign::Plus, bytes) => bytes,
(num_bigint::Sign::NoSign, bytes) => bytes, (num_bigint::Sign::NoSign, bytes) => bytes,
@@ -788,33 +702,24 @@
} }
} }
.as_slice(), .as_slice(),
), )),
), ]);
],
);
let mut encoded = Vec::with_capacity(4 + data.len()); let mut encoded = Vec::with_capacity(4 + data.len());
encoded.extend(Self::METHOD_ID); encoded.extend(Self::METHOD_ID);
encoded.extend(data); encoded.extend(data);
encoded encoded
} }
pub fn output_call( pub fn output_call(call: &substreams_ethereum::pb::eth::v2::Call) -> Result<bool, String> {
call: &substreams_ethereum::pb::eth::v2::Call,
) -> Result<bool, String> {
Self::output(call.return_data.as_ref()) Self::output(call.return_data.as_ref())
} }
pub fn output(data: &[u8]) -> Result<bool, String> { pub fn output(data: &[u8]) -> Result<bool, String> {
let mut values = ethabi::decode( let mut values = ethabi::decode(&[ethabi::ParamType::Bool], data.as_ref())
&[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( Ok(values
values
.pop() .pop()
.expect("one output data should have existed") .expect("one output data should have existed")
.into_bool() .into_bool()
.expect(INTERNAL_ERR), .expect(INTERNAL_ERR))
)
} }
pub fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { pub fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool {
match call.input.get(0..4) { match call.input.get(0..4) {
@@ -825,9 +730,7 @@
pub fn call(&self, address: Vec<u8>) -> Option<bool> { pub fn call(&self, address: Vec<u8>) -> Option<bool> {
use substreams_ethereum::pb::eth::rpc; use substreams_ethereum::pb::eth::rpc;
let rpc_calls = rpc::RpcCalls { let rpc_calls = rpc::RpcCalls {
calls: vec![ calls: vec![rpc::RpcCall { to_addr: address, data: self.encode() }],
rpc::RpcCall { to_addr : address, data : self.encode(), }
],
}; };
let responses = substreams_ethereum::rpc::eth_call(&rpc_calls).responses; let responses = substreams_ethereum::rpc::eth_call(&rpc_calls).responses;
let response = responses let response = responses
@@ -842,7 +745,8 @@
use substreams_ethereum::Function; use substreams_ethereum::Function;
substreams::log::info!( substreams::log::info!(
"Call output for function `{}` failed to decode with error: {}", "Call output for function `{}` failed to decode with error: {}",
Self::NAME, err Self::NAME,
err
); );
None None
} }
@@ -854,9 +758,7 @@
fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool {
Self::match_call(call) Self::match_call(call)
} }
fn decode( fn decode(call: &substreams_ethereum::pb::eth::v2::Call) -> Result<Self, String> {
call: &substreams_ethereum::pb::eth::v2::Call,
) -> Result<Self, String> {
Self::decode(call) Self::decode(call)
} }
fn encode(&self) -> Vec<u8> { fn encode(&self) -> Vec<u8> {
@@ -876,9 +778,7 @@
} }
impl TransferFrom { impl TransferFrom {
const METHOD_ID: [u8; 4] = [35u8, 184u8, 114u8, 221u8]; const METHOD_ID: [u8; 4] = [35u8, 184u8, 114u8, 221u8];
pub fn decode( pub fn decode(call: &substreams_ethereum::pb::eth::v2::Call) -> Result<Self, String> {
call: &substreams_ethereum::pb::eth::v2::Call,
) -> Result<Self, String> {
let maybe_data = call.input.get(4..); let maybe_data = call.input.get(4..);
if maybe_data.is_none() { if maybe_data.is_none() {
return Err("no data to decode".to_string()); return Err("no data to decode".to_string());
@@ -921,12 +821,10 @@
}) })
} }
pub fn encode(&self) -> Vec<u8> { pub fn encode(&self) -> Vec<u8> {
let data = ethabi::encode( let data = ethabi::encode(&[
&[
ethabi::Token::Address(ethabi::Address::from_slice(&self.from)), ethabi::Token::Address(ethabi::Address::from_slice(&self.from)),
ethabi::Token::Address(ethabi::Address::from_slice(&self.to)), ethabi::Token::Address(ethabi::Address::from_slice(&self.to)),
ethabi::Token::Uint( ethabi::Token::Uint(ethabi::Uint::from_big_endian(
ethabi::Uint::from_big_endian(
match self.value.clone().to_bytes_be() { match self.value.clone().to_bytes_be() {
(num_bigint::Sign::Plus, bytes) => bytes, (num_bigint::Sign::Plus, bytes) => bytes,
(num_bigint::Sign::NoSign, bytes) => bytes, (num_bigint::Sign::NoSign, bytes) => bytes,
@@ -935,33 +833,24 @@
} }
} }
.as_slice(), .as_slice(),
), )),
), ]);
],
);
let mut encoded = Vec::with_capacity(4 + data.len()); let mut encoded = Vec::with_capacity(4 + data.len());
encoded.extend(Self::METHOD_ID); encoded.extend(Self::METHOD_ID);
encoded.extend(data); encoded.extend(data);
encoded encoded
} }
pub fn output_call( pub fn output_call(call: &substreams_ethereum::pb::eth::v2::Call) -> Result<bool, String> {
call: &substreams_ethereum::pb::eth::v2::Call,
) -> Result<bool, String> {
Self::output(call.return_data.as_ref()) Self::output(call.return_data.as_ref())
} }
pub fn output(data: &[u8]) -> Result<bool, String> { pub fn output(data: &[u8]) -> Result<bool, String> {
let mut values = ethabi::decode( let mut values = ethabi::decode(&[ethabi::ParamType::Bool], data.as_ref())
&[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( Ok(values
values
.pop() .pop()
.expect("one output data should have existed") .expect("one output data should have existed")
.into_bool() .into_bool()
.expect(INTERNAL_ERR), .expect(INTERNAL_ERR))
)
} }
pub fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { pub fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool {
match call.input.get(0..4) { match call.input.get(0..4) {
@@ -972,9 +861,7 @@
pub fn call(&self, address: Vec<u8>) -> Option<bool> { pub fn call(&self, address: Vec<u8>) -> Option<bool> {
use substreams_ethereum::pb::eth::rpc; use substreams_ethereum::pb::eth::rpc;
let rpc_calls = rpc::RpcCalls { let rpc_calls = rpc::RpcCalls {
calls: vec![ calls: vec![rpc::RpcCall { to_addr: address, data: self.encode() }],
rpc::RpcCall { to_addr : address, data : self.encode(), }
],
}; };
let responses = substreams_ethereum::rpc::eth_call(&rpc_calls).responses; let responses = substreams_ethereum::rpc::eth_call(&rpc_calls).responses;
let response = responses let response = responses
@@ -989,7 +876,8 @@
use substreams_ethereum::Function; use substreams_ethereum::Function;
substreams::log::info!( substreams::log::info!(
"Call output for function `{}` failed to decode with error: {}", "Call output for function `{}` failed to decode with error: {}",
Self::NAME, err Self::NAME,
err
); );
None None
} }
@@ -1001,9 +889,7 @@
fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool { fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool {
Self::match_call(call) Self::match_call(call)
} }
fn decode( fn decode(call: &substreams_ethereum::pb::eth::v2::Call) -> Result<Self, String> {
call: &substreams_ethereum::pb::eth::v2::Call,
) -> Result<Self, String> {
Self::decode(call) Self::decode(call)
} }
fn encode(&self) -> Vec<u8> { fn encode(&self) -> Vec<u8> {
@@ -1028,38 +914,9 @@
} }
impl Approval { impl Approval {
const TOPIC_ID: [u8; 32] = [ const TOPIC_ID: [u8; 32] = [
140u8, 140u8, 91u8, 225u8, 229u8, 235u8, 236u8, 125u8, 91u8, 209u8, 79u8, 113u8, 66u8, 125u8,
91u8, 30u8, 132u8, 243u8, 221u8, 3u8, 20u8, 192u8, 247u8, 178u8, 41u8, 30u8, 91u8, 32u8,
225u8, 10u8, 200u8, 199u8, 195u8, 185u8, 37u8,
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 { pub fn match_log(log: &substreams_ethereum::pb::eth::v2::Log) -> bool {
if log.topics.len() != 3usize { if log.topics.len() != 3usize {
@@ -1068,23 +925,20 @@
if log.data.len() != 32usize { if log.data.len() != 32usize {
return false; return false;
} }
return log.topics.get(0).expect("bounds already checked").as_ref() return log
== Self::TOPIC_ID; .topics
.get(0)
.expect("bounds already checked")
.as_ref() ==
Self::TOPIC_ID;
} }
pub fn decode( pub fn decode(log: &substreams_ethereum::pb::eth::v2::Log) -> Result<Self, String> {
log: &substreams_ethereum::pb::eth::v2::Log, let mut values =
) -> Result<Self, String> { ethabi::decode(&[ethabi::ParamType::Uint(256usize)], log.data.as_ref())
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(); values.reverse();
Ok(Self { Ok(Self {
owner: ethabi::decode( owner: ethabi::decode(&[ethabi::ParamType::Address], log.topics[1usize].as_ref())
&[ethabi::ParamType::Address],
log.topics[1usize].as_ref(),
)
.map_err(|e| { .map_err(|e| {
format!( format!(
"unable to decode param 'owner' from topic of type 'address': {:?}", "unable to decode param 'owner' from topic of type 'address': {:?}",
@@ -1097,10 +951,7 @@
.expect(INTERNAL_ERR) .expect(INTERNAL_ERR)
.as_bytes() .as_bytes()
.to_vec(), .to_vec(),
spender: ethabi::decode( spender: ethabi::decode(&[ethabi::ParamType::Address], log.topics[2usize].as_ref())
&[ethabi::ParamType::Address],
log.topics[2usize].as_ref(),
)
.map_err(|e| { .map_err(|e| {
format!( format!(
"unable to decode param 'spender' from topic of type 'address': {:?}", "unable to decode param 'spender' from topic of type 'address': {:?}",
@@ -1131,9 +982,7 @@
fn match_log(log: &substreams_ethereum::pb::eth::v2::Log) -> bool { fn match_log(log: &substreams_ethereum::pb::eth::v2::Log) -> bool {
Self::match_log(log) Self::match_log(log)
} }
fn decode( fn decode(log: &substreams_ethereum::pb::eth::v2::Log) -> Result<Self, String> {
log: &substreams_ethereum::pb::eth::v2::Log,
) -> Result<Self, String> {
Self::decode(log) Self::decode(log)
} }
} }
@@ -1145,38 +994,9 @@
} }
impl Transfer { impl Transfer {
const TOPIC_ID: [u8; 32] = [ const TOPIC_ID: [u8; 32] = [
221u8, 221u8, 242u8, 82u8, 173u8, 27u8, 226u8, 200u8, 155u8, 105u8, 194u8, 176u8, 104u8,
242u8, 252u8, 55u8, 141u8, 170u8, 149u8, 43u8, 167u8, 241u8, 99u8, 196u8, 161u8, 22u8, 40u8,
82u8, 245u8, 90u8, 77u8, 245u8, 35u8, 179u8, 239u8,
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 { pub fn match_log(log: &substreams_ethereum::pb::eth::v2::Log) -> bool {
if log.topics.len() != 3usize { if log.topics.len() != 3usize {
@@ -1185,23 +1005,20 @@
if log.data.len() != 32usize { if log.data.len() != 32usize {
return false; return false;
} }
return log.topics.get(0).expect("bounds already checked").as_ref() return log
== Self::TOPIC_ID; .topics
.get(0)
.expect("bounds already checked")
.as_ref() ==
Self::TOPIC_ID;
} }
pub fn decode( pub fn decode(log: &substreams_ethereum::pb::eth::v2::Log) -> Result<Self, String> {
log: &substreams_ethereum::pb::eth::v2::Log, let mut values =
) -> Result<Self, String> { ethabi::decode(&[ethabi::ParamType::Uint(256usize)], log.data.as_ref())
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(); values.reverse();
Ok(Self { Ok(Self {
from: ethabi::decode( from: ethabi::decode(&[ethabi::ParamType::Address], log.topics[1usize].as_ref())
&[ethabi::ParamType::Address],
log.topics[1usize].as_ref(),
)
.map_err(|e| { .map_err(|e| {
format!( format!(
"unable to decode param 'from' from topic of type 'address': {:?}", "unable to decode param 'from' from topic of type 'address': {:?}",
@@ -1214,15 +1031,9 @@
.expect(INTERNAL_ERR) .expect(INTERNAL_ERR)
.as_bytes() .as_bytes()
.to_vec(), .to_vec(),
to: ethabi::decode( to: ethabi::decode(&[ethabi::ParamType::Address], log.topics[2usize].as_ref())
&[ethabi::ParamType::Address],
log.topics[2usize].as_ref(),
)
.map_err(|e| { .map_err(|e| {
format!( format!("unable to decode param 'to' from topic of type 'address': {:?}", e)
"unable to decode param 'to' from topic of type 'address': {:?}",
e
)
})? })?
.pop() .pop()
.expect(INTERNAL_ERR) .expect(INTERNAL_ERR)
@@ -1248,9 +1059,7 @@
fn match_log(log: &substreams_ethereum::pb::eth::v2::Log) -> bool { fn match_log(log: &substreams_ethereum::pb::eth::v2::Log) -> bool {
Self::match_log(log) Self::match_log(log)
} }
fn decode( fn decode(log: &substreams_ethereum::pb::eth::v2::Log) -> Result<Self, String> {
log: &substreams_ethereum::pb::eth::v2::Log,
) -> Result<Self, String> {
Self::decode(log) Self::decode(log)
} }
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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