Closed whxint closed 6 months ago
Good day @whxint,
The line _burnDsc(debtToCover, user, msg.sender);
from what you showed above decreases the balance of the person to be liquidated in favour of the person doing the liquidation. You can go through the _burnDsc
function for clarity.
function _burnDsc(uint256 amountDscToBurn, address onBehalfOf, address dscFrom) private {
s_DSCMinted[onBehalfOf] -= amountDscToBurn;
bool success = i_dsc.transferFrom(dscFrom, address(this), amountDscToBurn);
// This conditional is hypothetically unreachable
if (!success) {
revert DSCEngine__TransferFailed();
}
i_dsc.burn(amountDscToBurn);
}
When the burn() function runs, the liquidated user's DSC amount decreases, but the liquidater's tokens are transferred to the contract and burned. Considering that the liquidater has a DSC of $100 dollars, it does not have any DSCs since they are all burned, but it continues to write $100 dollars in the s_DSCMinted variable of the contract.
Someone is making depositcollateral, the system will run into a bug. It might have been overlooked because it wasn't a real project, or it might have worked that way. $100 dollars in the s_DSCMinted variable of the contract. When liquidater comes later and mints $100, he will write $200 in the s_DSCMinted variable, but he will have $100 dollars. It always has extra DSC.
Sorry @whxint, Yes it isnt a real project amd was intented to help more with how to write code.
I think i get your question however and it is not a bug; the s_DSCMinted
is also updated in the _burnDsc
function here: s_DSCMinted[onBehalfOf] -= amountDscToBurn;
which would mean that that the person to be liquidated balance is updated correctly.
Thanks for the answer @Chinwuba22
No. liquidatior balance never decreases. The state in the DSC engine never changes.
Bro, I am responding based on your answer. You go and test the increase in the amount of weth collateral. Is this a joke ?
s_DSCMinted[onBehalfOf] -= amountDscToBurn;
This does not reduce the DSC balance of the liquidatior and then DSC is transferred to the contract and burned, but the contract state does not change. Understand the code well pls
Send your own test that is failing here.
Lesson
Lesson 14
Could you please leave a link to the timestamp in the video where this error occurs? (You can right click a video and "copy video URL at current time")
https://youtu.be/8dRAd-Bzc_E?t=10229
Operating System
macOS (Apple Silicon)
Describe the bug
Liquidator pays someone's debt and burns its own DSC, but its state in the engine contract does not change.
When the burn() function runs, the liquidated user's DSC amount decreases, but the liquidater's tokens are transferred to the contract and burned. Considering that the liquidater has a DSC of $100 dollars, it does not have any DSCs since they are all burned, but it continues to write $100 dollars in the s_DSCMinted variable of the contract. When liquidater comes later and mints $100, he will write $200 in the s_DSCMinted variable, but he will have $100 dollars. It always has extra DSC.
If the liquidator liquidates a user, the DSC that will be used is not what he pressed into the engine, but a DSC sent to him by someone else or perhaps purchased from the exchange. Therefore, when liquidating a user, their DSC balance will not decrease. But when the Liquidator performs DepositColleteral and liquidates someone, he always has an extra amount of DSC. If he wants to withdraw his collectral after liquidating someone, the application will give an error because he does not have such a DSC amount, but the DSC engine shows that he has it. Why is the liquidator's DSC balance not taken into account in DSCEngine after a successful liquidation call?