-
Notifications
You must be signed in to change notification settings - Fork 30
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
Eth_Broker fix and test changes from js to ts #17
base: main
Are you sure you want to change the base?
Conversation
@@ -339,7 +338,7 @@ contract Eth_broker { | |||
"Curve burn failed" | |||
); | |||
// Getting expected ETH for DAI | |||
uint256 ethMin = sellRewardDai(_minDaiSellValue); | |||
uint256 ethMin = sellRewardDai(dai_.balanceOf(address(this))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why does this revert https://github.com/ethersphere/bzzaar-contracts/pull/7/files ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a bit more info - i believe the original change was made in order to allow the caller of the function to account for slippage. using the full amount of DAI received by the contract to calculate the minimum amount of ETH that would be received as a result of the transaction would only work in the case that the slippage is 0%. @ralph-pichler @RyRy79261 could you advise please guys? 😁
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More context: #7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would be really interested to hear Ralph has to say about this, since he approved #7 by Nicca42. Completely tracing this down to the source is probably warranted as this value might have an impact. I can help with that, but that will take a bit more time than just doing a review.
On the most rudimentary level, the function sellRewardDai
says that _daiAmount
is the amount of dai to be traded for ETH and this is indeed dai_.balanceOf(address(this))
and not _minDaiValue
. However, I see that #7 changed the value passed in at this line (which is now reverted), but did not update the comment for the function sellRewardDai
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Veronica writes that this could not be properly tested because the solidity versions between the router and this contract are different. If you do this change, at the very least I would call for caution and manually test that this works (and share the test artifacts)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi there, sorry it's been a while since I saw this code base so still need to pull it down but if I recall correctly, in trying to eliminate all potential entropy from the contracts when trying to fix the tests, I think this approach is more explicit as it takes the active balance as directly as possible
That being said it's be a while so I can't recall and specifically deliberate requirement for this line change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dan asked me to review this.
@@ -22,7 +22,6 @@ contract Eth_broker { | |||
// ------------------------------------------------------------------------- | |||
// Events | |||
// ------------------------------------------------------------------------- | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know it is not part of this changeset, but I notice that you are using Solidity version 0.5.0 which is rather outdated. Is it in the books to update this?
@@ -263,7 +262,7 @@ contract Eth_broker { | |||
mutex() | |||
returns (bool) | |||
{ | |||
(uint256 daiNeeded, uint256 ethReceived) = _commonMint( | |||
(uint256 daiNeeded, uint256 ethReceived, uint256 ethSpent) = _commonMint( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ethReceived is an unused variable now, better don't assign it
(uint256 daiNeeded, , uint256 ethSpent) =
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not part of this changeset, but I notice that the comments to the internal function _commonMint
don't document the last return value (ethSpent
).
@@ -217,7 +216,7 @@ contract Eth_broker { | |||
mutex() | |||
returns (bool) | |||
{ | |||
(uint256 daiNeeded, uint256 ethReceived) = _commonMint( | |||
(uint256 daiNeeded, uint256 ethReceived, uint256 ethSpent) = _commonMint( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my comment on line 265
@@ -339,7 +338,7 @@ contract Eth_broker { | |||
"Curve burn failed" | |||
); | |||
// Getting expected ETH for DAI | |||
uint256 ethMin = sellRewardDai(_minDaiSellValue); | |||
uint256 ethMin = sellRewardDai(dai_.balanceOf(address(this))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More context: #7
@@ -339,7 +338,7 @@ contract Eth_broker { | |||
"Curve burn failed" | |||
); | |||
// Getting expected ETH for DAI | |||
uint256 ethMin = sellRewardDai(_minDaiSellValue); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By removing this value, the passed in value _minDaiSellValue
(line 301) is not anymore used (only to emit it in an event). Given that this value is not used, it is not best practice to emit it in the event, so you could just remove it from the function signature and also don't emit it in the event. I understand there might be reasons for backwards compatibility that you keep the function signature and event as is (and that this particular change is not even wanted because it is reverting #7 )
@@ -339,7 +338,7 @@ contract Eth_broker { | |||
"Curve burn failed" | |||
); | |||
// Getting expected ETH for DAI | |||
uint256 ethMin = sellRewardDai(_minDaiSellValue); | |||
uint256 ethMin = sellRewardDai(dai_.balanceOf(address(this))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would be really interested to hear Ralph has to say about this, since he approved #7 by Nicca42. Completely tracing this down to the source is probably warranted as this value might have an impact. I can help with that, but that will take a bit more time than just doing a review.
On the most rudimentary level, the function sellRewardDai
says that _daiAmount
is the amount of dai to be traded for ETH and this is indeed dai_.balanceOf(address(this))
and not _minDaiValue
. However, I see that #7 changed the value passed in at this line (which is now reverted), but did not update the comment for the function sellRewardDai
.
@@ -339,7 +338,7 @@ contract Eth_broker { | |||
"Curve burn failed" | |||
); | |||
// Getting expected ETH for DAI | |||
uint256 ethMin = sellRewardDai(_minDaiSellValue); | |||
uint256 ethMin = sellRewardDai(dai_.balanceOf(address(this))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Veronica writes that this could not be properly tested because the solidity versions between the router and this contract are different. If you do this change, at the very least I would call for caution and manually test that this works (and share the test artifacts)
@@ -361,7 +361,7 @@ contract Eth_broker { | |||
msg.sender, | |||
_tokenAmount, | |||
daiReward, | |||
ethMin, | |||
swapOutputs[1], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find this a very strange change and don't understand why you pass 0
here (the array is initialized but never filled)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The outputs from the uniswap broker return the number required here in swapOutputs[1]
daiNeeded, | ||
getPath(true), | ||
address(this), | ||
_deadline | ||
); | ||
// Getting the amount of ETH received | ||
ethReceived = address(this).balance; | ||
ethSpent = swapOutputs[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You never use this variable. Why burdening yourself with assigning it (also to initialize and assign the array on lines 421 and 423)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To match the uniswap broker, the issue with testing was that the values for swapOutputs wasn't being returned in the mocks
No description provided.