# StakingEscrow¶

details

v5.7.1

notice

Contract holds and locks stakers tokens. Each staker that locks their tokens will receive some compensation

## events¶

notice

Signals that the worker associated with the staker made a commitment to next period

#### params¶

period

Period committed to

staker

value

Amount of tokens staked for the committed period

notice

Signals that tokens were deposited

#### params¶

periods

Number of periods tokens will be locked

staker

value

Amount deposited (in NuNits)

notice

Signals that a sub-stake was divided

#### params¶

lastPeriod

Final locked period of old sub-stake

newValue

New sub-stake value (in NuNits)

oldValue

Old sub-stake value (in NuNits)

periods

Number of periods to extend sub-stake

staker

### Initialized(uint256)¶

notice

Issuer is initialized with a reserved reward

notice

Signals that tokens were stake locked

#### params¶

firstPeriod

Starting lock period

periods

Number of periods tokens will be locked

staker

value

Amount locked (in NuNits)

notice

Signals that two sub-stakes were merged

#### params¶

lastPeriod

Final locked period of merged sub-stake

staker

value1

Value of first sub-stake (in NuNits)

value2

Value of second sub-stake (in NuNits)

notice

Signals that the staker migrated their stake to the new period length

#### params¶

period

Period when migration happened

staker

notice

Signals that tokens were minted for previous periods

#### params¶

period

Previous period tokens minted for

staker

value

Amount minted (in NuNits)

notice

Signals that a sub-stake was prolonged

#### params¶

lastPeriod

Final locked period of old sub-stake

periods

Number of periods sub-stake was extended

staker

value

Value of sub-stake

notice

Signals that the restake parameter was activated/deactivated

#### params¶

reStake

Updated parameter value

staker

notice

Signals that the staker was slashed

#### params¶

investigator

penalty

Slashing penalty

reward

Value of reward provided to investigator (in NuNits)

staker

notice

Signals that the snapshot parameter was activated/deactivated

#### params¶

snapshotsEnabled

Updated parameter value

staker

notice

Signals that the winddown parameter was activated/deactivated

#### params¶

staker

windDown

Updated parameter value

notice

Signals that tokens were withdrawn to the staker

#### params¶

staker

value

Amount withdraws (in NuNits)

notice

internal event

notice

Signals that a worker was bonded to the staker

#### params¶

staker

startPeriod

Period bonding occurred

worker

## methods¶

notice

Bond worker

_worker

### commitToNextPeriod()¶

notice

Make a commitment to the next period and mint for the previous period

### constructor¶

notice

Constructor sets address of token contract and coefficients for minting

#### params¶

_issuanceDecayCoefficient
1. Coefficient which modifies the rate at which the maximum issuance decays, only applicable to Phase 2. d = 365 * half-life / LOG2 where default half-life = 2. See Equation 10 in Staking Protocol & Economics paper

_firstPhaseMaxIssuance

(Imax) Maximum number of new tokens minted per period during Phase 1. See Equation 7 in Staking Protocol & Economics paper.

_firstPhaseTotalSupply

Total supply for the first phase

_genesisHoursPerPeriod

Size of period in hours at genesis

_hoursPerPeriod

Size of period in hours

_lockDurationCoefficient1

(k1) Numerator of the coefficient which modifies the extent to which a stake’s lock duration affects the subsidy it receives. Affects stakers differently. Applicable to Phase 1 and Phase 2. k1 = k2 * small_stake_multiplier where default small_stake_multiplier = 0.5. See Equation 8 in Staking Protocol & Economics paper.

_lockDurationCoefficient2

(k2) Denominator of the coefficient which modifies the extent to which a stake’s lock duration affects the subsidy it receives. Affects stakers differently. Applicable to Phase 1 and Phase 2. k2 = maximum_rewarded_periods / (1 - small_stake_multiplier) where default maximum_rewarded_periods = 365 and default small_stake_multiplier = 0.5. See Equation 8 in Staking Protocol & Economics paper.

_maxAllowableLockedTokens

Max amount of tokens that can be locked

_maximumRewardedPeriods

(kmax) Number of periods beyond which a stake’s lock duration no longer increases the subsidy it receives. kmax = reward_saturation * 365 where default reward_saturation = 1. See Equation 8 in Staking Protocol & Economics paper.

_minAllowableLockedTokens

Min amount of tokens that can be locked

_minLockedPeriods

Min amount of periods during which tokens can be locked

_minWorkerPeriods

Min amount of periods while a worker can’t be changed

_policyManager

Policy Manager contract

_token

Token contract

_workLock

WorkLock contract. Zero address if there is no WorkLock

notice

Deposit tokens and create new sub-stake. Use this method to become a staker

#### params¶

_staker

Staker

_unlockingDuration

Amount of periods during which tokens will be unlocked when wind down is enabled

_value

Amount of tokens to deposit

### depositAndIncrease(uint256,uint256)¶

details

This is preferable way to stake tokens because will be fewer active sub-stakes in the result

notice

Deposit tokens and increase lock amount of an existing sub-stake

#### params¶

_index

Index of the sub stake

_value

Amount of tokens which will be locked

notice

Deposit tokens from WorkLock contract

#### params¶

_staker

_unlockingDuration

Amount of periods during which tokens will be unlocked when wind down is enabled

_value

Amount of tokens to deposit

### divideStake(uint256,uint256,uint16)¶

notice

Divide sub stake into two parts

#### params¶

Amount of periods for extending sub stake

_index

Index of the sub stake

_newValue

New sub stake value

details

If specified period is outside all downtime periods, the length of the array will be returned

notice

Find index of downtime structure that includes specified period

#### params¶

_period

Specified period number

_staker

Staker

details

the onlyWhileUpgrading modifier works through a call to the parent finishUpgrade

### getActiveStakers(uint16,uint256,uint256)¶

details

Note that activeStakers[0] in an array of uint256, but you want addresses. Careful when used directly!

notice

Get the value of locked tokens for active stakers in (getCurrentPeriod() + _offsetPeriods) period as well as stakers and their locked tokens

#### params¶

_maxStakers

Max stakers for looking, if set 0 then all will be used

_offsetPeriods

Amount of periods for locked tokens calculation

_startIndex

Start index for looking in stakers array

#### returns¶

activeStakers

Array of stakers and their locked tokens. Stakers addresses stored as uint256

allLockedTokens

Sum of locked tokens for active stakers

notice

Get all tokens belonging to the staker

notice

Get work that completed by the staker

### getCurrentPeriod()¶

#### returns¶

_0

Number of current period

notice

Get all flags for the staker

notice

Get the last committed staker’s period

#### params¶

_staker

Staker

notice

Get the last period of the sub stake

#### params¶

_index

Stake index

_staker

Staker

details

This function is used by PreallocationEscrow so its signature can’t be updated.

notice

Get the value of locked tokens for a staker in a future period

#### params¶

_offsetPeriods

Amount of periods that will be added to the current period

_staker

Staker

notice

Return the information about past downtime

notice

Return the length of the array of past downtime

### getReservedReward()¶

notice

Returns the number of tokens that can be minted

### getStakersLength()¶

notice

Return the length of the array of stakers

notice

Return the information about sub stake

notice

Return the length of the array of sub stakes

notice

notice

Initialize reserved tokens for reward

### isOwner()¶

#### returns¶

_0

true if msg.sender is the owner of the contract.

### lockAndCreate(uint256,uint16)¶

notice

Lock some tokens as a new sub-stake

#### params¶

_unlockingDuration

Amount of periods during which tokens will be unlocked when wind down is enabled

_value

Amount of tokens which will be locked

### lockAndIncrease(uint256,uint256)¶

notice

Increase lock amount of an existing sub-stake

#### params¶

_index

Index of the sub-stake

_value

Amount of tokens which will be locked

### mergeStake(uint256,uint256)¶

details

It’s possible that both sub-stakes will be active after this transaction. But only one of them will be active until next call commitToNextPeriod (in the next period)

notice

Merge two sub-stakes into one if their last periods are equal

#### params¶

_index1

Index of the first sub-stake

_index2

Index of the second sub-stake

notice

Migrate from the old period length to the new one. Can be done only once

_staker

Staker

### mint()¶

notice

Mint tokens for previous periods if staker locked their tokens and made a commitment

_0

### previousPeriodSupply()¶

notice

Current supply is used in the minting formula and is stored to prevent different calculation for stakers which get reward in the same period. There are two values - supply for previous period (used in formula) and supply for current period which accumulates value before end of period.

### prolongStake(uint256,uint16)¶

notice

Prolong active sub stake

#### params¶

Amount of periods for extending sub stake

_index

Index of the sub stake

notice

Implementation of the receiveApproval(address,uint256,address,bytes) method (see NuCypherToken contract). Deposit all tokens that were approved to transfer(param _extraData) Amount of periods during which tokens will be unlocked when wind down is enabled

#### params¶

_from

Staker

_tokenContract

_value

Amount of tokens to deposit

### removeUnusedSubStake(uint16)¶

notice

Remove unused sub-stake to decrease gas cost for several methods

### renounceOwnership()¶

details

Allows the current owner to relinquish control of the contract.

notice

Renouncing to ownership will leave the contract without an owner. It will not be possible to call the functions with the onlyOwner modifier anymore.

### setReStake(bool)¶

notice

Set reStake parameter. If true then all staking rewards will be added to locked stake

#### params¶

_reStake

Value for parameter

### setSnapshots(bool)¶

notice

Activate/deactivate taking snapshots of balances

#### params¶

_enableSnapshots

True to activate snapshots, False to deactivate

### setWindDown(bool)¶

notice

Set windDown parameter. If true then stake’s duration will be decreasing in each period with commitToNextPeriod()

#### params¶

_windDown

Value for parameter

notice

Start or stop measuring the work of a staker

#### params¶

_measureWork

Value for measureWork parameter

_staker

Staker

#### returns¶

_0

Work that was previously done

notice

Slash the staker’s stake and reward the investigator

#### params¶

_investigator

Investigator

_penalty

Penalty

_reward

Reward for the investigator

_staker

details

Allows the current owner to transfer control of the contract to a newOwner.

#### params¶

newOwner

The address to transfer ownership to.

details

the onlyWhileUpgrading modifier works through a call to the parent verifyState

### withdraw(uint256)¶

notice

Withdraw available amount of tokens to staker

#### params¶

_value

Amount of tokens to withdraw