From 60a62750ce2fd2efe3ca16bc7d966359355168f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sojka?= Date: Mon, 27 Nov 2023 16:36:40 +0000 Subject: [PATCH] Add more functionality to the vesting skeleton --- src/vesting.cairo | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/vesting.cairo b/src/vesting.cairo index dbec80f1..765e2423 100644 --- a/src/vesting.cairo +++ b/src/vesting.cairo @@ -5,7 +5,7 @@ trait IVesting { fn vest(ref self: TContractState, grantee: ContractAddress, vested_timestamp: u64); fn add_vesting_milestone( - ref self: TContractState, vesting_timestamp: u64, grantee: ContractAddress + ref self: TContractState, vesting_timestamp: u64, grantee: ContractAddress, amount: u128 ); // add_linear_vesting_schedule // add_cliff_linear_vesting_schedule @@ -15,11 +15,25 @@ trait IVesting { #[starknet::component] mod vesting { + // TODO: must depend on Ownable or Proposals to clarify who has the right to add vesting milestones #[storage] struct Storage { milestone: LegacyMap::<(u64, ContractAddress), u128> } + #[derive(starknet::Event, Drop)] + #[event] + enum Event { + VestingMilestoneAdded: VestingMilestoneAdded + } + + #[derive(starknet::Event, Drop)] + struct VestingMilestoneAdded { + grantee: ContractAddress, + timestamp: u64, + amount: u128 + } + #[embeddable_as(VestingImpl)] impl Vesting< TContractState, +HasComponent @@ -28,12 +42,20 @@ mod vesting { ref self: ComponentState, grantee: ContractAddress, vested_timestamp: u64 - ) {} + ) { + let amt_to_vest = self.milestone.read((vested_timestamp, grantee)); + assert(amt_to_vest != 0, 'no vesting milestone found'); + } fn add_vesting_milestone( ref self: ComponentState, vesting_timestamp: u64, - grantee: ContractAddress - ) {} + grantee: ContractAddress, + amount: u128 + ) { + // TODO: check if caller is eligible to add vesting milestone or if this is part of a proposal + self.milestone.write((vested_timestamp, grantee), amount); + self.emit(VestingMilestoneAdded { grantee: grantee, timestamp: vesting_timestamp, amount: u128}) + } } }