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

Implement stake with permit/claim and restake/claim on behalf #5

Merged
merged 7 commits into from
Feb 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions contracts/interfaces/IERC20WithPermit.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.7.5;

import {IERC20} from './IERC20.sol';

interface IERC20WithPermit is IERC20 {
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
}
18 changes: 0 additions & 18 deletions contracts/interfaces/ISlashableStakeToken.sol

This file was deleted.

61 changes: 61 additions & 0 deletions contracts/interfaces/IStakedTokenV3.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.7.5;

import {IStakedToken} from './IStakedToken.sol';

interface IStakedTokenV3 is IStakedToken {
function exchangeRate() external view returns (uint256);

function getCooldownPaused() external view returns (bool);

function setCooldownPause(bool paused) external;

function slash(address destination, uint256 amount) external;

function getMaxSlashablePercentage() external view returns (uint256);

function setMaxSlashablePercentage(uint256 percentage) external;

function stakeWithPermit(
address from,
address to,
uint256 amount,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;

function claimRewardsOnBehalf(
address from,
address to,
uint256 amount
) external;

function redeemOnBehalf(
address from,
address to,
uint256 amount
) external;

function claimRewardsAndStake(address to, uint256 amount) external;

function claimRewardsAndRedeem(
address to,
uint256 claimAmount,
uint256 redeemAmount
) external;

function claimRewardsAndStakeOnBehalf(
address from,
address to,
uint256 amount
) external;

function claimRewardsAndRedeemOnBehalf(
address from,
address to,
uint256 claimAmount,
uint256 redeemAmount
) external;
}
14 changes: 7 additions & 7 deletions contracts/stake/StakedTokenV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ contract StakedTokenV2 is
using SafeMath for uint256;
using SafeERC20 for IERC20;

function REVISION() public virtual pure returns(uint256) {
function REVISION() public pure virtual returns (uint256) {
return 2;
}

IERC20 public immutable STAKED_TOKEN;
IERC20 public immutable REWARD_TOKEN;
uint256 public immutable COOLDOWN_SECONDS;
Expand Down Expand Up @@ -117,7 +118,7 @@ contract StakedTokenV2 is
);
}

function stake(address onBehalfOf, uint256 amount) external override virtual {
function stake(address onBehalfOf, uint256 amount) external virtual override {
require(amount != 0, 'INVALID_ZERO_AMOUNT');
uint256 balanceOfUser = balanceOf(onBehalfOf);

Expand All @@ -141,7 +142,7 @@ contract StakedTokenV2 is
* @param to Address to redeem to
* @param amount Amount to redeem
**/
function redeem(address to, uint256 amount) external override virtual {
function redeem(address to, uint256 amount) external virtual override {
require(amount != 0, 'INVALID_ZERO_AMOUNT');
//solium-disable-next-line
uint256 cooldownStartTimestamp = stakersCooldowns[msg.sender];
Expand Down Expand Up @@ -187,7 +188,7 @@ contract StakedTokenV2 is
* @param to Address to stake for
* @param amount Amount to stake
**/
function claimRewards(address to, uint256 amount) external override {
function claimRewards(address to, uint256 amount) external virtual override {
uint256 newTotalRewards =
_updateCurrentUnclaimedRewards(msg.sender, balanceOf(msg.sender), false);
uint256 amountToClaim = (amount == type(uint256).max) ? newTotalRewards : amount;
Expand Down Expand Up @@ -280,7 +281,7 @@ contract StakedTokenV2 is
uint256 amountToReceive,
address toAddress,
uint256 toBalance
) public returns (uint256) {
) public view returns (uint256) {
uint256 toCooldownTimestamp = stakersCooldowns[toAddress];
if (toCooldownTimestamp == 0) {
return 0;
Expand All @@ -306,7 +307,6 @@ contract StakedTokenV2 is
.div(amountToReceive.add(toBalance));
}
}
stakersCooldowns[toAddress] = toCooldownTimestamp;

return toCooldownTimestamp;
}
Expand All @@ -331,7 +331,7 @@ contract StakedTokenV2 is
* @dev returns the revision of the implementation contract
* @return The revision
*/
function getRevision() internal virtual pure override returns (uint256) {
function getRevision() internal pure virtual override returns (uint256) {
return REVISION();
}

Expand Down
Loading