GithubHelp home page GithubHelp logo

challenge's Introduction

Ether staking and get reward per week

Summary

ETHPool provides a service where people can deposit ETH and they will receive weekly rewards. Users must be able to take out their deposits along with their portion of rewards at any time. New rewards are deposited manually into the pool by the ETHPool team each week using a contract function.

Requirements

  • Only the team can deposit rewards.
  • Deposited rewards go to the pool of users, not to individual users.
  • Users should be able to withdraw their deposits along with their share of rewards considering the time when they deposited.

Example:

Let say we have user A and B and team T.

A deposits 100, and B deposits 300 for a total of 400 in the pool. Now A has 25% of the pool and B has 75%. When T deposits 200 rewards, A should be able to withdraw 150 and B 450.

What if the following happens? A deposits then T deposits then B deposits then A withdraws and finally B withdraws. A should get their deposit + all the rewards. B should only get their deposit because rewards were sent to the pool before they participated.

Keep staking principle.

First week:

  • A deposit 100, B deposit 150 and T deposit 500
  • A withdraw 100 + 200 = 300
  • ** B don't withdraw
  • Pool Ether: 100 + 150 + 500 - 300 = 450
  • B reward: 500 * 150 / 250 = 300

Second week:

  • C deposit 100 and T deposit 500
  • Total balance: 450 + 100 + 500 = 1050
  • Then B available withdraw amount ???
  • Not this: 1050 * 150 / (150 + 100) = 630

** B will be able to withdraw: 300 + 500 * 150 / (150 + 100) = 600

Test network contract: https://rinkeby.etherscan.io/address/0x00322a7E8e774157B3f160245Ac6365ae024D9f3#code

Test Result

 ·-----------------|-------------·
 |  Contract Name  ·  Size (Kb)  │
 ··················|··············
 |  console        ·       0.08  │
 ··················|··············
 |  SafeMath       ·       0.08  │
 ··················|··············
 |  Staking        ·       3.05  │
 ·-----------------|-------------·

  Token test
    √ Add Admin
    √ Stake
    √ Get Pending Reward
    √ UnSake
    √ Next week
    √ Next week: Get Pending Reward

·------------------------------|---------------------------|-------------|-----------------------------·
|     Solc version: 0.8.0      ·  Optimizer enabled: true  ·  Runs: 200  ·  Block limit: 30000000 gas  │
·······························|···························|·············|······························
|  Methods                                                                                             │
·············|·················|·············|·············|·············|···············|··············
|  Contract  ·  Method         ·  Min        ·  Max        ·  Avg        ·  # calls      ·  usd (avg)  │
·············|·················|·············|·············|·············|···············|··············
|  Staking   ·  addAdmin       ·      47394  ·      47406  ·      47400  ·            2  ·          -  │
·············|·················|·············|·············|·············|···············|··············
|  Staking   ·  depositReward  ·      54178  ·      59653  ·      56916  ·            2  ·          -  │
·············|·················|·············|·············|·············|···············|··············
|  Staking   ·  stake          ·      54877  ·      74777  ·      67210  ·            3  ·          -  │
·············|·················|·············|·············|·············|···············|··············
|  Staking   ·  unStake        ·          -  ·          -  ·      50834  ·            1  ·          -  │
·············|·················|·············|·············|·············|···············|··············
|  Deployments                 ·                                         ·  % of limit   ·             │
·······························|·············|·············|·············|···············|··············
|  Staking                     ·          -  ·          -  ·     820165  ·        2.7 %  ·          -  │
·------------------------------|-------------|-------------|-------------|---------------|-------------·

  6 passing (806ms)

challenge's People

Contributors

smart-hunter avatar gabrielgruber avatar

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.