Skip to content

Commit

Permalink
Move allow values to consts
Browse files Browse the repository at this point in the history
  • Loading branch information
cbrit committed Sep 1, 2023
1 parent 432a7e3 commit 045219f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
17 changes: 17 additions & 0 deletions steward/src/cellars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ pub(crate) mod cellar_v2_5;
// constants
// addresses are normalized by removing the 0x prefix and converting to lowercase for reliable comparison

// oracles

pub const ORACLE1: (U256, &'static str) = (
U256([3, 0, 0, 0]),
"72249f0199eacf6230def33a31e80cf76de78f67",
);
pub const ORACLE2: (U256, &'static str) = (
U256([5, 0, 0, 0]),
"c47278b65443ce71cf47e8455bb343f2db11b70e",
);
pub const ALLOWED_PRICE_ORACLES: [(U256, &'static str); 2] = [ORACLE1, ORACLE2];

// permissions

pub const ALLOWED_V2_0_SETUP_ADAPTORS: [(&str, &str); 1] = [(CELLAR_RYUSD, ADAPTOR_CELLAR_V2)];
Expand Down Expand Up @@ -359,4 +371,9 @@ mod tests {
assert!(res.is_err());
assert_eq!(expected_err, res.unwrap_err().to_string());
}

#[test]
fn test_U256_sanity() {
assert_eq!(U256([5, 0, 0, 0]), U256::from(5));
}
}
11 changes: 3 additions & 8 deletions steward/src/cellars/cellar_v2_5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ use crate::{

use super::{
check_blocked_adaptor, check_blocked_position, log_cellar_call, normalize_address,
validate_new_adaptor, validate_new_position, CELLAR_TURBO_SWETH, V2_5_PERMISSIONS,
validate_new_adaptor, validate_new_position, ALLOWED_PRICE_ORACLES, CELLAR_TURBO_SWETH,
V2_5_PERMISSIONS,
};

const CELLAR_NAME: &str = "CellarV2.5";
Expand Down Expand Up @@ -263,15 +264,9 @@ pub fn get_encoded_function(call: FunctionCall, cellar_id: String) -> Result<Vec
Function::SetSharePriceOracle(params) => {
let cellar_id_normalized = normalize_address(cellar_id.clone());
let oracle_in = normalize_address(params.oracle.clone());
let allowed_oracles = [
normalize_address("0x72249f0199EACf6230DEF33A31e80CF76de78f67".to_string()),
normalize_address("0xC47278B65443cE71CF47E8455BB343F2DB11B70e".to_string()),
];
let allowed_registry_ids = [U256::from(3), U256::from(5)];
let registry_id_in = string_to_u256(params.registry_id.clone())?;
if !cellar_id_normalized.eq(CELLAR_TURBO_SWETH)
|| !allowed_oracles.contains(&oracle_in)
|| !allowed_registry_ids.contains(&registry_id_in)
|| !ALLOWED_PRICE_ORACLES.contains(&(registry_id_in, &oracle_in))
{
return Err(ErrorKind::SPCallError
.context("unauthorized oracle update".to_string())
Expand Down

0 comments on commit 045219f

Please sign in to comment.