VoteEscrowDistribution
Description:
This contract handles the distribution of tokens (e.g., fees or rewards) to users based on their locked balances (voting power) in an associated VotingEscrow
contract. It operates on a weekly epoch system, calculating and allowing users to claim their proportional share of tokens deposited into this contract. The claimed tokens are typically deposited back into the user's lock in the VotingEscrow
contract, effectively compounding their rewards.
Constructor
Description:
Initializes the VoteEscrowDistribution
contract upon deployment. It sets the start time aligned to the beginning of the current week, identifies the VotingEscrow
contract and its underlying token, sets the deployer as the initial depositor
(who can checkpoint tokens), and approves the VotingEscrow
contract to spend the maximum amount of the token held by this contract (necessary for depositing claimed rewards).
Input Parameters:
_voting_escrow
address
The address of the VotingEscrow
contract managing the locks.
timestamp
Description:
Returns the current block timestamp rounded down to the beginning of the current week (based on WEEK = 7 * 86400
seconds).
Return Value:
uint
The timestamp marking the start of the current week.
checkpoint_token
Description:
Updates the distribution schedule based on the tokens newly received by this contract since the last checkpoint. It calculates the amount of new tokens and distributes them proportionally over the weeks that have passed since the last token checkpoint (last_token_time
). This function must be called by the designated depositor
.
Events Emitted: CheckpointToken(uint time, uint tokens)
ve_for_at
Description:
Calculates the voting power (veToken balance) of a specific NFT lock (_tokenId
) at a specified past timestamp (_timestamp
). It reads historical data from the associated VotingEscrow
contract.
Input Parameters:
_tokenId
uint
The ID of the NFT representing the lock in the VotingEscrow
contract.
_timestamp
uint
The specific past timestamp at which to calculate the veToken balance.
Return Value:
uint
The veToken balance (voting power) of the lock at the specified timestamp.
checkpoint_total_supply
Description:
Updates the contract's internal record of the total veToken supply (ve_supply
) for past weeks. It reads checkpoint data from the associated VotingEscrow
contract and calculates the supply at the beginning of each week from the last recorded time_cursor
up to the current week.
claimable
Description:
Calculates the total amount of tokens claimable for a specific NFT lock (_tokenId
) based on its historical voting power relative to the total voting power and the tokens distributed each week. This is a read-only function and does not change the contract state.
Input Parameters:
_tokenId
uint
The ID of the NFT representing the lock in the VotingEscrow
contract.
Return Value:
uint
The amount of tokens currently claimable for the NFT.
claim
Description:
Claims the accumulated distributable tokens for a single NFT lock (_tokenId
). It calculates the claimable amount, updates the user's claim tracking (time_cursor_of
, user_epoch_of
), and deposits the claimed tokens back into the user's lock within the associated VotingEscrow
contract using deposit_for
.
Input Parameters:
_tokenId
uint
The ID of the NFT representing the lock in the VotingEscrow
contract.
Return Value:
uint
The amount of tokens successfully claimed and deposited.
Events Emitted: Claimed(uint tokenId, uint amount, uint claim_epoch, uint max_epoch)
claim_many
Description:
Claims accumulated distributable tokens for multiple NFT locks specified in the _tokenIds
array in a single transaction. It iterates through the array, performs the claim logic for each ID, and deposits the claimed tokens back into the respective locks in the VotingEscrow
contract.
Input Parameters:
_tokenIds
uint[] memory
An array of NFT IDs for which to claim tokens.
Return Value:
bool
Returns true
upon successful execution of the transaction.
Events Emitted: Claimed(uint tokenId, uint amount, uint claim_epoch, uint max_epoch)
(for each successful claim in the loop)
setDepositor
Description:
Allows the current depositor
to transfer the depositor role to a new address. Only the address currently set as depositor
can successfully call this function.
Input Parameters:
_depositor
address
The address to designate as the new depositor.
Last updated