Przeglądaj źródła

add freeze and thaw delegated account instructions (#2164)

surfertas 3 lat temu
rodzic
commit
0c70d183ef
2 zmienionych plików z 61 dodań i 0 usunięć
  1. 1 0
      CHANGELOG.md
  2. 60 0
      spl/src/metadata.rs

+ 1 - 0
CHANGELOG.md

@@ -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
 

+ 60 - 0
spl/src/metadata.rs

@@ -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>,
@@ -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);