Skip to content

Commit

Permalink
migrate from ethabi to alloy
Browse files Browse the repository at this point in the history
  • Loading branch information
isum committed Nov 1, 2024
1 parent 1642eaf commit 9e19b0d
Show file tree
Hide file tree
Showing 30 changed files with 1,694 additions and 362 deletions.
1,346 changes: 1,268 additions & 78 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ repository = "https://github.com/graphprotocol/graph-node"
license = "MIT OR Apache-2.0"

[workspace.dependencies]
alloy = { version = "0.5.4", features = ["dyn-abi", "json-abi"] }
anyhow = "1.0"
async-graphql = { version = "7.0.11", features = ["chrono", "uuid"] }
async-graphql-axum = "7.0.11"
Expand Down
24 changes: 11 additions & 13 deletions chain/ethereum/src/adapter.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use anyhow::Error;
use ethabi::{Error as ABIError, Function, ParamType, Token};
use graph::blockchain::ChainIdentifier;
use graph::components::subgraph::MappingError;
use graph::data::store::ethereum::call;
Expand Down Expand Up @@ -98,8 +97,8 @@ pub struct ContractCall {
pub contract_name: String,
pub address: Address,
pub block_ptr: BlockPtr,
pub function: Function,
pub args: Vec<Token>,
pub function: graph::abi::Function,
pub args: Vec<graph::abi::DecodedValue>,
pub gas: Option<u32>,
}

Expand All @@ -113,13 +112,12 @@ pub enum EthereumRpcError {

#[derive(Error, Debug)]
pub enum ContractCallError {
#[error("ABI error: {0}")]
ABIError(#[from] ABIError),
/// `Token` is not of expected `ParamType`
#[error("type mismatch, token {0:?} is not of kind {1:?}")]
TypeError(Token, ParamType),
#[error("error encoding input call data: {0}")]
EncodingError(ethabi::Error),
#[error("ABI error: {0:#}")]
ABIError(anyhow::Error),
#[error("type mismatch, decoded value {0:?} is not of kind {1:?}")]
TypeError(graph::abi::DecodedValue, graph::abi::ParamType),
#[error("error encoding input call data: {0:#}")]
EncodingError(anyhow::Error),
#[error("call error: {0}")]
Web3Error(web3::Error),
#[error("ethereum node took too long to perform call")]
Expand Down Expand Up @@ -1174,7 +1172,7 @@ pub trait EthereumAdapter: Send + Sync + 'static {
logger: &Logger,
call: &ContractCall,
cache: Arc<dyn EthereumCallCache>,
) -> Result<(Option<Vec<Token>>, call::Source), ContractCallError>;
) -> Result<(Option<Vec<graph::abi::DecodedValue>>, call::Source), ContractCallError>;

/// Make multiple contract calls in a single batch. The returned `Vec`
/// has results in the same order as the calls in `calls` on input. The
Expand All @@ -1184,7 +1182,7 @@ pub trait EthereumAdapter: Send + Sync + 'static {
logger: &Logger,
calls: &[&ContractCall],
cache: Arc<dyn EthereumCallCache>,
) -> Result<Vec<(Option<Vec<Token>>, call::Source)>, ContractCallError>;
) -> Result<Vec<(Option<Vec<graph::abi::DecodedValue>>, call::Source)>, ContractCallError>;

fn get_balance(
&self,
Expand Down Expand Up @@ -1213,9 +1211,9 @@ mod tests {
use graph::blockchain::TriggerFilter as _;
use graph::firehose::{CallToFilter, CombinedFilter, LogFilter, MultiLogFilter};
use graph::petgraph::graphmap::GraphMap;
use graph::prelude::ethabi::ethereum_types::H256;
use graph::prelude::web3::types::Address;
use graph::prelude::web3::types::Bytes;
use graph::prelude::web3::types::H256;
use graph::prelude::EthereumCall;
use hex::ToHex;
use itertools::Itertools;
Expand Down
Loading

0 comments on commit 9e19b0d

Please sign in to comment.