Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add freeze and thaw delegated account instructions #2164

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -17,6 +17,7 @@ The minor version will be incremented upon a breaking change and the patch versi
* spl: Add `MetadataAccount` account deserialization. ([#2014](https://github.com/coral-xyz/anchor/pull/2014)).
* lang: Add parsing for consts from impl blocks for IDL PDA seeds generation ([#2128](https://github.com/coral-xyz/anchor/pull/2014))
* 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
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