Fixed APY Staking platform with Lockup and fixed APY, duration and max stake
- 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()
callsclaimRewards()
)
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
- 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
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
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
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
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
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
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
function that returns the amount of total Staked tokens for a specific user
function that returns the amount of total Staked tokens on the smart contract
function that returns the amount of pending rewards that can be claimed by the user
function that claims pending rewards
transfer the pending rewards to the msg.sender
calculate rewards based on the fixedAPY
, _percentageTimeRemaining()
the higher is the precision and the more the time remaining will be precise
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