stacksgov / grants-program

Archive of past Stacks Foundation grant applications. Historical record of ecosystem development.
https://stacks.org/grants
141 stars 36 forks source link

On-chain Accounting for Stacking Pools (Take 2b) #121

Closed friedger closed 2 years ago

friedger commented 3 years ago

Background Users of stacking pools have to trust the pool admin to manage their rewards correctly. Transparency can help to increase the trust. Therefore, income and expenses should be collected on-chain. This will create transparency as well as help to automate stacking pool operation in the future. This is the next step to make stacking pools more autonomous. Friedger Pool and other community stacking pools should benefit from it.

Project Overview The project is about writing a smart contract and a web interface that allows users and pool admins to submit and view tx of stacking pools that payout rewards in stx as well as perform some pool admin tasks. Users and pool admins have the same privileges because the submitted data is verified on-chain.

The project will collaborate and use results from related work by the following projects:

Scope What are the components or technical specs of the project? What will the final deliverable look like? How will you measure success? Components:

The project will be successful when

  1. users participate in delegated stacking through the smart contract in cycle #11.
  2. the pool contract meets the static stacking minimum (min_increment_ustx) and can join Friedger Pool's btc reward address.
  3. rewards are claimed and received by users through the smart contract.

Budget and Milestones What grant amount are you seeking? How long will the project take in hours? If more than 20, please break down the project into milestones, with a clear output (e.g., low-fi mockup, MVP with two features) and include the estimated work hours for each milestone.

Total Grant Request: $12000

M1: Smart contract for submitting btc transactions + web app to submit and view txs (1 week) $1500 development clarity + web $1500 operating costs Friedger Pool

M2: Extended smart contract with pool operations + web app + testnet test (1 week) $5369

M3: Extended smart contract with pool operations + web app + testnet test (1 week) $3631

M4: Invite pool members to use the contract for the next cycle. (1 week) $3000

Team Who is building this? What relevant experience do you bring to this project? Are there skills sets you are missing that you are seeking from the community? Please share links to previous work.

Friedger Müffke, pool administrator of Friedger Pool,

I have one open grant (https://github.com/stacksgov/Stacks-Grants/issues/84) that only requires a bit of communication with other pool admins over the next weeks.

I am looking for

Risks

The project depends on the successful submission of the Stacks Wallet for Web through the Hiro team. The project can only be successful once the wallet is published on the corresponding browser extension sites.

The verification of btc tx is not yet well tested in production. It can be too difficult or impossible to do it on-chain. Therefore, M1 focus on this part of the proposal.

Community and Supporting Materials This is continued work for Friedger Pool and related community stacking pools, following #52 and #84

This grant is a duplicate of #92 for easy accounting :-)

stx-grant-bot[bot] commented 3 years ago

Thanks for submitting a grant proposal. Our team will review your submission and get back to you.

stx-grant-bot[bot] commented 3 years ago

Congratulations. Your grant is now approved. Please complete the on-boarding link here: https://stacks-grant.netlify.app/onboard?q=456bb6b37dbef3daef15fc5e1d820215

stx-grant-bot[bot] commented 3 years ago

M1 has been funded! When you are finished with this milestone, please comment on this issue with !m1_complete

friedger commented 3 years ago

The first bitcoin transaction has been verified on the stacks testnet. I wrote a summary here: https://app.sigle.io/friedger.id/zwmiYGAH1TvqQnoiKGqSV The web app is part of Speed Spend. This complete m1

friedger commented 3 years ago

!m1_complete

stx-grant-bot[bot] commented 3 years ago

Thank you for completing M1. The grant committee will review and confirm completion or send feedback within a week

jennymith commented 3 years ago

Congratulations @friedger! Looking forward to M2. Just keep us posted on your work involving the price oracle.

stx-grant-bot[bot] commented 3 years ago

M2 has been funded! When you are finished with this milestone, please comment on this issue with !m2_complete

friedger commented 3 years ago

Update M2 - week 1

Bitcoin Testnet suffered from a Blockstorm and therefore, our testing was postponed.

Price finding via oracle has been improved to fall back to previous blocks (up to 3) in case of flash blocks or as a last resort to the last known price. The contract is deployed with a call to the price oracle such that there will always be a last known price. - With the launch of .btc domains we saw that the oracle couldn't register prices for more than 5 days.

Discord server for testing community is ready, @OmurCataltepe joined to support community during testing.

Next steps:

friedger commented 3 years ago

Update M2 - week 2

Bitcoin Testnet is working better.

More testing happened, UI has been improved.

As part of testing, a trustless BTC/STX swap has been implemented and tested: https://twitter.com/fmdroid/status/1410018264982470663

Next steps:

friedger commented 3 years ago

!m2_complete

stx-grant-bot[bot] commented 3 years ago

Thank you for completing M2. The grant committee will review and confirm completion or send feedback within a week

stx-grant-bot[bot] commented 3 years ago

M3 has been funded! When you are finished with this milestone, please comment on this issue with !m3_complete

stx-grant-bot[bot] commented 3 years ago

M3 has been funded! When you are finished with this milestone, please comment on this issue with !m3_complete

friedger commented 3 years ago

Milestone 2 has been split into 2 milestones to reflect the two payments for it. The previous Milestone 3 has been renamed to Milestone 4.

Looking forward to the new testnet!

friedger commented 3 years ago

Testnet is running, but we still don't have the possibility to test stacking (https://github.com/blockstack/stacks-blockchain-api/issues/664)

I tested the bitcoin clarity library on mainnet with BTC-NFT catamaran swap: https://twitter.com/fmdroid/status/1418533936498724874

friedger commented 3 years ago

I hit a road blocker. I am missing a way in clarity to find out and verify during which reward cycle a bitcoin transaction happened.

This is needed for the payout of rewards. As it looks to me, that a solution can only happen with Stacks 2.1 (see https://github.com/blockstack/stacks-blockchain/issues/2784)

friedger commented 3 years ago

!m3_complete

With the current blocker, here is a review from the scope and what I have achieved.

Contracts

There will be two smart contracts Auditing contract submit btc tx for rewards received by the pool's btc reward address, the corresponding stx value of the reward will be determined by an oracle, the value is stored both in stx and btc. submit btc tx for btc withdraw from pool's btc reward address, the corresponding stx value of the withdraw will be determined by an oracle, the value is stored both in stx and btc.

There are two auditing contracts in https://github.com/friedger/clarity-friedger-pool/tree/main/contracts:

The withdraw txs from the pool were too large (500+ ins) to verify them on-chain. Therefore, I decided to use the wrapped rewards token and audit these tokens instead of bitcoins directly. They map 1 sat to 1 reward token.

Admin contract delegate stx that are immediately locked by the users themselves aggregate commit the pool 50 blocks before the start of the next cycle request stx rewards payouts proportionally to their delegated stacked stxs, the total reward amount is retrieved from the auditing contract

This is implemented in the Boombox contract https://gitlab.com/riot.ai/clarity-boom-pool/-/blob/master/contracts/boomboxes-12.clar. The contract allows to delegate stx with immediate locking and to do the aggregate commit by any user, no interaction by the pool admin.

The payout can't be done trustless for now due to the blocker about cycle to reward mapping.

Web UI

The web app will focus on functionality and reuse design and app architecture of Speed Spend/Pool Registry/Send Many uses connect library for tx signing (requires users to use Stacks Wallet for Web) show btc and stx of the submitted txs provide UI to call the smart contract functions provide UI to allow the smart contract to manage the users' delegation

The UI for auditing with price oracle is implemented as part of Friedger Pool on https://pool.friedger.de/members The UI for managing the user' delegation is implemented in https://boom.money

Speed Spend has also some UI for verifying btc transactions and doing stack aggregation commit transactions: https://www.speed-spend.org/pool-audit

I contributed to stacks-blockchain-api to simplify the auditing process (https://github.com/blockstack/stacks-blockchain-api/issues/675)

User education update pool.friedger.de and include information how to use the smart contract answer questions via email, discord, twitter (and occasionally other social media)

The details about how to use the smart contracts are described in these articles:

I run a discord server for testing and answer emails, twitter, discord, reddits daily.

Testing

Test on Testnet

I did a few tests on testnet to verify the clarity-bitcoin-library before the testnet reset. Since then, it is not possible to test stacking.

I did more tests on mainnet with the 3 Catamaran swaps and 1 Catamaran mint that all use the clarity-bitcoin-library.

Operation

Operate Friedger Pool until it runs autonomous. This includes customer services, maintaining the website, trading BTC/STX, accounting, legal advice.

Friedger Pool is successfully participating in stacking since cycle #3 without any missed cycles. In cycle 13, we stacked 12,2m STXs for 1138 members (see details https://pool.friedger.de/cycles/) https://app.sigle.io/friedger.id/dAZao4q9C22DL76zHsF5-

What is left to do?

M4 user education

During cycle 13, I will assist users to use the smart contract, to report btc tx and claim their rewards in wrapped reward tokens at the end.

What was not achieved?

The fully automated stacking pool could not yet be realized. It is not possible to support btc transactions that happen during flash block. Furthmore, btc transactions can't be linked to the reward cycle trustlessly.

The relevant issues are:

The future (new grant maybe)

Friedger Pool will release a wrapped reward token that can be swapped against STX trustlessly.

stx-grant-bot[bot] commented 3 years ago

Sorry, you can only complete a milestone if it is active.

friedger commented 3 years ago

!m3_complete

stx-grant-bot[bot] commented 3 years ago

Thank you for completing M3. The grant committee will review and confirm completion or send feedback within a week

friedger commented 3 years ago

The first tx is now listed on https://pool.friedger.de/members (https://github.com/friedger/stacking) Screenshot from 2021-07-30 22-37-23

friedger commented 3 years ago

Update:

Full report here: https://app.sigle.io/friedger.id/MA3mBt0f-fwK2GxxG4JWY

I am still continuing to educate users about the impact.

RaffiSapire commented 3 years ago

Thanks @friedger we reviewed M3, great work! will disburse for M4 today.

friedger commented 3 years ago

Until today 0.5% of the reserved wrapped rewards have been claimed by 12 users. Considering that there is no use case for the wrapped rewards so far and that users with hardware wallets can't claim the tokens, we could at least show that it works.

As the final part of M4, I published an article about using the wrapped rewards for accounting and for other services like catamaranswaps.org:

https://app.sigle.io/friedger.id/sJuX84nlvLYEGfUTZVfZA

This completes M4.

Nevertheless, I will continue to help users using the wrapped rewards and running the pool of course. I am in contact with Hiro about the oracle for block heights, ideally this will run on my threefold node.

friedger commented 3 years ago

!m4_complete

stx-grant-bot[bot] commented 3 years ago

Thank you for completing M4. The grant committee will review and confirm completion or send feedback within a week

jennymith commented 3 years ago

Hi @friedger thanks for your hard work on getting this grant over the finish line, especially considering all the challenges you ran into! We can mark this as complete cc: @RaffiSapire @jhammond2012.

Some feedback for continued/future work:

It seems that the low redemption rate for wrapped rewards stems from the difficulty of the process. We understand that you won't be able to reasonably improve this process until Hiro pushes certain upgrades to its wallet. In the meantime though, perhaps you could consider the following:

We also encourage you to share the tools you've built with other pool operator/third parties. The tools you've developed have really advanced the decentralization of Stacking pools--all operators and Stackers could really benefit from implementing and using them.