Skip to content

Commit

Permalink
feat(stats): account abstraction wallets charts (#1201)
Browse files Browse the repository at this point in the history
* new wallets

* other aa charts

* add new charts to configs & endpoint & etc.

* small comment

* comment fix

* fix import

* random minor non-functional tweaks

* rewrite new_aa_wallets query to plain sql for readability

* fix comments
  • Loading branch information
bragov4ik authored Jan 28, 2025
1 parent 97be784 commit ad1927c
Show file tree
Hide file tree
Showing 17 changed files with 529 additions and 17 deletions.
16 changes: 16 additions & 0 deletions stats/config/charts.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@
"title": "Total user operations",
"description": "Number of user operations as per the ERC-4337 standard"
},
"total_account_abstraction_wallets": {
"title": "Total AA wallets",
"description": "Number of account abstraction wallets (ERC-4337) that sent at least 1 user operation"
},
"last_new_contracts": {
"title": "Number of contracts today",
"description": "Number of deployed contracts today (UTC)"
Expand Down Expand Up @@ -181,6 +185,18 @@
"title": "Number of user operations",
"description": "Cumulative user operation (ERC-4337) growth over time"
},
"new_account_abstraction_wallets": {
"title": "New AA wallets",
"description": "Number of newly added account abstraction wallets (ERC-4337)"
},
"account_abstraction_wallets_growth": {
"title": "Number of AA wallets",
"description": "Cumulative account abstraction wallets (ERC-4337) growth over time"
},
"active_account_abstraction_wallets": {
"title": "Active AA wallets",
"description": "Active account abstraction wallets (ERC-4337) number per period"
},
"active_bundlers": {
"title": "Active bundlers",
"description": "Active user ops bundlers number per period"
Expand Down
4 changes: 4 additions & 0 deletions stats/config/layout.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"total_txns",
"total_operational_txns",
"total_user_ops",
"total_account_abstraction_wallets",
"total_verified_contracts",
"new_txns_24h",
"pending_txns_30m",
Expand Down Expand Up @@ -90,6 +91,9 @@
"charts_order": [
"user_ops_growth",
"new_user_ops",
"new_account_abstraction_wallets",
"account_abstraction_wallets_growth",
"active_account_abstraction_wallets",
"active_bundlers",
"active_paymasters"
]
Expand Down
2 changes: 2 additions & 0 deletions stats/config/update_groups.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@
"new_contracts_group": "0 20 */3 * * * *",
"new_txns_group": "0 10 */3 * * * *",
"new_user_ops_group": "0 5 7 * * * *",
"new_account_abstraction_wallets_group": "0 35 12 * * * *",
"active_bundlers_group": "0 7 7 * * * *",
"active_paymasters_group": "0 8 7 * * * *",
"active_account_abstraction_wallets_group": "0 30 13 * * * *",
"new_verified_contracts_group": "0 30 */3 * * * *",
"native_coin_holders_growth_group": "0 0 7,17,22 * * * *",
"new_native_coin_transfers_group": "0 0 3,13 * * * *",
Expand Down
2 changes: 2 additions & 0 deletions stats/stats-server/src/runtime_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ impl RuntimeSetup {
Arc::new(ActiveAccountsGroup),
Arc::new(ActiveBundlersGroup),
Arc::new(ActivePaymastersGroup),
Arc::new(ActiveAccountAbstractionWalletsGroup),
Arc::new(AverageBlockTimeGroup),
Arc::new(CompletedTxnsGroup),
Arc::new(PendingTxns30mGroup),
Expand Down Expand Up @@ -337,6 +338,7 @@ impl RuntimeSetup {
Arc::new(TxnsSuccessRateGroup),
// complex groups
Arc::new(NewAccountsGroup),
Arc::new(NewAccountAbstractionWalletsGroup),
Arc::new(NewContractsGroup),
Arc::new(NewTxnsGroup),
Arc::new(NewUserOpsGroup),
Expand Down
3 changes: 2 additions & 1 deletion stats/stats-server/tests/it/chart_endpoints/counters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ pub async fn test_counters_ok(base: Url) {
"totalTxns",
"totalOperationalTxns",
"totalUserOps",
"totalAccountAbstractionWallets",
"totalVerifiedContracts",
"newTxns24h",
"pendingTxns30m",
"txnsFee24h",
"averageTxnFee24h",
// on a different page; they are checked by other endpoint tests and
// `check_all_enabled_charts_have_endpoints`
// `check_all_enabled_charts_have_endpoints`.

// "newContracts24h",
// "newVerifiedContracts24h",
Expand Down
3 changes: 3 additions & 0 deletions stats/stats-server/tests/it/chart_endpoints/lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ pub async fn test_lines_ok(base: Url) {
"txnsSuccessRate",
"newUserOps",
"userOpsGrowth",
"newAccountAbstractionWallets",
"accountAbstractionWalletsGrowth",
"activeAccountAbstractionWallets",
"activeBundlers",
"activePaymasters",
"newVerifiedContracts",
Expand Down
2 changes: 2 additions & 0 deletions stats/stats/src/charts/counters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mod last_new_verified_contracts;
mod new_contracts_24h;
mod new_verified_contracts_24h;
mod pending_txns;
mod total_aa_wallets;
mod total_accounts;
mod total_addresses;
mod total_blocks;
Expand All @@ -30,6 +31,7 @@ pub use last_new_verified_contracts::LastNewVerifiedContracts;
pub use new_contracts_24h::NewContracts24h;
pub use new_verified_contracts_24h::NewVerifiedContracts24h;
pub use pending_txns::PendingTxns30m;
pub use total_aa_wallets::TotalAccountAbstractionWallets;
pub use total_accounts::TotalAccounts;
pub use total_addresses::TotalAddresses;
pub use total_blocks::TotalBlocks;
Expand Down
9 changes: 2 additions & 7 deletions stats/stats/src/charts/counters/pending_txns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,11 @@ pub type PendingTxns30m = DirectPointLocalDbChartSource<PendingTxns30mRemote, Pr
#[cfg(test)]
mod tests {
use super::*;
use crate::tests::simple_test::simple_test_counter_with_migration_variants;
use crate::tests::simple_test::simple_test_counter;

#[tokio::test]
#[ignore = "needs database to run"]
async fn update_pending_txns_30m() {
simple_test_counter_with_migration_variants::<PendingTxns30m>(
"update_pending_txns_30m",
"0",
None,
)
.await;
simple_test_counter::<PendingTxns30m>("update_pending_txns_30m", "0", None).await;
}
}
50 changes: 50 additions & 0 deletions stats/stats/src/charts/counters/total_aa_wallets.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
use crate::{
data_source::kinds::{
data_manipulation::{last_point::LastPoint, map::StripExt},
local_db::DirectPointLocalDbChartSource,
},
lines::AccountAbstractionWalletsGrowth,
ChartProperties, MissingDatePolicy, Named,
};

use chrono::NaiveDate;
use entity::sea_orm_active_enums::ChartType;

pub struct Properties;

impl Named for Properties {
fn name() -> String {
"totalAccountAbstractionWallets".into()
}
}

impl ChartProperties for Properties {
type Resolution = NaiveDate;

fn chart_type() -> ChartType {
ChartType::Counter
}
fn missing_date_policy() -> MissingDatePolicy {
MissingDatePolicy::FillPrevious
}
}

pub type TotalAccountAbstractionWallets =
DirectPointLocalDbChartSource<LastPoint<StripExt<AccountAbstractionWalletsGrowth>>, Properties>;

#[cfg(test)]
mod tests {
use super::*;
use crate::tests::simple_test::simple_test_counter;

#[tokio::test]
#[ignore = "needs database to run"]
async fn update_total_account_abstraction_wallets() {
simple_test_counter::<TotalAccountAbstractionWallets>(
"update_total_account_abstraction_wallets",
"1",
None,
)
.await;
}
}
9 changes: 2 additions & 7 deletions stats/stats/src/charts/counters/total_txns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,8 @@ impl ValueEstimation for TotalTxnsEstimation {
}
}

// We will need it to update on not fully indexed data soon, therefore this counter is
// separated from `NewTxns`.
//
// Separate query not reliant on previous computation helps this counter to work in such
// environments.
//
// todo: make it dependant again if #845 is resolved
// Independent from `NewTxns` because this needs to work on not-fully-indexed
// just as well.
pub type TotalTxns =
DirectPointLocalDbChartSourceWithEstimate<TotalTxnsRemote, TotalTxnsEstimation, Properties>;
pub type TotalTxnsInt = MapParseTo<TotalTxns, i64>;
Expand Down
2 changes: 1 addition & 1 deletion stats/stats/src/charts/lines/accounts/new_accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl RemoteQueryBehaviour for NewAccountsQueryBehaviour {
/// though the implementation allows batching. The batching was done
/// to simplify interface of the data source.
///
/// Thus, use max batch size in the dependant data sources.
/// Thus, use max batch size in the `DirectVecLocalDbChartSource` for it.
pub type NewAccountsRemote = RemoteDatabaseSource<NewAccountsQueryBehaviour>;

pub struct Properties;
Expand Down
9 changes: 9 additions & 0 deletions stats/stats/src/charts/lines/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,21 @@ mod mock;

pub use new_txns_window::WINDOW as NEW_TXNS_WINDOW_RANGE;

pub use aa_wallets_growth::{
AccountAbstractionWalletsGrowth, AccountAbstractionWalletsGrowthMonthly,
AccountAbstractionWalletsGrowthWeekly, AccountAbstractionWalletsGrowthYearly,
};
pub use accounts_growth::{
AccountsGrowth, AccountsGrowthMonthly, AccountsGrowthWeekly, AccountsGrowthYearly,
};
pub use active_aa_wallets::ActiveAccountAbstractionWallets;
pub use active_accounts::ActiveAccounts;
pub use active_bundlers::ActiveBundlers;
pub use active_paymasters::ActivePaymasters;
pub use new_aa_wallets::{
NewAccountAbstractionWallets, NewAccountAbstractionWalletsMonthly,
NewAccountAbstractionWalletsWeekly, NewAccountAbstractionWalletsYearly,
};
#[rustfmt::skip]
pub use active_recurring_accounts::{
ActiveRecurringAccountsDailyRecurrence120Days, ActiveRecurringAccountsMonthlyRecurrence120Days,
Expand Down
112 changes: 112 additions & 0 deletions stats/stats/src/charts/lines/user_ops/aa_wallets_growth.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
use crate::{
charts::chart::ChartProperties,
data_source::kinds::{
data_manipulation::{map::StripExt, resolutions::last_value::LastValueLowerResolution},
local_db::{
parameters::update::batching::parameters::{Batch30Weeks, Batch30Years, Batch36Months},
DailyCumulativeLocalDbChartSource, DirectVecLocalDbChartSource,
},
},
define_and_impl_resolution_properties,
types::timespans::{Month, Week, Year},
MissingDatePolicy, Named,
};

use chrono::NaiveDate;
use entity::sea_orm_active_enums::ChartType;

use super::new_aa_wallets::NewAccountAbstractionWalletsInt;

pub struct Properties;

impl Named for Properties {
fn name() -> String {
"accountAbstractionWalletsGrowth".into()
}
}

impl ChartProperties for Properties {
type Resolution = NaiveDate;

fn chart_type() -> ChartType {
ChartType::Line
}
fn missing_date_policy() -> MissingDatePolicy {
MissingDatePolicy::FillPrevious
}
}

define_and_impl_resolution_properties!(
define_and_impl: {
WeeklyProperties: Week,
MonthlyProperties: Month,
YearlyProperties: Year,
},
base_impl: Properties
);

pub type AccountAbstractionWalletsGrowth =
DailyCumulativeLocalDbChartSource<NewAccountAbstractionWalletsInt, Properties>;
type AccountAbstractionWalletsGrowthS = StripExt<AccountAbstractionWalletsGrowth>;
pub type AccountAbstractionWalletsGrowthWeekly = DirectVecLocalDbChartSource<
LastValueLowerResolution<AccountAbstractionWalletsGrowthS, Week>,
Batch30Weeks,
WeeklyProperties,
>;
pub type AccountAbstractionWalletsGrowthMonthly = DirectVecLocalDbChartSource<
LastValueLowerResolution<AccountAbstractionWalletsGrowthS, Month>,
Batch36Months,
MonthlyProperties,
>;
type AccountAbstractionWalletsGrowthMonthlyS = StripExt<AccountAbstractionWalletsGrowthMonthly>;
pub type AccountAbstractionWalletsGrowthYearly = DirectVecLocalDbChartSource<
LastValueLowerResolution<AccountAbstractionWalletsGrowthMonthlyS, Year>,
Batch30Years,
YearlyProperties,
>;

#[cfg(test)]
mod tests {
use super::*;
use crate::tests::simple_test::simple_test_chart;

#[tokio::test]
#[ignore = "needs database to run"]
async fn update_account_abstraction_wallets_growth() {
simple_test_chart::<AccountAbstractionWalletsGrowth>(
"update_account_abstraction_wallets_growth",
vec![("2022-11-09", "1")],
)
.await;
}

#[tokio::test]
#[ignore = "needs database to run"]
async fn update_account_abstraction_wallets_growth_weekly() {
simple_test_chart::<AccountAbstractionWalletsGrowthWeekly>(
"update_account_abstraction_wallets_growth_weekly",
vec![("2022-11-07", "1")],
)
.await;
}

#[tokio::test]
#[ignore = "needs database to run"]
async fn update_account_abstraction_wallets_growth_monthly() {
simple_test_chart::<AccountAbstractionWalletsGrowthMonthly>(
"update_account_abstraction_wallets_growth_monthly",
vec![("2022-11-01", "1")],
)
.await;
}

#[tokio::test]
#[ignore = "needs database to run"]
async fn update_account_abstraction_wallets_growth_yearly() {
simple_test_chart::<AccountAbstractionWalletsGrowthYearly>(
"update_account_abstraction_wallets_growth_yearly",
vec![("2022-01-01", "1")],
)
.await;
}
}
Loading

0 comments on commit ad1927c

Please sign in to comment.