A solution for staking

This topic proposes a solution for staking, which is not relying on data inputs and also scalable (can support thousands of tokens).

We consider the case of ErgoMixer, with profit from the mixer to be collected in a box associated with some “funding NFT” first. Then payments done periodically, in epochs (say, 1 epoch = 1,024 blocks). Epoch number N+1 is going after epoch number N. During an epoch, each token being staked is getting rewarded with its part from all the funds received in this epoch and before.

The solution is based on interaction between two contracts.

  • First contract (aka staking contract) is representing tokens being staked by one user. It allows for unstaking and getting rewards. Payment epoch is stored in a box associated with the contract.

However, the box can be created in a way that it contains epoch written down with malicious intent (to get paid twice per epoch and so on). So the box must be registered (stamped) by the second contract before getting any payments. Then the box can be used for getting payments. Registration is done with a special token given to the box.

  • Second contract (aka master contract) is collecting funds, doing payment, and also doing registration (and getting back registration token on unstaking)

So first (staking) contract would be like ErgoScript Playground | PlutoMonkey Wallet

, and the master script would be like ErgoScript Playground | PlutoMonkey Wallet

And usage would be like:

  • first, ErgoMixer folks create master contract with “master contract NFT”, staking contract registration token and initial epoch set.
  • every new epoch they fund the master contract box once from a box with funding NFT (which collected mixer rewards during previous epoch). We can assume that the funding box is associated with just a public key of mixer service providers. Funding can be done by anyone
  • then payments done, with master contract to be input #0 and output #0, and staking contract to be input #1 and output #1. Payments can be easily chained in the same block. Payment transaction can be done by anyone.

To get payments, one needs to send ErgoMixer tokens to staking contract P2S address (and the receiving box should contain owner pubkey to get payments too in register R5). Then registration can be done (again, by anyone) with a transaction having master contract as input #0 and output #0, and staking contract as input #1 and output #1.

Unstaking can be one with staking box owner signature to be presented only.

Contracts provided are just sketches. There’s a need to audit and likely fix some issues there, also, not sure they are AOT-costing. Auditing and Ergo playground is the next step to get done.

7 Likes

What’s the source of ERG for paying the delegators? In PoS coins they just issue new coins… But ERG needs to be mined.

1 Like

The main motivation was about ErgoMixer tokens, when you stake the tokens to get ERG from mixer’s income flow

1 Like

Ok. So the reward will be in the form of whatever income generated by assets included in the mixer. Right?

1 Like

Yes, exactly. Some parts are missed in my prototype contracts, as they are about staking just.

1 Like