-
Notifications
You must be signed in to change notification settings - Fork 9
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
feat: more useful staking events in Governance
#98
Merged
+164
−69
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,18 +35,26 @@ contract UserProxy is IUserProxy { | |
function stake(uint256 _amount, address _lqtyFrom, bool _doSendRewards, address _recipient) | ||
public | ||
onlyStakingV2 | ||
returns (uint256 lusdAmount, uint256 ethAmount) | ||
returns ( | ||
uint256 lusdReceived, | ||
uint256 lusdSent, | ||
uint256 ethReceived, | ||
uint256 ethSent | ||
) | ||
{ | ||
uint256 initialLUSDAmount = lusd.balanceOf(address(this)); | ||
uint256 initialETHAmount = address(this).balance; | ||
|
||
lqty.transferFrom(_lqtyFrom, address(this), _amount); | ||
stakingV1.stake(_amount); | ||
emit Stake(_amount, _lqtyFrom); | ||
|
||
if (_doSendRewards) { | ||
(lusdAmount, ethAmount) = _sendRewards(_recipient, initialLUSDAmount, initialETHAmount); | ||
} | ||
uint256 lusdAmount = lusd.balanceOf(address(this)); | ||
uint256 ethAmount = address(this).balance; | ||
|
||
lusdReceived = lusdAmount - initialLUSDAmount; | ||
ethReceived = ethAmount - initialETHAmount; | ||
|
||
if (_doSendRewards) (lusdSent, ethSent) = _sendRewards(_recipient, lusdAmount, ethAmount); | ||
} | ||
|
||
/// @inheritdoc IUserProxy | ||
|
@@ -56,12 +64,18 @@ contract UserProxy is IUserProxy { | |
PermitParams calldata _permitParams, | ||
bool _doSendRewards, | ||
address _recipient | ||
) external onlyStakingV2 returns (uint256 lusdAmount, uint256 ethAmount) { | ||
) | ||
external | ||
onlyStakingV2 | ||
returns ( | ||
uint256 lusdReceived, | ||
uint256 lusdSent, | ||
uint256 ethReceived, | ||
uint256 ethSent | ||
) | ||
{ | ||
require(_lqtyFrom == _permitParams.owner, "UserProxy: owner-not-sender"); | ||
|
||
uint256 initialLUSDAmount = lusd.balanceOf(address(this)); | ||
uint256 initialETHAmount = address(this).balance; | ||
|
||
try IERC20Permit(address(lqty)).permit( | ||
_permitParams.owner, | ||
_permitParams.spender, | ||
|
@@ -71,50 +85,52 @@ contract UserProxy is IUserProxy { | |
_permitParams.r, | ||
_permitParams.s | ||
) {} catch {} | ||
stake(_amount, _lqtyFrom, _doSendRewards, _recipient); | ||
|
||
if (_doSendRewards) { | ||
(lusdAmount, ethAmount) = _sendRewards(_recipient, initialLUSDAmount, initialETHAmount); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing duplicate |
||
return stake(_amount, _lqtyFrom, _doSendRewards, _recipient); | ||
} | ||
|
||
/// @inheritdoc IUserProxy | ||
function unstake(uint256 _amount, bool _doSendRewards, address _recipient) | ||
external | ||
onlyStakingV2 | ||
returns (uint256 lusdAmount, uint256 ethAmount) | ||
returns ( | ||
uint256 lqtyReceived, | ||
uint256 lqtySent, | ||
uint256 lusdReceived, | ||
uint256 lusdSent, | ||
uint256 ethReceived, | ||
uint256 ethSent | ||
) | ||
{ | ||
uint256 initialLQTYAmount = lqty.balanceOf(address(this)); | ||
uint256 initialLUSDAmount = lusd.balanceOf(address(this)); | ||
uint256 initialETHAmount = address(this).balance; | ||
|
||
stakingV1.unstake(_amount); | ||
|
||
uint256 lqtyAmount = lqty.balanceOf(address(this)); | ||
if (lqtyAmount > 0) lqty.transfer(_recipient, lqtyAmount); | ||
lqtySent = lqty.balanceOf(address(this)); | ||
uint256 lusdAmount = lusd.balanceOf(address(this)); | ||
uint256 ethAmount = address(this).balance; | ||
|
||
emit Unstake(_recipient, lqtyAmount - initialLQTYAmount, lqtyAmount); | ||
lqtyReceived = lqtySent - initialLQTYAmount; | ||
lusdReceived = lusdAmount - initialLUSDAmount; | ||
ethReceived = ethAmount - initialETHAmount; | ||
|
||
if (_doSendRewards) { | ||
(lusdAmount, ethAmount) = _sendRewards(_recipient, initialLUSDAmount, initialETHAmount); | ||
} | ||
if (lqtySent > 0) lqty.transfer(_recipient, lqtySent); | ||
if (_doSendRewards) (lusdSent, ethSent) = _sendRewards(_recipient, lusdAmount, ethAmount); | ||
} | ||
|
||
function _sendRewards(address _recipient, uint256 _initialLUSDAmount, uint256 _initialETHAmount) | ||
function _sendRewards(address _recipient, uint256 _lusdAmount, uint256 _ethAmount) | ||
internal | ||
returns (uint256 lusdAmount, uint256 ethAmount) | ||
returns (uint256 lusdSent, uint256 ethSent) | ||
{ | ||
lusdAmount = lusd.balanceOf(address(this)); | ||
if (lusdAmount > 0) lusd.transfer(_recipient, lusdAmount); | ||
ethAmount = address(this).balance; | ||
if (ethAmount > 0) { | ||
(bool success,) = payable(_recipient).call{value: ethAmount}(""); | ||
if (_lusdAmount > 0) lusd.transfer(_recipient, _lusdAmount); | ||
if (_ethAmount > 0) { | ||
(bool success,) = payable(_recipient).call{value: _ethAmount}(""); | ||
require(success, "UserProxy: eth-fail"); | ||
} | ||
|
||
emit SendRewards( | ||
_recipient, lusdAmount - _initialLUSDAmount, lusdAmount, ethAmount - _initialETHAmount, ethAmount | ||
); | ||
return (_lusdAmount, _ethAmount); | ||
} | ||
|
||
/// @inheritdoc IUserProxy | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 guess lqty values will always be zero here, right?
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.
lqtyReceived
yes, butlqtySent
may be positive if someone has previously sent LQTY to theUserProxy
address, whichUserProxy.unstake()
would send to_rewardRecipient
. This is documented inIGovernance.sol
.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 considered returning the value of
lqtySent
, but in the end I didn't do it because it wouldn't normally be useful.