Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RYETH/BTC allow Aave V3 adaptor for RYETH/BTC, Cellar adaptor for RYBTC, cachePriceRouter function #221

Merged
merged 6 commits into from
Sep 12, 2023
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
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sommelier_steward"
version = "3.4.2"
version = "3.4.3"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
14 changes: 14 additions & 0 deletions proto/cellar_v2.proto
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ message CellarV2_2 {
RemoveAdaptorFromCatalogue remove_adaptor_from_catalogue = 14;
// Represents function `removePositionFromCatalogue(uint32 positionId)`
RemovePositionFromCatalogue remove_position_from_catalogue = 15;
// Represents function `cachePriceRouter(bool checkTotalAssets, uint16 allowableRange)`
CachePriceRouter cache_price_router = 16;
}
}

Expand Down Expand Up @@ -387,6 +389,18 @@ message CellarV2_2 {
message RemovePositionFromCatalogue {
uint32 position_id = 1;
}

/*
* Updates the cellar to use the latest price router in the registry.
*
* Represents function `cachePriceRouter(bool checkTotalAssets, uint16 allowableRange)`
*/
message CachePriceRouter {
// Whether to check the total assets of the cellar
bool check_total_assets = 1;
// The allowable range of the cellar's total assets to deviate between old and new routers
uint32 allowable_range = 2;
}
}

message CellarV2_5 {
Expand Down
2 changes: 1 addition & 1 deletion steward/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "steward"
authors = []
version = "3.4.2"
version = "3.4.3"
edition = "2018"

[dependencies]
Expand Down
37 changes: 35 additions & 2 deletions steward/src/cellars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,16 @@ pub const ORACLE2: (U256, &str) = (
"c47278b65443ce71cf47e8455bb343f2db11b70e",
);
pub const ALLOWED_PRICE_ORACLES: [(U256, &str); 2] = [ORACLE1, ORACLE2];
pub const ALLOWED_CACHE_PRICE_ROUTER: [&str; 1] = [CELLAR_RYETH];

// permissions

pub const ALLOWED_V2_0_SETUP_ADAPTORS: [(&str, &str); 1] = [(CELLAR_RYUSD, ADAPTOR_CELLAR_V2)];
pub const ALLOWED_V2_2_CATALOGUE_ADAPTORS: [(&str, &str); 0] = [];
pub const ALLOWED_V2_2_CATALOGUE_ADAPTORS: [(&str, &str); 3] = [
(CELLAR_RYETH, ADAPTOR_AAVE_V3_A_TOKEN_V1),
(CELLAR_RYBTC, ADAPTOR_AAVE_V3_A_TOKEN_V1),
(CELLAR_RYBTC, ADAPTOR_CELLAR_V1),
];
pub const ALLOWED_V2_5_CATALOGUE_ADAPTORS: [(&str, &str); 0] = [];

// due to position size limits in v2.0, positions must be added and removed from the limited list
Expand All @@ -61,7 +66,15 @@ pub const ALLOWED_V2_0_POSITIONS: [(&str, u32); 20] = [
(CELLAR_RYUSD, 28),
(CELLAR_RYUSD, 29),
];
pub const ALLOWED_V2_2_CATALOGUE_POSITIONS: [(&str, u32); 0] = [];
pub const ALLOWED_V2_2_CATALOGUE_POSITIONS: [(&str, u32); 7] = [
(CELLAR_RYETH, 188),
(CELLAR_RYETH, 189),
(CELLAR_RYETH, 190),
(CELLAR_RYETH, 191),
(CELLAR_RYBTC, 192),
(CELLAR_RYBTC, 193),
(CELLAR_RYBTC, 194),
];
pub const ALLOWED_V2_5_CATALOGUE_POSITIONS: [(&str, u32); 0] = [];

pub const BLOCKED_ADAPTORS: [&str; 3] = [
Expand Down Expand Up @@ -116,6 +129,8 @@ pub const ADAPTOR_COMPOUND_C_TOKEN_V1: &str = "26dba82495f6189dde7648ae88bead46c

// adaptors

pub const ADAPTOR_AAVE_V3_A_TOKEN_V1: &str = "76cef5606c8b6ba38fe2e3c639e1659afa530b47";
pub const ADAPTOR_CELLAR_V1: &str = "1e22adf9e63ef8f2a3626841ddddd19683e31068";
EricBolten marked this conversation as resolved.
Show resolved Hide resolved
pub const ADAPTOR_CELLAR_V2: &str = "3b5ca5de4d808cd793d3a7b3a731d3e67e707b27";
pub const ADAPTOR_MORPHO_AAVE_V2_A_TOKEN_V1: &str = "1a4cb53edb8c65c3df6aa9d88c1ab4cf35312b73";
pub const ADAPTOR_MORPHO_AAVE_V2_DEBT_TOKEN_V1: &str = "407d5489f201013ee6a6ca20fccb05047c548138";
Expand Down Expand Up @@ -204,6 +219,24 @@ pub fn validate_oracle(
Ok(())
}

pub fn validate_cache_price_router(
cellar_id: &str,
check_total_assets_value: bool,
allowable_range_value: u32,
) -> Result<(), Error> {
if !check_total_assets_value || allowable_range_value != 500 {
return Err(sp_call_error(
"unauthorized arguments for cachePriceRouter call".to_string(),
));
}
let cellar_id_normalized = normalize_address(cellar_id.to_string());
if !ALLOWED_CACHE_PRICE_ROUTER.contains(&cellar_id_normalized.as_str()) {
return Err(sp_call_error("call not authorized for cellar".to_string()));
}

Ok(())
}

pub fn check_blocked_adaptor(adaptor_id: &str) -> Result<(), Error> {
let adaptor_id = normalize_address(adaptor_id.to_string());
if BLOCKED_ADAPTORS.contains(&adaptor_id.as_str()) {
Expand Down
22 changes: 20 additions & 2 deletions steward/src/cellars/cellar_v2_2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ use crate::{
};

use super::{
check_blocked_adaptor, check_blocked_position, log_cellar_call, validate_new_adaptor,
validate_new_position, V2_2_PERMISSIONS,
check_blocked_adaptor, check_blocked_position, log_cellar_call, validate_cache_price_router,
validate_new_adaptor, validate_new_position, V2_2_PERMISSIONS,
};

const CELLAR_NAME: &str = "CellarV2.2";
Expand Down Expand Up @@ -233,6 +233,24 @@ pub fn get_encoded_function(call: FunctionCall, cellar_id: String) -> Result<Vec

Ok(CellarV2_2Calls::RemovePositionFromCatalogue(call).encode())
}
Function::CachePriceRouter(params) => {
validate_cache_price_router(
&cellar_id,
params.check_total_assets,
params.allowable_range,
)?;
log_cellar_call(
CELLAR_NAME,
&CachePriceRouterCall::function_name(),
&cellar_id,
);
let call = CachePriceRouterCall {
check_total_assets: params.check_total_assets,
allowable_range: params.allowable_range as u16,
EricBolten marked this conversation as resolved.
Show resolved Hide resolved
};

Ok(CellarV2_2Calls::CachePriceRouter(call).encode())
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion steward_abi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "steward_abi"
version = "3.4.2"
version = "3.4.3"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
Loading
Loading