Skip to content

Commit

Permalink
fix: add max_spread param to router operations simulation
Browse files Browse the repository at this point in the history
  • Loading branch information
kerber0x committed Sep 3, 2024
1 parent a96fecb commit 3e52f55
Show file tree
Hide file tree
Showing 16 changed files with 61 additions and 83 deletions.
65 changes: 23 additions & 42 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion contracts/liquidity_hub/fee_collector/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fee_collector"
version = "1.1.7"
version = "1.1.8"
authors = ["Kerber0x <[email protected]>"]
edition.workspace = true
description = "Contract to collect the fees accrued by the pools and vaults in the liquidity hub"
Expand Down
11 changes: 6 additions & 5 deletions contracts/liquidity_hub/fee_collector/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)),
})?,
}));

Expand Down Expand Up @@ -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),
},
},
})?,
Expand All @@ -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),
},
},
})?,
Expand All @@ -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),
},
},
})?,
Expand All @@ -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),
},
},
})?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "stableswap-3pool"
version = "1.2.5"
version = "1.2.6"
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 @@ -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,
)?;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "terraswap-factory"
version = "1.2.4"
version = "1.2.5"
authors = [
"Terraform Labs, PTE.",
"DELIGHT LABS",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub fn trio_key(asset_infos: &[AssetInfoRaw; 3]) -> Vec<u8> {
}

// 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,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "terraswap-pair"
version = "1.3.7"
version = "1.3.8"
authors = [
"Terraform Labs, PTE.",
"DELIGHT LABS",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)?;

Expand Down
Loading

0 comments on commit 3e52f55

Please sign in to comment.