Nucypher Ethereum Contracts¶
NuCypherTokenERC20 token contract
StakingEscrowHolds Ursula’s stake, stores information about Ursula’s activity, and assigns a reward for participating in the NuCypher network. (The
Issuercontract is part of the
PolicyManagerHolds a policy’s fee and distributes fee by periods
AdjudicatorManages the slashing protocol
UpgradeableBase contract for upgrading
DispatcherProxy to other contracts and provides upgrading of the
UserEscrowLocks tokens for predetermined time. Tokens will be unlocked after specified time and all tokens can be used as stake in the
NuCypherTokenwith all future supply tokens
StakingEscrowwith a dispatcher targeting it
PolicyManagerwith its own dispatcher, also targeting it
Adjudicatorwith a dispatcher
Transfer reward tokens to the
StakingEscrowcontract. These tokens are future mining rewards and initial allocations
initialize()method to initialize the
Set the address of the
PolicyManagercontract in the
StakingEscrowby using the
Pre-deposit tokens to the
Approve the transfer tokens for the
StakingEscrowcontract using the
approve(address, uint)method. The parameters are the address of
StakingEscrowand the amount of tokens for a staker or group of stakers;
Deposit tokens to the
StakingEscrowcontract using the
preDeposit(address, uint, uint)method. The parameters are the addresses of the stakers, the amount of tokens for each staker, and the number of periods during which tokens will be locked for each staker
Pre-deposit tokens to the
UserEscrowand, if necessary:
Create new instance of the
Transfer ownership of the instance of the
UserEscrowcontract to the user
Approve the transfer of tokens for the
Deposit tokens by the
Alice’s Contract Interaction¶
Alice Revokes a Blockchain Policy¶
When Alice wants to revoke a policy, she calls the
Execution of these methods results in Alice recovering all fees for future periods, and also for periods when the stakers were inactive.
Alice can refund ETH for any inactive periods without revoking the policy by using the method
Ursula’s Contract Interaction¶
Ursula Locks Tokens¶
In order to become a participant of the network, a staker stakes tokens in the
The staker allows the (staking) contract to perform a transaction using the
NuCypherToken.approve(address, uint256) method
(ERC20 contracts allow access delegation to another address).
After that, the staker transfers some quantity of tokens (
StakingEscrow.deposit(uint256, uint16)), locking them at the same time.
NucypherToken.approveAndCall(address, uint256, bytes) method can be used.
The parameters are:
The address of the
The amount of staked tokens
The periods for locking (which are serialized into an array of bytes)
When staking tokens, the staker sets the number of periods the tokens will be locked, which must be no less than some minimal locking time (30 periods).
In order to unlock tokens, the staker must be active during the time of locking (and confirm activity each period).
Each stake is represented by the amount of tokens locked, and the stake’s duration in periods.
The staker can add a new stake using
StakingEscrow.deposit(uint256, uint16) or
StakingEscrow.lock(uint256, uint16) methods.
The staker can split stake into two parts: one with the same duration and another with an extended duration.
For this purpose, the
StakingEscrow.divideStake(uint256, uint256, uint16) method is used.
The first parameter is used to identify the stake to divide and the last two for the extended part of the stake.
When calculating locked tokens using the
StakingEscrow.getLockedTokens(address, uint16) method, all stakes that are active during the specified period are summed.
Ursula Confirms Activity¶
In order to confirm activity every period, stakers call
StakingEscrow.confirmActivity() wherein activities for the next period are registered.
The staker gets a reward for every confirmed period.
Ursula Generates Staking Rewards¶
After the period of activity has passed, the staker may call
StakingEscrow.mint() method which computes and transfers tokens to the staker’s account.
Also note that calls to
StakingEscrow.confirmActivity() are included the
The reward value depends on the fraction of locked tokens for the period (only those who confirmed activity are accounted for).
Also, the reward depends on the number of periods during which the tokens will be locked: if the tokens will be locked for half a year, the coefficient is 1.5.
The minimum coefficient is 1 (when tokens will get unlocked in the next period), and the maximum is 2 (when the time is 1 year or more).
The reward is calculated separately for each stake that is active during the mining period and all rewards are summed up.
The order of calling
StakingEscrow.mint() by stakers (e.g. who calls first, second etc) doesn’t matter.
Stakers can claim their rewards by using the
StakingEscrow.withdraw(uint256) method. Only non-locked tokens can be withdrawn.
Ursula Generates Policy Rewards¶
Also the staker gets rewards for policies deployed.
Computation of a policy reward happens every time
StakingEscrow.mint() is called by the
PolicyManager.updateReward(address, uint16) method.
In order to take the reward, the staker needs to call method
withdraw() of the contract
The staker can set a minimum reward rate for a policy. For that, the staker should call the
NuCypher Partner Ursula Staking¶
Some users will have locked but not staked tokens.
In that case, an instance of the
UserEscrow contract will hold their tokens (method
All tokens will be unlocked after a specified time and the user can retrieve them using the
When the user wants to become a staker - he uses the
UserEscrow contract as a proxy for the
The staker must specify a worker who will confirm the activity and sign on behalf of this staker by calling the
Changing a worker is allowed no more than 1 time in
Only the worker can confirm activity.