Restaking Base
is a near contract designed to restake NEAR tokens for CC PoS
(Consumer Chain PoS). There are several user roles when interacting with the contract, including Staker
, CC PoS
, and CC Gov
(Consumer Chain Governance). Stakers
can stake their NEAR tokens through the contract, and gain the right to restake to CC PoS
to provide security, receive rewards from CC PoS
, and also bear the risk of being slashed. CC Gov
is responsible for managing CC PoS
and deciding whether to execute slashes submitted by CC PoS
.
Contents:
Staker
: A user who stake near.Validator
: A near validator.staking pool contract
: A contract deployed on each nearValidator
account.Staking Pool
: An account that deployed thestaking pool contract
.restake
: Stake the near that has already been staked inValidator
forConsumer Chain
'sPoS
.unstake
: A user cancel their stake. If a restake has been performed, it will first execute theunbond
operation with allCC PoS
.withdraw
: A user withdraws assets that can be withdrawn from theRestaking Base
.stake shares
: The total number of shares a user has in thestake pool contract
for a particularStaking Pool
.staked balance
: The staking amount ofstaker
.update-shares
: Triggers an update of the user's balance in theRestaking Base
contract. Anyone can call it, and it will also be triggered when stake/unstake/deposit/withdraw operations occur. This operation will call theping
function of thestake pool contract
to obtain the balance of theRestaking Base
contract in thestake pool contract
contract and save it locally.Consumer Chain
: A Consumer Chain establishes its PoS contract on NEAR to execute itsreward
andslash
rules and then registers itsunbonding period
,CC Gov
, and other parameters with theRestaking Base
contract.CC PoS
: A PoS contract established by a Consumer Chain on near.CC Gov
: An account specified when registering theCC PoS
, which has the authority to approve or reject theslash
submitted by theCC PoS
.Bond
: After theStaker
andConsumer Chain
bond, theStaker's
near provides security for theConsumer Chain
, and theConsumer Chain
providesRewards
to theStaker
. At the same time, theConsumer Chain
will have the right to initiate aslash
against theStaker
.Unbond
: TheStaker
andConsumer Chain
break theBond
. This process requires anunbonding period
to complete, during which theConsumer Chain
can apply toSlash
theStaker
.Slash
: A Consumer Chain can apply to penalize theStaker
during thebonding
orunbonding
period, andCC Gov
decides whether to approve or reject theSlash
.identity
: Staker ID in Consumer Chain.
The stake
operation requires specifying an account which is sub-account of near staking-pool-factory
account. Users will stake attached NEAR tokens to this account and record it internally in the staking-base
contract.
Users can only choose one staking pool
for staking
at same time. If they want to switch to another staking pool
, they need to complete an unstake
operation first.
The Staker
can increase their staking
amount after the stake
operation has been completed.
The Staker
can decrease their staking
amount after the stake
operation has been completed. The CC PoS
can't stop Staker
decreasing their stake amount, but the CC PoS
can only select Stakers
with staking balances ranked within a certain range.
This CC PoS
can submit registration information to the staking-base contract. The following information needs to be provided: chain_id
, unbonding_period
, website
, governance
, and treasury
. Additionally, a certain amount of NEAR tokens needs to be attached as the registration fee during the registration process.
The CC Gov
can unregister CC PoS
and the restaking-base
will transfer register fee to treasury
account.
The CC Gov
can update CC PoS
information and this interface must be called by the governance
account.
After the Staker
has completed the stake
operation through this contract, they can execute the bond
operation, which will restake their staked NEAR to a specific consumer chain
to provide security for the consumer chain
PoS operation and to receive rewards or slash
from the consumer chain
.
The Staker
need to submit his staking information and identity when bonding.
And Consumer Chain PoS accepts or rejects a bond request according to its rules, such as $NEAR > Th, NFT ownership, etc.
The Staker
can change his identity
after finish bonding.
The staker
can call the unbond
operation to exit the CC PoS
, which must go through the unbonding period
specified by the consumer chain
before completion.
And once unbonded, the staker can’t bond to the consumer chain until the unbonding period expired.
The CC PoS
can blackout Stakers, which will prevent them from bonding.
Slash
is a penalty operation that is initiated by the CC PoS
to punish a staker
for misconduct.
The process is divided into two steps: first, the CC PoS
submits a slash
to the staking-base
contract, and then governance
decides whether to execute the slash
.
Rules of executing slash:
- It will slash on the asset in
Staker.pending_unstakes
with the smallestunlock_time
first. - If the assets in
Staker.pending_unstakes
are not sufficient for theslash
amount, theunstake
operation is executed first, andStaker.pending_unstakes
is updated before continuing with theslash
operation. - If the assets are still not enough after the
unstake
operation, it is still considered a successfulslash
, and the total amount successfullyslashed
is returned. - After the assets in
Staker.pending_unstakes
areslashed
, aPendingUnstake
is created for theCC PoS
'streasury
that was specified during registration. ThePendingUnstake.unlock_epoch
field inherits theunlock_epoch
of thePendingUnstake
that wasslashed
, andPendingUnstake.unlock_time
is set to current_time.
In order to update validator set, the CC PoS
is motivated to query the Restaking Base contract periodically.
The CC PoS
can specify a limit
parameter to indicate that it only selects a certain number of Stakers ranked by staking amount. And the CC PoS
will still perform an additional filtering based on the Stakers' staking amount to determine if they will become their validator.
When a Staker
performs the unstake
operation, they must first Unbond
all consumer chain
PoS they are currently bonding.
The withdrawable time after Unstake
depends on the longest Unbonding period
among all bonding CC PoS
.
When a Staker performs the unstake or decrease stake operation, the contract will generate PendingUnstake data as a withdrawal voucher. When the Staker comes to withdraw, they need to specify the list of PendingUnstake IDs. The restaking-base contract
will destroy the Withdrawable PendingUnstake and transfer the corresponding NEAR to the Staker.
This contract (v1.1.2) had been audited by BlockSec. Here is the report.