Finance
This crate includes primitives for financial systems.
Vesting
IVesting
use openzeppelin_finance::vesting::interface::IVesting;
Common interface for contracts implementing the vesting functionality.
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.
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.
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.
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.
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.
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. |
0x01865aa64d7cbc465ab675d87b493c4c58af82eef726e702d87ca8ca4f6040e2
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.