Skip to content

Commit

Permalink
add freeze and thaw delegated account instructions (coral-xyz#2164)
Browse files Browse the repository at this point in the history
  • Loading branch information
surfertas authored and henrye committed Dec 6, 2022
1 parent 3d030ce commit 5de084f
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ The minor version will be incremented upon a breaking change and the patch versi
* lang: Add parsing for consts from impl blocks for IDL PDA seeds generation ([#2128](https://github.com/coral-xyz/anchor/pull/2014))
* lang: Account closing reassigns to system program and reallocates ([#2169](https://github.com/coral-xyz/anchor/pull/2169)).
* ts: Add coders for SPL programs ([#2143](https://github.com/coral-xyz/anchor/pull/2143)).
* spl: Add `freeze_delegated_account` and `thaw_delegated_account` wrappers ([#2164](https://github.com/coral-xyz/anchor/pull/2164))

### Fixes

Expand Down
60 changes: 60 additions & 0 deletions spl/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,46 @@ pub fn set_collection_size<'info>(
Ok(())
}

pub fn freeze_delegated_account<'info>(
ctx: CpiContext<'_, '_, '_, 'info, FreezeDelegatedAccount<'info>>,
) -> Result<()> {
let ix = mpl_token_metadata::instruction::freeze_delegated_account(
ID,
*ctx.accounts.delegate.key,
*ctx.accounts.token_account.key,
*ctx.accounts.edition.key,
*ctx.accounts.mint.key,
);

solana_program::program::invoke_signed(
&ix,
&ToAccountInfos::to_account_infos(&ctx),
ctx.signer_seeds,
)?;

Ok(())
}

pub fn thaw_delegated_account<'info>(
ctx: CpiContext<'_, '_, '_, 'info, ThawDelegatedAccount<'info>>,
) -> Result<()> {
let ix = mpl_token_metadata::instruction::thaw_delegated_account(
ID,
*ctx.accounts.delegate.key,
*ctx.accounts.token_account.key,
*ctx.accounts.edition.key,
*ctx.accounts.mint.key,
);

solana_program::program::invoke_signed(
&ix,
&ToAccountInfos::to_account_infos(&ctx),
ctx.signer_seeds,
)?;

Ok(())
}

#[derive(Accounts)]
pub struct CreateMetadataAccountsV2<'info> {
pub metadata: AccountInfo<'info>,
Expand Down Expand Up @@ -268,6 +308,26 @@ pub struct SetCollectionSize<'info> {
pub system_program: AccountInfo<'info>,
}

#[derive(Accounts)]
pub struct FreezeDelegatedAccount<'info> {
pub metadata: AccountInfo<'info>,
pub delegate: AccountInfo<'info>,
pub token_account: AccountInfo<'info>,
pub edition: AccountInfo<'info>,
pub mint: AccountInfo<'info>,
pub token_program: AccountInfo<'info>,
}

#[derive(Accounts)]
pub struct ThawDelegatedAccount<'info> {
pub metadata: AccountInfo<'info>,
pub delegate: AccountInfo<'info>,
pub token_account: AccountInfo<'info>,
pub edition: AccountInfo<'info>,
pub mint: AccountInfo<'info>,
pub token_program: AccountInfo<'info>,
}

#[derive(Clone, Debug, PartialEq)]
pub struct MetadataAccount(mpl_token_metadata::state::Metadata);

Expand Down

0 comments on commit 5de084f

Please sign in to comment.