From f9d649cd32260804e9d19eaecaef22a9415b1346 Mon Sep 17 00:00:00 2001 From: Loverush Date: Wed, 13 Jul 2022 15:55:41 +0800 Subject: [PATCH] Update sample dapp code --- assets/bep-153/SampleStakingContract.sol | 27 ++++++++++++------------ 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/assets/bep-153/SampleStakingContract.sol b/assets/bep-153/SampleStakingContract.sol index 42d6ed1c..c9eb9dda 100644 --- a/assets/bep-153/SampleStakingContract.sol +++ b/assets/bep-153/SampleStakingContract.sol @@ -178,6 +178,8 @@ library SafeMath { contract StakingDappExample { using SafeMath for uint256; + bool internal locked; + // constants uint256 public constant TEN_DECIMALS = 10; address public constant STAKING_CONTRACT_ADDR = 0x0000000000000000000000000000000000002001; @@ -251,8 +253,9 @@ contract StakingDappExample { // update reward first UserInfo storage user = userInfo[msg.sender]; _updatePool(); + uint256 pendingReward; if (user.amount > 0) { - uint256 pendingReward = user.amount.mul(poolInfo.rewardPerShare).sub(user.rewardDebt); + pendingReward = user.amount.mul(poolInfo.rewardPerShare).sub(user.rewardDebt); } user.amount = user.amount.add(amount); user.rewardDebt = user.amount.mul(poolInfo.rewardPerShare).sub(pendingReward); @@ -295,7 +298,7 @@ contract StakingDappExample { } totalReceived = totalReceived.sub(amount); - emit undelegatedSubmitted(msg.sender, amount); + emit undelegateSubmitted(msg.sender, amount); } function claimReward() external noReentrant { @@ -332,22 +335,22 @@ contract StakingDappExample { } /************************** Internal **************************/ - function _getHighestYieldingValidator() internal returns(address highestYieldingValidator) { + function _getHighestYieldingValidator() internal pure returns(address highestYieldingValidator) { // this function should return the desirable validator to delegate to // need to be implemented by the developer - highestYieldingValidator = address("0x1"); + highestYieldingValidator = address(0x1); } - function _getLowestYieldingValidator() internal returns(address lowestYieldingValidator) { + function _getLowestYieldingValidator() internal pure returns(address lowestYieldingValidator) { // this function should return the desirable validator to undelegate from // need to be implemented by the developer - lowestYieldingValidator = address("0x2"); + lowestYieldingValidator = address(0x2); } function _delegate(uint256 amount, uint256 oracleRelayerFee) internal { address validator = _getHighestYieldingValidator(); IStaking(STAKING_CONTRACT_ADDR).delegate{value: amount.add(oracleRelayerFee)}(validator, amount); - emit delegateSubmitted(validator, amount); + emit delegateSubmitted(msg.sender, validator, amount); } function _undelegate(uint256 amount, uint256 oracleRelayerFee) internal { @@ -357,14 +360,14 @@ contract StakingDappExample { } function _claimReward() internal { - uint256 amount = IStaking(STAKING_CONTRACT_ADDR).claimReward(address(this)); + uint256 amount = IStaking(STAKING_CONTRACT_ADDR).claimReward(); totalReward = totalReward.add(amount); reserveReward = reserveReward.add(amount); emit rewardReceived(amount); } function _claimUndelegated() internal { - uint256 amount = IStaking(STAKING_CONTRACT_ADDR).claimUndeldegated(address(this)); + uint256 amount = IStaking(STAKING_CONTRACT_ADDR).claimUndeldegated(); emit undelegatedReceived(amount); } @@ -408,7 +411,7 @@ contract StakingDappExample { /*********************** Params update **************************/ function transferOwnership(address newOwner) external onlyOwner { - own = newOwner; + owner = newOwner; } function addOperator(address opt) external onlyOwner { @@ -418,8 +421,4 @@ contract StakingDappExample { function delOperator(address opt) external onlyOwner { operators[opt] = false; } - - function setReserve(uint256 newReserve) external onlyOperator { - reserve = newReserve; - } }