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

token-js: Support metadata pointer extension #4550

Closed
joncinque opened this issue Jun 15, 2023 · 9 comments
Closed

token-js: Support metadata pointer extension #4550

joncinque opened this issue Jun 15, 2023 · 9 comments
Labels
good first issue Good for newcomers

Comments

@joncinque
Copy link
Contributor

joncinque commented Jun 15, 2023

Problem

With #4549, token-2022 can also store a pointer to a metadata account, but this isn't exposed in the JS bindings.

Solution

Support the following instructions:

  • initializing a mint with a metadata pointer:
    pub fn initialize(
    token_program_id: &Pubkey,
    mint: &Pubkey,
    authority: Option<Pubkey>,
    metadata_address: Option<Pubkey>,
    ) -> Result<Instruction, ProgramError> {
    check_program_account(token_program_id)?;
    let accounts = vec![AccountMeta::new(*mint, false)];
    Ok(encode_instruction(
    token_program_id,
    accounts,
    TokenInstruction::MetadataPointerExtension,
    MetadataPointerInstruction::Initialize,
    &InitializeInstructionData {
    authority: authority.try_into()?,
    metadata_address: metadata_address.try_into()?,
    },
    ))
    }
  • updating the metadata pointer address:
    pub fn update(
    token_program_id: &Pubkey,
    mint: &Pubkey,
    authority: &Pubkey,
    signers: &[&Pubkey],
    metadata_address: Option<Pubkey>,
    ) -> Result<Instruction, ProgramError> {
    check_program_account(token_program_id)?;
    let mut accounts = vec![
    AccountMeta::new(*mint, false),
    AccountMeta::new_readonly(*authority, signers.is_empty()),
    ];
    for signer_pubkey in signers.iter() {
    accounts.push(AccountMeta::new_readonly(**signer_pubkey, true));
    }
    Ok(encode_instruction(
    token_program_id,
    accounts,
    TokenInstruction::MetadataPointerExtension,
    MetadataPointerInstruction::Update,
    &UpdateInstructionData {
    metadata_address: metadata_address.try_into()?,
    },
    ))
    }

Support deserializing the extension data:

pub struct MetadataPointer {
/// Authority that can set the metadata address
pub authority: OptionalNonZeroPubkey,
/// Account address that holds the metadata
pub metadata_address: OptionalNonZeroPubkey,
}

This is a good example to follow, based on a different extension: #3833

@joncinque joncinque added the good first issue Good for newcomers label Jun 15, 2023
@github-project-automation github-project-automation bot moved this to Needs triage in SPL Token 22 Jun 15, 2023
@joncinque joncinque moved this from Needs triage to Token Clients in SPL Token 22 Jun 15, 2023
@pcellix
Copy link

pcellix commented Jul 4, 2023

@joncinque Can I work on it?

@joncinque
Copy link
Contributor Author

Go for it! I've updated the issue description to be more helpful

@pcellix
Copy link

pcellix commented Jul 7, 2023

I'm on it! Thank you!

@pcellix
Copy link

pcellix commented Jul 7, 2023

I installed the solana cli, when I try to execute cargo command I get the following message:

ubuntu@ubuntu-16gb-nbg1-1:~/solana-program-library$ cargo build-bpf
info: syncing channel updates for '1.69.0-x86_64-unknown-linux-gnu'
info: latest update on 2023-04-20, rust version 1.69.0 (84c898d65 2023-04-16)
info: downloading component 'cargo'
info: downloading component 'clippy'
info: downloading component 'rust-docs'
info: downloading component 'rust-std'
info: downloading component 'rustc'
info: downloading component 'rustfmt'
info: installing component 'cargo'
info: installing component 'clippy'
info: installing component 'rust-docs'
info: installing component 'rust-std'
info: installing component 'rustc'
info: installing component 'rustfmt'
[2023-07-07T17:37:28.456416664Z ERROR cargo_build_sbf] Failed to execute /home/ubuntu/.cache/solana/v1.37/platform-tools/rust/bin/rustc: No such file or directory (os error 2)

ubuntu@ubuntu-16gb-nbg1-1:~/solana-program-library$ solana --version
solana-cli 1.16.2 (src:02d5647b; feat:2891131721, client:SolanaLabs)

Any ideas how to proceed?

@joncinque
Copy link
Contributor Author

Sorry, we don't provide developer support through GitHub -- be sure to ask on an appropriate Discord server or the Solana Stack Exchange https://solana.stackexchange.com/

You can try the help for the build command by running cargo build-sbf -h and see if anything looks helpful. I'm guessing --force-tools-install might be a good start.

@pcellix
Copy link

pcellix commented Jul 8, 2023

The issue was with Solana-cli 1.16.2 after upgrading to newly released 1.16.3 all works

@dhruvdabhi101
Copy link
Contributor

Hey, I would love to take this up if anyone is not working on this. :)

@joncinque
Copy link
Contributor Author

@dhruvdabhi101 go for it!

@mistersimon
Copy link
Contributor

I think this can be closed now 😀

Was implemented in #5805 and deployed with #5813

@github-project-automation github-project-automation bot moved this from Token Clients to Closed in SPL Token 22 Nov 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
Status: Closed
Development

No branches or pull requests

5 participants