Request form
Cookbook may introduce a token in the future. Share and contribute to be eligible for future airdrops.
close icon
relevant tag icon
Token Staking
copy icon
oiler.network
• version 1.0.0
Staking
Token
ERC20
Audited

Token Staking

Audited

Staking contract where users deposit tokens and receive a reward based on the amount of time their tokens are staked. Users decide how long they want to stake their tokens for, and earn a bonus depending on the length of time. They can withdraw early, but are penalized.

*Visit desktop site to download or deploy

Version

1.0.0

Recent Use

🍞 0x0cff saved
🥐 0x0cff downloaded
🥖 0x04bB downloaded
🥨 0x5DF1 downloaded
🥯 0x9c24 downloaded
🥞 0x26cB downloaded
🧀 0xC3Dc saved
🍖 0x77CA downloaded
🍗 0x77CA saved
🥩 0x5F68 downloaded

Last Publish

9/26/2022
Any contract you deploy is yours.
Fully owned and controlled by your wallet.
Documentation
Source Code
setPoolToken(address,address) :
This function sets the pool token address and transfers a specified amount of OIL from the staking fund address to the contract address. It requires that the pool token address is not zero, that the staking fund address has enough OIL balance, that the staking fund address has enough allowance for the contract address to transfer the OIL, and that the transfer of OIL from the staking fund address to the contract address is successful. If all of these conditions are met, the pool token address is set and the OIL is transferred. (autogenerated documentation)
calculateStakingRewardPoints(uint72,uint24) :
This function calculates the staking reward points for a given amount of tokens and a given locking period in blocks. The function takes two parameters, tokenAmount_ and lockingPeriodInBlocks_, and returns a uint128 value representing the staking reward points. The calculation is done by multiplying the token amount by the locking period in blocks, and then by the locking period in blocks again. The function also includes a require statement to ensure that neither the token amount nor the locking period is 0. (autogenerated documentation)
lockTokens(uint72,uint24) :
This function allows users to lock tokens for a specified period of time in order to earn staking rewards. The function takes two parameters, tokenAmount_ and lockingPeriodInBlocks_, which represent the amount of tokens to be locked and the duration of the lock period, respectively. The function first checks that the lock period does not exceed the duration of the staking program, and that the user has not already staked tokens. It then calculates the expected staking reward points for the user based on the amount of tokens locked and the duration of the lock period. The function then creates a new Stake memory object with the user's details and adds it to the stakes mapping. It also updates the totalRewardPoints and rewardPointsEarned mappings with the expected staking reward points. Finally, it transfers the specified amount of tokens from the user's address to the contract address and emits a StakeLocked event. (autogenerated documentation)
unlockTokens() :
This function allows a user to unlock tokens that they have previously staked. It first retrieves the stake information from the stakes mapping, which stores the amount of tokens staked, the start block of the stake, and the end block of the stake. It then checks to make sure that the user has a stake to unlock, and that the current block is after the start block of the stake. The function then calls the _punishEarlyWithdrawal function, which is used to penalize users who withdraw their stake early. After this, the stake is removed from the mapping and the user is transferred the amount of tokens that they had staked. (autogenerated documentation)
_punishEarlyWithdrawal() :
This function is used to punish users who withdraw their stake early. It checks if the current block number is less than the start block number plus the locking period in blocks. If it is, then the user's reward points earned is reduced by the expected staking reward points and the total reward points is also reduced by the expected staking reward points. An event is then emitted to indicate that the stake was unlocked prematurely. If the current block number is not less than the start block number plus the locking period in blocks, then an event is emitted to indicate that the stake was unlocked. (autogenerated documentation)
getRewards() :
This function allows a user to withdraw their rewards from a staking program. It requires that the staking program has ended, that the user has no tokens locked in the staking program, and that the user has earned reward points. The function then calculates the amount of tokens earned by the user based on the total amount of staking fund and the total reward points earned by all users. Finally, the function grants the user the amount of tokens earned and sets the user's reward points to 0. (autogenerated documentation)
_grantTokens(address,uint256) :
This function is used to grant tokens to a recipient. It takes two parameters, an address of the recipient and an amount of tokens to be granted. The function first checks that the amount of tokens to be granted is greater than 0 and that the recipient address is not the zero address. If these checks pass, the function stores the amount of tokens granted to the recipient in the grantedTokens mapping and emits an event to notify that the reward has been granted. (autogenerated documentation)
release() :
This function allows a user to release tokens that have been vested. The function first checks to see if the user has any releasable tokens, and if so, it adds the releasable amount to the releasedTokens mapping. It then transfers the releasable amount of tokens to the user's address. Finally, it emits an event to indicate that the tokens have been released. (autogenerated documentation)
_releasableAmount(address) :
This function is used to calculate the amount of tokens that are available to be released to a given recipient. It does this by subtracting the amount of tokens that have already been released from the total amount of vested tokens for the recipient. The function takes in the address of the recipient as an argument and returns the amount of tokens that are available to be released as a uint256. (autogenerated documentation)
_vestedAmount(address) :
This function calculates the vested amount of tokens for a given recipient. It takes in the address of the recipient as an argument and returns the vested amount of tokens as a uint256. The vested amount is calculated by taking the total amount of tokens granted to the recipient and multiplying it by the ratio of the current block number to the block number at which the staking program ends plus the vesting duration. This ensures that the vested amount increases linearly over the vesting duration. (autogenerated documentation)

Get Cookin'
share iconShare

copy iconDownload Source
copy iconnpx cookbookdev i token-staking
copy icon

Recent Use

🍞 0x0cff saved
🥐 0x0cff downloaded
🥖 0x04bB downloaded
🥨 0x5DF1 downloaded
🥯 0x9c24 downloaded
🥞 0x26cB downloaded
🧀 0xC3Dc saved
🍖 0x77CA downloaded
🍗 0x77CA saved
🥩 0x5F68 downloaded

Last Publish

9/26/2022

Version

1.0.0

Cookbook is free.
Any contract you deploy is yours.
Your contract is owned and controlled by you.