Skip to content

Commit

Permalink
Merge pull request #689 from public-awesome/serkan/factory-creation-f…
Browse files Browse the repository at this point in the history
…ee-update

Transfer non-STARS creation fees to Launchpad DAO
  • Loading branch information
jhernandezb authored May 22, 2024
2 parents e0414c5 + 34aee21 commit 9b82612
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 15 deletions.
1 change: 0 additions & 1 deletion 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/collections/sg721-base/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ where
pub fn migrate(mut deps: DepsMut, env: Env, _msg: Empty) -> Result<Response, ContractError> {
let prev_contract_version = cw2::get_contract_version(deps.storage)?;

let valid_contract_names = vec![CONTRACT_NAME.to_string()];
let valid_contract_names = [CONTRACT_NAME.to_string()];
if !valid_contract_names.contains(&prev_contract_version.contract) {
return Err(StdError::generic_err("Invalid contract name for migration").into());
}
Expand Down
17 changes: 13 additions & 4 deletions contracts/factories/base-factory/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use cosmwasm_std::{
use cw2::set_contract_version;
use cw_utils::must_pay;
use semver::Version;
use sg1::checked_fair_burn;
use sg1::{checked_fair_burn, transfer_funds_to_launchpad_dao};
use sg2::msg::UpdateMinterParamsMsg;
use sg2::query::{AllowedCollectionCodeIdResponse, AllowedCollectionCodeIdsResponse, Sg2QueryMsg};
use sg2::MinterParams;
Expand Down Expand Up @@ -57,14 +57,23 @@ pub fn execute_create_minter(
info: MessageInfo,
msg: BaseMinterCreateMsg,
) -> Result<Response, ContractError> {
must_pay(&info, NATIVE_DENOM)?;
let params = SUDO_PARAMS.load(deps.storage)?;
must_pay(&info, &params.creation_fee.denom)?;
must_be_allowed_collection(deps.as_ref(), msg.collection_params.code_id)?;

let params = SUDO_PARAMS.load(deps.storage)?;
must_not_be_frozen(&params)?;

let mut res = Response::new();
checked_fair_burn(&info, params.creation_fee.amount.u128(), None, &mut res)?;
if params.creation_fee.denom == NATIVE_DENOM {
checked_fair_burn(&info, params.creation_fee.amount.u128(), None, &mut res)?;
} else {
transfer_funds_to_launchpad_dao(
&info,
params.creation_fee.amount.u128(),
&params.creation_fee.denom,
&mut res,
)?;
}

let msg = WasmMsg::Instantiate {
admin: Some(info.sender.to_string()),
Expand Down
15 changes: 12 additions & 3 deletions contracts/factories/open-edition-factory/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use base_factory::contract::{
must_be_allowed_collection, must_not_be_frozen, must_pay_exact_amount, update_params,
};
use base_factory::ContractError as BaseContractError;
use sg1::checked_fair_burn;
use sg1::{checked_fair_burn, transfer_funds_to_launchpad_dao};
use sg2::query::{AllowedCollectionCodeIdResponse, AllowedCollectionCodeIdsResponse, Sg2QueryMsg};

use crate::error::ContractError;
Expand Down Expand Up @@ -66,14 +66,23 @@ pub fn execute_create_minter(
) -> Result<Response, ContractError> {
let params = SUDO_PARAMS.load(deps.storage)?;

must_pay_exact_amount(&params, &info, NATIVE_DENOM)?;
must_pay_exact_amount(&params, &info, &params.creation_fee.denom)?;

must_be_allowed_collection(deps.as_ref(), msg.collection_params.code_id)?;

must_not_be_frozen(&params)?;

let mut res = Response::new();
checked_fair_burn(&info, params.creation_fee.amount.u128(), None, &mut res)?;
if params.creation_fee.denom == NATIVE_DENOM {
checked_fair_burn(&info, params.creation_fee.amount.u128(), None, &mut res)?;
} else {
transfer_funds_to_launchpad_dao(
&info,
params.creation_fee.amount.u128(),
&params.creation_fee.denom,
&mut res,
)?;
}

msg.init_msg = OpenEditionMinterInitMsgExtension::validate(
msg.init_msg.clone(),
Expand Down
17 changes: 13 additions & 4 deletions contracts/factories/vending-factory/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use cosmwasm_std::{
use cw2::set_contract_version;
use cw_utils::must_pay;
use semver::Version;
use sg1::checked_fair_burn;
use sg1::{checked_fair_burn, transfer_funds_to_launchpad_dao};
use sg2::query::{AllowedCollectionCodeIdResponse, AllowedCollectionCodeIdsResponse, Sg2QueryMsg};
use sg_std::{Response, NATIVE_DENOM};

Expand Down Expand Up @@ -57,14 +57,23 @@ pub fn execute_create_minter(
info: MessageInfo,
msg: VendingMinterCreateMsg,
) -> Result<Response, ContractError> {
must_pay(&info, NATIVE_DENOM)?;
let params = SUDO_PARAMS.load(deps.storage)?;
must_pay(&info, &params.creation_fee.denom)?;
must_be_allowed_collection(deps.as_ref(), msg.collection_params.code_id)?;

let params = SUDO_PARAMS.load(deps.storage)?;
must_not_be_frozen(&params)?;

let mut res = Response::new();
checked_fair_burn(&info, params.creation_fee.amount.u128(), None, &mut res)?;
if params.creation_fee.denom == NATIVE_DENOM {
checked_fair_burn(&info, params.creation_fee.amount.u128(), None, &mut res)?;
} else {
transfer_funds_to_launchpad_dao(
&info,
params.creation_fee.amount.u128(),
&params.creation_fee.denom,
&mut res,
)?;
}

// Check the number of tokens is more than zero and less than the max limit
if msg.init_msg.num_tokens == 0 || msg.init_msg.num_tokens > params.extension.max_token_limit {
Expand Down
29 changes: 27 additions & 2 deletions packages/sg1/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
use cosmwasm_std::{coin, coins, Addr, BankMsg, Coin, Decimal, Event, MessageInfo, Uint128};
use cw_utils::{may_pay, PaymentError};
use cosmwasm_std::{
coin, coins, ensure, Addr, BankMsg, Coin, Decimal, Event, MessageInfo, Uint128,
};
use cw_utils::{may_pay, must_pay, PaymentError};
use sg_std::{create_fund_fairburn_pool_msg, Response, SubMsg, NATIVE_DENOM};
use thiserror::Error;

// governance parameters
const FEE_BURN_PERCENT: u64 = 50;
const FOUNDATION: &str = "stars1xqz6xujjyz0r9uzn7srasle5uynmpa0zkjr5l8";
const LAUNCHPAD_DAO_ADDRESS: &str =
"stars1huqk6ha02jgrm69lxh8xfgl6wch9wlg7s65ujxydwdr725cxvuus423tj0";

/// Burn and distribute fees and return an error if the fee is not enough
pub fn checked_fair_burn(
Expand Down Expand Up @@ -103,6 +107,27 @@ pub fn fair_burn(fee: u128, developer: Option<Addr>, res: &mut Response) {
res.events.push(event);
}

pub fn transfer_funds_to_launchpad_dao(
info: &MessageInfo,
fee: u128,
accepted_denom: &str,
res: &mut Response,
) -> Result<(), FeeError> {
let payment = must_pay(info, accepted_denom)?;
ensure!(
payment.u128() >= fee,
FeeError::InsufficientFee(fee, payment.u128())
);

let msg = BankMsg::Send {
to_address: LAUNCHPAD_DAO_ADDRESS.to_string(),
amount: vec![coin(payment.u128(), accepted_denom)],
};
res.messages.push(SubMsg::new(msg));

Ok(())
}

#[derive(Error, Debug, PartialEq, Eq)]
pub enum FeeError {
#[error("Insufficient fee: expected {0}, got {1}")]
Expand Down

0 comments on commit 9b82612

Please sign in to comment.