Skip to content

Commit

Permalink
Update limited token pool
Browse files Browse the repository at this point in the history
- Update limitedTokenPool contract
- Add upgrade script for limitedTokenPoolBeacon
- Upgrade limitedTokenPoolBeacon
  • Loading branch information
SigismundSchlomo committed Oct 14, 2024
1 parent f86bba2 commit 567050e
Show file tree
Hide file tree
Showing 3 changed files with 366 additions and 3 deletions.
334 changes: 334 additions & 0 deletions .openzeppelin/unknown-30746.json
Original file line number Diff line number Diff line change
Expand Up @@ -3070,6 +3070,340 @@
"f1bb44122edd6286070134dda7b7d29673f84486f1e5ce51a6c803974e7fe448": {
"address": "0xD322465FA2ff95e5B52309b795B17897F244f502",
"txHash": "0x23611b93329c3df460f125c5db60a1f017f83bb84ae745325dedda6139f6c23d",
"layout": {
"solcVersion": "0.8.17",
"storage": [
{
"label": "_initialized",
"offset": 0,
"slot": "0",
"type": "t_uint8",
"contract": "Initializable",
"src": "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol:63",
"retypedFrom": "bool"
},
{
"label": "_initializing",
"offset": 1,
"slot": "0",
"type": "t_bool",
"contract": "Initializable",
"src": "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol:68"
},
{
"label": "_roles",
"offset": 0,
"slot": "1",
"type": "t_mapping(t_bytes32,t_struct(RoleData)3267_storage)",
"contract": "AccessControl",
"src": "@openzeppelin/contracts/access/AccessControl.sol:56"
},
{
"label": "active",
"offset": 0,
"slot": "2",
"type": "t_bool",
"contract": "LimitedTokenPool",
"src": "contracts/staking/token/LimitedTokenPool.sol:54"
},
{
"label": "lockKeeper",
"offset": 1,
"slot": "2",
"type": "t_contract(LockKeeper)8142",
"contract": "LimitedTokenPool",
"src": "contracts/staking/token/LimitedTokenPool.sol:56"
},
{
"label": "rewardsBank",
"offset": 0,
"slot": "3",
"type": "t_contract(RewardsBank)10815",
"contract": "LimitedTokenPool",
"src": "contracts/staking/token/LimitedTokenPool.sol:57"
},
{
"label": "mainConfig",
"offset": 0,
"slot": "4",
"type": "t_struct(MainConfig)17879_storage",
"contract": "LimitedTokenPool",
"src": "contracts/staking/token/LimitedTokenPool.sol:59"
},
{
"label": "limitsConfig",
"offset": 0,
"slot": "8",
"type": "t_struct(LimitsConfig)17902_storage",
"contract": "LimitedTokenPool",
"src": "contracts/staking/token/LimitedTokenPool.sol:60"
},
{
"label": "info",
"offset": 0,
"slot": "19",
"type": "t_struct(Info)17913_storage",
"contract": "LimitedTokenPool",
"src": "contracts/staking/token/LimitedTokenPool.sol:61"
},
{
"label": "stakers",
"offset": 0,
"slot": "24",
"type": "t_mapping(t_address,t_struct(Staker)17926_storage)",
"contract": "LimitedTokenPool",
"src": "contracts/staking/token/LimitedTokenPool.sol:63"
}
],
"types": {
"t_address": {
"label": "address",
"numberOfBytes": "20"
},
"t_bool": {
"label": "bool",
"numberOfBytes": "1"
},
"t_bytes32": {
"label": "bytes32",
"numberOfBytes": "32"
},
"t_contract(LockKeeper)8142": {
"label": "contract LockKeeper",
"numberOfBytes": "20"
},
"t_contract(RewardsBank)10815": {
"label": "contract RewardsBank",
"numberOfBytes": "20"
},
"t_mapping(t_address,t_bool)": {
"label": "mapping(address => bool)",
"numberOfBytes": "32"
},
"t_mapping(t_address,t_struct(Staker)17926_storage)": {
"label": "mapping(address => struct LimitedTokenPool.Staker)",
"numberOfBytes": "32"
},
"t_mapping(t_bytes32,t_struct(RoleData)3267_storage)": {
"label": "mapping(bytes32 => struct AccessControl.RoleData)",
"numberOfBytes": "32"
},
"t_string_storage": {
"label": "string",
"numberOfBytes": "32"
},
"t_struct(Info)17913_storage": {
"label": "struct LimitedTokenPool.Info",
"members": [
{
"label": "totalStake",
"type": "t_uint256",
"offset": 0,
"slot": "0"
},
{
"label": "totalDeposit",
"type": "t_uint256",
"offset": 0,
"slot": "1"
},
{
"label": "totalRewards",
"type": "t_uint256",
"offset": 0,
"slot": "2"
},
{
"label": "lastInterestUpdate",
"type": "t_uint256",
"offset": 0,
"slot": "3"
},
{
"label": "totalRewardsDebt",
"type": "t_uint256",
"offset": 0,
"slot": "4"
}
],
"numberOfBytes": "160"
},
"t_struct(LimitsConfig)17902_storage": {
"label": "struct LimitedTokenPool.LimitsConfig",
"members": [
{
"label": "rewardTokenPrice",
"type": "t_uint256",
"offset": 0,
"slot": "0"
},
{
"label": "interest",
"type": "t_uint256",
"offset": 0,
"slot": "1"
},
{
"label": "interestRate",
"type": "t_uint256",
"offset": 0,
"slot": "2"
},
{
"label": "minDepositValue",
"type": "t_uint256",
"offset": 0,
"slot": "3"
},
{
"label": "minStakeValue",
"type": "t_uint256",
"offset": 0,
"slot": "4"
},
{
"label": "fastUnstakePenalty",
"type": "t_uint256",
"offset": 0,
"slot": "5"
},
{
"label": "unstakeLockPeriod",
"type": "t_uint256",
"offset": 0,
"slot": "6"
},
{
"label": "stakeLockPeriod",
"type": "t_uint256",
"offset": 0,
"slot": "7"
},
{
"label": "maxTotalStakeValue",
"type": "t_uint256",
"offset": 0,
"slot": "8"
},
{
"label": "maxStakePerUserValue",
"type": "t_uint256",
"offset": 0,
"slot": "9"
},
{
"label": "stakeLimitsMultiplier",
"type": "t_uint256",
"offset": 0,
"slot": "10"
}
],
"numberOfBytes": "352"
},
"t_struct(MainConfig)17879_storage": {
"label": "struct LimitedTokenPool.MainConfig",
"members": [
{
"label": "name",
"type": "t_string_storage",
"offset": 0,
"slot": "0"
},
{
"label": "limitsMultiplierToken",
"type": "t_address",
"offset": 0,
"slot": "1"
},
{
"label": "profitableToken",
"type": "t_address",
"offset": 0,
"slot": "2"
},
{
"label": "rewardToken",
"type": "t_address",
"offset": 0,
"slot": "3"
}
],
"numberOfBytes": "128"
},
"t_struct(RoleData)3267_storage": {
"label": "struct AccessControl.RoleData",
"members": [
{
"label": "members",
"type": "t_mapping(t_address,t_bool)",
"offset": 0,
"slot": "0"
},
{
"label": "adminRole",
"type": "t_bytes32",
"offset": 0,
"slot": "1"
}
],
"numberOfBytes": "64"
},
"t_struct(Staker)17926_storage": {
"label": "struct LimitedTokenPool.Staker",
"members": [
{
"label": "stake",
"type": "t_uint256",
"offset": 0,
"slot": "0"
},
{
"label": "deposit",
"type": "t_uint256",
"offset": 0,
"slot": "1"
},
{
"label": "rewardsDebt",
"type": "t_uint256",
"offset": 0,
"slot": "2"
},
{
"label": "claimableRewards",
"type": "t_uint256",
"offset": 0,
"slot": "3"
},
{
"label": "lockedWithdrawal",
"type": "t_uint256",
"offset": 0,
"slot": "4"
},
{
"label": "stakedAt",
"type": "t_uint256",
"offset": 0,
"slot": "5"
}
],
"numberOfBytes": "192"
},
"t_uint256": {
"label": "uint256",
"numberOfBytes": "32"
},
"t_uint8": {
"label": "uint8",
"numberOfBytes": "1"
}
}
}
},
"7258e50e633cb323820369eda218978cdae2671f579ac4df50d54d73a0d78985": {
"address": "0x7f0E4Fe3641dCAf21e6202BD914481A3C00D4818",
"txHash": "0xf40021fb46d265f4ce1d3cbc586c7081d70fd6fe92e7cd26ac009063ebc7c0ad",
"layout": {
"solcVersion": "0.8.17",
"storage": [
Expand Down
8 changes: 5 additions & 3 deletions contracts/staking/token/LimitedTokenPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ contract LimitedTokenPool is Initializable, AccessControl, IOnBlockListener {
IERC20(mainConfig.profitableToken).safeTransferFrom(msg.sender, address(this), amount);
}

_calcClaimableRewards(msg.sender);
uint rewardsAmount = _calcRewards(amount);

stakers[msg.sender].stake += amount;
Expand All @@ -175,6 +176,8 @@ contract LimitedTokenPool is Initializable, AccessControl, IOnBlockListener {
require(stakers[msg.sender].stake >= amount, "Not enough stake");
require(block.timestamp - stakers[msg.sender].stakedAt >= limitsConfig.stakeLockPeriod, "Stake is locked");

_calcClaimableRewards(msg.sender);
_claimRewards(msg.sender);
uint rewardsAmount = _calcRewards(amount);

stakers[msg.sender].stake -= amount;
Expand Down Expand Up @@ -205,15 +208,15 @@ contract LimitedTokenPool is Initializable, AccessControl, IOnBlockListener {
);
}

_claimRewards(msg.sender);

emit UnstakeLocked(msg.sender, amount + canceledAmount, block.timestamp + limitsConfig.unstakeLockPeriod, block.timestamp);
}

function unstakeFast(uint amount) public {
require(stakers[msg.sender].stake >= amount, "Not enough stake");
require(block.timestamp - stakers[msg.sender].stakedAt >= limitsConfig.stakeLockPeriod, "Stake is locked");

_calcClaimableRewards(msg.sender);
_claimRewards(msg.sender);
uint rewardsAmount = _calcRewards(amount);

stakers[msg.sender].stake -= amount;
Expand All @@ -229,7 +232,6 @@ contract LimitedTokenPool is Initializable, AccessControl, IOnBlockListener {
} else {
IERC20(mainConfig.profitableToken).safeTransfer(msg.sender, amount - penalty);
}
_claimRewards(msg.sender);
}

function claim() public {
Expand Down
Loading

0 comments on commit 567050e

Please sign in to comment.