|
@@ -1,7 +1,7 @@
|
|
|
//! This example demonstrates the use of the `anchor_spl::token` CPI client.
|
|
|
|
|
|
use anchor_lang::prelude::*;
|
|
|
-use anchor_spl::token::{self, Burn, MintTo, Transfer};
|
|
|
+use anchor_spl::token::{self, Burn, MintTo, SetAuthority, Transfer};
|
|
|
|
|
|
#[program]
|
|
|
mod token_proxy {
|
|
@@ -18,6 +18,26 @@ mod token_proxy {
|
|
|
pub fn proxy_burn(ctx: Context<ProxyBurn>, amount: u64) -> ProgramResult {
|
|
|
token::burn(ctx.accounts.into(), amount)
|
|
|
}
|
|
|
+
|
|
|
+ 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,
|
|
|
}
|
|
|
|
|
|
#[derive(Accounts)]
|
|
@@ -53,6 +73,15 @@ pub struct ProxyBurn<'info> {
|
|
|
pub token_program: AccountInfo<'info>,
|
|
|
}
|
|
|
|
|
|
+#[derive(Accounts)]
|
|
|
+pub struct ProxySetAuthority<'info> {
|
|
|
+ #[account(signer)]
|
|
|
+ pub current_authority: AccountInfo<'info>,
|
|
|
+ #[account(mut)]
|
|
|
+ pub account_or_mint: AccountInfo<'info>,
|
|
|
+ pub token_program: AccountInfo<'info>,
|
|
|
+}
|
|
|
+
|
|
|
impl<'a, 'b, 'c, 'info> From<&mut ProxyTransfer<'info>>
|
|
|
for CpiContext<'a, 'b, 'c, 'info, Transfer<'info>>
|
|
|
{
|
|
@@ -92,3 +121,29 @@ impl<'a, 'b, 'c, 'info> From<&mut ProxyBurn<'info>> for CpiContext<'a, 'b, 'c, '
|
|
|
CpiContext::new(cpi_program, cpi_accounts)
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+impl<'a, 'b, 'c, 'info> From<&mut ProxySetAuthority<'info>>
|
|
|
+ for CpiContext<'a, 'b, 'c, 'info, SetAuthority<'info>>
|
|
|
+{
|
|
|
+ fn from(
|
|
|
+ accounts: &mut ProxySetAuthority<'info>,
|
|
|
+ ) -> CpiContext<'a, 'b, 'c, 'info, SetAuthority<'info>> {
|
|
|
+ let cpi_accounts = SetAuthority {
|
|
|
+ account_or_mint: accounts.account_or_mint.clone(),
|
|
|
+ current_authority: accounts.current_authority.clone(),
|
|
|
+ }; // TODO: Support multisig signers
|
|
|
+ let cpi_program = accounts.token_program.clone();
|
|
|
+ CpiContext::new(cpi_program, cpi_accounts)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+impl From<AuthorityType> for spl_token::instruction::AuthorityType {
|
|
|
+ fn from(authority_ty: AuthorityType) -> spl_token::instruction::AuthorityType {
|
|
|
+ match authority_ty {
|
|
|
+ AuthorityType::MintTokens => spl_token::instruction::AuthorityType::MintTokens,
|
|
|
+ AuthorityType::FreezeAccount => spl_token::instruction::AuthorityType::FreezeAccount,
|
|
|
+ AuthorityType::AccountOwner => spl_token::instruction::AuthorityType::AccountOwner,
|
|
|
+ AuthorityType::CloseAccount => spl_token::instruction::AuthorityType::CloseAccount,
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|