123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- use anchor_lang::{Accounts, CpiContext};
- use solana_program::account_info::AccountInfo;
- use solana_program::entrypoint::ProgramResult;
- pub fn transfer<'a, 'b, 'c, 'info>(
- ctx: CpiContext<'a, 'b, 'c, 'info, Transfer<'info>>,
- amount: u64,
- ) -> ProgramResult {
- let ix = spl_token::instruction::transfer(
- &spl_token::ID,
- ctx.accounts.from.key,
- ctx.accounts.to.key,
- ctx.accounts.authority.key,
- &[],
- amount,
- )?;
- solana_program::program::invoke_signed(
- &ix,
- &[
- ctx.accounts.from.clone(),
- ctx.accounts.to.clone(),
- ctx.accounts.authority.clone(),
- ctx.program.clone(),
- ],
- ctx.signer_seeds,
- )
- }
- pub fn mint_to<'a, 'b, 'c, 'info>(
- ctx: CpiContext<'a, 'b, 'c, 'info, MintTo<'info>>,
- amount: u64,
- ) -> ProgramResult {
- let ix = spl_token::instruction::mint_to(
- &spl_token::ID,
- ctx.accounts.mint.key,
- ctx.accounts.to.key,
- ctx.accounts.authority.key,
- &[],
- amount,
- )?;
- solana_program::program::invoke_signed(
- &ix,
- &[
- ctx.accounts.mint.clone(),
- ctx.accounts.to.clone(),
- ctx.accounts.authority.clone(),
- ctx.program.clone(),
- ],
- ctx.signer_seeds,
- )
- }
- pub fn burn<'a, 'b, 'c, 'info>(
- ctx: CpiContext<'a, 'b, 'c, 'info, Burn<'info>>,
- amount: u64,
- ) -> ProgramResult {
- let ix = spl_token::instruction::burn(
- &spl_token::ID,
- ctx.accounts.to.key,
- ctx.accounts.mint.key,
- ctx.accounts.authority.key,
- &[],
- amount,
- )?;
- solana_program::program::invoke_signed(
- &ix,
- &[
- ctx.accounts.to.clone(),
- ctx.accounts.mint.clone(),
- ctx.accounts.authority.clone(),
- ctx.program.clone(),
- ],
- ctx.signer_seeds,
- )
- }
- #[derive(Accounts)]
- pub struct Transfer<'info> {
- pub from: AccountInfo<'info>,
- pub to: AccountInfo<'info>,
- pub authority: AccountInfo<'info>,
- }
- #[derive(Accounts)]
- pub struct MintTo<'info> {
- pub mint: AccountInfo<'info>,
- pub to: AccountInfo<'info>,
- pub authority: AccountInfo<'info>,
- }
- #[derive(Accounts)]
- pub struct Burn<'info> {
- pub mint: AccountInfo<'info>,
- pub to: AccountInfo<'info>,
- pub authority: AccountInfo<'info>,
- }
|