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

Fix create metadata mistake, add update #2474

Merged
merged 1 commit into from
Jan 2, 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
1 change: 1 addition & 0 deletions contracts/solana/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub enum FluidityInstruction {
/// 5. `[]` System program
/// 6. `[]` Metaplex metadata program
CreateTokenMetadata(String, u8, String, String, String),
UpdateTokenMetadata(String, u8, String, String, String),
}

// solend instructions
Expand Down
66 changes: 64 additions & 2 deletions contracts/solana/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ use crate::{

use {
borsh::{BorshDeserialize, BorshSerialize},
mpl_token_metadata::instructions::CreateMetadataAccountV3CpiBuilder,
mpl_token_metadata::instructions::{
CreateMetadataAccountV3CpiBuilder, UpdateMetadataAccountV2CpiBuilder,
},
solana_program::{
account_info::{next_account_info, AccountInfo},
entrypoint::ProgramResult,
Expand Down Expand Up @@ -1053,6 +1055,8 @@ fn create_token_metadata(

let pda_seed = format!("FLU:{}_OBLIGATION", seed);

let modified_symbol = format!("f{symbol}");

CreateMetadataAccountV3CpiBuilder::new(&metaplex_program_account)
.metadata(&metaplex_metadata_account)
.mint(&fluidity_token_mint_account)
Expand All @@ -1064,7 +1068,61 @@ fn create_token_metadata(
.is_mutable(true)
.data(mpl_token_metadata::types::DataV2 {
name: name,
symbol: symbol,
symbol: modified_symbol,
uri: uri,
seller_fee_basis_points: seller_fee,
creators: None,
collection: None,
uses: None,
})
.invoke_signed(&[&[&pda_seed.as_bytes(), &[bump]]])
}

fn update_token_metadata(
accounts: &[AccountInfo],
program_id: &Pubkey,
seed: String,
bump: u8,
name: String,
symbol: String,
uri: String,
seller_fee: u16,
) -> ProgramResult {
let accounts_iter = &mut accounts.iter();

let fluidity_data_account = next_account_info(accounts_iter)?;
let base_token_mint_account = next_account_info(accounts_iter)?;
let fluidity_token_mint_account = next_account_info(accounts_iter)?;
let pda_account = next_account_info(accounts_iter)?;
let payer_account = next_account_info(accounts_iter)?;
let metaplex_program_account = next_account_info(accounts_iter)?;
let metaplex_metadata_account = next_account_info(accounts_iter)?;

let (_, fluidity_data, payer) = validate_authority(
&seed,
program_id,
fluidity_data_account, // fluidity data account
base_token_mint_account, // token mint
fluidity_token_mint_account, // fluidity mint
pda_account, // pda account
payer_account, // payer
)?;

if *payer.key != fluidity_data.operator {
panic!("not authorised to use this");
}

let pda_seed = format!("FLU:{}_OBLIGATION", seed);

let modified_symbol = format!("f{symbol}");

UpdateMetadataAccountV2CpiBuilder::new(&metaplex_program_account)
.metadata(&metaplex_metadata_account)
.update_authority(&payer_account)
.is_mutable(true)
.data(mpl_token_metadata::types::DataV2 {
name: name,
symbol: modified_symbol,
uri: uri,
seller_fee_basis_points: seller_fee,
creators: None,
Expand Down Expand Up @@ -1213,5 +1271,9 @@ pub fn process(program_id: &Pubkey, accounts: &[AccountInfo], input: &[u8]) -> P
FluidityInstruction::CreateTokenMetadata(seed, bump, name, symbol, uri) => {
create_token_metadata(accounts, program_id, seed, bump, name, symbol, uri, 0)
}

FluidityInstruction::UpdateTokenMetadata(seed, bump, name, symbol, uri) => {
update_token_metadata(accounts, program_id, seed, bump, name, symbol, uri, 0)
}
}
}
Loading