(program_id: &Pubkey, accounts: &[AccountInfo])
| 83 | } |
| 84 | |
| 85 | pub(crate) fn process(program_id: &Pubkey, accounts: &[AccountInfo]) -> ProgramResult { |
| 86 | let accounts = Accounts::parse(program_id, accounts)?; |
| 87 | |
| 88 | let mut market_state = DexState::get(accounts.market)?; |
| 89 | check_accounts(program_id, &market_state, &accounts)?; |
| 90 | check_metadata_account(accounts.token_metadata, &market_state.base_mint)?; |
| 91 | |
| 92 | let mut no_op = true; |
| 93 | |
| 94 | if accounts.token_metadata.data_len() != 0 && market_state.accumulated_royalties != 0 { |
| 95 | no_op = false; |
| 96 | let metadata: Metadata = Metadata::from_account_info(accounts.token_metadata)?; |
| 97 | let mut share_sum = 0; |
| 98 | let mut royalties_sum = 0u64; |
| 99 | if let Some(creators) = metadata.data.creators { |
| 100 | for (idx, creator) in creators.into_iter().enumerate() { |
| 101 | share_sum += creator.share; |
| 102 | let token_destination = accounts.creators_token_accounts.get(idx).unwrap(); |
| 103 | let amount = market_state |
| 104 | .accumulated_royalties |
| 105 | .checked_mul(creator.share as u64) |
| 106 | .ok_or(DexError::NumericalOverflow)? |
| 107 | / 100; |
| 108 | |
| 109 | royalties_sum = royalties_sum |
| 110 | .checked_add(amount) |
| 111 | .ok_or(DexError::NumericalOverflow)?; |
| 112 | |
| 113 | check_token_account_owner(token_destination, &creator.address)?; |
| 114 | |
| 115 | let transfer_instruction = spl_token::instruction::transfer( |
| 116 | &spl_token::ID, |
| 117 | accounts.quote_vault.key, |
| 118 | token_destination.key, |
| 119 | accounts.market_signer.key, |
| 120 | &[], |
| 121 | amount, |
| 122 | )?; |
| 123 | invoke_signed( |
| 124 | &transfer_instruction, |
| 125 | &[ |
| 126 | accounts.spl_token_program.clone(), |
| 127 | accounts.quote_vault.clone(), |
| 128 | token_destination.clone(), |
| 129 | accounts.market_signer.clone(), |
| 130 | ], |
| 131 | &[&[ |
| 132 | &accounts.market.key.to_bytes(), |
| 133 | &[market_state.signer_nonce as u8], |
| 134 | ]], |
| 135 | )?; |
| 136 | } |
| 137 | |
| 138 | if share_sum != 100 { |
| 139 | msg!("Invalid metadata shares - received {}", share_sum); |
| 140 | return Err(ProgramError::InvalidAccountData); |
| 141 | } |
| 142 |
nothing calls this directly
no test coverage detected