Skip to content

Commit

Permalink
send IBC assets to foundation address
Browse files Browse the repository at this point in the history
  • Loading branch information
yubrew committed Aug 31, 2023
1 parent 981f1ce commit 0b296f3
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 34 deletions.
19 changes: 9 additions & 10 deletions contracts/minters/vending-minter/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,21 @@ use crate::validation::{check_dynamic_per_address_limit, get_three_percent_of_to
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{
coin, coins, ensure, to_binary, Addr, BankMsg, Binary, Coin, CosmosMsg, Deps, DepsMut, Empty,
Env, Event, MessageInfo, Order, Reply, ReplyOn, StdError, StdResult, Timestamp, Uint128,
WasmMsg,
coin, ensure, to_binary, Addr, BankMsg, Binary, Coin, CosmosMsg, Deps, DepsMut, Empty, Env,
Event, MessageInfo, Order, Reply, ReplyOn, StdError, StdResult, Timestamp, Uint128, WasmMsg,
};
use cw2::set_contract_version;
use cw721_base::Extension;
use cw_utils::{may_pay, maybe_addr, nonpayable, parse_reply_instantiate_data};
use rand_core::{RngCore, SeedableRng};
use rand_xoshiro::Xoshiro128PlusPlus;
use semver::Version;
use sg1::checked_fair_burn;
use sg1::{checked_fair_burn, ibc_denom_fair_burn};
use sg2::query::Sg2QueryMsg;
use sg4::{MinterConfig, Status, StatusResponse, SudoMsg};
use sg721::{ExecuteMsg as Sg721ExecuteMsg, InstantiateMsg as Sg721InstantiateMsg};
use sg_std::math::U64Ext;
use sg_std::{
create_fund_community_pool_msg, StargazeMsgWrapper, GENESIS_MINT_START_TIME, NATIVE_DENOM,
};
use sg_std::{StargazeMsgWrapper, GENESIS_MINT_START_TIME, NATIVE_DENOM};
use sg_whitelist::msg::{
ConfigResponse as WhitelistConfigResponse, HasMemberResponse, QueryMsg as WhitelistQueryMsg,
};
Expand Down Expand Up @@ -661,9 +658,11 @@ fn _execute_mint(
if mint_price.denom != NATIVE_DENOM {
// only send non-zero amounts
if !network_fee.is_zero() {
let msg =
create_fund_community_pool_msg(coins(network_fee.u128(), mint_price.clone().denom));
res = res.add_message(msg);
ibc_denom_fair_burn(
coin(network_fee.u128(), mint_price.clone().denom),
None,
&mut res,
)?;
}
} else {
checked_fair_burn(&info, network_fee.u128(), None, &mut res)?;
Expand Down
38 changes: 19 additions & 19 deletions packages/sg1/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use cosmwasm_std::{coin, coins, Addr, BankMsg, Coin, Decimal, Event, MessageInfo, Uint128};
use cw_utils::{may_pay, PaymentError};
use sg_std::{
create_fund_community_pool_msg, create_fund_fairburn_pool_msg, Response, SubMsg, NATIVE_DENOM,
};
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";

/// Burn and distribute fees and return an error if the fee is not enough
pub fn checked_fair_burn(
Expand All @@ -28,7 +27,7 @@ pub fn checked_fair_burn(
Ok(())
}

/// IBC assets go to community pool and dev
/// IBC assets go to foundation and dev
/// 7/29/23 temporary fix until we switch to using fairburn contract
pub fn ibc_denom_fair_burn(
fee: Coin,
Expand All @@ -39,31 +38,32 @@ pub fn ibc_denom_fair_burn(

match &developer {
Some(developer) => {
// Calculate the fees. 50% to dev, 50% to community pool
// Calculate the fees. 50% to dev, 50% to foundation
let dev_fee = (fee.amount.mul_ceil(Decimal::percent(FEE_BURN_PERCENT))).u128();
let dev_coin = coins(dev_fee, fee.denom.to_string());
let comm_fee = coin(fee.amount.u128() - dev_fee, fee.denom.to_string());
let dev_coin = coin(dev_fee, fee.denom.to_string());
let foundation_coin = coin(fee.amount.u128() - dev_fee, fee.denom.to_string());

event = event.add_attribute("dev_addr", developer.to_string());
event = event.add_attribute("dev_denom", fee.denom.to_string());
event = event.add_attribute("dev_amount", fee.amount.u128().to_string());
event = event.add_attribute("com_pool_denom", comm_fee.denom.to_string());
event = event.add_attribute("com_pool_amount", comm_fee.amount.u128().to_string());
event = event.add_attribute("dev_coin", dev_coin.to_string());
event = event.add_attribute("foundation_coin", foundation_coin.to_string());

res.messages.push(SubMsg::new(BankMsg::Send {
to_address: developer.to_string(),
amount: dev_coin,
amount: vec![dev_coin],
}));
res.messages.push(SubMsg::new(BankMsg::Send {
to_address: FOUNDATION.to_string(),
amount: vec![foundation_coin],
}));
res.messages
.push(SubMsg::new(create_fund_community_pool_msg(vec![comm_fee])));
}
None => {
// No dev, send all to community pool.
event = event.add_attribute("com_pool_denom", fee.denom.to_string());
event = event.add_attribute("com_pool_amount", fee.amount.u128().to_string());
// No dev, send all to foundation.
event = event.add_attribute("foundation_coin", fee.to_string());

res.messages
.push(SubMsg::new(create_fund_community_pool_msg(vec![fee])));
res.messages.push(SubMsg::new(BankMsg::Send {
to_address: FOUNDATION.to_string(),
amount: vec![fee],
}));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ pub const SHUFFLE_FEE: u128 = 500_000_000;
pub const MAX_PER_ADDRESS_LIMIT: u32 = 50;
pub const DEV_ADDRESS: &str = "stars1abcd4kdla12mh86psg4y4h6hh05g2hmqoap350";
pub const MIN_MINT_PRICE_OPEN_EDITION: u128 = 100_000_000;
pub const FOUNDATION: &str = "stars1xqz6xujjyz0r9uzn7srasle5uynmpa0zkjr5l8";
4 changes: 2 additions & 2 deletions test-suite/src/open_edition_minter/tests/ibc_asset_mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::common_setup::{
contract_boxes::{contract_sg721_base, custom_mock_app},
setup_accounts_and_block::{setup_accounts, setup_block_time},
setup_minter::{
common::constants::{CREATION_FEE, MIN_MINT_PRICE_OPEN_EDITION},
common::constants::{CREATION_FEE, FOUNDATION, MIN_MINT_PRICE_OPEN_EDITION},
open_edition_minter::{
mock_params::{
mock_create_minter_init_msg, mock_init_minter_extension, mock_params_custom,
Expand Down Expand Up @@ -133,7 +133,7 @@ fn one_hundred_percent_burned_ibc_minter() {
// "community_pool" address from packages/sg-multi-test/src/multi.rs
let balance = router
.wrap()
.query_balance(Addr::unchecked("community_pool"), denom)
.query_balance(Addr::unchecked(FOUNDATION), denom)
.unwrap();
assert_eq!(balance.amount, mint_price.amount * Decimal::percent(50));
}
Expand Down
28 changes: 25 additions & 3 deletions test-suite/src/vending_minter/tests/ibc_asset_mint.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::common_setup::setup_collection_whitelist::WHITELIST_AMOUNT;
use cosmwasm_std::{coin, coins, Addr};
use crate::common_setup::{
setup_collection_whitelist::WHITELIST_AMOUNT, setup_minter::common::constants::FOUNDATION,
};
use cosmwasm_std::{coin, coins, Addr, Decimal, Uint128};
use cw_multi_test::{BankSudo, Executor, SudoMsg};
use sg2::{msg::Sg2ExecuteMsg, tests::mock_collection_params};
use sg_std::{GENESIS_MINT_START_TIME, NATIVE_DENOM};
Expand Down Expand Up @@ -238,6 +240,26 @@ fn wl_denom_mint() {

// Whitelist mint succeeds
let mint_msg = ExecuteMsg::Mint {};
let res = app.execute_contract(buyer, minter_addr, &mint_msg, &[wl_mint_price]);
let res = app.execute_contract(
buyer.clone(),
minter_addr,
&mint_msg,
&[wl_mint_price.clone()],
);
assert!(res.is_ok());

// confirm balances
// confirm buyer IBC assets spent
let balance = app.wrap().query_balance(buyer, denom).unwrap();
assert_eq!(balance.amount, Uint128::zero());
// for seller should get 90% of IBC asset
let balance = app.wrap().query_balance(creator, denom).unwrap();
assert_eq!(balance.amount, wl_mint_price.amount * Decimal::percent(90));
// confirm mint_price 50% sent to community pool, 50% sent to dev
// "community_pool" address from packages/sg-multi-test/src/multi.rs
let balance = app
.wrap()
.query_balance(Addr::unchecked(FOUNDATION), denom)
.unwrap();
assert_eq!(balance.amount, wl_mint_price.amount * Decimal::percent(10));
}

0 comments on commit 0b296f3

Please sign in to comment.