diff --git a/Cargo.lock b/Cargo.lock index 0fd7a8ba9..578b1294c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -749,7 +749,6 @@ dependencies = [ "serde_json", "speculoos", "thiserror", - "token-bindings", ] [[package]] diff --git a/contracts/external/cw-abc/Cargo.toml b/contracts/external/cw-abc/Cargo.toml index 1676c2fa5..43abe028c 100644 --- a/contracts/external/cw-abc/Cargo.toml +++ b/contracts/external/cw-abc/Cargo.toml @@ -41,7 +41,6 @@ integer-sqrt = { workspace = true } integer-cbrt = { workspace = true } getrandom = { workspace = true, features = ["js"] } thiserror = { workspace = true } -token-bindings = { workspace = true } [dev-dependencies] speculoos = { workspace = true } diff --git a/contracts/external/cw-abc/src/commands.rs b/contracts/external/cw-abc/src/commands.rs index c10dd881e..9a3ddf8ca 100644 --- a/contracts/external/cw-abc/src/commands.rs +++ b/contracts/external/cw-abc/src/commands.rs @@ -6,10 +6,8 @@ use cw_tokenfactory_issuer::msg::ExecuteMsg as IssuerExecuteMsg; use cw_utils::must_pay; use std::collections::HashSet; use std::ops::Deref; -use token_bindings::{TokenFactoryMsg, TokenFactoryQuery}; use crate::abc::{CommonsPhase, CurveType}; -use crate::contract::CwAbcResult; use crate::msg::UpdatePhaseConfigMsg; use crate::state::{ CURVE_STATE, CURVE_TYPE, DONATIONS, FEES_RECIPIENT, HATCHERS, HATCHER_ALLOWLIST, MAX_SUPPLY, @@ -17,7 +15,7 @@ use crate::state::{ }; use crate::ContractError; -pub fn execute_buy(deps: DepsMut, _env: Env, info: MessageInfo) -> CwAbcResult { +pub fn execute_buy(deps: DepsMut, _env: Env, info: MessageInfo) -> Result { let curve_type = CURVE_TYPE.load(deps.storage)?; let curve_fn = curve_type.to_curve_fn(); @@ -93,7 +91,7 @@ pub fn execute_buy(deps: DepsMut, _env: Env, info: MessageInf // Mint tokens for sender by calling mint on the cw-tokenfactory-issuer contract let issuer_addr = TOKEN_ISSUER_CONTRACT.load(deps.storage)?; - let mut msgs: Vec> = vec![CosmosMsg::Wasm(WasmMsg::Execute { + let mut msgs: Vec = vec![CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: issuer_addr.to_string(), msg: to_json_binary(&IssuerExecuteMsg::Mint { to_address: info.sender.to_string(), @@ -151,7 +149,11 @@ fn update_hatcher_contributions( } /// Sell tokens on the bonding curve -pub fn execute_sell(deps: DepsMut, _env: Env, info: MessageInfo) -> CwAbcResult { +pub fn execute_sell( + deps: DepsMut, + _env: Env, + info: MessageInfo, +) -> Result { let curve_type = CURVE_TYPE.load(deps.storage)?; let curve_fn = curve_type.to_curve_fn(); @@ -161,9 +163,9 @@ pub fn execute_sell(deps: DepsMut, _env: Env, info: MessageIn let issuer_addr = TOKEN_ISSUER_CONTRACT.load(deps.storage)?; // Burn the sent supply tokens - let burn_msgs: Vec> = vec![ + let burn_msgs: Vec = vec![ // Send tokens to the issuer contract to be burned - CosmosMsg::::Bank(BankMsg::Send { + CosmosMsg::Bank(BankMsg::Send { to_address: issuer_addr.to_string().clone(), amount: vec![Coin { amount: burn_amount, @@ -171,7 +173,7 @@ pub fn execute_sell(deps: DepsMut, _env: Env, info: MessageIn }], }), // Execute burn on the cw-tokenfactory-issuer contract - CosmosMsg::::Wasm(WasmMsg::Execute { + CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: issuer_addr.to_string(), msg: to_json_binary(&IssuerExecuteMsg::Burn { from_address: issuer_addr.to_string(), @@ -214,14 +216,13 @@ pub fn execute_sell(deps: DepsMut, _env: Env, info: MessageIn .map_err(StdError::overflow)?; // Now send the tokens to the sender and any fees to the DAO - let mut send_msgs: Vec> = - vec![CosmosMsg::::Bank(BankMsg::Send { - to_address: info.sender.to_string(), - amount: vec![Coin { - amount: released, - denom: curve_state.reserve_denom.clone(), - }], - })]; + let mut send_msgs: Vec = vec![CosmosMsg::Bank(BankMsg::Send { + to_address: info.sender.to_string(), + amount: vec![Coin { + amount: released, + denom: curve_state.reserve_denom.clone(), + }], + })]; // Send exit fees to the to the fee recipient if taxed_amount > Uint128::zero() { @@ -235,7 +236,7 @@ pub fn execute_sell(deps: DepsMut, _env: Env, info: MessageIn })) } - Ok(Response::::new() + Ok(Response::new() .add_messages(burn_msgs) .add_messages(send_msgs) .add_attribute("action", "burn") @@ -246,7 +247,10 @@ pub fn execute_sell(deps: DepsMut, _env: Env, info: MessageIn } /// Calculate the exit taxation for the sell amount based on the phase -fn calculate_exit_fee(storage: &dyn Storage, sell_amount: Uint128) -> CwAbcResult { +fn calculate_exit_fee( + storage: &dyn Storage, + sell_amount: Uint128, +) -> Result { // Load the phase config and phase let phase = PHASE.load(storage)?; let phase_config = PHASE_CONFIG.load(storage)?; @@ -270,7 +274,7 @@ fn calculate_exit_fee(storage: &dyn Storage, sell_amount: Uint128) -> CwAbcResul } /// Transitions the bonding curve to a closed phase where only sells are allowed -pub fn execute_close(deps: DepsMut, info: MessageInfo) -> CwAbcResult { +pub fn execute_close(deps: DepsMut, info: MessageInfo) -> Result { cw_ownable::assert_owner(deps.storage, &info.sender)?; PHASE.save(deps.storage, &CommonsPhase::Closed)?; @@ -280,10 +284,10 @@ pub fn execute_close(deps: DepsMut, info: MessageInfo) -> CwA /// Send a donation to the funding pool pub fn execute_donate( - deps: DepsMut, + deps: DepsMut, _env: Env, info: MessageInfo, -) -> CwAbcResult { +) -> Result { let mut curve_state = CURVE_STATE.load(deps.storage)?; let payment = must_pay(&info, &curve_state.reserve_denom)?; @@ -317,10 +321,10 @@ fn assert_allowlisted(storage: &dyn Storage, hatcher: &Addr) -> Result<(), Contr /// Set the maxiumum supply (only callable by owner) /// If `max_supply` is set to None there will be no limit.` pub fn update_max_supply( - deps: DepsMut, + deps: DepsMut, info: MessageInfo, max_supply: Option, -) -> CwAbcResult { +) -> Result { cw_ownable::assert_owner(deps.storage, &info.sender)?; match max_supply { @@ -335,11 +339,11 @@ pub fn update_max_supply( /// Add and remove addresses from the hatcher allowlist pub fn update_hatch_allowlist( - deps: DepsMut, + deps: DepsMut, info: MessageInfo, to_add: Vec, to_remove: Vec, -) -> CwAbcResult { +) -> Result { cw_ownable::assert_owner(deps.storage, &info.sender)?; let mut allowlist = HATCHER_ALLOWLIST.may_load(deps.storage)?; @@ -368,11 +372,11 @@ pub fn update_hatch_allowlist( /// Update the configuration of a particular phase pub fn update_phase_config( - deps: DepsMut, + deps: DepsMut, _env: Env, info: MessageInfo, update_phase_config_msg: UpdatePhaseConfigMsg, -) -> CwAbcResult { +) -> Result { // Assert that the sender is the contract owner cw_ownable::assert_owner(deps.storage, &info.sender)?; @@ -442,10 +446,10 @@ pub fn update_phase_config( /// NOTE: this changes the pricing. Use with caution. /// TODO: what other limitations do we want to put on this? pub fn update_curve( - deps: DepsMut, + deps: DepsMut, info: MessageInfo, curve_type: CurveType, -) -> CwAbcResult { +) -> Result { cw_ownable::assert_owner(deps.storage, &info.sender)?; CURVE_TYPE.save(deps.storage, &curve_type)?; @@ -455,11 +459,11 @@ pub fn update_curve( /// Update the ownership of the contract pub fn update_ownership( - deps: DepsMut, + deps: DepsMut, env: &Env, info: &MessageInfo, action: cw_ownable::Action, -) -> Result, ContractError> { +) -> Result { let ownership = cw_ownable::update_ownership( DepsMut { storage: deps.storage, @@ -489,7 +493,7 @@ mod tests { const TEST_DONOR: &str = "donor"; - fn exec_donate(deps: DepsMut, donation_amount: u128) -> CwAbcResult { + fn exec_donate(deps: DepsMut, donation_amount: u128) -> Result { execute_donate( deps, mock_env(), @@ -498,8 +502,8 @@ mod tests { } #[test] - fn should_fail_with_no_funds() -> CwAbcResult<()> { - let mut deps = mock_tf_dependencies(); + fn should_fail_with_no_funds() -> Result<(), ContractError> { + let mut deps = mock_dependencies(); let curve_type = CurveType::Linear { slope: Uint128::new(1), scale: 1, @@ -516,8 +520,8 @@ mod tests { } #[test] - fn should_fail_with_incorrect_denom() -> CwAbcResult<()> { - let mut deps = mock_tf_dependencies(); + fn should_fail_with_incorrect_denom() -> Result<(), ContractError> { + let mut deps = mock_dependencies(); let curve_type = CurveType::Linear { slope: Uint128::new(1), scale: 1, @@ -540,8 +544,8 @@ mod tests { } #[test] - fn should_add_to_funding_pool() -> CwAbcResult<()> { - let mut deps = mock_tf_dependencies(); + fn should_add_to_funding_pool() -> 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), diff --git a/contracts/external/cw-abc/src/contract.rs b/contracts/external/cw-abc/src/contract.rs index 968516e54..1c3b7e294 100644 --- a/contracts/external/cw-abc/src/contract.rs +++ b/contracts/external/cw-abc/src/contract.rs @@ -10,7 +10,6 @@ use cw_tokenfactory_issuer::msg::{ }; use cw_utils::parse_reply_instantiate_data; use std::collections::HashSet; -use token_bindings::{TokenFactoryMsg, TokenFactoryQuery}; use crate::abc::{CommonsPhase, CurveFn}; use crate::curves::DecimalPlaces; @@ -28,15 +27,13 @@ const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); const INSTANTIATE_TOKEN_FACTORY_ISSUER_REPLY_ID: u64 = 0; -pub type CwAbcResult> = Result; - #[cfg_attr(not(feature = "library"), entry_point)] pub fn instantiate( - deps: DepsMut, + deps: DepsMut, _env: Env, info: MessageInfo, msg: InstantiateMsg, -) -> CwAbcResult { +) -> Result { set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; let InstantiateMsg { @@ -110,11 +107,11 @@ pub fn instantiate( #[cfg_attr(not(feature = "library"), entry_point)] pub fn execute( - deps: DepsMut, + deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg, -) -> CwAbcResult { +) -> Result { match msg { ExecuteMsg::Buy {} => commands::execute_buy(deps, env, info), ExecuteMsg::Sell {} => commands::execute_sell(deps, env, info), @@ -137,7 +134,7 @@ pub fn execute( } #[cfg_attr(not(feature = "library"), entry_point)] -pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult { +pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult { // default implementation stores curve info as enum, you can do something else in a derived // contract and just pass in your custom curve to do_execute let curve_type = CURVE_TYPE.load(deps.storage)?; @@ -148,12 +145,7 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResul /// We pull out logic here, so we can import this from another contract and set a different Curve. /// This contacts sets a curve with an enum in [`InstantiateMsg`] and stored in state, but you may want /// to use custom math not included - make this easily reusable -pub fn do_query( - deps: Deps, - _env: Env, - msg: QueryMsg, - curve_fn: CurveFn, -) -> StdResult { +pub fn do_query(deps: Deps, _env: Env, msg: QueryMsg, curve_fn: CurveFn) -> StdResult { match msg { // custom queries QueryMsg::CurveInfo {} => to_json_binary(&queries::query_curve_info(deps, curve_fn)?), @@ -175,22 +167,14 @@ pub fn do_query( } #[cfg_attr(not(feature = "library"), entry_point)] -pub fn migrate( - deps: DepsMut, - _env: Env, - _msg: MigrateMsg, -) -> Result, ContractError> { +pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result { // Set contract to version to latest set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; - Ok(Response::::default()) + Ok(Response::default()) } #[cfg_attr(not(feature = "library"), entry_point)] -pub fn reply( - deps: DepsMut, - env: Env, - msg: Reply, -) -> Result, ContractError> { +pub fn reply(deps: DepsMut, env: Env, msg: Reply) -> Result { match msg.id { INSTANTIATE_TOKEN_FACTORY_ISSUER_REPLY_ID => { // Parse and save address of cw-tokenfactory-issuer diff --git a/contracts/external/cw-abc/src/queries.rs b/contracts/external/cw-abc/src/queries.rs index 1d113df3d..d80c4272c 100644 --- a/contracts/external/cw-abc/src/queries.rs +++ b/contracts/external/cw-abc/src/queries.rs @@ -8,13 +8,9 @@ use crate::state::{ }; use cosmwasm_std::{Deps, Order, QuerierWrapper, StdResult, Uint128}; use std::ops::Deref; -use token_bindings::TokenFactoryQuery; /// Get the current state of the curve -pub fn query_curve_info( - deps: Deps, - curve_fn: CurveFn, -) -> StdResult { +pub fn query_curve_info(deps: Deps, curve_fn: CurveFn) -> StdResult { let CurveState { reserve, supply, @@ -37,13 +33,13 @@ pub fn query_curve_info( } /// Returns information about the supply Denom -pub fn get_denom(deps: Deps) -> StdResult { +pub fn get_denom(deps: Deps) -> StdResult { let denom = SUPPLY_DENOM.load(deps.storage)?; Ok(DenomResponse { denom }) } pub fn query_donations( - deps: Deps, + deps: Deps, start_aftor: Option, limit: Option, ) -> StdResult { @@ -67,7 +63,7 @@ pub fn query_donations( /// Query hatchers who contributed during the hatch phase pub fn query_hatchers( - deps: Deps, + deps: Deps, start_aftor: Option, limit: Option, ) -> StdResult { @@ -90,13 +86,13 @@ pub fn query_hatchers( } /// Query the max supply of the supply token -pub fn query_max_supply(deps: Deps) -> StdResult { +pub fn query_max_supply(deps: Deps) -> StdResult { let max_supply = MAX_SUPPLY.may_load(deps.storage)?; Ok(max_supply.unwrap_or(Uint128::MAX)) } /// Load and return the phase config -pub fn query_phase_config(deps: Deps) -> StdResult { +pub fn query_phase_config(deps: Deps) -> StdResult { let phase = PHASE.load(deps.storage)?; let phase_config = PHASE_CONFIG.load(deps.storage)?; Ok(CommonsPhaseConfigResponse { diff --git a/contracts/external/cw-abc/src/testing.rs b/contracts/external/cw-abc/src/testing.rs index 39d483613..8f5214a21 100644 --- a/contracts/external/cw-abc/src/testing.rs +++ b/contracts/external/cw-abc/src/testing.rs @@ -1,23 +1,23 @@ use cosmwasm_std::{ - testing::{mock_env, mock_info, MockApi, MockQuerier, MockStorage}, - Decimal, DepsMut, OwnedDeps, Uint128, + testing::{mock_env, mock_info}, + Decimal, DepsMut, Response, Uint128, }; use dao_interface::token::NewDenomMetadata; -use std::marker::PhantomData; -use token_bindings::TokenFactoryQuery; -use crate::abc::{ - ClosedConfig, CommonsPhaseConfig, CurveType, HatchConfig, MinMax, OpenConfig, ReserveToken, - SupplyToken, -}; use crate::contract; -use crate::contract::CwAbcResult; use crate::msg::InstantiateMsg; +use crate::{ + abc::{ + ClosedConfig, CommonsPhaseConfig, CurveType, HatchConfig, MinMax, OpenConfig, ReserveToken, + SupplyToken, + }, + ContractError, +}; pub(crate) mod prelude { pub use super::{ - default_instantiate_msg, default_supply_metadata, mock_tf_dependencies, TEST_CREATOR, - TEST_RESERVE_DENOM, TEST_SUPPLY_DENOM, _TEST_BUYER, _TEST_INVESTOR, + default_instantiate_msg, default_supply_metadata, TEST_CREATOR, TEST_RESERVE_DENOM, + TEST_SUPPLY_DENOM, _TEST_BUYER, _TEST_INVESTOR, }; pub use crate::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; pub use speculoos::prelude::*; @@ -82,21 +82,21 @@ pub fn default_instantiate_msg( } } -pub fn mock_init(deps: DepsMut, init_msg: InstantiateMsg) -> CwAbcResult { +pub fn mock_init(deps: DepsMut, init_msg: InstantiateMsg) -> Result { let info = mock_info(TEST_CREATOR, &[]); let env = mock_env(); contract::instantiate(deps, env, info, init_msg) } -pub fn mock_tf_dependencies( -) -> OwnedDeps, TokenFactoryQuery> { - OwnedDeps { - storage: MockStorage::default(), - api: MockApi::default(), - querier: MockQuerier::::new(&[]), - custom_query_type: PhantomData::, - } -} +// pub fn mock_tf_dependencies( +// ) -> OwnedDeps, TokenFactoryQuery> { +// OwnedDeps { +// storage: MockStorage::default(), +// api: MockApi::default(), +// querier: MockQuerier::::new(&[]), +// custom_query_type: PhantomData::, +// } +// } // fn setup_test( // deps: DepsMut,