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

Fix/add position bug #212

Merged
merged 4 commits into from
Jul 5, 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.3.0"
version = "3.3.1"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
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.3.0"
version = "3.3.1"
edition = "2018"

[dependencies]
Expand Down
45 changes: 0 additions & 45 deletions steward/src/cellars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ pub(crate) mod cellar_v2_2;

// allow/block lists.

pub const ALLOWED_ADD_POSITION: [(&str, u32); 3] =
[(CELLAR_RYUSD, 25), (CELLAR_RYUSD, 26), (CELLAR_RYUSD, 27)];
pub const ALLOWED_CATALOGUE_ADAPTORS: [(&str, &str); 6] = [
(CELLAR_RYETH, ADAPTOR_MORPHO_AAVE_V2_A_TOKEN_V1),
(CELLAR_RYETH, ADAPTOR_MORPHO_AAVE_V2_DEBT_TOKEN_V1),
Expand Down Expand Up @@ -110,18 +108,6 @@ pub fn check_blocked_position(position: &u32) -> Result<(), Error> {
Ok(())
}

pub fn validate_add_position(cellar_id: &str, position: u32) -> Result<(), Error> {
check_blocked_position(&position)?;
let cellar_id = normalize_address(cellar_id.to_string());
if !ALLOWED_ADD_POSITION.contains(&(&cellar_id, position)) {
return Err(sp_call_error(format!(
"position {position} not allowed to be added for {cellar_id}"
)));
}

Ok(())
}

pub fn validate_add_adaptor_to_catalogue(cellar_id: &str, adaptor_id: &str) -> Result<(), Error> {
let adaptor_id = normalize_address(adaptor_id.to_string());
check_blocked_adaptor(&adaptor_id)?;
Expand Down Expand Up @@ -243,37 +229,6 @@ mod tests {
assert_eq!(expected_err, res.unwrap_err().to_string());
}

#[test]
fn test_validate_add_position() {
// allows approved cellar/position ID pairs
let (cellar_id, approved_pos) = (CELLAR_RYUSD, 25);
assert!(validate_add_position(cellar_id, approved_pos).is_ok());

let error_prefix = "SP call error: ".to_string();

// rejects blocked position ID
let blocked_pos = 4;
let res = validate_add_position(cellar_id, blocked_pos);
let expected_err = error_prefix.clone() + &format!("position {blocked_pos} is blocked");
assert!(res.is_err());
assert_eq!(expected_err, res.unwrap_err().to_string());

// rejects unapproved cellar/position ID pair
let unapproved_pos = 20;
let res = validate_add_position(cellar_id, unapproved_pos);
let expected_err = error_prefix.clone()
+ &format!("position {unapproved_pos} not allowed to be added for {cellar_id}");
assert!(res.is_err());
assert_eq!(expected_err, res.unwrap_err().to_string());

let unapproved_cellar = "0000000000000000000000000000000000000000";
let res = validate_add_position(unapproved_cellar, approved_pos);
let expected_err = error_prefix
+ &format!("position {approved_pos} not allowed to be added for {unapproved_cellar}");
assert!(res.is_err());
assert_eq!(expected_err, res.unwrap_err().to_string());
}

#[test]
fn test_validate_add_adaptor_to_catalogue() {
// allows approved cellar/adaptor ID pairs
Expand Down
4 changes: 2 additions & 2 deletions steward/src/cellars/cellar_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{
};

use super::{
check_blocked_adaptor, log_cellar_call, normalize_address, validate_add_position,
check_blocked_adaptor, check_blocked_position, log_cellar_call, normalize_address,
validate_setup_adaptor,
};

Expand All @@ -26,7 +26,7 @@ const CELLAR_NAME: &str = "CellarV2";
pub fn get_encoded_call(function: StrategyFunction, cellar_id: String) -> Result<Vec<u8>, Error> {
match function {
AddPosition(params) => {
validate_add_position(&cellar_id, params.position_id)?;
check_blocked_position(&params.position_id)?;
log_cellar_call(CELLAR_NAME, &AddPositionCall::function_name(), &cellar_id);

let call = AddPositionCall {
Expand Down
6 changes: 3 additions & 3 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, log_cellar_call, validate_add_adaptor_to_catalogue,
validate_add_position, validate_add_position_to_catalogue,
check_blocked_adaptor, check_blocked_position, log_cellar_call,
validate_add_adaptor_to_catalogue, validate_add_position_to_catalogue,
};

const CELLAR_NAME: &str = "CellarV2.2";
Expand Down Expand Up @@ -51,7 +51,7 @@ pub fn get_encoded_function(call: FunctionCall, cellar_id: String) -> Result<Vec
.ok_or_else(|| sp_call_error("call data is empty".to_string()))?;
match function {
Function::AddPosition(params) => {
validate_add_position(&cellar_id, params.position_id)?;
check_blocked_position(&params.position_id)?;
log_cellar_call(CELLAR_NAME, &AddPositionCall::function_name(), &cellar_id);

let call = AddPositionCall {
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.3.0"
version = "3.3.1"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
2 changes: 1 addition & 1 deletion steward_proto_rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "steward_proto"
version = "3.3.0"
version = "3.3.1"
edition = "2021"

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