Skip to content
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
36 changes: 27 additions & 9 deletions contracts/milestone-escrow/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,12 @@ pub enum DataKey {
/// `set_escrow_interest_yield`; read by getters and lock/unlock helpers.
InterestYieldState,
// ── escrow_interest_yield admin-override keys ────────────────────────────
/// Persistent: annual yield rate expressed in basis points (1 bp = 0.01 %).
/// Range 0–10 000 (0 %–100 %). Written by `admin_set_yield_rate`, read by
/// `get_yield_info` and `admin_accrue_yield`.
YieldRateBps,
/// Persistent: holds the `YieldConfig` struct (annual yield rate in basis
/// points, 1 bp = 0.01 %, range 0–10 000 / 0 %–100 %). Written by
/// `admin_set_yield_rate`, read by `get_yield_info` and `admin_accrue_yield`.
/// Consolidated into a single struct-valued key to minimise the ledger
/// footprint versus one key per field.
YieldConfig,
/// Persistent: total interest (in token stroops) accrued so far by the
/// admin via `admin_accrue_yield`. Reset to zero on admin override release
/// or refund so downstream indexers can detect a fresh yield cycle.
Expand Down Expand Up @@ -590,6 +592,17 @@ pub struct AdminOverrideTaxRefundEvent {
pub gross_amount: i128,
}

// ── escrow_interest_yield admin-override config ──────────────────────────────

/// Consolidated yield configuration stored under `DataKey::YieldConfig`.
/// Bundles all yield-related settings into a single struct-valued ledger
/// entry so `admin_set_yield_rate` touches one key instead of several.
#[contracttype]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct YieldConfig {
pub yield_rate: u32,
}

// ── escrow_interest_yield admin-override events ──────────────────────────────

/// Emitted by `admin_set_yield_rate` whenever the admin updates the annual
Expand Down Expand Up @@ -4341,12 +4354,16 @@ impl MilestoneEscrow {
let old_rate_bps: u32 = env
.storage()
.persistent()
.get(&DataKey::YieldRateBps)
.get(&DataKey::YieldConfig)
.map(|config: YieldConfig| config.yield_rate)
.unwrap_or(0);

env.storage()
.persistent()
.set(&DataKey::YieldRateBps, &rate_bps);
env.storage().persistent().set(
&DataKey::YieldConfig,
&YieldConfig {
yield_rate: rate_bps,
},
);

env.events().publish(
(symbol_short!("yldrate"),),
Expand Down Expand Up @@ -5105,7 +5122,8 @@ impl MilestoneEscrow {
let rate_bps: u32 = env
.storage()
.persistent()
.get(&DataKey::YieldRateBps)
.get(&DataKey::YieldConfig)
.map(|config: YieldConfig| config.yield_rate)
.unwrap_or(0);

let total_accrued: i128 = env
Expand Down
36 changes: 27 additions & 9 deletions contracts/reports/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,12 @@ pub enum DataKey {
MilestoneReleased(u32),
Reputation(Address),
// ── escrow_interest_yield admin-override keys ────────────────────────────
/// Persistent: annual yield rate expressed in basis points (1 bp = 0.01 %).
/// Range 0–10 000 (0 %–100 %). Written by `admin_set_yield_rate`, read by
/// `get_yield_info` and `admin_accrue_yield`.
YieldRateBps,
/// Persistent: holds the `YieldConfig` struct (annual yield rate in basis
/// points, 1 bp = 0.01 %, range 0–10 000 / 0 %–100 %). Written by
/// `admin_set_yield_rate`, read by `get_yield_info` and `admin_accrue_yield`.
/// Consolidated into a single struct-valued key to minimise the ledger
/// footprint versus one key per field.
YieldConfig,
/// Persistent: total interest (in token stroops) accrued so far by the
/// admin via `admin_accrue_yield`. Reset to zero on admin override release
/// or refund so downstream indexers can detect a fresh yield cycle.
Expand Down Expand Up @@ -300,6 +302,17 @@ pub struct CancelEscrowInitiatedEvent {
}


// ── escrow_interest_yield admin-override config ──────────────────────────────

/// Consolidated yield configuration stored under `DataKey::YieldConfig`.
/// Bundles all yield-related settings into a single struct-valued ledger
/// entry so `admin_set_yield_rate` touches one key instead of several.
#[contracttype]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct YieldConfig {
pub yield_rate: u32,
}

// ── escrow_interest_yield admin-override events ──────────────────────────────

/// Emitted by `admin_set_yield_rate` whenever the admin updates the annual
Expand Down Expand Up @@ -2111,12 +2124,16 @@ impl MilestoneEscrow {
let old_rate_bps: u32 = env
.storage()
.persistent()
.get(&DataKey::YieldRateBps)
.get(&DataKey::YieldConfig)
.map(|config: YieldConfig| config.yield_rate)
.unwrap_or(0);

env.storage()
.persistent()
.set(&DataKey::YieldRateBps, &rate_bps);
env.storage().persistent().set(
&DataKey::YieldConfig,
&YieldConfig {
yield_rate: rate_bps,
},
);

env.events().publish(
(symbol_short!("yldrate"),),
Expand Down Expand Up @@ -2472,7 +2489,8 @@ impl MilestoneEscrow {
let rate_bps: u32 = env
.storage()
.persistent()
.get(&DataKey::YieldRateBps)
.get(&DataKey::YieldConfig)
.map(|config: YieldConfig| config.yield_rate)
.unwrap_or(0);

let total_accrued: i128 = env
Expand Down
Loading