Skip to content

Commit

Permalink
feat: functional L2 faucet!
Browse files Browse the repository at this point in the history
  • Loading branch information
Zk2u committed Sep 18, 2024
1 parent fabdc11 commit f735e1b
Show file tree
Hide file tree
Showing 8 changed files with 320 additions and 47 deletions.
150 changes: 147 additions & 3 deletions Cargo.lock

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

5 changes: 1 addition & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ resolver = "2"
members = [".", "utils/html-solver"]

[dependencies]
alloy = { version = "0.3.5", default-features = false, features = [
"std",
"rpc-client-ws",
] }
alloy = { version = "0.3.5", features = ["std", "rpc-client-ws", "network", "signers", "signer-local", "providers", "rpc-types"] }
arrayvec = "0.7.6"
axum = { version = "0.7.5", features = ["http2"] }
axum-client-ip = "0.6.0"
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,14 @@ Once you find a solution, hex encode it and use it in a claim for either L1 or L

Where `l1_address` is the address that you want to receive funds on.

If successful, this will return a `200 OK` with an empty body.
If successful, this will return a `200 OK` with the hex-encoded txid in the body.
If not, it will return a status code and a raw error message string in the body.

### L2

`todo`
`GET /claim_l2/<solution_as_hex>/<l2_address>`

Where `l2_address` is the address that you want to receive funds on.

If successful, this will return a `200 OK` with the hex-encoded txid in the body.
If not, it will return a status code and a raw error message string in the body.
1 change: 1 addition & 0 deletions faucet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ seed_file = "faucet.seed"
sqlite_file = "faucet.sqlite"
network = "signet"
esplora = "https://explorer.bc-2.jp/api"
l2_http_endpoint = "https://ethereum-rpc.publicnode.com"

This comment has been minimized.

Copy link
@storopoli

storopoli Sep 18, 2024

Member

@Zk2u where does this point to?

This comment has been minimized.

Copy link
@Zk2u

Zk2u Sep 18, 2024

Author Collaborator

This is just a random ethereum mainnet API endpoint i'm using as dropin while we don't have the rollup's eth endpoints yet.

sats_per_claim = 10_000_000
pow_difficulty = 17
35 changes: 8 additions & 27 deletions src/l1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,14 @@ use bdk_esplora::{
EsploraAsyncExt,
};
use bdk_wallet::{
bitcoin::{
bip32::{Xpriv, Xpub},
key::Secp256k1,
FeeRate, Network,
},
descriptor::calc_checksum,
bitcoin::{bip32::Xpriv, FeeRate, Network},
rusqlite::{self, Connection},
ChangeSet, KeychainKind, PersistedWallet, Wallet, WalletPersister,
};
use colored::Colorize;
use tokio::time::sleep;
use tracing::{debug, error, info, warn};

use crate::{seed::SavableSeed, AppState, SETTINGS};
use crate::{seed::Seed, AppState, SETTINGS};

/// Live updating fee rate in sat/kwu
static FEE_RATE: AtomicU64 = AtomicU64::new(250);
Expand Down Expand Up @@ -122,26 +116,13 @@ impl WalletPersister for Persister {
pub struct L1Wallet(PersistedWallet<Persister>);

impl L1Wallet {
/// Load or create a wallet from the disk using the seed file and sqlite
/// database.
pub fn load_or_create(network: Network) -> io::Result<Self> {
let seed = SavableSeed::load_or_create()?;
let rootpriv = Xpriv::new_master(Network::Signet, &seed).expect("valid xpriv");
let rootpub = Xpub::from_priv(&Secp256k1::new(), &rootpriv);
/// Create a wallet using the seed file and sqlite database.
pub fn new(network: Network, seed: &Seed) -> io::Result<Self> {
let rootpriv = Xpriv::new_master(Network::Signet, seed).expect("valid xpriv");
// let rootpub = Xpub::from_priv(&Secp256k1::new(), &rootpriv);
let base_desc = format!("tr({}/86h/0h/0h", rootpriv);
let base_pub_desc = format!("tr({}/86h/0h/0h)", rootpub);
info!(
"public descriptor: {}",
format!(
"{}#{}",
base_pub_desc,
calc_checksum(&base_pub_desc).expect("valid descriptor")
)
.green()
);

let external_desc = format!("{base_desc}/0)");
let internal_desc = format!("{base_desc}/1)");
let external_desc = format!("{base_desc}/0/*)");
let internal_desc = format!("{base_desc}/1/*)");

Ok(Self(
Wallet::load()
Expand Down
Loading

0 comments on commit f735e1b

Please sign in to comment.