Skip to content
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

SNX Staking Pool #192

Open
hav-noms opened this issue Aug 12, 2019 · 19 comments · May be fixed by #291
Open

SNX Staking Pool #192

hav-noms opened this issue Aug 12, 2019 · 19 comments · May be fixed by #291
Labels
Projects

Comments

@hav-noms
Copy link
Member

@hav-noms hav-noms commented Aug 12, 2019

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

  • Tracking of pool percentage via liquidity tokens
  • locking the contract calls to whitelisted functions/addresses

For pool participants

  • Depositing of SNX
  • Withdrawal of SNX
  • Withdrawal of staking rewards

For pool managers

  • Mint/ burn with pooled SNX
  • Collect fees
  • Deposit to depot
  • Deposit to Uniswap sETH pool
  • Call exchange on SNX
  • Set fee structure % of fees, or % of SNX staked or some combination of the two

*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

  • that potentially a depositor can call StakingPool.vest and it proxy to RewardsEscrow.vest() and get only their SNX allotment.
  • a depositor can withdraw their SNX at any-point causing the contract to do the appropriate Synth burn to release their SNX

Deliverables

  • Smart Contracts StakingPoolFactory & StakingPool
  • Working environment on TESTNET (Contact us for TESTNET SNX)
  • Unit tests using truffle and JavaScript tests. See https://github.com/Synthetixio/synthetix

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

This comment has been minimized.

Copy link

@gitcoinbot gitcoinbot commented Aug 16, 2019

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

This comment has been minimized.

Copy link

@JGcarv JGcarv commented Sep 6, 2019

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

This comment has been minimized.

Copy link
Member

@kaiynne kaiynne commented Sep 6, 2019

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

This comment has been minimized.

Copy link

@JGcarv JGcarv commented Sep 6, 2019

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

This comment has been minimized.

Copy link
Member

@kaiynne kaiynne commented Sep 6, 2019

@RideSolo

This comment has been minimized.

Copy link

@RideSolo RideSolo commented Sep 8, 2019

@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

This comment has been minimized.

Copy link
Member Author

@hav-noms hav-noms commented Sep 11, 2019

@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

This comment has been minimized.

Copy link

@RideSolo RideSolo commented Sep 11, 2019

@hav-noms ok guys good luck then

@hav-noms

This comment has been minimized.

Copy link
Member Author

@hav-noms hav-noms commented Sep 11, 2019

@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

This comment has been minimized.

Copy link

@RideSolo RideSolo commented Sep 16, 2019

@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

This comment has been minimized.

Copy link

@JGcarv JGcarv commented Sep 16, 2019

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

This comment has been minimized.

Copy link
Member

@kaiynne kaiynne commented Sep 17, 2019

@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

This comment has been minimized.

Copy link
Member Author

@hav-noms hav-noms commented Sep 19, 2019

  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 hav-noms added this to In progress in Synthetix Oct 2, 2019
@hav-noms hav-noms added the Bounty label Oct 2, 2019
@hav-noms

This comment has been minimized.

Copy link
Member Author

@hav-noms hav-noms commented Oct 16, 2019

hey @JGcarv any updates on this one?

@JGcarv

This comment has been minimized.

Copy link

@JGcarv JGcarv commented Oct 17, 2019

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.

@JGcarv JGcarv linked a pull request that will close this issue Oct 21, 2019
@bneiluj

This comment has been minimized.

Copy link

@bneiluj bneiluj commented Oct 26, 2019

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

This comment has been minimized.

Copy link

@bneiluj bneiluj commented Oct 29, 2019

Any news on this issue ?

@RideSolo

This comment has been minimized.

Copy link

@RideSolo RideSolo commented Nov 16, 2019

@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

@hav-noms hav-noms moved this from In progress to To do in Synthetix Jan 20, 2020
@gitcoinbot

This comment has been minimized.

Copy link

@gitcoinbot gitcoinbot commented Jan 30, 2020

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


Work has been started.

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

1) ridesolo has started work.

First of all I have noticed that you are using this solution https://github.com/Synthetixio/Unipool/blob/master/contracts/Unipool.sol to reward sETH/ETH liquidity providers when they stake their Uniswap V1 token in the developed contract. I would like to know if this bounty does not cover the previously described implementation.
If not I assume that you intend to implement new contracts to reward users when they mint synths since it is done through a custodial solution right now, or you want to create a staking contract where managers will handle the users stake.
If you still need a developer to handle this, I would be happy to work on it, I have already implemented staking solution similar to unipool as you can see here: https://github.com/RideSolo/Cold-staking/blob/linear_formula/proposal.pdf.

Learn more on the Gitcoin Issue Details page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Synthetix
  
To do
Linked pull requests

Successfully merging a pull request may close this issue.

6 participants
You can’t perform that action at this time.