diff --git a/CHANGELOG.md b/CHANGELOG.md index a3fcebbe04..f82baefb40 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ incremented for features. ### Features * lang: Add new `AccountSysvarMismatch` error code and test cases for sysvars ([#1535](https://github.com/project-serum/anchor/pull/1535)). +* spl: Add support for revoke instruction ([#1493](https://github.com/project-serum/anchor/pull/1493)). ### Fixes diff --git a/spl/src/token.rs b/spl/src/token.rs index 2ed7558a13..669a195b65 100644 --- a/spl/src/token.rs +++ b/spl/src/token.rs @@ -104,6 +104,21 @@ pub fn approve<'a, 'b, 'c, 'info>( .map_err(Into::into) } +pub fn revoke<'a, 'b, 'c, 'info>(ctx: CpiContext<'a, 'b, 'c, 'info, Revoke<'info>>) -> Result<()> { + let ix = spl_token::instruction::revoke( + &spl_token::ID, + ctx.accounts.source.key, + ctx.accounts.authority.key, + &[], + )?; + solana_program::program::invoke_signed( + &ix, + &[ctx.accounts.source.clone(), ctx.accounts.authority.clone()], + ctx.signer_seeds, + ) + .map_err(Into::into) +} + pub fn initialize_account<'a, 'b, 'c, 'info>( ctx: CpiContext<'a, 'b, 'c, 'info, InitializeAccount<'info>>, ) -> Result<()> { @@ -270,6 +285,12 @@ pub struct Approve<'info> { pub authority: AccountInfo<'info>, } +#[derive(Accounts)] +pub struct Revoke<'info> { + pub source: AccountInfo<'info>, + pub authority: AccountInfo<'info>, +} + #[derive(Accounts)] pub struct InitializeAccount<'info> { pub account: AccountInfo<'info>,