Skip to content

Instantly share code, notes, and snippets.

@vit0rr
Last active December 9, 2021 14:41
Show Gist options
  • Save vit0rr/a274c01d06575ffdc2a8d24f258f0b6f to your computer and use it in GitHub Desktop.
Save vit0rr/a274c01d06575ffdc2a8d24f258f0b6f to your computer and use it in GitHub Desktop.
//! This example demonstrates the use of the `anchor_spl::token` CPI client to freeze account.
use anchor_lang::prelude::*;
use anchor_spl::token::{self, SetAuthority};
declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS");
#[program]
mod token_proxy {
use super::*;
pub fn proxy_set_authority(
ctx: Context<ProxySetAuthority>,
authority_type: AuthorityType,
new_authority: Option<Pubkey>,
) -> ProgramResult {
token::set_authority(ctx.accounts.into(), authority_type.into(), new_authority)
}
}
#[derive(AnchorSerialize, AnchorDeserialize)]
pub enum AuthorityType {
/// Authority to mint new tokens
MintTokens,
/// Authority to freeze any account associated with the Mint
FreezeAccount,
/// Owner of a given token account
AccountOwner,
/// Authority to close a token account
CloseAccount,
}
impl From<AuthorityType> for spl_token::instruction::AuthorityType {
fn from(authority_ty: AuthorityType) -> spl_token::instruction::AuthorityType {
match authority_ty {
AuthorityType::FreezeAccount => spl_token::instruction::AuthorityType::FreezeAccount
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment