Skip to content

Commit 747a730

Browse files
committed
feat: deposit into agg mode payment service command in cli
1 parent db7a40f commit 747a730

4 files changed

Lines changed: 92 additions & 4 deletions

File tree

Makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,11 @@ agg_mode_payments_poller_start_ethereum_package: agg_mode_run_migrations
319319

320320
AGG_MODE_SENDER ?= 0x70997970C51812dc3A010C7d01b50e0d17dc79C8
321321
agg_mode_gateway_send_payment:
322-
@cast send --value 1ether \
323-
0x922D6956C99E12DFeB3224DEA977D0939758A1Fe \
324-
--private-key 0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d
322+
@cd aggregation_mode/cli && \
323+
cargo run --release -- deposit \
324+
--private-key 0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d \
325+
--network devnet \
326+
--rpc-url http://localhost:8545
325327

326328

327329
agg_mode_install_cli: ## Install the aggregation mode CLI

aggregation_mode/cli/src/commands/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
use crate::commands::{submit::SubmitCommand, verify::VerifyOnChainArgs};
1+
use crate::commands::{payment::SendPaymentArgs, submit::SubmitCommand, verify::VerifyOnChainArgs};
22
use clap::{Parser, Subcommand};
33

44
mod helpers;
5+
pub mod payment;
56
pub mod submit;
67
pub mod verify;
78

@@ -17,4 +18,7 @@ pub enum Command {
1718
Submit(SubmitCommand),
1819
#[command(name = "verify-on-chain")]
1920
VerifyOnChain(VerifyOnChainArgs),
21+
/// Send 1 ether to the aggregation mode payment service
22+
#[command(name = "deposit")]
23+
Deposit(SendPaymentArgs),
2024
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
use agg_mode_sdk::types::Network;
2+
use alloy::{
3+
network::{EthereumWallet, TransactionBuilder},
4+
primitives::{Address, U256},
5+
providers::{Provider, ProviderBuilder},
6+
signers::local::LocalSigner,
7+
};
8+
use clap::{self, Args};
9+
use std::str::FromStr;
10+
11+
use crate::commands::helpers::parse_network;
12+
13+
const PAYMENT_AMOUNT: &str = "1"; // ether
14+
15+
/// Send 1 ether to the aggregation mode payment service to fund proof submissions
16+
#[derive(Debug, Clone, Args)]
17+
pub struct SendPaymentArgs {
18+
#[arg(long = "private-key")]
19+
private_key: String,
20+
#[arg(short = 'n', long = "network", default_value = "devnet", value_parser = parse_network)]
21+
network: Network,
22+
#[arg(long = "rpc-url")]
23+
rpc_url: String,
24+
}
25+
26+
pub async fn run(args: SendPaymentArgs) {
27+
tracing::info!("Sending payment to aggregation mode payment service on {:?}", args.network);
28+
29+
let signer = match LocalSigner::from_str(args.private_key.trim()) {
30+
Ok(s) => s,
31+
Err(e) => {
32+
tracing::error!("Failed to parse private key: {e}");
33+
return;
34+
}
35+
};
36+
37+
let wallet = EthereumWallet::from(signer.clone());
38+
39+
let rpc_url = args.rpc_url.parse().expect("Invalid RPC URL");
40+
let provider = ProviderBuilder::new()
41+
.wallet(wallet)
42+
.connect_http(rpc_url);
43+
44+
let payment_service_address_str = args.network.aggregation_mode_payment_service_address();
45+
let payment_service_address = match payment_service_address_str.parse::<Address>() {
46+
Ok(addr) => addr,
47+
Err(e) => {
48+
tracing::error!("Failed to parse payment service address: {e}");
49+
return;
50+
}
51+
};
52+
53+
let amount_ether: f64 = PAYMENT_AMOUNT.parse().expect("Invalid payment amount");
54+
let amount_wei = U256::from((amount_ether * 1e18) as u64);
55+
56+
let tx = alloy::rpc::types::TransactionRequest::default()
57+
.with_to(payment_service_address)
58+
.with_value(amount_wei);
59+
60+
match provider.send_transaction(tx).await {
61+
Ok(pending_tx) => {
62+
tracing::info!("Transaction sent. Hash: {:?}", pending_tx.tx_hash());
63+
match pending_tx.watch().await {
64+
Ok(receipt) => {
65+
tracing::info!(
66+
"Payment of {} ether sent successfully to aggregation mode payment service at {}",
67+
PAYMENT_AMOUNT,
68+
payment_service_address_str
69+
);
70+
tracing::info!("Transaction receipt: {:?}", receipt);
71+
}
72+
Err(e) => {
73+
tracing::error!("Failed to get transaction receipt: {e}");
74+
}
75+
}
76+
}
77+
Err(e) => {
78+
tracing::error!("Failed to send transaction: {e}");
79+
}
80+
}
81+
}

aggregation_mode/cli/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ async fn main() {
1515
SubmitCommand::SP1(args) => commands::submit::run(args).await,
1616
},
1717
Command::VerifyOnChain(args) => commands::verify::run(args).await,
18+
Command::Deposit(args) => commands::payment::run(args).await,
1819
};
1920
}

0 commit comments

Comments
 (0)