Skip to content

Commit

Permalink
Limit rating adjustments to dao members
Browse files Browse the repository at this point in the history
1st line of defense for gaming the system - will need DAO punishments for effectiveness
Can think of other options as well
  • Loading branch information
ismellike committed Jul 8, 2024
1 parent 348d903 commit 8cf90d7
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 21 deletions.
16 changes: 11 additions & 5 deletions contracts/arena-league-module/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,17 @@ pub fn process_matches(
// Trigger rating adjustments
let mut sub_msgs = vec![];
if let Some(category_id) = league.category_id {
sub_msgs.push(CompetitionModule::default().trigger_rating_adjustment(
deps.storage,
category_id,
member_results,
)?);
if CompetitionModule::default().query_is_dao_member(
deps.as_ref(),
&league.host,
league.start_height,
) {
sub_msgs.push(CompetitionModule::default().trigger_rating_adjustment(
deps.storage,
category_id,
member_results,
)?);
}
}

// Check if the processed matches have changed and update the league data accordingly.
Expand Down
16 changes: 11 additions & 5 deletions contracts/arena-tournament-module/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,11 +566,17 @@ pub fn process_matches(
// Trigger rating adjustments
let mut sub_msgs = vec![];
if let Some(category_id) = tournament.category_id {
sub_msgs.push(CompetitionModule::default().trigger_rating_adjustment(
deps.storage,
category_id,
member_results,
)?);
if CompetitionModule::default().query_is_dao_member(
deps.as_ref(),
&tournament.host,
tournament.start_height,
) {
sub_msgs.push(CompetitionModule::default().trigger_rating_adjustment(
deps.storage,
category_id,
member_results,
)?);
}
}

// Apply updates to the next matches
Expand Down
22 changes: 13 additions & 9 deletions contracts/arena-wager-module/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use arena_interface::ratings::MemberResult;
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{
Binary, Decimal, Deps, DepsMut, Empty, Env, MessageInfo, Reply, Response, StdResult, Storage,
SubMsg,
Binary, Decimal, Deps, DepsMut, Empty, Env, MessageInfo, Reply, Response, StdResult, SubMsg,
};
use cw2::{ensure_from_older_version, set_contract_version};
use cw_competition_base::{contract::CompetitionModuleContract, error::CompetitionError};
Expand Down Expand Up @@ -53,16 +52,21 @@ pub fn execute(
}
}

fn post_processing(
storage: &mut dyn Storage,
competition: &Wager,
) -> Result<Option<SubMsg>, CompetitionError> {
fn post_processing(deps: DepsMut, competition: &Wager) -> Result<Option<SubMsg>, CompetitionError> {
if !CompetitionModule::default().query_is_dao_member(
deps.as_ref(),
&competition.host,
competition.start_height,
) {
return Ok(None);
}

if let Some(category_id) = competition.category_id {
if let Some(registered_members) = &competition.extension.registered_members {
// This will be in state
let result = CompetitionModule::default()
.competition_result
.load(storage, competition.id.u128())?;
.load(deps.storage, competition.id.u128())?;

return Ok(match result {
Some(result) => {
Expand Down Expand Up @@ -96,7 +100,7 @@ fn post_processing(
};

Some(CompetitionModule::default().trigger_rating_adjustment(
storage,
deps.storage,
category_id,
vec![(member_result1, member_result2)],
)?)
Expand All @@ -106,7 +110,7 @@ fn post_processing(
}
// This is a Draw
None => Some(CompetitionModule::default().trigger_rating_adjustment(
storage,
deps.storage,
category_id,
vec![(
MemberResult {
Expand Down
26 changes: 24 additions & 2 deletions packages/cw-competition-base/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ impl<
distribution: Option<Distribution<String>>,
post_processing: Option<
fn(
storage: &mut dyn Storage,
deps: DepsMut,
&Competition<CompetitionExt>,
) -> Result<Option<SubMsg>, CompetitionError>,
>,
Expand All @@ -867,7 +867,7 @@ impl<

// Post-processing
if let Some(post_processing) = post_processing {
if let Some(sub_msg) = post_processing(deps.storage, &competition)? {
if let Some(sub_msg) = post_processing(deps.branch(), &competition)? {
response = response.add_submessage(sub_msg);
}
}
Expand Down Expand Up @@ -1073,6 +1073,28 @@ impl<
}
}

pub fn query_is_dao_member(&self, deps: Deps, addr: &Addr, height: u64) -> bool {
let result = self.query_dao(deps);

if let Ok(dao) = result {
let result = deps
.querier
.query_wasm_smart::<dao_interface::voting::VotingPowerAtHeightResponse>(
&dao,
&dao_interface::msg::QueryMsg::VotingPowerAtHeight {
address: addr.to_string(),
height: Some(height),
},
);

if let Ok(voting_power) = result {
return !voting_power.power.is_zero();
}
}

false
}

pub fn query_result(
&self,
deps: Deps,
Expand Down

0 comments on commit 8cf90d7

Please sign in to comment.