Synthetixio / synthetix

Synthetix Solidity smart contracts
https://synthetix.io/
MIT License
1.2k stars 599 forks source link

SNX Staking Pool #192

Open hav-noms opened 4 years ago

hav-noms commented 4 years ago

Staking SNX is a fairly complicated process with numerous strategies to optimise yield and reduce risk. There are a number of community members who have put significant effort into optimising these strategies, particularly Nocturnalsheet. The effort and skill required to optimally stake SNX presents an opportunity for staking pools managed by community members with fee structures based on performance. There are several custodial staking pools considering SNX integration including EON and Staked, however, we believe there is an opportunity for non-custodial pools.

We need a contract to be written that supports the following functionality:

General features

For pool participants

For pool managers

*because staking rewards are escrowed for a rolling 52 weeks against the pool contract, in order for a depositor to withdraw reward SNX escrowed in the RewardsEscrow Contract https://etherscan.io/address/0xb671F2210B1F6621A2607EA63E6B2DC3e2464d1F, the StakingPool needs a mapping to track the SNX rewards that the depositor is eligible for, so when the Pool Manager calls RewardsEscrow.vest() and the escrowed SNX rewards for the vesting period is sent to the StakingPool contract the the depositors can withdraw their allotment of the SNX rewards from the StakingPool.

*There should be some protection considerations for if the PoolManager has lost key access / gone AWOL

Deliverables

Associated Bounties | links will be posted soon Deployment dApp so a pool manager can configure and deploy a new pool.

A dApp that displays all active pools, including the fee structure and performance. Allow users to deposit/withdraw into pools.

gitcoinbot commented 4 years ago

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


This issue now has a funding of 15000.0 SNX (4342.5 USD @ $0.29/SNX) attached to it as part of the Synthetixio fund.

JGcarv commented 4 years ago

Hello,

First of all I apologize for taking this long to provide an update on any kind of progress.

Here is my naive approach to the staking pool, which closes part 1 of my working plan: https://gist.github.com/JGcarv/84056424d7a5052e0aabe33591ebb7ea

There're still two main points missing in the main contract: 1) Proper fee mechanisms 2) An exit mechanism. Right now, the withdraw function assumes that there's liquid SNX available, but that's not necessarily true, since some par of it might be locked or escrowed. For that my best solution so far is to make a sort of "fork" of the total assets available, transferring the manager function to the pool participants, but that brings other flavors of issues.

Anyway, that's just to provide a quick update on my working status, I hope to open a proper PR with my progress sometime tomorrow.

kaiynne commented 4 years ago

No problem, I think the solution to the exit problem will be account merging. It would basically allow the staking pool to reallocate a portion of the escrowed rewards to an exit address.

JGcarv commented 4 years ago

Don't this SIP defines that the full amount of SNX must be moved to another address at once? If that's the case, could it still be used as an exit for a single participant?

kaiynne commented 4 years ago

That’s a good point, I’ll review my notes on that SIP again and see what other options we had considered.

On 6 Sep 2019, at 11:48 pm, Joao Gabriel Carvalho notifications@github.com wrote:

Don't this SIP defines that the full amount of SNX must be moved to another address at once? If that's the case, could it still be used as an exit for a single participant?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

RideSolo commented 4 years ago

@kaiynne I'm new to gitcoin and I would like to apply for this request, I couldn't do it through the website page. is it taken or closed?

hav-noms commented 4 years ago

@RideSolo its taken sorry

@kaiynne I'm new to gitcoin and I would like to apply for this request, I couldn't do it through the website page. is it taken or closed?

RideSolo commented 4 years ago

@hav-noms ok guys good luck then

hav-noms commented 4 years ago

@JGcarv Cool to see progress

  1. An exit mechanism. Right now, the withdraw function assumes that there's liquid SNX available, but that's not necessarily true, since some par of it might be locked or escrowed. For that my best solution so far is to make a sort of "fork" of the total assets available, transferring the manager function to the pool participants, but that brings other flavors of issues.

I've just updated the issue with a solution for depositors to vest/withdraw their escrowed SNX rewards.

Also for an exit mechanism it should just follow the existing system. Try using mintr for yourself to get familiar with the process. You will need some SNX tho.

So for a user to exit the system, meaning they want to sell all their SNX then they need to repay their debt of the sUSD they minted, (like DAI repaying the loan) so the StakingPool will need to access the Synths its minted and burn the appropriate amount to release that users SNX. So the StakingPool will need a reserve of its minted Synths or kick off a process to pull its Synths out of the Depot or uniswap pool it sent them too then burn them then potentially send the user their SNX in one transaction

I think building the StakingPool to mint sETH and just send the sETH to the sETH uniswap pool is great because then the pool will get the LP tokens and earn LP SNX rewards and LP fees from the pool.

I'd say make depot support optional or skip it all together.

RideSolo commented 4 years ago

@hav-noms @kaiynne I see that the work expired without update from the previous dev, If you want I think that I can make a good work plan with a proposal for you guys since I developed a staking contract previously for callisto network.

JGcarv commented 4 years ago

Hello all!

First, I want to say that I didn't know that the bounty had an expiration date and since I've been pretty slow with this, I'll completely understand If you guys want to give the bounty to another dev, like @RideSolo . In that case, feel free to use my code, posted in a gist above as starting point, if you like.

Otherwise, I'm still up for doing it and I'll make an effort to finish as soon as possible, I'm aiming for end of the week. And since we're here I would like to take an opportunity to ask everything I still don't understand.

  1. Regarding interaction with uniswap: To be a LP is necessary to provide both sETH and ETH to uniswap contracts, therefore pool participants would need to provide the pair to the staking contract, since I don't think the Depot allows for trading SNX for ETH. This could be easily implemented but it does seem like a deviation from the initial proposal. Should we go ahead with this? Or is there another way that I'm missing?

  2. When Synths are burnt is the whole of the amount of SNX readily available for use? Or there's also a vesting mechanism?

  3. Is getting the collateralisationRatio a reliable way to get the total amount of SNX for an address?

  4. Should withdraws from the pool be on liquid SNX only? If so, can we run into the scenario that users can't get out because there's no liquidity(all of SNX is escrowed, for example)?

I think that's it for now. The updated ideas of @hav-noms are enough to make a reliable exiting mechanism, I believe.

kaiynne commented 4 years ago

@JGcarv Sorry my fault, I meant to extend this, so we would like you to keep working on it and take it to completion please. This is not hugely urgent, I just set a 1 month expiry by default when we posted it.

hav-noms commented 4 years ago
  1. Regarding interaction with uniswap: To be a LP is necessary to provide both sETH and ETH to uniswap contracts, therefore pool participants would need to provide the pair to the staking contract

Yeah uniswap is a not viable option because of the ETH requirement

since I don't think the Depot allows for trading SNX for ETH. This could be easily implemented but it does seem like a deviation from the initial proposal. Should we go ahead with this? Or is there another way that I'm missing?

It doesn't, well it does for the foundation only but not for anyone. Anyone can deposit sUSD though and sell for ETH so perhaps.

  1. When Synths are burnt is the whole of the amount of SNX readily available for use? Or there's also a vesting mechanism?

If you dont have any SNX Rewards then True. If you do then only the SNX in your wallet is ready to transfer. The SNX in the RewardsEscrow contract is locked up for 12 months from claiming. So vesting will needed to be done at a later date. People will need to return to claim. There may end up being lots of unclaimed SNX if people exit and forget.

  1. Is getting the collateralisationRatio a reliable way to get the total amount of SNX for an address?

Use Synthetix.collateral(account) to get the accounts total SNX in both wallet and in escrow. Use Synthetix.balanceOf(account) to the the SNX in their wallet collateralisationRatio is the value or the SNX used as collateral to the value of the synths they've minted

  1. Should withdraws from the pool be on liquid SNX only? If so, can we run into the scenario that users can't get out because there's no liquidity(all of SNX is escrowed, for example)?

No. users should be able to exit at anypoint. Just have the pool burn some sUSD to release the users SNX and let them withdraw it and leave.

hav-noms commented 4 years ago

hey @JGcarv any updates on this one?

JGcarv commented 4 years ago

Hello @hav-noms

Unfortunately, I've been crazy busy this month and could barely work this.

I took some time today to see where I'm at and I believe that there isn't that much left to be done. In the pool side, it's missing the mechanics for users to withdraw claimed fees and a smaller refinement on how the pool manager can charge fees.

After that, I need to create the factory, which should be quick and than expand the test coverage a bit.

I'll take this weekend to tackle this, as I've dragging for too long.

I'm really sorry for taking this long.

bneiluj commented 4 years ago

Hey guys - I've been working on different staking pool architectures across different staking systems.

What is the status of this issue ? @JGcarv are you free next week (Tuesday / Wednesday) to have a quick chat about your current idea ?

bneiluj commented 4 years ago

Any news on this issue ?

RideSolo commented 4 years ago

@hav-noms @JGcarv I have worked on this a year and half ago:

The following code is the implementention of the previous proposal:

of course it should be updated to snx staking requirements to make everything fit, and the solution should be highly optimized since no array is required to track users multiple stake and staking time.

The code was implemented for callisto network, and can be matched with snx and Uniswap pool with some modifications

I can team up with Jgcarv to deploy the code

RideSolo commented 4 years ago

@hav-noms is this bounty still open ?

gitcoinbot commented 4 years ago

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


Work has been started.

These users each claimed they can complete the work by 8 months, 2 weeks ago. Please review their action plans below:

1) developerfred has started work.

I would love to build this stacking pool. I have knowledge in contract construction and I know a little about auditing.

Learn more on the Gitcoin Issue Details page.

zoek1 commented 3 years ago

hey @hav-noms is this bounty still open? i'm pretty interested on working on this! My profile https://gitcoin.co/zoek1, you could see i'm pretty reliable :)

gitcoinbot commented 2 years ago

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


Work has been started.

These users each claimed they can complete the work by 2 years, 2 months ago. Please review their action plans below:

1) connoroday has started work.

Rescue the funds!!!!!!!!!!!!!!

Learn more on the Gitcoin Issue Details page.