An ether-rs middleware to craft UserOperations

Overview

Ethers UserOp

An ether-rs middleware to craft UserOperations

Pre-requisites

Geth (tested with v1.12.2).

Use

To start a Silius bundler with user operation pool and JSON-RPC API with default config at 127.0.0.1:3000 on Geth Testnet

cargo run --bin ethuo bundler test

To generate a random key and address(generated key will be updated in config.json)

cargo run --bin ethuo wallet new-key

To generate a counter-factual address(generated address will be updated in config.json)

cargo run --bin ethuo wallet new-wallet-address

To use UserOpMiddleware in your code, see example

use ethers::{
    contract::abigen,
    providers::{Http, Provider},
    signers::Signer,
    types::{Address, U256},
};
use ethers_userop::{
    consts::{GETH_CHAIN_ID, GETH_ENTRY_POINT_ADDRESS, GETH_WETH_ADDRESS, SALT, SEED_PHRASE},
    UserOpMiddleware,
};
use silius_primitives::Wallet as UoWallet;
use std::thread;
use std::time::Duration;

abigen!(WETH, "src/abi/WETH.json",);

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    env_logger::Builder::new()
        .filter_level(log::LevelFilter::Info)
        .init();
    // Setup the environment
    let eth_client_address = "http://localhost:8545".to_string();
    let seed = SEED_PHRASE.to_string();
    let provider = Provider::<Http>::try_from(eth_client_address.to_string())?;
    let rpc_address = format!("http://{}", "127.0.0.1:3000");
    let chain_id = GETH_CHAIN_ID; // Geth testnet
    let uo_wallet = UoWallet::from_phrase(seed.as_str(), &U256::from(chain_id), false).unwrap();

    let signer_wallet_address = uo_wallet.clone().signer.address();
    let wallet_name = "simple-account-test";

    // Instantiate a UserOpMiddleware
    let mut uo_middleware: UserOpMiddleware<Provider<Http>> = UserOpMiddleware::new(
        provider,
        GETH_ENTRY_POINT_ADDRESS.parse::<Address>().unwrap(),
        rpc_address,
        uo_wallet.clone(),
    );

    // Deploy a smart contract wallet
    let (uo_hash, scw_address) = uo_middleware
        .deploy_scw(wallet_name.into(), 10u64, SALT)
        .await?;
    println!(
        "Smart contract wallet deployed at {:x} 
        : {:?}",
        scw_address, uo_hash
    );

    // Force to wait for the smart contract wallet to be deployed on the next block
    thread::sleep(Duration::from_secs(12));

    // Send Eth
    let uo_hash = uo_middleware
        .send_eth(scw_address, wallet_name, signer_wallet_address, 1u64)
        .await?;
    println!("Sent ETH to {}: {:?}", signer_wallet_address, uo_hash);

    // Force to wait for the smart contract wallet to be deployed on the next block
    thread::sleep(Duration::from_secs(12));

    // Calling Weth contract to deposit Eth
    let weth = WETH::new(
        GETH_WETH_ADDRESS.parse::<Address>()?,
        uo_middleware.clone().into(),
    );

    let mut deposit = weth.deposit().tx;
    deposit.set_value(U256::from(100u64));
    let uo_hash = uo_middleware
        .call(wallet_name, scw_address, deposit)
        .await?;
    println!("Deposited ETH into WETH contract: {:?}", uo_hash);

    Ok(())
}
You might also like...
🔎 Prometheus metrics middleware for Axum

Axum-Prometheus A Prometheus middleware to collect HTTP metrics for Axum applications. axum-prometheus relies on metrics_exporter_prometheus as a back

Middleware/ios shortcut to setup alarms automatically based on the first class

Webuntis alarm This is a small little "middleware" / web server intended to connect to a webuntis timetable used in german schools which i wrote when

Rate Limiting middleware for Tower/Axum/Tonic/Hyper utilizing the governor crate

A Tower service and layer that provides a rate-limiting backend by governor. Based heavily on the work done for actix-governor. Works with Axum, Hyper

Ethers-rs CCIP-Read Middleware

Ethers-rs CCIP-Read Middleware Ready to dive into the world of cross-chain data access? Look no further! This Rust library provides an Ethers middlewa

Write Rack middleware in Rust.

RacksOnRacks Write Rack middleware in Rust. This repo is a proof of concept and should be used as an example. The best way to use this at the moment w

Drop-in replacement for the Actix Web HTTP Logger middleware

actix-contrib-logger Logger middleware for the Actix Web framework. Actually it's a copy & paste from the official Logger middleware (original source

🥠 Sessions as a `tower` and `axum` middleware.

tower-sessions 🥠 Sessions as a `tower` and `axum` middleware. 🎨 Overview This crate provides sessions, key-value pairs associated with a site visito

Axum + JWT authentication Middleware that allows you to start building your application fast

axum_jwt_ware Integration Guide Simple Axum + JWT authentication middleware with implemented Login and refresh token. Goal I aim to simplify the proce

Owner
null
Ethers-rs CCIP-Read Middleware

Ethers-rs CCIP-Read Middleware Ready to dive into the world of cross-chain data access? Look no further! This Rust library provides an Ethers middlewa

Ethereum Name Service (ENS) 14 May 28, 2023
An ether-rs middleware to access reth's db directly, bypassing JSON-RPC

Octane A ether-rs middleware for reth that bypasses JSON-RPC allowing for faster db queries. Work in Progress! Please note that Octane is currently in

Sorella Labs 75 Jun 4, 2023
Wrapper around reqwest to allow for client middleware chains.

reqwest-middleware A crate implementing a wrapper around reqwest to allow for client middleware chains. Overview The reqwest-middleware client exposes

TrueLayer 113 Dec 7, 2022
An Ethers middleware for submitting Flashbots bundles

Ethers Flashbots An Ethers middleware to send transactions as Flashbots bundles. Installation Add ethers-flashbots to your Cargo.toml. # This is the d

Oliver Nordbjerg 267 Jan 4, 2023
A cookie manager middleware built on top of tower.

tower-cookies A cookie manager middleware built on top of tower. Example With axum: use axum::{handler::get, Router}; use std::net::SocketAddr; use to

Imbolc 47 Dec 9, 2022
Handlebars middleware for Iron web framework

handlebars-iron Handlebars middleware for the Iron web framework. This library, together with handlebars, iron and hyper, works on both stable and nig

Ning Sun 118 Jun 28, 2022
In-progress extractors and middleware for Actix Web

actix-web-lab Experimental extractors, middleware, and other extras for possible inclusion in Actix Web. Things To Know About This Crate It will never

Rob Ede 51 Dec 20, 2022
Tide middleware for Diesel pooled connections & transactions

tide-diesel Tide middleware for Diesel pooled connections & transactions. A Tide middleware which holds a pool of Diesel database connections, and aut

Bradford Toney 2 Feb 7, 2022
Rate limit middleware for Poem framework

Rate limit middleware for Poem framework Usage Check examples, poem-ratelimit is available on crates.io. A yaml configuration file is used to set limi

Devs Day 5 Sep 22, 2022
Rate limit middleware for poem web framework

Rate limit middleware for Poem framework Usage Check examples, poem-ratelimit is available on crates.io. A yaml configuration file is used to set limi

Rui Li 5 Sep 22, 2022