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 Gauge LP Staking
copy icon
velodrome
• version 1.0.0
Staking
Rewards
Voting

Velodrome Gauge LP Staking

Gauges are used to incentivize pools, they emit reward tokens over 7 days for staked LP tokens. The contract includes several mappings and structs to track staking and rewards, as well as events to log important actions such as deposits, withdrawals, and rewards being claimed. The constructor sets the LP token that needs to be staked, the ve token used for gauges, the internal and external bribe addresses, the voter address, and whether the gauge is for a pair or not. It also sets up an array of allowed reward tokens.

*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
claimFees() :
This function allows users to claim fees from the contract. It works by calling the internal _claimFees() function, which returns the amount of fees that have been claimed by the user. The function is marked as "lock" which means that it can only be called once and will be locked after the first call. (autogenerated documentation)
_claimFees() :
This function is used to claim fees from a pair of tokens. It first checks if the pair is valid, and if so, it calls the claimFees() function from the IPair contract to retrieve the fees. It then checks if the fees are greater than the amount left in the IBribe contract, and if so, it approves the IBribe contract to transfer the fees and notifies the IBribe contract of the reward amount. Finally, it emits a ClaimFees event with the sender and the amount of fees claimed. (autogenerated documentation)
getPriorBalanceIndex(address) :
This function is used to find the index of the prior balance of an account at a given timestamp. It does this by first checking if the timestamp is greater than the most recent checkpoint, and if so, returns the index of the most recent checkpoint. If the timestamp is less than the most recent checkpoint, it uses a binary search to find the index of the checkpoint with the closest timestamp. (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)
getPriorRewardPerToken(address) :
This function is used to retrieve the reward per token for a given token at a given timestamp. It works by first checking if the timestamp is greater than the last checkpoint timestamp, and if so, it returns the reward per token and timestamp of the last checkpoint. If the timestamp is less than the first checkpoint timestamp, it returns 0. Otherwise, it uses a binary search to find the reward per token and timestamp of the checkpoint closest to the given timestamp. (autogenerated documentation)
_writeCheckpoint(address) :
This function is used to store a checkpoint of an account's balance at a given timestamp. It first checks if the last checkpoint for the account was created at the same timestamp as the current one. If so, it updates the balance of the last checkpoint. Otherwise, it creates a new checkpoint with the given timestamp and balance. The number of checkpoints for the account is then incremented. (autogenerated documentation)
_writeRewardPerTokenCheckpoint(address) :
This function is used to write a reward per token checkpoint to the blockchain. It takes in an address of a token, a reward amount, and a timestamp as parameters. It first checks if the timestamp of the last checkpoint is the same as the timestamp passed in. If it is, it updates the reward amount of the last checkpoint. If not, it adds a new checkpoint with the given timestamp and reward amount. (autogenerated documentation)
_writeSupplyCheckpoint() :
This function is used to store the current supply of the token in the blockchain. It stores the supply of the token at a certain timestamp in the supplyCheckpoints array. The function first checks if the last element in the array has the same timestamp as the current block. If it does, it updates the supply of the token in the last element. If not, it adds a new element to the array with the current timestamp and 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(address) :
This function is used to distribute rewards to a given account. It requires that the sender of the message is either the account or the voter. It then updates the reward per token stored in the rewardPerTokenStored mapping and sets the lastUpdateTime for the token. It then calculates the reward for the account and transfers it to the account. It then updates the derived balance for the account and writes the checkpoint for the account and the supply checkpoint. Finally, it emits the ClaimRewards event. (autogenerated documentation)
rewardPerToken(address) :
This function calculates the reward per token for a given token address. It does this by first checking if the derivedSupply is 0, and if so, returning the stored rewardPerTokenStored value for the given token address. If the derivedSupply is not 0, it calculates the reward per token by adding the stored rewardPerTokenStored value to the amount of reward earned since the last time the reward was applicable, multiplied by the reward rate for the given token address and the PRECISION constant. (autogenerated documentation)
derivedBalance(address) :
This function is a public view function that returns the balance of a given account. It takes in an address as an argument and returns the corresponding balance stored in the balanceOf mapping. (autogenerated documentation)
batchRewardPerToken(address) :
This function is used to calculate the reward per token for a given token address. It works by calling the _batchRewardPerToken() internal function, which takes the token address and the maximum number of runs as parameters. The _batchRewardPerToken() function then calculates the reward per token for the given token address and stores the result in the rewardPerTokenStored and lastUpdateTime variables. The result is then returned to the caller. (autogenerated documentation)
_batchRewardPerToken(address) :
This function is used to calculate the reward per token for a given token address. It takes in the token address and the maximum number of runs as parameters. It first retrieves the start timestamp and reward per token stored from the storage variables. If the supplyNumCheckpoints is 0, it returns the reward and start timestamp. If the reward rate for the token is 0, it returns the reward and the current block timestamp. It then calculates the start and end index for the supply checkpoints. It then iterates through the supply checkpoints and calculates the reward per token for each checkpoint. It then updates the reward per token stored and the last update time for the token. Finally, it returns the reward and the start timestamp. (autogenerated documentation)
_calcRewardPerToken(address) :
This function calculates the reward per token for a given token address, two timestamps, supply, and start timestamp. It first calculates the end time by taking the maximum of the two timestamps and the start timestamp. It then calculates the reward per token by taking the minimum of the end time and the period finish for the token, subtracting the minimum of the maximum of the two timestamps and the start timestamp and the period finish for the token, and multiplying that by the reward rate for the token and the precision divided by the supply. (autogenerated documentation)
batchUpdateRewardPerToken(address) :
This function is used to update the reward per token for a given token address. It takes in the token address and the maximum number of runs as parameters. It then calls the _updateRewardPerToken function, passing in the token address, the maximum number of runs, and a boolean value of false. This function will update the rewardPerTokenStored and lastUpdateTime values for the given token address. (autogenerated documentation)
_updateRewardForAllTokens() :
This function updates the reward for all tokens stored in the rewards array. It does this by looping through the array and calling the _updateRewardPerToken() function for each token. This function takes in the token address, a maximum value for the reward, and a boolean value indicating whether the reward should be updated. It then returns the updated reward and the time of the last update. (autogenerated documentation)
_updateRewardPerToken(address,bool) :
This function updates the reward per token for a given token address. It takes in the token address, the maximum number of runs, and a boolean value indicating whether the last run should be actual or not. It then calculates the reward per token by looping through the supply checkpoints from the start timestamp to the end index. It then calculates the reward per token for each checkpoint and adds it to the total reward. Finally, it writes the reward per token checkpoint to the storage and returns the total reward and the start timestamp. (autogenerated documentation)
earned(address,address) :
This function calculates the total rewards earned by an account for a given token. It does this by looping through the checkpoints stored for the account, starting from the last checkpoint stored for the token, and calculating the difference in rewards per token between each checkpoint. It then adds the rewards earned from the last checkpoint to the total reward. (autogenerated documentation)
depositAll() :
This function allows a user to deposit all of their tokens of a given tokenId into a stake contract. It works by first getting the balance of the user's tokens from the IERC20 contract, then calling the deposit function with the user's balance and the tokenId as parameters. (autogenerated documentation)
deposit() :
This function allows a user to deposit a certain amount of tokens into the Gauge contract. It requires that the amount is greater than 0, and if the user is depositing a token, it must be owned by them. The function then updates the total supply and balance of the user, and calculates the derived balance of the user. It then writes a checkpoint for the user's balance and the total supply, and emits a Deposit event. (autogenerated documentation)
withdrawAll() :
This function allows a user to withdraw all of their funds from the contract. It works by taking the balance of the user (stored in the balanceOf mapping) and passing it to the withdraw function. This will transfer the funds from the contract to the user's address. (autogenerated documentation)
withdraw() :
This function allows a user to withdraw a certain amount of tokens from their account. It takes in a parameter of the amount of tokens to be withdrawn and checks if the amount is equal to the user's balance. If it is, it sets the tokenId to the user's tokenId and calls the withdrawToken function with the amount and tokenId as parameters. (autogenerated documentation)
withdrawToken() :
This function allows a user to withdraw a specified amount of tokens from the contract. It first updates the reward for all tokens, then subtracts the amount from the total supply and the user's balance. It then transfers the amount to the stake address. If a token ID is specified, it checks that the token ID matches the one associated with the user, and then detaches the token from the gauge. It then calculates the user's derived balance and updates the derived supply accordingly. Finally, it writes a checkpoint for the user's derived balance and the total supply, and emits the Withdraw event. (autogenerated documentation)
left(address) :
This function calculates the amount of tokens remaining in a period for a given token. It does this by taking the difference between the periodFinish timestamp for the token and the current block timestamp, and then multiplying this difference by the rewardRate for the token. The result is the amount of tokens remaining in the period. (autogenerated documentation)
notifyRewardAmount(address) :
This function is used to notify the reward amount for a given token. It requires that the token is not the stake token, that the amount is greater than 0, and that the token is whitelisted. It then updates the reward per token stored and claims any fees. If the current block timestamp is greater than the period finish for the token, it transfers the amount to the contract and sets the reward rate for the token. Otherwise, it checks that the amount is greater than the remaining amount for the period and then transfers the amount to the contract and sets the reward rate for the token. It then checks that the reward rate is greater than 0 and that it is less than or equal to the balance of the contract divided by the duration (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)
_safeApprove(address,address,uint256) :
This function is used to approve a certain amount of tokens to a spender. It first checks that the token contract has code, then it calls the approve function of the IERC20 interface with the spender address and the amount of tokens to approve. Finally, it checks that the call was successful and that the data returned is either empty or a boolean. (autogenerated documentation)

Get Cookin'
share iconShare

copy iconDownload Source
copy iconnpx cookbookdev i velodrome-gauge
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.