diff --git a/src/contract.cairo b/src/contract.cairo index 5987a1b3..d0f072d5 100644 --- a/src/contract.cairo +++ b/src/contract.cairo @@ -42,15 +42,20 @@ mod Governance { use governance::types::PropDetails; use governance::upgrades::Upgrades; use governance::airdrop::airdrop as airdrop_component; + use governance::vesting::vesting as vesting_component; use starknet::ContractAddress; component!(path: airdrop_component, storage: airdrop, event: AirdropEvent); + component!(path: vesting_component, storage: vesting, event: VestingEvent); #[abi(embed_v0)] impl Airdrop = airdrop_component::AirdropImpl; + #[abi(embed_v0)] + impl Vesting = vesting_component::VestingImpl; + #[storage] struct Storage { proposal_details: LegacyMap::, @@ -68,7 +73,9 @@ mod Governance { delegate_hash: LegacyMap::, total_delegated_to: LegacyMap::, #[substorage(v0)] - airdrop: airdrop_component::Storage + airdrop: airdrop_component::Storage, + #[substorage(v0)] + vesting: vesting_component::Storage } // PROPOSALS @@ -77,7 +84,7 @@ mod Governance { struct Proposed { prop_id: felt252, payload: felt252, - to_upgrade: ContractType + to_upgrade: ContractType, } #[derive(starknet::Event, Drop)] @@ -92,7 +99,8 @@ mod Governance { enum Event { Proposed: Proposed, Voted: Voted, - AirdropEvent: airdrop_component::Event + AirdropEvent: airdrop_component::Event, + VestingEvent: vesting_component::Event } #[constructor] diff --git a/src/lib.cairo b/src/lib.cairo index 3df95c88..a42d4862 100644 --- a/src/lib.cairo +++ b/src/lib.cairo @@ -10,3 +10,4 @@ mod proposals; mod traits; mod types; mod upgrades; +mod vesting; diff --git a/src/vesting.cairo b/src/vesting.cairo index e0aecfe3..aa284a90 100644 --- a/src/vesting.cairo +++ b/src/vesting.cairo @@ -15,8 +15,9 @@ trait IVesting { ref self: TContractState, first_vest: u64, period: u64, - increments_count: u64, - total_amount: u128 + increments_count: u16, + total_amount: u128, + grantee: ContractAddress ); // MAYBE – streaming? // MAYBE – options on the govtoken? @@ -24,8 +25,12 @@ trait IVesting { #[starknet::component] mod vesting { - use starknet::syscalls::get_block_timestamp; + use governance::contract::IGovernance; + use starknet::get_block_timestamp; + use starknet::ContractAddress; + use governance::contract::Governance; + use governance::contract::Governance::ContractState; use governance::traits::IGovernanceTokenDispatcher; use governance::traits::IGovernanceTokenDispatcherTrait; @@ -65,10 +70,11 @@ mod vesting { vested_timestamp: u64 ) { let amt_to_vest = self.milestone.read((vested_timestamp, grantee)); - assert(amt_to_vest != 0, 'no vesting milestone found, or already vested'); + assert(amt_to_vest != 0, 'nothing to vest'); assert(get_block_timestamp() > vested_timestamp, 'not yet eligible'); - IGovernanceTokenDispatcher { contract_address: govtoken_addr } - .mint(claimee, u256 { high: 0, low: amt_to_vest }); + let state = Governance::unsafe_new_contract_state(); + IGovernanceTokenDispatcher { contract_address: state.get_governance_token_address() } + .mint(grantee, u256 { high: 0, low: amt_to_vest }); self.milestone.write((vested_timestamp, grantee), 0); self .emit( @@ -82,17 +88,17 @@ mod vesting { grantee: ContractAddress, amount: u128 ) { - self.milestone.write((vested_timestamp, grantee), amount); + self.milestone.write((vesting_timestamp, grantee), amount); self .emit( VestingMilestoneAdded { - grantee: grantee, timestamp: vesting_timestamp, amount: u128 + grantee: grantee, timestamp: vesting_timestamp, amount: amount } ) } fn add_linear_vesting_schedule( - ref self: TContractState, + ref self: ComponentState, first_vest: u64, period: u64, increments_count: u16, @@ -101,10 +107,9 @@ mod vesting { ) { let mut i: u16 = 0; let mut curr_timestamp = first_vest; - assert(increments_count > 1, 'schedule must have more than one milestone'); - assert(get_block_timestamp() < first_vest, 'first vest cannot be in the past'); - assert() - let per_vest_amount = total_amount / increments_count; + assert(increments_count > 1, 'increments_count <= 1'); + assert(get_block_timestamp() < first_vest, 'first vest can\'t be in the past'); + let per_vest_amount = total_amount / increments_count.into(); let mut total_scheduled = 0; loop { if i == increments_count {