GithubHelp home page GithubHelp logo

ujju89 / staking-platform-fixed-apy Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aboudjem/staking-platform-fixed-apy

0.0 0.0 0.0 8.85 MB

Staking platform with Lockup and fixed APY, duration, and max stake. Optimized and simple implementation

License: MIT License

JavaScript 94.89% Solidity 5.09% Shell 0.02%

staking-platform-fixed-apy's Introduction

StakingPlatform

ImmuneBytesAudits HackenAudits Coverage Status MythXBadge Solidity

Fixed APY Staking platform with Lockup and fixed APY, duration and max stake

Workflow

  • Deploy StakingPlatform with the appropriate parameters (See Constructor below)
  • Users should deposit their tokens before or during the staking period
  • Run Start() function launch the staking
  • Users can claim their rewards using claimRewards()
  • Once staking is over users can withdraw their initial deposit using withdraw() (withdraw() calls claimRewards())

Constructor

   constructor(
        address _token,
        uint8 _fixedAPY,
        uint _durationInDays,
        uint _lockupDurationInDays,
        uint _maxStake,
    )
  • Address of the ERC20 Token to be used by the Staking platform
  • fixed APY rates (must be consistent with the maxStake)
  • Duration of the staking (e.g, 365 == 1year)
  • Lockup duration (Impossible to withdraw until the lockup period is finish)
  • Max tokens that can be deposited by stake holders

Examples

  • Staking platform is deployed with 25% of APY
  • User1 approve 100000 TKN
  • User1 deposit 100000 TKN
  • Staking platform starts
  • after 1 day User1 can claim ~68.4750 TKN
  • after 1 year User1 can claim 25000 TKN, 25% of 100,000 TKN

StakingPlatform

constructor(address _token, uint8 _fixedAPY, uint256 _durationInDays, uint256 _lockDurationInDays, uint256 _maxAmountStaked) (public)

constructor contains all the parameters of the staking platform

all parameters are immutable

startStaking() (external)

function that start the staking

set startPeriod to the current current block.timestamp set lockupPeriod which is block.timestamp + lockupDuration and endPeriod which is startPeriod + stakingDuration

deposit(uint256 amount) (external)

function that allows a user to deposit tokens

user must first approve the amount to deposit before calling this function, cannot exceed the maxAmountStaked endPeriod to equal 0 (Staking didn't started yet), or endPeriod more than current block.timestamp (staking not finished yet) totalStaked + amount must be less than stakingMax that the amount deposited should greater than 0

withdraw(uint256 amount) (external)

function that allows a user to withdraw its initial deposit

block.timestamp must be higher than lockupPeriod (lockupPeriod finished) amount must be higher than 0 amount must be lower or equal to the amount staked withdraw reset all states variable for the msg.sender to 0, and claim rewards if rewards to claim

withdrawAll() (external)

function that allows a user to withdraw its initial deposit

must be called only when block.timestamp >= lockupPeriod block.timestamp higher than lockupPeriod (lockupPeriod finished) withdraw reset all states variable for the msg.sender to 0, and claim rewards if rewards to claim

withdrawResidualBalance() (external)

claim all remaining balance on the contract Residual balance is all the remaining tokens that have not been distributed (e.g, in case the number of stakeholders is not sufficient)

Can only be called one year after the end of the staking period Cannot claim initial stakeholders deposit

amountStaked(address stakeHolder) → uint256 (external)

function that returns the amount of total Staked tokens for a specific user

totalDeposited() → uint256 (external)

function that returns the amount of total Staked tokens on the smart contract

rewardOf(address stakeHolder) → uint256 (external)

function that returns the amount of pending rewards that can be claimed by the user

claimRewards() (external)

function that claims pending rewards

transfer the pending rewards to the msg.sender

_calculateRewards(address stakeHolder) → uint256 (internal)

calculate rewards based on the fixedAPY, _percentageTimeRemaining()

the higher is the precision and the more the time remaining will be precise

_percentageTimeRemaining(address stakeHolder) → uint256 (internal)

function that returns the remaining time in seconds of the staking period

the higher is the precision and the more the time remaining will be precise

staking-platform-fixed-apy's People

Contributors

aboudjem 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.