Finance

This document is better viewed at https://docs.openzeppelin.com/contracts/api/finance

This directory includes primitives for financial systems:

  • VestingWallet handles the vesting of Ether and ERC20 tokens for a given beneficiary. Custody of multiple tokens can be given to this contract, which will release the token to the beneficiary following a given, customizable, vesting schedule.

Contracts

VestingWallet

import "@openzeppelin/contracts/finance/VestingWallet.sol";

This contract handles the vesting of Eth and ERC20 tokens for a given beneficiary. Custody of multiple tokens can be given to this contract, which will release the token to the beneficiary following a given vesting schedule. The vesting schedule is customizable through the vestedAmount function.

Any token transferred to this contract will follow the vesting schedule as if they were locked from the beginning. Consequently, if the vesting has already started, any amount of tokens sent to this contract will (at least partly) be immediately releasable.

By setting the duration to 0, one can configure this contract to behave like an asset timelock that hold tokens for a beneficiary until a specified time.

constructor(address beneficiaryAddress, uint64 startTimestamp, uint64 durationSeconds) public

Set the beneficiary, start timestamp and vesting duration of the vesting wallet.

receive() external

The contract should be able to receive Eth.

beneficiary() → address public

Getter for the beneficiary address.

start() → uint256 public

Getter for the start timestamp.

duration() → uint256 public

Getter for the vesting duration.

end() → uint256 public

Getter for the end timestamp.

released() → uint256 public

Amount of eth already released

released(address token) → uint256 public

Amount of token already released

releasable() → uint256 public

Getter for the amount of releasable eth.

releasable(address token) → uint256 public

Getter for the amount of releasable token tokens. token should be the address of an IERC20 contract.

release() public

Release the native token (ether) that have already vested.

Emits a EtherReleased event.

release(address token) public

Release the tokens that have already vested.

Emits a ERC20Released event.

vestedAmount(uint64 timestamp) → uint256 public

Calculates the amount of ether that has already vested. Default implementation is a linear vesting curve.

vestedAmount(address token, uint64 timestamp) → uint256 public

Calculates the amount of tokens that has already vested. Default implementation is a linear vesting curve.

_vestingSchedule(uint256 totalAllocation, uint64 timestamp) → uint256 internal

Virtual implementation of the vesting formula. This returns the amount vested, as a function of time, for an asset given its total historical allocation.

EtherReleased(uint256 amount) event

ERC20Released(address indexed token, uint256 amount) event