Skip to content
This repository was archived by the owner on Jan 27, 2026. It is now read-only.
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
8 changes: 4 additions & 4 deletions crates/dev-utils/examples/transfer_eth.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use alloy::{
network::TransactionBuilder, primitives::Address, primitives::U256, providers::Provider,
rpc::types::TransactionRequest,
network::TransactionBuilder, primitives::utils::format_ether, primitives::Address,
primitives::U256, providers::Provider, rpc::types::TransactionRequest,
};
use clap::Parser;
use eyre::Result;
Expand Down Expand Up @@ -49,13 +49,13 @@ async fn main() -> Result<()> {

println!(
"Sender's ETH balance before transaction: {} ETH",
balance_before / U256::from(10u64.pow(18))
format_ether(balance_before)
);

let balance_after = wallet.provider.get_balance(to).await?;
println!(
"Receiver's ETH balance after transaction: {} ETH",
alloy::primitives::utils::format_ether(balance_after)
format_ether(balance_after)
);

Ok(())
Expand Down
12 changes: 5 additions & 7 deletions crates/worker/src/cli/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use crate::services::discovery::DiscoveryService;
use crate::services::discovery_updater::DiscoveryUpdater;
use crate::state::system_state::SystemState;
use crate::TaskHandles;
use alloy::primitives::utils::format_ether;
use alloy::primitives::U256;
use alloy::signers::local::PrivateKeySigner;
use alloy::signers::Signer;
Expand Down Expand Up @@ -528,10 +529,7 @@ pub async fn execute_command(
std::process::exit(1);
}
};
Console::info(
"Required stake",
&format!("{}", required_stake / U256::from(10u128.pow(18))),
);
Console::info("Required stake", &format_ether(required_stake).to_string());
Comment thread
JannikSt marked this conversation as resolved.

if let Err(e) = provider_ops
.retry_register_provider(
Expand Down Expand Up @@ -595,8 +593,8 @@ pub async fn execute_command(
"Provider stake is less than required stake",
&format!(
"Required: {} tokens, Current: {} tokens",
required_stake / U256::from(10u128.pow(18)),
provider_stake / U256::from(10u128.pow(18))
format_ether(required_stake),
format_ether(provider_stake)
),
);

Expand Down Expand Up @@ -885,7 +883,7 @@ pub async fn execute_command(
.await
.unwrap();

let format_balance = format!("{}", provider_balance / U256::from(10u128.pow(18)));
let format_balance = format_ether(provider_balance).to_string();
Comment thread
JannikSt marked this conversation as resolved.

println!("Provider balance: {format_balance}");
Ok(())
Expand Down
51 changes: 20 additions & 31 deletions crates/worker/src/operations/provider.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::console::Console;
use alloy::primitives::utils::format_ether;
use alloy::primitives::{Address, U256};
use log::error;
use shared::web3::contracts::core::builder::Contracts;
Expand Down Expand Up @@ -69,20 +70,20 @@ impl ProviderOperations {
match stake_manager.get_stake(provider_address).await {
Ok(stake) => {
if first_check || stake != last_stake {
Console::info("🔄 Chain Sync - Provider stake", &format!("{}", stake / U256::from(10u128.pow(18))));
Console::info("🔄 Chain Sync - Provider stake", &format_ether(stake));
if !first_check {
if stake < last_stake {
Console::warning(&format!("Stake decreased - possible slashing detected: From {} to {}",
last_stake / U256::from(10u128.pow(18)),
stake / U256::from(10u128.pow(18))
format_ether(last_stake),
format_ether(stake)
));
if stake == U256::ZERO {
Console::warning("Stake is 0 - you might have to restart the node to increase your stake (if you still have balance left)");
}
} else {
Console::info("🔄 Chain Sync - Stake changed", &format!("From {} to {}",
last_stake / U256::from(10u128.pow(18)),
stake / U256::from(10u128.pow(18))
format_ether(last_stake),
format_ether(stake)
));
}
}
Expand All @@ -100,11 +101,11 @@ impl ProviderOperations {
match contracts.ai_token.balance_of(provider_address).await {
Ok(balance) => {
if first_check || balance != last_balance {
Console::info("🔄 Chain Sync - Balance", &format!("{}", balance / U256::from(10u128.pow(18))));
Console::info("🔄 Chain Sync - Balance", &format_ether(balance));
if !first_check {
Console::info("🔄 Chain Sync - Balance changed", &format!("From {} to {}",
last_balance / U256::from(10u128.pow(18)),
balance / U256::from(10u128.pow(18))
format_ether(last_balance),
format_ether(balance)
));
}
last_balance = balance;
Expand Down Expand Up @@ -222,24 +223,21 @@ impl ProviderOperations {
let provider_exists = self.check_provider_exists().await?;

if !provider_exists {
Console::info(
"Balance",
&format!("{}", balance / U256::from(10u128.pow(18))),
);
Console::info("Balance", &format_ether(balance));
Console::info(
"ETH Balance",
&format!("{:.6} ETH", { f64::from(eth_balance) / 10f64.powf(18.0) }),
&format!("{} ETH", format_ether(U256::from(eth_balance))),
Comment thread
JannikSt marked this conversation as resolved.
);
if balance < stake {
Console::user_error(&format!(
"Insufficient balance for stake: {}",
stake / U256::from(10u128.pow(18))
format_ether(stake)
));
return Err(ProviderError::InsufficientBalance);
}
if !self.prompt_user_confirmation(&format!(
"Do you want to approve staking {}?",
stake.to_string().parse::<f64>().unwrap_or(0.0) / 10f64.powf(18.0)
format_ether(stake)
)) {
Console::info("Operation cancelled by user", "Staking approval declined");
return Err(ProviderError::UserCancelled);
Expand Down Expand Up @@ -273,24 +271,21 @@ impl ProviderOperations {
let provider_exists = self.check_provider_exists().await?;

if !provider_exists {
Console::info(
"Balance",
&format!("{}", balance / U256::from(10u128.pow(18))),
);
Console::info("Balance", &format_ether(balance));
Console::info(
"ETH Balance",
&format!("{:.6} ETH", { f64::from(eth_balance) / 10f64.powf(18.0) }),
&format!("{} ETH", format_ether(U256::from(eth_balance))),
Comment thread
JannikSt marked this conversation as resolved.
);
if balance < stake {
Console::user_error(&format!(
"Insufficient balance for stake: {}",
stake / U256::from(10u128.pow(18))
format_ether(stake)
));
return Err(ProviderError::InsufficientBalance);
}
if !self.prompt_user_confirmation(&format!(
"Do you want to approve staking {}?",
stake.to_string().parse::<f64>().unwrap_or(0.0) / 10f64.powf(18.0)
format_ether(stake)
)) {
Console::info("Operation cancelled by user", "Staking approval declined");
return Err(ProviderError::UserCancelled);
Expand Down Expand Up @@ -347,14 +342,8 @@ impl ProviderOperations {
.await
.map_err(|_| ProviderError::Other)?;

Console::info(
"Current Balance",
&format!("{}", balance / U256::from(10u128.pow(18))),
);
Console::info(
"Additional stake amount",
&format!("{}", additional_stake / U256::from(10u128.pow(18))),
);
Console::info("Current Balance", &format_ether(balance));
Console::info("Additional stake amount", &format_ether(additional_stake));

if balance < additional_stake {
Console::user_error("Insufficient balance for stake increase");
Expand All @@ -363,7 +352,7 @@ impl ProviderOperations {

if !self.prompt_user_confirmation(&format!(
"Do you want to approve staking {} additional funds?",
additional_stake.to_string().parse::<f64>().unwrap_or(0.0) / 10f64.powf(18.0)
format_ether(additional_stake)
)) {
Console::info("Operation cancelled by user", "Staking approval declined");
return Err(ProviderError::UserCancelled);
Expand Down