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

[H01] Check for ETH deposited in buyOTokens. #185

Merged
merged 4 commits into from
Oct 12, 2020
Merged

Conversation

mshrieve
Copy link
Contributor

@mshrieve mshrieve commented Oct 1, 2020

Added a check to make sure msg.value is sufficient to purchase the amount specified.
Also added functionality to set amount = 0 and spend all of msg.value.
This is in response to openZeppelin:
"Additionally, consider implementing a way to either return any ETH deposited in excess, or trade all ETH sent for oTokens."

…_amt = 0, then buyOTokens will spend all of msg.value
@mshrieve mshrieve requested a review from aparnakr October 1, 2020 19:13
@mshrieve
Copy link
Contributor Author

mshrieve commented Oct 1, 2020

I want to make sure it's ok to switch uniswapBuyOToken to internal ?

@mshrieve
Copy link
Contributor Author

mshrieve commented Oct 1, 2020

FYI, it still does not "return any ETH deposited in excess."

@mshrieve
Copy link
Contributor Author

mshrieve commented Oct 1, 2020

OK, I changed uniswapBuyOToken so that it always sends back excess ETH. Let me know if that sounds good?

Copy link
Contributor

@aparnakr aparnakr left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -241,20 +241,33 @@ contract OptionsExchange {
uniswapFactory.getExchange(address(oToken))
);

uint256 ethToTransfer = exchange.getEthToTokenOutputPrice(_amt);
uint256 ethToTransfer;
uint256 amount = _amt;
Copy link
Member

Choose a reason for hiding this comment

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

Awesome work 🔥 , but why here re-assigning _amt into amount ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OpenZeppelin suggested providing a way to buy as many oTokens as msg.value can afford.
So, if _amt == 0, we get the amount from the exchange contract.
Otherwise, amount = _amt.
Then we emit the event and send the exchange transfer with amount.
Happy to do it a different way, or get rid of the _amt == 0 thing.

@mshrieve mshrieve changed the title check for ETH deposited in buyOTokens. [H01] Check for ETH deposited in buyOTokens. Oct 1, 2020
Comment on lines 257 to 258
ethToTransfer = msg.value;
amount = exchange.getTokenToEthOutputPrice(msg.value);
Copy link
Member

Choose a reason for hiding this comment

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

Here u are assigning ethToTransfer = msg.value but using msg.value in getTokenToEthOutputPrice

Copy link
Contributor Author

@mshrieve mshrieve Oct 4, 2020

Choose a reason for hiding this comment

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

they are equal, but we can switch msg.value to ethToTransfer in line 258 if that's more clear.

Copy link
Contributor

@antoncoding antoncoding Oct 4, 2020

Choose a reason for hiding this comment

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

I think that would be more clear!

@aparnakr aparnakr merged commit 4d3b6d0 into dev Oct 12, 2020
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.

None yet

4 participants