Skip to content

Commit

Permalink
Merge branch 'release/v2_contracts' into feat/integration-tests-crate
Browse files Browse the repository at this point in the history
  • Loading branch information
kerber0x authored Sep 2, 2024
2 parents bf28bfb + 0611928 commit d2461cb
Show file tree
Hide file tree
Showing 28 changed files with 589 additions and 72 deletions.
18 changes: 18 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ prost = { version = "0.11.9", default-features = false, features = [
"prost-derive",
] }
test-case = { version = "3.3.1" }
cw-migrate-error-derive = { version = "0.1.0" }

# contracts
whale-lair = { path = "./contracts/liquidity_hub/whale_lair" }
Expand Down
1 change: 1 addition & 0 deletions contracts/liquidity_hub/bonding-manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ white-whale-std.workspace = true
cw-utils.workspace = true
pool-manager.workspace = true
cw-ownable.workspace = true
cw-migrate-error-derive.workspace = true

[dev-dependencies]
cw-multi-test.workspace = true
Expand Down
9 changes: 2 additions & 7 deletions contracts/liquidity_hub/bonding-manager/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use cosmwasm_std::{
CheckedMultiplyFractionError, DivideByZeroError, OverflowError, StdError, Uint128,
};
use cw_migrate_error_derive::cw_migrate_invalid_version_error;
use cw_ownable::OwnershipError;
use cw_utils::PaymentError;
use semver::Version;
use thiserror::Error;

#[cw_migrate_invalid_version_error]
#[derive(Error, Debug, PartialEq)]
pub enum ContractError {
#[error("{0}")]
Expand Down Expand Up @@ -55,12 +56,6 @@ pub enum ContractError {
#[error("Nothing to withdraw")]
NothingToWithdraw,

#[error("Attempt to migrate to version {new_version}, but contract is on a higher version {current_version}")]
MigrateInvalidVersion {
new_version: Version,
current_version: Version,
},

#[error("There are unclaimed rewards available. Claim them before attempting to bond/unbond")]
UnclaimedRewards,

Expand Down
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
1 change: 1 addition & 0 deletions contracts/liquidity_hub/epoch-manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ thiserror.workspace = true
white-whale-std.workspace = true
cw-controllers.workspace = true
cw-utils.workspace = true
cw-migrate-error-derive.workspace = true
9 changes: 2 additions & 7 deletions contracts/liquidity_hub/epoch-manager/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use cosmwasm_std::StdError;
use cw_controllers::{AdminError, HookError};
use cw_migrate_error_derive::cw_migrate_invalid_version_error;
use cw_utils::PaymentError;
use semver::Version;
use thiserror::Error;

#[cw_migrate_invalid_version_error]
#[derive(Error, Debug)]
pub enum ContractError {
#[error("{0}")]
Expand All @@ -24,12 +25,6 @@ pub enum ContractError {
#[error("Semver parsing error: {0}")]
SemVer(String),

#[error("Attempt to migrate to version {new_version}, but contract is on a higher version {current_version}")]
MigrateInvalidVersion {
new_version: Version,
current_version: Version,
},

#[error("The current epoch epoch has not expired yet.")]
CurrentEpochNotExpired,

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
1 change: 1 addition & 0 deletions contracts/liquidity_hub/incentive-manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ thiserror.workspace = true
white-whale-std.workspace = true
cw-utils.workspace = true
cw-ownable.workspace = true
cw-migrate-error-derive.workspace = true

[dev-dependencies]
cw-multi-test.workspace = true
Expand Down
9 changes: 2 additions & 7 deletions contracts/liquidity_hub/incentive-manager/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ use cosmwasm_std::{
CheckedFromRatioError, CheckedMultiplyFractionError, ConversionOverflowError,
DivideByZeroError, OverflowError, StdError, Uint128,
};
use cw_migrate_error_derive::cw_migrate_invalid_version_error;
use cw_ownable::OwnershipError;
use cw_utils::PaymentError;
use semver::Version;
use thiserror::Error;

use white_whale_std::incentive_manager::EpochId;

#[cw_migrate_invalid_version_error]
#[derive(Error, Debug)]
pub enum ContractError {
#[error("{0}")]
Expand Down Expand Up @@ -148,12 +149,6 @@ pub enum ContractError {

#[error("There's no snapshot of the LP weight in the contract for the epoch {epoch_id}")]
LpWeightNotFound { epoch_id: EpochId },

#[error("Attempt to migrate to version {new_version}, but contract is on a higher version {current_version}")]
MigrateInvalidVersion {
new_version: Version,
current_version: Version,
},
}

impl From<semver::Error> for ContractError {
Expand Down
3 changes: 2 additions & 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 All @@ -48,6 +48,7 @@ cw-utils.workspace = true
cw-ownable.workspace = true
sha2.workspace = true
semver.workspace = true
cw-migrate-error-derive.workspace = true

[dev-dependencies]
cw-multi-test.workspace = true
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
17 changes: 10 additions & 7 deletions contracts/liquidity_hub/pool-manager/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ use cosmwasm_std::{
ConversionOverflowError, DivideByZeroError, Instantiate2AddressError, OverflowError, StdError,
Uint128,
};
use cw_migrate_error_derive::cw_migrate_invalid_version_error;
use cw_ownable::OwnershipError;
use cw_utils::PaymentError;
use semver::Version;
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 {
// Handle all normal errors from the StdError
Expand Down Expand Up @@ -38,12 +42,6 @@ pub enum ContractError {
#[error("The provided assets are both the same")]
SameAsset,

#[error("Attempt to migrate to version {new_version}, but contract is on a higher version {current_version}")]
MigrateInvalidVersion {
new_version: Version,
current_version: Version,
},

#[error(
"Assertion failed; minimum receive amount: {minimum_receive}, swap amount: {swap_amount}"
)]
Expand Down Expand Up @@ -162,8 +160,13 @@ pub enum ContractError {

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

#[error("The pool has no assets")]
PoolHasNoAssets,

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

impl From<semver::Error> for ContractError {
Expand Down
Loading

0 comments on commit d2461cb

Please sign in to comment.