formatting & lints
This commit is contained in:
@@ -4,7 +4,6 @@ pub mod balances;
|
|||||||
pub mod contract;
|
pub mod contract;
|
||||||
mod mock_store;
|
mod mock_store;
|
||||||
pub mod models;
|
pub mod models;
|
||||||
#[allow(clippy::too_long_first_doc_paragraph)]
|
|
||||||
mod pb;
|
mod pb;
|
||||||
|
|
||||||
pub mod prelude {
|
pub mod prelude {
|
||||||
|
|||||||
@@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
mod abi;
|
mod abi;
|
||||||
mod modules;
|
mod modules;
|
||||||
mod pool_factories;
|
mod pool_factories;
|
||||||
|
|
||||||
|
|||||||
@@ -27,26 +27,22 @@
|
|||||||
//! Adjustments to the template may include:
|
//! Adjustments to the template may include:
|
||||||
//! - Handling native ETH balances alongside token balances.
|
//! - Handling native ETH balances alongside token balances.
|
||||||
//! - Customizing indexing logic for specific factory contract behavior.
|
//! - Customizing indexing logic for specific factory contract behavior.
|
||||||
use std::collections::HashMap;
|
|
||||||
use anyhow::Result;
|
|
||||||
use substreams::pb::substreams::StoreDeltas;
|
|
||||||
use substreams::prelude::*;
|
|
||||||
use substreams_ethereum::Event;
|
|
||||||
use substreams_ethereum::pb::eth;
|
|
||||||
use tycho_substreams::balances::aggregate_balances_changes;
|
|
||||||
use tycho_substreams::contract::extract_contract_changes_builder;
|
|
||||||
use tycho_substreams::prelude::*;
|
|
||||||
use itertools::Itertools;
|
|
||||||
use crate::pool_factories;
|
use crate::pool_factories;
|
||||||
|
use anyhow::Result;
|
||||||
|
use itertools::Itertools;
|
||||||
|
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::*,
|
||||||
|
};
|
||||||
|
|
||||||
/// Find and create all relevant protocol components
|
/// Find and create all relevant protocol components
|
||||||
///
|
///
|
||||||
/// This method maps over blocks and instantiates ProtocolComponents with a unique ids
|
/// This method maps over blocks and instantiates ProtocolComponents with a unique ids
|
||||||
/// as well as all necessary metadata for routing and encoding.
|
/// as well as all necessary metadata for routing and encoding.
|
||||||
#[substreams::handlers::map]
|
#[substreams::handlers::map]
|
||||||
fn map_protocol_components(
|
fn map_protocol_components(block: eth::v2::Block) -> Result<BlockTransactionProtocolComponents> {
|
||||||
block: eth::v2::Block
|
|
||||||
) -> Result<BlockTransactionProtocolComponents> {
|
|
||||||
Ok(BlockTransactionProtocolComponents {
|
Ok(BlockTransactionProtocolComponents {
|
||||||
tx_components: block
|
tx_components: block
|
||||||
.transactions()
|
.transactions()
|
||||||
@@ -55,11 +51,7 @@ fn map_protocol_components(
|
|||||||
.logs_with_calls()
|
.logs_with_calls()
|
||||||
.filter_map(|(log, call)| {
|
.filter_map(|(log, call)| {
|
||||||
// TODO: ensure this method is implemented correctly
|
// TODO: ensure this method is implemented correctly
|
||||||
pool_factories::maybe_create_component(
|
pool_factories::maybe_create_component(call.call, log, tx)
|
||||||
call.call,
|
|
||||||
log,
|
|
||||||
tx,
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
@@ -79,17 +71,21 @@ fn map_protocol_components(
|
|||||||
/// you need to access the whole set of components within your indexing logic.
|
/// you need to access the whole set of components within your indexing logic.
|
||||||
///
|
///
|
||||||
/// Popular use cases are:
|
/// Popular use cases are:
|
||||||
/// - Checking if a contract belongs to a component. In this case suggest to use an
|
/// - Checking if a contract belongs to a component. In this case suggest to use an address as the
|
||||||
/// address as the store key so lookup operations are O(1).
|
/// store key so lookup operations are O(1).
|
||||||
/// - Tallying up relative balances changes to calcualte absolute erc20 token balances
|
/// - Tallying up relative balances changes to calcualte absolute erc20 token balances per
|
||||||
/// per component.
|
/// component.
|
||||||
///
|
///
|
||||||
/// Usually you can skip this step if:
|
/// Usually you can skip this step if:
|
||||||
/// - You are interested in a static set of components only
|
/// - You are interested in a static set of components only
|
||||||
/// - Your protocol emits balance change events with absolute values
|
/// - Your protocol emits balance change events with absolute values
|
||||||
#[substreams::handlers::store]
|
#[substreams::handlers::store]
|
||||||
fn store_protocol_components(map_protocol_components: BlockTransactionProtocolComponents, store: StoreSetRaw) {
|
fn store_protocol_components(
|
||||||
map_protocol_components.tx_components
|
map_protocol_components: BlockTransactionProtocolComponents,
|
||||||
|
store: StoreSetRaw,
|
||||||
|
) {
|
||||||
|
map_protocol_components
|
||||||
|
.tx_components
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.for_each(|tx_pc| {
|
.for_each(|tx_pc| {
|
||||||
tx_pc
|
tx_pc
|
||||||
@@ -120,8 +116,12 @@ fn store_protocol_components(map_protocol_components: BlockTransactionProtocolCo
|
|||||||
/// You may want to ignore LP tokens if your protocol emits transfer events for these
|
/// You may want to ignore LP tokens if your protocol emits transfer events for these
|
||||||
/// here.
|
/// here.
|
||||||
#[substreams::handlers::map]
|
#[substreams::handlers::map]
|
||||||
fn map_relative_component_balance(block: eth::v2::Block, store: StoreGetRaw) -> Result<BlockBalanceDeltas> {
|
fn map_relative_component_balance(
|
||||||
let res = block.logs()
|
block: eth::v2::Block,
|
||||||
|
store: StoreGetRaw,
|
||||||
|
) -> Result<BlockBalanceDeltas> {
|
||||||
|
let res = block
|
||||||
|
.logs()
|
||||||
.filter_map(|log| {
|
.filter_map(|log| {
|
||||||
crate::abi::erc20::events::Transfer::match_and_decode(log).map(|transfer| {
|
crate::abi::erc20::events::Transfer::match_and_decode(log).map(|transfer| {
|
||||||
let to_addr = hex::encode(transfer.to.as_slice());
|
let to_addr = hex::encode(transfer.to.as_slice());
|
||||||
@@ -235,7 +235,6 @@ fn map_protocol_changes(
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// Extract and insert any storage changes that happened for any of the components.
|
// Extract and insert any storage changes that happened for any of the components.
|
||||||
extract_contract_changes_builder(
|
extract_contract_changes_builder(
|
||||||
&block,
|
&block,
|
||||||
@@ -251,7 +250,6 @@ fn map_protocol_changes(
|
|||||||
&mut transaction_changes,
|
&mut transaction_changes,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
// Process all `transaction_changes` for final output in the `BlockChanges`,
|
// Process all `transaction_changes` for final output in the `BlockChanges`,
|
||||||
// sorted by transaction index (the key).
|
// sorted by transaction index (the key).
|
||||||
Ok(BlockChanges {
|
Ok(BlockChanges {
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
use substreams::hex;
|
use substreams::hex;
|
||||||
use substreams_ethereum::pb::eth::v2::{Call, Log, TransactionTrace};
|
use substreams_ethereum::pb::eth::v2::{Call, Log, TransactionTrace};
|
||||||
use tycho_substreams::models::{ChangeType, FinancialType, ImplementationType, ProtocolComponent, ProtocolType};
|
use tycho_substreams::models::{
|
||||||
|
ChangeType, FinancialType, ImplementationType, ProtocolComponent, ProtocolType,
|
||||||
|
};
|
||||||
|
|
||||||
/// Potentially constructs a new ProtocolComponent given a call
|
/// Potentially constructs a new ProtocolComponent given a call
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
const INTERNAL_ERR: &'static str = "`ethabi_derive` internal error";
|
const INTERNAL_ERR: &'static str = "`ethabi_derive` internal error";
|
||||||
/// Contract's functions.
|
/// Contract's functions.
|
||||||
#[allow(dead_code, unused_imports, unused_variables)]
|
#[allow(dead_code, unused_imports, unused_variables)]
|
||||||
@@ -10,9 +11,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 +40,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 +55,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 +77,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 +92,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 +105,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 +124,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 +156,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 +167,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 +195,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 +210,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 +223,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 +241,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 +260,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 +273,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 +295,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 +310,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 +323,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 +339,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 +355,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 +377,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 +392,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 +405,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 +421,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 +437,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 +454,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 +469,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 +482,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 +498,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 +514,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 +531,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 +546,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 +559,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 +575,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 +591,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 +613,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 +628,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 +641,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 +660,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 +692,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 +703,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 +731,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 +746,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 +759,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 +779,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 +822,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 +834,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 +862,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 +877,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 +890,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 +915,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 +926,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 +952,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 +983,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 +995,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 +1006,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 +1032,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 +1060,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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
mod abi;
|
mod abi;
|
||||||
mod pool_factories;
|
|
||||||
mod modules;
|
mod modules;
|
||||||
|
mod pool_factories;
|
||||||
|
|||||||
@@ -14,21 +14,16 @@
|
|||||||
//! likely that you will need to adapt the steps to suit your specific use case. Use the
|
//! likely that you will need to adapt the steps to suit your specific use case. Use the
|
||||||
//! provided code with care and ensure you fully understand each step before proceeding
|
//! provided code with care and ensure you fully understand each step before proceeding
|
||||||
//! with your implementation
|
//! with your implementation
|
||||||
//!
|
use crate::{pool_factories, pool_factories::DeploymentConfig};
|
||||||
use std::collections::HashMap;
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use substreams::pb::substreams::StoreDeltas;
|
|
||||||
use substreams::prelude::*;
|
|
||||||
use substreams_ethereum::Event;
|
|
||||||
use substreams_ethereum::pb::eth;
|
|
||||||
use tycho_substreams::balances::aggregate_balances_changes;
|
|
||||||
use tycho_substreams::contract::extract_contract_changes_builder;
|
|
||||||
use tycho_substreams::prelude::*;
|
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use prost::Message;
|
use prost::Message;
|
||||||
use substreams_ethereum::block_view::CallView;
|
use std::collections::HashMap;
|
||||||
use crate::pool_factories;
|
use substreams::{pb::substreams::StoreDeltas, prelude::*};
|
||||||
use crate::pool_factories::DeploymentConfig;
|
use substreams_ethereum::{block_view::CallView, pb::eth, Event};
|
||||||
|
use tycho_substreams::{
|
||||||
|
balances::aggregate_balances_changes, contract::extract_contract_changes_builder, prelude::*,
|
||||||
|
};
|
||||||
|
|
||||||
/// Find and create all relevant protocol components
|
/// Find and create all relevant protocol components
|
||||||
///
|
///
|
||||||
@@ -48,12 +43,7 @@ fn map_protocol_components(
|
|||||||
.logs_with_calls()
|
.logs_with_calls()
|
||||||
.filter_map(|(log, call)| {
|
.filter_map(|(log, call)| {
|
||||||
// TODO: ensure this method is implemented correctly
|
// TODO: ensure this method is implemented correctly
|
||||||
pool_factories::maybe_create_component(
|
pool_factories::maybe_create_component(call.call, log, tx, &config)
|
||||||
call.call,
|
|
||||||
log,
|
|
||||||
tx,
|
|
||||||
&config,
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
@@ -68,8 +58,12 @@ fn map_protocol_components(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[substreams::handlers::store]
|
#[substreams::handlers::store]
|
||||||
fn store_protocol_tokens(map_protocol_components: BlockTransactionProtocolComponents, store: StoreSetInt64) {
|
fn store_protocol_tokens(
|
||||||
map_protocol_components.tx_components
|
map_protocol_components: BlockTransactionProtocolComponents,
|
||||||
|
store: StoreSetInt64,
|
||||||
|
) {
|
||||||
|
map_protocol_components
|
||||||
|
.tx_components
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.for_each(|tx_pc| {
|
.for_each(|tx_pc| {
|
||||||
tx_pc
|
tx_pc
|
||||||
@@ -92,20 +86,22 @@ fn store_protocol_tokens(map_protocol_components: BlockTransactionProtocolCompon
|
|||||||
/// is decreased.
|
/// is decreased.
|
||||||
///
|
///
|
||||||
/// ## Note:
|
/// ## Note:
|
||||||
/// - If your protocol emits events that let you calculate balance deltas more
|
/// - If your protocol emits events that let you calculate balance deltas more efficiently you may
|
||||||
/// efficiently you may want to use those instead of raw transfers.
|
/// want to use those instead of raw transfers.
|
||||||
/// - Changes are necessary if your protocol uses native ETH or your component burns or
|
/// - Changes are necessary if your protocol uses native ETH or your component burns or mints tokens
|
||||||
/// mints tokens without emitting transfer events.
|
/// without emitting transfer events.
|
||||||
/// - You may want to ignore LP tokens if your protocol emits transfer events for these
|
/// - You may want to ignore LP tokens if your protocol emits transfer events for these here.
|
||||||
/// here.
|
|
||||||
#[substreams::handlers::map]
|
#[substreams::handlers::map]
|
||||||
fn map_relative_component_balance(params: String, block: eth::v2::Block, store: StoreGetInt64) -> Result<BlockBalanceDeltas> {
|
fn map_relative_component_balance(
|
||||||
|
params: String,
|
||||||
|
block: eth::v2::Block,
|
||||||
|
store: StoreGetInt64,
|
||||||
|
) -> Result<BlockBalanceDeltas> {
|
||||||
let config: DeploymentConfig = serde_qs::from_str(params.as_str())?;
|
let config: DeploymentConfig = serde_qs::from_str(params.as_str())?;
|
||||||
let res = block
|
let res = block
|
||||||
.transactions()
|
.transactions()
|
||||||
.flat_map(|tx| {
|
.flat_map(|tx| {
|
||||||
tx
|
tx.logs_with_calls()
|
||||||
.logs_with_calls()
|
|
||||||
.filter_map(|(log, call)| {
|
.filter_map(|(log, call)| {
|
||||||
let token_addr_hex = hex::encode(&log.address);
|
let token_addr_hex = hex::encode(&log.address);
|
||||||
if !store.has_last(&token_addr_hex) {
|
if !store.has_last(&token_addr_hex) {
|
||||||
@@ -222,19 +218,17 @@ fn map_protocol_changes(
|
|||||||
balances
|
balances
|
||||||
.values()
|
.values()
|
||||||
.for_each(|token_bc_map| {
|
.for_each(|token_bc_map| {
|
||||||
token_bc_map
|
token_bc_map.values().for_each(|bc| {
|
||||||
.values()
|
|
||||||
.for_each(|bc| {
|
|
||||||
// track component balance
|
// track component balance
|
||||||
builder.add_balance_change(bc);
|
builder.add_balance_change(bc);
|
||||||
// track vault contract balance
|
// track vault contract balance
|
||||||
contract_changes.upsert_token_balance(bc.token.as_slice(), bc.balance.as_slice())
|
contract_changes
|
||||||
|
.upsert_token_balance(bc.token.as_slice(), bc.balance.as_slice())
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
builder.add_contract_changes(&contract_changes);
|
builder.add_contract_changes(&contract_changes);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// Extract and insert any storage changes that happened for any of the components.
|
// Extract and insert any storage changes that happened for any of the components.
|
||||||
extract_contract_changes_builder(
|
extract_contract_changes_builder(
|
||||||
&block,
|
&block,
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use substreams_ethereum::pb::eth::v2::{Call, Log, TransactionTrace};
|
use substreams_ethereum::pb::eth::v2::{Call, Log, TransactionTrace};
|
||||||
use tycho_substreams::models::{ChangeType, FinancialType, ImplementationType, ProtocolComponent, ProtocolType};
|
use tycho_substreams::models::{
|
||||||
|
ChangeType, FinancialType, ImplementationType, ProtocolComponent, ProtocolType,
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct DeploymentConfig {
|
pub struct DeploymentConfig {
|
||||||
@@ -48,7 +49,6 @@ pub fn maybe_create_component(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|||||||
Reference in New Issue
Block a user