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

"Max Buttons" incorrectly calculate max amounts to Redeem and Unwrap-Weth #117

Merged
merged 2 commits into from
Aug 11, 2020

Conversation

nicholaspai
Copy link
Member

There are two problems here:

  • The "Max" button in the Redeem feature sets the max amount to redeem equal to the user's balance, even if they have more tokens than # tokens outstanding in their position. This needs to be set to Math.min(tokenBalance, tokensInPosition)
  • The amount set to the max is equal to the "intended max" amount casted to a number, and JS casting loses precision. Therefore, the amount set to the max should be equal to the string. This affects both Redeem and UnwrapWETH
    Fixes Redeem should set amounts > num Tokens outstanding to num tokens outstanding #116

@vercel
Copy link

vercel bot commented Aug 11, 2020

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/uma/emp-tools/lx75ono6u
✅ Preview: https://emp-tools-git-npai-max-redeem.uma.vercel.app

@nicholaspai nicholaspai requested review from chrismaree, mrice32, daywiss and kendricktan and removed request for chrismaree August 11, 2020 14:03
Copy link
Member

@chrismaree chrismaree left a comment

Choose a reason for hiding this comment

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

The types we are dealing with here are pretty janky. it's such a pain to keep having to convert and name the type within the variable. I wish there was a cleaner pattern for this.

@nicholaspai
Copy link
Member Author

nicholaspai commented Aug 11, 2020

The types we are dealing with here are pretty janky. it's such a pain to keep having to convert and name the type within the variable. I wish there was a cleaner pattern for this.

Maybe a better solution is to export both a string version and a number version. This way if we don't want to lose precision we can use string, else number, wdyt? However, I don't like the idea of the "backend" container exporting numbers that have lost precision. I think the container should return as close to raw data as possible.

Alternatively, we could export averything from the containers as BigNumbers so they don't lose precision

@nicholaspai
Copy link
Member Author

@chrismaree I'd like to tackle the type casting in a future PR, but want to make this bug fix for now: #118

@nicholaspai nicholaspai merged commit f2922a2 into master Aug 11, 2020
@nicholaspai nicholaspai deleted the npai/max-redeem branch August 11, 2020 21:25
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.

Redeem should set amounts > num Tokens outstanding to num tokens outstanding
2 participants