Skip to content

Commit

Permalink
Close curve, update curve, set max supply methods
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeHartnell committed Nov 17, 2023
1 parent 923cdd9 commit ae7e73b
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 14 deletions.
47 changes: 46 additions & 1 deletion contracts/external/cw-abc/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::collections::HashSet;
use std::ops::Deref;
use token_bindings::{TokenFactoryMsg, TokenFactoryQuery};

use crate::abc::CommonsPhase;
use crate::abc::{CommonsPhase, CurveType};
use crate::contract::CwAbcResult;
use crate::msg::UpdatePhaseConfigMsg;
use crate::state::{
Expand Down Expand Up @@ -140,6 +140,7 @@ fn update_hatcher_contributions(
})
}

/// Sell tokens on the bonding curve
pub fn execute_sell(deps: DepsMut<TokenFactoryQuery>, _env: Env, info: MessageInfo) -> CwAbcResult {
let curve_type = CURVE_TYPE.load(deps.storage)?;
let curve_fn = curve_type.to_curve_fn();
Expand Down Expand Up @@ -235,6 +236,15 @@ fn calculate_exit_tax(storage: &dyn Storage, sell_amount: Uint128) -> CwAbcResul
Ok(taxed_amount)
}

/// Transitions the bonding curve to a closed phase where only sells are allowed
pub fn execute_close(deps: DepsMut<TokenFactoryQuery>, info: MessageInfo) -> CwAbcResult {
cw_ownable::assert_owner(deps.storage, &info.sender)?;

PHASE.save(deps.storage, &CommonsPhase::Closed)?;

Ok(Response::new().add_attribute("action", "close"))
}

/// Send a donation to the funding pool
pub fn execute_donate(
deps: DepsMut<TokenFactoryQuery>,
Expand Down Expand Up @@ -271,6 +281,25 @@ fn assert_allowlisted(storage: &dyn Storage, hatcher: &Addr) -> Result<(), Contr
Ok(())
}

/// Set the maxiumum supply (only callable by owner)
/// If `max_supply` is set to None there will be no limit.`
pub fn set_max_supply(
deps: DepsMut<TokenFactoryQuery>,
info: MessageInfo,
max_supply: Option<Uint128>,
) -> CwAbcResult {
cw_ownable::assert_owner(deps.storage, &info.sender)?;

match max_supply {
Some(max) => MAX_SUPPLY.save(deps.storage, &max)?,
None => MAX_SUPPLY.remove(deps.storage),
}

Ok(Response::new()
.add_attribute("action", "set_max_supply")
.add_attribute("value", max_supply.unwrap_or(Uint128::MAX).to_string()))
}

/// Add and remove addresses from the hatcher allowlist
pub fn update_hatch_allowlist(
deps: DepsMut<TokenFactoryQuery>,
Expand Down Expand Up @@ -304,6 +333,7 @@ pub fn update_hatch_allowlist(
Ok(Response::new().add_attributes(vec![("action", "update_hatch_allowlist")]))
}

/// Update the configuration of a particular phase
pub fn update_phase_config(
deps: DepsMut<TokenFactoryQuery>,
_env: Env,
Expand Down Expand Up @@ -375,6 +405,21 @@ pub fn update_phase_config(
}
}

/// Update the bonding curve. Only callable by the owner.
/// 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<TokenFactoryQuery>,
info: MessageInfo,
curve_type: CurveType,
) -> CwAbcResult {
cw_ownable::assert_owner(deps.storage, &info.sender)?;

CURVE_TYPE.save(deps.storage, &curve_type)?;

Ok(Response::new().add_attribute("action", "close"))
}

/// Update the ownership of the contract
pub fn update_ownership(
deps: DepsMut<TokenFactoryQuery>,
Expand Down
3 changes: 3 additions & 0 deletions contracts/external/cw-abc/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ pub fn execute(
match msg {
ExecuteMsg::Buy {} => commands::execute_buy(deps, env, info),
ExecuteMsg::Burn {} => commands::execute_sell(deps, env, info),
ExecuteMsg::Close {} => commands::execute_close(deps, info),
ExecuteMsg::Donate {} => commands::execute_donate(deps, env, info),
ExecuteMsg::SetMaxSupply { max_supply } => commands::set_max_supply(deps, info, max_supply),
ExecuteMsg::UpdateCurve { curve_type } => commands::update_curve(deps, info, curve_type),
ExecuteMsg::UpdateHatchAllowlist { to_add, to_remove } => {
commands::update_hatch_allowlist(deps, info, to_add, to_remove)
}
Expand Down
38 changes: 25 additions & 13 deletions contracts/external/cw-abc/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,24 @@ pub struct InstantiateMsg {
}

/// Update the phase configurations.
/// These can only be called by the admin and only before or during each phase
/// These can only be called by the owner.
#[cw_serde]
pub enum UpdatePhaseConfigMsg {
/// Update the hatch phase configuration
Hatch {
contribution_limits: Option<MinMax>,
exit_tax: Option<StdDecimal>,
// TODO what is the minimum used for?
initial_raise: Option<MinMax>,
initial_allocation_ratio: Option<StdDecimal>,
},
/// Update the open phase configuration
/// Update the open phase configuration.
Open {
exit_tax: Option<StdDecimal>,
allocation_percentage: Option<StdDecimal>,
},
/// TODO include curve type so we know what happens when a DAO dies?
/// Update the closed phase configuration
/// Update the closed phase configuration.
/// TODO Set the curve type to be used on close?
Closed {},
}

Expand All @@ -57,24 +58,35 @@ pub enum ExecuteMsg {
Burn {},
/// Donate will add reserve tokens to the funding pool
Donate {},
/// Update the hatch phase allowlist
/// Sets (or unsets if set to None) the maximum supply
SetMaxSupply {
/// The maximum supply able to be minted.
max_supply: Option<Uint128>,
},
/// Updates the curve type used for pricing tokens.
/// Only callable by owner.
/// TODO think about other potential limitations on this.
UpdateCurve { curve_type: CurveType },
/// Update the hatch phase allowlist.
/// This can only be called by the owner.
UpdateHatchAllowlist {
/// Addresses to be added.
to_add: Vec<String>,
/// Addresses to be removed.
to_remove: Vec<String>,
},
/// Update the hatch phase configuration
/// This can only be called by the admin and only during the hatch phase
/// Update the configuration of a certain phase.
/// This can only be called by the owner.
UpdatePhaseConfig(UpdatePhaseConfigMsg),
// TODO Close the bonding curve
// Closing the bonding curve means no more buys are enabled and exit tax is set
// to zero. This could be used in the event of a project shutting down for example.
//
// Q: do we allow updating of the curve type? Is it passed in here?
// Close {},
/// Closing the bonding curve means no more buys are enabled and exit tax is set
/// to zero.
/// For example, this could be used in the event of a project shutting down.
Close {},
}

// TODO Price queries:
// - Price to buy a certain amount?
// - What can be bought for a certain amount?
#[cw_ownable::cw_ownable_query]
#[cw_serde]
#[derive(QueryResponses)]
Expand Down

0 comments on commit ae7e73b

Please sign in to comment.