Skip to content

Commit

Permalink
Add default_royalty_fee_percent parameter to global config
Browse files Browse the repository at this point in the history
  • Loading branch information
tasiov committed Oct 1, 2023
1 parent cde5249 commit 7d7594b
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 14 deletions.
2 changes: 2 additions & 0 deletions contracts/infinity-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pub struct InstantiateMsg {
pub marketplace: String,
pub pair_creation_fee: Coin,
pub fair_burn_fee_percent: Decimal,
pub default_royalty_fee_percent: Decimal,
pub max_royalty_fee_percent: Decimal,
pub max_swap_fee_percent: Decimal,
pub code_ids: CodeIds,
Expand Down Expand Up @@ -104,6 +105,7 @@ pub fn instantiate(
infinity_pair_code_id: msg.code_ids.infinity_pair,
pair_creation_fee: msg.pair_creation_fee,
fair_burn_fee_percent: msg.fair_burn_fee_percent,
default_royalty_fee_percent: msg.default_royalty_fee_percent,
max_royalty_fee_percent: msg.max_royalty_fee_percent,
max_swap_fee_percent: msg.max_swap_fee_percent,
},
Expand Down
3 changes: 3 additions & 0 deletions contracts/infinity-global/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ pub struct GlobalConfig<T: AddressLike> {
pub pair_creation_fee: Coin,
/// The percentage amount of a sale that is paid to the FairBurn contract
pub fair_burn_fee_percent: Decimal,
/// The royalty percentage amount to be paid when no royalty is specified for the protocol
pub default_royalty_fee_percent: Decimal,
/// The maximum percentage amount of a sale that can be paid in royalties
pub max_royalty_fee_percent: Decimal,
/// The maximum percentage amount of a sale that can be paid to LPs
Expand All @@ -53,6 +55,7 @@ impl GlobalConfig<String> {
infinity_pair_code_id: self.infinity_pair_code_id,
pair_creation_fee: self.pair_creation_fee,
fair_burn_fee_percent: self.fair_burn_fee_percent,
default_royalty_fee_percent: self.default_royalty_fee_percent,
max_royalty_fee_percent: self.max_royalty_fee_percent,
max_swap_fee_percent: self.max_swap_fee_percent,
})
Expand Down
26 changes: 21 additions & 5 deletions contracts/infinity-pair/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ use crate::{
use cosmwasm_std::{ensure_eq, Addr, Coin, Decimal, Deps, QuerierWrapper, Storage, Uint128};
use infinity_global::{load_global_config, load_min_price, GlobalConfig};
use infinity_shared::InfinityError;
use stargaze_royalty_registry::{fetch_royalty_entry, state::RoyaltyEntry};
use stargaze_royalty_registry::{
msg::{QueryMsg as RoyaltyRegistryQueryMsg, RoyaltyPaymentResponse},
state::RoyaltyEntry,
};
use std::cmp::min;

pub fn only_pair_owner(sender: &Addr, pair: &Pair) -> Result<(), ContractError> {
Expand Down Expand Up @@ -112,13 +115,26 @@ pub fn load_payout_context(
let min_price = load_min_price(&deps.querier, infinity_global, denom)?
.ok_or(InfinityError::InternalError("denom not supported".to_string()))?;

let royalty_entry = fetch_royalty_entry(
&deps.querier,
let royalty_payment_response = deps.querier.query_wasm_smart::<RoyaltyPaymentResponse>(
&global_config.royalty_registry,
collection,
Some(infinity_global),
&RoyaltyRegistryQueryMsg::RoyaltyPayment {
collection: collection.to_string(),
protocol: Some(infinity_global.to_string()),
},
)?;

let royalty_entry = if let Some(royalty_protocol) = royalty_payment_response.royalty_protocol {
Some(royalty_protocol.royalty_entry)
} else if let Some(royalty_default) = royalty_payment_response.royalty_default {
Some(RoyaltyEntry {
recipient: royalty_default.royalty_entry.recipient,
share: global_config.default_royalty_fee_percent,
updated: None,
})
} else {
None
};

Ok(PayoutContext {
global_config,
royalty_entry,
Expand Down
9 changes: 6 additions & 3 deletions unit-tests/src/infinity_global_tests/message_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ fn try_infinity_global_init() {
infinity_pair_code_id: 1u64,
pair_creation_fee: coin(1_000_000u128, NATIVE_DENOM),
fair_burn_fee_percent: Decimal::percent(1u64),
max_royalty_fee_percent: Decimal::percent(10u64),
default_royalty_fee_percent: Decimal::percent(10u64),
max_royalty_fee_percent: Decimal::percent(15u64),
max_swap_fee_percent: Decimal::percent(10u64),
};

Expand Down Expand Up @@ -96,7 +97,8 @@ fn try_infinity_global_update_config() {
infinity_pair_code_id: 1u64,
pair_creation_fee: coin(1_000_000u128, NATIVE_DENOM),
fair_burn_fee_percent: Decimal::percent(1u64),
max_royalty_fee_percent: Decimal::percent(10u64),
default_royalty_fee_percent: Decimal::percent(10u64),
max_royalty_fee_percent: Decimal::percent(15u64),
max_swap_fee_percent: Decimal::percent(10u64),
};

Expand Down Expand Up @@ -193,7 +195,8 @@ fn try_infinity_global_add_remove_min_prices() {
infinity_pair_code_id: 1u64,
pair_creation_fee: coin(1_000_000u128, NATIVE_DENOM),
fair_burn_fee_percent: Decimal::percent(1u64),
max_royalty_fee_percent: Decimal::percent(10u64),
default_royalty_fee_percent: Decimal::percent(10u64),
max_royalty_fee_percent: Decimal::percent(15u64),
max_swap_fee_percent: Decimal::percent(10u64),
};

Expand Down
10 changes: 5 additions & 5 deletions unit-tests/src/infinity_pair_tests/pair_quote_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ fn try_generate_quotes_token_linear() {
while spot_price <= remaining_amount && spot_price >= delta {
let quote = spot_price
- spot_price.mul_ceil(global_config.fair_burn_fee_percent)
- spot_price.mul_ceil(global_config.max_royalty_fee_percent);
- spot_price.mul_ceil(global_config.default_royalty_fee_percent);
expected_quotes.push(quote);
remaining_amount -= spot_price;
spot_price -= delta;
Expand Down Expand Up @@ -161,7 +161,7 @@ fn try_generate_quotes_token_exponential() {
while spot_price <= remaining_amount {
let quote = spot_price
- spot_price.mul_ceil(global_config.fair_burn_fee_percent)
- spot_price.mul_ceil(global_config.max_royalty_fee_percent);
- spot_price.mul_ceil(global_config.default_royalty_fee_percent);
expected_quotes.push(quote);
remaining_amount -= spot_price;
spot_price = spot_price.checked_div_floor(Decimal::one() + delta).unwrap();
Expand Down Expand Up @@ -389,7 +389,7 @@ fn try_generate_quotes_trade_linear() {
while spot_price <= remaining_amount && spot_price >= delta {
let quote = spot_price
- spot_price.mul_ceil(global_config.fair_burn_fee_percent)
- spot_price.mul_ceil(global_config.max_royalty_fee_percent)
- spot_price.mul_ceil(global_config.default_royalty_fee_percent)
- spot_price.mul_ceil(swap_fee_percent);
expected_quotes.push(quote);
remaining_amount -= spot_price;
Expand Down Expand Up @@ -499,7 +499,7 @@ fn try_generate_quotes_trade_exponential() {
while spot_price <= remaining_amount {
let quote = spot_price
- spot_price.mul_ceil(global_config.fair_burn_fee_percent)
- spot_price.mul_ceil(global_config.max_royalty_fee_percent)
- spot_price.mul_ceil(global_config.default_royalty_fee_percent)
- spot_price.mul_ceil(swap_fee_percent);
expected_quotes.push(quote);
remaining_amount -= spot_price;
Expand Down Expand Up @@ -608,7 +608,7 @@ fn try_generate_quotes_trade_cp() {
while counter < limit {
let quote = spot_price
- spot_price.mul_ceil(global_config.fair_burn_fee_percent)
- spot_price.mul_ceil(global_config.max_royalty_fee_percent)
- spot_price.mul_ceil(global_config.default_royalty_fee_percent)
- spot_price.mul_ceil(swap_fee_percent);
expected_quotes.push(quote);
remaining_amount -= spot_price;
Expand Down
3 changes: 2 additions & 1 deletion unit-tests/src/setup/setup_infinity_contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ pub fn setup_infinity_global(
infinity_pair_code_id,
pair_creation_fee: coin(1_000_000, "ustars"),
fair_burn_fee_percent: Decimal::percent(1),
max_royalty_fee_percent: Decimal::percent(5),
default_royalty_fee_percent: Decimal::percent(5),
max_royalty_fee_percent: Decimal::percent(10),
max_swap_fee_percent: Decimal::percent(5),
},
min_prices: vec![coin(10u128, NATIVE_DENOM), coin(10u128, UOSMO)],
Expand Down

0 comments on commit 7d7594b

Please sign in to comment.