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
2 changes: 2 additions & 0 deletions contracts/savings-vault/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ pub const EVENT_SCHEMA_VERSION: u32 = 1;
pub const TOPIC_INIT: &str = "init";
/// Emitted at the end of a successful `set_admin` call.
pub const TOPIC_ADMIN_SET: &str = "admin_set";
/// Emitted at the end of a successful `upgrade` call.
pub const TOPIC_UPGRADED: &str = "upgraded";

// --- flexible ------------------------------------------------------------
/// Emitted at the end of a successful `deposit` call.
Expand Down
37 changes: 37 additions & 0 deletions contracts/savings-vault/src/interest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,24 @@ pub fn set_rate(env: &Env, caller: Address, rate_bps: u32) -> Result<(), Error>
Ok(())
}

/// Internal variant of [`set_rate`] used by `timelock::execute_action`.
///
/// Auth has already been verified by the timelock; this function skips
/// `require_auth` and writes the rate directly.
pub(crate) fn set_rate_internal(env: &Env, admin: Address, rate_bps: u32) -> Result<(), Error> {
if rate_bps > MAX_INTEREST_BPS {
return Err(Error::InvalidParameters);
}
env.storage()
.instance()
.set(&DataKey::InterestRateBps, &rate_bps);
env.events().publish(
(TOPIC_INTEREST_RATE_SET,),
(admin, rate_bps, env.ledger().timestamp()),
);
Ok(())
}

/// The annual interest rate, in basis points. `0` (the default) means no
/// interest accrues.
pub fn rate_bps(env: &Env) -> u32 {
Expand Down Expand Up @@ -124,6 +142,25 @@ pub fn set_frequency(
Ok(())
}

/// Internal variant of [`set_frequency`] used by `timelock::execute_action`.
///
/// Auth has already been verified by the timelock; this function skips
/// `require_auth` and writes the frequency directly.
pub(crate) fn set_frequency_internal(
env: &Env,
admin: Address,
frequency: CompoundFrequency,
) -> Result<(), Error> {
env.storage()
.instance()
.set(&DataKey::InterestFrequency, &frequency);
env.events().publish(
(TOPIC_INTEREST_FREQUENCY_SET,),
(admin, frequency, env.ledger().timestamp()),
);
Ok(())
}

/// The current compounding frequency. Defaults to
/// [`CompoundFrequency::Annually`] before `set_frequency` is ever called.
pub fn frequency(env: &Env) -> CompoundFrequency {
Expand Down
1 change: 1 addition & 0 deletions contracts/savings-vault/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ mod challenge;
mod locked;
pub mod rewards;
mod storage;
mod timelock;
mod types;
mod voting;

Expand Down
Loading
Loading