From a7e1dd9397474a6b3011fb475fc39870300b27a1 Mon Sep 17 00:00:00 2001 From: kayibal Date: Thu, 6 Feb 2025 10:15:22 -0600 Subject: [PATCH] Use tycho-substreams erc20 abi. --- .../ethereum-template-factory/abi/.gitkeep | 1 + .../ethereum-template-factory/abi/erc20.json | 222 ---- .../src/abi/erc20.rs | 1066 ----------------- .../ethereum-template-factory/src/abi/mod.rs | 1 - .../ethereum-template-factory/src/modules.rs | 5 +- .../ethereum-template-singleton/abi/.gitkeep | 1 + .../abi/erc20.json | 222 ---- .../src/abi/erc20.rs | 1066 ----------------- .../src/abi/mod.rs | 1 - .../src/modules.rs | 3 +- 10 files changed, 6 insertions(+), 2582 deletions(-) create mode 100644 substreams/ethereum-template-factory/abi/.gitkeep delete mode 100644 substreams/ethereum-template-factory/abi/erc20.json delete mode 100644 substreams/ethereum-template-factory/src/abi/erc20.rs create mode 100644 substreams/ethereum-template-singleton/abi/.gitkeep delete mode 100644 substreams/ethereum-template-singleton/abi/erc20.json delete mode 100644 substreams/ethereum-template-singleton/src/abi/erc20.rs diff --git a/substreams/ethereum-template-factory/abi/.gitkeep b/substreams/ethereum-template-factory/abi/.gitkeep new file mode 100644 index 000000000..d18638c31 --- /dev/null +++ b/substreams/ethereum-template-factory/abi/.gitkeep @@ -0,0 +1 @@ +Please put any abi JSONs into this folder the buildscript will compile these to rust code. \ No newline at end of file diff --git a/substreams/ethereum-template-factory/abi/erc20.json b/substreams/ethereum-template-factory/abi/erc20.json deleted file mode 100644 index 3b0ab2f1a..000000000 --- a/substreams/ethereum-template-factory/abi/erc20.json +++ /dev/null @@ -1,222 +0,0 @@ -[ - { - "constant": true, - "inputs": [], - "name": "name", - "outputs": [ - { - "name": "", - "type": "string" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "_spender", - "type": "address" - }, - { - "name": "_value", - "type": "uint256" - } - ], - "name": "approve", - "outputs": [ - { - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "totalSupply", - "outputs": [ - { - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "_from", - "type": "address" - }, - { - "name": "_to", - "type": "address" - }, - { - "name": "_value", - "type": "uint256" - } - ], - "name": "transferFrom", - "outputs": [ - { - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "decimals", - "outputs": [ - { - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "name": "_owner", - "type": "address" - } - ], - "name": "balanceOf", - "outputs": [ - { - "name": "balance", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "symbol", - "outputs": [ - { - "name": "", - "type": "string" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "_to", - "type": "address" - }, - { - "name": "_value", - "type": "uint256" - } - ], - "name": "transfer", - "outputs": [ - { - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "name": "_owner", - "type": "address" - }, - { - "name": "_spender", - "type": "address" - } - ], - "name": "allowance", - "outputs": [ - { - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "payable": true, - "stateMutability": "payable", - "type": "fallback" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "name": "owner", - "type": "address" - }, - { - "indexed": true, - "name": "spender", - "type": "address" - }, - { - "indexed": false, - "name": "value", - "type": "uint256" - } - ], - "name": "Approval", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "name": "from", - "type": "address" - }, - { - "indexed": true, - "name": "to", - "type": "address" - }, - { - "indexed": false, - "name": "value", - "type": "uint256" - } - ], - "name": "Transfer", - "type": "event" - } -] \ No newline at end of file diff --git a/substreams/ethereum-template-factory/src/abi/erc20.rs b/substreams/ethereum-template-factory/src/abi/erc20.rs deleted file mode 100644 index 5dd70caf6..000000000 --- a/substreams/ethereum-template-factory/src/abi/erc20.rs +++ /dev/null @@ -1,1066 +0,0 @@ -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 owner: Vec, - pub spender: 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 { - owner: values - .pop() - .expect(INTERNAL_ERR) - .into_address() - .expect(INTERNAL_ERR) - .as_bytes() - .to_vec(), - spender: 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.owner)), - ethabi::Token::Address(ethabi::Address::from_slice(&self.spender)), - ]); - 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 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 spender: Vec, - pub value: 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 { - spender: values - .pop() - .expect(INTERNAL_ERR) - .into_address() - .expect(INTERNAL_ERR) - .as_bytes() - .to_vec(), - value: { - 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.spender)), - ethabi::Token::Uint(ethabi::Uint::from_big_endian( - match self.value.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 owner: 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 { - owner: 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.owner))]); - 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 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 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 to: Vec, - pub value: 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 { - to: values - .pop() - .expect(INTERNAL_ERR) - .into_address() - .expect(INTERNAL_ERR) - .as_bytes() - .to_vec(), - value: { - 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.to)), - ethabi::Token::Uint(ethabi::Uint::from_big_endian( - match self.value.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 from: Vec, - pub to: Vec, - pub value: 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 { - from: values - .pop() - .expect(INTERNAL_ERR) - .into_address() - .expect(INTERNAL_ERR) - .as_bytes() - .to_vec(), - to: values - .pop() - .expect(INTERNAL_ERR) - .into_address() - .expect(INTERNAL_ERR) - .as_bytes() - .to_vec(), - value: { - 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.from)), - ethabi::Token::Address(ethabi::Address::from_slice(&self.to)), - ethabi::Token::Uint(ethabi::Uint::from_big_endian( - match self.value.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) - } - } -} -/// 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 owner: Vec, - pub spender: Vec, - pub value: 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; - } - 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 { - 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 - ) - })? - .pop() - .expect(INTERNAL_ERR) - .into_address() - .expect(INTERNAL_ERR) - .as_bytes() - .to_vec(), - 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 - ) - })? - .pop() - .expect(INTERNAL_ERR) - .into_address() - .expect(INTERNAL_ERR) - .as_bytes() - .to_vec(), - value: { - 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 Transfer { - pub from: Vec, - pub to: Vec, - pub value: 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 { - 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 - ) - })? - .pop() - .expect(INTERNAL_ERR) - .into_address() - .expect(INTERNAL_ERR) - .as_bytes() - .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) - })? - .pop() - .expect(INTERNAL_ERR) - .into_address() - .expect(INTERNAL_ERR) - .as_bytes() - .to_vec(), - value: { - 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) - } - } -} diff --git a/substreams/ethereum-template-factory/src/abi/mod.rs b/substreams/ethereum-template-factory/src/abi/mod.rs index 4542b55b8..76e240afa 100644 --- a/substreams/ethereum-template-factory/src/abi/mod.rs +++ b/substreams/ethereum-template-factory/src/abi/mod.rs @@ -1,2 +1 @@ #![allow(clippy::all)] -pub mod erc20; diff --git a/substreams/ethereum-template-factory/src/modules.rs b/substreams/ethereum-template-factory/src/modules.rs index ba3eb1699..5a87592d6 100644 --- a/substreams/ethereum-template-factory/src/modules.rs +++ b/substreams/ethereum-template-factory/src/modules.rs @@ -39,7 +39,8 @@ use std::collections::HashMap; use substreams::{pb::substreams::StoreDeltas, prelude::*}; use substreams_ethereum::{pb::eth, Event}; use tycho_substreams::{ - balances::aggregate_balances_changes, contract::extract_contract_changes_builder, prelude::*, + abi::erc20, balances::aggregate_balances_changes, contract::extract_contract_changes_builder, + prelude::*, }; /// Find and create all relevant protocol components @@ -128,7 +129,7 @@ fn map_relative_component_balance( let res = block .logs() .filter_map(|log| { - crate::abi::erc20::events::Transfer::match_and_decode(log).map(|transfer| { + erc20::events::Transfer::match_and_decode(log).map(|transfer| { let to_addr = hex::encode(transfer.to.as_slice()); let from_addr = hex::encode(transfer.from.as_slice()); let tx = log.receipt.transaction; diff --git a/substreams/ethereum-template-singleton/abi/.gitkeep b/substreams/ethereum-template-singleton/abi/.gitkeep new file mode 100644 index 000000000..d18638c31 --- /dev/null +++ b/substreams/ethereum-template-singleton/abi/.gitkeep @@ -0,0 +1 @@ +Please put any abi JSONs into this folder the buildscript will compile these to rust code. \ No newline at end of file diff --git a/substreams/ethereum-template-singleton/abi/erc20.json b/substreams/ethereum-template-singleton/abi/erc20.json deleted file mode 100644 index 3b0ab2f1a..000000000 --- a/substreams/ethereum-template-singleton/abi/erc20.json +++ /dev/null @@ -1,222 +0,0 @@ -[ - { - "constant": true, - "inputs": [], - "name": "name", - "outputs": [ - { - "name": "", - "type": "string" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "_spender", - "type": "address" - }, - { - "name": "_value", - "type": "uint256" - } - ], - "name": "approve", - "outputs": [ - { - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "totalSupply", - "outputs": [ - { - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "_from", - "type": "address" - }, - { - "name": "_to", - "type": "address" - }, - { - "name": "_value", - "type": "uint256" - } - ], - "name": "transferFrom", - "outputs": [ - { - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "decimals", - "outputs": [ - { - "name": "", - "type": "uint8" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "name": "_owner", - "type": "address" - } - ], - "name": "balanceOf", - "outputs": [ - { - "name": "balance", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "symbol", - "outputs": [ - { - "name": "", - "type": "string" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "_to", - "type": "address" - }, - { - "name": "_value", - "type": "uint256" - } - ], - "name": "transfer", - "outputs": [ - { - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "name": "_owner", - "type": "address" - }, - { - "name": "_spender", - "type": "address" - } - ], - "name": "allowance", - "outputs": [ - { - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "payable": true, - "stateMutability": "payable", - "type": "fallback" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "name": "owner", - "type": "address" - }, - { - "indexed": true, - "name": "spender", - "type": "address" - }, - { - "indexed": false, - "name": "value", - "type": "uint256" - } - ], - "name": "Approval", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "name": "from", - "type": "address" - }, - { - "indexed": true, - "name": "to", - "type": "address" - }, - { - "indexed": false, - "name": "value", - "type": "uint256" - } - ], - "name": "Transfer", - "type": "event" - } -] \ No newline at end of file diff --git a/substreams/ethereum-template-singleton/src/abi/erc20.rs b/substreams/ethereum-template-singleton/src/abi/erc20.rs deleted file mode 100644 index 5dd70caf6..000000000 --- a/substreams/ethereum-template-singleton/src/abi/erc20.rs +++ /dev/null @@ -1,1066 +0,0 @@ -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 owner: Vec, - pub spender: 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 { - owner: values - .pop() - .expect(INTERNAL_ERR) - .into_address() - .expect(INTERNAL_ERR) - .as_bytes() - .to_vec(), - spender: 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.owner)), - ethabi::Token::Address(ethabi::Address::from_slice(&self.spender)), - ]); - 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 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 spender: Vec, - pub value: 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 { - spender: values - .pop() - .expect(INTERNAL_ERR) - .into_address() - .expect(INTERNAL_ERR) - .as_bytes() - .to_vec(), - value: { - 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.spender)), - ethabi::Token::Uint(ethabi::Uint::from_big_endian( - match self.value.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 owner: 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 { - owner: 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.owner))]); - 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 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 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 to: Vec, - pub value: 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 { - to: values - .pop() - .expect(INTERNAL_ERR) - .into_address() - .expect(INTERNAL_ERR) - .as_bytes() - .to_vec(), - value: { - 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.to)), - ethabi::Token::Uint(ethabi::Uint::from_big_endian( - match self.value.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 from: Vec, - pub to: Vec, - pub value: 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 { - from: values - .pop() - .expect(INTERNAL_ERR) - .into_address() - .expect(INTERNAL_ERR) - .as_bytes() - .to_vec(), - to: values - .pop() - .expect(INTERNAL_ERR) - .into_address() - .expect(INTERNAL_ERR) - .as_bytes() - .to_vec(), - value: { - 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.from)), - ethabi::Token::Address(ethabi::Address::from_slice(&self.to)), - ethabi::Token::Uint(ethabi::Uint::from_big_endian( - match self.value.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) - } - } -} -/// 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 owner: Vec, - pub spender: Vec, - pub value: 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; - } - 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 { - 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 - ) - })? - .pop() - .expect(INTERNAL_ERR) - .into_address() - .expect(INTERNAL_ERR) - .as_bytes() - .to_vec(), - 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 - ) - })? - .pop() - .expect(INTERNAL_ERR) - .into_address() - .expect(INTERNAL_ERR) - .as_bytes() - .to_vec(), - value: { - 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 Transfer { - pub from: Vec, - pub to: Vec, - pub value: 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 { - 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 - ) - })? - .pop() - .expect(INTERNAL_ERR) - .into_address() - .expect(INTERNAL_ERR) - .as_bytes() - .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) - })? - .pop() - .expect(INTERNAL_ERR) - .into_address() - .expect(INTERNAL_ERR) - .as_bytes() - .to_vec(), - value: { - 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) - } - } -} diff --git a/substreams/ethereum-template-singleton/src/abi/mod.rs b/substreams/ethereum-template-singleton/src/abi/mod.rs index 4542b55b8..76e240afa 100644 --- a/substreams/ethereum-template-singleton/src/abi/mod.rs +++ b/substreams/ethereum-template-singleton/src/abi/mod.rs @@ -1,2 +1 @@ #![allow(clippy::all)] -pub mod erc20; diff --git a/substreams/ethereum-template-singleton/src/modules.rs b/substreams/ethereum-template-singleton/src/modules.rs index 6d28fa777..478d60cd9 100644 --- a/substreams/ethereum-template-singleton/src/modules.rs +++ b/substreams/ethereum-template-singleton/src/modules.rs @@ -102,7 +102,7 @@ fn map_relative_component_balance( .transactions() .flat_map(|tx| { tx.logs_with_calls() - .map(|(_log, _call)| -> Vec { + .flat_map(|(_log, _call)| -> Vec { /* TODO: Parse events/calls to extract balance deltas @@ -138,7 +138,6 @@ fn map_relative_component_balance( */ vec![] }) - .flatten() }) .collect::>();