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

Stake slashing implementation #2

Open
wants to merge 40 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
5f85047
Added exchange rate, initial tests
Jan 26, 2021
6cc4689
Added cooldown admin, modifiers
Jan 26, 2021
436c7fe
Updated StakedTokenV3 implementation, added StakedAaveV3
Jan 27, 2021
2e961ea
Updated tests
Jan 28, 2021
951d09a
Added more tests
Jan 28, 2021
3f22cd2
Added more slashing tests
Jan 29, 2021
47e6eb4
Refactored StakeTokenV3, added more tests
Jan 29, 2021
5917b9d
Added claim admins pattern
The-3D Feb 1, 2021
138ec5c
Merge branch 'master' into feat/slashing-implementation
The-3D Feb 9, 2021
fdc8cf2
Added missing events
The-3D Feb 9, 2021
8c1403f
Added stakeWithPermit function, tests
The-3D Feb 11, 2021
b8d366a
Added features and tests (1/2)
dhadrien Feb 15, 2021
baf9f32
added redeemOnBehalf claimRewardsOnBehalf claimRewardsAndStake claimR…
dhadrien Feb 16, 2021
5bd671a
Change on StakedTokenV2
eboadom Feb 19, 2021
586d02f
removed useless transfers in claimAndStake
dhadrien Feb 16, 2021
57bd352
updated behavior on claimAndStake
The-3D Feb 16, 2021
1bb2173
Updated tests, added gas reporter
The-3D Feb 16, 2021
769e1d3
Merge pull request #5 from aave/feat/other-features
eboadom Feb 19, 2021
eee3207
adding return type to claimOnBehalf
dhadrien Mar 15, 2021
6522d51
Swap arguments at handleAction to match aToken implementation: user, …
kartojal Mar 22, 2021
869902d
Merge pull request #8 from aave/feat/swap-handleAction-params
The-3D Mar 22, 2021
ce0be83
Moved AaveEcosystemReserve.sol to the repository. Create hardhat scri…
kartojal Mar 22, 2021
782798e
Remove unused helper.
kartojal Mar 22, 2021
2672c64
Add distribution and reward vault setters. Add new rewards role to Aa…
kartojal Mar 24, 2021
5f0d34f
Keep old interface compatibility at AaveDistributionManager
kartojal Mar 25, 2021
a42ea49
Merge pull request #11 from aave/feat/rewards-role
kartojal Mar 26, 2021
740440c
Solve conflicts. Update scripts to latest AaveIncentivesController.
kartojal Mar 26, 2021
d315278
Upload fixed package-lock
kartojal Mar 26, 2021
206a886
Import typings and polygon verifier from protocol-v2
kartojal Mar 26, 2021
c909437
Fixed getters of AaveEcosystemReserve, AaveIncentivesController and p…
kartojal Mar 31, 2021
cb8e5e8
Added config script
dhadrien Apr 12, 2021
231a589
new addresses mumbai
dhadrien Apr 12, 2021
d39a684
updated to new mumbai addresses
dhadrien Apr 12, 2021
b81c1a3
Added fork test matic
dhadrien Apr 13, 2021
1dbb853
Updated the AaveIncentivesController interface
The-3D Apr 14, 2021
0fb481c
Merge branch 'feat/incentives/mumbai-config' of github.com:aave/aave-…
The-3D Apr 14, 2021
ad1afde
refactor: Updated IAaveIncentivesController interface
The-3D Apr 17, 2021
d3c4208
Merge pull request #13 from aave/feat/incentives/mumbai-config
kartojal Apr 28, 2021
da4bad6
Merge pull request #9 from aave/feat/deployment-scripts
kartojal Apr 28, 2021
759258e
feat: merge master and fix conflicts
kartojal Aug 9, 2021
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
53 changes: 35 additions & 18 deletions contracts/stake/StakedTokenV3.sol
Original file line number Diff line number Diff line change
@@ -58,6 +58,11 @@ contract StakedTokenV3 is StakedTokenV2, IStakedTokenV3, RoleManager {
_;
}

modifier onlyStakedTokenIsRewardToken {
require((REWARD_TOKEN == STAKED_TOKEN), 'REWARD_TOKEN_IS_NOT_STAKED_TOKEN');
_;
}

event Staked(address indexed from, address indexed to, uint256 amount, uint256 sharesMinted);
event Redeem(
address indexed from,
@@ -156,8 +161,6 @@ contract StakedTokenV3 is StakedTokenV2, IStakedTokenV3, RoleManager {
_initAdmins(adminsRoles, adminsAddresses);

_maxSlashablePercentage = maxSlashablePercentage;

IERC20(STAKED_TOKEN).approve(address(this), type(uint256).max);
}

/**
@@ -166,7 +169,7 @@ contract StakedTokenV3 is StakedTokenV2, IStakedTokenV3, RoleManager {
* @param amount The amount to be staked
**/
function stake(address to, uint256 amount) external override(IStakedToken, StakedTokenV2) {
_stake(msg.sender, to, amount);
_stake(msg.sender, to, amount, false);
}

/**
@@ -188,7 +191,7 @@ contract StakedTokenV3 is StakedTokenV2, IStakedTokenV3, RoleManager {
bytes32 s
) external override {
IERC20WithPermit(address(STAKED_TOKEN)).permit(from, address(this), amount, deadline, v, r, s);
_stake(from, to, amount);
_stake(from, to, amount, false);
}

/**
@@ -220,7 +223,7 @@ contract StakedTokenV3 is StakedTokenV2, IStakedTokenV3, RoleManager {
* @param amount Amount to stake
**/
function claimRewards(address to, uint256 amount) external override(StakedTokenV2, IStakedToken) {
_claimRewards(msg.sender, to, amount);
_claimRewards(msg.sender, to, amount, false);
}

/**
@@ -234,17 +237,21 @@ contract StakedTokenV3 is StakedTokenV2, IStakedTokenV3, RoleManager {
address to,
uint256 amount
) external override onlyClaimHelper {
_claimRewards(from, to, amount);
_claimRewards(from, to, amount, false);
}

/**
* @dev Claims an `amount` of `REWARD_TOKEN` amd restakes
* @param to Address to stake to
* @param amount Amount to claim
**/
function claimRewardsAndStake(address to, uint256 amount) external override {
uint256 rewardsClaimed = _claimRewards(msg.sender, address(this), amount);
_stake(address(this), to, rewardsClaimed);
function claimRewardsAndStake(address to, uint256 amount)
external
override
onlyStakedTokenIsRewardToken
{
uint256 rewardsClaimed = _claimRewards(msg.sender, address(this), amount, true);
_stake(address(this), to, rewardsClaimed, true);
}

/**
@@ -257,9 +264,9 @@ contract StakedTokenV3 is StakedTokenV2, IStakedTokenV3, RoleManager {
address from,
address to,
uint256 amount
) external override onlyClaimHelper {
uint256 rewardsClaimed = _claimRewards(from, address(this), amount);
_stake(address(this), to, rewardsClaimed);
) external override onlyStakedTokenIsRewardToken onlyClaimHelper {
uint256 rewardsClaimed = _claimRewards(from, address(this), amount, true);
_stake(address(this), to, rewardsClaimed, true);
}

/**
@@ -273,7 +280,7 @@ contract StakedTokenV3 is StakedTokenV2, IStakedTokenV3, RoleManager {
uint256 claimAmount,
uint256 redeemAmount
) external override {
_claimRewards(msg.sender, to, claimAmount);
_claimRewards(msg.sender, to, claimAmount, false);
_redeem(msg.sender, to, redeemAmount);
}

@@ -290,7 +297,7 @@ contract StakedTokenV3 is StakedTokenV2, IStakedTokenV3, RoleManager {
uint256 claimAmount,
uint256 redeemAmount
) external override onlyClaimHelper {
_claimRewards(from, to, claimAmount);
_claimRewards(from, to, claimAmount, false);
_redeem(from, to, redeemAmount);
}

@@ -372,14 +379,17 @@ contract StakedTokenV3 is StakedTokenV2, IStakedTokenV3, RoleManager {
function _claimRewards(
address from,
address to,
uint256 amount
uint256 amount,
bool claimToReserve
) internal returns (uint256) {
uint256 newTotalRewards = _updateCurrentUnclaimedRewards(from, balanceOf(from), false);
uint256 amountToClaim = (amount == type(uint256).max) ? newTotalRewards : amount;

stakerRewardsToClaim[from] = newTotalRewards.sub(amountToClaim, 'INVALID_AMOUNT');

REWARD_TOKEN.safeTransferFrom(REWARDS_VAULT, to, amountToClaim);
if (!claimToReserve) {
REWARD_TOKEN.safeTransferFrom(REWARDS_VAULT, to, amountToClaim);
}

emit RewardsClaimed(from, to, amountToClaim);
return (amountToClaim);
@@ -388,7 +398,8 @@ contract StakedTokenV3 is StakedTokenV2, IStakedTokenV3, RoleManager {
function _stake(
address from,
address to,
uint256 amount
uint256 amount,
bool stakeFromReserve
) internal {
require(amount != 0, 'INVALID_ZERO_AMOUNT');

@@ -407,7 +418,13 @@ contract StakedTokenV3 is StakedTokenV2, IStakedTokenV3, RoleManager {
uint256 sharesToMint = amount.mul(1e18).div(exchangeRate());
_mint(to, sharesToMint);

STAKED_TOKEN.safeTransferFrom(from, address(this), amount);
if (stakeFromReserve) {
// redondant in current implementation
require((REWARD_TOKEN == STAKED_TOKEN), 'SHOULD_BE_SETTLED');
REWARD_TOKEN.safeTransferFrom(REWARDS_VAULT, address(this), amount);
} else {
STAKED_TOKEN.safeTransferFrom(from, address(this), amount);
}

emit Staked(from, to, amount, sharesToMint);
}