Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit 3bb3b90

Browse files
authored
stateless-asks: Remove metaplex dependency (#4590)
* stateless-asks: Remove metaplex dependency * Add inline declarations * cargo fmt
1 parent bd60d25 commit 3bb3b90

File tree

3 files changed

+56
-44
lines changed

3 files changed

+56
-44
lines changed

Cargo.lock

Lines changed: 0 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

stateless-asks/program/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ borsh = "0.9.1"
1515
solana-program = "1.14.12"
1616
spl-token = { version = "3.5", path = "../../token/program", features = ["no-entrypoint"] }
1717
spl-associated-token-account = {version = "1.1", path = "../../associated-token-account/program", features = ["no-entrypoint"]}
18-
metaplex-token-metadata = { version = "0.0.1", features = ["no-entrypoint"] }
1918
thiserror = "1.0"
2019

2120
[dev-dependencies]

stateless-asks/program/src/processor.rs

Lines changed: 56 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,66 @@
11
//! Program state processor
22
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};
103
use {
4+
crate::{
5+
error::UtilError,
6+
instruction::StatelessOfferInstruction,
7+
validation_utils::{assert_is_ata, assert_keys_equal},
8+
},
119
borsh::BorshDeserialize,
1210
solana_program::{
1311
account_info::next_account_info,
1412
account_info::AccountInfo,
13+
borsh::try_from_slice_unchecked,
1514
entrypoint::ProgramResult,
1615
msg,
1716
program::{invoke, invoke_signed},
1817
program_error::ProgramError,
18+
program_option::COption,
1919
program_pack::Pack,
2020
pubkey::Pubkey,
2121
system_instruction, system_program,
2222
},
23+
std::slice::Iter,
2324
};
2425

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+
2564
/// Program state handler.
2665
pub struct Processor {}
2766
impl Processor {
@@ -89,18 +128,18 @@ fn process_accept_offer(
89128
let (maker_metadata_key, _) = Pubkey::find_program_address(
90129
&[
91130
b"metadata",
92-
metaplex_token_metadata::id().as_ref(),
131+
inline_mpl_token_metadata::id().as_ref(),
93132
maker_src_mint.key.as_ref(),
94133
],
95-
&metaplex_token_metadata::id(),
134+
&inline_mpl_token_metadata::id(),
96135
);
97136
let (taker_metadata_key, _) = Pubkey::find_program_address(
98137
&[
99138
b"metadata",
100-
metaplex_token_metadata::id().as_ref(),
139+
inline_mpl_token_metadata::id().as_ref(),
101140
taker_src_mint.key.as_ref(),
102141
],
103-
&metaplex_token_metadata::id(),
142+
&inline_mpl_token_metadata::id(),
104143
);
105144
if *metadata_info.key == maker_metadata_key {
106145
msg!("Taker pays for fees");
@@ -246,7 +285,12 @@ fn pay_creator_fees<'a>(
246285
is_native: bool,
247286
seeds: &[&[u8]],
248287
) -> 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+
)?;
250294
let fees = metadata.data.seller_fee_basis_points;
251295
let total_fee = (fees as u64)
252296
.checked_mul(size)

0 commit comments

Comments
 (0)