update address for staking

This commit is contained in:
CounterFire2023 2024-09-10 15:57:28 +08:00
parent cf6dd1d49b
commit 6ea5075c4e
11 changed files with 2109 additions and 791 deletions

View File

@ -51,9 +51,11 @@ const mint = {
const staking = {
cec: '0xe34c5ea0c3083d11a735dc0609533b92130319f5',
// stake cec时, 每质押一个cec, 每年可获得的收益
rewardPerSecond: BigInt(1.5 * 10 ** 18) / BigInt(365 * 24 * 60 * 60),
// rewardPerSecond: BigInt(1.5 * 10 ** 18) / BigInt(365 * 24 * 60 * 60),
rewardPerSecond: BigInt(1.5 * 10 ** 18) / BigInt(24 * 60 * 60),
// esCEC 转化为cec的时间
vestingDuration: BigInt(365 * 24 * 60 * 60)
// vestingDuration: BigInt(365 * 24 * 60 * 60)
vestingDuration: BigInt(60 * 60)
}
var config = {

View File

@ -73,33 +73,6 @@ contract RewardRouter is ReentrancyGuard, Governable {
IRewardTracker(stakedCecTracker).claimForAccount(account, account);
}
function handleRewards(
bool _shouldClaimCec,
bool _shouldStakeCec,
bool _shouldClaimEsCec,
bool _shouldStakeEsCec
) external nonReentrant {
address account = msg.sender;
uint256 cecAmount = 0;
if (_shouldClaimCec) {
cecAmount = IVester(cecVester).claimForAccount(account, account);
}
if (_shouldStakeCec && cecAmount > 0) {
_stakeCec(account, account, cec, cecAmount);
}
uint256 esCecAmount = 0;
if (_shouldClaimEsCec) {
esCecAmount = IRewardTracker(stakedCecTracker).claimForAccount(account, account);
}
if (_shouldStakeEsCec && esCecAmount > 0) {
_stakeCec(account, account, esCec, esCecAmount);
}
}
function _stakeCec(address _fundingAccount, address _account, address _token, uint256 _amount) private {
require(_amount > 0, "invalid _amount");

View File

@ -20,7 +20,7 @@ const deployNFTClaim: DeployFunction = async function (hre: HardhatRuntimeEnviro
name: "stakedEsCecTracker",
type: "logic",
contractName: "RewardTracker",
args: ["Staked CEC", "sCEC"],
args: ["Staked esCEC", "essCEC"],
verify: true,
});

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -26,10 +26,19 @@
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.4) (utils/Context.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract Context {\n function _msgSender() internal view virtual returns (address) {\n return msg.sender;\n }\n\n function _msgData() internal view virtual returns (bytes calldata) {\n return msg.data;\n }\n\n function _contextSuffixLength() internal view virtual returns (uint256) {\n return 0;\n }\n}\n"
},
"contracts/activity/CECDistributor.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.19;\n\nimport {ReentrancyGuard} from \"@openzeppelin/contracts/security/ReentrancyGuard.sol\";\nimport {Pausable} from \"@openzeppelin/contracts/security/Pausable.sol\";\nimport {IERC20} from \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport {SafeERC20} from \"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol\";\nimport {Ownable} from \"@openzeppelin/contracts/access/Ownable.sol\";\nimport {Governable} from \"../core/Governable.sol\";\n\n/**\n * @title CECDistributor\n * @dev CECDistributor is a contract for distributing CEC token with unlock time\n * after all data is set, transfer owner to timelock contract\n */\ncontract CECDistributor is ReentrancyGuard, Pausable, Ownable, Governable {\n using SafeERC20 for IERC20;\n\n struct ReleaseInfo {\n uint256 amount;\n uint256 releaseAllMonth;\n uint256 tgeRatio;\n uint256 lockDuration;\n }\n \n mapping(address account => ReleaseInfo info) public infoMap;\n mapping(address account => uint256 amount) public releasedMap;\n\n string public name;\n IERC20 public immutable cecToken;\n uint256 public constant DURATION = 86400 * 30;\n\n uint256 public start = 0;\n uint256 public constant TGE_PRECISION = 1000000;\n uint256 public lockDuration;\n\n event EventInfoUpdated(address indexed account, ReleaseInfo info);\n event EventCECClaimed(address indexed user, address indexed to, uint256 amount);\n event EventChangeAddress(address oldAddr, address newAddr);\n\n \n constructor(\n string memory _name,\n address _cecToken,\n uint256 _start\n ) {\n name = _name;\n cecToken = IERC20(_cecToken);\n start = _start;\n }\n\n /**\n * @dev Throws if called by any account other than the owner or gov.\n */\n modifier ownerOrGov() {\n require(msg.sender == owner() || msg.sender == gov, \"CECDistributor: forbidden\");\n _;\n }\n\n function setGov(address _gov) external override onlyOwner {\n gov = _gov;\n }\n /**\n * @dev update pause state\n * When encountering special circumstances that require an emergency pause of the contract,\n * the pause function can be called by the gov account to quickly pause the contract and minimize losses.\n */\n function pause() external ownerOrGov {\n _pause();\n }\n\n /**\n * @dev update unpause state\n */\n function unpause() external ownerOrGov {\n _unpause();\n }\n\n function withdrawToken(address to, uint256 amount) external onlyOwner {\n cecToken.safeTransfer(to, amount);\n }\n\n function updateInfo(address[] calldata accounts, ReleaseInfo[] calldata infos) external onlyOwner {\n require(accounts.length == infos.length, \"CECDistributor: invalid input\");\n for (uint256 i = 0; i < accounts.length; i++) {\n infoMap[accounts[i]] = infos[i];\n emit EventInfoUpdated(accounts[i], infos[i]);\n }\n }\n\n function calcClaimAmount(address user) public view whenNotPaused returns (uint256) {\n require(infoMap[user].amount > 0, \"CECDistributor: not in whitelist\");\n require(block.timestamp >= start, \"CECDistributor: not in claim time\");\n uint256 claimAmount = 0;\n uint256 tgeAmount = 0;\n ReleaseInfo memory info = infoMap[user];\n if (info.tgeRatio > 0) {\n tgeAmount = ((info.amount * info.tgeRatio) / TGE_PRECISION);\n claimAmount += tgeAmount;\n }\n if (block.timestamp > start + info.lockDuration) {\n uint256 monthNum = (block.timestamp - start - info.lockDuration) / DURATION;\n if (monthNum <= info.releaseAllMonth) {\n claimAmount += (((info.amount - tgeAmount) * monthNum) / info.releaseAllMonth);\n } else {\n claimAmount = info.amount;\n }\n }\n claimAmount -= releasedMap[user];\n return claimAmount;\n }\n\n function claim(address to) external nonReentrant whenNotPaused returns (uint256) {\n require(start > 0, \"CECDistributor: start isn't init\");\n require(to != address(0), \"CECDistributor: invalid address\");\n address _user = _msgSender();\n uint256 amount = calcClaimAmount(_user);\n if (amount > 0) {\n releasedMap[_user] = releasedMap[_user] + amount;\n cecToken.safeTransfer(to, amount);\n emit EventCECClaimed(_user, to, amount);\n }\n return amount;\n }\n\n function changeAddress(address from, address to) external {\n require(infoMap[to].amount == 0, \"CECDistributor: new addr is in whitelist\");\n require(infoMap[from].amount > 0, \"CECDistributor: not in whitelist\");\n address _sender = _msgSender();\n require(_sender == owner() || _sender == from, \"CECDistributor: sender not allowed\");\n infoMap[to] = infoMap[from];\n delete infoMap[from];\n releasedMap[to] = releasedMap[from];\n releasedMap[from] = 0;\n emit EventChangeAddress(from, to);\n }\n}\n"
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.19;\n\nimport {ReentrancyGuard} from \"@openzeppelin/contracts/security/ReentrancyGuard.sol\";\nimport {Pausable} from \"@openzeppelin/contracts/security/Pausable.sol\";\nimport {IERC20} from \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport {SafeERC20} from \"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol\";\nimport {Ownable} from \"@openzeppelin/contracts/access/Ownable.sol\";\nimport {Governable} from \"../core/Governable.sol\";\n\n/**\n * @title CECDistributor\n * @dev CECDistributor is a contract for distributing CEC token with unlock time\n * after all data is set, transfer owner to timelock contract\n */\ncontract CECDistributor is ReentrancyGuard, Pausable, Ownable, Governable {\n using SafeERC20 for IERC20;\n\n struct ReleaseInfo {\n uint256 amount;\n uint256 releaseAllMonth;\n uint256 tgeRatio;\n uint256 lockDuration;\n }\n \n mapping(address account => ReleaseInfo info) public infoMap;\n mapping(address account => uint256 amount) public releasedMap;\n\n string public name;\n IERC20 public immutable cecToken;\n uint256 public constant DURATION = 86400 * 30;\n\n uint256 public start = 0;\n uint256 public constant TGE_PRECISION = 1000000;\n\n event EventInfoUpdated(address indexed account, ReleaseInfo info);\n event EventCECClaimed(address indexed user, address indexed to, uint256 amount);\n event EventChangeAddress(address oldAddr, address newAddr);\n\n \n constructor(\n string memory _name,\n address _cecToken,\n uint256 _start\n ) {\n name = _name;\n cecToken = IERC20(_cecToken);\n start = _start;\n }\n\n /**\n * @dev Throws if called by any account other than the owner or gov.\n */\n modifier ownerOrGov() {\n require(msg.sender == owner() || msg.sender == gov, \"CECDistributor: forbidden\");\n _;\n }\n\n function setGov(address _gov) external override onlyOwner {\n gov = _gov;\n }\n /**\n * @dev update pause state\n * When encountering special circumstances that require an emergency pause of the contract,\n * the pause function can be called by the gov account to quickly pause the contract and minimize losses.\n */\n function pause() external ownerOrGov {\n _pause();\n }\n\n /**\n * @dev update unpause state\n */\n function unpause() external ownerOrGov {\n _unpause();\n }\n\n function withdrawToken(address to, uint256 amount) external onlyOwner {\n cecToken.safeTransfer(to, amount);\n }\n\n function updateInfo(address[] calldata accounts, ReleaseInfo[] calldata infos) external onlyOwner {\n require(accounts.length == infos.length, \"CECDistributor: invalid input\");\n for (uint256 i = 0; i < accounts.length; i++) {\n infoMap[accounts[i]] = infos[i];\n emit EventInfoUpdated(accounts[i], infos[i]);\n }\n }\n\n function calcClaimAmount(address user) public view whenNotPaused returns (uint256) {\n require(infoMap[user].amount > 0, \"CECDistributor: not in whitelist\");\n require(block.timestamp >= start, \"CECDistributor: not in claim time\");\n uint256 claimAmount = 0;\n uint256 tgeAmount = 0;\n ReleaseInfo memory info = infoMap[user];\n if (info.tgeRatio > 0) {\n tgeAmount = ((info.amount * info.tgeRatio) / TGE_PRECISION);\n claimAmount += tgeAmount;\n }\n if (block.timestamp > start + info.lockDuration) {\n uint256 monthNum = (block.timestamp - start - info.lockDuration) / DURATION;\n if (monthNum <= info.releaseAllMonth) {\n claimAmount += (((info.amount - tgeAmount) * monthNum) / info.releaseAllMonth);\n } else {\n claimAmount = info.amount;\n }\n }\n claimAmount -= releasedMap[user];\n return claimAmount;\n }\n\n function claim(address to) external nonReentrant whenNotPaused returns (uint256) {\n require(start > 0, \"CECDistributor: start isn't init\");\n require(to != address(0), \"CECDistributor: invalid address\");\n address _user = _msgSender();\n uint256 amount = calcClaimAmount(_user);\n if (amount > 0) {\n releasedMap[_user] = releasedMap[_user] + amount;\n cecToken.safeTransfer(to, amount);\n emit EventCECClaimed(_user, to, amount);\n }\n return amount;\n }\n\n function changeAddress(address from, address to) external {\n require(infoMap[to].amount == 0, \"CECDistributor: new addr is in whitelist\");\n require(infoMap[from].amount > 0, \"CECDistributor: not in whitelist\");\n address _sender = _msgSender();\n require(_sender == owner() || _sender == from, \"CECDistributor: sender not allowed\");\n infoMap[to] = infoMap[from];\n delete infoMap[from];\n releasedMap[to] = releasedMap[from];\n releasedMap[from] = 0;\n emit EventChangeAddress(from, to);\n }\n}\n"
},
"contracts/core/Governable.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.19;\n\ncontract Governable {\n address public gov;\n\n constructor() {\n gov = msg.sender;\n }\n\n modifier onlyGov() {\n require(msg.sender == gov, \"Governable: forbidden\");\n _;\n }\n\n function setGov(address _gov) external virtual onlyGov {\n gov = _gov;\n }\n}\n"
},
"contracts/staking/interfaces/IRewardTracker.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.19;\n\ninterface IRewardTracker {\n function depositBalances(address _account, address _depositToken) external view returns (uint256);\n function stakedAmounts(address _account) external view returns (uint256);\n function updateRewards() external;\n function stake(address _depositToken, uint256 _amount) external;\n function stakeForAccount(address _fundingAccount, address _account, address _depositToken, uint256 _amount) external;\n function unstake(address _depositToken, uint256 _amount) external;\n function unstakeForAccount(address _account, address _depositToken, uint256 _amount, address _receiver) external;\n function tokensPerInterval() external view returns (uint256);\n function claim(address _receiver) external returns (uint256);\n function claimForAccount(address _account, address _receiver) external returns (uint256);\n function claimable(address _account) external view returns (uint256);\n function averageStakedAmounts(address _account) external view returns (uint256);\n function cumulativeRewards(address _account) external view returns (uint256);\n}\n"
},
"contracts/staking/interfaces/IVester.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.19;\n\ninterface IVester {\n function needCheckStake() external view returns (bool);\n function updateVesting(address _account) external;\n\n function rewardTracker() external view returns (address);\n\n function claimForAccount(address _account, address _receiver) external returns (uint256);\n\n function claimable(address _account) external view returns (uint256);\n function cumulativeClaimAmounts(address _account) external view returns (uint256);\n function claimedAmounts(address _account) external view returns (uint256);\n function pairAmounts(address _account) external view returns (uint256);\n function getVestedAmount(address _account) external view returns (uint256);\n function cumulativeRewardDeductions(address _account) external view returns (uint256);\n function bonusRewards(address _account) external view returns (uint256);\n\n function setCumulativeRewardDeductions(address _account, uint256 _amount) external;\n function setBonusRewards(address _account, uint256 _amount) external;\n\n function getMaxVestableAmount(address _account) external view returns (uint256);\n function getCombinedAverageStakedAmount(address _account) external view returns (uint256);\n}\n"
},
"contracts/staking/RewardRouter.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.19;\n\nimport {IERC20} from \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport {ReentrancyGuard} from \"@openzeppelin/contracts/security/ReentrancyGuard.sol\";\nimport {SafeERC20} from \"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol\";\n\nimport {IRewardTracker} from \"./interfaces/IRewardTracker.sol\";\nimport {IVester} from \"./interfaces/IVester.sol\";\nimport {Governable} from \"../core/Governable.sol\";\n\ncontract RewardRouter is ReentrancyGuard, Governable {\n using SafeERC20 for IERC20;\n\n address public cec;\n address public esCec;\n\n address public stakedCecTracker;\n address public cecVester;\n\n event StakeCec(address account, address token, uint256 amount);\n event UnstakeCec(address account, address token, uint256 amount);\n\n constructor(address _cec, address _esCec, address _stakedCecTracker, address _cecVester) {\n cec = _cec;\n esCec = _esCec;\n stakedCecTracker = _stakedCecTracker;\n cecVester = _cecVester;\n }\n\n // to help users who accidentally send their tokens to this contract\n function withdrawToken(address _token, address _account, uint256 _amount) external onlyGov {\n IERC20(_token).safeTransfer(_account, _amount);\n }\n\n function batchStakeCecForAccount(\n address[] memory _accounts,\n uint256[] memory _amounts\n ) external nonReentrant onlyGov {\n address _cec = cec;\n for (uint256 i = 0; i < _accounts.length; i++) {\n _stakeCec(msg.sender, _accounts[i], _cec, _amounts[i]);\n }\n }\n\n function stakeCecForAccount(address _account, uint256 _amount) external nonReentrant onlyGov {\n _stakeCec(msg.sender, _account, cec, _amount);\n }\n\n function stakeCec(uint256 _amount) external nonReentrant {\n _stakeCec(msg.sender, msg.sender, cec, _amount);\n }\n\n function stakeEsCec(uint256 _amount) external nonReentrant {\n _stakeCec(msg.sender, msg.sender, esCec, _amount);\n }\n\n function unstakeCec(uint256 _amount) external nonReentrant {\n // check if the user has staked CEC in the vester\n if (IVester(cecVester).needCheckStake()) {\n IVester(cecVester).updateVesting(msg.sender);\n require(IERC20(cecVester).balanceOf(msg.sender) + _amount <= IRewardTracker(stakedCecTracker).depositBalances(msg.sender, cec), \"RewardRouter: insufficient CEC balance\");\n }\n _unstakeCec(msg.sender, cec, _amount);\n }\n\n function unstakeEsCec(uint256 _amount) external nonReentrant {\n _unstakeCec(msg.sender, esCec, _amount);\n }\n\n function claim() external nonReentrant {\n address account = msg.sender;\n IRewardTracker(stakedCecTracker).claimForAccount(account, account);\n }\n\n function _stakeCec(address _fundingAccount, address _account, address _token, uint256 _amount) private {\n require(_amount > 0, \"invalid _amount\");\n\n IRewardTracker(stakedCecTracker).stakeForAccount(_fundingAccount, _account, _token, _amount);\n\n emit StakeCec(_account, _token, _amount);\n }\n\n function _unstakeCec(address _account, address _token, uint256 _amount) private {\n require(_amount > 0, \"invalid _amount\");\n // uint256 balance = IRewardTracker(stakedCecTracker).stakedAmounts(_account);\n IRewardTracker(stakedCecTracker).unstakeForAccount(_account, _token, _amount, _account);\n\n emit UnstakeCec(_account, _token, _amount);\n }\n}\n"
}
},
"settings": {

File diff suppressed because one or more lines are too long

View File

@ -16,5 +16,29 @@
"type": "logic",
"json": "assets/contracts/TokenClaim.json",
"address": "0x899365493273d8d7761E867B493946A2700A9ecC"
},
{
"name": "FundraisingDistributor",
"type": "logic",
"json": "assets/contracts/CECDistributor.json",
"address": "0x4A2c863C403e1E96e085506E618F3Ef5845e9bEE"
},
{
"name": "TeamDistributor",
"type": "logic",
"json": "assets/contracts/CECDistributor.json",
"address": "0xc2159fb9dC322dD7b5A513a5A008345b3f5C7052"
},
{
"name": "AdvisoryDistributor",
"type": "logic",
"json": "assets/contracts/CECDistributor.json",
"address": "0xFE143344a424Bdf09F2cA32acaC4009e20c1C344"
},
{
"name": "EcosystemDistributor",
"type": "logic",
"json": "assets/contracts/CECDistributor.json",
"address": "0x8319891E6c805934b9d91E3182998956A36da8EE"
}
]

View File

@ -29,48 +29,6 @@
"json": "assets/contracts/EsToken.json",
"address": "0x1FbA3F84e62163069050f1156b73C008722136A3"
},
{
"name": "stakedCecTracker",
"type": "logic",
"json": "assets/contracts/RewardTracker.json",
"address": "0x409890BEEf967e63b52F7BB13A986eD4900691Ed"
},
{
"name": "stakedCecDistributor",
"type": "logic",
"json": "assets/contracts/RewardDistributor.json",
"address": "0x613884c63F9c9e7Aa02c659364E060AaA1c8dB33"
},
{
"name": "vester",
"type": "logic",
"json": "assets/contracts/Vester.json",
"address": "0x49dcb6Ba542374147278efe9163a6E94e5E40762"
},
{
"name": "stakedCecRouter",
"type": "logic",
"json": "assets/contracts/RewardRouter.json",
"address": "0xCB3dBb5d893743CE6f7c959CbBb44AfE0b83a04F"
},
{
"name": "stakedEsCecTracker",
"type": "logic",
"json": "assets/contracts/RewardTracker.json",
"address": "0x3299431803704C63941531d9d894CB095D15C4bC"
},
{
"name": "stakedEsCecDistributor",
"type": "logic",
"json": "assets/contracts/RewardDistributor.json",
"address": "0x67869546655e1A6A09b9877aEA858cC47444172D"
},
{
"name": "stakedEsCecRouter",
"type": "logic",
"json": "assets/contracts/RewardRouter.json",
"address": "0x775d7Dbc06835c78437C8783fE11937E46F9ec6e"
},
{
"name": "TestCEC",
"type": "erc20",
@ -82,5 +40,47 @@
"type": "logic",
"json": "assets/contracts/CECDistributor.json",
"address": "0x19E3F7E52AbbEED5A0A0e3e2F8892F4dd1079239"
},
{
"name": "stakedCecTracker",
"type": "logic",
"json": "assets/contracts/RewardTracker.json",
"address": "0xEC3caFD4175A03d1Aa867D9E77e354386Cfa61F6"
},
{
"name": "stakedCecDistributor",
"type": "logic",
"json": "assets/contracts/RewardDistributor.json",
"address": "0xE4546FA6DdC15442a1FED835e7A007b001213495"
},
{
"name": "vester",
"type": "logic",
"json": "assets/contracts/Vester.json",
"address": "0x41a7f94f0B3b615F84c7084F45556FEf1bd18A18"
},
{
"name": "stakedCecRouter",
"type": "logic",
"json": "assets/contracts/RewardRouter.json",
"address": "0xdA3f8b9fCD17D39B2fEa99F00A8aa44Fc188BbAD"
},
{
"name": "stakedEsCecTracker",
"type": "logic",
"json": "assets/contracts/RewardTracker.json",
"address": "0x880aC8D394141a700855a349D865FA54227d302e"
},
{
"name": "stakedEsCecDistributor",
"type": "logic",
"json": "assets/contracts/RewardDistributor.json",
"address": "0x994dE61dD536B22F7e3BDB77aa3ef55AeC938bFD"
},
{
"name": "stakedEsCecRouter",
"type": "logic",
"json": "assets/contracts/RewardRouter.json",
"address": "0x314c4A9853F354CA012064592d3315d81be03321"
}
]