Skip to content

Commit

Permalink
chore: this removes the sanity check preventing to add burn fees to a…
Browse files Browse the repository at this point in the history
… pair or trio with token factory tokens
  • Loading branch information
kerber0x committed Jan 29, 2024
1 parent 067ae80 commit b9eba56
Show file tree
Hide file tree
Showing 12 changed files with 16 additions and 308 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "stableswap-3pool"
version = "1.2.2"
version = "1.2.3"
authors = ["Adam J. Weigold <[email protected]>"]
edition.workspace = true
license.workspace = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use white_whale_std::pool_network::trio::{Config, Cw20HookMsg, FeatureToggle, Po

use crate::error::ContractError;
use crate::helpers;
use crate::helpers::{get_protocol_fee_for_asset, get_total_share, has_factory_token};
use crate::helpers::{get_protocol_fee_for_asset, get_total_share};
use crate::stableswap_math::curve::StableSwap;
use crate::state::{
store_fee, ALL_TIME_BURNED_FEES, ALL_TIME_COLLECTED_PROTOCOL_FEES, COLLECTED_PROTOCOL_FEES,
Expand Down Expand Up @@ -567,20 +567,6 @@ pub fn update_config(

if let Some(pool_fees) = pool_fees {
pool_fees.is_valid()?;

let trio_info_raw: TrioInfoRaw = TRIO_INFO.load(deps.storage)?;

if has_factory_token(
&trio_info_raw
.asset_infos
.into_iter()
.map(|raw| raw.to_normal(deps.api).unwrap())
.collect::<Vec<AssetInfo>>(),
) && pool_fees.burn_fee.share > Decimal::zero()
{
return Err(ContractError::TokenFactoryAssetBurnDisabled {});
}

config.pool_fees = pool_fees;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{
to_json_binary, Binary, Decimal, Deps, DepsMut, Env, MessageInfo, Reply, Response, StdError,
StdResult,
to_json_binary, Binary, Deps, DepsMut, Env, MessageInfo, Reply, Response, StdError, StdResult,
};
use cw2::{get_contract_version, set_contract_version};
use protobuf::Message;
Expand All @@ -15,7 +14,6 @@ use white_whale_std::pool_network::trio::{

use crate::error::ContractError;
use crate::error::ContractError::MigrateInvalidVersion;
use crate::helpers::has_factory_token;
use crate::response::MsgInstantiateContractResponse;
use crate::state::{
ALL_TIME_BURNED_FEES, ALL_TIME_COLLECTED_PROTOCOL_FEES, COLLECTED_PROTOCOL_FEES, CONFIG,
Expand Down Expand Up @@ -47,10 +45,6 @@ pub fn instantiate(
) -> Result<Response, ContractError> {
set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;

if has_factory_token(&msg.asset_infos) && msg.pool_fees.burn_fee.share > Decimal::zero() {
return Err(ContractError::TokenFactoryAssetBurnDisabled {});
}

let trio_info: &TrioInfoRaw = &TrioInfoRaw {
contract_addr: deps.api.addr_canonicalize(env.contract.address.as_str())?,
liquidity_token: AssetInfoRaw::NativeToken {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ pub enum ContractError {
#[error("Failed to compute the LP share with the given deposit")]
LiquidityShareComputation {},

#[error("Burn fee is not allowed when using factory tokens")]
TokenFactoryAssetBurnDisabled {},

#[error("The token factory feature is not enabled")]
TokenFactoryNotEnabled {},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ use cw_storage_plus::Item;
feature = "injective"
))]
use cosmwasm_std::CosmosMsg;
use white_whale_std::pool_network::asset::{is_factory_token, Asset, AssetInfo, AssetInfoRaw};
#[cfg(any(
feature = "token_factory",
feature = "osmosis_token_factory",
feature = "injective"
))]
use white_whale_std::pool_network::asset::is_factory_token;
use white_whale_std::pool_network::asset::{Asset, AssetInfo, AssetInfoRaw};
#[cfg(feature = "token_factory")]
use white_whale_std::pool_network::denom::MsgCreateDenom;
#[cfg(feature = "injective")]
Expand Down Expand Up @@ -300,15 +306,6 @@ pub fn get_total_share(deps: &Deps, liquidity_token: String) -> StdResult<Uint12
Ok(total_share)
}

/// Verifies if there's a factory token in the vector of [AssetInfo]s.
/// todo consolidate this once the pool PRs are merged
pub fn has_factory_token(assets: &[AssetInfo]) -> bool {
assets.iter().any(|asset| match asset {
AssetInfo::Token { .. } => false,
AssetInfo::NativeToken { denom } => is_factory_token(denom),
})
}

/// Creates a new LP token for this pool
pub fn create_lp_token(
deps: DepsMut,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,134 +204,6 @@ fn proper_initialization_tokenfactory_lp() {
);
}

#[cfg(feature = "token_factory")]
#[test]
fn intialize_with_burnable_token_factory_asset() {
let mut deps = mock_dependencies(&[]);

deps.querier.with_token_balances(&[
(
&"asset0000".to_string(),
&[(&MOCK_CONTRACT_ADDR.to_string(), &Uint128::from(123u128))],
),
(
&"asset0001".to_string(),
&[(&MOCK_CONTRACT_ADDR.to_string(), &Uint128::from(456u128))],
),
]);

let msg = InstantiateMsg {
asset_infos: [
AssetInfo::NativeToken {
denom: "factory/migaloo1436kxs0w2es6xlqpp9rd35e3d0cjnw4sv8j3a7483sgks29jqwgshqdky4/ampWHALE".to_string(),
},
AssetInfo::Token {
contract_addr: "asset0000".to_string(),
},
AssetInfo::Token {
contract_addr: "asset0001".to_string(),
},
],
token_code_id: 10u64,
asset_decimals: [6u8, 8u8, 10u8],
pool_fees: PoolFee {
protocol_fee: Fee {
share: Decimal::percent(1u64),
},
swap_fee: Fee {
share: Decimal::percent(1u64),
},
burn_fee: Fee {
share: Decimal::zero(),
},
},
fee_collector_addr: "collector".to_string(),
amp_factor: 1000,
token_factory_lp: true,
};

// we can just call .unwrap() to assert this was a success
let env = mock_env();
let info = mock_info("addr0000", &[]);
let res = instantiate(deps.as_mut(), env.clone(), info.clone(), msg).unwrap();

let expected = <MsgCreateDenom as Into<CosmosMsg>>::into(MsgCreateDenom {
sender: MOCK_CONTRACT_ADDR.to_string(),
subdenom: LP_SYMBOL.to_string(),
});

assert_eq!(res.messages[0].msg, expected);

// let's try to increase the burn fee. It should fail
let update_config_message = UpdateConfig {
owner: None,
fee_collector_addr: None,
pool_fees: Some(PoolFee {
protocol_fee: Fee {
share: Decimal::percent(1u64),
},
swap_fee: Fee {
share: Decimal::percent(1u64),
},
burn_fee: Fee {
share: Decimal::percent(1u64),
},
}),
feature_toggle: None,
amp_factor: None,
};

let res = execute(
deps.as_mut(),
env.clone(),
info.clone(),
update_config_message,
);
match res {
Ok(_) => panic!("Expected error, ContractError::TokenFactoryAssetBurnDisabled"),
Err(ContractError::TokenFactoryAssetBurnDisabled {}) => (),
_ => panic!("Expected error, ContractError::TokenFactoryAssetBurnDisabled"),
}

// now let's try instantiating the contract with burning fees, it should fail
let msg = InstantiateMsg {
asset_infos: [
AssetInfo::NativeToken {
denom: "factory/migaloo1436kxs0w2es6xlqpp9rd35e3d0cjnw4sv8j3a7483sgks29jqwgshqdky4/ampWHALE".to_string(),
},
AssetInfo::Token {
contract_addr: "asset0000".to_string(),
},
AssetInfo::Token {
contract_addr: "asset0001".to_string(),
},
],
token_code_id: 10u64,
asset_decimals: [6u8, 8u8, 10u8],
pool_fees: PoolFee {
protocol_fee: Fee {
share: Decimal::percent(1u64),
},
swap_fee: Fee {
share: Decimal::percent(1u64),
},
burn_fee: Fee {
share: Decimal::percent(1u64),
},
},
fee_collector_addr: "collector".to_string(),
amp_factor: 1000,
token_factory_lp: true,
};

let res = instantiate(deps.as_mut(), env, info, msg);
match res {
Ok(_) => panic!("Expected error, ContractError::TokenFactoryAssetBurnDisabled"),
Err(ContractError::TokenFactoryAssetBurnDisabled {}) => (),
_ => panic!("Expected error, ContractError::TokenFactoryAssetBurnDisabled"),
}
}

#[cfg(not(feature = "osmosis"))]
#[test]
fn test_initialization_invalid_fees() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "terraswap-pair"
version = "1.3.3"
version = "1.3.4"
authors = [
"Terraform Labs, PTE.",
"DELIGHT LABS",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ use cw20::{Cw20ExecuteMsg, Cw20ReceiveMsg};
))]
use white_whale_std::pool_network::asset::is_factory_token;
use white_whale_std::pool_network::asset::{
get_total_share, has_factory_token, Asset, AssetInfo, AssetInfoRaw, PairInfoRaw,
MINIMUM_LIQUIDITY_AMOUNT,
get_total_share, Asset, AssetInfo, AssetInfoRaw, PairInfoRaw, MINIMUM_LIQUIDITY_AMOUNT,
};
#[cfg(feature = "token_factory")]
use white_whale_std::pool_network::denom::{Coin, MsgBurn, MsgMint};
Expand Down Expand Up @@ -565,20 +564,6 @@ pub fn update_config(

if let Some(pool_fees) = pool_fees {
pool_fees.is_valid()?;

let pair_info_raw = PAIR_INFO.load(deps.storage)?;

if has_factory_token(
&pair_info_raw
.asset_infos
.into_iter()
.map(|raw| raw.to_normal(deps.api).unwrap())
.collect::<Vec<AssetInfo>>(),
) && pool_fees.burn_fee.share > Decimal::zero()
{
return Err(ContractError::TokenFactoryAssetBurnDisabled {});
}

config.pool_fees = pool_fees;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{
to_json_binary, Binary, Decimal, Deps, DepsMut, Env, MessageInfo, Reply, Response, StdError,
StdResult,
to_json_binary, Binary, Deps, DepsMut, Env, MessageInfo, Reply, Response, StdError, StdResult,
};
use cw2::{get_contract_version, set_contract_version};
use protobuf::Message;
use semver::Version;

use white_whale_std::pool_network::asset::{has_factory_token, AssetInfoRaw, PairInfoRaw};
use white_whale_std::pool_network::asset::{AssetInfoRaw, PairInfoRaw};
use white_whale_std::pool_network::pair::{
Config, ExecuteMsg, FeatureToggle, InstantiateMsg, MigrateMsg, QueryMsg,
};
Expand Down Expand Up @@ -36,10 +35,6 @@ pub fn instantiate(
) -> Result<Response, ContractError> {
set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;

if has_factory_token(&msg.asset_infos) && msg.pool_fees.burn_fee.share > Decimal::zero() {
return Err(ContractError::TokenFactoryAssetBurnDisabled {});
}

let pair_info: &PairInfoRaw = &PairInfoRaw {
contract_addr: deps.api.addr_canonicalize(env.contract.address.as_str())?,
liquidity_token: AssetInfoRaw::NativeToken {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@ pub enum ContractError {
#[error("An overflow occurred when attempting to construct a decimal")]
DecimalOverflow {},

#[error("Burn fee is not allowed when using factory tokens")]
TokenFactoryAssetBurnDisabled {},

#[error("The token factory feature is not enabled")]
TokenFactoryNotEnabled {},
}
Expand Down
Loading

0 comments on commit b9eba56

Please sign in to comment.