mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-16 07:26:51 +00:00
move spl cpis to utils
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
#[cfg(feature = "spl")]
|
||||
pub mod spl;
|
||||
|
||||
use solana_program::{
|
||||
account_info::AccountInfo, entrypoint::ProgramResult, program_error::ProgramError,
|
||||
pubkey::Pubkey, rent::Rent, sysvar::Sysvar,
|
||||
|
||||
138
utils/src/spl.rs
Normal file
138
utils/src/spl.rs
Normal file
@@ -0,0 +1,138 @@
|
||||
use solana_program::{account_info::AccountInfo, entrypoint::ProgramResult};
|
||||
|
||||
#[inline(always)]
|
||||
pub fn create_ata<'info>(
|
||||
funder_info: &AccountInfo<'info>,
|
||||
owner_info: &AccountInfo<'info>,
|
||||
token_account_info: &AccountInfo<'info>,
|
||||
mint_info: &AccountInfo<'info>,
|
||||
system_program: &AccountInfo<'info>,
|
||||
token_program: &AccountInfo<'info>,
|
||||
associated_token_program: &AccountInfo<'info>,
|
||||
) -> ProgramResult {
|
||||
solana_program::program::invoke(
|
||||
&spl_associated_token_account::instruction::create_associated_token_account(
|
||||
funder_info.key,
|
||||
owner_info.key,
|
||||
mint_info.key,
|
||||
&spl_token::id(),
|
||||
),
|
||||
&[
|
||||
funder_info.clone(),
|
||||
token_account_info.clone(),
|
||||
owner_info.clone(),
|
||||
mint_info.clone(),
|
||||
system_program.clone(),
|
||||
token_program.clone(),
|
||||
associated_token_program.clone(),
|
||||
],
|
||||
)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn transfer<'info>(
|
||||
authority_info: &AccountInfo<'info>,
|
||||
from_info: &AccountInfo<'info>,
|
||||
to_info: &AccountInfo<'info>,
|
||||
token_program: &AccountInfo<'info>,
|
||||
amount: u64,
|
||||
) -> ProgramResult {
|
||||
solana_program::program::invoke(
|
||||
&spl_token::instruction::transfer(
|
||||
&spl_token::id(),
|
||||
from_info.key,
|
||||
to_info.key,
|
||||
authority_info.key,
|
||||
&[authority_info.key],
|
||||
amount,
|
||||
)?,
|
||||
&[
|
||||
token_program.clone(),
|
||||
from_info.clone(),
|
||||
to_info.clone(),
|
||||
authority_info.clone(),
|
||||
],
|
||||
)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn transfer_signed<'info>(
|
||||
authority_info: &AccountInfo<'info>,
|
||||
from_info: &AccountInfo<'info>,
|
||||
to_info: &AccountInfo<'info>,
|
||||
token_program: &AccountInfo<'info>,
|
||||
amount: u64,
|
||||
signer_seeds: &[&[&[u8]]],
|
||||
) -> ProgramResult {
|
||||
solana_program::program::invoke_signed(
|
||||
&spl_token::instruction::transfer(
|
||||
&spl_token::id(),
|
||||
from_info.key,
|
||||
to_info.key,
|
||||
authority_info.key,
|
||||
&[authority_info.key],
|
||||
amount,
|
||||
)?,
|
||||
&[
|
||||
token_program.clone(),
|
||||
from_info.clone(),
|
||||
to_info.clone(),
|
||||
authority_info.clone(),
|
||||
],
|
||||
signer_seeds,
|
||||
)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn mint_to_signed<'info>(
|
||||
mint_info: &AccountInfo<'info>,
|
||||
to_info: &AccountInfo<'info>,
|
||||
authority_info: &AccountInfo<'info>,
|
||||
token_program: &AccountInfo<'info>,
|
||||
amount: u64,
|
||||
signer_seeds: &[&[&[u8]]],
|
||||
) -> ProgramResult {
|
||||
solana_program::program::invoke_signed(
|
||||
&spl_token::instruction::mint_to(
|
||||
&spl_token::id(),
|
||||
mint_info.key,
|
||||
to_info.key,
|
||||
authority_info.key,
|
||||
&[authority_info.key],
|
||||
amount,
|
||||
)?,
|
||||
&[
|
||||
token_program.clone(),
|
||||
mint_info.clone(),
|
||||
to_info.clone(),
|
||||
authority_info.clone(),
|
||||
],
|
||||
signer_seeds,
|
||||
)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn burn<'info>(
|
||||
token_account_info: &AccountInfo<'info>,
|
||||
mint_info: &AccountInfo<'info>,
|
||||
authority_info: &AccountInfo<'info>,
|
||||
token_program: &AccountInfo<'info>,
|
||||
amount: u64,
|
||||
) -> ProgramResult {
|
||||
solana_program::program::invoke(
|
||||
&spl_token::instruction::burn(
|
||||
&spl_token::id(),
|
||||
token_account_info.key,
|
||||
mint_info.key,
|
||||
authority_info.key,
|
||||
&[authority_info.key],
|
||||
amount,
|
||||
)?,
|
||||
&[
|
||||
token_program.clone(),
|
||||
token_account_info.clone(),
|
||||
mint_info.clone(),
|
||||
authority_info.clone(),
|
||||
],
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user