Request form
Cookbook may introduce a token in the future. Share and contribute to be eligible for future airdrops.
close icon
relevant tag icon
Velodrome External Bribe
copy icon
velodrome
• version 1.0.0
Rewards
Voting

Velodrome External Bribe

Bribes pay out rewards for a given pool based on the votes that were received from the user (goes hand in hand with Voter.vote())

*Visit desktop site to download or deploy

Version

1.0.0

Creator

velodrome

Last Publish

1/20/2023
Any contract you deploy is yours.
Fully owned and controlled by your wallet.
Documentation
Source Code
_bribeStart() :
This function is used to calculate the start of a 7-day period. It takes a timestamp as an argument and returns the timestamp of the start of the 7-day period that the given timestamp falls within. It works by subtracting the remainder of the timestamp divided by 7 days from the given timestamp. (autogenerated documentation)
getEpochStart() :
This function calculates the start of an epoch given a timestamp. It does this by first calculating the start of the bribe period for the given timestamp using the _bribeStart() function. It then adds the duration of the bribe period to this start time to get the end of the bribe period. Finally, it checks if the given timestamp is before the end of the bribe period, and if so, returns the start of the bribe period. Otherwise, it returns the start of the bribe period plus 7 days. (autogenerated documentation)
getPriorBalanceIndex() :
This function is used to find the index of the prior balance checkpoint for a given token and timestamp. It works by using a binary search algorithm to find the index of the checkpoint with the closest timestamp to the given timestamp. If the given timestamp is greater than the timestamp of the last checkpoint, the index of the last checkpoint is returned. If the given timestamp is less than the timestamp of the first checkpoint, the index of the first checkpoint is returned. (autogenerated documentation)
getPriorSupplyIndex() :
This function is used to find the index of the supply checkpoint that is prior to a given timestamp. It does this by using a binary search algorithm to search through the supplyCheckpoints array. The function first checks if the timestamp is greater than the last checkpoint in the array, and if so, returns the index of the last checkpoint. If the timestamp is less than the first checkpoint, it returns 0. Otherwise, it uses a binary search algorithm to find the index of the checkpoint that is prior to the given timestamp. (autogenerated documentation)
_writeCheckpoint() :
This function is used to store a checkpoint of the balance of a given token at a given timestamp. It first checks if the last checkpoint stored for the token has the same timestamp as the current block timestamp. If so, it updates the balance of the last checkpoint. Otherwise, it creates a new checkpoint with the current block timestamp and the given balance. The number of checkpoints stored for the token is also updated. (autogenerated documentation)
_writeSupplyCheckpoint() :
This function is used to store the total supply of the token at a given timestamp. It first checks if the last checkpoint stored has the same timestamp as the current block. If it does, it updates the supply of the last checkpoint. Otherwise, it creates a new checkpoint with the current timestamp and total supply. (autogenerated documentation)
rewardsListLength() :
This function returns the length of the rewards list. It works by accessing the rewards list and returning the length of the list. (autogenerated documentation)
lastTimeRewardApplicable(address) :
This function is used to determine the last time a reward is applicable for a given token. It takes in the address of the token as an argument and returns a uint value. The function works by taking the minimum of the current block timestamp and the periodFinish value associated with the token address. This value is then returned as the last time a reward is applicable for the given token. (autogenerated documentation)
getReward() :
This function allows a user to claim rewards for a given tokenId. It requires that the user is either the owner or an approved user of the tokenId. It then loops through an array of tokens and calculates the reward for each token. If the reward is greater than 0, it will transfer the reward to the user. Finally, it emits an event to log the reward claim. (autogenerated documentation)
getRewardForOwner() :
This function is used to distribute rewards to the owner of a token. It takes in two parameters, a tokenId and an array of tokens. It first checks that the sender of the message is the voter. It then gets the owner of the tokenId from the IVotingEscrow contract. It then iterates through the array of tokens and calculates the reward for each token. If the reward is greater than 0, it transfers the reward to the owner. Finally, it emits an event to log the reward distribution. (autogenerated documentation)
earned(address) :
This function calculates the total rewards earned by a token holder for a given token and tokenId. It does this by looping through the checkpoints array for the given tokenId, starting from the lastEarn timestamp, and calculating the rewards earned for each epoch. It then adds up the rewards earned for each epoch and returns the total rewards earned. The rewards are calculated by multiplying the balance of the token holder at each checkpoint by the tokenRewardsPerEpoch for the given token and epoch start timestamp, and dividing by the supply at the end of the epoch. (autogenerated documentation)
_deposit() :
This function allows a voter to deposit a certain amount of a token with a given token ID. The amount is added to the total supply and the balance of the token with the given ID is increased by the amount. The new balance is then written to a checkpoint and the total supply is written to a supply checkpoint. Finally, a Deposit event is emitted. (autogenerated documentation)
_withdraw() :
This function allows a voter to withdraw a specified amount of a token with a given token ID. It first checks that the sender of the transaction is the voter, then subtracts the amount from the total supply and the balance of the token with the given ID. It then writes a checkpoint for the token balance and the total supply, and emits an event to indicate that the withdrawal has taken place. (autogenerated documentation)
left(address) :
This function returns the amount of rewards that have been earned for a given token in a given epoch. It works by taking in the address of the token and using the block timestamp to calculate the epoch start. It then looks up the amount of rewards earned for the token in the given epoch in the tokenRewardsPerEpoch mapping. (autogenerated documentation)
notifyRewardAmount(address) :
This function is used to notify the contract of a reward amount for a given token. It requires that the amount is greater than 0, that the token is whitelisted, and that the number of reward tokens is less than the maximum allowed. It then calculates the adjusted timestamp for the current epoch, and adds the reward amount to the total rewards for that token in that epoch. It also sets the period finish for the token to the adjusted timestamp plus the duration. Finally, it adds the token to the list of rewards if it is not already present, and emits a NotifyReward event. (autogenerated documentation)
swapOutRewardToken(address,address) :
This function allows the team to swap out a reward token for another token. It takes in two parameters, an index (i) and two addresses (oldToken and newToken). It first checks that the sender is the team, then checks that the reward at the given index is the oldToken. It then sets the isReward boolean for the oldToken to false and the isReward boolean for the newToken to true. Finally, it sets the reward at the given index to the newToken. (autogenerated documentation)
_safeTransfer(address,address,uint256) :
This function is an internal function that is used to transfer tokens from one address to another. It requires that the token address has a code length greater than 0, and then calls the IERC20 transfer selector with the address of the recipient and the value of the tokens to be transferred. It then requires that the call was successful and that the data returned is either empty or a boolean. (autogenerated documentation)
_safeTransferFrom(address,address,address,uint256) :
This function is an internal function that is used to safely transfer tokens from one address to another. It requires the address of the token, the address of the sender, the address of the recipient, and the amount of tokens to be transferred. It then calls the token's transferFrom function, which is part of the ERC20 standard, and checks that the call was successful and that the data returned is valid. If all of these conditions are met, the transfer is completed. (autogenerated documentation)

Get Cookin'
share iconShare

copy iconDownload Source
copy iconnpx cookbookdev i velodrome-external-bribe
copy icon

Last Publish

1/20/2023

Version

1.0.0

Creator

velodrome

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