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: add max_spread param to router operations simulation #381

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

kerber0x
Copy link
Contributor

@kerber0x kerber0x commented Sep 3, 2024

Description and Motivation

With the previous fix for failing fee aggregation it was introduced a simulation on the aggregation swap. However, the aggregation doesn't perform any spread assertions. This code introduces this into the pool router.

Related Issues


Checklist:

  • I have read Migaloo's contribution guidelines.
  • My pull request has a sound title and description (not something vague like Update index.md)
  • All existing and new tests are passing.
  • I updated/added relevant documentation.
  • The code is formatted properly cargo fmt --all --.
  • Clippy doesn't report any issues cargo clippy -- -D warnings.
  • I have regenerated the schemas if needed cargo schema.

@@ -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)),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add new max_spread in simulation

@@ -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),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

increased limit to 60 items, as there are over 30 pools on terra atm.

// check max spread limit if exist
swap::assert_max_spread(
belief_price,
max_spread,
offer_asset.amount,
return_asset.amount.checked_add(fees)?,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix for bug reported a while ago

Copy link

codecov bot commented Sep 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.84%. Comparing base (a96fecb) to head (3eb627d).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #381      +/-   ##
==========================================
+ Coverage   93.21%   94.84%   +1.63%     
==========================================
  Files         219      214       -5     
  Lines       24868    24770      -98     
==========================================
+ Hits        23180    23493     +313     
+ Misses       1688     1277     -411     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

// check max spread limit if exist
swap::assert_max_spread(
belief_price,
max_spread,
offer_asset.amount,
return_asset.amount.checked_add(fees)?,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

@@ -369,6 +374,16 @@ fn simulate_swap_operations(
},
)?;

if max_spread.is_some() && res.return_amount > Uint128::zero() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if the max_spread is passed and the return_amount is above zero then we can perform the spread assertion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant