/
StakedTokenMTA.sol
70 lines (62 loc) 路 2.41 KB
/
StakedTokenMTA.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity 0.8.6;
pragma abicoder v2;
import { StakedToken } from "./StakedToken.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { Initializable } from "@openzeppelin/contracts/proxy/utils/Initializable.sol";
/**
* @title StakedTokenMTA
* @dev Derives from StakedToken, and simply adds the functionality specific to the $MTA staking token,
* for example compounding rewards.
**/
contract StakedTokenMTA is StakedToken, Initializable {
using SafeERC20 for IERC20;
/**
* @param _nexus System nexus
* @param _rewardsToken Token that is being distributed as a reward. eg MTA
* @param _questManager Centralised manager of quests
* @param _stakedToken Core token that is staked and tracked (e.g. MTA)
* @param _cooldownSeconds Seconds a user must wait after she initiates her cooldown before withdrawal is possible
*/
constructor(
address _nexus,
address _rewardsToken,
address _questManager,
address _stakedToken,
uint256 _cooldownSeconds
)
StakedToken(
_nexus,
_rewardsToken,
_questManager,
_stakedToken,
_cooldownSeconds,
false
)
{}
function initialize(
bytes32 _nameArg,
bytes32 _symbolArg,
address _rewardsDistributorArg
) external initializer {
__StakedToken_init(_nameArg, _symbolArg, _rewardsDistributorArg);
}
/**
* @dev Allows a staker to compound their rewards IF the Staking token and the Rewards token are the same
* for example, with $MTA as both staking token and rewards token. Calls 'claimRewards' on the HeadlessStakingRewards
* before executing a stake here
*/
function compoundRewards() external nonReentrant {
require(address(STAKED_TOKEN) == address(REWARDS_TOKEN), "Only for same pairs");
// 1. claim rewards
uint256 balBefore = STAKED_TOKEN.balanceOf(address(this));
_claimReward(address(this));
// 2. check claim amount
uint256 balAfter = STAKED_TOKEN.balanceOf(address(this));
uint256 claimed = balAfter - balBefore;
require(claimed > 0, "Must compound something");
// 3. re-invest
_settleStake(claimed, address(0), false);
}
}