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/spread assertion #222

Merged
merged 4 commits into from
Oct 20, 2023
Merged

Fix/spread assertion #222

merged 4 commits into from
Oct 20, 2023

Conversation

kerber0x
Copy link
Contributor

@kerber0x kerber0x commented Oct 20, 2023

Description and Motivation

This PR fixes the spread assertion miscalculation when interacting with tokens with different decimals. This is in preparation to the upcoming injective migration.

Additionally, it adds the max_spread parameter to 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.

@codecov
Copy link

codecov bot commented Oct 20, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (0dfcd12) 94.50% compared to head (5e57ffb) 94.50%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #222   +/-   ##
=======================================
  Coverage   94.50%   94.50%           
=======================================
  Files         217      218    +1     
  Lines       24822    24750   -72     
=======================================
- Hits        23457    23389   -68     
+ Misses       1365     1361    -4     
Files Coverage Δ
...tracts/liquidity_hub/fee_collector/src/commands.rs 100.00% <100.00%> (ø)
..._hub/fee_collector/src/tests/common_integration.rs 100.00% <100.00%> (ø)
...quidity_hub/fee_collector/src/tests/integration.rs 99.90% <100.00%> (+<0.01%) ⬆️
..._hub/pool-network/stableswap_3pool/src/commands.rs 90.90% <100.00%> (+0.90%) ⬆️
...ity_hub/pool-network/stableswap_3pool/src/error.rs 0.00% <ø> (ø)
...y_hub/pool-network/stableswap_3pool/src/helpers.rs 99.11% <ø> (+0.47%) ⬆️
...pool-network/stableswap_3pool/src/tests/testing.rs 94.52% <100.00%> (-0.53%) ⬇️
...ty_hub/pool-network/terraswap_pair/src/commands.rs 99.63% <100.00%> (+<0.01%) ⬆️
...idity_hub/pool-network/terraswap_pair/src/error.rs 0.00% <ø> (ø)
...ity_hub/pool-network/terraswap_pair/src/helpers.rs 84.69% <ø> (-2.04%) ⬇️
... and 8 more

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

@kerber0x kerber0x force-pushed the fix/spread-assertion branch from 61bd61e to b371f74 Compare October 20, 2023 09:38
/// If `belief_price` and `max_spread` both are given,
/// we compute new spread else we just use terraswap
/// spread to check `max_spread`
pub fn assert_max_spread(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved to packages/white-whale/src/pool_network/swap.rs since this code is shared with the pair contract as well.

@@ -74,11 +74,13 @@ pub enum ExecuteMsg {
operations: Vec<SwapOperation>,
minimum_receive: Option<Uint128>,
to: Option<String>,
max_spread: Option<Decimal>,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added max_spread to router messages

@kerber0x kerber0x force-pushed the fix/spread-assertion branch from b371f74 to a820252 Compare October 20, 2023 10:11
offer_asset.clone(),
return_asset.clone(),
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.

fees should be accounted for when calculating spread in the return amount, otherwise the max_spread input by the user is gonna be off

) -> Result<(), ContractError> {
let (offer_amount, return_amount, spread_amount): (Uint256, Uint256, Uint256) =
match offer_decimal.cmp(&return_decimal) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

remove all the decimal things as it's not needed

@@ -289,6 +289,7 @@ pub fn aggregate_fees(
operations,
minimum_receive: None,
to: None,
max_spread: Some(Decimal::percent(50u64)),
Copy link
Contributor Author

@kerber0x kerber0x Oct 20, 2023

Choose a reason for hiding this comment

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

Add the max_spread possible (50%) when doing the fees aggregation to avoid max spread assertions

@kerber0x kerber0x force-pushed the fix/spread-assertion branch from a820252 to 50b8c5d Compare October 20, 2023 10:23
0xFable
0xFable previously approved these changes Oct 20, 2023
Copy link
Contributor

@0xFable 0xFable left a comment

Choose a reason for hiding this comment

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

Changes LGTM 🚀

@kerber0x kerber0x force-pushed the fix/spread-assertion branch from 035bb05 to 5e57ffb Compare October 20, 2023 11:21
@kerber0x kerber0x merged commit 054d320 into main Oct 20, 2023
@kerber0x kerber0x deleted the fix/spread-assertion branch October 20, 2023 12:36
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.

2 participants