Skip to content

RewardEscrow

Description

This is the mechanism for distributing SNX rewards from the inflationary supply. When an SNX staker claims fees, the inflationary reward component is escrowed in this contract and an entry is added to an escrow schedule for that staker for them to claim after a year. These vesting schedules can only be appended to by the FeePool contract.

The logic of RewardEscrow is derived from the SynthetixEscrow contract.

Source: contracts/RewardEscrow.sol

Architecture

Variables

MAX_VESTING_ENTRIES

Source

This constant limits vesting schedules to be shorter than 260 entries long so that iteration is bounded. This allows up to five years of vesting entries to be handled, if one is generated per weekly fee period.

Value: 52 * 5

Type: uint256

feePool

Source

The address of the FeePool contract.

Type: contract IFeePool

synthetix

Source

The address of the main Synthetix contract.

Type: contract ISynthetix

totalEscrowedAccountBalance

Source

The quantity of remaining tokens for each account; it saves the recomputation involved in summing over vestingSchedules entries.

Type: mapping(address => uint256)

totalEscrowedBalance

Source

A record of the total remaining vested balance in this contract, which should be equal to the actual SNX balance.

Type: uint256

totalVestedAccountBalance

Source

The quantity of tokens that have already been vested for each account.

Type: mapping(address => uint256)

vestingSchedules

Source

Stores the vesting schedule for each for each account. Each schedule is a list of (vesting timestamp, quantity) pairs in ascending time order.

Type: mapping(address => uint256[2][])

Constructor

constructor

Source

Initialises the Synthetix and FeePool contract addresses, and the inherited Owned instance.

Details

Signature

constructor(address _owner, contract ISynthetix _synthetix, contract IFeePool _feePool)

Visibility

public

State Mutability

``

Views

balanceOf

Source

An alias to totalEscrowedAccountBalance[account] for ERC20 integration.

Details

Signature

balanceOf(address account) view returns (uint256)

Visibility

public

State Mutability

view

checkAccountSchedule

Source

Returns the full vesting schedule for a given account.

Details

Signature

checkAccountSchedule(address account) view returns (uint256[520])

Visibility

public

State Mutability

view

getNextVestingEntry

Source

Returns the next vesting entry in the same manner as getNextVestingIndex. Returns [0,0] if there is no next vesting entry.

Details

Signature

getNextVestingEntry(address account) view returns (uint256[2])

Visibility

public

State Mutability

view

getNextVestingIndex

Source

Returns the index of the next vesting entry that will vest for a given account. Returns one past the end if there are none remaining.

The function iterates until it finds the first nonzero vesting entry timestamp, so the gas cost increases slightly as more entries vest. A full schedule of 260 entries would cost a little over 50\,000 gas to iterate over.

Details

Signature

getNextVestingIndex(address account) view returns (uint256)

Visibility

public

State Mutability

view

getNextVestingQuantity

Source

Returns the SNX quantity of the next vesting entry. Returns 0 if there is no such entry.

Details

Signature

getNextVestingQuantity(address account) view returns (uint256)

Visibility

external

State Mutability

view

getNextVestingTime

Source

Returns the timestamp of the next vesting entry. Returns 0 if there is no such entry.

Details

Signature

getNextVestingTime(address account) view returns (uint256)

Visibility

external

State Mutability

view

getVestingQuantity

Source

Returns the quantity of SNX a given schedule entry will yield.

Details

Signature

getVestingQuantity(address account, uint256 index) view returns (uint256)

Visibility

public

State Mutability

view

getVestingScheduleEntry

Source

Returns a particular schedule entry for an account, which is a pair of uints: (vesting timestamp, SNX quantity).

This is here because the public function generated for vestingSchedules awkwardly requires the index into the pair as its third argument.

Details

Signature

getVestingScheduleEntry(address account, uint256 index) view returns (uint256[2])

Visibility

public

State Mutability

view

getVestingTime

Source

Returns the time at which a given schedule entry will vest.

Details

Signature

getVestingTime(address account, uint256 index) view returns (uint256)

Visibility

public

State Mutability

view

numVestingEntries

Source

The number of entries in an account's vesting schedule, including those already claimed.

Details

Signature

numVestingEntries(address account) view returns (uint256)

Visibility

external

State Mutability

view

Restricted Functions

appendVestingEntry

Source

This function allows the FeePool contract to add a new entry to a given account's vesting schedule when it claims its fees. All new entries are set to vest after one year.

Details

Signature

appendVestingEntry(address account, uint256 quantity)

Visibility

external

State Mutability

``

Modifiers

setFeePool

Source

Sets the address of the FeePool contract, so that new vesting entries can be generated.

Details

Signature

setFeePool(contract IFeePool _feePool)

Visibility

external

State Mutability

``

Modifiers

Emits

setSynthetix

Source

Sets the address of the Synthetix contract, so that escrowed SNX can be transferred to accounts claiming them.

Details

Signature

setSynthetix(contract ISynthetix _synthetix)

Visibility

external

State Mutability

``

Modifiers

Emits

Internal Functions

_appendVestingEntry

Source

Details

Signature

_appendVestingEntry(address account, uint256 quantity)

Visibility

internal

State Mutability

``

Requires

Emits

_numVestingEntries

Source

Details

Signature

_numVestingEntries(address account) view returns (uint256)

Visibility

internal

State Mutability

view

External Functions

vest

Source

Finds all vesting schedule entries that have come due for the caller and transfers the total quantity of tokens to them. Vested entries are overwritten with [0,0].

Details

Signature

vest()

Visibility

external

State Mutability

``

Modifiers

onlyFeePool

Source

Reverts the transaction if the msg.sender is not the FeePool.

Events

FeePoolUpdated

Source

Records that the fee pool contract address was altered.

Signature: FeePoolUpdated(address newFeePool)

SynthetixUpdated

Source

Records that the SNX contract address was altered.

Signature: SynthetixUpdated(address newSynthetix)

Vested

Source

Records that an account vested a quantity of tokens.

Signature: Vested(address beneficiary, uint256 time, uint256 value)

VestingEntryCreated

Source

Records that the fee pool created a vesting entry.

Signature: VestingEntryCreated(address beneficiary, uint256 time, uint256 value)