Crate snapshots

Source
Expand description

Voting Escrow Snapshots: Historical snapshots of previous voting escrow balances.

§Motivation

There are several instances in which one may want to use an instantaneous snapshot of all vote escrow balances, for example:

  • Fee distribution. One may want to send protocol revenue to veToken holders.
  • Airdrops. One may want to send tokens to holders of a veToken.

§Mechanism

veToken balances are recorded for every period. A period is recorded for every 3 days.

There are two accounts that are used to compute historical balances:

  • LockerHistory, which stores the total number of veTokens for each period, and
  • EscrowHistory, which stores the veTokens in each Escrow per period.

Any time someone refreshes and/or modifies their vote escrow, they should refresh their EscrowHistory accounts.

§Program Addresses

§License

The snapshots program is licensed under the Affero General Public License version 3.

Modules§

accounts
An Anchor generated module, providing a set of structs mirroring the structs deriving Accounts, where each field is a Pubkey. This is useful for specifying accounts for a client.
instruction
An Anchor generated module containing the program’s set of instructions, where each method handler in the #[program] mod is associated with a struct defining the input arguments to the method. These should be used directly, when one wants to serialize Anchor instruction data, for example, when speciying instructions on a client.
program
Module representing the program.
snapshots
The snapshots program.

Structs§

EscrowHistory
Stores the total veToken balance of an locked_voter::Escrow for the given epochs.
LockerHistory
Stores the total number of veTokens in circulation for each period.

Enums§

ErrorCode
Errors.

Constants§

COMMON_ERA_UNIX_TS
The Unix timestamp of the start of the first era.
ERA_NUM_PERIODS
Number of periods in an era.
PERIOD_SECONDS
Number of seconds in a period.
SECONDS_PER_ERA
Number of seconds in an era.

Statics§

ID
The static program ID

Functions§

calculate_era_and_period_of_ts
Calculates the era and period of the given Unix timestamp.
calculate_era_start_ts
Calculates the start timestamp of an era.
calculate_next_era_and_period
Calculates the next era and period of the given period.
calculate_next_era_and_period_of_ts
Calculates the next era and period of the given Unix timestamp.
calculate_period_start_ts
Calculates the start timestamp of a period of an era.
check_id
Confirms that a given pubkey is equivalent to the program ID
entry
The Anchor codegen exposes a programming model where a user defines a set of methods inside of a #[program] module in a way similar to writing RPC request handlers. The macro then generates a bunch of code wrapping these user defined methods into something that can be executed on Solana.
entrypoint
Safety
has_period_elapsed
A period is elapsed if its start time has passed.
id
Returns the program ID