-
Notifications
You must be signed in to change notification settings - Fork 2
Implement FIG stake
#130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Implement FIG stake
#130
Conversation
|
Basically looks good to me through an initial review, but I think a thorough review is still required. |
|
|
||
| // scan user stakes and check valid stake number | ||
| Stake[] memory stakes = getUserStakes(staker); | ||
| require(stakes.length < MAX_USER_STAKE_NUMBER, "User stakes overflow"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest to add a method to return the number only for saving gas, since the detailed information is not required here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not necessary on the chain of filecoin
|
|
||
| // calculate stake reward, reward equals to `stakeType powerRate * bonus reward amount / totalPower` | ||
| function _calculate(Stake memory stake) private view returns (uint[2] memory r) { | ||
| for (uint i = stake.startBounsId; i < _bonuses.length; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If _bonuses.length becomes large, is it possible that EVM end up reverting with out of gas?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
user stake started from startBonusId, here only traverse the bonus that can be distributed.
contracts/FIGStake.sol
Outdated
| uint amount = _reward(rewardUnit, stake.amount); | ||
| uint remain = amount * (block.number - bonus.start) / (bonus.end - bonus.start); | ||
| r[0] += remain; | ||
| r[1] += amount - remain; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The naming is a bit confusing, since amount - remain is what's actually remained .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, good suggestion. updated the variables as follow:
uint amount = _reward(rewardUnit, stake.amount);
// calculate the reward amount that can be withdrawn
uint canBeWithdraw = amount * (block.number - bonus.start) / (bonus.end - bonus.start);
// calculate the rest reward amount which cannot be withdrawn at present
uint rest = amount - canBeWithdraw;
r[0] += canBeWithdraw;
r[1] += rest;
|
LGTM in general, only several nits. |
FIG Stake
this contract implement user
fig stakingprofit sharing.kinds of stake type:
user can choose different stake types. and the staked
Fig tokenCAN NOTbe withdrawn within the defaulted stake period. the profit sharing ratio of different stake types are different. the longer the stake period, the higher the profit sharing ratio. this is because there is a silent cost for users within the stake period, such as other projects with higher profit.system parameters:
how to create bonus?
FIL tokento the contract for bonus rewardingFIG token, and the availableFIG tokenshould not be zeroMIN_BONUS_AMOUNThow to stake?
FIGis anERC20token,user should approve enough allowance to the contract firststake typeand sent enoughFIG tokento the contractMIN_STAKE_AMOUNTMAX_USER_STAKE_NUMBERuncancelled stakes at the same timehow to cancel stake?
staking IDof the userhow to withdraw reward?
bonus rewardat any timeReward calculation
stake type powerRate:
the user's staking income is linearly related to the staking type
powerRateand the number ofFIGtokens stakedstakeAmount30 daysstake type = 1090 daysstake type = 20180 daysstake type = 30360 daysstake type = 40power calculation:
rewardUnitcalculation just for convenience, so that the user can calculate reward amount with his owner stake amount, the final format equals to:single bonus reward calculation for single stake:
the order of user staking and bonus creation is that user stake first, then bonus can be created.when sharing profits, if a
stakeis created before the bonus, then thestakecan only enjoy therewardafter thebonusis created, e.g:stake bonus reward sum:
single stake can earn multiple bonuses. before the user cancels the stake, starting from the
startBonusIdof the stake, all subsequent bonuses will be distributed to the stake in proportion to the stake amount and other parameters.user stakes reward sum:
if user have multiple stakes, the reward amount should be the sum of
stakeBonusRewardSumNotice
the contract
FIGStakealready existed in the project before this pull request. we deleted the old file and created a new file with the same name, which made it inconvenient to read the code differences of pr. we can directly read the following pure new file of https://github.com/FILL-Lab/FILLiquid/blob/fig_stake/contracts/FIGStake.sol