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

feat: add MPL Core program #2905

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions spl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ stake = ["borsh"]
token = ["spl-token"]
token_2022 = ["spl-token-2022"]
token_2022_extensions = ["spl-token-2022", "spl-token-group-interface", "spl-token-metadata-interface", "spl-pod"]
mpl_core = ["mpl-core"]

[dependencies]
anchor-lang = { path = "../lang", version = "0.29.0", features = ["derive"] }
Expand All @@ -38,3 +39,4 @@ spl-token-2022 = { version = "3", features = ["no-entrypoint"], optional = true
spl-token-group-interface = { version = "0.2.3", optional = true }
spl-token-metadata-interface = { version = "0.3.3", optional = true }
spl-pod = { version = "0.2.2", optional = true }
mpl-core = { version = "0.4.4", optional = true}
3 changes: 3 additions & 0 deletions spl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ pub mod memo;

#[cfg(feature = "idl-build")]
mod idl_build;

#[cfg(feature = "mpl_core")]
mod mpl_core;
82 changes: 82 additions & 0 deletions spl/src/mpl_core.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
use anchor_lang::error::ErrorCode;
use std::ops::Deref;

pub use mpl_core;
pub use mpl_core::ID;

#[derive(Clone, Debug, PartialEq)]
pub struct AssetAccount(mpl_core::Asset);

impl anchor_lang::AccountDeserialize for AssetAccount {
fn try_deserialize(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
let asset = Self::try_deserialize_unchecked(buf)?;
if asset.base.key == mpl_core::types::Key::Uninitialized {
return Err(ErrorCode::AccountNotInitialized.into());
}

Ok(asset)
}

fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
let asset = mpl_core::Asset::deserialize(buf)?;
Ok(Self(asset))
}
}

impl anchor_lang::AccountSerialize for AssetAccount {}

impl anchor_lang::Owner for AssetAccount {
fn owner() -> Pubkey {
ID
}
}

impl Deref for AssetAccount {
type Target = mpl_core::Asset;
fn deref(&self) -> &Self::Target {
&self.0
}
}

#[derive(Clone, Debug, PartialEq)]
pub struct BaseAssetV1Account(mpl_core::accounts::BaseAssetV1);

impl anchor_lang::AccountDeserialize for BaseAssetV1Account {
fn try_deserialize(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
let base_asset = Self::try_deserialize_unchecked(buf)?;
if base_asset.key == mpl_core::types::Key::Uninitialized {
return Err(ErrorCode::AccountNotInitialized.into());
}

Ok(base_asset)
}

fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
let base_asset = mpl_core::accounts::BaseAssetV1::deserialize(buf)?;
Ok(Self(base_asset))
}
}

impl anchor_lang::AccountSerialize for BaseAssetV1Account {}

impl anchor_lang::Owner for BaseAssetV1Account {
fn owner() -> Pubkey {
ID
}
}

impl Deref for BaseAssetV1Account {
type Target = mpl_core::accounts::BaseAssetV1;
fn deref(&self) -> &Self::Target {
&self.0
}
}

#[derive(Clone)]
pub struct MplCore;

impl anchor_lang::Id for MplCore {
fn id() -> Pubkey {
mpl_core::ID
}
}
Loading