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
17 changes: 12 additions & 5 deletions contracts/price-oracle/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,11 @@ pub fn _is_authorized(env: &Env, caller: &Address) -> bool {
return false;
}

env.storage()
let admins = env
.storage()
.instance()
.get::<DataKey, Vec<Address>>(&DataKey::Admin)
else {
return false;
};
.unwrap_or_else(|| Vec::new(env));

// Stack-local fixed buffer — avoids any BTreeMap / HashMap heap allocation.
const CAP: usize = 16;
Expand All @@ -103,6 +102,15 @@ pub fn _is_authorized(env: &Env, caller: &Address) -> bool {
false
}

pub fn _require_auth_for_args<T: soroban_sdk::IntoVal>(
env: &Env,
caller: &Address,
args: &[T],
) {
caller.require_auth_for_args(args);
let _ = env;
}

pub fn _require_authorized(env: &Env, caller: &Address) {
if !_is_authorized(env, caller) {
panic_with_error!(env, ContractError::NotAuthorized);
Expand Down Expand Up @@ -295,7 +303,6 @@ pub fn _is_provider(env: &Env, addr: &Address) -> bool {
return false;
}

env.storage()
// 1. Direct provider whitelist check
if env
.storage()
Expand Down
55 changes: 34 additions & 21 deletions contracts/price-oracle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ pub trait StellarFlowTrait {
/// Remove a coordinator node's circuit-breaker privileges.
///
/// Only an authorized admin may call this.
fn remove_circuit_breaker_coordinator(
fn remove_breaker_coord(
env: Env,
admin: Address,
coordinator: Address,
Expand Down Expand Up @@ -2254,10 +2254,19 @@ impl PriceOracle {
ttl: u64,
liquidity: i128,
) -> Result<(), ContractError> {
_require_not_destroyed(&env)?;
_require_initialized(&env)?;
if crate::auth::_is_frozen(&env) { return Err(ContractError::ContractFrozen); }
source.require_auth();
_require_not_destroyed(&env);
_require_initialized(&env);
crate::auth::_require_not_frozen(&env);
let auth_args = soroban_sdk::vec![
&env,
asset.clone().into_val(&env),
price.into_val(&env),
decimals.into_val(&env),
confidence_score.into_val(&env),
ttl.into_val(&env),
liquidity.into_val(&env),
];
crate::auth::_require_auth_for_args(&env, &source, &auth_args);

if !env
.storage()
Expand Down Expand Up @@ -3433,9 +3442,10 @@ impl PriceOracle {
/// The owner can reassign the delegate by calling this again, or break the
/// link immediately with `clear_vote_delegate`.
pub fn delegate_vote(env: Env, owner: Address, delegate: Address) -> Result<(), ContractError> {
_require_not_destroyed(&env)?;
if crate::auth::_is_frozen(&env) { return Err(ContractError::ContractFrozen); }
owner.require_auth();
_require_not_destroyed(&env);
crate::auth::_require_not_frozen(&env);
let auth_args = soroban_sdk::vec![&env, owner.clone().into_val(&env), delegate.clone().into_val(&env)];
crate::auth::_require_auth_for_args(&env, &owner, &auth_args);

if owner == delegate {
return Err(ContractError::InvalidDelegate);
Expand All @@ -3450,8 +3460,9 @@ impl PriceOracle {

/// Remove the owner's active vote delegation.
pub fn clear_vote_delegate(env: Env, owner: Address) -> Result<(), ContractError> {
_require_not_destroyed(&env)?;
owner.require_auth();
_require_not_destroyed(&env);
let auth_args = soroban_sdk::vec![&env, owner.clone().into_val(&env)];
crate::auth::_require_auth_for_args(&env, &owner, &auth_args);

crate::auth::_remove_vote_delegate(&env, &owner);
env.events()
Expand All @@ -3471,10 +3482,11 @@ impl PriceOracle {
admin: Address,
delegate: Address,
) -> Result<(), ContractError> {
_require_not_destroyed(&env)?;
if crate::auth::_is_frozen(&env) { return Err(ContractError::ContractFrozen); }
admin.require_auth();
if !crate::auth::_is_authorized(&env, &admin) { return Err(ContractError::NotAuthorized); }
_require_not_destroyed(&env);
crate::auth::_require_not_frozen(&env);
let auth_args = soroban_sdk::vec![&env, admin.clone().into_val(&env), delegate.clone().into_val(&env)];
crate::auth::_require_auth_for_args(&env, &admin, &auth_args);
crate::auth::_require_authorized(&env, &admin);

if admin == delegate {
return Err(ContractError::InvalidDelegate);
Expand All @@ -3495,9 +3507,10 @@ impl PriceOracle {

/// Remove an active submission delegate from an administrative identity.
pub fn revoke_delegate(env: Env, admin: Address) -> Result<(), ContractError> {
_require_not_destroyed(&env)?;
admin.require_auth();
if !crate::auth::_is_authorized(&env, &admin) { return Err(ContractError::NotAuthorized); }
_require_not_destroyed(&env);
let auth_args = soroban_sdk::vec![&env, admin.clone().into_val(&env)];
crate::auth::_require_auth_for_args(&env, &admin, &auth_args);
crate::auth::_require_authorized(&env, &admin);

if let Some(delegate) = crate::auth::_get_delegate(&env, &admin) {
crate::auth::_remove_delegate(&env, &admin);
Expand Down Expand Up @@ -4347,7 +4360,7 @@ impl PriceOracle {
}

/// Get the relayer's current consecutive missed-block count.
pub fn get_provider_consecutive_missed_blocks(env: Env, relayer: Address) -> u32 {
pub fn get_missed_blocks(env: Env, relayer: Address) -> u32 {
crate::slashing::get_consecutive_missed_blocks(&env, &relayer)
}

Expand Down Expand Up @@ -4437,14 +4450,14 @@ impl PriceOracle {

/// Claim accumulated rewards for a relayer. This is a thin wrapper that
/// delegates to the rewards module which enforces Checks-Effects-Interactions.
pub fn claim_rewards(env: Env, relayer: Address, token_contract: Address) -> i128 {
pub fn claim_relayer_rewards(env: Env, relayer: Address, token_contract: Address) -> i128 {
crate::rewards::Rewards::claim_rewards(env, relayer, token_contract)
}

// ── Circuit-Breaker ───────────────────────────────────────────────────────

/// Register a new coordinator node that may trip/reset the circuit-breaker.
pub fn register_circuit_breaker_coordinator(
pub fn register_breaker_coord(
env: Env,
admin: Address,
coordinator: Address,
Expand All @@ -4454,7 +4467,7 @@ impl PriceOracle {
}

/// Remove a coordinator node's circuit-breaker privileges.
pub fn remove_circuit_breaker_coordinator(
pub fn remove_breaker_coord(
env: Env,
admin: Address,
coordinator: Address,
Expand Down
3 changes: 0 additions & 3 deletions contracts/price-oracle/src/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,6 @@ pub fn require_nonzero_denominator(n: i128) -> Result<(), Error> {
}
}

// --- 3. Wrap in a Soroban String ------------------------------------------
let text = core::str::from_utf8(&out[..pos]).expect("price formatting produced invalid utf-8");
String::from_str(env, text)
/// Validate that a slippage tolerance is within acceptable bounds.
///
/// Slippage tolerance must be in the range [0, 10_000] basis points (0-100%).
Expand Down
Loading
Loading