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: event withdrawn amounts #7

Conversation

md0x
Copy link
Contributor

@md0x md0x commented Nov 16, 2023

Changes proposed in this PR:

  • Fix the issue where events were emitting 0 amounts due to ordering of functions.

Signed-off-by: Pablo Maldonado <pablo@umaproject.org>
Copy link

linear bot commented Nov 16, 2023

UMA-2040 HoneyPotEmptied and PotReset not showing correct amounts

https://github.com/UMAprotocol/oev-demo/blob/master/src/HoneyPot.sol#L61

_emptyPotForUser is updating the stored balance before the events are emitted making the events to have 0 amounts.

@md0x md0x marked this pull request as ready for review November 16, 2023 13:33
Signed-off-by: Pablo Maldonado <pablo@umaproject.org>
src/HoneyPot.sol Outdated
@@ -53,17 +53,17 @@ contract HoneyPot is Ownable {
(, int256 currentPrice,,,) = oracle.latestRoundData();
require(currentPrice >= 0, "Invalid price from oracle");

HoneyPotDetails storage userPot = honeyPots[honeyPotCreator];
HoneyPotDetails memory userPot = honeyPots[honeyPotCreator];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Storage wasn't needed here.

Copy link
Member

Choose a reason for hiding this comment

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

tiny nit: why change this?

In general, I think using storage references is usually (there are some exceptions) preferable (gas-wise) to copying the entire struct to memory because you may not actually need to SLOAD every element of the struct and you may end up using less memory overall by avoiding the copy. Does that make sense?

This is just a demo contract, so it's not super important, just wanted to make a note of it!

Copy link
Member

@mrice32 mrice32 left a comment

Choose a reason for hiding this comment

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

LGTM!

src/HoneyPot.sol Outdated
@@ -53,17 +53,17 @@ contract HoneyPot is Ownable {
(, int256 currentPrice,,,) = oracle.latestRoundData();
require(currentPrice >= 0, "Invalid price from oracle");

HoneyPotDetails storage userPot = honeyPots[honeyPotCreator];
HoneyPotDetails memory userPot = honeyPots[honeyPotCreator];
Copy link
Member

Choose a reason for hiding this comment

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

tiny nit: why change this?

In general, I think using storage references is usually (there are some exceptions) preferable (gas-wise) to copying the entire struct to memory because you may not actually need to SLOAD every element of the struct and you may end up using less memory overall by avoiding the copy. Does that make sense?

This is just a demo contract, so it's not super important, just wanted to make a note of it!

Signed-off-by: Pablo Maldonado <pablo@umaproject.org>
@md0x md0x merged commit 0e585b1 into master Nov 17, 2023
3 checks passed
@md0x md0x deleted the pablo/uma-2040-honeypotemptied-and-potreset-not-showing-correct-amounts branch November 17, 2023 10:47
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.

4 participants