Files
tycho-protocol-sdk/substreams/ethereum-balancer/src/abi/weighted_pool_tokens_factory.rs
2024-07-25 14:11:29 +01:00

559 lines
21 KiB
Rust

const INTERNAL_ERR: &'static str = "`ethabi_derive` internal error";
/// Contract's functions.
#[allow(dead_code, unused_imports, unused_variables)]
pub mod functions {
use super::INTERNAL_ERR;
#[derive(Debug, Clone, PartialEq)]
pub struct Create {
pub name: String,
pub symbol: String,
pub tokens: Vec<Vec<u8>>,
pub weights: Vec<substreams::scalar::BigInt>,
pub swap_fee_percentage: substreams::scalar::BigInt,
pub oracle_enabled: bool,
pub owner: Vec<u8>,
}
impl Create {
const METHOD_ID: [u8; 4] = [21u8, 150u8, 1u8, 155u8];
pub fn decode(call: &substreams_ethereum::pb::eth::v2::Call) -> Result<Self, String> {
let maybe_data = call.input.get(4..);
if maybe_data.is_none() {
return Err("no data to decode".to_string());
}
let mut values = ethabi::decode(
&[
ethabi::ParamType::String,
ethabi::ParamType::String,
ethabi::ParamType::Array(Box::new(ethabi::ParamType::Address)),
ethabi::ParamType::Array(Box::new(ethabi::ParamType::Uint(256usize))),
ethabi::ParamType::Uint(256usize),
ethabi::ParamType::Bool,
ethabi::ParamType::Address,
],
maybe_data.unwrap(),
)
.map_err(|e| format!("unable to decode call.input: {:?}", e))?;
values.reverse();
Ok(Self {
name: values
.pop()
.expect(INTERNAL_ERR)
.into_string()
.expect(INTERNAL_ERR),
symbol: values
.pop()
.expect(INTERNAL_ERR)
.into_string()
.expect(INTERNAL_ERR),
tokens: values
.pop()
.expect(INTERNAL_ERR)
.into_array()
.expect(INTERNAL_ERR)
.into_iter()
.map(|inner| {
inner
.into_address()
.expect(INTERNAL_ERR)
.as_bytes()
.to_vec()
})
.collect(),
weights: values
.pop()
.expect(INTERNAL_ERR)
.into_array()
.expect(INTERNAL_ERR)
.into_iter()
.map(|inner| {
let mut v = [0 as u8; 32];
inner
.into_uint()
.expect(INTERNAL_ERR)
.to_big_endian(v.as_mut_slice());
substreams::scalar::BigInt::from_unsigned_bytes_be(&v)
})
.collect(),
swap_fee_percentage: {
let mut v = [0 as u8; 32];
values
.pop()
.expect(INTERNAL_ERR)
.into_uint()
.expect(INTERNAL_ERR)
.to_big_endian(v.as_mut_slice());
substreams::scalar::BigInt::from_unsigned_bytes_be(&v)
},
oracle_enabled: values
.pop()
.expect(INTERNAL_ERR)
.into_bool()
.expect(INTERNAL_ERR),
owner: values
.pop()
.expect(INTERNAL_ERR)
.into_address()
.expect(INTERNAL_ERR)
.as_bytes()
.to_vec(),
})
}
pub fn encode(&self) -> Vec<u8> {
let data = ethabi::encode(&[
ethabi::Token::String(self.name.clone()),
ethabi::Token::String(self.symbol.clone()),
{
let v = self
.tokens
.iter()
.map(|inner| ethabi::Token::Address(ethabi::Address::from_slice(&inner)))
.collect();
ethabi::Token::Array(v)
},
{
let v = self
.weights
.iter()
.map(|inner| {
ethabi::Token::Uint(ethabi::Uint::from_big_endian(
match inner.clone().to_bytes_be() {
(num_bigint::Sign::Plus, bytes) => bytes,
(num_bigint::Sign::NoSign, bytes) => bytes,
(num_bigint::Sign::Minus, _) => {
panic!("negative numbers are not supported")
}
}
.as_slice(),
))
})
.collect();
ethabi::Token::Array(v)
},
ethabi::Token::Uint(ethabi::Uint::from_big_endian(
match self
.swap_fee_percentage
.clone()
.to_bytes_be()
{
(num_bigint::Sign::Plus, bytes) => bytes,
(num_bigint::Sign::NoSign, bytes) => bytes,
(num_bigint::Sign::Minus, _) => {
panic!("negative numbers are not supported")
}
}
.as_slice(),
)),
ethabi::Token::Bool(self.oracle_enabled.clone()),
ethabi::Token::Address(ethabi::Address::from_slice(&self.owner)),
]);
let mut encoded = Vec::with_capacity(4 + data.len());
encoded.extend(Self::METHOD_ID);
encoded.extend(data);
encoded
}
pub fn output_call(
call: &substreams_ethereum::pb::eth::v2::Call,
) -> Result<Vec<u8>, String> {
Self::output(call.return_data.as_ref())
}
pub fn output(data: &[u8]) -> Result<Vec<u8>, String> {
let mut values = ethabi::decode(&[ethabi::ParamType::Address], data.as_ref())
.map_err(|e| format!("unable to decode output data: {:?}", e))?;
Ok(values
.pop()
.expect("one output data should have existed")
.into_address()
.expect(INTERNAL_ERR)
.as_bytes()
.to_vec())
}
pub fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool {
match call.input.get(0..4) {
Some(signature) => Self::METHOD_ID == signature,
None => false,
}
}
pub fn call(&self, address: Vec<u8>) -> Option<Vec<u8>> {
use substreams_ethereum::pb::eth::rpc;
let rpc_calls = rpc::RpcCalls {
calls: vec![rpc::RpcCall { to_addr: address, data: self.encode() }],
};
let responses = substreams_ethereum::rpc::eth_call(&rpc_calls).responses;
let response = responses
.get(0)
.expect("one response should have existed");
if response.failed {
return None;
}
match Self::output(response.raw.as_ref()) {
Ok(data) => Some(data),
Err(err) => {
use substreams_ethereum::Function;
substreams::log::info!(
"Call output for function `{}` failed to decode with error: {}",
Self::NAME,
err
);
None
}
}
}
}
impl substreams_ethereum::Function for Create {
const NAME: &'static str = "create";
fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool {
Self::match_call(call)
}
fn decode(call: &substreams_ethereum::pb::eth::v2::Call) -> Result<Self, String> {
Self::decode(call)
}
fn encode(&self) -> Vec<u8> {
self.encode()
}
}
impl substreams_ethereum::rpc::RPCDecodable<Vec<u8>> for Create {
fn output(data: &[u8]) -> Result<Vec<u8>, String> {
Self::output(data)
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct GetPauseConfiguration {}
impl GetPauseConfiguration {
const METHOD_ID: [u8; 4] = [45u8, 164u8, 124u8, 64u8];
pub fn decode(call: &substreams_ethereum::pb::eth::v2::Call) -> Result<Self, String> {
Ok(Self {})
}
pub fn encode(&self) -> Vec<u8> {
let data = ethabi::encode(&[]);
let mut encoded = Vec::with_capacity(4 + data.len());
encoded.extend(Self::METHOD_ID);
encoded.extend(data);
encoded
}
pub fn output_call(
call: &substreams_ethereum::pb::eth::v2::Call,
) -> Result<(substreams::scalar::BigInt, substreams::scalar::BigInt), String> {
Self::output(call.return_data.as_ref())
}
pub fn output(
data: &[u8],
) -> Result<(substreams::scalar::BigInt, substreams::scalar::BigInt), String> {
let mut values = ethabi::decode(
&[ethabi::ParamType::Uint(256usize), ethabi::ParamType::Uint(256usize)],
data.as_ref(),
)
.map_err(|e| format!("unable to decode output data: {:?}", e))?;
values.reverse();
Ok((
{
let mut v = [0 as u8; 32];
values
.pop()
.expect(INTERNAL_ERR)
.into_uint()
.expect(INTERNAL_ERR)
.to_big_endian(v.as_mut_slice());
substreams::scalar::BigInt::from_unsigned_bytes_be(&v)
},
{
let mut v = [0 as u8; 32];
values
.pop()
.expect(INTERNAL_ERR)
.into_uint()
.expect(INTERNAL_ERR)
.to_big_endian(v.as_mut_slice());
substreams::scalar::BigInt::from_unsigned_bytes_be(&v)
},
))
}
pub fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool {
match call.input.get(0..4) {
Some(signature) => Self::METHOD_ID == signature,
None => false,
}
}
pub fn call(
&self,
address: Vec<u8>,
) -> Option<(substreams::scalar::BigInt, substreams::scalar::BigInt)> {
use substreams_ethereum::pb::eth::rpc;
let rpc_calls = rpc::RpcCalls {
calls: vec![rpc::RpcCall { to_addr: address, data: self.encode() }],
};
let responses = substreams_ethereum::rpc::eth_call(&rpc_calls).responses;
let response = responses
.get(0)
.expect("one response should have existed");
if response.failed {
return None;
}
match Self::output(response.raw.as_ref()) {
Ok(data) => Some(data),
Err(err) => {
use substreams_ethereum::Function;
substreams::log::info!(
"Call output for function `{}` failed to decode with error: {}",
Self::NAME,
err
);
None
}
}
}
}
impl substreams_ethereum::Function for GetPauseConfiguration {
const NAME: &'static str = "getPauseConfiguration";
fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool {
Self::match_call(call)
}
fn decode(call: &substreams_ethereum::pb::eth::v2::Call) -> Result<Self, String> {
Self::decode(call)
}
fn encode(&self) -> Vec<u8> {
self.encode()
}
}
impl
substreams_ethereum::rpc::RPCDecodable<(
substreams::scalar::BigInt,
substreams::scalar::BigInt,
)> for GetPauseConfiguration
{
fn output(
data: &[u8],
) -> Result<(substreams::scalar::BigInt, substreams::scalar::BigInt), String> {
Self::output(data)
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct GetVault {}
impl GetVault {
const METHOD_ID: [u8; 4] = [141u8, 146u8, 138u8, 248u8];
pub fn decode(call: &substreams_ethereum::pb::eth::v2::Call) -> Result<Self, String> {
Ok(Self {})
}
pub fn encode(&self) -> Vec<u8> {
let data = ethabi::encode(&[]);
let mut encoded = Vec::with_capacity(4 + data.len());
encoded.extend(Self::METHOD_ID);
encoded.extend(data);
encoded
}
pub fn output_call(
call: &substreams_ethereum::pb::eth::v2::Call,
) -> Result<Vec<u8>, String> {
Self::output(call.return_data.as_ref())
}
pub fn output(data: &[u8]) -> Result<Vec<u8>, String> {
let mut values = ethabi::decode(&[ethabi::ParamType::Address], data.as_ref())
.map_err(|e| format!("unable to decode output data: {:?}", e))?;
Ok(values
.pop()
.expect("one output data should have existed")
.into_address()
.expect(INTERNAL_ERR)
.as_bytes()
.to_vec())
}
pub fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool {
match call.input.get(0..4) {
Some(signature) => Self::METHOD_ID == signature,
None => false,
}
}
pub fn call(&self, address: Vec<u8>) -> Option<Vec<u8>> {
use substreams_ethereum::pb::eth::rpc;
let rpc_calls = rpc::RpcCalls {
calls: vec![rpc::RpcCall { to_addr: address, data: self.encode() }],
};
let responses = substreams_ethereum::rpc::eth_call(&rpc_calls).responses;
let response = responses
.get(0)
.expect("one response should have existed");
if response.failed {
return None;
}
match Self::output(response.raw.as_ref()) {
Ok(data) => Some(data),
Err(err) => {
use substreams_ethereum::Function;
substreams::log::info!(
"Call output for function `{}` failed to decode with error: {}",
Self::NAME,
err
);
None
}
}
}
}
impl substreams_ethereum::Function for GetVault {
const NAME: &'static str = "getVault";
fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool {
Self::match_call(call)
}
fn decode(call: &substreams_ethereum::pb::eth::v2::Call) -> Result<Self, String> {
Self::decode(call)
}
fn encode(&self) -> Vec<u8> {
self.encode()
}
}
impl substreams_ethereum::rpc::RPCDecodable<Vec<u8>> for GetVault {
fn output(data: &[u8]) -> Result<Vec<u8>, String> {
Self::output(data)
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct IsPoolFromFactory {
pub pool: Vec<u8>,
}
impl IsPoolFromFactory {
const METHOD_ID: [u8; 4] = [102u8, 52u8, 183u8, 83u8];
pub fn decode(call: &substreams_ethereum::pb::eth::v2::Call) -> Result<Self, String> {
let maybe_data = call.input.get(4..);
if maybe_data.is_none() {
return Err("no data to decode".to_string());
}
let mut values = ethabi::decode(&[ethabi::ParamType::Address], maybe_data.unwrap())
.map_err(|e| format!("unable to decode call.input: {:?}", e))?;
values.reverse();
Ok(Self {
pool: values
.pop()
.expect(INTERNAL_ERR)
.into_address()
.expect(INTERNAL_ERR)
.as_bytes()
.to_vec(),
})
}
pub fn encode(&self) -> Vec<u8> {
let data =
ethabi::encode(&[ethabi::Token::Address(ethabi::Address::from_slice(&self.pool))]);
let mut encoded = Vec::with_capacity(4 + data.len());
encoded.extend(Self::METHOD_ID);
encoded.extend(data);
encoded
}
pub fn output_call(call: &substreams_ethereum::pb::eth::v2::Call) -> Result<bool, String> {
Self::output(call.return_data.as_ref())
}
pub fn output(data: &[u8]) -> Result<bool, String> {
let mut values = ethabi::decode(&[ethabi::ParamType::Bool], data.as_ref())
.map_err(|e| format!("unable to decode output data: {:?}", e))?;
Ok(values
.pop()
.expect("one output data should have existed")
.into_bool()
.expect(INTERNAL_ERR))
}
pub fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool {
match call.input.get(0..4) {
Some(signature) => Self::METHOD_ID == signature,
None => false,
}
}
pub fn call(&self, address: Vec<u8>) -> Option<bool> {
use substreams_ethereum::pb::eth::rpc;
let rpc_calls = rpc::RpcCalls {
calls: vec![rpc::RpcCall { to_addr: address, data: self.encode() }],
};
let responses = substreams_ethereum::rpc::eth_call(&rpc_calls).responses;
let response = responses
.get(0)
.expect("one response should have existed");
if response.failed {
return None;
}
match Self::output(response.raw.as_ref()) {
Ok(data) => Some(data),
Err(err) => {
use substreams_ethereum::Function;
substreams::log::info!(
"Call output for function `{}` failed to decode with error: {}",
Self::NAME,
err
);
None
}
}
}
}
impl substreams_ethereum::Function for IsPoolFromFactory {
const NAME: &'static str = "isPoolFromFactory";
fn match_call(call: &substreams_ethereum::pb::eth::v2::Call) -> bool {
Self::match_call(call)
}
fn decode(call: &substreams_ethereum::pb::eth::v2::Call) -> Result<Self, String> {
Self::decode(call)
}
fn encode(&self) -> Vec<u8> {
self.encode()
}
}
impl substreams_ethereum::rpc::RPCDecodable<bool> for IsPoolFromFactory {
fn output(data: &[u8]) -> Result<bool, String> {
Self::output(data)
}
}
}
/// Contract's events.
#[allow(dead_code, unused_imports, unused_variables)]
pub mod events {
use super::INTERNAL_ERR;
#[derive(Debug, Clone, PartialEq)]
pub struct PoolCreated {
pub pool: Vec<u8>,
}
impl PoolCreated {
const TOPIC_ID: [u8; 32] = [
131u8, 164u8, 143u8, 188u8, 252u8, 153u8, 19u8, 53u8, 49u8, 78u8, 116u8, 208u8, 73u8,
106u8, 171u8, 106u8, 25u8, 135u8, 233u8, 146u8, 221u8, 200u8, 93u8, 221u8, 188u8,
196u8, 214u8, 221u8, 110u8, 242u8, 233u8, 252u8,
];
pub fn match_log(log: &substreams_ethereum::pb::eth::v2::Log) -> bool {
if log.topics.len() != 2usize {
return false;
}
if log.data.len() != 0usize {
return false;
}
return log
.topics
.get(0)
.expect("bounds already checked")
.as_ref()
== Self::TOPIC_ID;
}
pub fn decode(log: &substreams_ethereum::pb::eth::v2::Log) -> Result<Self, String> {
Ok(Self {
pool: ethabi::decode(&[ethabi::ParamType::Address], log.topics[1usize].as_ref())
.map_err(|e| {
format!(
"unable to decode param 'pool' from topic of type 'address': {:?}",
e
)
})?
.pop()
.expect(INTERNAL_ERR)
.into_address()
.expect(INTERNAL_ERR)
.as_bytes()
.to_vec(),
})
}
}
impl substreams_ethereum::Event for PoolCreated {
const NAME: &'static str = "PoolCreated";
fn match_log(log: &substreams_ethereum::pb::eth::v2::Log) -> bool {
Self::match_log(log)
}
fn decode(log: &substreams_ethereum::pb::eth::v2::Log) -> Result<Self, String> {
Self::decode(log)
}
}
}