Skip to content

Commit

Permalink
Merge pull request #1 from darwinia-network/changes
Browse files Browse the repository at this point in the history
Contract changes
  • Loading branch information
hujw77 authored Feb 6, 2024
2 parents 7b1f815 + b166fe6 commit d6bbc38
Showing 1 changed file with 4 additions and 21 deletions.
25 changes: 4 additions & 21 deletions src/KTONStakingRewards.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ contract StakingRewards is IStakingRewards, RewardsDistributionRecipient, Reentr

/* ========== STATE VARIABLES ========== */

IERC20 public rewardsToken;
IERC20 public stakingToken;
uint256 public periodFinish = 0;
uint256 public rewardRate = 0;
uint256 public rewardsDuration = 60 days;
uint256 public rewardsDuration = 7200;
uint256 public lastUpdateTime;
uint256 public rewardPerTokenStored;

Expand All @@ -34,10 +33,8 @@ contract StakingRewards is IStakingRewards, RewardsDistributionRecipient, Reentr

constructor(
address _rewardsDistribution,
address _rewardsToken,
address _stakingToken
) public {
rewardsToken = IERC20(_rewardsToken);
stakingToken = IERC20(_stakingToken);
rewardsDistribution = _rewardsDistribution;
}
Expand Down Expand Up @@ -76,18 +73,6 @@ contract StakingRewards is IStakingRewards, RewardsDistributionRecipient, Reentr

/* ========== MUTATIVE FUNCTIONS ========== */

function stakeWithPermit(uint256 amount, uint deadline, uint8 v, bytes32 r, bytes32 s) external nonReentrant updateReward(msg.sender) {
require(amount > 0, "Cannot stake 0");
_totalSupply = _totalSupply.add(amount);
_balances[msg.sender] = _balances[msg.sender].add(amount);

// permit
IUniswapV2ERC20(address(stakingToken)).permit(msg.sender, address(this), amount, deadline, v, r, s);

stakingToken.safeTransferFrom(msg.sender, address(this), amount);
emit Staked(msg.sender, amount);
}

function stake(uint256 amount) external nonReentrant updateReward(msg.sender) {
require(amount > 0, "Cannot stake 0");
_totalSupply = _totalSupply.add(amount);
Expand All @@ -108,7 +93,8 @@ contract StakingRewards is IStakingRewards, RewardsDistributionRecipient, Reentr
uint256 reward = rewards[msg.sender];
if (reward > 0) {
rewards[msg.sender] = 0;
rewardsToken.safeTransfer(msg.sender, reward);
(bool success, ) = msg.sender.call.value(reward)("");
require(success, "Transfer failed");
emit RewardPaid(msg.sender, reward);
}
}
Expand All @@ -133,7 +119,7 @@ contract StakingRewards is IStakingRewards, RewardsDistributionRecipient, Reentr
// This keeps the reward rate in the right range, preventing overflows due to
// very high values of rewardRate in the earned and rewardsPerToken functions;
// Reward + leftover must be less than 2^256 / 10^18 to avoid overflow.
uint balance = rewardsToken.balanceOf(address(this));
uint balance = address(this).balance;
require(rewardRate <= balance.div(rewardsDuration), "Provided reward too high");

lastUpdateTime = block.timestamp;
Expand Down Expand Up @@ -161,6 +147,3 @@ contract StakingRewards is IStakingRewards, RewardsDistributionRecipient, Reentr
event RewardPaid(address indexed user, uint256 reward);
}

interface IUniswapV2ERC20 {
function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
}

0 comments on commit d6bbc38

Please sign in to comment.