diff --git a/Cargo.lock b/Cargo.lock index 833e8c71e..c98e8d4e6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -541,7 +541,7 @@ dependencies = [ "semver", "serde", "thiserror", - "white-whale-std 1.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "white-whale-std", ] [[package]] @@ -587,12 +587,12 @@ dependencies = [ "schemars", "serde", "thiserror", - "white-whale-std 1.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "white-whale-std", ] [[package]] name = "fee_collector" -version = "1.1.7" +version = "1.1.8" dependencies = [ "cosmwasm-schema", "cosmwasm-std", @@ -614,7 +614,7 @@ dependencies = [ "vault", "vault_factory", "whale-lair", - "white-whale-std 1.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "white-whale-std", ] [[package]] @@ -631,7 +631,7 @@ dependencies = [ "semver", "serde", "thiserror", - "white-whale-std 1.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "white-whale-std", ] [[package]] @@ -685,7 +685,7 @@ dependencies = [ "serde", "terraswap-pair", "thiserror", - "white-whale-std 1.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "white-whale-std", ] [[package]] @@ -787,7 +787,7 @@ dependencies = [ "serde", "terraswap-token", "thiserror", - "white-whale-std 1.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "white-whale-std", ] [[package]] @@ -804,7 +804,7 @@ dependencies = [ "semver", "serde", "thiserror", - "white-whale-std 1.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "white-whale-std", ] [[package]] @@ -1515,7 +1515,7 @@ dependencies = [ [[package]] name = "stableswap-3pool" -version = "1.2.5" +version = "1.2.6" dependencies = [ "cosmwasm-schema", "cosmwasm-std", @@ -1532,7 +1532,7 @@ dependencies = [ "serde", "stable-swap-sim", "thiserror", - "white-whale-std 1.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "white-whale-std", ] [[package]] @@ -1590,7 +1590,7 @@ dependencies = [ [[package]] name = "terraswap-factory" -version = "1.2.4" +version = "1.2.5" dependencies = [ "cosmwasm-schema", "cosmwasm-std", @@ -1602,12 +1602,12 @@ dependencies = [ "semver", "serde", "thiserror", - "white-whale-std 1.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "white-whale-std", ] [[package]] name = "terraswap-pair" -version = "1.3.7" +version = "1.3.8" dependencies = [ "anybuf", "cosmwasm-schema", @@ -1623,12 +1623,12 @@ dependencies = [ "semver", "serde", "thiserror", - "white-whale-std 1.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "white-whale-std", ] [[package]] name = "terraswap-router" -version = "1.1.2" +version = "1.1.3" dependencies = [ "cosmwasm-schema", "cosmwasm-std", @@ -1640,7 +1640,7 @@ dependencies = [ "semver", "serde", "thiserror", - "white-whale-std 1.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "white-whale-std", ] [[package]] @@ -1657,7 +1657,7 @@ dependencies = [ "schemars", "serde", "thiserror", - "white-whale-std 1.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "white-whale-std", ] [[package]] @@ -1733,7 +1733,7 @@ dependencies = [ "semver", "serde", "thiserror", - "white-whale-std 1.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "white-whale-std", ] [[package]] @@ -1754,7 +1754,7 @@ dependencies = [ "serde", "thiserror", "vault", - "white-whale-std 1.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "white-whale-std", ] [[package]] @@ -1776,7 +1776,7 @@ dependencies = [ "thiserror", "vault", "vault_factory", - "white-whale-std 1.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "white-whale-std", ] [[package]] @@ -1820,32 +1820,13 @@ dependencies = [ "semver", "serde", "thiserror", - "white-whale-std 1.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "white-whale-std", "white-whale-testing", ] [[package]] name = "white-whale-std" -version = "1.1.5" -dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", - "cw2", - "cw20", - "osmosis-std-derive", - "prost 0.11.9", - "prost-types", - "protobuf", - "schemars", - "serde", - "uint", -] - -[[package]] -name = "white-whale-std" -version = "1.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3015d5c0c46b6e1cf2fb02c036e8d1481174508a32572d62e6f240a4dec4077" +version = "1.1.8" dependencies = [ "cosmwasm-schema", "cosmwasm-std", @@ -1872,7 +1853,7 @@ dependencies = [ "schemars", "serde", "whale-lair", - "white-whale-std 1.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "white-whale-std", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 4e2cc7ca1..60acd1f63 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,8 +39,8 @@ prost = { version = "0.11.9", default-features = false, features = [ ] } prost-types = { version = "0.11.9", default-features = false } # for local development -#white-whale-std = { path = "packages/white-whale-std" } -white-whale-std = { version = "1.1.5" } +white-whale-std = { path = "packages/white-whale-std" } +#white-whale-std = { version = "1.1.5" } white-whale-testing = { path = "./packages/white-whale-testing" } cw-multi-test = { version = "0.16.5" } uint = "0.9.5" diff --git a/contracts/liquidity_hub/fee_collector/Cargo.toml b/contracts/liquidity_hub/fee_collector/Cargo.toml index fec63ae0c..929b389c5 100644 --- a/contracts/liquidity_hub/fee_collector/Cargo.toml +++ b/contracts/liquidity_hub/fee_collector/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "fee_collector" -version = "1.1.7" +version = "1.1.8" authors = ["Kerber0x "] edition.workspace = true description = "Contract to collect the fees accrued by the pools and vaults in the liquidity hub" diff --git a/contracts/liquidity_hub/fee_collector/src/commands.rs b/contracts/liquidity_hub/fee_collector/src/commands.rs index 0a1dd632c..945f17001 100644 --- a/contracts/liquidity_hub/fee_collector/src/commands.rs +++ b/contracts/liquidity_hub/fee_collector/src/commands.rs @@ -231,7 +231,7 @@ pub fn aggregate_fees( })?, }))?; - if balance_response.balance > Uint128::zero() { + if balance_response.balance > MINIMUM_AGGREGABLE_BALANCE { // if balance is greater than zero, some swap will occur // Increase the allowance for the cw20 token so the router can perform the swap aggregate_fees_messages.push(CosmosMsg::Wasm(WasmMsg::Execute { @@ -284,6 +284,7 @@ pub fn aggregate_fees( msg: to_json_binary(&router::QueryMsg::SimulateSwapOperations { offer_amount: balance, operations: operations.clone(), + max_spread: Some(Decimal::percent(50u64)), })?, })); @@ -365,7 +366,7 @@ pub fn forward_fees( factory_addr: config.vault_factory.to_string(), factory_type: FactoryType::Vault { start_after: None, - limit: Some(30u32), + limit: Some(60u32), }, }, })?, @@ -384,7 +385,7 @@ pub fn forward_fees( factory_addr: config.pool_factory.to_string(), factory_type: FactoryType::Pool { start_after: None, - limit: Some(30u32), + limit: Some(60u32), }, }, })?, @@ -404,7 +405,7 @@ pub fn forward_fees( factory_addr: config.vault_factory.to_string(), factory_type: FactoryType::Vault { start_after: None, - limit: Some(30u32), + limit: Some(60u32), }, }, })?, @@ -423,7 +424,7 @@ pub fn forward_fees( factory_addr: config.pool_factory.to_string(), factory_type: FactoryType::Pool { start_after: None, - limit: Some(30u32), + limit: Some(60u32), }, }, })?, diff --git a/contracts/liquidity_hub/fee_collector/src/tests/integration.rs b/contracts/liquidity_hub/fee_collector/src/tests/integration.rs index 58f0f0b09..af6170dbe 100644 --- a/contracts/liquidity_hub/fee_collector/src/tests/integration.rs +++ b/contracts/liquidity_hub/fee_collector/src/tests/integration.rs @@ -814,7 +814,7 @@ fn collect_cw20_fees_for_specific_contracts_successfully() { amount: Uint128::new(200_000u128), msg: to_json_binary(&pool_network::pair::Cw20HookMsg::Swap { belief_price: None, - max_spread: Some(Decimal::percent(30u64)), + max_spread: Some(Decimal::percent(50u64)), to: None, }) .unwrap(), @@ -3311,7 +3311,7 @@ fn collect_and_distribute_fees_successfully() { amount: Uint128::new(200_000u128), }, belief_price: None, - max_spread: Some(Decimal::percent(30u64)), + max_spread: Some(Decimal::percent(50u64)), to: None, }, &[Coin { @@ -4737,7 +4737,7 @@ fn collect_and_distribute_fees_with_expiring_epoch_successfully() { amount: Uint128::new(200_000u128), }, belief_price: None, - max_spread: Some(Decimal::percent(30u64)), + max_spread: Some(Decimal::percent(50u64)), to: None, }, &[Coin { diff --git a/contracts/liquidity_hub/pool-network/stableswap_3pool/Cargo.toml b/contracts/liquidity_hub/pool-network/stableswap_3pool/Cargo.toml index 158aebf54..d58005836 100644 --- a/contracts/liquidity_hub/pool-network/stableswap_3pool/Cargo.toml +++ b/contracts/liquidity_hub/pool-network/stableswap_3pool/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "stableswap-3pool" -version = "1.2.5" +version = "1.2.6" authors = ["Adam J. Weigold "] edition.workspace = true license.workspace = true diff --git a/contracts/liquidity_hub/pool-network/stableswap_3pool/src/commands.rs b/contracts/liquidity_hub/pool-network/stableswap_3pool/src/commands.rs index f4218fcea..133d245fd 100644 --- a/contracts/liquidity_hub/pool-network/stableswap_3pool/src/commands.rs +++ b/contracts/liquidity_hub/pool-network/stableswap_3pool/src/commands.rs @@ -455,17 +455,12 @@ pub fn swap( amount: swap_computation.return_amount, }; - let fees = swap_computation - .swap_fee_amount - .checked_add(swap_computation.protocol_fee_amount)? - .checked_add(swap_computation.burn_fee_amount)?; - // check max spread limit if exist swap::assert_max_spread( belief_price, max_spread, offer_asset.amount, - return_asset.amount.checked_add(fees)?, + return_asset.amount, swap_computation.spread_amount, )?; diff --git a/contracts/liquidity_hub/pool-network/terraswap_factory/Cargo.toml b/contracts/liquidity_hub/pool-network/terraswap_factory/Cargo.toml index cfca4f570..acdad661d 100644 --- a/contracts/liquidity_hub/pool-network/terraswap_factory/Cargo.toml +++ b/contracts/liquidity_hub/pool-network/terraswap_factory/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "terraswap-factory" -version = "1.2.4" +version = "1.2.5" authors = [ "Terraform Labs, PTE.", "DELIGHT LABS", diff --git a/contracts/liquidity_hub/pool-network/terraswap_factory/src/state.rs b/contracts/liquidity_hub/pool-network/terraswap_factory/src/state.rs index e7872f46b..bc3f2eeeb 100644 --- a/contracts/liquidity_hub/pool-network/terraswap_factory/src/state.rs +++ b/contracts/liquidity_hub/pool-network/terraswap_factory/src/state.rs @@ -57,7 +57,7 @@ pub fn trio_key(asset_infos: &[AssetInfoRaw; 3]) -> Vec { } // settings for pagination -const MAX_LIMIT: u32 = 30; +const MAX_LIMIT: u32 = 60; const DEFAULT_LIMIT: u32 = 10; pub fn read_pairs( storage: &dyn Storage, diff --git a/contracts/liquidity_hub/pool-network/terraswap_pair/Cargo.toml b/contracts/liquidity_hub/pool-network/terraswap_pair/Cargo.toml index c44756d82..956189f5a 100644 --- a/contracts/liquidity_hub/pool-network/terraswap_pair/Cargo.toml +++ b/contracts/liquidity_hub/pool-network/terraswap_pair/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "terraswap-pair" -version = "1.3.7" +version = "1.3.8" authors = [ "Terraform Labs, PTE.", "DELIGHT LABS", diff --git a/contracts/liquidity_hub/pool-network/terraswap_pair/src/commands.rs b/contracts/liquidity_hub/pool-network/terraswap_pair/src/commands.rs index 9e922544b..841d8ea37 100644 --- a/contracts/liquidity_hub/pool-network/terraswap_pair/src/commands.rs +++ b/contracts/liquidity_hub/pool-network/terraswap_pair/src/commands.rs @@ -411,29 +411,12 @@ pub fn swap( amount: swap_computation.return_amount, }; - let fees = { - let base_fees = swap_computation - .swap_fee_amount - .checked_add(swap_computation.protocol_fee_amount)? - .checked_add(swap_computation.burn_fee_amount)?; - - #[cfg(feature = "osmosis")] - { - base_fees.checked_add(swap_computation.osmosis_fee_amount)? - } - - #[cfg(not(feature = "osmosis"))] - { - base_fees - } - }; - // check max spread limit if exist swap::assert_max_spread( belief_price, max_spread, offer_asset.amount, - return_asset.amount.checked_add(fees)?, + return_asset.amount, swap_computation.spread_amount, )?; diff --git a/contracts/liquidity_hub/pool-network/terraswap_router/Cargo.toml b/contracts/liquidity_hub/pool-network/terraswap_router/Cargo.toml index 2226b7229..ef8fb3c1b 100644 --- a/contracts/liquidity_hub/pool-network/terraswap_router/Cargo.toml +++ b/contracts/liquidity_hub/pool-network/terraswap_router/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "terraswap-router" -version = "1.1.2" +version = "1.1.3" authors = [ "Terraform Labs, PTE.", "DELIGHT LABS", diff --git a/contracts/liquidity_hub/pool-network/terraswap_router/src/contract.rs b/contracts/liquidity_hub/pool-network/terraswap_router/src/contract.rs index dff627d18..4e7b2c032 100644 --- a/contracts/liquidity_hub/pool-network/terraswap_router/src/contract.rs +++ b/contracts/liquidity_hub/pool-network/terraswap_router/src/contract.rs @@ -17,6 +17,7 @@ use white_whale_std::pool_network::router::{ ConfigResponse, Cw20HookMsg, ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg, SimulateSwapOperationsResponse, SwapOperation, SwapRoute, SwapRouteResponse, }; +use white_whale_std::pool_network::swap; use crate::error::ContractError; use crate::error::ContractError::MigrateInvalidVersion; @@ -248,6 +249,7 @@ fn add_swap_routes( deps.as_ref(), Uint128::one(), swap_route.clone().swap_operations, + None, ) .map_err(|_| ContractError::InvalidSwapRoute(swap_route.clone()))?; @@ -299,10 +301,12 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> Result Ok(to_json_binary(&simulate_swap_operations( deps, offer_amount, operations, + max_spread, )?)?), QueryMsg::ReverseSimulateSwapOperations { ask_amount, @@ -338,6 +342,7 @@ fn simulate_swap_operations( deps: Deps, offer_amount: Uint128, operations: Vec, + max_spread: Option, ) -> Result { let config: Config = CONFIG.load(deps.storage)?; let terraswap_factory = deps.api.addr_humanize(&config.terraswap_factory)?; @@ -369,6 +374,16 @@ fn simulate_swap_operations( }, )?; + if max_spread.is_some() && res.return_amount > Uint128::zero() { + swap::assert_max_spread( + None, + max_spread, + offer_amount, + res.return_amount, + res.spread_amount, + )?; + } + offer_amount = res.return_amount; } } diff --git a/contracts/liquidity_hub/pool-network/terraswap_router/src/testing/tests.rs b/contracts/liquidity_hub/pool-network/terraswap_router/src/testing/tests.rs index 46e8a6bf2..ea440917b 100644 --- a/contracts/liquidity_hub/pool-network/terraswap_router/src/testing/tests.rs +++ b/contracts/liquidity_hub/pool-network/terraswap_router/src/testing/tests.rs @@ -469,6 +469,7 @@ fn query_buy_with_routes() { let empty_operations_msg = QueryMsg::SimulateSwapOperations { offer_amount: Uint128::from(1000000u128), operations: vec![], + max_spread: None, }; let error = query(deps.as_ref(), mock_env(), empty_operations_msg).unwrap_err(); @@ -498,6 +499,7 @@ fn query_buy_with_routes() { }, }, ], + max_spread: None, }; deps.querier.with_pool_factory( diff --git a/packages/white-whale-std/Cargo.toml b/packages/white-whale-std/Cargo.toml index f716910a3..24b11307c 100644 --- a/packages/white-whale-std/Cargo.toml +++ b/packages/white-whale-std/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "white-whale-std" -version = "1.1.5" +version = "1.1.8" edition.workspace = true authors = [ "Kerber0x ", diff --git a/packages/white-whale-std/src/pool_network/router.rs b/packages/white-whale-std/src/pool_network/router.rs index d71651ee8..71882d47e 100644 --- a/packages/white-whale-std/src/pool_network/router.rs +++ b/packages/white-whale-std/src/pool_network/router.rs @@ -121,6 +121,7 @@ pub enum QueryMsg { SimulateSwapOperations { offer_amount: Uint128, operations: Vec, + max_spread: Option, }, /// Simulates a reverse swap operations, i.e. given the ask asset, how much of the offer asset /// is needed to perform the swap.