Skip to content

Commit

Permalink
spl: add create metadata v3 and set collection size ix (coral-xyz#2119)
Browse files Browse the repository at this point in the history
* add create metadata v3 and set collection size ix

* update changelog
  • Loading branch information
callensm authored and yf-castel committed Aug 15, 2022
1 parent 0863308 commit 857de83
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -13,6 +13,7 @@ The minor version will be incremented upon a breaking change and the patch versi
### Features

* client: Add `transaction` functions to RequestBuilder ([#1958](https://github.com/coral-xyz/anchor/pull/1958)).
* spl: Add `create_metadata_accounts_v3` and `set_collection_size` wrappers ([#2119](https://github.com/coral-xyz/anchor/pull/2119))

## [0.25.0] - 2022-07-05

Expand Down
16 changes: 8 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion spl/Cargo.toml
Expand Up @@ -24,4 +24,4 @@ serum_dex = { git = "https://github.com/project-serum/serum-dex", rev = "1be91f2
solana-program = "~1.10.29"
spl-token = { version = "~3.3.0", features = ["no-entrypoint"], optional = true }
spl-associated-token-account = { version = "~1.0.5", features = ["no-entrypoint"], optional = true }
mpl-token-metadata = { version = "1.2.7", optional = true, features = ["no-entrypoint"] }
mpl-token-metadata = { version = "1.3.4", optional = true, features = ["no-entrypoint"] }
85 changes: 84 additions & 1 deletion spl/src/metadata.rs
@@ -1,6 +1,6 @@
use anchor_lang::context::CpiContext;
use anchor_lang::{Accounts, Result, ToAccountInfos};
use mpl_token_metadata::state::DataV2;
use mpl_token_metadata::state::{CollectionDetails, DataV2};
use mpl_token_metadata::ID;
use solana_program::account_info::AccountInfo;
use solana_program::pubkey::Pubkey;
Expand Down Expand Up @@ -54,6 +54,48 @@ pub fn create_metadata_accounts_v2<'info>(
Ok(())
}

pub fn create_metadata_accounts_v3<'info>(
ctx: CpiContext<'_, '_, '_, 'info, CreateMetadataAccountsV3<'info>>,
data: DataV2,
is_mutable: bool,
update_authority_is_signer: bool,
details: Option<CollectionDetails>,
) -> Result<()> {
let DataV2 {
name,
symbol,
uri,
creators,
seller_fee_basis_points,
collection,
uses,
} = data;
let ix = mpl_token_metadata::instruction::create_metadata_accounts_v3(
ID,
*ctx.accounts.metadata.key,
*ctx.accounts.mint.key,
*ctx.accounts.mint_authority.key,
*ctx.accounts.payer.key,
*ctx.accounts.update_authority.key,
name,
symbol,
uri,
creators,
seller_fee_basis_points,
update_authority_is_signer,
is_mutable,
collection,
uses,
details,
);
solana_program::program::invoke_signed(
&ix,
&ToAccountInfos::to_account_infos(&ctx),
ctx.signer_seeds,
)?;
Ok(())
}

pub fn update_metadata_accounts_v2<'info>(
ctx: CpiContext<'_, '_, '_, 'info, UpdateMetadataAccountsV2<'info>>,
new_update_authority: Option<Pubkey>,
Expand Down Expand Up @@ -128,6 +170,28 @@ pub fn mint_new_edition_from_master_edition_via_token<'info>(
Ok(())
}

pub fn set_collection_size<'info>(
ctx: CpiContext<'_, '_, '_, 'info, SetCollectionSize<'info>>,
collection_authority_record: Option<Pubkey>,
size: u64,
) -> Result<()> {
let ix = mpl_token_metadata::instruction::set_collection_size(
ID,
*ctx.accounts.metadata.key,
*ctx.accounts.update_authority.key,
*ctx.accounts.mint.key,
collection_authority_record,
size,
);

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 All @@ -139,6 +203,17 @@ pub struct CreateMetadataAccountsV2<'info> {
pub rent: AccountInfo<'info>,
}

#[derive(Accounts)]
pub struct CreateMetadataAccountsV3<'info> {
pub metadata: AccountInfo<'info>,
pub mint: AccountInfo<'info>,
pub mint_authority: AccountInfo<'info>,
pub payer: AccountInfo<'info>,
pub update_authority: AccountInfo<'info>,
pub system_program: AccountInfo<'info>,
pub rent: AccountInfo<'info>,
}

#[derive(Accounts)]
pub struct UpdateMetadataAccountsV2<'info> {
pub metadata: AccountInfo<'info>,
Expand Down Expand Up @@ -183,3 +258,11 @@ pub struct MintNewEditionFromMasterEditionViaToken<'info> {
//
pub metadata_mint: AccountInfo<'info>,
}

#[derive(Accounts)]
pub struct SetCollectionSize<'info> {
pub metadata: AccountInfo<'info>,
pub mint: AccountInfo<'info>,
pub update_authority: AccountInfo<'info>,
pub system_program: AccountInfo<'info>,
}

0 comments on commit 857de83

Please sign in to comment.