-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Staking Contract #27
Staking Contract #27
Conversation
@evgenykuzyakov thoughts? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm against having any callback towards contracts that are called based on the time/block/some event. It has a lot of security implications as well as complexity involved with this.
Security:
- priorities of such callbacks
- handling them securely
Complexity:
- gas price uncertainty
- limited use-case for staking. Not general enough.
Alternative solution is to design the contract that is unaware of the rewards or events happening with the account balance/locked.
It's possible to issue token (similar to uniswap pooling) that gives shares towards the contract balance. Once the account balance has changed, we can recalculate your share towards this balance.
It will also account for the storage/account_name rent.
Discussion offline:
|
Longer discussion happened in CW: https://commonwealth.im/near/proposal/discussion/357-riskless-delegation-aka-tezos-delegation re:delegation with outcome to continue with this approach for all delegation needs. Will refresh this with latest approach. |
Co-Authored-By: Evgeny Kuzyakov <ek@nearprotocol.com>
The latest staking design looks better. We'll need to incorporate |
Your Render PR Server URL is https://nomicon-pr-27.onrender.com. Follow its progress at https://dashboard.render.com/static/srv-bqq8lj08atn30p5p2900. |
Your Render PR Server at https://nomicon-pr-27.onrender.com is now live! View it on your dashboard at https://dashboard.render.com/static/srv-bqq8lj08atn30p5p2900. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't mention anything about voting
It doesn't have to. The spec just defines the interface and invariants with guarantees. It doesn't need to mention particular implementation, e.g. shares or inner implementation or extra methods, like initialization, etc. |
See https://github.com/near/core-contracts/tree/master/staking-pool to detailed design and implementation. |
Summary
Provides standard and reference internal design for staking contract with delegation.
Motivation
In NEAR contracts and accounts are the same object. This allows to have a contract that stakes NEAR with it's balance.
This is useful to implement delegation, custom reward dispersion, liquid staking and various derivatives on stake and more.
Guide-level explanation
The simplest example of staking contract would be a delegation contract.
Let's define actors:
staking-pool
. A key-less account with the contract that pools funds.owner
. Owner runs the validator node on behalf of the staking pool account.user1
. The account who wants to stake their fund to the pool.The owner can setup such contract and validate on behalf of this contract in their node.
Any other user can send their tokens to the contract, which will be pooled together and increase the total stake.
These users would accrue rewards (subtracted fees set by the owner).
Then they can unstake and withdraw their balance after some unlocking period.
More complex example can also issue token for deposited user's stake. This stake is the right to withdraw underlaying balance and rewards. This provides staking liquidity and allows to trade staked tokens.
Reference-level explanation
Staking contract guarantees:
Staking Contract spec
Next interface is implemented by staking contract:
User path
A simple path for a user who wants to pool their funds can be the following:
Delegate money
To deposit and stake 100 NEAR.
Wait for a week, so the pool accumulate some rewards.
Update internal state of the staking pool (optional)
near call staking-pool ping '{}' --accountId user1
See current balance
Unstake some rewards and withdraw them
Get the current staked balance
Let's say
user1
accumulated0.6
NEAR and the total is100.6
NEAR. The user decides to withdraw0.5
NEAR.First the user has to unstake
0.5
NEAR.near call staking-pool unstake '{"amount": "500000000000000000000000"}' --accountId user1
Let's check the unstaked balance.
Wait for 4 epochs. Check if the balance is liquid and can be withdrawn now.
Now withdraw
0.5
NEAR back to theuser1
account.near call staking-pool withdraw '{"amount": "500000000000000000000000"}' --accountId user1
Drawbacks
General drawback of staking finance, is leverage of the stake. Someone can try to create leverage and buy more stake to control bigger position of the network and do bigger harm. The issue is that this happening and addressing this on chain gives us great visibility.
Rationale and alternatives
There a number of applications around DeFi and staking that are going to happened soon.
Currently they require a separate set of multi-sig holders on a different chain. This creates new vectors of attack in addition to reducing visibility of security on chain.
Because in NEAR contracts can stake, we can relatively easily add the support for any generic staking financial contracts.
Unresolved questions
Future possibilities