Skip to content
Open
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
150 changes: 150 additions & 0 deletions contracts/price-oracle/check_output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
Checking price-oracle v0.0.0 (/home/abujulaybeeb/Documents/Drips 13/stellarflow-contracts/contracts/price-oracle)
error[E0425]: cannot find type `PriceDataWithStatus` in this scope
--> contracts/price-oracle/src/lib.rs:27:65
|
27 | fn get_price_with_status(env: Env, asset: Symbol) -> Result<PriceDataWithStatus, Error>;
| ^^^^^^^^^^^^^^^^^^^ not found in this scope
|
help: consider importing this struct
|
3 + use crate::types::PriceDataWithStatus;
|

error[E0425]: cannot find type `PriceDataWithStatus` in this scope
--> contracts/price-oracle/src/lib.rs:523:69
|
523 | pub fn get_price_with_status(env: Env, asset: Symbol) -> Result<PriceDataWithStatus, Error> {
| ^^^^^^^^^^^^^^^^^^^ not found in this scope
|
help: consider importing this struct
|
3 + use crate::types::PriceDataWithStatus;
|

error[E0422]: cannot find struct, variant or union type `PriceDataWithStatus` in this scope
--> contracts/price-oracle/src/lib.rs:533:20
|
533 | Ok(PriceDataWithStatus {
| ^^^^^^^^^^^^^^^^^^^ not found in this scope
|
help: consider importing this struct
|
3 + use crate::types::PriceDataWithStatus;
|

error[E0425]: cannot find type `PriceEntryWithStatus` in this scope
--> contracts/price-oracle/src/lib.rs:600:34
|
600 | ) -> soroban_sdk::Vec<Option<PriceEntryWithStatus>> {
| ^^^^^^^^^^^^^^^^^^^^ not found in this scope
|
help: consider importing this struct
|
3 + use crate::types::PriceEntryWithStatus;
|

error[E0422]: cannot find struct, variant or union type `PriceEntryWithStatus` in this scope
--> contracts/price-oracle/src/lib.rs:611:52
|
611 | let entry = prices.get(asset).map(|pd| PriceEntryWithStatus {
| ^^^^^^^^^^^^^^^^^^^^ not found in this scope
|
help: consider importing this struct
|
3 + use crate::types::PriceEntryWithStatus;
|

error[E0422]: cannot find struct, variant or union type `RescueTokensEvent` in this scope
--> contracts/price-oracle/src/lib.rs:734:37
|
734 | env.events().publish_event(&RescueTokensEvent {
| ^^^^^^^^^^^^^^^^^ not found in this scope

warning: unused import: `alloc::string::ToString`
--> contracts/price-oracle/src/math.rs:3:5
|
3 | use alloc::string::ToString;
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` (part of `#[warn(unused)]`) on by default

warning: unused import: `Symbol`
--> contracts/price-oracle/src/types.rs:1:42
|
1 | use soroban_sdk::{contracttype, Address, Symbol};
| ^^^^^^

warning: use of deprecated method `soroban_sdk::events::Events::publish`: use the #[contractevent] macro on a contract event type
--> contracts/price-oracle/src/lib.rs:326:22
|
326 | env.events().publish(
| ^^^^^^^
|
= note: `#[warn(deprecated)]` on by default

warning: use of deprecated method `soroban_sdk::events::Events::publish`: use the #[contractevent] macro on a contract event type
--> contracts/price-oracle/src/lib.rs:351:22
|
351 | env.events().publish(
| ^^^^^^^

error[E0599]: no variant or associated item named `AssetDescription` found for enum `types::DataKey` in the current scope
--> contracts/price-oracle/src/lib.rs:640:28
|
640 | .set(&DataKey::AssetDescription(asset), &description);
| ^^^^^^^^^^^^^^^^ variant or associated item not found in `types::DataKey`
|
::: contracts/price-oracle/src/types.rs:5:1
|
5 | pub enum DataKey {
| ---------------- variant or associated item `AssetDescription` not found for this enum

error[E0599]: no variant or associated item named `AssetDescription` found for enum `types::DataKey` in the current scope
--> contracts/price-oracle/src/lib.rs:649:28
|
649 | .get(&DataKey::AssetDescription(asset))
| ^^^^^^^^^^^^^^^^ variant or associated item not found in `types::DataKey`
|
::: contracts/price-oracle/src/types.rs:5:1
|
5 | pub enum DataKey {
| ---------------- variant or associated item `AssetDescription` not found for this enum

error[E0433]: failed to resolve: use of undeclared type `TokenContractClient`
--> contracts/price-oracle/src/lib.rs:731:28
|
731 | let token_client = TokenContractClient::new(&env, &token);
| ^^^^^^^^^^^^^^^^^^^ use of undeclared type `TokenContractClient`

warning: use of deprecated method `soroban_sdk::events::Events::publish`: use the #[contractevent] macro on a contract event type
--> contracts/price-oracle/src/lib.rs:989:22
|
989 | env.events().publish(
| ^^^^^^^

warning: use of deprecated method `soroban_sdk::events::Events::publish`: use the #[contractevent] macro on a contract event type
--> contracts/price-oracle/src/lib.rs:1033:22
|
1033 | env.events().publish(
| ^^^^^^^

warning: use of deprecated method `soroban_sdk::events::Events::publish`: use the #[contractevent] macro on a contract event type
--> contracts/price-oracle/src/lib.rs:1082:22
|
1082 | env.events().publish(
| ^^^^^^^

warning: variable does not need to be mutable
--> contracts/price-oracle/src/lib.rs:771:13
|
771 | let mut tracked = get_tracked_assets(&env);
| ----^^^^^^^
| |
| help: remove this `mut`
|
= note: `#[warn(unused_mut)]` (part of `#[warn(unused)]`) on by default

Some errors have detailed explanations: E0422, E0425, E0433, E0599.
For more information about an error, try `rustc --explain E0422`.
warning: `price-oracle` (lib) generated 8 warnings
error: could not compile `price-oracle` (lib) due to 9 previous errors; 8 warnings emitted
34 changes: 25 additions & 9 deletions contracts/price-oracle/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ use soroban_sdk::{contracttype, Address, Env, Vec};
// Storage Key
// ─────────────────────────────────────────────────────────────────────────────

use crate::types::DataKey;

#[contracttype]
pub enum DataKey {
Admin,
Provider(Address),
ProviderWeight(Address),
IsPaused,
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct Provider {
pub joined_ledger: u32,
}


// ─────────────────────────────────────────────────────────────────────────────
// Storage Helpers
// ─────────────────────────────────────────────────────────────────────────────
Expand Down Expand Up @@ -105,11 +106,15 @@ pub fn _set_paused(env: &Env, paused: bool) {

/// Whitelist a provider address.
pub fn _add_provider(env: &Env, provider: &Address) {
let p = Provider {
joined_ledger: env.ledger().sequence(),
};
env.storage()
.instance()
.set(&DataKey::Provider(provider.clone()), &true);
.set(&DataKey::Provider(provider.clone()), &p);
}


/// Remove a provider from the whitelist.
pub fn _remove_provider(env: &Env, provider: &Address) {
env.storage()
Expand All @@ -121,10 +126,17 @@ pub fn _remove_provider(env: &Env, provider: &Address) {
pub fn _is_provider(env: &Env, addr: &Address) -> bool {
env.storage()
.instance()
.get::<DataKey, bool>(&DataKey::Provider(addr.clone()))
.unwrap_or(false)
.has(&DataKey::Provider(addr.clone()))
}

/// Returns the provider info if whitelisted.
pub fn _get_provider(env: &Env, addr: &Address) -> Option<Provider> {
env.storage()
.instance()
.get::<DataKey, Provider>(&DataKey::Provider(addr.clone()))
}


/// Panics if the caller is not a whitelisted provider.
pub fn _require_provider(env: &Env, caller: &Address) {
if !_is_provider(env, caller) {
Expand All @@ -148,8 +160,12 @@ pub fn _get_provider_weight(env: &Env, provider: &Address) -> u32 {
// ─────────────────────────────────────────────────────────────────────────────
// Tests
// ─────────────────────────────────────────────────────────────────────────────

#[cfg(test)]
mod auth_tests {



extern crate alloc;
use super::*;
use soroban_sdk::{contract, contractimpl};
Expand Down Expand Up @@ -437,7 +453,7 @@ mod auth_tests {

#[test]
fn test_renounce_ownership_removes_all_admins() {
let (env, contract_id, admin1) = setup();
let (env, contract_id, _admin1) = setup();
let admin2 = <soroban_sdk::Address as soroban_sdk::testutils::Address>::generate(&env);
env.as_contract(&contract_id, || {
_add_authorized(&env, &admin2);
Expand Down
39 changes: 32 additions & 7 deletions contracts/price-oracle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ pub trait StellarFlowTrait {
/// The new asset is added to the internal asset list and initialized with a zero-price placeholder.
fn add_asset(env: Env, admin: Address, asset: Symbol) -> Result<(), Error>;

/// Whitelist a provider address.
fn add_provider(env: Env, admin: Address, provider: Address);

/// Remove a provider from the whitelist.
fn remove_provider(env: Env, admin: Address, provider: Address);


/// Get the current admin address.
///
/// Returns the address of the contract administrator.
Expand Down Expand Up @@ -142,7 +149,7 @@ pub enum Error {
/// Price change exceeds maximum allowed threshold (flash crash protection).
FlashCrashDetected = 5,
/// Caller is not authorized to perform this action.
NotAuthorized = 5,
NotAuthorized = 15,
/// Contract or admin has already been initialized.
AlreadyInitialized = 6,
/// Price change exceeds the allowed delta limit in a single update.
Expand Down Expand Up @@ -460,6 +467,7 @@ impl PriceOracle {
admin.require_auth();
crate::auth::_require_authorized(&env, &admin);

if !crate::asset_symbol::is_approved_asset_symbol(asset.clone()) { return Err(Error::InvalidAssetSymbol); }
track_asset(&env, asset.clone());

let storage = env.storage().temporary();
Expand Down Expand Up @@ -488,6 +496,23 @@ impl PriceOracle {
Ok(())
}

/// Whitelist a provider address.
pub fn add_provider(env: Env, admin: Address, provider: Address) {
admin.require_auth();
crate::auth::_require_authorized(&env, &admin);

crate::auth::_add_provider(&env, &provider);
}

/// Remove a provider from the whitelist.
pub fn remove_provider(env: Env, admin: Address, provider: Address) {
admin.require_auth();
crate::auth::_require_authorized(&env, &admin);

crate::auth::_remove_provider(&env, &provider);
}


/// Return the current admin addresses.
pub fn get_admin(env: Env) -> Address {
crate::auth::_get_admin(&env)
Expand Down Expand Up @@ -644,7 +669,7 @@ impl PriceOracle {
pub fn get_price_with_status(env: Env, asset: Symbol) -> Result<PriceDataWithStatus, Error> {
let prices: soroban_sdk::Map<Symbol, PriceData> = env
.storage()
.persistent()
.temporary()
.get(&DataKey::PriceData)
.unwrap_or_else(|| soroban_sdk::Map::new(&env));

Expand Down Expand Up @@ -721,7 +746,7 @@ impl PriceOracle {
) -> soroban_sdk::Vec<Option<PriceEntryWithStatus>> {
let prices: soroban_sdk::Map<Symbol, PriceData> = env
.storage()
.persistent()
.temporary()
.get(&DataKey::PriceData)
.unwrap_or_else(|| soroban_sdk::Map::new(&env));

Expand Down Expand Up @@ -790,7 +815,7 @@ impl PriceOracle {
panic_with_error!(&env, Error::InvalidPrice);
}

let storage = env.storage().persistent();
let storage = env.storage().temporary();
let mut prices: soroban_sdk::Map<Symbol, PriceData> = storage
.get(&DataKey::PriceData)
.unwrap_or_else(|| soroban_sdk::Map::new(&env));
Expand Down Expand Up @@ -898,7 +923,7 @@ impl PriceOracle {
prices.remove(asset.clone());
storage.set(&DataKey::PriceData, &prices);

let mut tracked = get_tracked_assets(&env);
let tracked = get_tracked_assets(&env);
let mut updated_assets = soroban_sdk::Vec::new(&env);
for tracked_asset in tracked.iter() {
if tracked_asset != asset {
Expand Down Expand Up @@ -1051,7 +1076,7 @@ impl PriceOracle {
assert!(min_price > 0 && max_price > 0, "bounds must be positive");
assert!(min_price <= max_price, "min_price must be <= max_price");

let storage = env.storage().temporary();
let storage = env.storage().instance();
let mut bounds_map: soroban_sdk::Map<Symbol, PriceBounds> = storage
.get(&DataKey::PriceBoundsData)
.unwrap_or_else(|| soroban_sdk::Map::new(&env));
Expand All @@ -1070,7 +1095,7 @@ impl PriceOracle {
pub fn get_price_bounds(env: Env, asset: Symbol) -> Option<PriceBounds> {
let bounds_map: soroban_sdk::Map<Symbol, PriceBounds> = env
.storage()
.temporary()
.instance()
.get(&DataKey::PriceBoundsData)
.unwrap_or_else(|| soroban_sdk::Map::new(&env));
bounds_map.get(asset)
Expand Down
1 change: 0 additions & 1 deletion contracts/price-oracle/src/math.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use soroban_sdk::{Env, String};
extern crate alloc;
use alloc::string::ToString;

/// Format a scaled integer price into a human-readable decimal string.
///
Expand Down
Loading