Skip to content

Commit

Permalink
moved unused/non-building contracts into archive (#361)
Browse files Browse the repository at this point in the history
  • Loading branch information
DrPresident authored Sep 25, 2023
1 parent 555ea6d commit 40ece0a
Show file tree
Hide file tree
Showing 77 changed files with 129 additions and 146 deletions.
17 changes: 5 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ resolver = "2"
members = [
# Packages
"packages/shade_protocol",
"packages/secretcli",
# "packages/secretcli",
"packages/multi_test",
"packages/multi_derive",
"packages/contract_derive",
Expand All @@ -13,11 +13,6 @@ members = [

# Protocol contracts
"contracts/snip20",
"contracts/governance",
# "contracts/bonds", //TODO: migrate to v1
# "contracts/liability_mint", //TODO: migrate
"contracts/sky",
"contracts/peg_stability",
"contracts/query_auth",
"contracts/admin",
"contracts/basic_staking",
Expand All @@ -34,11 +29,9 @@ members = [
# - Adapters
"contracts/dao/scrt_staking",
"contracts/dao/stkd_scrt",
"contracts/dao/rewards_emission",
"contracts/dao/lp_shdswap",
# "contracts/dao/rewards_emission",
# "contracts/dao/lp_shdswap",

# "contracts/snip20_staking", //TODO: migrate to v1

# Mock contracts
# "contracts/mock/mock_band", //TODO: migrate to v1
# "contracts/mock/mock_secretswap_pair", //TODO: migrate to v1
Expand All @@ -47,8 +40,8 @@ members = [
"contracts/mock/mock_stkd_derivative",

# Tools
"tools/doc2book",
"launch"
# "tools/doc2book",
# "launch"
]

exclude = ["packages/network_integration"]
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
28 changes: 5 additions & 23 deletions contracts/admin/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,36 +1,18 @@
use shade_protocol::{
admin::{
errors::unauthorized_super,
AdminAuthStatus,
AdminsResponse,
ConfigResponse,
ExecuteMsg,
InstantiateMsg,
PermissionsResponse,
QueryMsg,
errors::unauthorized_super, AdminAuthStatus, AdminsResponse, ConfigResponse, ExecuteMsg,
InstantiateMsg, PermissionsResponse, QueryMsg,
},
c_std::{
shd_entry_point,
to_binary,
Addr,
Deps,
DepsMut,
Env,
MessageInfo,
QueryResponse,
Response,
StdResult,
Storage,
shd_entry_point, to_binary, Addr, Deps, DepsMut, Env, MessageInfo, QueryResponse, Response,
StdResult, Storage,
},
utils::pad_handle_result,
};

use crate::{
execute::{
try_self_destruct,
try_toggle_status,
try_transfer_super,
try_update_registry,
try_self_destruct, try_toggle_status, try_transfer_super, try_update_registry,
try_update_registry_bulk,
},
query::query_validate_permission,
Expand Down
8 changes: 4 additions & 4 deletions contracts/admin/src/execute.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::shared::{validate_permissions, ADMINS, PERMISSIONS, STATUS, SUPER};
use shade_protocol::admin::errors::{no_permission, unregistered_admin};
use shade_protocol::c_std::{DepsMut, Response, Storage, Api, Addr, StdResult};
use shade_protocol::admin::{RegistryAction, AdminAuthStatus};
use crate::shared::{STATUS, ADMINS, PERMISSIONS, SUPER, validate_permissions};
use shade_protocol::admin::{AdminAuthStatus, RegistryAction};
use shade_protocol::c_std::{Addr, Api, DepsMut, Response, StdResult, Storage};

/// Performs one registry update. Cannot be run during a shutdown.
pub fn try_update_registry(
Expand Down Expand Up @@ -164,4 +164,4 @@ fn verify_registered(admins: &[Addr], user: &Addr) -> StdResult<()> {
return Err(no_permission(user.as_str()));
}
Ok(())
}
}
17 changes: 8 additions & 9 deletions contracts/admin/src/shared.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use shade_protocol::c_std::Addr;
use shade_protocol::{admin::{AdminAuthStatus, errors::invalid_permission_format}, c_std::StdResult};
use shade_protocol::utils::storage::plus::{Map, Item};
use shade_protocol::utils::storage::plus::{Item, Map};
use shade_protocol::{
admin::{errors::invalid_permission_format, AdminAuthStatus},
c_std::StdResult,
};

/// Maps user to permissions for which they have user.
pub const PERMISSIONS: Map<&Addr, Vec<String>> = Map::new("permissions");
Expand All @@ -20,17 +23,13 @@ pub fn validate_permissions(permissions: &[String]) -> StdResult<()> {

pub fn is_valid_permission(permission: &str) -> StdResult<()> {
if permission.len() <= 10 {
return Err(invalid_permission_format(
permission
));
return Err(invalid_permission_format(permission));
}
let valid_chars = permission.bytes().all(|byte| {
(b'A'..=b'Z').contains(&byte) || (b'0'..=b'9').contains(&byte) || b'_'.eq(&byte)
});
if !valid_chars {
return Err(invalid_permission_format(
permission
));
return Err(invalid_permission_format(permission));
}
Ok(())
}
}
178 changes: 95 additions & 83 deletions contracts/admin/src/test.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
use crate::{
shared::is_valid_permission,
};
use crate::shared::is_valid_permission;
use rstest::*;
use shade_multi_test::multi::admin::Admin;
use shade_protocol::{
admin::{
AdminAuthStatus,
AdminsResponse,
ConfigResponse,
ExecuteMsg,
InstantiateMsg,
PermissionsResponse,
QueryMsg,
RegistryAction,
ValidateAdminPermissionResponse,
AdminAuthStatus, AdminsResponse, ConfigResponse, ExecuteMsg, InstantiateMsg,
PermissionsResponse, QueryMsg, RegistryAction, ValidateAdminPermissionResponse,
},
c_std::Addr,
multi_test::App,
Expand Down Expand Up @@ -43,51 +34,80 @@ fn test_is_valid_permission(#[case] permission: String, #[case] is_valid: bool)
#[case(AdminAuthStatus::Maintenance, vec![true, true, true, false, true, true, true])]
#[case(AdminAuthStatus::Shutdown, vec![false, false, false, false, false, false, true])]
fn test_status(#[case] status: AdminAuthStatus, #[case] expect_success: Vec<bool>) {
//init
let mut chain: App = App::default();
let contract = InstantiateMsg { super_admin: None }
.test_init(
Admin::default(),
&mut chain,
Addr::unchecked("admin"),
"admin_contract",
&[],
)
.unwrap();
//set state
ExecuteMsg::ToggleStatus { new_status: status }.test_exec(&contract, &mut chain, Addr::unchecked("admin"), &[]).unwrap();

//register 'super' as admin
let action = RegistryAction::RegisterAdmin { user: "super".to_string() };
let result = ExecuteMsg::UpdateRegistry { action: action.clone() }.test_exec(&contract, &mut chain, Addr::unchecked("admin"), &[]);
assert_eq!(&result.is_ok(), expect_success.get(0).unwrap());

//test bulk update
let actions = vec![action.clone()];
let result = ExecuteMsg::UpdateRegistryBulk { actions }.test_exec(&contract, &mut chain, Addr::unchecked("admin"), &[]);
assert_eq!(&result.is_ok(), expect_success.get(1).unwrap());

//set super admin to 'super'
let result = ExecuteMsg::TransferSuper { new_super: "super".to_string() }.test_exec(&contract, &mut chain, Addr::unchecked("admin"), &[]);
assert_eq!(&result.is_ok(), expect_success.get(2).unwrap());

//register 'admin' as admin without being the super user
let action = RegistryAction::RegisterAdmin { user: "admin".to_string() };
let result = ExecuteMsg::UpdateRegistry { action: action.clone() }.test_exec(&contract, &mut chain, Addr::unchecked("admin"), &[]);
assert_eq!(&result.is_ok(), expect_success.get(3).unwrap());

//register admin as admin with correct permissions
let action = RegistryAction::RegisterAdmin { user: "admin".to_string() };
let result = ExecuteMsg::UpdateRegistry { action: action.clone() }.test_exec(&contract, &mut chain, Addr::unchecked("super"), &[]);
assert_eq!(&result.is_ok(), expect_success.get(4).unwrap());

//set super admin to 'admin'
let result = ExecuteMsg::TransferSuper { new_super: "admin".to_string() }.test_exec(&contract, &mut chain, Addr::unchecked("super"), &[]);
assert_eq!(&result.is_ok(), expect_success.get(5).unwrap());

//self destruct
let result = ExecuteMsg::SelfDestruct { }.test_exec(&contract, &mut chain, Addr::unchecked("admin"), &[]);
assert_eq!(&result.is_ok(), expect_success.get(6).unwrap());
//init
let mut chain: App = App::default();
let contract = InstantiateMsg { super_admin: None }
.test_init(
Admin::default(),
&mut chain,
Addr::unchecked("admin"),
"admin_contract",
&[],
)
.unwrap();
//set state
ExecuteMsg::ToggleStatus { new_status: status }
.test_exec(&contract, &mut chain, Addr::unchecked("admin"), &[])
.unwrap();

//register 'super' as admin
let action = RegistryAction::RegisterAdmin {
user: "super".to_string(),
};
let result = ExecuteMsg::UpdateRegistry {
action: action.clone(),
}
.test_exec(&contract, &mut chain, Addr::unchecked("admin"), &[]);
assert_eq!(&result.is_ok(), expect_success.get(0).unwrap());

//test bulk update
let actions = vec![action.clone()];
let result = ExecuteMsg::UpdateRegistryBulk { actions }.test_exec(
&contract,
&mut chain,
Addr::unchecked("admin"),
&[],
);
assert_eq!(&result.is_ok(), expect_success.get(1).unwrap());

//set super admin to 'super'
let result = ExecuteMsg::TransferSuper {
new_super: "super".to_string(),
}
.test_exec(&contract, &mut chain, Addr::unchecked("admin"), &[]);
assert_eq!(&result.is_ok(), expect_success.get(2).unwrap());

//register 'admin' as admin without being the super user
let action = RegistryAction::RegisterAdmin {
user: "admin".to_string(),
};
let result = ExecuteMsg::UpdateRegistry {
action: action.clone(),
}
.test_exec(&contract, &mut chain, Addr::unchecked("admin"), &[]);
assert_eq!(&result.is_ok(), expect_success.get(3).unwrap());

//register admin as admin with correct permissions
let action = RegistryAction::RegisterAdmin {
user: "admin".to_string(),
};
let result = ExecuteMsg::UpdateRegistry {
action: action.clone(),
}
.test_exec(&contract, &mut chain, Addr::unchecked("super"), &[]);
assert_eq!(&result.is_ok(), expect_success.get(4).unwrap());

//set super admin to 'admin'
let result = ExecuteMsg::TransferSuper {
new_super: "admin".to_string(),
}
.test_exec(&contract, &mut chain, Addr::unchecked("super"), &[]);
assert_eq!(&result.is_ok(), expect_success.get(5).unwrap());

//self destruct
let result =
ExecuteMsg::SelfDestruct {}.test_exec(&contract, &mut chain, Addr::unchecked("admin"), &[]);
assert_eq!(&result.is_ok(), expect_success.get(6).unwrap());
}

#[rstest]
Expand Down Expand Up @@ -235,19 +255,15 @@ fn test_permissions(
}

// Check that only super admin chan do this
assert!(
ExecuteMsg::UpdateRegistryBulk {
actions: actions.clone()
}
.test_exec(&admin, &mut chain, Addr::unchecked("user"), &[])
.is_err()
);
assert!(ExecuteMsg::UpdateRegistryBulk {
actions: actions.clone()
}
.test_exec(&admin, &mut chain, Addr::unchecked("user"), &[])
.is_err());

assert!(
ExecuteMsg::UpdateRegistryBulk { actions }
.test_exec(&admin, &mut chain, Addr::unchecked("admin"), &[])
.is_ok()
);
assert!(ExecuteMsg::UpdateRegistryBulk { actions }
.test_exec(&admin, &mut chain, Addr::unchecked("admin"), &[])
.is_ok());

// Confirm that all permissions are set
for permission in permissions.iter() {
Expand Down Expand Up @@ -282,21 +298,17 @@ fn test_permissions(
})
.collect();

assert!(
ExecuteMsg::UpdateRegistryBulk {
actions: revoke_actions.clone()
}
.test_exec(&admin, &mut chain, Addr::unchecked("user"), &[])
.is_err()
);
assert!(ExecuteMsg::UpdateRegistryBulk {
actions: revoke_actions.clone()
}
.test_exec(&admin, &mut chain, Addr::unchecked("user"), &[])
.is_err());

assert!(
ExecuteMsg::UpdateRegistryBulk {
actions: revoke_actions
}
.test_exec(&admin, &mut chain, Addr::unchecked("admin"), &[])
.is_ok()
);
assert!(ExecuteMsg::UpdateRegistryBulk {
actions: revoke_actions
}
.test_exec(&admin, &mut chain, Addr::unchecked("admin"), &[])
.is_ok());

for permission in permissions.iter() {
// Check that the permissions are correctly returned
Expand Down
15 changes: 6 additions & 9 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,19 @@ rm ./$(1).wasm
endef

CONTRACTS = \
airdrop governance \
treasury treasury_manager scrt_staking rewards_emission \
oracle snip20 query_auth sky peg_stability admin\
mock_band mock_secretswap_pair mock_sienna_pair mock_adapter\
mock_stkd_derivative basic_staking snip20_migration lp_shdswap stkd_scrt\
airdrop treasury treasury_manager scrt_staking \
snip20 query_auth admin \
mock_sienna_pair mock_adapter \
mock_stkd_derivative basic_staking snip20_migration stkd_scrt \
snip20_derivative

PACKAGES = \
shade_protocol contract_harness cosmwasm_math_compat \
network_integration network_tester secretcli
PACKAGES = shade_protocol contract_harness cosmwasm_math_compat

release: setup
${build-release}
@$(MAKE) compress_all

dao: treasury treasury_manager scrt_staking rewards_emission
dao: treasury treasury_manager scrt_staking

compress_all: setup
@$(MAKE) $(addprefix compress-,$(CONTRACTS))
Expand Down
Loading

0 comments on commit 40ece0a

Please sign in to comment.