getPriorBalanceIndex() :
This function is used to find the index of the prior balance of a token at a given timestamp. It takes in a tokenId and a timestamp as parameters and returns the index of the prior balance. The function first checks if there are any checkpoints for the given tokenId. If there are none, it returns 0. If the timestamp is greater than the timestamp of the last checkpoint, it returns the index of the last checkpoint. If the timestamp is less than the timestamp of the first checkpoint, it returns 0. Otherwise, it uses a binary search algorithm to find the index of the prior balance. It sets the lower and upper bounds of the search to the first and last checkpoints respectively. It then finds the (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() :
This function is used to store a checkpoint of the balance of a token at a given timestamp. It takes in the tokenId and the balance of the token as parameters. It first stores the current block timestamp in a variable. It then checks if the last checkpoint stored for the token has the same timestamp as the current block timestamp. If it does, it updates the balance of the last checkpoint. Otherwise, it creates a new checkpoint with the current timestamp and the balance of the token. It then increments the number of checkpoints stored for the token. (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, the reward amount, and a timestamp as parameters. It first checks if the timestamp of the last checkpoint is the same as the one passed in. If it is, it updates the reward amount of the last checkpoint. Otherwise, it adds a new checkpoint with the given timestamp and reward amount. (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 is used to get rewards for a given token ID. It requires that the sender is approved or the owner of the token ID. It then updates the reward per token stored for each token in the tokens array. It then calculates the earned reward for each token and stores the last earned timestamp. It then transfers the reward to the sender if the reward is greater than 0. Finally, it emits an event to log the claim rewards. (autogenerated documentation)
getRewardForOwner() :
This function is used to reward the owner of a token with a specified tokenId. It first checks that the sender of the message is the voter, then it retrieves the owner of the token from the IVotingEscrow contract. It then iterates through the tokens array and updates the rewardPerTokenStored and lastUpdateTime for each token. It then calculates the reward for the owner of the token and stores the lastEarn, userRewardPerTokenStored, and rewardPerTokenStored for each token. Finally, it transfers the reward to the owner and emits a ClaimRewards event. (autogenerated documentation)
rewardPerToken(address) :
This function calculates the reward per token for a given token address. It does this by taking the stored reward per token for the given token address, and adding to it the amount of reward earned since the last time the reward was applicable, multiplied by the reward rate for the token and the precision. The amount of reward earned since the last time the reward was applicable is calculated by subtracting the minimum of the last update time for the token and the period finish for the token from the last time reward was applicable for the token. (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 stored reward and start timestamp. If the reward rate for the token is 0, it returns the stored reward and the current block timestamp. Otherwise, it calculates the reward per token by looping through the supply checkpoints from the start index to the end index. For each loop, it calculates the reward per token using the _calcRewardPerToken function and updates the reward per token checkpoint in the storage variables. Finally, it returns the total (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 actualized. It then calculates the reward per token by looping through the supply checkpoints from the start timestamp to the end index. It then writes the reward per token checkpoint and updates the start timestamp. Finally, it returns the reward and the start timestamp. (autogenerated documentation)
earned(address) :
This function calculates the total rewards earned by a particular token holder for a given token. It does this by looping through all the checkpoints for the given token, starting from the last checkpoint that the token holder earned rewards from. For each checkpoint, it calculates the difference between the reward per token stored at the current checkpoint and the reward per token stored at the previous checkpoint, and adds this difference to the total reward. Finally, it calculates the difference between the current reward per token and the reward per token stored at the last checkpoint, and adds this difference to the total reward. (autogenerated documentation)
_deposit() :
This function allows a voter to deposit a certain amount of a specific token into the contract. It first updates the reward for all tokens, then adds the amount to the total supply and the balance of the specified token. It then writes a checkpoint for the token's balance and the total supply, and emits a Deposit event. (autogenerated documentation)
_withdraw() :
This function allows a voter to withdraw a specified amount of a specified token from the contract. It first updates the rewards for all tokens, then subtracts the specified amount from the total supply and the balance of the specified token. It then writes a checkpoint for the token's balance and the total supply, and emits an event to confirm the withdrawal. (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 amount is greater than 0 and that the token is a reward token. It then calculates the reward rate for the token by dividing the amount by the duration of the period. It then checks that the reward rate is not greater than the balance of the token divided by the duration. Finally, it emits a NotifyReward event with the sender, token, and amount. (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)