Skip to content

Commit

Permalink
Got rid of warnings; simplify account list (remove Rent & Clock) #5
Browse files Browse the repository at this point in the history
  • Loading branch information
Semen Medvedev committed Mar 23, 2022
1 parent 8b40fa3 commit ed98aff
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 36 deletions.
25 changes: 9 additions & 16 deletions addin-vesting/program/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use solana_program::{
program_error::ProgramError,
pubkey::Pubkey,
system_program,
sysvar,
};

use borsh::{BorshDeserialize, BorshSchema, BorshSerialize};
Expand Down Expand Up @@ -76,7 +75,6 @@ pub enum VestingInstruction {
/// 5. `[writable]` The source spl-token account (from account)
/// 6. `[]` The Vesting Owner account
/// 7. `[signer]` Payer
/// 8. `[]` Rent sysvar
///
/// Optional part (vesting for Realm)
/// 8. `[]` The Governance program account
Expand All @@ -97,18 +95,17 @@ pub enum VestingInstruction {
///
/// * Single owner
/// 0. `[]` The spl-token program account
/// 1. `[]` The clock sysvar account
/// 2. `[writable]` The vesting account (vesting owner account: PDA [seeds])
/// 3. `[writable]` The vesting spl-token account (vesting balance account)
/// 4. `[writable]` The destination spl-token account
/// 5. `[signer]` The Vesting Owner account
/// 1. `[writable]` The vesting account (vesting owner account: PDA [seeds])
/// 2. `[writable]` The vesting spl-token account (vesting balance account)
/// 3. `[writable]` The destination spl-token account
/// 4. `[signer]` The Vesting Owner account
///
/// Optional part (vesting for Realm)
/// 6. `[]` The Governance program account
/// 7. `[]` The Realm account
/// 8. `[]` Governing Owner Record. PDA seeds (governance program): ['governance', realm, token_mint, vesting_owner]
/// 9. `[writable]` The VoterWeightRecord. PDA seeds: ['voter_weight', realm, token_mint, vesting_owner]
/// 10. `[writable]` The MaxVoterWeightRecord. PDA seeds: ['max_voter_weight', realm, token_mint]
/// 5. `[]` The Governance program account
/// 6. `[]` The Realm account
/// 7. `[]` Governing Owner Record. PDA seeds (governance program): ['governance', realm, token_mint, vesting_owner]
/// 8. `[writable]` The VoterWeightRecord. PDA seeds: ['voter_weight', realm, token_mint, vesting_owner]
/// 9. `[writable]` The MaxVoterWeightRecord. PDA seeds: ['max_voter_weight', realm, token_mint]
///
Withdraw {
#[allow(dead_code)]
Expand Down Expand Up @@ -161,7 +158,6 @@ pub fn deposit(
AccountMeta::new(*source_token_account, false),
AccountMeta::new_readonly(*vesting_owner, false),
AccountMeta::new_readonly(*payer, true),
AccountMeta::new_readonly(sysvar::rent::id(), false),
];

let instruction = VestingInstruction::Deposit { seeds, schedules };
Expand Down Expand Up @@ -201,7 +197,6 @@ pub fn deposit_with_realm(
AccountMeta::new(*source_token_account, false),
AccountMeta::new_readonly(*vesting_owner, false),
AccountMeta::new_readonly(*payer, true),
AccountMeta::new_readonly(sysvar::rent::id(), false),

AccountMeta::new_readonly(*governance_id, false),
AccountMeta::new_readonly(*realm, false),
Expand Down Expand Up @@ -230,7 +225,6 @@ pub fn withdraw(
let vesting_account = Pubkey::create_program_address(&[&seeds], program_id)?;
let accounts = vec![
AccountMeta::new_readonly(*token_program_id, false),
AccountMeta::new_readonly(sysvar::clock::id(), false),
AccountMeta::new(vesting_account, false),
AccountMeta::new(*vesting_token_account, false),
AccountMeta::new(*destination_token_account, false),
Expand Down Expand Up @@ -264,7 +258,6 @@ pub fn withdraw_with_realm(
let max_voting_weight_record_account = get_max_voter_weight_record_address(program_id, realm, mint);
let accounts = vec![
AccountMeta::new_readonly(*token_program_id, false),
AccountMeta::new_readonly(sysvar::clock::id(), false),
AccountMeta::new(vesting_account, false),
AccountMeta::new(*vesting_token_account, false),
AccountMeta::new(*destination_token_account, false),
Expand Down
5 changes: 1 addition & 4 deletions addin-vesting/program/src/max_voter_weight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ use solana_program::{
sysvar::Sysvar,
};
use spl_governance::addins::max_voter_weight::get_max_voter_weight_record_data;
use spl_governance_tools::account::{
get_account_data,
create_and_serialize_account_signed,
};
use spl_governance_tools::account::create_and_serialize_account_signed;

pub use spl_governance_addin_api::max_voter_weight::MaxVoterWeightRecord;

Expand Down
11 changes: 2 additions & 9 deletions addin-vesting/program/src/processor.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use solana_program::{
account_info::{next_account_info, AccountInfo},
borsh::try_from_slice_unchecked,
decode_error::DecodeError,
entrypoint::ProgramResult,
msg,
program::{invoke, invoke_signed},
Expand All @@ -12,15 +11,14 @@ use solana_program::{
sysvar::{clock::Clock, Sysvar},
};

use num_traits::FromPrimitive;
use borsh::BorshSerialize;
use spl_token::{instruction::transfer, state::Account};
use spl_governance_tools::account::{
get_account_data,
create_and_serialize_account_signed,
};
use spl_governance::state::{
realm::{get_realm_address_seeds, get_realm_data},
realm::get_realm_data,
token_owner_record::{
get_token_owner_record_address_seeds,
get_token_owner_record_data_for_seeds,
Expand All @@ -32,12 +30,10 @@ use crate::{
instruction::VestingInstruction,
state::{VestingAccountType, VestingRecord, VestingSchedule},
voter_weight::{
VoterWeightRecord,
create_voter_weight_record,
get_voter_weight_record_data_checked,
},
max_voter_weight::{
MaxVoterWeightRecord,
create_max_voter_weight_record,
get_max_voter_weight_record_data_checked,
},
Expand All @@ -63,7 +59,6 @@ impl Processor {
let source_token_account = next_account_info(accounts_iter)?;
let vesting_owner_account = next_account_info(accounts_iter)?;
let payer_account = next_account_info(accounts_iter)?;
let rent_sysvar_info = next_account_info(accounts_iter)?;

let realm_info = if let Some(governance) = accounts_iter.next() {
let realm = next_account_info(accounts_iter)?;
Expand Down Expand Up @@ -112,7 +107,6 @@ impl Processor {
total_amount = total_amount.checked_add(s.amount).ok_or_else(|| ProgramError::InvalidInstructionData)?;
}

let rent = &Rent::from_account_info(rent_sysvar_info)?;
let vesting_record = VestingRecord {
account_type: VestingAccountType::VestingRecord,
owner: *vesting_owner_account.key,
Expand All @@ -127,7 +121,7 @@ impl Processor {
&[&seeds[..31]],
program_id,
system_program_account,
rent
&Rent::get()?,
)?;

if Account::unpack(&source_token_account.data.borrow())?.amount < total_amount {
Expand Down Expand Up @@ -213,7 +207,6 @@ impl Processor {
let accounts_iter = &mut _accounts.iter();

let spl_token_account = next_account_info(accounts_iter)?;
let clock_sysvar_account = next_account_info(accounts_iter)?;
let vesting_account = next_account_info(accounts_iter)?;
let vesting_token_account = next_account_info(accounts_iter)?;
let destination_token_account = next_account_info(accounts_iter)?;
Expand Down
3 changes: 0 additions & 3 deletions addin-vesting/program/src/state.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
use solana_program::{
program_pack::IsInitialized,
pubkey::Pubkey,
program_error::ProgramError,
};
use borsh::{BorshDeserialize, BorshSchema, BorshSerialize};
use spl_governance_tools::account::AccountMaxSize;
use crate::error::VestingError;


#[repr(C)]
#[derive(Clone, Debug, PartialEq, BorshDeserialize, BorshSerialize, BorshSchema)]
Expand Down
5 changes: 1 addition & 4 deletions addin-vesting/program/src/voter_weight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ use solana_program::{
sysvar::Sysvar,
};
use spl_governance::addins::voter_weight::get_voter_weight_record_data;
use spl_governance_tools::account::{
get_account_data,
create_and_serialize_account_signed,
};
use spl_governance_tools::account::create_and_serialize_account_signed;

pub use spl_governance_addin_api::voter_weight::VoterWeightRecord;

Expand Down

0 comments on commit ed98aff

Please sign in to comment.