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

Bundler wallet (#2) #16

Merged
merged 2 commits into from
Nov 25, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target
# Rust
/target
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ anyhow = "1"
async-trait = "0.1"
bytes = { version = "1", features = ["serde"] }
clap = { version = "4", features = ["derive"] }
dirs = "4.0"
educe = { version = "0.4", features = ["Debug", "Default"] }
ethereum-interfaces = { git = "https://github.com/ledgerwatch/interfaces" }
ethereum-types = { version = "0.14", features = ["codec"] }
Expand Down Expand Up @@ -45,3 +46,7 @@ name = "bundler-uopool"
[[bin]]
path = "bin/bundler-rpc.rs"
name = "bundler-rpc"

[[bin]]
path = "bin/create-wallet.rs"
name = "create-wallet"
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
run-bundler:
cargo run -- --mnemonic-file ./src/res/bundler/0xD00D3EEc454D05d3d9bB48532BabED0c89941f17
cargo run -- --mnemonic-file ${HOME}/.aa-bundler/0x129D197b2a989C6798601A49D89a4AEC822A17a3

run-bundler-uopool:
cargo run --bin bundler-uopool

run-bundler-rpc:
cargo run --bin bundler-rpc

run-create-wallet:
cargo run --bin create-wallet -- --output-path ${HOME}/.aa-bundler

cargo-fmt:
cargo fmt --all
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,25 @@ For more information: https://hackmd.io/@Vid201/aa-bundler-rust

## How to run?

Bundler:
Create wallet for bundler:

```bash
cargo run -- --mnemonic-folder ./src/res/bundler
cargo run --bin create-wallet -- --output-path ${HOME}/.aa-bundler
```

User operation pool:
Run bundler (with user operation pool and JSON-RPC API):

```bash
cargo run -- --mnemonic-file ${HOME}/.aa-bundler/0x129D197b2a989C6798601A49D89a4AEC822A17a3
```

Run only user operation pool:

```bash
cargo run --bin bundler-uopool
```

Bundler RPC:
Run only JSON-RPC API:

```bash
cargo run --bin bundler-rpc
Expand Down
4 changes: 2 additions & 2 deletions bin/bundler-rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use aa_bundler::rpc::{eth::EthApiServerImpl, eth_api::EthApiServer};
#[derive(Parser)]
#[clap(
name = "aa-bundler-rpc",
about = "RPC server for EIP-4337 Account Abstraction Bundler"
about = "JSON-RPC server for EIP-4337 Account Abstraction Bundler"
)]
pub struct Opt {
#[clap(long, default_value = "127.0.0.1:4337")]
Expand All @@ -36,7 +36,7 @@ async fn main() -> Result<()> {
.unwrap();

let _jsonrpc_server_handle = jsonrpc_server.start(api.clone())?;
info!("JSONRPC server listening on {}", opt.rpc_listen_address);
info!("JSON-RPC server listening on {}", opt.rpc_listen_address);

pending().await
}
32 changes: 10 additions & 22 deletions bin/bundler.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use aa_bundler::rpc::{eth::EthApiServerImpl, eth_api::EthApiServer};
use aa_bundler::{
bundler::bundler::Bundler,
models::wallet::Wallet,
rpc::{eth::EthApiServerImpl, eth_api::EthApiServer},
};
use anyhow::Result;
use clap::Parser;
use ethers::{
prelude::rand,
signers::{coins_bip39::English, MnemonicBuilder},
};
use expanded_pathbuf::ExpandedPathBuf;
use jsonrpsee::{core::server::rpc_module::Methods, server::ServerBuilder, tracing::info};
use std::{future::pending, panic};
Expand All @@ -16,10 +16,7 @@ use std::{future::pending, panic};
)]
pub struct Opt {
#[clap(long)]
pub mnemonic_file: Option<ExpandedPathBuf>,

#[clap(long, default_value = "./src/res/bundler")]
pub mnemonic_folder: ExpandedPathBuf,
pub mnemonic_file: ExpandedPathBuf,

// #[clap(long, default_value = "127.0.0.1:3000")]
// pub grpc_listen_address: String,
Expand Down Expand Up @@ -52,19 +49,10 @@ fn main() -> Result<()> {
rt.block_on(async move {
info!("Starting AA - Bundler");

// TODO: move this to bundler package
let wallet = if let Some(mnemonic_file) = opt.mnemonic_file {
MnemonicBuilder::<English>::default()
.phrase(mnemonic_file.to_path_buf())
.build()?
} else {
let mut rng = rand::thread_rng();
MnemonicBuilder::<English>::default()
.write_to(opt.mnemonic_folder.to_path_buf())
.build_random(&mut rng)?
};
let wallet = Wallet::from_file(opt.mnemonic_file);
info!("{:?}", wallet.signer);

println!("{:?}", wallet);
let bundler = Bundler::new(wallet);

if !opt.no_uopool {
aa_bundler::uopool::run(opt.uopool_opts).await?;
Expand All @@ -88,7 +76,7 @@ fn main() -> Result<()> {
.unwrap();

let _jsonrpc_server_handle = jsonrpc_server.start(api.clone()).unwrap();
info!("JSONRPC server listening on {}", opt.rpc_listen_address);
info!("JSON-RPC server listening on {}", opt.rpc_listen_address);

pending::<()>().await
}
Expand Down
35 changes: 35 additions & 0 deletions bin/create-wallet.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use aa_bundler::models::wallet::Wallet;
use anyhow::Result;
use clap::Parser;
use dirs::home_dir;
use expanded_pathbuf::ExpandedPathBuf;
use jsonrpsee::tracing::info;
use std::str::FromStr;

#[derive(Parser)]
#[clap(
name = "aa-bundler-create-wallet",
about = "Bundler's wallet creation for EIP-4337 Account Abstraction"
)]
pub struct Opt {
#[clap(long)]
pub output_path: Option<ExpandedPathBuf>,
}

fn main() -> Result<()> {
let opt: Opt = Opt::parse();

tracing_subscriber::fmt::init();

let path = if let Some(output_path) = opt.output_path {
output_path
} else {
ExpandedPathBuf::from_str(home_dir().unwrap().join(".aa-bundler").to_str().unwrap())
.unwrap()
};

let wallet = Wallet::new(path);
info!("{:?}", wallet.signer);

Ok(())
}
11 changes: 11 additions & 0 deletions src/bundler/bundler.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use crate::models::wallet::Wallet;

pub struct Bundler {
pub wallet: Wallet,
}

impl Bundler {
pub fn new(wallet: Wallet) -> Self {
Self { wallet }
}
}
1 change: 1 addition & 0 deletions src/bundler/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod bundler;
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod bundler;
pub mod models;
pub mod rpc;
pub mod types;
Expand Down
1 change: 1 addition & 0 deletions src/models/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub mod chainspec;
pub mod wallet;
34 changes: 34 additions & 0 deletions src/models/wallet.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use ethers::{
prelude::{k256::ecdsa::SigningKey, rand},
signers::{coins_bip39::English, MnemonicBuilder},
};
use expanded_pathbuf::ExpandedPathBuf;
use std::fs;

pub struct Wallet {
pub signer: ethers::signers::Wallet<SigningKey>,
}

impl Wallet {
pub fn new(output_path: ExpandedPathBuf) -> Self {
let mut rng = rand::thread_rng();

fs::create_dir_all(output_path.to_path_buf()).unwrap();

Self {
signer: MnemonicBuilder::<English>::default()
.write_to(output_path.to_path_buf())
.build_random(&mut rng)
.unwrap(),
}
}

pub fn from_file(input_path: ExpandedPathBuf) -> Self {
Self {
signer: MnemonicBuilder::<English>::default()
.phrase(input_path.to_path_buf())
.build()
.unwrap(),
}
}
}
Empty file removed src/res/bundler/.gitkeep
Empty file.

This file was deleted.

6 changes: 3 additions & 3 deletions src/rpc/eth.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{rpc::eth_api::EthApiServer, types::user_operation::UserOperation};
use async_trait::async_trait;
use ethereum_types::{Address, U64};
use jsonrpsee::core::RpcResult;
use jsonrpsee::{core::RpcResult, tracing::info};

pub struct EthApiServerImpl {
pub call_gas_limit: u64,
Expand All @@ -22,8 +22,8 @@ impl EthApiServer for EthApiServerImpl {
user_operation: UserOperation,
entry_point: Address,
) -> RpcResult<bool> {
println!("{:?}", user_operation);
println!("{:?}", entry_point);
info!("{:?}", user_operation);
info!("{:?}", entry_point);
Ok(true)
}
}