GithubHelp home page GithubHelp logo

syvita / sypool Goto Github PK

View Code? Open in Web Editor NEW
24.0 5.0 4.0 5.62 MB

Sypool is a custodial STX mining pool using smart contracts on the Stacks blockchain for trustless contributions & reward redemption. 🏊 ♾️

Home Page: https://sypool.co

License: GNU Affero General Public License v3.0

JavaScript 75.02% TypeScript 2.92% CSS 22.06%
stacks mining-pool stx web3 smart-contracts nextjs deno typescript clarity stacks-address

sypool's Introduction

CodeFactor Test contracts

UPDATE: The grant request for mining hardware to the Stacks Foundation has been approved.


How it works (simply)

Mining STX tokens is a game of numbers and probability. In order to mine profitably, an estimated ~1BTC is required initially. Many people don't have 1BTC to throw at a new miner, so we made this!

This 'pool' combines lots of people's Bitcoin together to mine STX profitably. You put Bitcoin in and get STX tokens out. You commit Bitcoin at our site, which will then add you to the list of contributors in the smart contract.

Fee model

There is a 5% fee on profits. 20% of this fee is distributed to Sypool Collateral holders (when collateral gets activated).

If you contribute 1BTC and when you redeem your proportion of STX back you have 1.5BTC worth of STX, the fee will be 0.5BTC * 0.05 = 0.025BTC fee so you would get 1.475BTC back.

The Sypool ($SYPL) token

When you commit your sats, we'll send an equal amount of Sypool tokens to your Stacks address. If you contribute 500,000 sats, you get 500,000 Sypool tokens to your Stacks address.

What can you do with these tokens? You can vote on decisions that we as a community might make in the future, and more importantly, you can redeem your STX rewards.

After 1000 blocks (1 cycle), you'll be able to redeem your STX rewards. You might not make a profit after this 1000 block cooldown, as not all of your Bitcoin would have been spent for mining yet. Don't worry if you don't make a profit, as the miner will eventually use up all your BTC.

we got trust issues

Understandably. We're as transparent as possible, and automate as much as we can so there's less grey area for us to go wrong.

Once you commit Bitcoin, after the cooldown, you can take your share out (if you want), even if all our services go down. This is ensured by the smart contract and requires no manual intervention from us.

The only trust is that we use the Bitcoin to mine. Basically everything else is automated and trustless through the contract. And if we don't use the Bitcoin to mine, 20% of the 5% fee goes towards collateral providers, to reduce risk (when activated).

How does it really work?

most likely outdated, updates to come soon

Warning: technical bits ahead

Syvita's pool is not unique in that it is primarily controlled by a smart contract. However, it is unique in how it verifies contributions cross-chain through hashing, merkle roots and some other cool stuff. Big s/o to Jude at the Stacks Foundation for how this works. He wrote the majority of the Bitcoin library functions that the pool uses to verify contributions.

From start to finish

First, a user that wants to contribute bitcoin hashes a secret with SHA512. This is generated in the UI client-side for ease-of-use. This hash is then added to the HashMap in the smart contract through the public function register-hash. Once they've done this, the hash is stored along with the tx-sender, in this case, the Stacks address the user wants their rewards to be redeemable to.

Once the smart contract call confirmed and is ok, the user sends a Bitcoin transaction to add their Bitcoin to the pool's publicly known BTC address with secret in the OP_RETURN output of the transaction. This can be from any Bitcoin address or key, and doesn't have to be one tied to the Stacks redeem address.

Once that confirms on the BTC chain, the user calls the reveal-hash function with the transaction, a Merkle proof and secret. this function verifies that:

  1. The transaction was mined on the Bitcoin chain using the Merkle proof (verifies it's a valid transaction)
  2. secret is registered in hash-map that was stored in the first step (secret is needed for adding btc)
  3. SHA256(secret) is in the OP_RETURN field of the passed transaction (makes sure you were the one who sent the transaction)
  4. The transaction pays out to the known pool BTC address that's used to mine. (self-explanatory)

If all of those return ok, the contract extracts how many sats were added to the pool and mints that amount of Sypool fungible tokens to the tx-sender in hash-map.

Worth noting that these fields will be autofilled by the UI to improve ease-of-use, though can be set manually (if something goes wrong with the UI). The user will enter their txid once it has been mined, then the UI will pull the necessary info from a Bitcoin node. Also worth saying - all these values can be entered manually by you in the UI (or the Stacks Explorer even) if you don't trust what the UI is doing. UI is also open-source and in this repo for you to read through if you want :)

Cool. All done. And now for the (relatively) simpler mining process. The Bitcoin that's sent to the pool are then transferred to Stackers to try to win the ability to mine the block. If the miner wins this 'lottery' against other miners, the miner gets the block reward and all transaction fees in that.

The miner also will mine microblocks when it has won a block, which you can read more about here, along with other cool stuff for mining.

When the miner gets the rewards, it creates a transaction in that block that immediately sends the STX rewards to the smart contract. Over time, these will average out and make it so (hopefully) each user of the mining pool makes a healthy profit.

The 5% fee only applies on profit. The contract will get the current STX/BTC from Swapr and calculate how much profit you made, then charge the 5% fee on the profit you made. If you made a loss, the fee doesn't apply.

Architecture

The web UI will be hosted as a static Next.js site on Cloudflare's edge, alike other Syvita sites. The static site will make API requests to Stacks node B as default. The code for this site is in this repo.

The Bitcoin node & Stacks node A (the miner) will be hosted on a M1-based Mac Mini owned and managed by Asteria. This will be locally controlled and not accessable to the public internet as a private key to the pool Bitcoin wallet are held here. The Mac is connected only via a VPN, as to not expose the IP address, open any public ports to the machine and reduce the attack surface. The Bitcoin node is Bitcoin Core and the Stacks node is the one created by Hiro.

Stacks node B will be run as a VM on Bitlaunch. No private keys or funds are stored on this machine. It will be connected to requests to it via a Cloudflare Argo Tunnel, to protect from attacks. This node runs stacks-blockchain-api, created by Hiro.

Both Stacks nodes will be updated as new releases of the Stacks node software are released. Stacks node B will have a 2nd VM booted and connected to Cloudflare until it has caught up with the chain, then traffic will be routed to it via Cloudflare and the other VM will be destroyed. Stacks node A will use a similar method, but will start a new instance on the same machine instead.

sypool's People

Contributors

dependabot[bot] avatar snyk-bot avatar vidiabtc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

sypool's Issues

Bounty 1: Build STX Mining Pool Infrastructure

Extend Daemon's Mining Bot to make it easy to start and run or join an STX mining pool.

Type: Solo or Team
Expiration Date: Good until cancelled
Reward: 100,000 STX tokens to the best entry (winner take all)

Requirements

  • Must make use of Daemon's mining bot
  • Creation of mining pool must be permissionless (anyone can do it)
  • Must be open source

Judging Criteria

  • How easy is it to create a new STX mining pool?
  • How easy is it to add members to and operate a new mining pool?
  • How fault-tolerant is the setup and operation of the pool? Another way of asking this is what is the worst a bad actor can do to a pool?
  • Preference will be given to submissions with no/minimal coding needed to start or join a pool. Ideally this is something a nontechnical person could use to create a STX mining pool.

How to Submit

  • Create a PR in the Mining Bot repo with the infrastructure you have built.
  • Send an email to [email protected] with a link to the PR, and an explanation of what you have built.
  • Daemon Technologies reserves the right to require a follow-up call to cover any questions on your submission.

Bounty 2: Create & Grow a STX Mining Pool

Become one of the first 2 STX Mining Pools with at least $100,000 of BTC committed for a Stacking cycle.

Create an STX Mining pool, start operating it, and try to grow the amount of BTC pooled to at least $100,000. You may create proprietary infrastructure and/or business models for your pool.

Type: Solo or Team
Expiration Date: Good until cancelled
Reward: 2 separate rewards, each for 100,000 STX tokens

Requirements

  • Mining pool must be permissionless, meaning anyone who wants to join can
  • Must use the pooled BTC for the purpose of STX Mining
  • Must have proof of mining activity over the course of at least 1 Stacking cycle

Judging Criteria

  • How does the submission go about pooling? Is it custodial?
  • How does the submission ensure the safety of member funds?
  • How easy is it to join?
  • How many members have committed capital? (of 2 pools both have $100K BTC committed, preference will be given to the pool that has more members)

How to Submit

  • Send an email with your pool's information, including BTC and STX addresses to [email protected].
  • Include the pool's BTC address and snapshots of the pool's BTC balance.
  • Include proof of STX Mining activity over the course of 1 Stacking cycle.
  • Daemon Technologies reserves the right to require a follow up call to cover any questions on your submission

Dealing with (temporary) losses due to mining - dealing with it programatically

There was a discussion in Discord about this asteria mentioned we might vote when to stop mining when the yield drops due to fluctuations in market valuation of BTC or STX or both.

I do not think we can use an onchain voting procedure for this, that may take to long. I think we should decide beforehand what we deem unprofitable. The way stxmining.club calculates this is just one way. The bullish miner that kept bidding 800,000 sats per block clearly had an other idea compared to the miners bidding ~400k sats (on May 19th it was the first time he changed since a long time).

Some questions to consider: i.e. do we use a 30 day moving average to valuate stx? instead of the current average? Do you use the value of BTC when it was committed or day to day avg trading price? In Discord I found agreement that we do not want to consider conversion to dollars at all, seems like a good idea to only consider the BTC <-> STX trading pair.

When members commit BTC to the miner address they could give a range for their stx valuation in sats (i.e. 2500 sats per 1 stx or 3000 - 2500 sats per stx). This could be repeated/adjusted by members every cycle (2 weeks). That way temporary changes in the market have little influence? And the miner can use that data to make his bids based on that info.

The miner would need to programmatically adjust its bids based on what other miners do. Temporary bidding more to keep going vs stopping and restarting may also be reasonable for hours in the day and within reason ofc (some max bid). Atleast it was Daemon's experience that miners who were online continuously were most profitable because the odds become more favorable (with good ratio between own bid/total bid per block ofc. )

There is also a system in place to discourage short term miners. I am not sure if that is only done by the time between winning a bid and getting the reward or there is more to it.

How I think we should build this now based on the trading pair.

  • Use some oracle for STX/BTC pair valuation: lets say 30 day moving average for 1 stx is 3000 sats. (MarketValuationSTX)
  • Lets assume we require some minimum of profitmargin: lets say 5%. (MinimumProfitMargin)
  • Total bid should not exceed 3000 - 5% of 3000 = 2850 sats per stx or 2850000 sats per block
  • We set a certain minimum percentage of blocks we want to win: i.e. 10% of all blocks (BlockWinRate)
    --> influenced by how many miners there are and how much BTC the pool has for two weeks, lets assume we want to continuously mine that is best for the network and best for our odds on winning 10% of blocks consistantly. We bid more and win more blocks if we have more BTC. We always work in mining per (2 week) cycle (that is also needed to earmark profits and sypool tokens). People can start committing BTC to mine in a specific cycle.
  • In that case we bid a maximum of 10% of 2850000 per block
  • MarketValuationSTX and MinerValuationSTX (=total commits by other miners per stx in a coinbase) together determine the actual bid, when we make our first bids we will also have to see how the other miners adjust their bids. i.e. if current bids total 2,850,000 per block and we add 285,000 the total will exceed the MarketValuationSTX and our effective BlockWinRate is <10% (285/(2850+285)) yet we expect other miners to adjust in time how many blocks that is to be determined.

And then we can think about scenarios where a new miner starts bidding or one leaves and our effective BlockWinRate goes down or up. We may accept that for x amount of blocks and then make adjustments accordingly.

Asteria in the call just now someone asked how long untill someone can claim rewards. Would this need to be a fixed amount so we know what Sypool tokens are for what profit margin? Or is this arranged outside of smart contracts.
It would make sense to have Sypool tokens for a specific cycle. You commit for mining in cycle 10 and you receive sypool tokens earmarked cycle 10. Sats will be spend in cycle 10 (as per the above bids are adjusted to spend all committed sats for that cycle so the miner can be active continuously). And then someone can claim rewards for cycle 10 by sending Sypool cycle 10 tokens to the contract and claim stx rewards with whatever effective profit margin.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.