You are on page 1of 2

TECH CHALLENGE

Blockchain Developer

Challenge

Context

Staking in the Elrond blockchain refers to the process of holding and locking
up Elrond (EGLD) tokens in a staking smart contract in exchange for
rewards. The primary purpose of staking in Elrond is to participate in the
consensus mechanism of the network and help secure it, as well as earn
rewards for doing so.

Stakers in the Elrond network receive rewards for participating in the


consensus mechanism, with the rewards being proportional to the amount
of EGLD they hold in the staking contract. The rewards are distributed on a
regular basis, such as weekly or monthly, and the specific reward formula is
defined in the staking smart contract.

Challenge

Create a smart contract on the Elrond network that implements a staking


mechanism with the following features:

● Users can deposit their EGLD tokens into the contract to become a
staker.
● Assume rewards are distributed based on a global speed. For
example, 0.0003 EGLD are distributed per second among all users.
● Users earn rewards in proportion to their stake. These rewards are
continuously distributed (of course, they are kept at the staking smart
contract).
● Users can withdraw their staked EGLD or claim their rewards at any
time.

The document may not be shared with anyone not associated with Rather Labs. Copying or sharing it outside the provided link is prohibited.
TECH CHALLENGE
Blockchain Developer

Hint

Avoid using a loop to update the rewards for all stakers at any given
protocol interaction. The problem can be thought as having a share
amount and a share price: while the share amount an account has does
not change when someone else interacts with the protocol, the share price
does.

Total Rewards:
dR(t) = v(t) * dt

Account Rewards:
dr(t) = n(t) / N(t) * dR(t)
dr(t) = n(t) / N(t) * v(t) * dt
dr(t) = n(t) * dS(t)

In which:
dS(t) = 1 / N(t) * v(t) * dt
Is the Share price.

Steps

- Install rust (use nightly version)


- Install mxpy (ex erdpy)
- Start a contract using a template, such as:
mxpy contract new staking —template xxxx
- Start coding the contract.

Bonus Points

- Create some tests for the staking smart contract, tests are important
to ensure that the contract works as expected and to catch any
potential bugs or issues before deployment.
- Deploy the smart contract on the Elrond network using the mxpy or
any other Elrond development environment of your choice.

The document may not be shared with anyone not associated with Rather Labs. Copying or sharing it outside the provided link is prohibited.

You might also like