Skip to content

Commit

Permalink
address PR feedback; regen JS API
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelvanderwaal committed May 24, 2023
1 parent 0da9c73 commit e0437c7
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 31 deletions.
12 changes: 6 additions & 6 deletions token-metadata/js/idl/mpl_token_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -1270,7 +1270,7 @@
},
{
"name": "metadata",
"isMut": false,
"isMut": true,
"isSigner": false,
"desc": "Metadata account"
},
Expand Down Expand Up @@ -1360,7 +1360,7 @@
},
{
"name": "metadata",
"isMut": false,
"isMut": true,
"isSigner": false,
"desc": "Metadata account"
},
Expand Down Expand Up @@ -1484,7 +1484,7 @@
},
{
"name": "metadata",
"isMut": false,
"isMut": true,
"isSigner": false,
"desc": "Collection Metadata account"
},
Expand Down Expand Up @@ -1543,7 +1543,7 @@
},
{
"name": "metadata",
"isMut": false,
"isMut": true,
"isSigner": false,
"desc": "Metadata account"
},
Expand Down Expand Up @@ -1660,7 +1660,7 @@
},
{
"name": "edition",
"isMut": false,
"isMut": true,
"isSigner": false,
"desc": "Edition"
},
Expand Down Expand Up @@ -1712,7 +1712,7 @@
},
{
"name": "edition",
"isMut": false,
"isMut": true,
"isSigner": false,
"desc": "Edition"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const ApproveCollectionAuthorityStruct = new beet.BeetArgsStruct<{
* @property [] newCollectionAuthority A Collection Authority
* @property [_writable_, **signer**] updateAuthority Update Authority of Collection NFT
* @property [_writable_, **signer**] payer Payer
* @property [] metadata Collection Metadata account
* @property [_writable_] metadata Collection Metadata account
* @property [] mint Mint of Collection Metadata
* @property [] sysvarInstructions Instructions sysvar account
* @category Instructions
Expand Down Expand Up @@ -87,7 +87,7 @@ export function createApproveCollectionAuthorityInstruction(
},
{
pubkey: accounts.metadata,
isWritable: false,
isWritable: true,
isSigner: false,
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const ApproveUseAuthorityStruct = new beet.BeetArgsStruct<
* @property [_writable_, **signer**] payer Payer
* @property [] user A Use Authority
* @property [_writable_] ownerTokenAccount Owned Token Account Of Mint
* @property [] metadata Metadata account
* @property [_writable_] metadata Metadata account
* @property [] mint Mint of Metadata
* @property [] burner Program As Signer (Burner)
* @property [] sysvarInstructions Instructions sysvar account
Expand Down Expand Up @@ -122,7 +122,7 @@ export function createApproveUseAuthorityInstruction(
},
{
pubkey: accounts.metadata,
isWritable: false,
isWritable: true,
isSigner: false,
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const FreezeDelegatedAccountStruct = new beet.BeetArgsStruct<{
*
* @property [_writable_, **signer**] delegate Delegate
* @property [_writable_] tokenAccount Token account to freeze
* @property [] edition Edition
* @property [_writable_] edition Edition
* @property [] mint Token mint
* @property [] sysvarInstructions Instructions sysvar account
* @category Instructions
Expand Down Expand Up @@ -69,7 +69,7 @@ export function createFreezeDelegatedAccountInstruction(
},
{
pubkey: accounts.edition,
isWritable: false,
isWritable: true,
isSigner: false,
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const RevokeCollectionAuthorityStruct = new beet.BeetArgsStruct<{
* @property [_writable_] collectionAuthorityRecord Collection Authority Record PDA
* @property [_writable_] delegateAuthority Delegated Collection Authority
* @property [_writable_, **signer**] revokeAuthority Update Authority, or Delegated Authority, of Collection NFT
* @property [] metadata Metadata account
* @property [_writable_] metadata Metadata account
* @property [] mint Mint of Metadata
* @property [] sysvarInstructions Instructions sysvar account
* @category Instructions
Expand Down Expand Up @@ -74,7 +74,7 @@ export function createRevokeCollectionAuthorityInstruction(
},
{
pubkey: accounts.metadata,
isWritable: false,
isWritable: true,
isSigner: false,
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const RevokeUseAuthorityStruct = new beet.BeetArgsStruct<{
* @property [] user A Use Authority
* @property [_writable_] ownerTokenAccount Owned Token Account Of Mint
* @property [] mint Mint of Metadata
* @property [] metadata Metadata account
* @property [_writable_] metadata Metadata account
* @property [] sysvarInstructions Instructions sysvar account
* @category Instructions
* @category RevokeUseAuthority
Expand Down Expand Up @@ -94,7 +94,7 @@ export function createRevokeUseAuthorityInstruction(
},
{
pubkey: accounts.metadata,
isWritable: false,
isWritable: true,
isSigner: false,
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const ThawDelegatedAccountStruct = new beet.BeetArgsStruct<{
*
* @property [_writable_, **signer**] delegate Delegate
* @property [_writable_] tokenAccount Token account to thaw
* @property [] edition Edition
* @property [_writable_] edition Edition
* @property [] mint Token mint
* @property [] sysvarInstructions Instructions sysvar account
* @category Instructions
Expand Down Expand Up @@ -69,7 +69,7 @@ export function createThawDelegatedAccountInstruction(
},
{
pubkey: accounts.edition,
isWritable: false,
isWritable: true,
isSigner: false,
},
{
Expand Down
12 changes: 6 additions & 6 deletions token-metadata/program/src/instruction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ pub enum MetadataInstruction {
#[account(2, signer, writable, name="payer", desc="Payer")]
#[account(3, name="user", desc="A Use Authority")]
#[account(4, writable, name="owner_token_account", desc="Owned Token Account Of Mint")]
#[account(5, name="metadata", desc="Metadata account")]
#[account(5, writable, name="metadata", desc="Metadata account")]
#[account(6, name="mint", desc="Mint of Metadata")]
#[account(7, name="burner", desc="Program As Signer (Burner)")]
#[account(8, name="token_program", desc="Token program")]
Expand All @@ -324,7 +324,7 @@ pub enum MetadataInstruction {
#[account(2, name="user", desc="A Use Authority")]
#[account(3, writable, name="owner_token_account", desc="Owned Token Account Of Mint")]
#[account(4, name="mint", desc="Mint of Metadata")]
#[account(5, name="metadata", desc="Metadata account")]
#[account(5, writable, name="metadata", desc="Metadata account")]
#[account(6, name="token_program", desc="Token program")]
#[account(7, name="system_program", desc="System program")]
#[account(8, optional, name="rent", desc="Rent info")]
Expand All @@ -347,7 +347,7 @@ pub enum MetadataInstruction {
#[account(1, name="new_collection_authority", desc="A Collection Authority")]
#[account(2, signer, writable, name="update_authority", desc="Update Authority of Collection NFT")]
#[account(3, signer, writable, name="payer", desc="Payer")]
#[account(4, name="metadata", desc="Collection Metadata account")]
#[account(4, writable, name="metadata", desc="Collection Metadata account")]
#[account(5, name="mint", desc="Mint of Collection Metadata")]
#[account(6, name="system_program", desc="System program")]
#[account(7, optional, name="rent", desc="Rent info")]
Expand All @@ -358,7 +358,7 @@ pub enum MetadataInstruction {
#[account(0, writable, name="collection_authority_record", desc="Collection Authority Record PDA")]
#[account(1, writable, name="delegate_authority", desc="Delegated Collection Authority")]
#[account(2, signer, writable, name="revoke_authority", desc="Update Authority, or Delegated Authority, of Collection NFT")]
#[account(3, name="metadata", desc="Metadata account")]
#[account(3, writable, name="metadata", desc="Metadata account")]
#[account(4, name="mint", desc="Mint of Metadata")]
#[account(5, name="system_program", desc="System program")]
#[account(6, name="sysvar_instructions", desc="Instructions sysvar account")]
Expand All @@ -381,7 +381,7 @@ pub enum MetadataInstruction {
/// Allow freezing of an NFT if this user is the delegate of the NFT.
#[account(0, signer, writable, name="delegate", desc="Delegate")]
#[account(1, writable, name="token_account", desc="Token account to freeze")]
#[account(2, name="edition", desc="Edition")]
#[account(2, writable, name="edition", desc="Edition")]
#[account(3, name="mint", desc="Token mint")]
#[account(4, name="token_program", desc="Token Program")]
#[account(5, name="system_program", desc="System program")]
Expand All @@ -391,7 +391,7 @@ pub enum MetadataInstruction {
/// Allow thawing of an NFT if this user is the delegate of the NFT.
#[account(0, signer, writable, name="delegate", desc="Delegate")]
#[account(1, writable, name="token_account", desc="Token account to thaw")]
#[account(2, name="edition", desc="Edition")]
#[account(2, writable, name="edition", desc="Edition")]
#[account(3, name="mint", desc="Token mint")]
#[account(4, name="token_program", desc="Token Program")]
#[account(5, name="system_program", desc="System program")]
Expand Down
18 changes: 12 additions & 6 deletions token-metadata/program/src/processor/metadata/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,20 @@ fn create_v1(program_id: &Pubkey, ctx: Context<Create>, args: CreateArgs) -> Pro
return Err(MetadataError::InvalidTokenStandard.into());
}

let ix_type = IxType::CreateMetadata;
let mut levy_args = LevyArgs {
ix_type,
payer_account_info: ctx.accounts.payer_info,
token_metadata_pda_info: ctx.accounts.metadata_info,
include_rent: false,
};

// if the account does not exist, we will allocate a new mint

if ctx.accounts.mint_info.data_is_empty() {
// New account so need fee collection to include rent amount.
levy_args.include_rent = true;

// mint account must be a signer in the transaction
if !ctx.accounts.mint_info.is_signer {
return Err(MetadataError::MintIsNotSigner.into());
Expand Down Expand Up @@ -124,12 +135,7 @@ fn create_v1(program_id: &Pubkey, ctx: Context<Create>, args: CreateArgs) -> Pro
}
}

let ix_type = IxType::CreateMetadata;
levy(LevyArgs {
ix_type,
payer_account_info: ctx.accounts.payer_info,
token_metadata_pda_info: ctx.accounts.metadata_info,
})?;
levy(levy_args)?;

// creates the metadata account

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub fn process_create_metadata_accounts_v3<'a>(
ix_type,
payer_account_info,
token_metadata_pda_info: metadata_account_info,
include_rent: true,
})?;

process_create_metadata_accounts_logic(
Expand Down
9 changes: 8 additions & 1 deletion token-metadata/program/src/utils/fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,21 @@ pub(crate) struct LevyArgs<'a> {
pub ix_type: IxType,
pub payer_account_info: &'a AccountInfo<'a>,
pub token_metadata_pda_info: &'a AccountInfo<'a>,
pub include_rent: bool,
}

pub(crate) fn levy(args: LevyArgs) -> ProgramResult {
// Fund metadata account with rent + Metaplex fee.
let rent = Rent::get()?;

let fee = match args.ix_type {
IxType::CreateMetadata => CREATE_FEE + rent.minimum_balance(Metadata::size()),
IxType::CreateMetadata => {
if args.include_rent {
CREATE_FEE + rent.minimum_balance(Metadata::size())
} else {
CREATE_FEE
}
}
IxType::UpdateMetadata => UPDATE_FEE,
};

Expand Down

0 comments on commit e0437c7

Please sign in to comment.