Metrics

Struct Metrics 

Source
#[repr(C)]
pub struct Metrics { pub last_updated: i64, pub weekly_active_users: u32, pub weekly_activity_count: u32, pub weekly_retention_rate: u16, pub community_score: u16, pub user_weight: u16, pub activity_weight: u16, pub retention_weight: u16, pub customer_reward_share: u16, pub merchant_reward_share: u16, pub _padding: [u8; 2], }
Expand description

Metrics stores weekly community health data used for reward decay calculation.

This struct implements the Enhanced Community-Driven Decay model which adjusts daily rewards based on community health metrics. The community score is calculated using a weighted geometric mean approach combining weekly active users, weekly activity count, and weekly retention rate with dynamic weights based on community age.

§Formula

user_score = min((weekly_active_users / TARGET_WEEKLY_USERS) * 10000, 10000)
activity_score = min((weekly_activity_count / TARGET_WEEKLY_ACTIVITY) * 10000, 10000)
retention_score = min((weekly_retention_rate / TARGET_RETENTION_RATE) * 10000, 10000)
weights = oracle_provided_weights (no longer fixed phases)
community_score = weighted_geometric_mean([user_score, activity_score, retention_score], weights)

decay_factor = smooth_function(community_score) // 0.5 + 0.5 * (1 - (score/10000)^2)
daily_rewards = BASE_DAILY_REWARDS * decay_factor * time_decay / 100_000_000
customer_pool = daily_rewards * customer_reward_share / 10000
merchant_pool = daily_rewards * merchant_reward_share / 10000

§Targets

  • TARGET_WEEKLY_USERS: 10,000 active users per week
  • TARGET_WEEKLY_ACTIVITY: 50,000 transactions per week (replaces volume-based target)
  • TARGET_RETENTION_RATE: 70% retention rate (7000 basis points)

§Dynamic Weight Strategy (Oracle Configurable)

  • Launch Phase: [6000, 3000, 1000] - User focus, encourage activity
  • Growth Phase: [4000, 3500, 2500] - Balanced metrics
  • Maturity Phase: [3000, 3000, 4000] - Quality focus

§Customer/Merchant Split

  • Launch: 70% customers, 30% merchants (drive adoption)
  • Growth: 60% customers, 40% merchants (balanced)
  • Maturity: 50% customers, 50% merchants (equal partnership)

§Decay Factors

  • Smooth Decay: Gradual transition from 100% to 50% rewards based on community score
  • Time Decay: Linear decay over 5 years, reaching 10% minimum
  • Formula: 0.5 + 0.5 * (1 - (score/10000)^2)
  • No sharp thresholds, eliminates gaming incentives

§Daily Rewards Impact

  • Healthy Community (score = 100%): 50,000 MIRACLE/day (50% of 100,000)
  • Growing Community (score = 50%): 87,500 MIRACLE/day (87.5% of 100,000)
  • Struggling Community (score = 0%): 100,000 MIRACLE/day (100% of 100,000)

§Edge Cases

  • Initial Launch (score = 0%): 100,000 MIRACLE/day (100% of base rewards)
  • Zero Activity (no users/activity): 100,000 MIRACLE/day (100% of base rewards)
  • Oracle Failure (stale data): Uses last known community score
  • New Project: Full rewards encourage early adoption and community growth

§Memory Layout

Optimized for 8-byte alignment with explicit padding to ensure consistent cross-platform behavior and minimal account size (48 bytes total).

Fields§

§last_updated: i64

Last update timestamp (Unix timestamp). Tracks when the metrics were last updated by the oracle.

§weekly_active_users: u32

Weekly active users count. Used to calculate user score component of community health.

§weekly_activity_count: u32

Weekly activity count (number of transactions, not amounts). Used to calculate activity score component of community health. Replaces volume-based counting for fair mediator platform rewards.

§weekly_retention_rate: u16

Weekly retention rate in basis points (0-10000, 0-100%). Percentage of users who return week-over-week.

§community_score: u16

Calculated community score (0-10000 basis points). Represents overall community health as percentage (0-100%).

§user_weight: u16

User weight in basis points (0-10000) for weighted geometric mean. Determines importance of user count in community score calculation.

§activity_weight: u16

Activity weight in basis points (0-10000) for weighted geometric mean. Determines importance of transaction count in community score calculation.

§retention_weight: u16

Retention weight in basis points (0-10000) for weighted geometric mean. Determines importance of retention rate in community score calculation.

§customer_reward_share: u16

Customer reward share in basis points (0-10000, 0-100%). Percentage of daily rewards allocated to customers.

§merchant_reward_share: u16

Merchant reward share in basis points (0-10000, 0-100%). Percentage of daily rewards allocated to merchants. Must sum to 10000 with customer_reward_share.

§_padding: [u8; 2]

Padding to ensure proper alignment (2 bytes to maintain 48-byte struct size)

Implementations§

Source§

impl Metrics

Source

pub fn to_bytes(&self) -> &[u8]

Trait Implementations§

Source§

impl AccountValidation for Metrics

Source§

fn assert<F>(&self, condition: F) -> Result<&Self, ProgramError>
where F: Fn(&Self) -> bool,

Source§

fn assert_err<F>( &self, condition: F, err: ProgramError, ) -> Result<&Self, ProgramError>
where F: Fn(&Self) -> bool,

Source§

fn assert_msg<F>(&self, condition: F, msg: &str) -> Result<&Self, ProgramError>
where F: Fn(&Self) -> bool,

Source§

fn assert_mut<F>(&mut self, condition: F) -> Result<&mut Self, ProgramError>
where F: Fn(&Self) -> bool,

Source§

fn assert_mut_err<F>( &mut self, condition: F, err: ProgramError, ) -> Result<&mut Self, ProgramError>
where F: Fn(&Self) -> bool,

Source§

fn assert_mut_msg<F>( &mut self, condition: F, msg: &str, ) -> Result<&mut Self, ProgramError>
where F: Fn(&Self) -> bool,

Source§

impl Clone for Metrics

Source§

fn clone(&self) -> Metrics

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Metrics

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Discriminator for Metrics

Source§

impl PartialEq for Metrics

Source§

fn eq(&self, other: &Metrics) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Zeroable for Metrics

Source§

fn zeroed() -> Self

Source§

impl Copy for Metrics

Source§

impl Pod for Metrics

Source§

impl StructuralPartialEq for Metrics

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> AccountDeserialize for T
where T: Discriminator + Pod,

Source§

impl<T> AccountHeaderDeserialize for T
where T: Discriminator + Pod,

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<T> CheckedBitPattern for T
where T: AnyBitPattern,

Source§

type Bits = T

Self must have the same layout as the specified Bits except for the possible invalid bit patterns being checked during is_valid_bit_pattern.
Source§

fn is_valid_bit_pattern(_bits: &T) -> bool

If this function returns true, then it must be valid to reinterpret bits as &Self.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<Src, Dst> LosslessTryInto<Dst> for Src
where Dst: LosslessTryFrom<Src>,

Source§

fn lossless_try_into(self) -> Option<Dst>

Performs the conversion.
Source§

impl<Src, Dst> LossyInto<Dst> for Src
where Dst: LossyFrom<Src>,

Source§

fn lossy_into(self) -> Dst

Performs the conversion.
Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> AnyBitPattern for T
where T: Pod,

Source§

impl<T> NoUninit for T
where T: Pod,