-
Notifications
You must be signed in to change notification settings - Fork 586
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: position cannot be liquidated when turn on liquidation protocol fee #709
Conversation
@zhoujia6139 could you provide some extra context on why you think this doesn't work as expected? |
let me take an example: during liquidation, if then the PToken balance(before rebase) for so the PToken balance(before rebase) needed for liquidation is 103(52 + 51), and the user PToken balance(before rebase) is only 102, makes the following call fail:
|
@zhoujia6139 not sure why you consider your flow the "before the rebase" state (I assume you refer to data before the liquidity index gets updated).
Then the Do you have any test for example in mainnet fork showing how in this scenario the code fails? |
I think the test case I added in |
@zhoujia6139 your tests are positive, checking that after your changes the system works, but not checking that it doesn't before. In addition both the naming on your previous message (pToken? I assumed aToken) and amounts don't really fit. To clarify why the logic is actually correct, the flow of liquidation is the following:
|
oh yeah. PToken is actually AToken, it's my fault. You can remove the solidity code I added, then the test case will fail. The key point of this issue is the WadRayMath library you used. it's a rounded operation(If a value is >=.5, will be rounded up, otherwise rounded down.). I list the actual failed data for test case I added here. The user AToken balance(after scale) is 1000000000000000000, and AToken normalized income index is 1000018968212153143659992975 During liquidation, if Then the AToken balance(after scale) for so the AToken balance(after scale) needed for liquidation is 1000000000000000001(
|
When Integer A multiply by an index which is greater than 1.0 and end up with a rounded up operation to Integer B. Then we divide B to two parts, Integer B1 and Integer B2. if we divide B1 by this index and end up with a rounded up operation to Integer C1 and then C1 + C2 == A + 1. The liquidation logic code assume C1 + C2 == A, so in some case it will fail. |
@zhoujia6139 now I see what you are referring to. And yes, agree that precision can be a problem in some cases. Regarding the change, looks correct to me, will just do some suggestions about naming |
Co-authored-by: Ernesto Boado <[email protected]>
ok, great. |
Thanks for your contribution @zhoujia6139 ! |
No description provided.