0

I was doing the chainlink hackton lesson "DeFi Staking App: Code Along" link when I got this error while running yarn hardhat compile:

ParserError: Expected ',' but got ';' --> contracts/Staking.sol:59:24: | 59 | pastRewards; | ^

Error HH600: Compilation failed

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.7;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

error Staking__TransferFailed();
error Stakig__NeedsMoteThanZero();


contract Staking {
    IERC20 public s_stakingToken;
    ERC20 public s_rewardToken;
    // somones address -> how much they staked
    mapping(address => uint256) public s_balances;

   // mapping of how much each address has been paid
   mapping(address => uint256) public s_userRewardPerTokenPaid;

   // a mapping of how much rewards each address has to claim
   mapping(address => uint256) public s_rewards;

uint256 public constant REWARD_RATE =100;
uint256 public s_totalSupply;
uint256 public s_rewardPerTokenStored;
uint256 public s_lastUpdateTime;

modifier updateReward(address account){
    s_rewardPerTokenStored = rewardPerToken();
    s_lasrUpdateTime = block.timestamp;
    s_rewards[account] = earned(account);
    s_userRewardPerTokenPaid[account] = s_rewardPerTokenStored;
    _;
}

modifier moreThanZero(uint256 amount){
    if( amount ==0){
        revert Stakig__NeedsMoteThanZero();
    }
    _;

}
    


constructor(address stakingToken, address rewardToken) {
    s_stakingToken = IER20(stakingToken);
    s_rewardToken = IER20(rewardToken);
}

function earned(address account) public view returns (uint256){
    uint256 currentBlanace = s_balances[account];
    // how much they have paid alredy
    uint256 amountPaid = s_userRewardPerToken[account];
    uint256 currentRewardPerToken = rewardPerToken();
    uint256 pastRewards = s_rewards[account];
    uint256 _earned = ((currentBalance *(currentRewardPerToken - amountPaid)/1e18) + 
        pastRewards;
    return _earned; 

}



function rewardPerToken public view returns(uint256) {
    if (s_totalSupply ==0){
        return s_rewardPerTokenStored;
    }
    return s_rewardPerTokenStored + (((block.timestamp -s_lastUpdateTime) * REWARD_RATE * 1e18/ s_totalSupply);
}

function stake(uint256 amount) external updateReward(msg.sender) moreThanZero(amount) {
    s_balances[msg.sender] = s_balances[msg.sender] + amount;
    s_totalSupply = s_totalSupply + amount;
    // emit event
    bool success = s_stakingToken.transferFrom(msg.sender, address(this), amount);
    // require(success, "Failed");
    if(!success) {
        revert Staking__TransferFailed();
    }

}

}

function withdraw(uint256 amount) external updateReward(msg.sender) moreThanZero(amount) {
    s_balances[msg.sender] = s_balances[msg.sender] - amount;
    s_totalSupply = s_totalSupply - amount; 
    bool success = s_stakingToken.transfer(msg.sender, amount);
    if(!success) {
        revert Staking__TransferFailed();
    }

}

function claimReward() external updateReward(msg.sender) {
    uint256 reward = s_rewards[msg.sender];
    bool succes = s_rewardToken.transfer(msg.sender, reward);
    if(!success){
        revert Staking__TransferFailed();
    }
    

}
  

}

1 Answer 1

0

Here:

function rewardPerToken public view returns(uint256) {
    if (s_totalSupply ==0){
        return s_rewardPerTokenStored;
    }
    return s_rewardPerTokenStored + (((block.timestamp -s_lastUpdateTime) *     REWARD_RATE * 1e18/ s_totalSupply);
}

you forgot the function parenthesis. It should looks like function rewardPerToken()

1
  • Thanks. This fixed the problem. Silly mistake.
    – Bobby
    May 8 at 15:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.