Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/osmosis fee 1e 3 #377

Merged
merged 5 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions contracts/liquidity_hub/bonding-manager/src/tests/claim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,23 @@ fn test_claim_successfully() {

let asset_denoms = vec!["uwhale".to_string(), "uusdc".to_string()];

#[cfg(feature = "osmosis")]
let pool_fees = PoolFee {
protocol_fee: Fee {
share: Decimal::from_ratio(1u128, 100u128),
},
swap_fee: Fee {
share: Decimal::from_ratio(1u128, 100u128),
},
burn_fee: Fee {
share: Decimal::zero(),
},
extra_fees: vec![],
osmosis_fee: Fee {
share: Decimal::permille(1),
},
};

#[cfg(not(feature = "osmosis"))]
let pool_fees = PoolFee {
protocol_fee: Fee {
Expand Down Expand Up @@ -895,6 +912,23 @@ fn test_rewards_forwarding() {
extra_fees: vec![],
};

#[cfg(feature = "osmosis")]
let pool_fees = PoolFee {
protocol_fee: Fee {
share: Decimal::from_ratio(1u128, 100u128),
},
swap_fee: Fee {
share: Decimal::from_ratio(1u128, 100u128),
},
burn_fee: Fee {
share: Decimal::zero(),
},
extra_fees: vec![],
osmosis_fee: Fee {
share: Decimal::permille(1),
},
};

suite
.instantiate_default()
.create_pair(
Expand Down
17 changes: 17 additions & 0 deletions contracts/liquidity_hub/bonding-manager/src/tests/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@ fn test_queries() {
extra_fees: vec![],
};

#[cfg(feature = "osmosis")]
let pool_fees = PoolFee {
protocol_fee: Fee {
share: Decimal::from_ratio(1u128, 100u128),
},
swap_fee: Fee {
share: Decimal::from_ratio(1u128, 100u128),
},
burn_fee: Fee {
share: Decimal::zero(),
},
extra_fees: vec![],
osmosis_fee: Fee {
share: Decimal::permille(1),
},
};

suite
.instantiate_default()
.bond(creator.clone(), &coins(1_000u128, "ampWHALE"), |result| {
Expand Down
17 changes: 17 additions & 0 deletions contracts/liquidity_hub/bonding-manager/src/tests/rewards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,23 @@ fn test_fill_rewards_from_pool_manager() {
extra_fees: vec![],
};

#[cfg(feature = "osmosis")]
let pool_fees = PoolFee {
protocol_fee: Fee {
share: Decimal::from_ratio(1u128, 100u128),
},
swap_fee: Fee {
share: Decimal::from_ratio(1u128, 100u128),
},
burn_fee: Fee {
share: Decimal::zero(),
},
extra_fees: vec![],
osmosis_fee: Fee {
share: Decimal::permille(1),
},
};

suite
.instantiate_default()
.fast_forward(90_000)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,23 @@ fn test_unbonding_withdraw() {
extra_fees: vec![],
};

#[cfg(feature = "osmosis")]
let pool_fees = PoolFee {
protocol_fee: Fee {
share: Decimal::from_ratio(1u128, 100u128),
},
swap_fee: Fee {
share: Decimal::from_ratio(1u128, 100u128),
},
burn_fee: Fee {
share: Decimal::zero(),
},
extra_fees: vec![],
osmosis_fee: Fee {
share: Decimal::permille(1),
},
};

suite
.instantiate_default()
.bond(creator.clone(), &coins(1_000u128, "ampWHALE"), |result| {
Expand Down
9 changes: 3 additions & 6 deletions contracts/liquidity_hub/fee_distributor/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,9 @@ pub fn get_current_epoch(deps: Deps) -> StdResult<EpochResponse> {

/// Returns the [Epoch] with the given id.
pub fn get_epoch(deps: Deps, id: Uint64) -> StdResult<EpochResponse> {
let option = EPOCHS.may_load(deps.storage, &id.to_be_bytes())?;

let epoch = match option {
Some(epoch) => epoch,
None => Epoch::default(),
};
let epoch = EPOCHS
.may_load(deps.storage, &id.to_be_bytes())?
.unwrap_or_default();

Ok(EpochResponse { epoch })
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/liquidity_hub/pool-manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ injective = ["white-whale-std/injective"]
token_factory = ["white-whale-std/token_factory"]
osmosis = ["osmosis_token_factory"]
osmosis_token_factory = ["white-whale-std/osmosis_token_factory"]

tarpaulin_include = []
# use library feature to disable all instantiate/execute/query exports
library = []

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
cc 55857276de2241e3d09d36aba47854e0017db66f6c5a61e306b38ad0d3b8aeeb # shrinks to amp_factor = 1, initial_user_token_a_amount = 10000000, initial_user_token_b_amount = 10000000
cc 33456e9a9f11bed69ac5171155ce7a64f73f912fcbfede19046989302d1b2da9 # shrinks to amp_factor = 10, deposit_amount_a = 0, deposit_amount_b = 0, deposit_amount_c = 0, swap_token_a_amount = 0, swap_token_b_amount = 0, swap_token_c_amount = 1, pool_token_supply = 0
cc 75c3b0922c450b034b92dc8c2ea87edff47c90bbede702d84c9fd9c672e2f31f # shrinks to amp_factor = 141, deposit_amount_a = 308442737939502983046195411808336, deposit_amount_b = 0, deposit_amount_c = 0, swap_token_a_amount = 870112623450347049437652954298478, swap_token_b_amount = 501497230776538877048085549853566, swap_token_c_amount = 24063806364666791266594852039507, pool_token_supply = 2
cc 0e8058d82bcea9791825f64915edb7336ff8f46a9e5400f9a035f2602838fb96 # shrinks to amp_factor = 139040, source_token_amount = 2201422791601550300438305308643575, swap_source_amount = 0, swap_destination_amount = 0, unswapped_amount = 0
1 change: 0 additions & 1 deletion contracts/liquidity_hub/pool-manager/sim/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! Simulations of the StableSwap invariant compared to Curve's reference implementation.
#![allow(deprecated)]
#![allow(deprecated)]

use pyo3::prelude::*;
use pyo3::types::PyTuple;
Expand Down
7 changes: 7 additions & 0 deletions contracts/liquidity_hub/pool-manager/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ use cw_utils::PaymentError;
use thiserror::Error;
use white_whale_std::pool_manager::SwapRoute;

#[cfg(feature = "osmosis")]
use cosmwasm_std::Decimal;

#[cw_migrate_invalid_version_error]
#[derive(Error, Debug, PartialEq)]
pub enum ContractError {
Expand Down Expand Up @@ -157,6 +160,10 @@ pub enum ContractError {

#[error("Invalid pool assets length, expected {expected} got {actual}")]
InvalidPoolAssetsLength { expected: usize, actual: usize },

#[cfg(feature = "osmosis")]
#[error("Invalid osmosis fee, expected: {expected} got: {got}")]
InvalidOsmosisFee { expected: Decimal, got: Decimal },
}

impl From<semver::Error> for ContractError {
Expand Down
15 changes: 15 additions & 0 deletions contracts/liquidity_hub/pool-manager/src/manager/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ use cosmwasm_std::{
attr, Attribute, Coin, CosmosMsg, DepsMut, Env, MessageInfo, Response, Uint128,
};

#[cfg(feature = "osmosis")]
use cosmwasm_std::Decimal;

use white_whale_std::fee::PoolFee;

use crate::state::{get_pool_by_identifier, POOL_COUNTER};
Expand All @@ -15,6 +18,9 @@ use white_whale_std::pool_manager::{PoolInfo, PoolType};

pub const MAX_ASSETS_PER_POOL: usize = 4;

#[cfg(feature = "osmosis")]
pub const OSMOSIS_FEE_AMOUNT: Decimal = Decimal::permille(1);

/// Creates a pool with 2, 3, or N assets. The function dynamically handles different numbers of assets,
/// allowing for the creation of pools with varying configurations. The maximum number of assets per pool is defined by
/// the constant `MAX_ASSETS_PER_POOL`.
Expand Down Expand Up @@ -122,6 +128,15 @@ pub fn create_pool(
return Err(ContractError::SameAsset);
}

// ensure that osmosis fee is 0.001
#[cfg(feature = "osmosis")]
if pool_fees.osmosis_fee.share != OSMOSIS_FEE_AMOUNT {
return Err(ContractError::InvalidOsmosisFee {
expected: OSMOSIS_FEE_AMOUNT,
got: pool_fees.osmosis_fee.share,
});
}

// Verify pool fees
pool_fees.is_valid()?;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ pub fn swap(
#[cfg(feature = "osmosis")]
(
"osmosis_fee_amount",
swap_result.osmosis_fee_amount.to_string(),
swap_result.osmosis_fee_asset.amount.to_string(),
),
(
"swap_type",
Expand Down
Loading
Loading