Skip to content

Commit

Permalink
Implement testing configuration #50
Browse files Browse the repository at this point in the history
  • Loading branch information
Semen Medvedev committed Jun 13, 2022
1 parent e009bbd commit 6968102
Show file tree
Hide file tree
Showing 11 changed files with 374 additions and 263 deletions.
2 changes: 1 addition & 1 deletion addin-fixed-weights/program/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ cfg_if! {
("Dsc7huV17uZQWW4LG7K2o3TEiGKXTZNjxkARz2xzFu1d", 60_000_000 * TOKEN_MULT),
("26kiPimzAioocLxZAmCvkPqgLtQL6xUSCMwkRvCSFc6j", 11_250_000 * TOKEN_MULT),
("GUSDGuq94QYpj3YysYfnkgiKWeNcXanV2LgMrqFnsLBs", 142_700_000 * TOKEN_MULT),
("DyDYCzoxQ2UpmXJrEZofh721VWXy2N7832Bz7JtK8q2k", 1_000_000 * TOKEN_MULT),
("8sz14WSG3ykPFL2WHni31P6RH5F2S71JprBJKVYjZEPy", 1_000_000 * TOKEN_MULT),
]
);

Expand Down
1 change: 1 addition & 0 deletions artifacts-pubkey/neon-evm.pubkey
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"DCPSnJHB38e7vNK6o3AVLswJGRaP87iiNx2zvvapiKBz"
1 change: 1 addition & 0 deletions artifacts/neon-evm.keypair
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[81,105,226,134,135,234,130,127,73,129,211,135,45,156,221,199,148,9,201,246,97,207,120,162,92,154,43,202,103,210,40,127,181,55,2,149,117,203,161,147,34,14,122,44,227,121,68,203,206,68,65,197,34,116,221,241,173,192,26,133,158,237,237,189]
6 changes: 4 additions & 2 deletions governance-lib/src/governance.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use {
crate::{
client::{Client, ClientResult},
errors::GovernanceLibError,
realm::Realm,
token_owner::TokenOwner,
proposal::Proposal,
Expand Down Expand Up @@ -50,8 +51,9 @@ impl<'a> Governance<'a> {
self.realm.client.get_account_data_borsh::<GovernanceV2>(&self.realm.program_id, &self.governance_address)
}

pub fn get_proposals_count(&self) -> u32 {
self.get_data().unwrap().unwrap().proposals_count
pub fn get_proposals_count(&self) -> ClientResult<u32> {
let data = self.get_data()?.ok_or(GovernanceLibError::StateError(self.governance_address, "Missed governance".to_string()))?;
Ok(data.proposals_count)
}

pub fn create_governance_instruction(&self, creator: &Pubkey, token_owner: &TokenOwner,
Expand Down
1 change: 0 additions & 1 deletion launch-script/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
## Preparing steps:
```
solana-keygen new -f -o governance-test-scripts/community_mint.keypair --no-bip39-passphrase
spl-token --url http://localhost:8899 create-token --decimals 6 --fee-payer artifacts/payer.keypair launch-script/community-mint.keypair
solana config set -u http://localhost:8899
solana airdrop 1000 artifacts/payer.keypair
Expand Down
3 changes: 3 additions & 0 deletions launch-script/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ pub enum StateError {
#[error("Unknown MultiSig {0:?}")]
UnknownMultiSig(String),

#[error("Unknown MultiSig governed {0:?} {1:?}")]
UnknownMultiSigGoverned(String, Pubkey),

#[error("Invalid voter list")]
InvalidVoterList,
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,29 @@
use chrono::prelude::*;
use chrono::{Duration, NaiveDateTime};
use chronoutil::delta::{shift_months, shift_years};
use chrono::Duration;
use crate::Lockup;
use spl_governance_addin_vesting::state::VestingSchedule;
pub use spl_governance_addin_vesting::state::VestingSchedule;

pub struct ScheduleCreator {
pub current: NaiveDateTime,
pub testing: bool,
#[derive(Debug,PartialEq,Copy,Clone)]
pub enum Lockup {
NoLockup,
For4Years,
For1year1yearLinear,
}

impl ScheduleCreator {
pub fn new(testing: bool) -> Self {
let current = if testing {
Utc::now().naive_utc()
} else {
Utc::today().naive_utc().and_hms(0, 0, 0)
};
Self {
current,
testing,
}
}
impl Lockup {
pub fn default() -> Self {Lockup::For1year1yearLinear}

pub fn is_locked(&self) -> bool {*self != Lockup::NoLockup}

pub fn get_schedule(&self, amount: u64, lockup: Lockup) -> Vec<VestingSchedule> {
if self.testing {
self._get_schedule_testing(amount, &lockup)
} else {
self._get_schedule_real(amount, lockup)
pub fn get_schedule_size(&self) -> u32 {
match *self {
Lockup::NoLockup => 1,
Lockup::For4Years => 1,
Lockup::For1year1yearLinear => 12,
}
}

fn _get_schedule_real(&self, amount: u64, lockup: Lockup) -> Vec<VestingSchedule> {
match lockup {
pub fn get_mainnet_schedule(&self, start_time: NaiveDateTime, amount: u64) -> Vec<VestingSchedule> {
match self {
Lockup::NoLockup => {
vec![
VestingSchedule {release_time: 0, amount}
Expand All @@ -40,14 +32,14 @@ impl ScheduleCreator {
Lockup::For4Years => {
vec![
VestingSchedule {
release_time: shift_years(self.current, 4).timestamp() as u64,
release_time: shift_years(start_time, 4).timestamp() as u64,
amount
}
]
},
Lockup::For1year1yearLinear => {
let mut schedules = vec!();
let start = shift_years(self.current, 1);
let start = shift_years(start_time, 1);
for i in 1i32..=12 {
let prev = (amount as u128)
.checked_mul((i-1) as u128).unwrap()
Expand All @@ -66,8 +58,8 @@ impl ScheduleCreator {
}
}

fn _get_schedule_testing(&self, amount: u64, lockup: &Lockup) -> Vec<VestingSchedule> {
match lockup {
pub fn get_testing_schedule(&self, start_time: NaiveDateTime, amount: u64) -> Vec<VestingSchedule> {
match self {
Lockup::NoLockup => {
vec![
VestingSchedule {release_time: 0, amount}
Expand All @@ -76,14 +68,14 @@ impl ScheduleCreator {
Lockup::For4Years => {
vec![
VestingSchedule {
release_time: (self.current + Duration::minutes(4*12)).timestamp() as u64,
release_time: (start_time + Duration::minutes(4*12)).timestamp() as u64,
amount
}
]
},
Lockup::For1year1yearLinear => {
let mut schedules = vec!();
let start = self.current + Duration::minutes(12);
let start = start_time + Duration::minutes(12);
for i in 1i32..=12 {
let prev = (amount as u128)
.checked_mul((i-1) as u128).unwrap()
Expand All @@ -107,22 +99,6 @@ impl ScheduleCreator {
mod test {
use super::*;

#[test]
fn test_schedule_creator_testing() {
let schedule_creator = ScheduleCreator::new(true);
println!("{:?}", schedule_creator.get_schedule(11, Lockup::NoLockup));
println!("{:?}", schedule_creator.get_schedule(11, Lockup::For4Years));
println!("{:?}", schedule_creator.get_schedule(11, Lockup::For1year1yearLinear));
}

#[test]
fn test_schedule_creator_real() {
let schedule_creator = ScheduleCreator::new(false);
println!("{:?}", schedule_creator.get_schedule(1_000_000, Lockup::NoLockup));
println!("{:?}", schedule_creator.get_schedule(1_000_000, Lockup::For4Years));
println!("{:?}", schedule_creator.get_schedule(1_000_000, Lockup::For1year1yearLinear));
}

#[test]
fn test_date() {
let today = Utc::today();
Expand Down
Loading

0 comments on commit 6968102

Please sign in to comment.