From adde122a7d00faeb86a76b1eef2a75159be40e0e Mon Sep 17 00:00:00 2001 From: zpoken <82594516+zpoken@users.noreply.github.com> Date: Thu, 27 Feb 2025 19:12:01 +0200 Subject: [PATCH 1/2] Use token::Token instead of token_interface::TokenInterface --- solana/programs/staking/src/contexts/cancel_vesting.rs | 6 +++--- solana/programs/staking/src/contexts/claim_vesting.rs | 5 +++-- solana/programs/staking/src/contexts/create_vesting.rs | 6 +++--- .../programs/staking/src/contexts/create_vesting_balance.rs | 5 +++-- solana/programs/staking/src/contexts/finalize.rs | 5 +++-- solana/programs/staking/src/contexts/initialize.rs | 5 +++-- solana/programs/staking/src/contexts/transfer_vesting.rs | 5 +++-- solana/programs/staking/src/contexts/withdraw_surplus.rs | 5 +++-- 8 files changed, 24 insertions(+), 18 deletions(-) diff --git a/solana/programs/staking/src/contexts/cancel_vesting.rs b/solana/programs/staking/src/contexts/cancel_vesting.rs index fb9cba44..495ac91d 100644 --- a/solana/programs/staking/src/contexts/cancel_vesting.rs +++ b/solana/programs/staking/src/contexts/cancel_vesting.rs @@ -1,7 +1,7 @@ use anchor_lang::prelude::*; use anchor_spl::associated_token::AssociatedToken; -use anchor_spl::token_interface::{Mint, TokenAccount, TokenInterface}; - +use anchor_spl::token_interface::{Mint, TokenAccount}; +use anchor_spl::token::Token; use crate::context::{VESTING_BALANCE_SEED, VESTING_CONFIG_SEED, VEST_SEED, CONFIG_SEED}; use crate::error::VestingError; use crate::state::{Vesting, VestingBalance, VestingConfig}; @@ -51,7 +51,7 @@ pub struct CancelVesting<'info> { )] pub global_config: Box>, associated_token_program: Program<'info, AssociatedToken>, - token_program: Interface<'info, TokenInterface>, + token_program: Program<'info, Token>, system_program: Program<'info, System>, } diff --git a/solana/programs/staking/src/contexts/claim_vesting.rs b/solana/programs/staking/src/contexts/claim_vesting.rs index ae70ff37..42847cf9 100644 --- a/solana/programs/staking/src/contexts/claim_vesting.rs +++ b/solana/programs/staking/src/contexts/claim_vesting.rs @@ -9,8 +9,9 @@ use crate::{ use anchor_lang::prelude::*; use anchor_spl::associated_token::AssociatedToken; use anchor_spl::token_interface::{ - transfer_checked, Mint, TokenAccount, TokenInterface, TransferChecked, + transfer_checked, Mint, TokenAccount, TransferChecked, }; +use anchor_spl::token::Token; use std::convert::TryInto; #[event_cpi] @@ -77,7 +78,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>, } diff --git a/solana/programs/staking/src/contexts/create_vesting.rs b/solana/programs/staking/src/contexts/create_vesting.rs index 65c6b4b7..4190e0cd 100644 --- a/solana/programs/staking/src/contexts/create_vesting.rs +++ b/solana/programs/staking/src/contexts/create_vesting.rs @@ -1,7 +1,7 @@ use anchor_lang::prelude::*; use anchor_spl::associated_token::AssociatedToken; -use anchor_spl::token_interface::{Mint, TokenAccount, TokenInterface}; - +use anchor_spl::token_interface::{Mint, TokenAccount}; +use anchor_spl::token::Token; use crate::context::{CONFIG_SEED, VESTING_BALANCE_SEED, VESTING_CONFIG_SEED, VEST_SEED}; use crate::error::VestingError; use crate::state::global_config::GlobalConfig; @@ -51,7 +51,7 @@ pub struct CreateVesting<'info> { )] pub global_config: Box>, associated_token_program: Program<'info, AssociatedToken>, - token_program: Interface<'info, TokenInterface>, + token_program: Program<'info, Token>, system_program: Program<'info, System>, } diff --git a/solana/programs/staking/src/contexts/create_vesting_balance.rs b/solana/programs/staking/src/contexts/create_vesting_balance.rs index 098f0d6e..b110de08 100644 --- a/solana/programs/staking/src/contexts/create_vesting_balance.rs +++ b/solana/programs/staking/src/contexts/create_vesting_balance.rs @@ -4,7 +4,8 @@ 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_interface::{Mint, TokenAccount}; +use anchor_spl::token::Token; #[derive(Accounts)] #[instruction()] @@ -42,7 +43,7 @@ pub struct CreateVestingBalance<'info> { )] pub global_config: Box>, associated_token_program: Program<'info, AssociatedToken>, - token_program: Interface<'info, TokenInterface>, + token_program: Program<'info, Token>, system_program: Program<'info, System>, } diff --git a/solana/programs/staking/src/contexts/finalize.rs b/solana/programs/staking/src/contexts/finalize.rs index 84ae620e..63cd0900 100644 --- a/solana/programs/staking/src/contexts/finalize.rs +++ b/solana/programs/staking/src/contexts/finalize.rs @@ -2,7 +2,8 @@ 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_interface::{Mint, TokenAccount}; +use anchor_spl::token::Token; use crate::state::global_config::GlobalConfig; #[derive(Accounts)] @@ -33,7 +34,7 @@ pub struct Finalize<'info> { bump = global_config.bump, )] pub global_config: Box>, - token_program: Interface<'info, TokenInterface>, + token_program: Program<'info, Token>, } impl<'info> Finalize<'info> { diff --git a/solana/programs/staking/src/contexts/initialize.rs b/solana/programs/staking/src/contexts/initialize.rs index 995cfa15..79081eac 100644 --- a/solana/programs/staking/src/contexts/initialize.rs +++ b/solana/programs/staking/src/contexts/initialize.rs @@ -4,7 +4,8 @@ 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_interface::{Mint, TokenAccount}; +use anchor_spl::token::Token; #[derive(Accounts)] #[instruction(seed: u64)] @@ -46,7 +47,7 @@ pub struct Initialize<'info> { global_config: Box>, associated_token_program: Program<'info, AssociatedToken>, - token_program: Interface<'info, TokenInterface>, + token_program: Program<'info, Token>, system_program: Program<'info, System>, } diff --git a/solana/programs/staking/src/contexts/transfer_vesting.rs b/solana/programs/staking/src/contexts/transfer_vesting.rs index f28a8c18..cb1c7eed 100644 --- a/solana/programs/staking/src/contexts/transfer_vesting.rs +++ b/solana/programs/staking/src/contexts/transfer_vesting.rs @@ -9,7 +9,8 @@ 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_interface::{Mint, TokenAccount}; +use anchor_spl::token::Token; #[event_cpi] #[derive(Accounts)] @@ -88,7 +89,7 @@ pub struct TransferVesting<'info> { pub new_stake_account_metadata: Option>>, associated_token_program: Program<'info, AssociatedToken>, - token_program: Interface<'info, TokenInterface>, + token_program: Program<'info, Token>, system_program: Program<'info, System>, } diff --git a/solana/programs/staking/src/contexts/withdraw_surplus.rs b/solana/programs/staking/src/contexts/withdraw_surplus.rs index b5af67c7..166d53fb 100644 --- a/solana/programs/staking/src/contexts/withdraw_surplus.rs +++ b/solana/programs/staking/src/contexts/withdraw_surplus.rs @@ -4,8 +4,9 @@ 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, + transfer_checked, Mint, TokenAccount, TransferChecked, }; +use anchor_spl::token::Token; use crate::state::global_config::GlobalConfig; #[derive(Accounts)] @@ -44,7 +45,7 @@ pub struct WithdrawSurplus<'info> { )] pub global_config: Box>, associated_token_program: Program<'info, AssociatedToken>, - token_program: Interface<'info, TokenInterface>, + token_program: Program<'info, Token>, system_program: Program<'info, System>, } From 82a188a63239491cb6cc5dad473bd89a5251a425 Mon Sep 17 00:00:00 2001 From: zpoken <82594516+zpoken@users.noreply.github.com> Date: Thu, 27 Feb 2025 22:11:50 +0200 Subject: [PATCH 2/2] Use Account instead of InterfaceAccount --- .../programs/staking/src/contexts/cancel_vesting.rs | 7 +++---- solana/programs/staking/src/contexts/claim_vesting.rs | 11 ++++------- .../programs/staking/src/contexts/create_vesting.rs | 7 +++---- .../staking/src/contexts/create_vesting_balance.rs | 7 +++---- solana/programs/staking/src/contexts/finalize.rs | 7 +++---- solana/programs/staking/src/contexts/initialize.rs | 9 ++++----- .../programs/staking/src/contexts/transfer_vesting.rs | 9 ++++----- .../programs/staking/src/contexts/withdraw_surplus.rs | 11 ++++------- 8 files changed, 28 insertions(+), 40 deletions(-) diff --git a/solana/programs/staking/src/contexts/cancel_vesting.rs b/solana/programs/staking/src/contexts/cancel_vesting.rs index 495ac91d..49cfef0f 100644 --- a/solana/programs/staking/src/contexts/cancel_vesting.rs +++ b/solana/programs/staking/src/contexts/cancel_vesting.rs @@ -1,7 +1,6 @@ use anchor_lang::prelude::*; use anchor_spl::associated_token::AssociatedToken; -use anchor_spl::token_interface::{Mint, TokenAccount}; -use anchor_spl::token::Token; +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}; @@ -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 diff --git a/solana/programs/staking/src/contexts/claim_vesting.rs b/solana/programs/staking/src/contexts/claim_vesting.rs index 42847cf9..1ae7b01b 100644 --- a/solana/programs/staking/src/contexts/claim_vesting.rs +++ b/solana/programs/staking/src/contexts/claim_vesting.rs @@ -8,10 +8,7 @@ use crate::{ }; use anchor_lang::prelude::*; use anchor_spl::associated_token::AssociatedToken; -use anchor_spl::token_interface::{ - transfer_checked, Mint, TokenAccount, TransferChecked, -}; -use anchor_spl::token::Token; +use anchor_spl::token::{Mint, Token, TokenAccount, transfer_checked, TransferChecked}; use std::convert::TryInto; #[event_cpi] @@ -19,21 +16,21 @@ use std::convert::TryInto; 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, diff --git a/solana/programs/staking/src/contexts/create_vesting.rs b/solana/programs/staking/src/contexts/create_vesting.rs index 4190e0cd..8e7f7719 100644 --- a/solana/programs/staking/src/contexts/create_vesting.rs +++ b/solana/programs/staking/src/contexts/create_vesting.rs @@ -1,7 +1,6 @@ use anchor_lang::prelude::*; use anchor_spl::associated_token::AssociatedToken; -use anchor_spl::token_interface::{Mint, TokenAccount}; -use anchor_spl::token::Token; +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; @@ -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 diff --git a/solana/programs/staking/src/contexts/create_vesting_balance.rs b/solana/programs/staking/src/contexts/create_vesting_balance.rs index b110de08..38901739 100644 --- a/solana/programs/staking/src/contexts/create_vesting_balance.rs +++ b/solana/programs/staking/src/contexts/create_vesting_balance.rs @@ -4,8 +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}; -use anchor_spl::token::Token; +use anchor_spl::token::{Mint, Token, TokenAccount}; #[derive(Accounts)] #[instruction()] @@ -16,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()], @@ -36,7 +35,7 @@ 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, diff --git a/solana/programs/staking/src/contexts/finalize.rs b/solana/programs/staking/src/contexts/finalize.rs index 63cd0900..398fc53d 100644 --- a/solana/programs/staking/src/contexts/finalize.rs +++ b/solana/programs/staking/src/contexts/finalize.rs @@ -2,8 +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}; -use anchor_spl::token::Token; +use anchor_spl::token::{Mint, Token, TokenAccount}; use crate::state::global_config::GlobalConfig; #[derive(Accounts)] @@ -14,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, diff --git a/solana/programs/staking/src/contexts/initialize.rs b/solana/programs/staking/src/contexts/initialize.rs index 79081eac..ec89f823 100644 --- a/solana/programs/staking/src/contexts/initialize.rs +++ b/solana/programs/staking/src/contexts/initialize.rs @@ -4,8 +4,7 @@ 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}; -use anchor_spl::token::Token; +use anchor_spl::token::{Mint, Token, TokenAccount}; #[derive(Accounts)] #[instruction(seed: u64)] @@ -13,7 +12,7 @@ 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, @@ -22,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, diff --git a/solana/programs/staking/src/contexts/transfer_vesting.rs b/solana/programs/staking/src/contexts/transfer_vesting.rs index cb1c7eed..dfd833e7 100644 --- a/solana/programs/staking/src/contexts/transfer_vesting.rs +++ b/solana/programs/staking/src/contexts/transfer_vesting.rs @@ -9,29 +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}; -use anchor_spl::token::Token; +use anchor_spl::token::{Mint, Token, TokenAccount}; #[event_cpi] #[derive(Accounts)] pub struct TransferVesting<'info> { #[account(mut)] vester: Signer<'info>, - mint: Box>, + mint: Box>, #[account( mut, associated_token::mint = mint, associated_token::authority = vester_ta.owner, associated_token::token_program = token_program )] - vester_ta: Box>, + vester_ta: Box>, #[account( mut, associated_token::mint = mint, associated_token::authority = new_vester_ta.owner, associated_token::token_program = token_program )] - new_vester_ta: Box>, + new_vester_ta: Box>, #[account( mut, constraint = config.finalized @ VestingError::VestingUnfinalized, diff --git a/solana/programs/staking/src/contexts/withdraw_surplus.rs b/solana/programs/staking/src/contexts/withdraw_surplus.rs index 166d53fb..52d6fc2c 100644 --- a/solana/programs/staking/src/contexts/withdraw_surplus.rs +++ b/solana/programs/staking/src/contexts/withdraw_surplus.rs @@ -3,10 +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, TransferChecked, -}; -use anchor_spl::token::Token; +use anchor_spl::token::{Mint, Token, TokenAccount, transfer_checked, TransferChecked}; use crate::state::global_config::GlobalConfig; #[derive(Accounts)] @@ -22,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,