Finance

This crate includes primitives for financial systems.

Vesting

IVesting

use openzeppelin_finance::vesting::interface::IVesting;

Common interface for contracts implementing the vesting functionality.

Functions

start() → u64 external

Returns the timestamp marking the beginning of the vesting period.

cliff() → u64 external

Returns the timestamp marking the end of the cliff period.

duration() → u64 external

Returns the total duration of the vesting period.

end() → u64 external

Returns the timestamp marking the end of the vesting period.

released(token: ContractAddress) → u256 external

Returns the already released amount for a given token.

releasable(token: ContractAddress) → u256 external

Returns the amount of a given token that can be released at the time of the call.

vested_amount(token: ContractAddress, timestamp: u64) → u256 external

Returns the total vested amount of a specified token at a given timestamp.

release(token: ContractAddress) → u256 external

Releases the amount of a given token that has already vested and returns that amount.

Emits AmountReleased event.

Events

AmountReleased(token: ContractAddress, amount: u256) event

Emitted when vested tokens are released to the beneficiary.

VestingComponent

use openzeppelin_finance::vesting::VestingComponent;

Vesting component implementing the IVesting interface.

VestingSchedule trait

A trait that defines the logic for calculating the vested amount based on a given timestamp.

You can read more about the trait’s purpose and how to use it here.

calculate_vested_amount(self: @ContractState, token: ContractAddress, total_allocation: u256, timestamp: u64, start: u64, duration: u64, cliff: u64) → u256 internal

Calculates and returns the vested amount at a given timestamp based on the core vesting parameters.

Functions

start(self: @ContractState) → u64 external

Returns the timestamp marking the beginning of the vesting period.

cliff(self: @ContractState) → u64 external

Returns the timestamp marking the end of the cliff period.

duration(self: @ContractState) → u64 external

Returns the total duration of the vesting period.

end(self: @ContractState) → u64 external

Returns the timestamp marking the end of the vesting period.

released(self: @ContractState, token: ContractAddress) → u256 external

Returns the already released amount for a given token.

releasable(self: @ContractState, token: ContractAddress) → u256 external

Returns the amount of a given token that can be released at the time of the call.

vested_amount(self: @ContractState, token: ContractAddress, timestamp: u64) → u256 external

Returns the total vested amount of a specified token at a given timestamp.

release(ref self: ContractState, token: ContractAddress) → u256 external

Releases the amount of a given token that has already vested and returns that amount.

Requirements:

  • transfer call to the token must return true indicating a successful transfer.

Emits AmountReleased event.

Internal functions

initializer(ref self: ContractState, start: u64, duration: u64, cliff_duration: u64) internal

Initializes the component by setting the vesting start, duration and cliff_duration. To prevent reinitialization, this should only be used inside of a contract’s constructor.

Requirements:

  • cliff_duration must be less than or equal to duration.

resolve_vested_amount(self: @ContractState, token: ContractAddress, timestamp: u64) → u256 internal

Returns the vested amount that’s calculated using the VestingSchedule trait implementation.

LinearVestingSchedule

use openzeppelin_finance::vesting::LinearVestingSchedule;

Defines the logic for calculating the vested amount, incorporating a cliff period. It returns 0 before the cliff ends. After the cliff period, the vested amount returned is directly proportional to the time passed since the start of the vesting schedule.

Presets

VestingWallet

use openzeppelin::presets::VestingWallet;

A non-upgradable contract leveraging VestingComponent and OwnableComponent.

The contract is intentionally designed to be non-upgradable to ensure that neither the vesting initiator nor the vesting beneficiary can modify the vesting schedule without the consent of the other party.

0x02f9206089b6256db631acef1f8ca9f60da133a363600f89b4219f6d92632afa

Embedded Implementations
VestingComponent
OwnableComponent

Constructor

constructor(ref self: ContractState, beneficiary: ContractAddress, start: u64, duration: u64, cliff_duration: u64) constructor

Initializes the vesting component by setting the vesting start, duration and cliff_duration. Assigns beneficiary as the contract owner and the vesting beneficiary.

Requirements:

  • cliff_duration must be less than or equal to duration.