Finance
Alpha Version
v3.0.0-alpha.3. Click here to visit the latest stable release.This crate includes primitives for financial systems.
Interfaces
Starting from version 3.x.x, the interfaces are no longer part of the openzeppelin_access package. The references
documented here are contained in the openzeppelin_interfaces package version 2.1.0-alpha.0.
use openzeppelin_interfaces::vesting::IVesting;Common interface for contracts implementing the vesting functionality.
Functions
start()cliff()duration()end()released(token)releasable(token)vested_amount(token, timestamp)release(token)
Events
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.
May emit an AmountReleased event.
Events
AmountReleased(token: ContractAddress, amount: u256)
event
#Emitted when vested tokens are released to the beneficiary.
Vesting
use openzeppelin_finance::vesting::VestingComponent;Vesting component implementing the IVesting interface.
Vesting Schedule Trait Implementations
functions
Embeddable Implementations
VestingImpl
start(self)cliff(self)duration(self)end(self)released(self, token)releasable(self, token)vested_amount(self, token, timestamp)release(self, token)
Internal implementations
InternalImpl
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.
If the releasable amount is zero, this function won't emit the event or attempt to transfer the tokens.
Requirements:
transfercall to thetokenmust returntrueindicating a successful transfer.
May emit an 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_durationmust be less than or equal toduration.
resolve_vested_amount(self: @ContractState, token: ContractAddress, timestamp: u64) → u256
internal
#Returns the vested amount that's calculated using the VestingSchedule trait implementation.
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
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.
0x03e7d05eb2325c2e10d219f6b70468aef9e915352ac31521ec2950ebf0e3acb4Constructor
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_durationmust be less than or equal toduration.