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

🎈 perf(staking): returns and events #143

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
8 changes: 5 additions & 3 deletions contracts/staking/P12MineUpgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ contract P12MineUpgradeable is
@notice Get pending rewards
@param lpToken Address of lpToken
*/
function claim(address lpToken) public virtual override nonReentrant whenNotPaused {
function claim(address lpToken) public virtual override nonReentrant whenNotPaused returns (uint256){
uint256 pid = getPid(lpToken);
require(userInfo[pid][msg.sender].amount > 0, 'P12Mine: no staked token');
PoolInfo storage pool = poolInfos[pid];
Expand All @@ -312,12 +312,13 @@ contract P12MineUpgradeable is
uint256 pending = (user.amount * pool.accP12PerShare) / ONE - user.rewardDebt;
user.rewardDebt = (user.amount * pool.accP12PerShare) / ONE;
_safeP12Transfer(msg.sender, pending);
return pending;
}

/**
@notice Get all pending rewards
*/
function claimAll() public virtual override nonReentrant whenNotPaused {
function claimAll() public virtual override nonReentrant whenNotPaused returns (uint256){
uint256 length = poolInfos.length;
uint256 pending = 0;
for (uint256 pid = 0; pid < length; pid++) {
Expand All @@ -331,6 +332,7 @@ contract P12MineUpgradeable is
user.rewardDebt = (user.amount * pool.accP12PerShare) / ONE;
}
_safeP12Transfer(msg.sender, pending);
return pending;
}

/**
Expand All @@ -356,7 +358,7 @@ contract P12MineUpgradeable is
pool.amount -= amount;
user.rewardDebt = (user.amount * pool.accP12PerShare) / ONE;
IERC20Upgradeable(pool.lpToken).safeTransfer(address(_who), amount);
emit ExecuteWithdraw(_who, pid, amount, user.amount, pool.amount);
emit ExecuteWithdraw(_who, pid,id, amount, user.amount, pool.amount);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion contracts/staking/interfaces/IGaugeController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface IGaugeController {

event ApplyOwnership(address admin);

event AddType(string, int128 typeId);
event AddType(string name, int128 typeId);

event NewTypeWeight(int128 typeId, uint256 time, uint256 weight, uint256 totalWeight);

Expand Down
8 changes: 4 additions & 4 deletions contracts/staking/interfaces/IP12MineUpgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import './IGaugeController.sol';

interface IP12MineUpgradeable {
event Deposit(address indexed user, uint256 indexed pid, uint256 amount, uint256 userAmount, uint256 poolAmount); // deposit lpToken log
event ExecuteWithdraw(address indexed user, uint256 indexed pid, uint256 amount, uint256 userAmount, uint256 poolAmount); // withdraw lpToken log
event ExecuteWithdraw(address indexed user, uint256 indexed pid,bytes32 indexed withdrawId, uint256 amount, uint256 userAmount, uint256 poolAmount); // withdraw lpToken log
event QueueWithdraw(
address indexed user,
uint256 pid,
Expand Down Expand Up @@ -68,9 +68,9 @@ interface IP12MineUpgradeable {
address gameCoinCreator
) external; // add lpToken info for gameCoin creator when first time

function claim(address lpToken) external; // get pending rewards
function claim(address lpToken) external returns (uint256); // get pending rewards

function claimAll() external; // get all pending rewards
function claimAll() external returns (uint256); // get all pending rewards

function checkpoint(address lpToken) external;
function checkpoint(address lpToken) external ;
}