-
Notifications
You must be signed in to change notification settings - Fork 796
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: eth_callMany #2664
Open
hjawhar
wants to merge
6
commits into
gakonst:master
Choose a base branch
from
hjawhar:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat: eth_callMany #2664
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
966c412
Init draft for erigon - eth_callMany implementation
hjawhar 9e84749
Reverted formatting
hjawhar 8f46389
Removed debugging and printing data
hjawhar c5b8ae3
Added erigon reference
hjawhar 88d36d8
Updated inputs and models to match erigon's CallMany methods
hjawhar d5b345e
Merge remote-tracking branch 'upstream/master'
hjawhar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use ethabi::ethereum_types::U256; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use crate::types::{transaction::eip2718::TypedTransaction, BlockNumber, Bytes}; | ||
|
||
#[derive(Serialize, Debug, Clone)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct EthCallManyBlockOverride { | ||
pub block_number: U256, | ||
} | ||
|
||
#[derive(Serialize, Debug, Clone)] | ||
pub struct EthCallManyBundle { | ||
pub transactions: Vec<TypedTransaction>, | ||
#[serde(default, skip_serializing_if = "Option::is_none")] | ||
pub block_override: Option<EthCallManyBlockOverride>, | ||
} | ||
|
||
#[derive(Serialize, Debug, Clone)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct EthCallManyStateContext { | ||
pub block_number: BlockNumber, | ||
#[serde(default, skip_serializing_if = "Option::is_none")] | ||
pub transaction_index: Option<i32>, | ||
} | ||
|
||
#[derive(Serialize, Debug, Clone)] | ||
pub struct EthCallManyBalanceDiff { | ||
pub balance: U256, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug, Clone)] | ||
pub struct EthCallManyOutputEmpty {} | ||
Comment on lines
+32
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. redundant type? |
||
|
||
#[derive(Serialize, Deserialize, Debug, Clone)] | ||
pub struct EthCallManyOutput { | ||
pub value: Option<Bytes>, | ||
pub error: Option<EthCallManyOutputEmpty>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be a string |
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
use ethers::{ | ||
providers::{Http, Middleware, Provider}, | ||
types::{ | ||
transaction::eip2718::TypedTransaction, Address, BlockNumber, Bytes, | ||
EthCallManyBalanceDiff, EthCallManyBundle, EthCallManyStateContext, TransactionRequest, | ||
H160, U256, | ||
}, | ||
}; | ||
use eyre::Result; | ||
use std::{collections::HashMap, str::FromStr}; | ||
|
||
/// use `eth_callMany` to simulate output | ||
/// requires, a valid endpoint in `RPC_URL` env var that supports `eth_callMany` (Erigon) | ||
/// Example 1: of approving SHIBA INU (token) with Uniswap V2 as spender returns bool | ||
/// Expected output: 0x0000000000000000000000000000000000000000000000000000000000000001 | ||
/// Example 2: transferring tokens while not having enough balance | ||
/// Expected output: Empty error object | ||
#[tokio::main] | ||
async fn main() -> Result<()> { | ||
if let Ok(url) = std::env::var("RPC_URL") { | ||
let client = Provider::<Http>::try_from(url)?; | ||
let block_number = client.get_block_number().await.unwrap(); | ||
let gas_fees = client.get_gas_price().await.unwrap(); | ||
{ | ||
let tx = TransactionRequest::new().from(Address::from_str("0xdeadbeef29292929192939494959594933929292").unwrap()).to(Address::from_str("0x95ad61b0a150d79219dcf64e1e6cc01f0b64c4ce").unwrap()).gas_price(gas_fees).gas("0x7a120").data(Bytes::from_str("0x095ea7b30000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d0000000000000000000000000000000000000000b3827a7d5189a7b76dac0000").unwrap()); | ||
let req = vec![EthCallManyBundle { | ||
transactions: vec![TypedTransaction::Legacy(tx)], | ||
block_override: None, | ||
}]; | ||
let mut hashmap: HashMap<H160, Option<EthCallManyBalanceDiff>> = HashMap::new(); | ||
hashmap.insert( | ||
"0xDeaDbEEF29292929192939494959594933929292".parse::<H160>().unwrap(), | ||
Some(EthCallManyBalanceDiff { | ||
balance: U256::from( | ||
"0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", | ||
), | ||
}), | ||
); | ||
|
||
let state_context = EthCallManyStateContext { | ||
block_number: BlockNumber::Number(block_number), | ||
transaction_index: None, | ||
}; | ||
let traces = client.eth_call_many(req, state_context, Some(hashmap)).await?; | ||
println!("{traces:?}"); | ||
} | ||
|
||
{ | ||
let tx = TransactionRequest::new().from(Address::from_str("0xdeadbeef29292929192939494959594933929292").unwrap()).to(Address::from_str("0x95ad61b0a150d79219dcf64e1e6cc01f0b64c4ce").unwrap()).gas_price(gas_fees).gas("0x7a120").data(Bytes::from_str("0xa9059cbb000000000000000000000000deadbeef292929291929394949595949339292920000000000000000000000000000000000000000000000000000000000000005").unwrap()); | ||
let req = vec![EthCallManyBundle { | ||
transactions: vec![TypedTransaction::Legacy(tx)], | ||
block_override: None, | ||
}]; | ||
let mut hashmap: HashMap<H160, Option<EthCallManyBalanceDiff>> = HashMap::new(); | ||
hashmap.insert( | ||
"0xDeaDbEEF29292929192939494959594933929292".parse::<H160>().unwrap(), | ||
Some(EthCallManyBalanceDiff { | ||
balance: U256::from( | ||
"0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", | ||
), | ||
}), | ||
); | ||
|
||
let state_context = EthCallManyStateContext { | ||
block_number: BlockNumber::Number(block_number), | ||
transaction_index: None, | ||
}; | ||
let traces = client.eth_call_many(req, state_context, Some(hashmap)).await?; | ||
println!("{traces:?}"); | ||
} | ||
} | ||
|
||
Ok(()) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to have this as Option, in case we need more fields