Skip to content

Commit

Permalink
Huge improvements to escrow process
Browse files Browse the repository at this point in the history
Improved names of MemberShares -> MemberPercentage
Escrow now receives a tax_info parameter to handle instead of having the tax be calculated and inserted into the shares.
Shares concept is now using percentages to make input easier
  • Loading branch information
ismellike committed Feb 15, 2024
1 parent d9acd30 commit 0241c63
Show file tree
Hide file tree
Showing 30 changed files with 397 additions and 271 deletions.
2 changes: 1 addition & 1 deletion 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-core/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ pub fn propose(
&cw_competition::msg::ExecuteBase::<Empty, Empty>::ProcessCompetition {
id: msg.id,
distribution: msg.distribution,
cw20_msg: msg.cw20_msg,
cw721_msg: msg.cw721_msg,
},
)?,
funds: vec![],
Expand Down
2 changes: 1 addition & 1 deletion contracts/arena-core/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl CompetitionModule {
pub fn to_response(&self, deps: Deps) -> StdResult<CompetitionModuleResponse<String>> {
let competition_count: Uint128 = deps.querier.query_wasm_smart(
self.addr.to_string(),
&cw_competition::msg::QueryBase::<Empty, Empty>::CompetitionCount {},
&cw_competition::msg::QueryBase::<Empty, Empty, Empty>::CompetitionCount {},
)?;

Ok(CompetitionModuleResponse {
Expand Down
15 changes: 9 additions & 6 deletions contracts/arena-core/src/tests/leagues.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use arena_league_module::{
CompetitionInstantiateExt, ExecuteExt, ExecuteMsg, InstantiateMsg, LeagueResponse,
MatchResult, MemberPoints, QueryExt, QueryMsg,
},
state::{Match, Result, RoundResponse},
state::{Match, Result, RoundResponse, TournamentExt},
};
use cosmwasm_std::{to_json_binary, Addr, Coin, Coins, Empty, Uint128, Uint64, WasmMsg};
use cosmwasm_std::{to_json_binary, Addr, Coin, Coins, Decimal, Uint128, Uint64, WasmMsg};
use cw4::Member;
use cw_balance::MemberBalanceUnchecked;
use cw_competition::msg::ModuleInfo;
Expand Down Expand Up @@ -55,7 +55,10 @@ fn setup_league_context(
msg: to_json_binary(&InstantiateMsg {
key: "Leagues".to_string(),
description: "This is a description".to_string(),
extension: Empty {},
extension: TournamentExt {
cw20_msg: None,
cw721_msg: None,
},
})
.unwrap(),
admin: None,
Expand Down Expand Up @@ -146,9 +149,9 @@ fn create_competition(
match_draw_points: Uint128::one(),
match_lose_points: Uint128::zero(),
distribution: vec![
Uint128::from(70u128),
Uint128::from(20u128),
Uint128::from(10u128),
Decimal::from_ratio(70u128, 100u128),
Decimal::from_ratio(20u128, 100u128),
Decimal::from_ratio(10u128, 100u128),
],
},
},
Expand Down
42 changes: 36 additions & 6 deletions contracts/arena-core/src/tests/wagers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ use arena_core_interface::msg::{
CompetitionModuleQuery, CompetitionModuleResponse, ProposeMessage, QueryExt,
};
use arena_wager_module::msg::{EmptyWrapper, ExecuteMsg, InstantiateMsg, QueryMsg, WagerResponse};
use cosmwasm_std::{to_json_binary, Addr, Coin, Coins, CosmosMsg, Empty, Uint128, WasmMsg};
use cosmwasm_std::{
to_json_binary, Addr, Coin, Coins, CosmosMsg, Decimal, Empty, Uint128, WasmMsg,
};
use cw4::Member;
use cw_balance::{MemberBalanceUnchecked, MemberShare};
use cw_balance::{MemberBalanceUnchecked, MemberPercentage};
use cw_competition::{
msg::ModuleInfo,
state::{CompetitionResponse, CompetitionStatus},
Expand Down Expand Up @@ -372,10 +374,12 @@ fn test_create_competition() {
msg: to_json_binary(
&cw_competition::msg::ExecuteBase::<Empty, Empty>::ProcessCompetition {
id: competition1_id,
distribution: vec![MemberShare {
distribution: vec![MemberPercentage {
addr: user1.to_string(),
shares: Uint128::one(),
percentage: Decimal::one(),
}],
cw20_msg: None,
cw721_msg: None,
},
)
.unwrap(),
Expand Down Expand Up @@ -453,6 +457,18 @@ fn test_create_competition() {
);
assert!(result.is_ok());

// Claim balances
let result = context.app.execute_contract(
user1.clone(),
competition1.escrow.clone().unwrap(),
&arena_escrow::msg::ExecuteMsg::Withdraw {
cw20_msg: None,
cw721_msg: None,
},
&[],
);
assert!(result.is_ok());

// Assert correct balances user 1 - 20_000*.85, dao - 20_000*.15
let balance = context
.app
Expand Down Expand Up @@ -580,10 +596,12 @@ fn test_create_competition_jailed() {
id: competition1_id,
title: "Title".to_string(),
description: "Description".to_string(),
distribution: vec![MemberShare {
distribution: vec![MemberPercentage {
addr: user1.to_string(),
shares: Uint128::one(),
percentage: Decimal::one(),
}],
cw20_msg: None,
cw721_msg: None,
};

let result = context.app.execute_contract(
Expand Down Expand Up @@ -696,6 +714,18 @@ fn test_create_competition_jailed() {
);
assert!(result.is_ok());

// Claim balances
let result = context.app.execute_contract(
user1.clone(),
competition1.escrow.clone().unwrap(),
&arena_escrow::msg::ExecuteMsg::Withdraw {
cw20_msg: None,
cw721_msg: None,
},
&[],
);
assert!(result.is_ok());

// Assert correct balances user 1 - 20_000*.85, dao - 20_000*.15
let balance = context
.app
Expand Down
4 changes: 3 additions & 1 deletion contracts/arena-escrow/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
execute,
msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg},
query,
state::{self, DUE, INITIAL_DUE, IS_LOCKED},
state::{self, DUE, HAS_DISTRIBUTED, INITIAL_DUE, IS_LOCKED},
ContractError,
};
use cosmwasm_std::{
Expand Down Expand Up @@ -47,6 +47,7 @@ pub fn instantiate_contract(

cw_ownable::initialize_owner(deps.storage, deps.api, Some(info.sender.as_str()))?;
IS_LOCKED.save(deps.storage, &false)?;
HAS_DISTRIBUTED.save(deps.storage, &false)?;
for member_balance in due {
let member_balance = member_balance.into_checked(deps.as_ref())?;

Expand Down Expand Up @@ -91,6 +92,7 @@ pub fn execute(
deps,
info,
competition_escrow_distribute_msg.distribution,
competition_escrow_distribute_msg.tax_info,
competition_escrow_distribute_msg.remainder_addr,
),
ExecuteMsg::Lock { value } => execute::lock(deps, info, value),
Expand Down
8 changes: 7 additions & 1 deletion contracts/arena-escrow/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cosmwasm_std::{CheckedFromRatioError, OverflowError, StdError};
use cosmwasm_std::{CheckedFromRatioError, CheckedMultiplyFractionError, OverflowError, StdError};
use cw_balance::BalanceError;
use cw_ownable::OwnershipError;
use thiserror::Error;
Expand All @@ -20,6 +20,9 @@ pub enum ContractError {
#[error("{0}")]
BalanceError(#[from] BalanceError),

#[error("{0}")]
CheckedMultiplyFractionError(#[from] CheckedMultiplyFractionError),

#[error("Locked")]
Locked {},

Expand All @@ -31,4 +34,7 @@ pub enum ContractError {

#[error("InvalidDue")]
InvalidDue { msg: String },

#[error("EmptyBalance")]
EmptyBalance {},
}
Loading

0 comments on commit 0241c63

Please sign in to comment.