Manager
Manager.sol
The main control center of the system. Defines exchange rate between CELO and stCELO, has ability to mint and burn stCELO, is the main point of interaction for depositing and withdrawing CELO from the pool, and defines the system's voting strategy.
Mainnet Deployment:
0x0239b96D10a434a56CC9E09383077A0490cF9398Alfajores Testnet Deployment:
0xFfe124dde2b29fA848aD8caAEBE85651F0b5c406
Methods
initialize
Initialize the contract with registry and owner. .
function initialize(address _registry, address _owner) external initializer {
_transferOwnership(_owner);
__UsingRegistry_init(_registry);
}setDependencies
Set this contract's dependencies in the StakedCelo system. Manager, Account and StakedCelo all reference each other so we need a way of setting these after all contracts are deployed and initialized.
function setDependencies(address _stakedCelo, address _account) external onlyOwner {
stakedCelo = IStakedCelo(_stakedCelo);
account = IAccount(_account);
}activateGroup
Marks a group as votable.
getGroups
Returns the array of active groups.
deprecateGroup
Marks a group as deprecated. A deprecated group will remain in the `deprecatedGroups` array as long as it is still being voted for by the Account contract. Deprecated groups will be the first to have their votes withdrawn.
getDeprecatedGroups
Returns the list of deprecated groups.
deposit
Used to deposit CELO into the StakedCelo system. The user will receive an amount of stCELO proportional to their contribution. The CELO will be scheduled to be voted for with the Account contract.
withdraw
Used to withdraw CELO from the system, in exchange for burning stCELO.
toStakedCelo
Computes the amount of stCELO that should be minted for a given amount of CELO deposited.
toCelo
Computes the amount of CELO that should be withdrawn for a given amount of stCELO burn.
distributeVotes
Distribute votes, such that groups are receiving the same amount of votes from the system. If a group already has more votes than the average of the total available votes it will not be voted for, and instead we'll try to evenly distribute between the remaining groups.
Election.sol sets a dynamic limit on the number of votes receivable by a group, based on the group's size, the total amount of Locked CELO, and the total number of electable validators. We don't want to schedule votes for a group when the amount would exceed this threshold. `getVotableGroups` below selects those groups that could receive the entire `votes` amount, and filters out the rest.
This is a heuristic
when distributing votes evenly, the group might receive less than`votes`, and the total amount could end up being under the limit. However, doing an exact computation would be both complex and cost a lot of additional gas, hence the heuristic. If indeed all groups are close to their voting limit, causing a larger deposit to revert with NoVotableGroups, despite there still being some room for deposits, this can be worked around by sending a few smaller deposits.
distributeWithdrawals
Distributes withdrawals by computing the number of votes that should be withdrawn from each group, then calling out to `Account.scheduleVotes`.
The withdrawal distribution strategy is to:
Withdraw as much as possible from any deprecated groups.
If more votes still need to be withdrawn, try and have each validator group end up receiving the same amount of votes from the system. If a group already has less votes than the average of the total remaining votes, it will not be withdrawn from, and instead will try to evenly distribute between the remaining groups.
getDeprecatedGroupsWithdrawalDistribution
Calculates how many votes should be withdrawn from each deprecated group.
getActiveGroupWithdrawalDistribution
Calculates how votes should be withdrawn from each active group.
getSortedGroupsWithVotes
Returns a list of group addresses with their corresponding current total votes, sorted by the number of votes, and the total number of votes in the system.
getVotableGroups
Returns the active groups that can receive the entire `votes` amount based on their current receivable votes limit in Election.sol.
sortGroupsWithVotes
Sorts an array of GroupWithVotes structs based on increasing `votes` values.
Last updated