Skip to content

Commit

Permalink
Add basic vesting functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
tensojka committed Nov 27, 2023
1 parent fc704fa commit 39a494f
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/vesting.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ trait IVesting<TContractState> {

#[starknet::component]
mod vesting {
use starknet::syscalls::get_block_timestamp;

use governance::traits::IGovernanceTokenDispatcher;
use governance::traits::IGovernanceTokenDispatcherTrait;

// TODO: must depend on Ownable or Proposals to clarify who has the right to add vesting milestones
#[storage]
struct Storage {
Expand All @@ -24,7 +29,8 @@ mod vesting {
#[derive(starknet::Event, Drop)]
#[event]
enum Event {
VestingMilestoneAdded: VestingMilestoneAdded
VestingMilestoneAdded: VestingMilestoneAdded,
Vested: Vested
}

#[derive(starknet::Event, Drop)]
Expand All @@ -34,6 +40,13 @@ mod vesting {
amount: u128
}

#[derive(starknet::Event, Drop)]
struct Vested {
grantee: ContractAddress,
timestamp: u64,
amount: u128
}

#[embeddable_as(VestingImpl)]
impl Vesting<
TContractState, +HasComponent<TContractState>
Expand All @@ -44,7 +57,15 @@ mod vesting {
vested_timestamp: u64
) {
let amt_to_vest = self.milestone.read((vested_timestamp, grantee));
assert(amt_to_vest != 0, 'no vesting milestone found');
assert(amt_to_vest != 0, 'no vesting milestone found, or already vested');
assert(get_block_timestamp() > vested_timestamp, 'not yet eligible');
IGovernanceTokenDispatcher { contract_address: govtoken_addr }
.mint(claimee, u256 { high: 0, low: amt_to_vest });
self.milestone.write((vested_timestamp, grantee), 0);
self
.emit(
Vested { grantee: grantee, timestamp: vested_timestamp, amount: amt_to_vest }
);
}

fn add_vesting_milestone(
Expand Down

0 comments on commit 39a494f

Please sign in to comment.