Skip to content

Commit

Permalink
Bundler wallet (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vid201 committed Nov 24, 2022
1 parent d1f09e4 commit d3dab9f
Show file tree
Hide file tree
Showing 13 changed files with 104 additions and 30 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
# Rust
/target

# bundler wallets
/src/res/bundler/0x*
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,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 ./src/res/bundler/0xF78bB01dFd478608F5738fB0560642b2806D295E

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-folder ./src/res/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-folder ./src/res/bundler
```

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

```bash
cargo run -- --mnemonic-file ./src/res/bundler/0xF78bB01dFd478608F5738fB0560642b2806D295E
```

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);
println!("{:?}", 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
25 changes: 25 additions & 0 deletions bin/create-wallet.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use aa_bundler::models::wallet::Wallet;
use anyhow::Result;
use clap::Parser;
use expanded_pathbuf::ExpandedPathBuf;

#[derive(Parser)]
#[clap(
name = "aa-bundler-create-wallet",
about = "Bundler's wallet creation for EIP-4337 Account Abstraction"
)]
pub struct Opt {
#[clap(long, default_value = "./src/res/bundler")]
pub output_folder: ExpandedPathBuf,
}

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

tracing_subscriber::fmt::init();

let wallet = Wallet::new(opt.output_folder);
println!("{:?}", 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;
31 changes: 31 additions & 0 deletions src/models/wallet.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use ethers::{
prelude::{k256::ecdsa::SigningKey, rand},
signers::{coins_bip39::English, MnemonicBuilder},
};
use expanded_pathbuf::ExpandedPathBuf;

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

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

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(),
}
}
}
1 change: 0 additions & 1 deletion src/res/bundler/0xD00D3EEc454D05d3d9bB48532BabED0c89941f17

This file was deleted.

0 comments on commit d3dab9f

Please sign in to comment.