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

[x/gamm][stableswap]: Create scaling/descaling functions for token inputs/outputs #2902

Closed
Tracked by #1451
AlpinYukseloglu opened this issue Sep 29, 2022 · 0 comments · Fixed by #2904
Closed
Tracked by #1451
Labels
C:stableswap C:x/gamm Changes, features and bugs related to the gamm module.

Comments

@AlpinYukseloglu
Copy link
Contributor

Background

We currently have functions to scale/descale pool reserves, but not ones to scale/descale inputs. This leads to odd behavior where unscaled inputs are passed into scaled pool reserves.

Suggested Design

  • Apply same logic used in pool reserve scaling but modified to accommodate specific token inputs and outputs (notes/ideas: return slice with length of input []DecCoin, loop through pool liquidity and add scaled output to return slice if denom exists in input array)

Acceptance Criteria

  • All existing and new tests pass
@AlpinYukseloglu AlpinYukseloglu added C:x/gamm Changes, features and bugs related to the gamm module. C:stableswap labels Sep 29, 2022
@mergify mergify bot closed this as completed in #2904 Sep 30, 2022
mergify bot pushed a commit that referenced this issue Sep 30, 2022
…puts/outputs (#2904)

Closes: #2902

## What is the purpose of the change

This PR adds a scaling function for token inputs. Depending on what level we want to handle rounding at (at the scaling function level vs. at the `SwapExactAmountIn` level), we can either use this function for outputs as well or create a second one that handles outputs with different rounding.

I personally think having one function with rounding handled at a higher level of abstraction is cleaner because it has less repeat code, but I can see the security argument for having multiple scaling functions that round differently for each specific use (cc: @ValarDragon)

## Brief Changelog

- Add `scaledInput` function and tests

## Testing and Verifying

- The function added in this PR is tested in `pool_test.go` under `TestScaledInput`

## Documentation and Release Note

  - Does this pull request introduce a new feature or user-facing behavior changes? (no)
  - Is a relevant changelog entry added to the `Unreleased` section in `CHANGELOG.md`? (no)
  - How is the feature or change documented? (not documented)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:stableswap C:x/gamm Changes, features and bugs related to the gamm module.
Projects
Archived in project
1 participant