|
1 | 1 | //! Program state processor
|
2 | 2 |
|
3 |
| -use metaplex_token_metadata::state::Metadata; |
4 |
| -use solana_program::program_option::COption; |
5 |
| -use std::slice::Iter; |
6 |
| - |
7 |
| -use crate::error::UtilError; |
8 |
| -use crate::instruction::StatelessOfferInstruction; |
9 |
| -use crate::validation_utils::{assert_is_ata, assert_keys_equal}; |
10 | 3 | use {
|
| 4 | + crate::{ |
| 5 | + error::UtilError, |
| 6 | + instruction::StatelessOfferInstruction, |
| 7 | + validation_utils::{assert_is_ata, assert_keys_equal}, |
| 8 | + }, |
11 | 9 | borsh::BorshDeserialize,
|
12 | 10 | solana_program::{
|
13 | 11 | account_info::next_account_info,
|
14 | 12 | account_info::AccountInfo,
|
| 13 | + borsh::try_from_slice_unchecked, |
15 | 14 | entrypoint::ProgramResult,
|
16 | 15 | msg,
|
17 | 16 | program::{invoke, invoke_signed},
|
18 | 17 | program_error::ProgramError,
|
| 18 | + program_option::COption, |
19 | 19 | program_pack::Pack,
|
20 | 20 | pubkey::Pubkey,
|
21 | 21 | system_instruction, system_program,
|
22 | 22 | },
|
| 23 | + std::slice::Iter, |
23 | 24 | };
|
24 | 25 |
|
| 26 | +pub(crate) mod inline_mpl_token_metadata { |
| 27 | + use {borsh::BorshDeserialize, solana_program::pubkey::Pubkey}; |
| 28 | + solana_program::declare_id!("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"); |
| 29 | + |
| 30 | + #[derive(Clone, BorshDeserialize, Debug, PartialEq, Eq)] |
| 31 | + pub(crate) struct Metadata { |
| 32 | + /// Account discriminator. |
| 33 | + pub key: u8, |
| 34 | + /// Address of the update authority. |
| 35 | + pub update_authority: Pubkey, |
| 36 | + /// Address of the mint. |
| 37 | + pub mint: Pubkey, |
| 38 | + /// Asset data. |
| 39 | + pub data: Data, |
| 40 | + } |
| 41 | + |
| 42 | + #[derive(BorshDeserialize, Default, PartialEq, Eq, Debug, Clone)] |
| 43 | + pub(crate) struct Data { |
| 44 | + /// The name of the asset |
| 45 | + pub name: String, |
| 46 | + /// The symbol for the asset |
| 47 | + pub symbol: String, |
| 48 | + /// URI pointing to JSON representing the asset |
| 49 | + pub uri: String, |
| 50 | + /// Royalty basis points that goes to creators in secondary sales (0-10000) |
| 51 | + pub seller_fee_basis_points: u16, |
| 52 | + /// Array of creators, optional |
| 53 | + pub creators: Option<Vec<Creator>>, |
| 54 | + } |
| 55 | + |
| 56 | + #[derive(BorshDeserialize, PartialEq, Debug, Clone, Eq, Hash)] |
| 57 | + pub(crate) struct Creator { |
| 58 | + pub address: Pubkey, |
| 59 | + pub verified: bool, |
| 60 | + pub share: u8, |
| 61 | + } |
| 62 | +} |
| 63 | + |
25 | 64 | /// Program state handler.
|
26 | 65 | pub struct Processor {}
|
27 | 66 | impl Processor {
|
@@ -89,18 +128,18 @@ fn process_accept_offer(
|
89 | 128 | let (maker_metadata_key, _) = Pubkey::find_program_address(
|
90 | 129 | &[
|
91 | 130 | b"metadata",
|
92 |
| - metaplex_token_metadata::id().as_ref(), |
| 131 | + inline_mpl_token_metadata::id().as_ref(), |
93 | 132 | maker_src_mint.key.as_ref(),
|
94 | 133 | ],
|
95 |
| - &metaplex_token_metadata::id(), |
| 134 | + &inline_mpl_token_metadata::id(), |
96 | 135 | );
|
97 | 136 | let (taker_metadata_key, _) = Pubkey::find_program_address(
|
98 | 137 | &[
|
99 | 138 | b"metadata",
|
100 |
| - metaplex_token_metadata::id().as_ref(), |
| 139 | + inline_mpl_token_metadata::id().as_ref(), |
101 | 140 | taker_src_mint.key.as_ref(),
|
102 | 141 | ],
|
103 |
| - &metaplex_token_metadata::id(), |
| 142 | + &inline_mpl_token_metadata::id(), |
104 | 143 | );
|
105 | 144 | if *metadata_info.key == maker_metadata_key {
|
106 | 145 | msg!("Taker pays for fees");
|
@@ -246,7 +285,12 @@ fn pay_creator_fees<'a>(
|
246 | 285 | is_native: bool,
|
247 | 286 | seeds: &[&[u8]],
|
248 | 287 | ) -> Result<u64, ProgramError> {
|
249 |
| - let metadata = Metadata::from_account_info(metadata_info)?; |
| 288 | + if *metadata_info.owner != inline_mpl_token_metadata::id() { |
| 289 | + return Err(ProgramError::InvalidAccountData); |
| 290 | + } |
| 291 | + let metadata = try_from_slice_unchecked::<inline_mpl_token_metadata::Metadata>( |
| 292 | + &metadata_info.try_borrow_data()?, |
| 293 | + )?; |
250 | 294 | let fees = metadata.data.seller_fee_basis_points;
|
251 | 295 | let total_fee = (fees as u64)
|
252 | 296 | .checked_mul(size)
|
|
0 commit comments