Staking manager
For the Ramesttaβs Proof of Security based consensus, all the β +1 proof verification and handling of staking, rewards are executed on the Polygon smart contract. The whole design follows this philosophy of doing less on the Mainnet contract. It does information verification and pushes all the computation-heavy operations to L2 (read about Heimdall).
Stakers are divided into validators, delegators, and watchers (for fraud reporting).
StakeManager is the main contract for handling validator related activities like checkPoint signature verification, reward distribution, and stake management. Since the contract is using NFT ID as a source of ownership, change of ownership and signer wonβt affect anything in the system.
To ensure Proof of Security consensus, Ramestta executes all proof verification and staking operations on the Polygon smart contract, leaving the computation-heavy tasks to L2.
Stakeholders can take on the role of a validator, delegate, or watcher for reporting fraud. StakeManager is the primary contract for validator-related activities such as stake management, reward distribution, and signature verification. Only one role, either validator or delegator, can be assigned to a single Polygon address as a design choice.
Using NFT ID as the source of ownership ensures that changes in ownership and signer will not impact the system.
validatorThreshold: Shows the maximum number of validators accepted by the system, also called slots
AccountStateRootβ
For various accounting done on heimdall for validators and delegator account root is submitted while submitting the
checkpoint.accRoot is used while
claimRewardsandunStakeClaim.
Stake/stakeForβ
StakeManager.sol
function stake(
uint256 amount,
uint256 heimdallFee,
bool acceptDelegation,
bytes calldata signerPubkey
) public;
function stakeFor(
address user,
uint256 amount,
uint256 heimdallFee,
bool acceptDelegation,
bytes memory signerPubkey
) public;
Allows anyone with amount (in RAMA tokens) greater
minDepositthen ifcurrentValidatorSetSizeis less thenvalidatorThreshold.MUST transfer
amount+heimdallFee, puts validator into auction period for an auctionInterval.(more on auction in auction section)updateTimeLineupdates special timeline data structure, which keeps track of active validators and active stake for given epoch/checkpoint count.One unique
NFTis minted on each new stake/stakeFor call, which can be transferred to anyone but can be owned 1:1 ethereum address.acceptDelegationset true if validators want to accept delegation,ValidatorSharecontract is deployed for the validator.
unstake:β
If a validator decides to unstake, they will be removed from the validator set in the next epoch. However, this removal is only applicable for the current checkpoint.
To account for a validator's exit, their stake will be removed from the timeline data structure, and the count for their exit epoch will be updated.
If a validator had a delegation, they should collect all rewards before their exit, and their delegation contract should be locked to prevent new delegations.
unstakeClaim:β
function unstakeClaim(uint256 validatorId) public;After
unstakingvalidators are put into withdrawal period so that they can be slashed if any fraud found afterunstakingfor pas frauds.Once
WITHDRAWAL_DELAYperiod is served validator's can call this function and do settlement with stakeManager(get rewards if any, get staked tokens back, burn NFT etc)
Restakeβ
function restake(uint256 validatorId, uint256 amount, bool stakeRewards) public;Allows validators to increase their stake by putting new amount or rewards or both.
MUST update timeline(amount) for active stake.
withdrawRewardsβ
function withdrawRewards(uint256 validatorId) public;Allows validators to withdraw accumulated rewards, must consider getting rewards from delegation contract if validator accepts delegation.
updateSignerβ
function updateSigner(uint256 validatorId, bytes memory signerPubkey) publicAllows validators to update signer address(which is used to validate blocks on ramestta chain and checkpoint sigs on stakeManager)
topUpForFeeβ
function topUpForFee(uint256 validatorId, uint256 heimdallFee) public;Validators can top-up their balance for heimdall fee by invoking this method.
claimFeeβ
function claimFee(
uint256 validatorId,
uint256 accumSlashedAmount,
uint256 accumFeeAmount,
uint256 index,
bytes memory proof
) public;
Used to withdraw fee from heimdall.
accountStateRootis updated on each checkpoint, so that validators can provide proof of inclusion in this root for account on heimdall and withdraw fee.Note that
accountStateRootis re-written to prevent exits on multiple checkpoints(for old root and save accounting on stakeManager)accumSlashedAmountis unused atm, will be used for slashing on heimdall if needed.
StakingNFTβ
Standard erc721 with few restrictions like one token per user and minted in sequential manner.
Validator Replacementβ
In order to replace poor performing validator there is periodic auction for each validator slot.
For individual validators there is auction window where wanna be validators can bid their amount and start an auction using
startAuctionfunction.Once the
auctionIntervalis over last bidder needs to close the auction in order to confirm and become validator. For which she needs to callconfirmAuctionBidwhich accepts and behave similar to newstakefunction for upcoming validator andunStakefor old validator.Current validator can bid for herself and try to keep that place.
Whole mech dynamically balances the stake value and overall security according to market conditions and use of ramestta chain.
startAuctionβ
function startAuction(
uint256 validatorId, /** auction for validator */
uint256 amount /** amount greater then old validator's stake */
) external;
In order to start a bid or bid higher on already running auction this function is used.
Auction period runs in cycles like
(auctionPeriod--dynasty)--(auctionPeriod--dynasty)--(auctionPeriod--dynasty)so it MUST check for correct auction period.perceivedStakeFactoris used to calculate exact factor*old stake (note currently it is by default 1 WIP for picking the function).MUST check for auction from last auction period if any still going on (one can choose to not call
confirmAuctionin order to get her capital out in next auction).Normally continuous english auction is going on in a
auctionPeriod.
confirmAuctionBidβ
function confirmAuctionBid(
uint256 validatorId,
uint256 heimdallFee, /** for new validator */
bool acceptDelegation,
bytes calldata signerPubkey
) external
MUST check that this is not an auctionPeriod.
If last bidder is owner of
validatorIdbehaviour should be similar to restake.In second case unStake
validatorIdand add new user as validator from next checkpoint, for the new user behaviour should be similar to stake/stakeFor.
checkSignaturesβ
function checkSignatures(
uint256 blockInterval,
bytes32 voteHash,
bytes32 stateRoot,
bytes memory sigs
) public;
Writes are meant only for RootChain contract when submitting checkpoints
voteHashon which all validators sign (BFT β +1 agreement)This function validates only unique sigs and checks for β +1 power has signed on checkpoint root (inclusion in
voteHashverification in RootChain contract for all data)currentValidatorSetTotalStakeprovides current active stake.Rewards are distributed proportional to validator's stake.
isValidatorβ
Checks if given validator is active validator for current epoch.
Timeline data structureβ
struct State {
int256 amount;
int256 stakerCount;
}
mapping(uint256 => State) public validatorState;

StakingInfo:
StakingInfo:Source: StakingInfo.sol
Centralised logging contract for both validator and delegation events, Includes few read only functions.
ValidatorShareFactory:
A factory contract to deploy ValidatorShare contract for each validator who opt-in for delegation. You can check out the source code of the ValidatorShareFactory.sol contract on GitHub.
Last updated