Skip to content

Commit

Permalink
Add test for dao hatchers + update schemas
Browse files Browse the repository at this point in the history
Also removes unused deps from cw-abc which now live in cw-curves
  • Loading branch information
ismellike committed Apr 28, 2024
1 parent 76f48e7 commit cb986e0
Show file tree
Hide file tree
Showing 11 changed files with 289 additions and 57 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion contracts/dao-dao-core/schema/dao-dao-core.json
Original file line number Diff line number Diff line change
Expand Up @@ -1723,7 +1723,7 @@
"additionalProperties": false
},
{
"description": "Lists all of the items associted with the contract. For example, given the items `{ \"group\": \"foo\", \"subdao\": \"bar\"}` this query would return `[(\"group\", \"foo\"), (\"subdao\", \"bar\")]`.",
"description": "Lists all of the items associated with the contract. For example, given the items `{ \"group\": \"foo\", \"subdao\": \"bar\"}` this query would return `[(\"group\", \"foo\"), (\"subdao\", \"bar\")]`.",
"type": "object",
"required": [
"list_items"
Expand Down
8 changes: 4 additions & 4 deletions contracts/external/cw-abc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ cw-ownable = { workspace = true }
cw-paginate-storage = { workspace = true }
cw-tokenfactory-issuer = { workspace = true, features = ["library"] }
dao-interface = { workspace = true }
rust_decimal = { workspace = true }
integer-sqrt = { workspace = true }
integer-cbrt = { workspace = true }
getrandom = { workspace = true, features = ["js"] }
thiserror = { workspace = true }
cw-curves = { workspace = true }
Expand All @@ -53,4 +50,7 @@ osmosis-std = { workspace = true }
osmosis-test-tube = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
cw-tokenfactory-issuer = { workspace = true }
cw-tokenfactory-issuer = { workspace = true }
dao-voting-token-staked = { workspace = true }
dao-proposal-single = { workspace = true }
dao-voting = { workspace = true }
26 changes: 13 additions & 13 deletions contracts/external/cw-abc/src/abc.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use cosmwasm_schema::cw_serde;
use cosmwasm_std::{ensure, Decimal as StdDecimal, Uint128};
use cosmwasm_std::{ensure, Decimal, Uint128};
use cw_curves::{
curves::{Constant, Linear, SquareRoot},
utils::decimal,
Expand Down Expand Up @@ -45,9 +45,9 @@ pub struct HatchConfig {
/// The initial raise range (min, max) in the reserve token
pub initial_raise: MinMax,
/// The initial allocation (θ), percentage of the initial raise allocated to the Funding Pool
pub entry_fee: StdDecimal,
pub entry_fee: Decimal,
/// Exit tax for the hatch phase
pub exit_fee: StdDecimal,
pub exit_fee: Decimal,
}

impl HatchConfig {
Expand All @@ -69,14 +69,14 @@ impl HatchConfig {
);

ensure!(
self.entry_fee <= StdDecimal::percent(100u64),
self.entry_fee <= Decimal::percent(100u64),
ContractError::HatchPhaseConfigError(
"Initial allocation percentage must be between 0 and 100.".to_string()
)
);

ensure!(
self.exit_fee <= StdDecimal::percent(100u64),
self.exit_fee <= Decimal::percent(100u64),
ContractError::HatchPhaseConfigError(
"Exit taxation percentage must be less than or equal to 100.".to_string()
)
Expand All @@ -90,23 +90,23 @@ impl HatchConfig {
pub struct OpenConfig {
/// Percentage of capital put into the Reserve Pool during the Open phase
/// when buying from the curve.
pub entry_fee: StdDecimal,
pub entry_fee: Decimal,
/// Exit taxation ratio
pub exit_fee: StdDecimal,
pub exit_fee: Decimal,
}

impl OpenConfig {
/// Validate the open config
pub fn validate(&self) -> Result<(), ContractError> {
ensure!(
self.entry_fee <= StdDecimal::percent(100u64),
self.entry_fee <= Decimal::percent(100u64),
ContractError::OpenPhaseConfigError(
"Reserve percentage must be between 0 and 100.".to_string()
)
);

ensure!(
self.exit_fee <= StdDecimal::percent(100u64),
self.exit_fee <= Decimal::percent(100u64),
ContractError::OpenPhaseConfigError(
"Exit taxation percentage must be between 0 and 100.".to_string()
)
Expand Down Expand Up @@ -247,12 +247,12 @@ mod unit_tests {
min: Uint128::one(),
max: Uint128::from(1000000u128),
},
entry_fee: StdDecimal::percent(10u64),
exit_fee: StdDecimal::percent(10u64),
entry_fee: Decimal::percent(10u64),
exit_fee: Decimal::percent(10u64),
},
open: OpenConfig {
entry_fee: StdDecimal::percent(10u64),
exit_fee: StdDecimal::percent(10u64),
entry_fee: Decimal::percent(10u64),
exit_fee: Decimal::percent(10u64),
},
closed: ClosedConfig {},
};
Expand Down
15 changes: 5 additions & 10 deletions contracts/external/cw-abc/src/commands.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use cosmwasm_std::{
ensure, to_json_binary, Addr, BankMsg, Coin, CosmosMsg, Decimal as StdDecimal, DepsMut, Env,
MessageInfo, QuerierWrapper, Response, StdResult, Storage, Uint128, WasmMsg,
ensure, to_json_binary, Addr, BankMsg, Coin, CosmosMsg, Decimal, DepsMut, Env, MessageInfo,
QuerierWrapper, Response, StdResult, Storage, Uint128, WasmMsg,
};
use cw_tokenfactory_issuer::msg::ExecuteMsg as IssuerExecuteMsg;
use cw_utils::must_pay;
Expand Down Expand Up @@ -212,7 +212,7 @@ pub fn sell(deps: DepsMut, _env: Env, info: MessageInfo) -> Result<Response, Con
/// Return the reserved and funded amounts based on the payment and the allocation ratio
fn calculate_reserved_and_funded(
payment: Uint128,
allocation_ratio: StdDecimal,
allocation_ratio: Decimal,
) -> (Uint128, Uint128) {
let funded = payment * allocation_ratio;
let reserved = payment.checked_sub(funded).unwrap(); // Since allocation_ratio is < 1, this subtraction is safe
Expand Down Expand Up @@ -253,10 +253,7 @@ fn calculate_exit_fee(
};

// Ensure the exit fee is not greater than 100%
ensure!(
exit_fee <= StdDecimal::one(),
ContractError::InvalidExitFee {}
);
ensure!(exit_fee <= Decimal::one(), ContractError::InvalidExitFee {});

// This won't ever overflow because it's checked
let taxed_amount = sell_amount * exit_fee;
Expand Down Expand Up @@ -465,9 +462,7 @@ pub fn update_hatch_allowlist(
for allow in to_add {
let addr = deps.api.addr_validate(allow.addr.as_str())?;

if !list.has(deps.storage, &addr) {
list.save(deps.storage, &addr, &allow.config)?;
}
list.save(deps.storage, &addr, &allow.config)?;
}

// Remove addresses from the allowlist
Expand Down
12 changes: 6 additions & 6 deletions contracts/external/cw-abc/src/msg.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use cosmwasm_schema::{cw_serde, QueryResponses};
use cosmwasm_std::{Addr, Decimal as StdDecimal, Uint128};
use cosmwasm_std::{Addr, Decimal, Uint128};
use cw_address_like::AddressLike;

use crate::{
Expand Down Expand Up @@ -42,13 +42,13 @@ pub enum UpdatePhaseConfigMsg {
contribution_limits: Option<MinMax>,
// TODO what is the minimum used for?
initial_raise: Option<MinMax>,
entry_fee: Option<StdDecimal>,
exit_fee: Option<StdDecimal>,
entry_fee: Option<Decimal>,
exit_fee: Option<Decimal>,
},
/// Update the open phase configuration.
Open {
exit_fee: Option<StdDecimal>,
entry_fee: Option<StdDecimal>,
exit_fee: Option<Decimal>,
entry_fee: Option<Decimal>,
},
/// Update the closed phase configuration.
/// TODO Set the curve type to be used on close?
Expand Down Expand Up @@ -179,7 +179,7 @@ pub struct CurveInfoResponse {
/// The amount of tokens in the funding pool
pub funding: Uint128,
/// Current spot price of the token
pub spot_price: StdDecimal,
pub spot_price: Decimal,
/// Current reserve denom
pub reserve_denom: String,
}
Expand Down
49 changes: 49 additions & 0 deletions contracts/external/cw-abc/src/test_tube/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,3 +541,52 @@ fn test_update_curve() {
})
);
}

#[test]
fn test_dao_hatcher() {
let app = OsmosisTestApp::new();
let builder = TestEnvBuilder::new();
let env = builder.default_setup(&app);
let TestEnv {
ref abc,
ref accounts,
..
} = env;

// Setup a dao with the 1st half of accounts
let dao = env.setup_dao();
app.increase_time(1u64);

// Update hatcher allowlist for DAO membership
let result = abc.execute(
&ExecuteMsg::UpdateHatchAllowlist {
to_add: vec![HatcherAllowlistEntry::<String> {
addr: dao.contract_addr.to_string(),
config: HatcherAllowlistConfig {
config_type: HatcherAllowlistConfigType::DAO {},
},
}],
to_remove: vec![],
},
&[],
&accounts[0],
);
assert!(result.is_ok());

// Only DAO members (1st half of accounts) can hatch
let result = abc.execute(&ExecuteMsg::Buy {}, &coins(1000, RESERVE), &accounts[0]);
assert!(result.is_ok());

// Check not member
let result = abc.execute(
&ExecuteMsg::Buy {},
&coins(1000, RESERVE),
&accounts[accounts.len() - 1],
);
assert_eq!(
result.unwrap_err(),
abc.execute_error(ContractError::SenderNotAllowlisted {
sender: accounts[accounts.len() - 1].address().to_string()
})
);
}
Loading

0 comments on commit cb986e0

Please sign in to comment.