Request form
Cookbook may introduce a token in the future. Share and contribute to be eligible for future airdrops.
close icon
relevant tag icon
veSPA Reward Distributor
copy icon
Sperax
• version 1.0.0
Reward
ERC20
Audited

veSPA Reward Distributor

Audited

This contract Distributes rewards based on user's checkpointed veSPA balance.

*Visit desktop site to download or deploy

Version

1.0.0

Creator

Sperax

Last Publish

11/23/2022
Any contract you deploy is yours.
Fully owned and controlled by your wallet.
Documentation
Source Code
addRewards(uint256) :
This function adds rewards to the contract. It requires that the value passed to it is greater than 0, and that the contract is not killed. It then transfers the value from the message sender to the contract using the IERC20 token. If the canCheckpointReward flag is set to true and the current block timestamp is greater than the lastRewardCheckpointTime plus the REWARD_CHECKPOINT_DEADLINE, then the _checkpointReward() function is called. (autogenerated documentation)
checkpointReward() :
This function allows the owner of the contract or anyone with the permission to checkpoint rewards to call the _checkpointReward() function. The _checkpointReward() function is only allowed to be called if the sender is the owner of the contract or if the canCheckpointReward flag is set to true and the current block timestamp is greater than the lastRewardCheckpointTime plus the REWARD_CHECKPOINT_DEADLINE. This function is also non-reentrant, meaning that it cannot be called again until the first call has finished executing. (autogenerated documentation)
claim(bool) :
This function allows a user to claim their rewards from staking. If the restake parameter is set to true, the user's rewards will be automatically reinvested in the staking pool. The function returns the amount of rewards that the user has earned. (autogenerated documentation)
toggleAllowCheckpointReward() :
This function allows the owner of the contract to toggle whether or not users can receive rewards for reaching checkpoints. When the function is called, the boolean variable canCheckpointReward is flipped from true to false or vice versa. An event is then emitted to notify users of the change in status. (autogenerated documentation)
updateMaxIterations(uint256) :
This function allows the owner of the contract to update the maximum number of iterations allowed. It requires that the new iteration number is greater than 0, and then sets the maxIterations variable to the new iteration number. It also emits an event to notify that the maxIterations variable has been updated. (autogenerated documentation)
killMe() :
This function is used to kill the contract and return all of the tokens held by the contract to the EMERGENCY_RETURN address. It can only be called by the owner of the contract and will only execute if the contract has not already been killed. When the function is called, it will transfer all of the tokens held by the contract to the EMERGENCY_RETURN address and emit a Killed event. (autogenerated documentation)
recoverERC20(address) :
This function allows the owner of the contract to recover ERC20 tokens from the contract address. It takes the address of the ERC20 token as an argument and checks that it is not the address of the Token contract. It then gets the balance of the contract address from the ERC20 token and sends it to the EMERGENCY_RETURN address. Finally, it emits an event to log the recovery of the ERC20 tokens. (autogenerated documentation)
computeRewards(address) :
This function computes the rewards for a given address. It takes the address as an input and returns three values: totalRewards, lastRewardCollectionTime, and rewardsTill. The function first calculates the lastRewardCheckpointTime by dividing it by the WEEK and then multiplying it by the WEEK. It then calls the _computeRewards function with the address and the lastRewardCheckpointTime as inputs. The _computeRewards function returns two values: rewardsTill and totalRewards. Finally, the function checks if the lastRewardCollectionTime is 0, and if so, sets it to the startTime. The function then returns the three values. (autogenerated documentation)
claim(address,bool) :
This function allows users to claim rewards from the contract. It first checks if the reward checkpoint deadline has been reached, and if so, it calls the _checkpointReward() function to update the rewards. It then calculates the rewards for the user based on the last reward checkpoint time and the user's last reward collection time. If the user is eligible for rewards, it subtracts the amount from the last reward balance and either deposits it into the user's veToken account or transfers it to the user's address, depending on the value of the restake parameter. Finally, it emits an event to log the claim. (autogenerated documentation)
_checkpointReward() :
This function is used to distribute rewards to the VeChain token holders. It calculates the amount of tokens that have been distributed since the last reward checkpoint and distributes them accordingly. It also keeps track of the total supply of VeChain tokens at each reward checkpoint. The rewards are distributed based on the amount of time since the last reward checkpoint and the total amount of tokens that have been distributed. The rewards are then emitted to the token holders. (autogenerated documentation)
_findUserTimestampEpoch(address,uint256,uint256) :
This function is an internal view function that is used to find the timestamp epoch of a given user address. It uses a binary search algorithm to find the timestamp epoch. It takes in three parameters: the address of the user, the timestamp, and the maximum epoch. It then sets the minimum and maximum values to 0 and the maximum epoch respectively. It then iterates through a loop 128 times, and each time it calculates the midpoint between the minimum and maximum values. It then checks if the user's point history timestamp is less than or equal to the given timestamp. If it is, the minimum value is set to the midpoint, otherwise the maximum value is set to the midpoint minus one. Once the loop is finished, the (autogenerated documentation)
_initializeUser(address) :
This function initializes a user's account in the IveToken contract. It takes an address as an argument and returns a uint256 weekCursor. It first checks if the user has made a deposit by checking the userPointEpoch of the address. If the user has made a deposit, it finds the user's timestamp epoch by calling the _findUserTimestampEpoch function. If the user has not made a deposit, it sets the userEpoch to 1. It then gets the user's point history timestamp by calling the getUserPointHistoryTS function. Finally, it calculates the weekCursor by taking the userPointTs and adding the WEEK constant, subtracting 1, and then multiplying it by the WEEK constant (autogenerated documentation)
_computeRewards(address,uint256) :
This function computes the rewards that a given address is eligible to receive. It takes in the address and the last reward checkpoint time as parameters. It then iterates through the weeks since the last reward checkpoint time, and for each week, it calculates the balance of the address at that time and multiplies it by the rewards per week for that week, divided by the total VE token supply at that time. It then adds this amount to the total rewards to be distributed, and continues the loop until it reaches the current week. Finally, it returns the week cursor and the total rewards to be distributed. (autogenerated documentation)

Get Cookin'
share iconShare

copy iconDownload Source
copy iconnpx cookbookdev i vespa-reward-distributor
copy icon

Last Publish

11/23/2022

Version

1.0.0

Creator

Sperax

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