Skip to content

Commit

Permalink
Add vesting to the main contract
Browse files Browse the repository at this point in the history
  • Loading branch information
tensojka committed Jan 31, 2024
1 parent 3c50c51 commit a82be39
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
14 changes: 11 additions & 3 deletions src/contract.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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<ContractState>;

#[abi(embed_v0)]
impl Vesting = vesting_component::VestingImpl<ContractState>;

#[storage]
struct Storage {
proposal_details: LegacyMap::<felt252, PropDetails>,
Expand All @@ -68,7 +73,9 @@ mod Governance {
delegate_hash: LegacyMap::<ContractAddress, felt252>,
total_delegated_to: LegacyMap::<ContractAddress, u128>,
#[substorage(v0)]
airdrop: airdrop_component::Storage
airdrop: airdrop_component::Storage,
#[substorage(v0)]
vesting: vesting_component::Storage
}

// PROPOSALS
Expand All @@ -77,7 +84,7 @@ mod Governance {
struct Proposed {
prop_id: felt252,
payload: felt252,
to_upgrade: ContractType
to_upgrade: ContractType,
}

#[derive(starknet::Event, Drop)]
Expand All @@ -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]
Expand Down
1 change: 1 addition & 0 deletions src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ mod proposals;
mod traits;
mod types;
mod upgrades;
mod vesting;
31 changes: 18 additions & 13 deletions src/vesting.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,22 @@ trait IVesting<TContractState> {
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?
}

#[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;

Expand Down Expand Up @@ -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(
Expand All @@ -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<TContractState>,
first_vest: u64,
period: u64,
increments_count: u16,
Expand All @@ -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 {
Expand Down

0 comments on commit a82be39

Please sign in to comment.