Skip to content
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: removed wallet_getCapabilities #104

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 36 additions & 7 deletions crates/e2e-tests/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{collections::BTreeMap, sync::LazyLock};
use std::{collections::BTreeMap, str::FromStr, sync::LazyLock};

use alloy::{
eips::eip7702::Authorization,
Expand Down Expand Up @@ -27,6 +27,7 @@ static SEQUENCER_RPC: LazyLock<Url> = LazyLock::new(|| {
.expect("failed to parse SEQUENCER_RPC env var")
});


#[tokio::test]
async fn assert_chain_advances() -> Result<(), Box<dyn std::error::Error>> {
if !ci_info::is_ci() {
Expand Down Expand Up @@ -54,11 +55,25 @@ async fn test_wallet_api() -> Result<(), Box<dyn std::error::Error>> {
"59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d"
))?;

let capabilities: BTreeMap<U256, BTreeMap<String, BTreeMap<String, Vec<Address>>>> =
provider.client().request_noparams("wallet_getCapabilities").await?;

let chain_id = U256::from(provider.get_chain_id().await?);

let capabilities = {
let mut innermost_tree = BTreeMap::new();
innermost_tree.insert(
"addresses".to_string(),
vec![Address::from_str(&std::env::var("DELEGATION_ADDRESS").unwrap()).unwrap()],
);

let mut inner_tree = BTreeMap::new();
inner_tree.insert("delegation".to_string(), innermost_tree);

let mut capabilities = BTreeMap::new();
capabilities.insert(chain_id, inner_tree);

capabilities
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should remove the capabilities structs entirely, we don't need them anymore, and instead use a const address here or an env var

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to clarify, you mean to remove WalletCapabilities right?

#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)]
pub struct WalletCapabilities(pub HashMap<U64, Capabilities>);

I see its not really being used anywhere else in the code

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes



let delegation_address =
capabilities.get(&chain_id).unwrap().get("delegation").unwrap().get("addresses").unwrap()
[0];
Expand Down Expand Up @@ -98,11 +113,25 @@ async fn test_new_wallet_api() -> Result<(), Box<dyn std::error::Error>> {
"59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d"
))?;

let capabilities: BTreeMap<U256, BTreeMap<String, BTreeMap<String, Vec<Address>>>> =
provider.client().request_noparams("wallet_getCapabilities").await?;

let chain_id = U256::from(provider.get_chain_id().await?);

let capabilities = {
let mut innermost_tree = BTreeMap::new();
innermost_tree.insert(
"addresses".to_string(),
vec![Address::from_str("0x90f79bf6eb2c4f870365e785982e1f101e93b906").unwrap()],
// vec![Address::from_str(&std::env::var("DELEGATION_ADDRESS").unwrap()).unwrap()],
);

let mut inner_tree = BTreeMap::new();
inner_tree.insert("delegation".to_string(), innermost_tree);

let mut capabilities = BTreeMap::new();
capabilities.insert(chain_id, inner_tree);

capabilities
};

let delegation_address =
capabilities.get(&chain_id).unwrap().get("delegation").unwrap().get("addresses").unwrap()
[0];
Expand Down
14 changes: 0 additions & 14 deletions crates/wallet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,6 @@ impl WalletCapabilities {
#[cfg_attr(not(test), rpc(server, namespace = "wallet"))]
#[cfg_attr(test, rpc(server, client, namespace = "wallet"))]
pub trait OdysseyWalletApi {
/// Get the capabilities of the wallet.
///
/// Currently the only capability is [`DelegationCapability`].
///
/// See also [EIP-5792][eip-5792].
///
/// [eip-5792]: https://eips.ethereum.org/EIPS/eip-5792
#[method(name = "getCapabilities")]
fn get_capabilities(&self) -> RpcResult<WalletCapabilities>;

/// Send a sequencer-sponsored transaction.
///
/// The transaction will only be processed if:
Expand Down Expand Up @@ -200,10 +190,6 @@ where
Provider: StateProviderFactory + Send + Sync + 'static,
Eth: FullEthApi + Send + Sync + 'static,
{
fn get_capabilities(&self) -> RpcResult<WalletCapabilities> {
trace!(target: "rpc::wallet", "Serving wallet_getCapabilities");
Ok(self.inner.capabilities.clone())
}

async fn send_transaction(&self, mut request: TransactionRequest) -> RpcResult<TxHash> {
trace!(target: "rpc::wallet", ?request, "Serving odyssey_sendTransaction");
Expand Down