Skip to content

Commit

Permalink
Optional team size requirement for enrollments
Browse files Browse the repository at this point in the history
  • Loading branch information
ismellike committed Dec 26, 2024
1 parent d38ce70 commit 67008b5
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions contracts/arena-competition-enrollment/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ cw-ownable = { workspace = true }
cw-orch = { workspace = true }
cw-balance = { workspace = true }
itertools = { workspace = true }
dao-voting-cw4 = { workspace = true }
cw4 = { workspace = true }
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@
"type": "null"
}
]
},
"require_team_size": {
"type": [
"integer",
"null"
],
"format": "uint32",
"minimum": 0.0
}
},
"additionalProperties": false
Expand Down Expand Up @@ -1163,6 +1171,14 @@
"type": "null"
}
]
},
"require_team_size": {
"type": [
"integer",
"null"
],
"format": "uint32",
"minimum": 0.0
}
},
"additionalProperties": false
Expand Down Expand Up @@ -1349,6 +1365,14 @@
"type": "null"
}
]
},
"require_team_size": {
"type": [
"integer",
"null"
],
"format": "uint32",
"minimum": 0.0
}
},
"additionalProperties": false,
Expand Down Expand Up @@ -1950,6 +1974,14 @@
"type": "null"
}
]
},
"require_team_size": {
"type": [
"integer",
"null"
],
"format": "uint32",
"minimum": 0.0
}
},
"additionalProperties": false
Expand Down
2 changes: 2 additions & 0 deletions contracts/arena-competition-enrollment/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ pub fn execute(
competition_info,
competition_type,
group_contract_info,
require_team_size,
} => execute::create_enrollment(
deps,
env,
Expand All @@ -71,6 +72,7 @@ pub fn execute(
competition_info,
competition_type,
group_contract_info,
require_team_size,
),
ExecuteMsg::TriggerExpiration { id, escrow_id } => {
execute::trigger_expiration(deps, env, info, id, escrow_id)
Expand Down
3 changes: 3 additions & 0 deletions contracts/arena-competition-enrollment/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,7 @@ pub enum ContractError {

#[error("Enrollment is at max members already")]
EnrollmentMaxMembers {},

#[error("Only teams of size {required_team_size} can enroll")]
TeamSizeMismatch { required_team_size: u32 },
}
28 changes: 28 additions & 0 deletions contracts/arena-competition-enrollment/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ use crate::{
};

pub const TRIGGER_COMPETITION_REPLY_ID: u64 = 1;
/// Team size is limited to cw4-group's max size limit
const TEAM_SIZE_LIMIT: u32 = 30;

#[allow(clippy::too_many_arguments)]
pub fn create_enrollment(
Expand All @@ -40,6 +42,7 @@ pub fn create_enrollment(
competition_info: CompetitionInfoMsg,
competition_type: CompetitionType,
group_contract_info: ModuleInstantiateInfo,
require_team_size: Option<u32>,
) -> Result<Response, ContractError> {
ensure!(
!expiration.is_expired(&env.block),
Expand Down Expand Up @@ -186,6 +189,7 @@ pub fn create_enrollment(
category_id,
competition_module,
group_contract,
required_team_size: require_team_size,
},
)?;

Expand Down Expand Up @@ -424,6 +428,30 @@ pub fn enroll(
ContractError::EnrollmentMaxMembers {}
);

// Ensure team size requirement is handled
if let Some(required_team_size) = entry.required_team_size {
let dao_voting_module: Addr = deps.querier.query_wasm_smart(
info.sender.to_string(),
&dao_interface::msg::QueryMsg::VotingModule {},
)?;
let group_contract: Addr = deps.querier.query_wasm_smart(
dao_voting_module,
&dao_voting_cw4::msg::QueryMsg::GroupContract {},
)?;
let member_list_response: cw4::MemberListResponse = deps.querier.query_wasm_smart(
group_contract,
&cw4::Cw4QueryMsg::ListMembers {
start_after: None,
limit: Some(TEAM_SIZE_LIMIT),
},
)?;

ensure!(
member_list_response.members.len() as u32 == required_team_size,
ContractError::TeamSizeMismatch { required_team_size }
);
}

let msg = CosmosMsg::Wasm(WasmMsg::Execute {
contract_addr: entry.group_contract.to_string(),
msg: to_json_binary(&group::ExecuteMsg::UpdateMembers {
Expand Down
1 change: 1 addition & 0 deletions contracts/arena-competition-enrollment/src/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ pub fn from_v2_to_v2_1(deps: DepsMut, env: &Env, group_id: u64) -> StdResult<Vec
category_id: enrollment.category_id,
competition_module: enrollment.competition_module,
group_contract,
required_team_size: None,
};

enrollment_entries().replace(
Expand Down
1 change: 1 addition & 0 deletions contracts/arena-competition-enrollment/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub enum ExecuteMsg {
competition_info: CompetitionInfoMsg,
competition_type: CompetitionType,
group_contract_info: ModuleInstantiateInfo,
require_team_size: Option<u32>,
},
TriggerExpiration {
id: Uint128,
Expand Down
3 changes: 3 additions & 0 deletions contracts/arena-competition-enrollment/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub struct EnrollmentEntry {
pub category_id: Option<Uint128>,
pub competition_module: Addr,
pub group_contract: Addr,
pub required_team_size: Option<u32>,
}

#[cw_serde]
Expand Down Expand Up @@ -52,6 +53,7 @@ pub struct EnrollmentEntryResponse {
pub is_expired: bool,
pub competition_module: Addr,
pub group_contract: Addr,
pub require_team_size: Option<u32>,
}

#[cw_serde]
Expand Down Expand Up @@ -96,6 +98,7 @@ impl EnrollmentEntry {
is_expired,
competition_module: self.competition_module,
group_contract: self.group_contract,
require_team_size: self.required_team_size,
})
}
}
Expand Down
10 changes: 10 additions & 0 deletions scripts/src/tests/arena_competition_enrollment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ fn test_competition_enrollment() -> anyhow::Result<()> {
funds: vec![],
label: "Arena Group".to_string(),
},
require_team_size: None,
};

let res = arena
Expand Down Expand Up @@ -195,6 +196,7 @@ fn test_invalid_enrollment() -> anyhow::Result<()> {
funds: vec![],
label: "Arena Group".to_string(),
},
require_team_size: None,
};

let result = arena
Expand Down Expand Up @@ -263,6 +265,7 @@ fn test_enrollment_capacity() -> anyhow::Result<()> {
funds: vec![],
label: "Arena Group".to_string(),
},
require_team_size: None,
};

arena
Expand Down Expand Up @@ -345,6 +348,7 @@ fn test_successful_tournament_creation() -> anyhow::Result<()> {
funds: vec![],
label: "Arena Group".to_string(),
},
require_team_size: None,
};

arena
Expand Down Expand Up @@ -428,6 +432,7 @@ fn test_successful_wager_creation() -> anyhow::Result<()> {
funds: vec![],
label: "Arena Group".to_string(),
},
require_team_size: None,
};

arena
Expand Down Expand Up @@ -524,6 +529,7 @@ fn test_successful_league_creation() -> anyhow::Result<()> {
funds: vec![],
label: "Arena Group".to_string(),
},
require_team_size: None,
};

arena
Expand Down Expand Up @@ -603,6 +609,7 @@ fn test_trigger_expiration_without_escrow() -> anyhow::Result<()> {
funds: vec![],
label: "Arena Group".to_string(),
},
require_team_size: None,
};

arena
Expand Down Expand Up @@ -692,6 +699,7 @@ fn test_trigger_expiration_before_min_members() -> anyhow::Result<()> {
funds: vec![],
label: "Arena Group".to_string(),
},
require_team_size: None,
};

arena
Expand Down Expand Up @@ -775,6 +783,7 @@ fn test_unregistered_competition_enrollment() -> anyhow::Result<()> {
funds: vec![],
label: "Arena Group".to_string(),
},
require_team_size: None,
};

arena
Expand Down Expand Up @@ -880,6 +889,7 @@ fn test_huge_tournament() -> anyhow::Result<()> {
funds: vec![],
label: "Arena Group".to_string(),
},
require_team_size: None,
};

arena
Expand Down

0 comments on commit 67008b5

Please sign in to comment.