-
Notifications
You must be signed in to change notification settings - Fork 2
Implement delegation contract handling in EIP-7702 executor and bundler client #41
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
33a1cb4
Implement delegation contract handling in EIP-7702 executor and bundl…
d4mr b6f91f5
don't fail job on bundler request failure
d4mr b249621
add "pop_id" to lease token
d4mr 80b47ef
don't release lock in case of lock lost error cases
d4mr 2066a8b
retry if fail to fetch delegation target address
d4mr 2cca023
rename ambiguous field
d4mr 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,68 @@ | ||
use std::{ops::Deref, sync::Arc}; | ||
|
||
use alloy::primitives::Address; | ||
use engine_core::{ | ||
chain::Chain, | ||
error::{AlloyRpcErrorToEngineError, EngineError}, | ||
rpc_clients::TwGetDelegationContractResponse, | ||
}; | ||
use moka::future::Cache; | ||
|
||
/// Cache key for delegation contract - uses chain_id as the key since each chain has one delegation contract | ||
#[derive(Hash, Eq, PartialEq, Clone, Debug)] | ||
pub struct DelegationContractCacheKey { | ||
chain_id: u64, | ||
} | ||
|
||
/// Cache for delegation contract addresses to avoid repeated RPC calls | ||
#[derive(Clone)] | ||
pub struct DelegationContractCache { | ||
pub inner: moka::future::Cache<DelegationContractCacheKey, Address>, | ||
} | ||
|
||
impl DelegationContractCache { | ||
/// Create a new delegation contract cache with the provided moka cache | ||
pub fn new(cache: Cache<DelegationContractCacheKey, Address>) -> Self { | ||
Self { inner: cache } | ||
} | ||
|
||
/// Get the delegation contract address for a chain, fetching it if not cached | ||
pub async fn get_delegation_contract<C: Chain>( | ||
&self, | ||
chain: &C, | ||
) -> Result<Address, EngineError> { | ||
let cache_key = DelegationContractCacheKey { | ||
chain_id: chain.chain_id(), | ||
}; | ||
|
||
// Use try_get_with for SWR behavior - this will fetch if not cached or expired | ||
let result = self | ||
.inner | ||
.try_get_with(cache_key, async { | ||
tracing::debug!( | ||
chain_id = chain.chain_id(), | ||
"Fetching delegation contract from bundler" | ||
); | ||
|
||
let TwGetDelegationContractResponse { | ||
delegation_contract, | ||
} = chain | ||
.bundler_client() | ||
.tw_get_delegation_contract() | ||
.await | ||
.map_err(|e| e.to_engine_bundler_error(chain))?; | ||
|
||
tracing::debug!( | ||
chain_id = chain.chain_id(), | ||
delegation_contract = ?delegation_contract, | ||
"Successfully fetched and cached delegation contract" | ||
); | ||
|
||
Ok(delegation_contract) | ||
}) | ||
.await | ||
.map_err(|e: Arc<EngineError>| e.deref().clone())?; | ||
|
||
Ok(result) | ||
} | ||
} |
This file contains hidden or 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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod send; | ||
pub mod confirm; | ||
pub mod confirm; | ||
pub mod delegation_cache; |
Oops, something went wrong.
Oops, something went wrong.
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.
💡 Verification agent
🧩 Analysis chain
Prefer sending [] over () for zero-arg JSON-RPC calls
Some servers reject params: null. Using an empty array is safer and matches other methods here.
Apply this diff:
To verify consistency repo-wide (and catch any other zero-arg calls using ()), run:
🏁 Script executed:
Length of output: 305
Use an empty JSON array for zero-arg RPC calls
Some JSON-RPC servers reject
params: null
. To ensure compatibility and match the rest of our clients, always send[]
instead of()
when there are no parameters.Affected methods:
core/src/rpc_clients/bundler.rs
:tw_get_delegation_contract
core/src/rpc_clients/paymaster.rs
:thirdweb_getUserOperationGasPrice
Proposed diffs:
📝 Committable suggestion
🤖 Prompt for AI Agents