Coder Social home page Coder Social logo

harvest's People

Contributors

borispovod avatar krishnacore avatar mkurnikov avatar obaranni avatar sirwill avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

harvest's Issues

Make sure that StakeCoins are always obtainable to withdraw

In unstake function we have few invokes of functions where arithmetic error can occur:

  • fun update_accum_reward:

let total_reward = to_u128(pool.reward_per_sec) * to_u128(seconds_passed) * SIX_DECIMALS;
pool.accum_reward = pool.accum_reward + total_reward / to_u128(total_stake);

  • fun update_user_earnings:

let earned = (accum_reward * (to_u128(user_stake.amount)) / SIX_DECIMALS) - user_stake.unobtainable_reward;
user_stake.earned_reward = user_stake.earned_reward + to_u64(earned);
user_stake.unobtainable_reward = user_stake.unobtainable_reward + earned;

  • fun unstake:

user_stake.unobtainable_reward = (pool.accum_reward * to_u128(user_stake.amount)) / SIX_DECIMALS;

It is necessary to check the correctness of the calculations with boundary values. These calculations are also associated with issue #13.

Handle different decimals for Stake and Reward coins

For now we use six decimals in reward calculations:
const SIX_DECIMALS: u128 = 1000000;

Like in this case, user_stake.amount is stake coin amount with six decimals and result earned - amount for reward coin with six decimals:
let earned = (pool.accum_reward * (to_u128(user_stake.amount)) / SIX_DECIMALS) - user_stake.unobtainable_reward;

We need to come up with restrictions on decimals, adapt the calculations to their different values.

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.