Skip to content

Commit

Permalink
Adding docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
blockiosaurus committed Feb 26, 2024
1 parent 8c6b107 commit bac0ce0
Show file tree
Hide file tree
Showing 38 changed files with 353 additions and 139 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions clients/js/src/generated/types/creator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@
import { PublicKey } from '@metaplex-foundation/umi';
import {
Serializer,
bool,
publicKey as publicKeySerializer,
struct,
u8,
} from '@metaplex-foundation/umi/serializers';

export type Creator = { address: PublicKey; verified: boolean };
export type Creator = { address: PublicKey; percentage: number };

export type CreatorArgs = Creator;

export function getCreatorSerializer(): Serializer<CreatorArgs, Creator> {
return struct<Creator>(
[
['address', publicKeySerializer()],
['verified', bool()],
['percentage', u8()],
],
{ description: 'Creator' }
) as Serializer<CreatorArgs, Creator>;
Expand Down
8 changes: 4 additions & 4 deletions clients/js/src/generated/types/royalties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
Serializer,
array,
struct,
u16,
u8,
} from '@metaplex-foundation/umi/serializers';
import {
Creator,
Expand All @@ -22,21 +22,21 @@ import {
} from '.';

export type Royalties = {
sellerFeeBasisPoints: number;
percentage: number;
creators: Array<Creator>;
ruleSet: RuleSet;
};

export type RoyaltiesArgs = {
sellerFeeBasisPoints: number;
percentage: number;
creators: Array<CreatorArgs>;
ruleSet: RuleSetArgs;
};

export function getRoyaltiesSerializer(): Serializer<RoyaltiesArgs, Royalties> {
return struct<Royalties>(
[
['sellerFeeBasisPoints', u16()],
['percentage', u8()],
['creators', array(getCreatorSerializer())],
['ruleSet', getRuleSetSerializer()],
],
Expand Down
2 changes: 1 addition & 1 deletion clients/rust/src/generated/types/creator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ pub struct Creator {
serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
)]
pub address: Pubkey,
pub verified: bool,
pub percentage: u8,
}
2 changes: 1 addition & 1 deletion clients/rust/src/generated/types/royalties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use borsh::BorshSerialize;
#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Royalties {
pub seller_fee_basis_points: u16,
pub percentage: u8,
pub creators: Vec<Creator>,
pub rule_set: RuleSet,
}
8 changes: 4 additions & 4 deletions idls/mpl_core_program.json
Original file line number Diff line number Diff line change
Expand Up @@ -943,8 +943,8 @@
"type": "publicKey"
},
{
"name": "verified",
"type": "bool"
"name": "percentage",
"type": "u8"
}
]
}
Expand All @@ -955,8 +955,8 @@
"kind": "struct",
"fields": [
{
"name": "sellerFeeBasisPoints",
"type": "u16"
"name": "percentage",
"type": "u8"
},
{
"name": "creators",
Expand Down
1 change: 1 addition & 0 deletions programs/mpl-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ thiserror = "^1.0"
bytemuck = "1.14.1"
mpl-utils = "0.3.3"
spl-noop = { version = "0.2.0", features = ["cpi"] }
podded = "0.5.1"
6 changes: 4 additions & 2 deletions programs/mpl-core/src/entrypoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@ use solana_program::{
program_error::PrintProgramError, pubkey::Pubkey,
};

use crate::{error::MplAssetError, processor};
use crate::{error::MplCoreError, processor};

entrypoint!(process_instruction);

/// Entrypoint function
fn process_instruction<'a>(
program_id: &'a Pubkey,
accounts: &'a [AccountInfo<'a>],
instruction_data: &[u8],
) -> ProgramResult {
if let Err(error) = processor::process_instruction(program_id, accounts, instruction_data) {
// catch the error so we can print it
error.print::<MplAssetError>();
error.print::<MplCoreError>();
return Err(error);
}
Ok(())
Expand Down
11 changes: 6 additions & 5 deletions programs/mpl-core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ use solana_program::{
};
use thiserror::Error;

/// Errors that may be returned by the Mpl Core program.
#[derive(Error, Clone, Debug, Eq, PartialEq, FromPrimitive)]
pub enum MplAssetError {
pub enum MplCoreError {
/// 0 - Invalid System Program
#[error("Invalid System Program")]
InvalidSystemProgram,
Expand Down Expand Up @@ -85,19 +86,19 @@ pub enum MplAssetError {
AlreadyDecompressed,
}

impl PrintProgramError for MplAssetError {
impl PrintProgramError for MplCoreError {
fn print<E>(&self) {
msg!(&self.to_string());
}
}

impl From<MplAssetError> for ProgramError {
fn from(e: MplAssetError) -> Self {
impl From<MplCoreError> for ProgramError {
fn from(e: MplCoreError) -> Self {
ProgramError::Custom(e as u32)
}
}

impl<T> DecodeError<T> for MplAssetError {
impl<T> DecodeError<T> for MplCoreError {
fn type_of() -> &'static str {
"Mpl Core Error"
}
Expand Down
4 changes: 3 additions & 1 deletion programs/mpl-core/src/instruction.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(missing_docs)]
use borsh::{BorshDeserialize, BorshSerialize};
use shank::{ShankContext, ShankInstruction};

Expand All @@ -6,6 +7,7 @@ use crate::processor::{
RemoveAuthorityArgs, RemovePluginArgs, TransferArgs, UpdateArgs, UpdatePluginArgs,
};

/// Instructions supported by the mpl-core program.
#[derive(BorshDeserialize, BorshSerialize, Clone, Debug, ShankContext, ShankInstruction)]
#[rustfmt::skip]
pub enum MplAssetInstruction {
Expand Down Expand Up @@ -75,7 +77,7 @@ pub enum MplAssetInstruction {
Burn(BurnArgs),

// Transfer an asset.
// danenbm WIP
/// Transfer an asset by changing its owner.
#[account(0, writable, name="asset_address", desc = "The address of the asset")]
#[account(1, optional, name="collection", desc = "The collection to which the asset belongs")]
#[account(2, signer, name="authority", desc = "The owner or delegate of the asset")]
Expand Down
22 changes: 22 additions & 0 deletions programs/mpl-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@
#![deny(missing_docs)]
//! # MPL Core
//!
//! Metaplex Core (“Core”) sheds the complexity and technical debt of previous
//! standards and provides a clean and simple core spec for digital assets.
//! This makes the bare minimum use case easy and understandable for users just
//! starting out with Digital Assets.
//!
//!However, it's designed with a flexible plugin system that allows for users
//! to extend the program itself without relying on Metaplex to add support to
//! a rigid standard like Token Metadata. The plugin system is so powerful that
//! it could even allow users to contribute third party plugins after the core
//! program is made immutable.
/// Standard Solana entrypoint.
pub mod entrypoint;
/// Error types for MPL Core.
pub mod error;
/// Main enum for managing instructions on MPL Core.
pub mod instruction;
/// Module for managing plugins.
pub mod plugins;
/// Module for processing instructions and routing them
/// to the associated processor.
pub mod processor;
/// State and Type definitions for MPL Core.
pub mod state;
/// Program-wide utility functions.
pub mod utils;

pub use solana_program;
Expand Down
3 changes: 3 additions & 0 deletions programs/mpl-core/src/plugins/burn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ use crate::{

use super::{PluginValidation, ValidationResult};

/// This plugin manages additional permissions to burn.
/// Any authorities approved are given permission to burn the asset on behalf of the owner.
#[repr(C)]
#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, Debug, PartialEq, Eq)]
pub struct Burn {}

impl Burn {
/// Initialize the Burn plugin.
pub fn new() -> Self {
Self {}
}
Expand Down
6 changes: 6 additions & 0 deletions programs/mpl-core/src/plugins/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@ use crate::{

use super::{PluginValidation, ValidationResult};

/// This plugin manages a collection or grouping of assets.
#[derive(Clone, BorshSerialize, BorshDeserialize, Debug, Eq, PartialEq)]
pub struct Collection {
/// A pointer to the collection which the asset is a part of.
collection_address: Pubkey,
/// This flag indicates if the collection is required when operating on the asset.
/// Managed collections use the Collection as a parent which can store plugins that
/// are applied to all assets in the collection by default. Plugins on the asset itself
/// can override the collection plugins.
managed: bool,
}

Expand Down
4 changes: 4 additions & 0 deletions programs/mpl-core/src/plugins/freeze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@ use crate::{

use super::{PluginValidation, ValidationResult};

/// The freeze plugin allows any authority to lock the asset so it's no longer transferable.
/// The default authority for this plugin is the owner.
#[repr(C)]
#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, Debug, PartialEq, Eq)]
pub struct Freeze {
/// The current state of the asset and whether or not it's transferable.
pub frozen: bool, // 1
}

impl Freeze {
/// Initialize the Freeze plugin, unfrozen by default.
pub fn new() -> Self {
Self { frozen: false }
}
Expand Down
Loading

0 comments on commit bac0ce0

Please sign in to comment.