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: Remove balance check from EstimateSwap #2764

Closed
wants to merge 15 commits into from

Conversation

mattverse
Copy link
Member

Closes: #2337

What is the purpose of the change

EstimateSwap currently checks the balance of the query sender, not because it actually moves the assets on an actual swap, but beacuse it uses the same API with the actual multi swaps that happen.

This PR separates out the API needed for the estimation so that it does not check balance of the query sender.

(Special thanks to @vuong177 the original author of this PR!)

Brief Changelog

  • Remove balance check from EstimateSwap

Testing and Verifying

This change added tests.

Documentation and Release Note

  • Does this pull request introduce a new feature or user-facing behavior changes? yes
  • Is a relevant changelog entry added to the Unreleased section in CHANGELOG.mxd? yes
  • How is the feature or change documented? (not applicable / specification (x/<module>/spec/) / Osmosis docs repo / not documented)

@mattverse mattverse requested a review from a team September 16, 2022 04:32
@github-actions github-actions bot added C:CLI C:docs Improvements or additions to documentation C:x/gamm Changes, features and bugs related to the gamm module. labels Sep 16, 2022
Copy link
Member

@ValarDragon ValarDragon left a comment

Choose a reason for hiding this comment

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

Reviewed all of the wasmbinding and proto changes, looks great to me! Reviewing keeper logic now

@mattverse mattverse added the A:backport/v12.x backport patches to v12.x branch label Sep 20, 2022
@ValarDragon
Copy link
Member

(Had a call to rename the internal estimate methods to better indicate that they can really change state, and move cacheCtx from query into the go API for public Estimate methods

wasmbinding/queries.go Outdated Show resolved Hide resolved
x/gamm/keeper/grpc_query_test.go Show resolved Hide resolved
x/gamm/keeper/estimate_swap.go Outdated Show resolved Hide resolved
x/gamm/keeper/swap.go Outdated Show resolved Hide resolved
x/gamm/keeper/swap.go Outdated Show resolved Hide resolved
x/gamm/keeper/swap.go Outdated Show resolved Hide resolved
x/gamm/keeper/swap.go Outdated Show resolved Hide resolved
x/gamm/keeper/swap.go Outdated Show resolved Hide resolved
x/gamm/keeper/swap.go Outdated Show resolved Hide resolved
@p0mvn p0mvn removed this from the V12 Blockers milestone Sep 21, 2022
@p0mvn p0mvn removed the A:backport/v12.x backport patches to v12.x branch label Sep 21, 2022
@mattverse mattverse added this to the V13 milestone Sep 22, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Oct 7, 2022

This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. Thank you!

@github-actions github-actions bot added the Stale label Oct 7, 2022
@github-actions github-actions bot closed this Oct 14, 2022
@ValarDragon ValarDragon reopened this Oct 26, 2022
@github-actions github-actions bot removed the C:docs Improvements or additions to documentation label Oct 26, 2022
@mattverse mattverse added the V:state/breaking State machine breaking PR label Nov 14, 2022
Copy link
Member

@czarcas7ic czarcas7ic left a comment

Choose a reason for hiding this comment

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

Left some comments, main thing is changing the multi-hop logic to match the new design here #3352

Also, unclear what is going on with the proto gen CI check

wasmbinding/message_plugin.go Show resolved Hide resolved
if swap == nil {
return nil, wasmvmtypes.InvalidRequest{Err: "gamm perform swap null swap"}
}
if swap.Amount.ExactIn != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we double check swap.Amount.ExactIn != nil && swap.Amount.ExactOut == nil here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Why do you think that's the case? AFAIU, i think swap.Amount.ExactIn != nil && swap.Amount.ExactOut == nil can be a possible scenario, for example, when a pool is 1:1 ratio(10 uosmo, 10 uatom), you could be expecting 1 in 1out or similar

Copy link
Member

@czarcas7ic czarcas7ic Nov 15, 2022

Choose a reason for hiding this comment

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

Right, not only CAN it be a possible scenario, it should be the only scenario for the one sided argument. What I am trying to prevent here is if someone provides a SwapMsg with both a swap.Amount.ExactIn and swap.Amount.ExactOut, with this current code instead of erroring they would go through the first for loop. EstimatePerformSwap should only return a valid response if one side is given, not both sides

Copy link
Member

Choose a reason for hiding this comment

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

AFAIU, we should never call an estimate method with both the in and the out. We either give it the in to calculate the out or we give it the out to calculate the in

Copy link
Member

Choose a reason for hiding this comment

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

I still feel this is the case

x/gamm/keeper/estimate_swap.go Outdated Show resolved Hide resolved
x/gamm/keeper/estimate_swap.go Outdated Show resolved Hide resolved
x/gamm/keeper/estimate_swap.go Outdated Show resolved Hide resolved
x/gamm/keeper/estimate_swap.go Outdated Show resolved Hide resolved
x/gamm/keeper/estimate_swap.go Outdated Show resolved Hide resolved
x/gamm/keeper/estimate_swap.go Outdated Show resolved Hide resolved
x/gamm/keeper/estimate_swap_test.go Outdated Show resolved Hide resolved
@czarcas7ic
Copy link
Member

Wait, but wouldn't it be as simple as adding a "useCacheCtx" boolean here

func (k Keeper) MultihopSwapExactAmountIn(
ctx sdk.Context,
sender sdk.AccAddress,
routes []types.SwapAmountInRoute,
tokenIn sdk.Coin,
tokenOutMinAmount sdk.Int,
) (tokenOutAmount sdk.Int, err error) {
and then we could get rid of the entire estimate_swap.go file?

@github-actions github-actions bot added C:app-wiring Changes to the app folder C:x/txfees labels Nov 16, 2022
@mattverse
Copy link
Member Author

@czarcas7ic I actaully think that's a great idea. Removed the whole file of estimate swap in my last commit and changed the existing swap methods to have a boolean filed for the estimate swaps.

I think this requires detailed, in-depth review as it touches the core swap logic

@czarcas7ic
Copy link
Member

@mattverse will review in depth tomorrow!

@p0mvn
Copy link
Member

p0mvn commented Nov 17, 2022

Is this v13 blocking?

@p0mvn
Copy link
Member

p0mvn commented Nov 17, 2022

NVM, I see that we went with the code duplication approach for safety here: #3424

@p0mvn p0mvn removed this from the V13 milestone Nov 17, 2022
@ValarDragon
Copy link
Member

@mattverse should we close this PR, and re-PR with elements you want added in still?

@ValarDragon
Copy link
Member

Closing per last comment

@ValarDragon ValarDragon closed this Dec 2, 2022
@czarcas7ic czarcas7ic deleted the mattverse/estimate-swap branch August 7, 2023 23:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:app-wiring Changes to the app folder C:CLI C:x/gamm Changes, features and bugs related to the gamm module. C:x/txfees V:state/breaking State machine breaking PR
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Change EstimateSwap to not require assets
4 participants