Skip to content

Add Update Authority method #103

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

Merged
merged 8 commits into from
Dec 13, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion programs/libreplex_editions/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,20 @@ pub enum EditionsError {
InvalidMetadata,

#[msg("Creator fee too high")]
CreatorFeeTooHigh
CreatorFeeTooHigh,

#[msg("Invalid creator")]
InvalidCreator,

#[msg("Update authority already changed")]
UpdateAuthorityAlreadyChanged,

#[msg("Metadata not found")]
MetadataNotFound,

#[msg("Mint is not finished")]
MintNotComplete,

#[msg("Invalid signer")]
InvalidSigner,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
use spl_token_metadata_interface::instruction::update_authority;
use anchor_lang::{prelude::*, solana_program::program::invoke_signed};
use anchor_spl::token_2022::{self};
use spl_pod::optional_keys::OptionalNonZeroPubkey;

use crate::{EditionsDeployment, errors::EditionsError};

/// TODO: Add hashlist marker or hashlist to verify mint?
#[derive(Accounts)]
pub struct ClaimUpdateAuthorityCtx<'info> {

#[account(mut,
seeds = ["editions_deployment".as_ref(), editions_deployment.symbol.as_ref()], bump)]
pub editions_deployment: Account<'info, EditionsDeployment>,

#[account(mut)]
pub payer: Signer<'info>,

#[account(mut)]
pub mint: AccountInfo<'info>,

/* BOILERPLATE PROGRAM ACCOUNTS */
/// CHECK: Checked in constraint
#[account(
constraint = token_program.key() == token_2022::ID
)]
pub token_program: UncheckedAccount<'info>,

#[account()]
pub system_program: Program<'info, System>,

}

pub fn claim_update_authority<'info>(ctx: Context<'_, '_, '_, 'info, ClaimUpdateAuthorityCtx<'info>>) -> Result<()> {
let mint = &ctx.accounts.mint;
let token_program = &ctx.accounts.token_program;
let editions_deployment = &ctx.accounts.editions_deployment;
let payer = &ctx.accounts.payer;

require!(editions_deployment.max_number_of_tokens == editions_deployment.number_of_tokens_issued, EditionsError::MintNotComplete);
require!(editions_deployment.creator.key() == payer.key(), EditionsError::InvalidCreator);
require!(payer.is_signer, EditionsError::InvalidSigner);

let deployment_seeds: &[&[u8]] = &[
"editions_deployment".as_bytes(),
editions_deployment.symbol.as_ref(),
&[ctx.bumps.editions_deployment],
];

let account_infos = [
payer.to_account_info(),
editions_deployment.to_account_info(),
mint.to_account_info(),
token_program.to_account_info(),
];

let payer = OptionalNonZeroPubkey::try_from(Some(payer.to_account_info().key()))?;

let update_authority_ix = update_authority(
&spl_token_2022::ID,
&mint.key(),
&editions_deployment.key(),
payer
);

invoke_signed(&update_authority_ix, &account_infos, &[deployment_seeds])?;

Ok(())
}
3 changes: 3 additions & 0 deletions programs/libreplex_editions/src/instructions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ pub use initialise::*;
pub mod mint;
pub use mint::*;

pub mod claim_update_authority;
pub use claim_update_authority::*;

4 changes: 4 additions & 0 deletions programs/libreplex_editions/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,9 @@ pub mod libreplex_editions {
instructions::mint(ctx)
}

pub fn claim_update_authority<'info>(ctx: Context<'_, '_, '_, 'info, ClaimUpdateAuthorityCtx<'info>>) -> Result<()> {
instructions::claim_update_authority(ctx)
}


}
112 changes: 112 additions & 0 deletions target/types/libreplex_editions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,37 @@ export type LibreplexEditions = {
}
],
"args": []
},
{
"name": "claimUpdateAuthority",
"accounts": [
{
"name": "editionsDeployment",
"isMut": true,
"isSigner": false
},
{
"name": "payer",
"isMut": true,
"isSigner": true
},
{
"name": "mint",
"isMut": true,
"isSigner": false
},
{
"name": "tokenProgram",
"isMut": false,
"isSigner": false
},
{
"name": "systemProgram",
"isMut": false,
"isSigner": false
}
],
"args": []
}
],
"accounts": [
Expand Down Expand Up @@ -334,6 +365,31 @@ export type LibreplexEditions = {
"code": 6009,
"name": "CreatorFeeTooHigh",
"msg": "Creator fee too high"
},
{
"code": 6010,
"name": "InvalidCreator",
"msg": "Invalid creator"
},
{
"code": 6011,
"name": "UpdateAuthorityAlreadyChanged",
"msg": "Update authority already changed"
},
{
"code": 6012,
"name": "MetadataNotFound",
"msg": "Metadata not found"
},
{
"code": 6013,
"name": "MintNotComplete",
"msg": "Mint is not finished"
},
{
"code": 6014,
"name": "InvalidSigner",
"msg": "Invalid signer"
}
]
};
Expand Down Expand Up @@ -475,6 +531,37 @@ export const IDL: LibreplexEditions = {
}
],
"args": []
},
{
"name": "claimUpdateAuthority",
"accounts": [
{
"name": "editionsDeployment",
"isMut": true,
"isSigner": false
},
{
"name": "payer",
"isMut": true,
"isSigner": true
},
{
"name": "mint",
"isMut": true,
"isSigner": false
},
{
"name": "tokenProgram",
"isMut": false,
"isSigner": false
},
{
"name": "systemProgram",
"isMut": false,
"isSigner": false
}
],
"args": []
}
],
"accounts": [
Expand Down Expand Up @@ -674,6 +761,31 @@ export const IDL: LibreplexEditions = {
"code": 6009,
"name": "CreatorFeeTooHigh",
"msg": "Creator fee too high"
},
{
"code": 6010,
"name": "InvalidCreator",
"msg": "Invalid creator"
},
{
"code": 6011,
"name": "UpdateAuthorityAlreadyChanged",
"msg": "Update authority already changed"
},
{
"code": 6012,
"name": "MetadataNotFound",
"msg": "Metadata not found"
},
{
"code": 6013,
"name": "MintNotComplete",
"msg": "Mint is not finished"
},
{
"code": 6014,
"name": "InvalidSigner",
"msg": "Invalid signer"
}
]
};
Loading