Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[solana] Use token instead of token_interface #255

Merged
merged 2 commits into from
Mar 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions solana/programs/staking/src/contexts/cancel_vesting.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use anchor_lang::prelude::*;
use anchor_spl::associated_token::AssociatedToken;
use anchor_spl::token_interface::{Mint, TokenAccount, TokenInterface};

use anchor_spl::token::{Mint, Token, TokenAccount};
use crate::context::{VESTING_BALANCE_SEED, VESTING_CONFIG_SEED, VEST_SEED, CONFIG_SEED};
use crate::error::VestingError;
use crate::state::{Vesting, VestingBalance, VestingConfig};
Expand All @@ -15,13 +14,13 @@ pub struct CancelVesting<'info> {
@ VestingError::InvalidVestingAdmin
)]
admin: Signer<'info>,
mint: InterfaceAccount<'info, Mint>,
mint: Account<'info, Mint>,
#[account(
associated_token::mint = mint,
associated_token::authority = vester_ta.owner,
associated_token::token_program = token_program
)]
vester_ta: InterfaceAccount<'info, TokenAccount>,
vester_ta: Account<'info, TokenAccount>,
#[account(
mut,
constraint = !config.finalized @ VestingError::VestingFinalized, // Vesting cannot be cancelled after vest is finalized
Expand Down Expand Up @@ -51,7 +50,7 @@ pub struct CancelVesting<'info> {
)]
pub global_config: Box<Account<'info, GlobalConfig>>,
associated_token_program: Program<'info, AssociatedToken>,
token_program: Interface<'info, TokenInterface>,
token_program: Program<'info, Token>,
system_program: Program<'info, System>,
}

Expand Down
12 changes: 5 additions & 7 deletions solana/programs/staking/src/contexts/claim_vesting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,29 @@ use crate::{
};
use anchor_lang::prelude::*;
use anchor_spl::associated_token::AssociatedToken;
use anchor_spl::token_interface::{
transfer_checked, Mint, TokenAccount, TokenInterface, TransferChecked,
};
use anchor_spl::token::{Mint, Token, TokenAccount, transfer_checked, TransferChecked};
use std::convert::TryInto;

#[event_cpi]
#[derive(Accounts)]
pub struct ClaimVesting<'info> {
#[account(mut)]
vester: Signer<'info>,
mint: InterfaceAccount<'info, Mint>,
mint: Account<'info, Mint>,
#[account(
mut,
associated_token::mint = mint,
associated_token::authority = config,
associated_token::token_program = token_program
)]
vault: InterfaceAccount<'info, TokenAccount>,
vault: Account<'info, TokenAccount>,
#[account(
mut,
associated_token::mint = mint,
associated_token::authority = vester,
associated_token::token_program = token_program
)]
vester_ta: InterfaceAccount<'info, TokenAccount>,
vester_ta: Account<'info, TokenAccount>,
#[account(
mut,
constraint = config.finalized @ VestingError::VestingUnfinalized,
Expand Down Expand Up @@ -77,7 +75,7 @@ pub struct ClaimVesting<'info> {
)]
admin: AccountInfo<'info>,
associated_token_program: Program<'info, AssociatedToken>,
token_program: Interface<'info, TokenInterface>,
token_program: Program<'info, Token>,
system_program: Program<'info, System>,
}

Expand Down
9 changes: 4 additions & 5 deletions solana/programs/staking/src/contexts/create_vesting.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use anchor_lang::prelude::*;
use anchor_spl::associated_token::AssociatedToken;
use anchor_spl::token_interface::{Mint, TokenAccount, TokenInterface};

use anchor_spl::token::{Mint, Token, TokenAccount};
use crate::context::{CONFIG_SEED, VESTING_BALANCE_SEED, VESTING_CONFIG_SEED, VEST_SEED};
use crate::error::VestingError;
use crate::state::global_config::GlobalConfig;
Expand All @@ -16,13 +15,13 @@ pub struct CreateVesting<'info> {
@ VestingError::InvalidVestingAdmin
)]
admin: Signer<'info>,
mint: InterfaceAccount<'info, Mint>,
mint: Account<'info, Mint>,
#[account(
associated_token::mint = mint,
associated_token::authority = vester_ta.owner,
associated_token::token_program = token_program
)]
vester_ta: InterfaceAccount<'info, TokenAccount>,
vester_ta: Account<'info, TokenAccount>,
#[account(
mut,
constraint = !config.finalized @ VestingError::VestingFinalized, // A vest can only be created before a vest is finalized
Expand Down Expand Up @@ -51,7 +50,7 @@ pub struct CreateVesting<'info> {
)]
pub global_config: Box<Account<'info, GlobalConfig>>,
associated_token_program: Program<'info, AssociatedToken>,
token_program: Interface<'info, TokenInterface>,
token_program: Program<'info, Token>,
system_program: Program<'info, System>,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::state::global_config::GlobalConfig;
use crate::state::{VestingBalance, VestingConfig};
use anchor_lang::prelude::*;
use anchor_spl::associated_token::AssociatedToken;
use anchor_spl::token_interface::{Mint, TokenAccount, TokenInterface};
use anchor_spl::token::{Mint, Token, TokenAccount};

#[derive(Accounts)]
#[instruction()]
Expand All @@ -15,7 +15,7 @@ pub struct CreateVestingBalance<'info> {
@ VestingError::InvalidVestingAdmin
)]
admin: Signer<'info>,
mint: InterfaceAccount<'info, Mint>,
mint: Account<'info, Mint>,
#[account(
mut,
seeds = [VESTING_CONFIG_SEED.as_bytes(), mint.key().as_ref(), config.seed.to_le_bytes().as_ref()],
Expand All @@ -35,14 +35,14 @@ pub struct CreateVestingBalance<'info> {
associated_token::authority = vester_ta.owner,
associated_token::token_program = token_program
)]
vester_ta: InterfaceAccount<'info, TokenAccount>,
vester_ta: Account<'info, TokenAccount>,
#[account(
seeds = [CONFIG_SEED.as_bytes()],
bump = global_config.bump,
)]
pub global_config: Box<Account<'info, GlobalConfig>>,
associated_token_program: Program<'info, AssociatedToken>,
token_program: Interface<'info, TokenInterface>,
token_program: Program<'info, Token>,
system_program: Program<'info, System>,
}

Expand Down
8 changes: 4 additions & 4 deletions solana/programs/staking/src/contexts/finalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::context::{VESTING_CONFIG_SEED, CONFIG_SEED};
use crate::error::VestingError;
use crate::state::VestingConfig;
use anchor_lang::prelude::*;
use anchor_spl::token_interface::{Mint, TokenAccount, TokenInterface};
use anchor_spl::token::{Mint, Token, TokenAccount};
use crate::state::global_config::GlobalConfig;

#[derive(Accounts)]
Expand All @@ -13,14 +13,14 @@ pub struct Finalize<'info> {
@ VestingError::InvalidVestingAdmin
)]
pub admin: Signer<'info>,
pub mint: InterfaceAccount<'info, Mint>,
pub mint: Account<'info, Mint>,
#[account(
mut,
associated_token::mint = mint,
associated_token::authority = config,
associated_token::token_program = token_program
)]
vault: InterfaceAccount<'info, TokenAccount>,
vault: Account<'info, TokenAccount>,
#[account(
mut,
constraint = !config.finalized @ VestingError::VestingFinalized,
Expand All @@ -33,7 +33,7 @@ pub struct Finalize<'info> {
bump = global_config.bump,
)]
pub global_config: Box<Account<'info, GlobalConfig>>,
token_program: Interface<'info, TokenInterface>,
token_program: Program<'info, Token>,
}

impl<'info> Finalize<'info> {
Expand Down
10 changes: 5 additions & 5 deletions solana/programs/staking/src/contexts/initialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ use crate::state::global_config::GlobalConfig;
use crate::state::VestingConfig;
use anchor_lang::prelude::*;
use anchor_spl::associated_token::AssociatedToken;
use anchor_spl::token_interface::{Mint, TokenAccount, TokenInterface};
use anchor_spl::token::{Mint, Token, TokenAccount};

#[derive(Accounts)]
#[instruction(seed: u64)]
pub struct Initialize<'info> {
#[account(mut)]
admin: Signer<'info>,
#[account(address = global_config.voting_token_mint)]
mint: InterfaceAccount<'info, Mint>,
mint: Account<'info, Mint>,
// Initialize a vault for us to store our money in escrow for vesting
#[account(
init,
Expand All @@ -21,13 +21,13 @@ pub struct Initialize<'info> {
associated_token::authority = config,
associated_token::token_program = token_program
)]
vault: InterfaceAccount<'info, TokenAccount>,
vault: Account<'info, TokenAccount>,
// Set a recovery address for recovering surplus funds from the contract
#[account(
token::mint = mint,
token::token_program = token_program
)]
recovery: InterfaceAccount<'info, TokenAccount>,
recovery: Account<'info, TokenAccount>,
// Initialize a vesting config for a specific admin, mint and seed
#[account(
init,
Expand All @@ -46,7 +46,7 @@ pub struct Initialize<'info> {
global_config: Box<Account<'info, GlobalConfig>>,

associated_token_program: Program<'info, AssociatedToken>,
token_program: Interface<'info, TokenInterface>,
token_program: Program<'info, Token>,
system_program: Program<'info, System>,
}

Expand Down
10 changes: 5 additions & 5 deletions solana/programs/staking/src/contexts/transfer_vesting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,28 @@ use crate::state::{Vesting, VestingBalance, VestingConfig};
use crate::{error::ErrorCode, error::VestingError};
use anchor_lang::prelude::*;
use anchor_spl::associated_token::AssociatedToken;
use anchor_spl::token_interface::{Mint, TokenAccount, TokenInterface};
use anchor_spl::token::{Mint, Token, TokenAccount};

#[event_cpi]
#[derive(Accounts)]
pub struct TransferVesting<'info> {
#[account(mut)]
vester: Signer<'info>,
mint: Box<InterfaceAccount<'info, Mint>>,
mint: Box<Account<'info, Mint>>,
#[account(
mut,
associated_token::mint = mint,
associated_token::authority = vester_ta.owner,
associated_token::token_program = token_program
)]
vester_ta: Box<InterfaceAccount<'info, TokenAccount>>,
vester_ta: Box<Account<'info, TokenAccount>>,
#[account(
mut,
associated_token::mint = mint,
associated_token::authority = new_vester_ta.owner,
associated_token::token_program = token_program
)]
new_vester_ta: Box<InterfaceAccount<'info, TokenAccount>>,
new_vester_ta: Box<Account<'info, TokenAccount>>,
#[account(
mut,
constraint = config.finalized @ VestingError::VestingUnfinalized,
Expand Down Expand Up @@ -88,7 +88,7 @@ pub struct TransferVesting<'info> {
pub new_stake_account_metadata: Option<Box<Account<'info, StakeAccountMetadata>>>,

associated_token_program: Program<'info, AssociatedToken>,
token_program: Interface<'info, TokenInterface>,
token_program: Program<'info, Token>,
system_program: Program<'info, System>,
}

Expand Down
12 changes: 5 additions & 7 deletions solana/programs/staking/src/contexts/withdraw_surplus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ use crate::error::VestingError;
use crate::state::VestingConfig;
use anchor_lang::prelude::*;
use anchor_spl::associated_token::AssociatedToken;
use anchor_spl::token_interface::{
transfer_checked, Mint, TokenAccount, TokenInterface, TransferChecked,
};
use anchor_spl::token::{Mint, Token, TokenAccount, transfer_checked, TransferChecked};
use crate::state::global_config::GlobalConfig;

#[derive(Accounts)]
Expand All @@ -21,15 +19,15 @@ pub struct WithdrawSurplus<'info> {
token::mint = mint,
token::token_program = token_program
)]
recovery: InterfaceAccount<'info, TokenAccount>,
mint: InterfaceAccount<'info, Mint>,
recovery: Account<'info, TokenAccount>,
mint: Account<'info, Mint>,
#[account(
mut,
associated_token::mint = mint,
associated_token::authority = config,
associated_token::token_program = token_program
)]
vault: InterfaceAccount<'info, TokenAccount>,
vault: Account<'info, TokenAccount>,
#[account(
mut,
constraint = vault.amount > config.vested @ VestingError::NotInSurplus,
Expand All @@ -44,7 +42,7 @@ pub struct WithdrawSurplus<'info> {
)]
pub global_config: Box<Account<'info, GlobalConfig>>,
associated_token_program: Program<'info, AssociatedToken>,
token_program: Interface<'info, TokenInterface>,
token_program: Program<'info, Token>,
system_program: Program<'info, System>,
}

Expand Down