-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(
anvil
): wallet_
namespace + inject P256BatchDelegation + exe…
…cutor (#9110) * feat(anvil-rpc): wallet_ namespace * feat: init sponsor and delegation contract in backend * wallet_sendTransaction * wallet_sendTransaction * update p256 runtime code * nit P256_DELEGATION_CONTRACT addr * use correct runtime codes * fix * doc nits * fix * feat: anvil_addCapability * nit * feat: anvil_setExecutor * tests
- Loading branch information
1 parent
ca49147
commit 08021d9
Showing
8 changed files
with
445 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -38,6 +38,7 @@ bytes = "1.4" | |
|
||
# misc | ||
rand = "0.8" | ||
thiserror.workspace = true | ||
|
||
[features] | ||
default = ["serde"] | ||
|
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,79 @@ | ||
use alloy_primitives::{map::HashMap, Address, ChainId, U64}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
/// The capability to perform [EIP-7702][eip-7702] delegations, sponsored by the sequencer. | ||
/// | ||
/// The sequencer will only perform delegations, and act on behalf of delegated accounts, if the | ||
/// account delegates to one of the addresses specified within this capability. | ||
/// | ||
/// [eip-7702]: https://eips.ethereum.org/EIPS/eip-7702 | ||
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize, Default)] | ||
pub struct DelegationCapability { | ||
/// A list of valid delegation contracts. | ||
pub addresses: Vec<Address>, | ||
} | ||
|
||
/// Wallet capabilities for a specific chain. | ||
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize, Default)] | ||
pub struct Capabilities { | ||
/// The capability to delegate. | ||
pub delegation: DelegationCapability, | ||
} | ||
|
||
/// A map of wallet capabilities per chain ID. | ||
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize, Default)] | ||
pub struct WalletCapabilities(HashMap<U64, Capabilities>); | ||
|
||
impl WalletCapabilities { | ||
/// Get the capabilities of the wallet API for the specified chain ID. | ||
pub fn get(&self, chain_id: ChainId) -> Option<&Capabilities> { | ||
self.0.get(&U64::from(chain_id)) | ||
} | ||
|
||
pub fn insert(&mut self, chain_id: ChainId, capabilities: Capabilities) { | ||
self.0.insert(U64::from(chain_id), capabilities); | ||
} | ||
} | ||
|
||
#[derive(Debug, thiserror::Error)] | ||
pub enum WalletError { | ||
/// The transaction value is not 0. | ||
/// | ||
/// The value should be 0 to prevent draining the sequencer. | ||
#[error("tx value not zero")] | ||
ValueNotZero, | ||
/// The from field is set on the transaction. | ||
/// | ||
/// Requests with the from field are rejected, since it is implied that it will always be the | ||
/// sequencer. | ||
#[error("tx from field is set")] | ||
FromSet, | ||
/// The nonce field is set on the transaction. | ||
/// | ||
/// Requests with the nonce field set are rejected, as this is managed by the sequencer. | ||
#[error("tx nonce is set")] | ||
NonceSet, | ||
/// An authorization item was invalid. | ||
/// | ||
/// The item is invalid if it tries to delegate an account to a contract that is not | ||
/// whitelisted. | ||
#[error("invalid authorization address")] | ||
InvalidAuthorization, | ||
/// The to field of the transaction was invalid. | ||
/// | ||
/// The destination is invalid if: | ||
/// | ||
/// - There is no bytecode at the destination, or | ||
/// - The bytecode is not an EIP-7702 delegation designator, or | ||
/// - The delegation designator points to a contract that is not whitelisted | ||
#[error("the destination of the transaction is not a delegated account")] | ||
IllegalDestination, | ||
/// The transaction request was invalid. | ||
/// | ||
/// This is likely an internal error, as most of the request is built by the sequencer. | ||
#[error("invalid tx request")] | ||
InvalidTransactionRequest, | ||
/// An internal error occurred. | ||
#[error("internal error")] | ||
InternalError, | ||
} |
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
Oops, something went wrong.