-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented proposal for Token Genesis Event #30
- Loading branch information
Semen Medvedev
committed
Apr 29, 2022
1 parent
c0c3732
commit f823b2d
Showing
18 changed files
with
1,335 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[167,119,139,142,62,185,218,144,63,242,132,68,181,77,117,88,16,84,69,103,210,49,114,237,151,235,178,55,159,74,223,248,70,191,83,171,68,147,169,18,114,190,120,151,80,58,132,43,50,211,123,76,233,134,230,10,26,102,162,8,173,8,2,54] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
use { | ||
crate::{ | ||
client::SplGovernanceInteractor, | ||
realm::Realm, | ||
}, | ||
solana_sdk::{ | ||
pubkey::Pubkey, | ||
signer::{Signer, keypair::Keypair}, | ||
instruction::Instruction, | ||
transaction::Transaction, | ||
program_error::ProgramError, | ||
}, | ||
spl_governance_addin_vesting::{ | ||
state::VestingSchedule, | ||
instruction::{deposit, deposit_with_realm}, | ||
voter_weight::get_voter_weight_record_address, | ||
}, | ||
solana_client::{ | ||
client_error::ClientError, | ||
}, | ||
}; | ||
|
||
#[derive(Debug)] | ||
pub struct AddinVesting<'a> { | ||
interactor: &'a SplGovernanceInteractor<'a>, | ||
pub program_id: Pubkey, | ||
} | ||
|
||
|
||
impl<'a> AddinVesting<'a> { | ||
pub fn new(interactor: &'a SplGovernanceInteractor, program_id: Pubkey) -> Self { | ||
AddinVesting { | ||
interactor, | ||
program_id, | ||
} | ||
} | ||
|
||
pub fn find_vesting_account(&self, vesting_token_account: &Pubkey) -> Pubkey { | ||
let (vesting_account,_) = Pubkey::find_program_address( | ||
&[&vesting_token_account.as_ref()], | ||
&self.program_id, | ||
); | ||
vesting_account | ||
} | ||
|
||
pub fn get_voter_weight_record_address(&self, owner: &Pubkey, realm: &Realm) -> Pubkey { | ||
get_voter_weight_record_address( | ||
&self.program_id, | ||
&realm.address, | ||
&realm.community_mint, | ||
owner) | ||
} | ||
|
||
pub fn deposit(&self, source_token_authority: &Pubkey, source_token_account: &Pubkey, | ||
vesting_owner: &Pubkey, vesting_token_account: &Pubkey, schedules: Vec<VestingSchedule>) -> Result<Instruction, ProgramError> | ||
{ | ||
deposit( | ||
&self.program_id, | ||
&spl_token::id(), | ||
vesting_token_account, | ||
&source_token_authority, | ||
source_token_account, | ||
vesting_owner, | ||
&self.interactor.payer.pubkey(), | ||
schedules, | ||
) | ||
} | ||
|
||
pub fn deposit_with_realm_instruction(&self, source_token_authority: &Pubkey, source_token_account: &Pubkey, | ||
vesting_owner: &Pubkey, vesting_token_account: &Pubkey, schedules: Vec<VestingSchedule>, realm: &Realm) -> Result<Instruction, ProgramError> | ||
{ | ||
deposit_with_realm( | ||
&self.program_id, | ||
&spl_token::id(), | ||
vesting_token_account, | ||
&source_token_authority, | ||
source_token_account, | ||
vesting_owner, | ||
&self.interactor.payer.pubkey(), | ||
schedules, | ||
&realm.interactor.spl_governance_program_address, | ||
&realm.address, | ||
&realm.community_mint, | ||
) | ||
} | ||
|
||
/* pub fn setup_max_voter_weight_record(&self, realm: &Realm) -> Result<Pubkey, ()> { | ||
use spl_governance_addin_fixed_weights::instruction; | ||
let (max_voter_weight_record_pubkey,_): (Pubkey,u8) = instruction::get_max_voter_weight_address( | ||
&self.program_id, | ||
&realm.address, | ||
&realm.community_mint, | ||
); | ||
if !self.interactor.account_exists(&max_voter_weight_record_pubkey) { | ||
let setup_max_voter_weight_record_instruction: Instruction = | ||
instruction::setup_max_voter_weight_record( | ||
&self.program_id, | ||
&realm.address, | ||
&realm.community_mint, | ||
&self.interactor.payer.pubkey(), | ||
); | ||
let transaction: Transaction = | ||
Transaction::new_signed_with_payer( | ||
&[ | ||
setup_max_voter_weight_record_instruction, | ||
], | ||
Some(&self.interactor.payer.pubkey()), | ||
&[ | ||
self.interactor.payer, | ||
], | ||
self.interactor.solana_client.get_latest_blockhash().unwrap(), | ||
); | ||
self.interactor.solana_client.send_and_confirm_transaction(&transaction) | ||
.map_err(|_|())?; | ||
} | ||
Ok(max_voter_weight_record_pubkey) | ||
} | ||
pub fn setup_voter_weight_record(&self, realm: &Realm, token_owner: &Pubkey) -> Result<Pubkey,()> { | ||
let (voter_weight_record_pubkey,_): (Pubkey,u8) = spl_governance_addin_fixed_weights::instruction::get_voter_weight_address( | ||
&self.program_id, | ||
&realm.address, | ||
&realm.community_mint, | ||
token_owner); | ||
if !self.interactor.account_exists(&voter_weight_record_pubkey) { | ||
let setup_voter_weight_record_instruction: Instruction = | ||
spl_governance_addin_fixed_weights::instruction::setup_voter_weight_record( | ||
&self.program_id, | ||
&realm.address, | ||
&realm.data.community_mint, | ||
token_owner, | ||
&self.interactor.payer.pubkey(), | ||
); | ||
let transaction: Transaction = | ||
Transaction::new_signed_with_payer( | ||
&[ | ||
setup_voter_weight_record_instruction, | ||
], | ||
Some(&self.interactor.payer.pubkey()), | ||
&[ | ||
self.interactor.payer, | ||
], | ||
self.interactor.solana_client.get_latest_blockhash().unwrap(), | ||
); | ||
self.interactor.solana_client.send_and_confirm_transaction(&transaction).unwrap(); | ||
} | ||
Ok(voter_weight_record_pubkey) | ||
}*/ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.