编译器
0.8.17+commit.8df45f5f
文件 1 的 15:AccessControl.sol
pragma solidity ^0.8.0;
import "./IAccessControl.sol";
import "../utils/Context.sol";
import "../utils/Strings.sol";
import "../utils/introspection/ERC165.sol";
abstract contract AccessControl is Context, IAccessControl, ERC165 {
struct RoleData {
mapping(address => bool) members;
bytes32 adminRole;
}
mapping(bytes32 => RoleData) private _roles;
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
modifier onlyRole(bytes32 role) {
_checkRole(role);
_;
}
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
}
function hasRole(bytes32 role, address account) public view virtual override returns (bool) {
return _roles[role].members[account];
}
function _checkRole(bytes32 role) internal view virtual {
_checkRole(role, _msgSender());
}
function _checkRole(bytes32 role, address account) internal view virtual {
if (!hasRole(role, account)) {
revert(
string(
abi.encodePacked(
"AccessControl: account ",
Strings.toHexString(account),
" is missing role ",
Strings.toHexString(uint256(role), 32)
)
)
);
}
}
function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {
return _roles[role].adminRole;
}
function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
_grantRole(role, account);
}
function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
_revokeRole(role, account);
}
function renounceRole(bytes32 role, address account) public virtual override {
require(account == _msgSender(), "AccessControl: can only renounce roles for self");
_revokeRole(role, account);
}
function _setupRole(bytes32 role, address account) internal virtual {
_grantRole(role, account);
}
function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
bytes32 previousAdminRole = getRoleAdmin(role);
_roles[role].adminRole = adminRole;
emit RoleAdminChanged(role, previousAdminRole, adminRole);
}
function _grantRole(bytes32 role, address account) internal virtual {
if (!hasRole(role, account)) {
_roles[role].members[account] = true;
emit RoleGranted(role, account, _msgSender());
}
}
function _revokeRole(bytes32 role, address account) internal virtual {
if (hasRole(role, account)) {
_roles[role].members[account] = false;
emit RoleRevoked(role, account, _msgSender());
}
}
}
文件 2 的 15:Address.sol
pragma solidity ^0.8.1;
library Address {
function isContract(address account) internal view returns (bool) {
return account.code.length > 0;
}
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
if (returndata.length > 0) {
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
文件 3 的 15:ChromiaDelegation.sol
pragma solidity ^0.8.17;
import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol";
import {ReentrancyGuard} from "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import {ITwoWeeksNotice} from "contracts/interfaces/ITwoWeeksNotice.sol";
struct DelegationChange {
address delegatedTo;
uint72 balance;
uint16 nextChange;
}
struct DelegationState {
uint16 claimedEpoch;
uint16 latestChangeEpoch;
uint96 processed;
uint64 processedDate;
uint96 balanceAtProcessed;
mapping(uint16 => DelegationChange) delegationTimeline;
}
struct RateTimeline {
uint16 latestChangeEpoch;
mapping(uint16 => uint16) timeline;
mapping(uint16 => uint16) nextChange;
}
struct ProviderStateChange {
bool lostWhitelist;
bool gainedWhitelist;
uint96 delegationsIncrease;
uint96 delegationsDecrease;
uint16 nextChangeDelegations;
uint16 nextChangeWhitelist;
}
struct AdditionalReward {
uint16 additionalRewardPerYieldPeriodPerToken;
uint16 epoch;
}
struct ProviderState {
bool whitelisted;
uint16 claimedEpochReward;
uint16 latestDelegationsChange;
uint16 latestWhitelistChange;
uint128 latestTotalDelegation;
uint16 latestTotalDelegationEpoch;
AdditionalReward[] additionalRewards;
mapping(uint16 => ProviderStateChange) providerStateTimeline;
}
contract ChromiaDelegation is AccessControl, ReentrancyGuard {
using SafeERC20 for IERC20Metadata;
bytes32 public constant WHITELIST_ADMIN = keccak256("WHITELIST_ADMIN");
bytes32 public constant RATE_ADMIN = keccak256("RATE_ADMIN");
bytes32 public constant ADDITIONAL_REWARD_ADMIN = keccak256("ADDITIONAL_REWARD_ADMIN");
uint32 public immutable yieldPeriod;
uint32 public immutable epochLength;
uint32 public immutable startTime;
ITwoWeeksNotice public immutable twn;
IERC20Metadata public immutable token;
address public bank;
uint128 private immutable minorTokenUnitsInMajor;
mapping(address => DelegationState) public delegatorStates;
mapping(address => ProviderState) public providerStates;
RateTimeline private delegatorYieldTimeline;
RateTimeline private providerRewardRateTimeline;
event Delegated(address indexed delegator, address indexed provider, uint128 amount);
event Undelegated(address indexed delegator, address indexed provider, uint128 amount);
event DelegatorYieldRateChanged(uint16 newRate);
event ProviderTotalDelegationRateChanged(uint16 newRate);
event AddedWhitelist(address provider);
event RemovedWhitelist(address provider);
event RevisedDelegation(address delegator);
event ResetAccount(address delegator);
event GrantedAdditionalReward(address provider, uint16 rate);
event ClaimedYield(address delegator, uint128 amount);
event ProviderClaimedTotalDelegationYield(address provider, uint128 amount);
string private constant INVALID_WITHDRAW_ERROR = "Withdrawn without undelegating";
string private constant TIMELINE_MISMATCH_ERROR = "Timeline does not match with TWN.";
string private constant UNAUTHORISED_ERROR = "Unauthorized";
string private constant CANNOT_CHANGE_WITHDRAWAL_ERROR = "Cannot change delegation while withdrawing";
string private constant WITHDRAWAL_NOT_REQUESTED_ERROR = "Withdraw has not been requested";
string private constant MUST_HAVE_STAKE_ERROR = "Must have a stake to delegate";
string private constant MUST_WHITELISTED_ERROR = "Provider must be whitelisted";
string private constant MUST_AFTER_START_ERROR = "Time must be after start time";
string private constant CHANGE_TOO_RECENT_ERROR = "Change is too recent";
string private constant ZERO_REWARD_ERROR = "Reward is 0";
string private constant FIRST_DELEGATION_NEEDED_ERROR = "Address must make a first delegation.";
string private constant ALREADY_SYNCRONISED_ERROR = "Stake is synced";
constructor(
IERC20Metadata _token,
ITwoWeeksNotice _twn,
address _owner,
uint16 _delegatorYield,
uint16 _totalDelegationYield,
address _bank,
uint32 _yieldPeriodInSecs,
uint32 _epochLengthInYieldPeriods
) {
yieldPeriod = _yieldPeriodInSecs;
epochLength = _epochLengthInYieldPeriods * yieldPeriod;
startTime = uint32(block.timestamp) - epochLength;
_setupRole(DEFAULT_ADMIN_ROLE, _owner);
_setupRole(WHITELIST_ADMIN, _owner);
_setupRole(RATE_ADMIN, _owner);
_setupRole(ADDITIONAL_REWARD_ADMIN, _owner);
twn = _twn;
token = _token;
bank = _bank;
minorTokenUnitsInMajor = uint128(10 ** token.decimals());
delegatorYieldTimeline.timeline[1] = _delegatorYield;
delegatorYieldTimeline.nextChange[0] = 1;
delegatorYieldTimeline.latestChangeEpoch = 1;
providerRewardRateTimeline.timeline[1] = _totalDelegationYield;
providerRewardRateTimeline.nextChange[0] = 1;
providerRewardRateTimeline.latestChangeEpoch = 1;
}
function isStakeValid(address account) public view returns (bool) {
(, uint128 remoteAccumulated) = twn.getAccumulated(account);
return remoteAccumulated == delegatorStates[account].processed;
}
function setRewardRate(uint16 newRate) external {
setNewRate(newRate, delegatorYieldTimeline);
emit DelegatorYieldRateChanged(newRate);
}
function setProviderRewardRate(uint16 newRate) external {
setNewRate(newRate, providerRewardRateTimeline);
emit ProviderTotalDelegationRateChanged(newRate);
}
function setNewRate(uint16 newRate, RateTimeline storage rateTimeline) private {
require(hasRole(DEFAULT_ADMIN_ROLE, msg.sender) || hasRole(RATE_ADMIN, msg.sender), UNAUTHORISED_ERROR);
uint16 nextEpoch = getCurrentEpoch() + 1;
rateTimeline.timeline[nextEpoch] = newRate;
if (rateTimeline.latestChangeEpoch != nextEpoch) {
rateTimeline.nextChange[rateTimeline.latestChangeEpoch] = nextEpoch;
rateTimeline.latestChangeEpoch = nextEpoch;
}
}
function journalProviderWhitelistChange(ProviderState storage providerState) private returns (uint16 newLatestChange) {
ProviderStateChange storage nextChangeMapping = providerState.providerStateTimeline[providerState.latestWhitelistChange];
if (providerState.latestWhitelistChange != getCurrentEpoch()) {
nextChangeMapping.nextChangeWhitelist = getCurrentEpoch();
return getCurrentEpoch();
}
return providerState.latestWhitelistChange;
}
function journalProviderDelegationChange(ProviderState storage ps) private returns (uint16 newLatestChange) {
uint16 changeEpoch = getCurrentEpoch() + 1;
ProviderStateChange storage nextChangeMapping = ps.providerStateTimeline[ps.latestDelegationsChange];
if (ps.latestDelegationsChange != changeEpoch) {
nextChangeMapping.nextChangeDelegations = changeEpoch;
return changeEpoch;
}
return ps.latestDelegationsChange;
}
function journalDelegationChange(uint16 epoch, DelegationState storage userState) private returns (uint16 newLatestChange) {
DelegationChange storage nextChangeMapping = userState.delegationTimeline[userState.latestChangeEpoch];
if (userState.latestChangeEpoch != epoch) {
nextChangeMapping.nextChange = epoch;
return epoch;
}
return userState.latestChangeEpoch;
}
function getActiveProviderRewardRate(uint16 epoch) public view returns (uint128 activeRate, uint16 latestEpoch) {
return getActiveRate(epoch, providerRewardRateTimeline);
}
function getActiveYieldRate(uint16 epoch) public view returns (uint128 activeRate, uint16 latestEpoch) {
return getActiveRate(epoch, delegatorYieldTimeline);
}
function getActiveRate(uint16 epoch, RateTimeline storage rateTimeline) private view returns (uint128 activeRate, uint16 latestEpoch) {
if (epoch >= rateTimeline.latestChangeEpoch) {
return (rateTimeline.timeline[rateTimeline.latestChangeEpoch], rateTimeline.latestChangeEpoch);
}
uint16 nextChange = 0;
while (true) {
if (rateTimeline.nextChange[nextChange] > epoch) {
return (rateTimeline.timeline[nextChange], nextChange);
}
nextChange = rateTimeline.nextChange[nextChange];
}
}
function getActiveDelegation(address account, uint16 epoch) public view returns (DelegationChange memory activeDelegation, uint16 latestEpoch) {
DelegationState storage userState = delegatorStates[account];
if (userState.latestChangeEpoch == 0) {
return (activeDelegation, 0);
}
if (epoch >= userState.latestChangeEpoch) {
return (userState.delegationTimeline[userState.latestChangeEpoch], userState.latestChangeEpoch);
}
uint16 nextChange = 0;
while (true) {
if (userState.delegationTimeline[nextChange].nextChange > epoch) {
return (userState.delegationTimeline[nextChange], nextChange);
}
nextChange = userState.delegationTimeline[nextChange].nextChange;
}
}
function getWhitelisted(address account, uint16 epoch) public view returns (bool whitelisted, uint16 latestEpoch) {
ProviderState storage providerState = providerStates[account];
if (providerState.latestWhitelistChange == 0) {
return (false, 0);
}
ProviderStateChange storage psc;
if (epoch >= providerState.latestWhitelistChange) {
psc = providerState.providerStateTimeline[providerState.latestWhitelistChange];
if (psc.lostWhitelist) {
return (false, providerState.latestWhitelistChange);
} else if (psc.gainedWhitelist) {
return (true, providerState.latestWhitelistChange);
}
}
uint16 nextChange = 0;
while (true) {
if (providerState.providerStateTimeline[nextChange].nextChangeWhitelist > epoch) {
psc = providerState.providerStateTimeline[nextChange];
if (psc.lostWhitelist) {
return (false, nextChange);
} else if (psc.gainedWhitelist) {
return (true, nextChange);
}
}
nextChange = providerState.providerStateTimeline[nextChange].nextChangeWhitelist;
}
}
function getTotalDelegations(address provider) external view returns (uint128 totalDelegations) {
ProviderState storage providerState = providerStates[provider];
totalDelegations = providerState.latestTotalDelegation;
uint16 next = providerState.providerStateTimeline[providerState.latestTotalDelegationEpoch].nextChangeDelegations;
ProviderStateChange storage psc;
while (true) {
if (next == 0 || next > getCurrentEpoch() - 1) {
break;
}
psc = providerState.providerStateTimeline[next];
if (psc.delegationsIncrease != 0) {
totalDelegations += psc.delegationsIncrease;
}
if (psc.delegationsDecrease != 0) {
if (totalDelegations > psc.delegationsDecrease) {
totalDelegations -= psc.delegationsDecrease;
} else totalDelegations = 0;
}
next = providerState.providerStateTimeline[next].nextChangeDelegations;
}
}
function removeCurrentDelegationFromProvider(DelegationChange memory currentDelegation, uint16 currDelEpoch) private {
uint16 nextEpoch = getCurrentEpoch() + 1;
ProviderState storage ps = providerStates[currentDelegation.delegatedTo];
if (currDelEpoch >= ps.latestWhitelistChange) {
ps.providerStateTimeline[nextEpoch].delegationsDecrease += currentDelegation.balance;
ps.latestDelegationsChange = journalProviderDelegationChange(ps);
}
}
function addDelegation(DelegationState storage userState, uint16 epoch, address to, uint128 acc, uint64 since, uint64 delegateAmount) private {
userState.delegationTimeline[epoch] = DelegationChange(to, delegateAmount, 0);
userState.latestChangeEpoch = journalDelegationChange(epoch, userState);
userState.balanceAtProcessed = delegateAmount;
userState.processed = uint96(acc);
userState.processedDate = since;
}
function undelegate(address account) external nonReentrant {
(, , uint64 lockedUntil, uint64 since) = twn.getStakeState(account);
require(lockedUntil > 0, WITHDRAWAL_NOT_REQUESTED_ERROR);
DelegationState storage userState = delegatorStates[account];
(, uint128 acc) = twn.getAccumulated(msg.sender);
ensureSyncronisedDelegationState(userState, acc, since);
uint16 nextEpoch = getCurrentEpoch() + 1;
(DelegationChange memory currentDelegation, uint16 currDelEpoch) = getActiveDelegation(msg.sender, nextEpoch);
removeCurrentDelegationFromProvider(currentDelegation, currDelEpoch);
uint16 requestWithdrawEpoch = getEpoch(since);
if (currDelEpoch > requestWithdrawEpoch) {
(, uint16 prevDelEpoch) = getActiveDelegation(msg.sender, currDelEpoch - 1);
delete userState.delegationTimeline[currDelEpoch];
userState.delegationTimeline[prevDelEpoch].nextChange = 0;
userState.latestChangeEpoch = prevDelEpoch;
}
addDelegation(userState, requestWithdrawEpoch, address(0), acc, since, 0);
emit Undelegated(account, currentDelegation.delegatedTo, currentDelegation.balance);
}
function delegate(address to) external nonReentrant {
DelegationState storage userState = delegatorStates[msg.sender];
ProviderState storage ps = providerStates[to];
(, uint128 acc) = twn.getAccumulated(msg.sender);
(uint64 delegateAmount, , uint64 lockedUntil, uint64 since) = twn.getStakeState(msg.sender);
require(delegateAmount > 0, MUST_HAVE_STAKE_ERROR);
require(lockedUntil == 0, CANNOT_CHANGE_WITHDRAWAL_ERROR);
require(ps.whitelisted, MUST_WHITELISTED_ERROR);
uint16 nextEpoch = getCurrentEpoch() + 1;
(DelegationChange memory currentDelegation, uint16 currDelEpoch) = getActiveDelegation(msg.sender, nextEpoch);
if (currentDelegation.delegatedTo != address(0) && (currentDelegation.delegatedTo != to || currDelEpoch < ps.latestWhitelistChange)) {
removeCurrentDelegationFromProvider(currentDelegation, currDelEpoch);
}
if (userState.latestChangeEpoch == 0) {
userState.claimedEpoch = nextEpoch - 1;
} else {
ensureSyncronisedDelegationState(userState, acc, since);
}
addDelegation(userState, nextEpoch, to, acc, since, delegateAmount);
if (currentDelegation.delegatedTo != to || currDelEpoch < ps.latestWhitelistChange) {
ps.providerStateTimeline[nextEpoch].delegationsIncrease += delegateAmount;
} else {
ps.providerStateTimeline[nextEpoch].delegationsIncrease += delegateAmount - currentDelegation.balance;
}
ps.latestDelegationsChange = journalProviderDelegationChange(ps);
emit Delegated(msg.sender, to, delegateAmount);
}
function resetAccount() external {
DelegationState storage userState = delegatorStates[msg.sender];
require(userState.latestChangeEpoch > 0, FIRST_DELEGATION_NEEDED_ERROR);
(DelegationChange memory currentDelegation, uint16 currDelEpoch) = getActiveDelegation(msg.sender, getCurrentEpoch() + 1);
removeCurrentDelegationFromProvider(currentDelegation, currDelEpoch);
uint16 currChange = 0;
uint16 nextChange;
while (true) {
nextChange = userState.delegationTimeline[currChange].nextChange;
delete userState.delegationTimeline[currChange];
if (nextChange == 0) break;
currChange = nextChange;
}
delete delegatorStates[msg.sender];
emit ResetAccount(msg.sender);
}
function reviseDelegation(address account) external nonReentrant onlyRole(WHITELIST_ADMIN) {
require(!isStakeValid(account), ALREADY_SYNCRONISED_ERROR);
(, , , uint64 since) = twn.getStakeState(account);
require(block.timestamp - since > epochLength, CHANGE_TOO_RECENT_ERROR);
DelegationState storage userState = delegatorStates[account];
require(userState.latestChangeEpoch > 0, FIRST_DELEGATION_NEEDED_ERROR);
uint16 currentEpoch = getCurrentEpoch();
(DelegationChange memory currentDelegation, uint16 currDelEpoch) = getActiveDelegation(account, currentEpoch + 1);
removeCurrentDelegationFromProvider(currentDelegation, currDelEpoch);
userState.delegationTimeline[currentEpoch] = DelegationChange(address(0), 0, 0);
userState.latestChangeEpoch = journalDelegationChange(currentEpoch, userState);
emit RevisedDelegation(account);
}
function updateProviderDelegationRewardEstimate(address account) external nonReentrant returns (uint128 reward) {
return _updateProviderDelegationRewardEstimate(account);
}
function _updateProviderDelegationRewardEstimate(address account) internal returns (uint128 reward) {
ProviderState storage providerState = providerStates[account];
uint16 currentEpoch = getCurrentEpoch();
if (currentEpoch - 1 <= providerState.claimedEpochReward) {
return 0;
}
uint128 totalDelegations = providerState.latestTotalDelegation;
uint16 nextDC = providerState.latestTotalDelegationEpoch;
(uint128 activeRate, uint16 nextAR) = getActiveProviderRewardRate(providerState.claimedEpochReward + 1);
uint16 latestTotalDelegationEpoch = nextDC;
nextAR = providerRewardRateTimeline.nextChange[nextAR];
nextDC = providerState.providerStateTimeline[nextDC].nextChangeDelegations;
uint16 prev = providerState.claimedEpochReward + 1;
uint16 next = findSmallestNonZero(nextAR, nextDC);
if (next == 0 || next >= currentEpoch) {
next = currentEpoch;
}
ProviderStateChange storage psc;
while (true) {
reward += uint128((activeRate) * totalDelegations * epochLength) * (next - prev);
if (next == currentEpoch) break;
if (next == nextAR) {
activeRate = providerRewardRateTimeline.timeline[next];
nextAR = providerRewardRateTimeline.nextChange[next];
}
if (next == nextDC) {
psc = providerStates[account].providerStateTimeline[next];
if (psc.delegationsIncrease != 0) {
totalDelegations += psc.delegationsIncrease;
}
if (psc.delegationsDecrease != 0) {
if (totalDelegations > psc.delegationsDecrease) {
totalDelegations -= psc.delegationsDecrease;
} else totalDelegations = 0;
}
latestTotalDelegationEpoch = nextDC;
nextDC = providerState.providerStateTimeline[next].nextChangeDelegations;
}
prev = next;
next = findSmallestNonZero(nextAR, nextDC);
if (next == 0 || next >= currentEpoch) {
next = currentEpoch;
}
}
reward /= minorTokenUnitsInMajor * yieldPeriod;
providerState.latestTotalDelegation = totalDelegations;
providerState.latestTotalDelegationEpoch = latestTotalDelegationEpoch;
}
function estimateYield(address account) public view returns (uint128 reward) {
DelegationState storage userState = delegatorStates[account];
uint16 processedEpoch = userState.claimedEpoch;
uint16 currentEpoch = getCurrentEpoch();
if (currentEpoch - 1 <= processedEpoch) {
return 0;
}
(uint128 activeRate, uint16 nextAR) = getActiveYieldRate(processedEpoch + 1);
(DelegationChange memory activeDelegation, uint16 nextAD) = getActiveDelegation(account, processedEpoch + 1);
(bool whitelisted, uint16 nextWL) = getWhitelisted(activeDelegation.delegatedTo, processedEpoch + 1);
ProviderState storage providerState = providerStates[activeDelegation.delegatedTo];
nextAR = delegatorYieldTimeline.nextChange[nextAR];
nextAD = userState.delegationTimeline[nextAD].nextChange;
nextWL = providerState.providerStateTimeline[nextWL].nextChangeWhitelist;
uint16 prev = processedEpoch + 1;
uint16 next = findSmallestNonZero(nextAR, nextAD, nextWL);
if (next == 0 || next >= currentEpoch) {
next = currentEpoch;
}
while (true) {
if (whitelisted) {
reward += uint128((activeRate) * activeDelegation.balance * epochLength) * (next - prev);
if (providerState.additionalRewards.length > 0) {
for (uint i = providerState.additionalRewards.length - 1; i >= 0; i--) {
if (providerState.additionalRewards[i].epoch < prev) break;
if (
providerState.additionalRewards[i].epoch < next &&
providerState.additionalRewards[i].additionalRewardPerYieldPeriodPerToken > 0
) {
reward += uint128(
(providerState.additionalRewards[i].additionalRewardPerYieldPeriodPerToken) * activeDelegation.balance * epochLength
);
}
if (i == 0) break;
}
}
}
if (next == currentEpoch) break;
if (next == nextAR) {
activeRate = delegatorYieldTimeline.timeline[next];
nextAR = delegatorYieldTimeline.nextChange[next];
}
if (next == nextAD) {
DelegationChange memory oldDelegation = activeDelegation;
activeDelegation = userState.delegationTimeline[next];
if (oldDelegation.delegatedTo != activeDelegation.delegatedTo) {
providerState = providerStates[activeDelegation.delegatedTo];
(whitelisted, nextWL) = getWhitelisted(activeDelegation.delegatedTo, next);
nextWL = providerState.providerStateTimeline[nextWL].nextChangeWhitelist;
}
nextAD = userState.delegationTimeline[next].nextChange;
}
if (next == nextWL) {
ProviderStateChange storage psc = providerState.providerStateTimeline[next];
if (psc.lostWhitelist) {
whitelisted = false;
} else if (psc.gainedWhitelist) {
whitelisted = true;
}
nextWL = providerState.providerStateTimeline[next].nextChangeWhitelist;
}
prev = next;
next = findSmallestNonZero(nextAR, nextAD, nextWL);
if (next == 0 || next >= currentEpoch) {
next = currentEpoch;
}
}
reward /= (minorTokenUnitsInMajor * yieldPeriod);
}
function claimYield(address account) external nonReentrant {
require(delegatorStates[account].latestChangeEpoch > 0, FIRST_DELEGATION_NEEDED_ERROR);
require(isStakeValid(account), TIMELINE_MISMATCH_ERROR);
uint128 reward = estimateYield(account);
require(reward > 0, ZERO_REWARD_ERROR);
delegatorStates[account].claimedEpoch = getCurrentEpoch() - 1;
token.safeTransferFrom(bank, account, reward);
emit ClaimedYield(account, reward);
}
function claimProviderDelegationReward(address account) external nonReentrant {
_claimProviderDelegationReward(account);
}
function _claimProviderDelegationReward(address account) internal {
uint128 reward = _updateProviderDelegationRewardEstimate(account);
providerStates[account].claimedEpochReward = getCurrentEpoch() - 1;
token.safeTransferFrom(bank, account, reward);
emit ProviderClaimedTotalDelegationYield(account, reward);
}
function getCurrentEpoch() public view returns (uint16) {
return getEpoch(block.timestamp);
}
function getEpoch(uint time) public view returns (uint16) {
require(time > startTime, MUST_AFTER_START_ERROR);
return uint16((time - startTime) / epochLength);
}
function ensureSyncronisedDelegationState(DelegationState storage userState, uint128 acc, uint64 since) private view {
require(
(userState.balanceAtProcessed * (since - userState.processedDate)) / yieldPeriod + userState.processed <= acc,
INVALID_WITHDRAW_ERROR
);
}
function findSmallestNonZero(uint16 a, uint16 b, uint16 c) private pure returns (uint16 smallestNonZero) {
if (a == 0 && b == 0 && c == 0) {
return 0;
}
smallestNonZero = type(uint16).max;
if (a != 0 && a < smallestNonZero) {
smallestNonZero = a;
}
if (b != 0 && b < smallestNonZero) {
smallestNonZero = b;
}
if (c != 0 && c < smallestNonZero) {
smallestNonZero = c;
}
}
function findSmallestNonZero(uint16 a, uint16 b) private pure returns (uint16 smallestNonZero) {
if (a == 0 && b == 0) {
return 0;
}
smallestNonZero = type(uint16).max;
if (a != 0 && a < smallestNonZero) {
smallestNonZero = a;
}
if (b != 0 && b < smallestNonZero) {
smallestNonZero = b;
}
}
function addToWhitelist(address account) external {
require(hasRole(DEFAULT_ADMIN_ROLE, msg.sender) || hasRole(WHITELIST_ADMIN, msg.sender), UNAUTHORISED_ERROR);
uint16 currentEpoch = getCurrentEpoch();
ProviderState storage providerState = providerStates[account];
providerState.whitelisted = true;
providerState.providerStateTimeline[currentEpoch].gainedWhitelist = true;
providerState.latestWhitelistChange = journalProviderWhitelistChange(providerState);
emit AddedWhitelist(account);
}
function removeFromWhitelist(address account) external nonReentrant {
require(hasRole(DEFAULT_ADMIN_ROLE, msg.sender) || hasRole(WHITELIST_ADMIN, msg.sender), UNAUTHORISED_ERROR);
ProviderState storage providerState = providerStates[account];
uint16 currentEpoch = getCurrentEpoch();
_claimProviderDelegationReward(account);
providerState.latestTotalDelegation = 0;
providerState.whitelisted = false;
providerState.providerStateTimeline[currentEpoch].lostWhitelist = true;
providerState.latestWhitelistChange = journalProviderWhitelistChange(providerState);
emit RemovedWhitelist(account);
}
function grantAdditionalReward(address account, uint16 epoch, uint16 amount) external onlyRole(ADDITIONAL_REWARD_ADMIN) {
require(epoch >= getCurrentEpoch(), "Cannot grant additional rewards retroactively");
providerStates[account].additionalRewards.push(AdditionalReward(amount, epoch));
emit GrantedAdditionalReward(account, amount);
}
function changeBank(address newBank) external onlyRole(DEFAULT_ADMIN_ROLE) {
bank = newBank;
}
function drain() external onlyRole(DEFAULT_ADMIN_ROLE) {
token.safeTransfer(msg.sender, token.balanceOf(address(this)));
}
}
文件 4 的 15:Context.sol
pragma solidity ^0.8.0;
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
文件 5 的 15:ERC165.sol
pragma solidity ^0.8.0;
import "./IERC165.sol";
abstract contract ERC165 is IERC165 {
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
文件 6 的 15:IAccessControl.sol
pragma solidity ^0.8.0;
interface IAccessControl {
event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);
event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);
function hasRole(bytes32 role, address account) external view returns (bool);
function getRoleAdmin(bytes32 role) external view returns (bytes32);
function grantRole(bytes32 role, address account) external;
function revokeRole(bytes32 role, address account) external;
function renounceRole(bytes32 role, address account) external;
}
文件 7 的 15:IERC165.sol
pragma solidity ^0.8.0;
interface IERC165 {
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
文件 8 的 15:IERC20.sol
pragma solidity ^0.8.0;
interface IERC20 {
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address to, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(
address from,
address to,
uint256 amount
) external returns (bool);
}
文件 9 的 15:IERC20Metadata.sol
pragma solidity ^0.8.0;
import "../IERC20.sol";
interface IERC20Metadata is IERC20 {
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function decimals() external view returns (uint8);
}
文件 10 的 15:ITwoWeeksNotice.sol
pragma solidity ^0.8.17;
interface ITwoWeeksNotice {
function getStakeState(address account) external view returns (uint64, uint64, uint64, uint64);
function getAccumulated(address account) external view returns (uint128, uint128);
}
文件 11 的 15:Math.sol
pragma solidity ^0.8.0;
library Math {
enum Rounding {
Down,
Up,
Zero
}
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
function average(uint256 a, uint256 b) internal pure returns (uint256) {
return (a & b) + (a ^ b) / 2;
}
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
return a == 0 ? 0 : (a - 1) / b + 1;
}
function mulDiv(
uint256 x,
uint256 y,
uint256 denominator
) internal pure returns (uint256 result) {
unchecked {
uint256 prod0;
uint256 prod1;
assembly {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
if (prod1 == 0) {
return prod0 / denominator;
}
require(denominator > prod1);
uint256 remainder;
assembly {
remainder := mulmod(x, y, denominator)
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
uint256 twos = denominator & (~denominator + 1);
assembly {
denominator := div(denominator, twos)
prod0 := div(prod0, twos)
twos := add(div(sub(0, twos), twos), 1)
}
prod0 |= prod1 * twos;
uint256 inverse = (3 * denominator) ^ 2;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
result = prod0 * inverse;
return result;
}
}
function mulDiv(
uint256 x,
uint256 y,
uint256 denominator,
Rounding rounding
) internal pure returns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 result = 1 << (log2(a) >> 1);
unchecked {
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
return min(result, a / result);
}
}
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
}
}
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 128;
}
if (value >> 64 > 0) {
value >>= 64;
result += 64;
}
if (value >> 32 > 0) {
value >>= 32;
result += 32;
}
if (value >> 16 > 0) {
value >>= 16;
result += 16;
}
if (value >> 8 > 0) {
value >>= 8;
result += 8;
}
if (value >> 4 > 0) {
value >>= 4;
result += 4;
}
if (value >> 2 > 0) {
value >>= 2;
result += 2;
}
if (value >> 1 > 0) {
result += 1;
}
}
return result;
}
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
}
}
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10**64) {
value /= 10**64;
result += 64;
}
if (value >= 10**32) {
value /= 10**32;
result += 32;
}
if (value >= 10**16) {
value /= 10**16;
result += 16;
}
if (value >= 10**8) {
value /= 10**8;
result += 8;
}
if (value >= 10**4) {
value /= 10**4;
result += 4;
}
if (value >= 10**2) {
value /= 10**2;
result += 2;
}
if (value >= 10**1) {
result += 1;
}
}
return result;
}
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0);
}
}
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 16;
}
if (value >> 64 > 0) {
value >>= 64;
result += 8;
}
if (value >> 32 > 0) {
value >>= 32;
result += 4;
}
if (value >> 16 > 0) {
value >>= 16;
result += 2;
}
if (value >> 8 > 0) {
result += 1;
}
}
return result;
}
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0);
}
}
}
文件 12 的 15:ReentrancyGuard.sol
pragma solidity ^0.8.0;
abstract contract ReentrancyGuard {
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor() {
_status = _NOT_ENTERED;
}
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
_status = _ENTERED;
}
function _nonReentrantAfter() private {
_status = _NOT_ENTERED;
}
}
文件 13 的 15:SafeERC20.sol
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../extensions/draft-IERC20Permit.sol";
import "../../../utils/Address.sol";
library SafeERC20 {
using Address for address;
function safeTransfer(
IERC20 token,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(
IERC20 token,
address from,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
function safeApprove(
IERC20 token,
address spender,
uint256 value
) internal {
require(
(value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
function safeIncreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
uint256 newAllowance = token.allowance(address(this), spender) + value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function safeDecreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
uint256 newAllowance = oldAllowance - value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
}
function safePermit(
IERC20Permit token,
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) internal {
uint256 nonceBefore = token.nonces(owner);
token.permit(owner, spender, value, deadline, v, r, s);
uint256 nonceAfter = token.nonces(owner);
require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
}
function _callOptionalReturn(IERC20 token, bytes memory data) private {
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length > 0) {
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
文件 14 的 15:Strings.sol
pragma solidity ^0.8.0;
import "./math/Math.sol";
library Strings {
bytes16 private constant _SYMBOLS = "0123456789abcdef";
uint8 private constant _ADDRESS_LENGTH = 20;
function toString(uint256 value) internal pure returns (string memory) {
unchecked {
uint256 length = Math.log10(value) + 1;
string memory buffer = new string(length);
uint256 ptr;
assembly {
ptr := add(buffer, add(32, length))
}
while (true) {
ptr--;
assembly {
mstore8(ptr, byte(mod(value, 10), _SYMBOLS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}
function toHexString(uint256 value) internal pure returns (string memory) {
unchecked {
return toHexString(value, Math.log256(value) + 1);
}
}
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = _SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
}
}
文件 15 的 15:draft-IERC20Permit.sol
pragma solidity ^0.8.0;
interface IERC20Permit {
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
function nonces(address owner) external view returns (uint256);
function DOMAIN_SEPARATOR() external view returns (bytes32);
}
{
"compilationTarget": {
"contracts/ChromiaDelegation.sol": "ChromiaDelegation"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs",
"useLiteralContent": true
},
"optimizer": {
"enabled": true,
"runs": 2000
},
"remappings": []
}
[{"inputs":[{"internalType":"contract IERC20Metadata","name":"_token","type":"address"},{"internalType":"contract ITwoWeeksNotice","name":"_twn","type":"address"},{"internalType":"address","name":"_owner","type":"address"},{"internalType":"uint16","name":"_delegatorYield","type":"uint16"},{"internalType":"uint16","name":"_totalDelegationYield","type":"uint16"},{"internalType":"address","name":"_bank","type":"address"},{"internalType":"uint32","name":"_yieldPeriodInSecs","type":"uint32"},{"internalType":"uint32","name":"_epochLengthInYieldPeriods","type":"uint32"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"provider","type":"address"}],"name":"AddedWhitelist","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"delegator","type":"address"},{"indexed":false,"internalType":"uint128","name":"amount","type":"uint128"}],"name":"ClaimedYield","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"delegator","type":"address"},{"indexed":true,"internalType":"address","name":"provider","type":"address"},{"indexed":false,"internalType":"uint128","name":"amount","type":"uint128"}],"name":"Delegated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint16","name":"newRate","type":"uint16"}],"name":"DelegatorYieldRateChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"provider","type":"address"},{"indexed":false,"internalType":"uint16","name":"rate","type":"uint16"}],"name":"GrantedAdditionalReward","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"provider","type":"address"},{"indexed":false,"internalType":"uint128","name":"amount","type":"uint128"}],"name":"ProviderClaimedTotalDelegationYield","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint16","name":"newRate","type":"uint16"}],"name":"ProviderTotalDelegationRateChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"provider","type":"address"}],"name":"RemovedWhitelist","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"delegator","type":"address"}],"name":"ResetAccount","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"delegator","type":"address"}],"name":"RevisedDelegation","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"previousAdminRole","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"newAdminRole","type":"bytes32"}],"name":"RoleAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleRevoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"delegator","type":"address"},{"indexed":true,"internalType":"address","name":"provider","type":"address"},{"indexed":false,"internalType":"uint128","name":"amount","type":"uint128"}],"name":"Undelegated","type":"event"},{"inputs":[],"name":"ADDITIONAL_REWARD_ADMIN","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"RATE_ADMIN","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"WHITELIST_ADMIN","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"addToWhitelist","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"bank","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newBank","type":"address"}],"name":"changeBank","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"claimProviderDelegationReward","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"claimYield","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"}],"name":"delegate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"delegatorStates","outputs":[{"internalType":"uint16","name":"claimedEpoch","type":"uint16"},{"internalType":"uint16","name":"latestChangeEpoch","type":"uint16"},{"internalType":"uint96","name":"processed","type":"uint96"},{"internalType":"uint64","name":"processedDate","type":"uint64"},{"internalType":"uint96","name":"balanceAtProcessed","type":"uint96"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"drain","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"epochLength","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"estimateYield","outputs":[{"internalType":"uint128","name":"reward","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint16","name":"epoch","type":"uint16"}],"name":"getActiveDelegation","outputs":[{"components":[{"internalType":"address","name":"delegatedTo","type":"address"},{"internalType":"uint72","name":"balance","type":"uint72"},{"internalType":"uint16","name":"nextChange","type":"uint16"}],"internalType":"struct DelegationChange","name":"activeDelegation","type":"tuple"},{"internalType":"uint16","name":"latestEpoch","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint16","name":"epoch","type":"uint16"}],"name":"getActiveProviderRewardRate","outputs":[{"internalType":"uint128","name":"activeRate","type":"uint128"},{"internalType":"uint16","name":"latestEpoch","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint16","name":"epoch","type":"uint16"}],"name":"getActiveYieldRate","outputs":[{"internalType":"uint128","name":"activeRate","type":"uint128"},{"internalType":"uint16","name":"latestEpoch","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getCurrentEpoch","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"time","type":"uint256"}],"name":"getEpoch","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"provider","type":"address"}],"name":"getTotalDelegations","outputs":[{"internalType":"uint128","name":"totalDelegations","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint16","name":"epoch","type":"uint16"}],"name":"getWhitelisted","outputs":[{"internalType":"bool","name":"whitelisted","type":"bool"},{"internalType":"uint16","name":"latestEpoch","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint16","name":"epoch","type":"uint16"},{"internalType":"uint16","name":"amount","type":"uint16"}],"name":"grantAdditionalReward","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"grantRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"isStakeValid","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"providerStates","outputs":[{"internalType":"bool","name":"whitelisted","type":"bool"},{"internalType":"uint16","name":"claimedEpochReward","type":"uint16"},{"internalType":"uint16","name":"latestDelegationsChange","type":"uint16"},{"internalType":"uint16","name":"latestWhitelistChange","type":"uint16"},{"internalType":"uint128","name":"latestTotalDelegation","type":"uint128"},{"internalType":"uint16","name":"latestTotalDelegationEpoch","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"removeFromWhitelist","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"resetAccount","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"reviseDelegation","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint16","name":"newRate","type":"uint16"}],"name":"setProviderRewardRate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint16","name":"newRate","type":"uint16"}],"name":"setRewardRate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"startTime","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"token","outputs":[{"internalType":"contract IERC20Metadata","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"twn","outputs":[{"internalType":"contract ITwoWeeksNotice","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"undelegate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"updateProviderDelegationRewardEstimate","outputs":[{"internalType":"uint128","name":"reward","type":"uint128"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"yieldPeriod","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"}]