Skip to content

Commit

Permalink
Update sample dapp code
Browse files Browse the repository at this point in the history
  • Loading branch information
pythonberg1997 committed Jul 13, 2022
1 parent 4fb95d0 commit f9d649c
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions assets/bep-153/SampleStakingContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -295,7 +298,7 @@ contract StakingDappExample {
}

totalReceived = totalReceived.sub(amount);
emit undelegatedSubmitted(msg.sender, amount);
emit undelegateSubmitted(msg.sender, amount);
}

function claimReward() external noReentrant {
Expand Down Expand Up @@ -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 {
Expand All @@ -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);
}

Expand Down Expand Up @@ -408,7 +411,7 @@ contract StakingDappExample {

/*********************** Params update **************************/
function transferOwnership(address newOwner) external onlyOwner {
own = newOwner;
owner = newOwner;
}

function addOperator(address opt) external onlyOwner {
Expand All @@ -418,8 +421,4 @@ contract StakingDappExample {
function delOperator(address opt) external onlyOwner {
operators[opt] = false;
}

function setReserve(uint256 newReserve) external onlyOperator {
reserve = newReserve;
}
}

0 comments on commit f9d649c

Please sign in to comment.