diff --git a/contracts/external/cw-abc/schema/cw-abc.json b/contracts/external/cw-abc/schema/cw-abc.json index 79d409cb8..88e427d27 100644 --- a/contracts/external/cw-abc/schema/cw-abc.json +++ b/contracts/external/cw-abc/schema/cw-abc.json @@ -520,7 +520,7 @@ "additionalProperties": false }, { - "description": "Donate will donate tokens to a pool. You must send only reserve tokens.", + "description": "Donate will donate tokens to the funding pool. You must send only reserve tokens.", "type": "object", "required": [ "donate" @@ -528,19 +528,6 @@ "properties": { "donate": { "type": "object", - "properties": { - "pool": { - "description": "The pool to donate tokens into (defaults to funding pool)", - "anyOf": [ - { - "$ref": "#/definitions/DonationPool" - }, - { - "type": "null" - } - ] - } - }, "additionalProperties": false } }, @@ -878,36 +865,6 @@ "description": "A fixed-point decimal value with 18 fractional digits, i.e. Decimal(1_000_000_000_000_000_000) == 1.0\n\nThe greatest possible value that can be represented is 340282366920938463463.374607431768211455 (which is (2^128 - 1) / 10^18)", "type": "string" }, - "DonationPool": { - "oneOf": [ - { - "type": "object", - "required": [ - "funding" - ], - "properties": { - "funding": { - "type": "object", - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "reserve" - ], - "properties": { - "reserve": { - "type": "object", - "additionalProperties": false - } - }, - "additionalProperties": false - } - ] - }, "Expiration": { "description": "Expiration represents a point in time when some event happens. It can compare with a BlockInfo and will return is_expired() == true once the condition is hit (and for every block in the future)", "oneOf": [ diff --git a/contracts/external/cw-abc/src/commands.rs b/contracts/external/cw-abc/src/commands.rs index ca0d0030b..bbed7449f 100644 --- a/contracts/external/cw-abc/src/commands.rs +++ b/contracts/external/cw-abc/src/commands.rs @@ -7,7 +7,7 @@ use cw_utils::must_pay; use std::ops::Deref; use crate::abc::{CommonsPhase, CurveType}; -use crate::msg::{DonationPool, HatcherAllowlistEntry, UpdatePhaseConfigMsg}; +use crate::msg::{HatcherAllowlistEntry, UpdatePhaseConfigMsg}; use crate::state::{ hatcher_allowlist, HatcherAllowlistConfigType, CURVE_STATE, CURVE_TYPE, DONATIONS, FUNDING_POOL_FORWARDING, HATCHERS, IS_PAUSED, MAX_SUPPLY, PHASE, PHASE_CONFIG, SUPPLY_DENOM, @@ -273,36 +273,24 @@ pub fn close(deps: DepsMut, info: MessageInfo) -> Result Result { +pub fn donate(deps: DepsMut, _env: Env, info: MessageInfo) -> Result { let mut curve_state = CURVE_STATE.load(deps.storage)?; let payment = must_pay(&info, &curve_state.reserve_denom)?; - let mut msgs = vec![]; - match pool { - DonationPool::Funding {} => { - if let Some(funding_pool_forwarding) = FUNDING_POOL_FORWARDING.may_load(deps.storage)? { - msgs.push(CosmosMsg::Bank(BankMsg::Send { - to_address: funding_pool_forwarding.to_string(), - amount: info.funds, - })); - } else { - curve_state.funding += payment; - - CURVE_STATE.save(deps.storage, &curve_state)?; - } - } - DonationPool::Reserve {} => { - curve_state.reserve += payment; + let msgs = + if let Some(funding_pool_forwarding) = FUNDING_POOL_FORWARDING.may_load(deps.storage)? { + vec![CosmosMsg::Bank(BankMsg::Send { + to_address: funding_pool_forwarding.to_string(), + amount: info.funds, + })] + } else { + curve_state.funding += payment; CURVE_STATE.save(deps.storage, &curve_state)?; - } - }; + + vec![] + }; // No minting of tokens is necessary, the supply stays the same let total_donation = @@ -318,7 +306,6 @@ pub fn donate( .add_attribute("action", "donate") .add_attribute("donor", info.sender) .add_attribute("amount", payment) - .add_attribute("pool", pool.to_string()) .add_attribute("total_donation", total_donation) .add_messages(msgs)) } @@ -621,7 +608,6 @@ mod tests { deps, mock_env(), mock_info(TEST_DONOR, &[coin(donation_amount, TEST_RESERVE_DENOM)]), - DonationPool::Funding {}, ) } @@ -657,7 +643,6 @@ mod tests { deps.as_mut(), mock_env(), mock_info(TEST_DONOR, &[coin(1, "fake")]), - DonationPool::Funding {}, ); assert_that!(res) .is_err() @@ -669,64 +654,7 @@ mod tests { } #[test] - fn test_donation() -> Result<(), ContractError> { - let mut deps = mock_dependencies(); - // this matches `linear_curve` test case from curves.rs - let curve_type = CurveType::SquareRoot { - slope: Uint128::new(1), - scale: 1, - }; - let init_msg = default_instantiate_msg(2, 8, curve_type); - mock_init(deps.as_mut(), init_msg)?; - - let donation_amount = 5; - let _res = exec_donate(deps.as_mut(), donation_amount)?; - - // check that the curve's funding has been increased while supply and reserve have not - let curve_state = CURVE_STATE.load(&deps.storage)?; - assert_that!(curve_state.funding).is_equal_to(Uint128::new(donation_amount)); - - // check that the donor is in the donations map - let donation = DONATIONS.load(&deps.storage, &Addr::unchecked(TEST_DONOR))?; - assert_that!(donation).is_equal_to(Uint128::new(donation_amount)); - - // check that the owner can withdraw - withdraw( - deps.as_mut(), - mock_env(), - mock_info(TEST_CREATOR, &[]), - None, - )?; - - // check that a random can't withdraw - let res = withdraw(deps.as_mut(), mock_env(), mock_info("random", &[]), None); - assert_that!(res) - .is_err() - .is_equal_to(ContractError::Ownership( - cw_ownable::OwnershipError::NotOwner, - )); - - // execute donation to the reserve pool - donate( - deps.as_mut(), - mock_env(), - mock_info(TEST_DONOR, &[coin(donation_amount, TEST_RESERVE_DENOM)]), - DonationPool::Reserve {}, - )?; - - // check that the curve's reserve has been increased while supply and reserve have not - let curve_state = CURVE_STATE.load(&deps.storage)?; - assert_that!(curve_state.reserve).is_equal_to(Uint128::new(donation_amount)); - - // check that the donor is in the donations map - let donation = DONATIONS.load(&deps.storage, &Addr::unchecked(TEST_DONOR))?; - assert_that!(donation).is_equal_to(Uint128::new(donation_amount * 2)); - - Ok(()) - } - - #[test] - fn should_send_to_funding_pool_forwarding() -> Result<(), ContractError> { + fn should_donation_with_forwarding() -> Result<(), ContractError> { let mut deps = mock_dependencies(); // this matches `linear_curve` test case from curves.rs let curve_type = CurveType::SquareRoot { diff --git a/contracts/external/cw-abc/src/contract.rs b/contracts/external/cw-abc/src/contract.rs index 2916ced81..ffd443a8d 100644 --- a/contracts/external/cw-abc/src/contract.rs +++ b/contracts/external/cw-abc/src/contract.rs @@ -135,7 +135,7 @@ pub fn execute( ExecuteMsg::Buy {} => commands::buy(deps, env, info), ExecuteMsg::Sell {} => commands::sell(deps, env, info), ExecuteMsg::Close {} => commands::close(deps, info), - ExecuteMsg::Donate { pool } => commands::donate(deps, env, info, pool.unwrap_or_default()), + ExecuteMsg::Donate {} => commands::donate(deps, env, info), ExecuteMsg::Withdraw { amount } => commands::withdraw(deps, env, info, amount), ExecuteMsg::UpdateFundingPoolForwarding { address } => { commands::update_funding_pool_forwarding(deps, env, info, address) diff --git a/contracts/external/cw-abc/src/msg.rs b/contracts/external/cw-abc/src/msg.rs index 2116153d0..d0a0baa56 100644 --- a/contracts/external/cw-abc/src/msg.rs +++ b/contracts/external/cw-abc/src/msg.rs @@ -1,7 +1,6 @@ use cosmwasm_schema::{cw_serde, QueryResponses}; use cosmwasm_std::{Addr, Decimal as StdDecimal, Uint128}; use cw_address_like::AddressLike; -use std::fmt::{self, Display}; use crate::{ abc::{CommonsPhase, CommonsPhaseConfig, CurveType, MinMax, ReserveToken, SupplyToken}, @@ -65,12 +64,9 @@ pub enum ExecuteMsg { /// Sell burns supply tokens in return for the reserve token. /// You must send only supply tokens. Sell {}, - /// Donate will donate tokens to a pool. + /// Donate will donate tokens to the funding pool. /// You must send only reserve tokens. - Donate { - /// The pool to donate tokens into (defaults to funding pool) - pool: Option, - }, + Donate {}, /// Withdraw will withdraw tokens from the funding pool. Withdraw { /// The amount to withdraw (defaults to full amount). @@ -174,27 +170,6 @@ pub struct HatcherAllowlistEntry { pub config: HatcherAllowlistConfig, } -#[cw_serde] -pub enum DonationPool { - Funding {}, - Reserve {}, -} - -impl Default for DonationPool { - fn default() -> Self { - DonationPool::Funding {} - } -} - -impl Display for DonationPool { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - DonationPool::Funding {} => write!(f, "Funding"), - DonationPool::Reserve {} => write!(f, "Reserve"), - } - } -} - #[cw_serde] pub struct CurveInfoResponse { /// How many reserve tokens have been received