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

Feat: whitelist LPs #NTRN-442 #117

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
6 changes: 6 additions & 0 deletions contracts/dao/neutron-chain-manager/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,12 @@ fn check_dex_update_msg_params(
return Err(ContractError::Unauthorized {});
}

if dex_params.params.whitelisted_lps != msg_update_params.params.whitelisted_lps
&& !dex_update_param_permission.whitelisted_lps
{
return Err(ContractError::Unauthorized {});
}

Ok(())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub struct ParamsDex {
pub max_jits_per_block: u64,
#[serde(deserialize_with = "deserialize_u64")]
pub good_til_purge_allowance: u64,
pub whitelisted_lps: Vec<String>,
}

/// The types below are used for querying dex module parameters via stargate.
Expand Down
2 changes: 2 additions & 0 deletions contracts/dao/neutron-chain-manager/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ impl Strategy {
paused: true,
max_jits_per_block: true,
good_til_purge_allowance: true,
whitelisted_lps: true,
}),
Strategy::AllowOnly(permissions) => {
match permissions.get(&PermissionType::UpdateDexParamsPermission) {
Expand Down Expand Up @@ -289,6 +290,7 @@ pub struct DexUpdateParamsPermission {
pub paused: bool,
pub max_jits_per_block: bool,
pub good_til_purge_allowance: bool,
pub whitelisted_lps: bool,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ impl WasmMockQuerier {
paused: false,
max_jits_per_block: 20,
good_til_purge_allowance: 25000,
whitelisted_lps: vec![],
},
});
SystemResult::Ok(ContractResult::from(resp))
Expand Down
62 changes: 57 additions & 5 deletions contracts/dao/neutron-chain-manager/src/testing/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ pub fn test_execute_execute_message_update_params_dex_authorized() {
admin_proposal: AdminProposal::ProposalExecuteMessage(ProposalExecuteMessage {
message: r#"{"@type":"/neutron.dex.MsgUpdateParams",
"authority":"neutron1hxskfdxpp5hqgtjj6am6nkjefhfzj359x0ar3z",
"params": {"fee_tiers":["1","2"],"paused":true,"max_jits_per_block":"25","good_til_purge_allowance":"540000"}}"#
"params": {"fee_tiers":["1","2"],"paused":true,"max_jits_per_block":"25","good_til_purge_allowance":"540000", "whitelisted_lps": ["neutron10h9stc5v6ntgeygf5xf945njqq5h32r54rf7kf"]}}"#
.to_string(),
}),
});
Expand Down Expand Up @@ -731,6 +731,7 @@ pub fn test_execute_execute_message_update_params_dex_authorized() {
paused: true,
max_jits_per_block: true,
good_til_purge_allowance: true,
whitelisted_lps: true,
})]),
)
.unwrap();
Expand All @@ -747,7 +748,7 @@ pub fn test_execute_execute_message_update_params_dex_unauthorized_fee_tiers() {
admin_proposal: AdminProposal::ProposalExecuteMessage(ProposalExecuteMessage {
message: r#"{"@type":"/neutron.dex.MsgUpdateParams",
"authority":"neutron1hxskfdxpp5hqgtjj6am6nkjefhfzj359x0ar3z",
"params": {"fee_tiers":["1","2"],"paused":true,"max_jits_per_block":"25","good_til_purge_allowance":"540000"}}"#
"params": {"fee_tiers":["1","2"],"paused":true,"max_jits_per_block":"25","good_til_purge_allowance":"540000", "whitelisted_lps": ["neutron10h9stc5v6ntgeygf5xf945njqq5h32r54rf7kf"]}}"#
.to_string(),
}),
});
Expand Down Expand Up @@ -776,6 +777,7 @@ pub fn test_execute_execute_message_update_params_dex_unauthorized_fee_tiers() {
paused: true,
max_jits_per_block: true,
good_til_purge_allowance: true,
whitelisted_lps: true,
})]),
)
.unwrap();
Expand All @@ -794,7 +796,7 @@ pub fn test_execute_execute_message_update_params_dex_unauthorized_paused() {
admin_proposal: AdminProposal::ProposalExecuteMessage(ProposalExecuteMessage {
message: r#"{"@type":"/neutron.dex.MsgUpdateParams",
"authority":"neutron1hxskfdxpp5hqgtjj6am6nkjefhfzj359x0ar3z",
"params": {"fee_tiers":["1","2"],"paused":true,"max_jits_per_block":"25","good_til_purge_allowance":"540000"}}"#
"params": {"fee_tiers":["1","2"],"paused":true,"max_jits_per_block":"25","good_til_purge_allowance":"540000", "whitelisted_lps": ["neutron10h9stc5v6ntgeygf5xf945njqq5h32r54rf7kf"]}}"#
.to_string(),
}),
});
Expand Down Expand Up @@ -823,6 +825,7 @@ pub fn test_execute_execute_message_update_params_dex_unauthorized_paused() {
paused: false,
max_jits_per_block: true,
good_til_purge_allowance: true,
whitelisted_lps: true,
})]),
)
.unwrap();
Expand All @@ -840,7 +843,7 @@ pub fn test_execute_execute_message_update_params_dex_unauthorized_max_jits_per_
admin_proposal: AdminProposal::ProposalExecuteMessage(ProposalExecuteMessage {
message: r#"{"@type":"/neutron.dex.MsgUpdateParams",
"authority":"neutron1hxskfdxpp5hqgtjj6am6nkjefhfzj359x0ar3z",
"params": {"fee_tiers":["1","2"],"paused":true,"max_jits_per_block":"25","good_til_purge_allowance":"540000"}}"#
"params": {"fee_tiers":["1","2"],"paused":true,"max_jits_per_block":"25","good_til_purge_allowance":"540000", "whitelisted_lps": ["neutron10h9stc5v6ntgeygf5xf945njqq5h32r54rf7kf"]}}"#
.to_string(),
}),
});
Expand Down Expand Up @@ -869,6 +872,7 @@ pub fn test_execute_execute_message_update_params_dex_unauthorized_max_jits_per_
paused: true,
max_jits_per_block: false,
good_til_purge_allowance: true,
whitelisted_lps: true,
})]),
)
.unwrap();
Expand All @@ -885,7 +889,7 @@ pub fn test_execute_execute_message_update_params_dex_unauthorized_good_til_purg
admin_proposal: AdminProposal::ProposalExecuteMessage(ProposalExecuteMessage {
message: r#"{"@type":"/neutron.dex.MsgUpdateParams",
"authority":"neutron1hxskfdxpp5hqgtjj6am6nkjefhfzj359x0ar3z",
"params": {"fee_tiers":["1","2"],"paused":true,"max_jits_per_block":"25","good_til_purge_allowance":"540000"}}"#
"params": {"fee_tiers":["1","2"],"paused":true,"max_jits_per_block":"25","good_til_purge_allowance":"540000", "whitelisted_lps": ["neutron10h9stc5v6ntgeygf5xf945njqq5h32r54rf7kf"]}}"#
.to_string(),
}),
});
Expand Down Expand Up @@ -914,6 +918,54 @@ pub fn test_execute_execute_message_update_params_dex_unauthorized_good_til_purg
paused: true,
max_jits_per_block: true,
good_til_purge_allowance: false,
whitelisted_lps: true,
})]),
)
.unwrap();

let info = message_info(&Addr::unchecked("addr1"), &[]);
let err = execute_execute_messages(deps.as_mut(), info.clone(), vec![msg]).unwrap_err();
assert_eq!(err, Unauthorized {});
}

/// Checks that you can't change `whitelisted_lps` if you don't have the permission to do so
/// (new style parameter changes).
#[test]
pub fn test_execute_execute_message_update_params_dex_unauthorized_whitelisted_lps() {
let msg = CosmosMsg::Custom(NeutronMsg::SubmitAdminProposal {
admin_proposal: AdminProposal::ProposalExecuteMessage(ProposalExecuteMessage {
message: r#"{"@type":"/neutron.dex.MsgUpdateParams",
"authority":"neutron1hxskfdxpp5hqgtjj6am6nkjefhfzj359x0ar3z",
"params": {"fee_tiers":["1","2"],"paused":true,"max_jits_per_block":"25","good_til_purge_allowance":"540000", "whitelisted_lps": ["neutron10h9stc5v6ntgeygf5xf945njqq5h32r54rf7kf"]}}"#
.to_string(),
}),
});

let mut deps = mock_dependencies();
let env = mock_env();
let info = message_info(&Addr::unchecked("neutron_dao_address"), &[]);

instantiate(
deps.as_mut(),
env.clone(),
info.clone(),
InstantiateMsg {
initial_strategy_address: Addr::unchecked("neutron_dao_address".to_string()),
},
)
.unwrap();

let info = message_info(&Addr::unchecked("neutron_dao_address"), &[]);
execute_add_strategy(
deps.as_mut(),
info.clone(),
Addr::unchecked("addr1".to_string()),
StrategyMsg::AllowOnly(vec![UpdateDexParamsPermission(DexUpdateParamsPermission {
fee_tiers: true,
paused: true,
max_jits_per_block: true,
good_til_purge_allowance: true,
whitelisted_lps: false,
})]),
)
.unwrap();
Expand Down
Loading