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

Creating a 1.13.3 patch for backwards compatibility. #136

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

## Getting Started

The packages below can be use to interact with Token Metadata program.
The packages below can be used to interact with Token Metadata program.

### TypeScript
```sh
npm install @metaplex-foundation/mpl-token-metadata@alpha
npm install @metaplex-foundation/mpl-token-metadata
```

[See typedoc documentation](https://mpl-token-metadata-js-docs.vercel.app/).
Expand All @@ -30,13 +30,13 @@ npm install @metaplex-foundation/mpl-token-metadata@alpha
cargo add mpl-token-metadata
```

[See crate documentation](https://docs.rs/mpl-token-metadata/1.13.1/mpl_token_metadata/).
[See crate documentation](https://docs.rs/mpl-token-metadata/1.13.3/mpl_token_metadata/).

## Building

From the root directory of the repository:

- Install the required packges:
- Install the required packages:
```sh
pnpm install
```
Expand All @@ -50,7 +50,7 @@ This will create the program binary at `<ROOT>/programs/.bin`

## Testing

Token Metadata includes two set of tests: BPF and TypeScript.
Token Metadata includes two sets of tests: BPF and TypeScript.

### BPF

Expand Down Expand Up @@ -80,7 +80,7 @@ pnpm build && pnpm test

## Documentation

Full documentation for Token Metadata can be found [here](https://docs.metaplex.com/programs/token-metadata/).
Full documentation for Token Metadata can be found here [developers.metaplex.com/token-metadata](https://developers.metaplex.com/token-metadata).

## Security

Expand Down
6 changes: 3 additions & 3 deletions idls/token_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -7731,7 +7731,7 @@
"metadata": {
"origin": "shank",
"address": "metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s",
"binaryVersion": "0.2.0",
"libVersion": "0.2.0"
"binaryVersion": "0.4.2",
"libVersion": "0.4.2"
}
}
}
28 changes: 14 additions & 14 deletions programs/token-metadata/Cargo.lock

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

26 changes: 16 additions & 10 deletions programs/token-metadata/program/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,38 +1,44 @@
[package]
name = "token_metadata"
version = "1.13.3"
description = "Metaplex Metadata"
authors = ["Metaplex Developers <[email protected]>"]
repository = "https://github.com/metaplex-foundation/metaplex-program-library"
license-file = "../../../LICENSE"
description = "Metaplex Metadata"
edition = "2021"
license-file = "../../../LICENSE"
name = "token_metadata"
readme = "README.md"
repository = "https://github.com/metaplex-foundation/metaplex-program-library"
version = "1.13.3"

[features]
no-entrypoint = []
test-bpf = []
serde-feature = ["serde", "serde_with"]
test-bpf = []

[dependencies]
arrayref = "0.3.6"
borsh = "0.9.3"
mpl-token-auth-rules = { version = "=1.4.3-beta.1", features = ["no-entrypoint"] }
mpl-token-auth-rules = { version = "=1.4.3-beta.1", features = [
"no-entrypoint",
] }
mpl-token-metadata-context-derive = { version = "0.3.0", path = "../macro" }
mpl-utils = { version = "0.3.1" }
num-derive = "0.3"
num-traits = "0.2"
serde = { version = "1.0.149", optional = true }
serde_with = { version = "1.14.0", optional = true }
shank = "0.2.0"
shank = "0.4.2"
solana-program = ">= 1.14.13, < 1.17"
spl-associated-token-account = { version = ">= 1.1.3, < 3.0", features = [
"no-entrypoint",
] }
spl-token = { version = ">= 3.5.0, < 5.0", features = ["no-entrypoint"] }
spl-associated-token-account = { version = ">= 1.1.3, < 3.0", features = ["no-entrypoint"] }
thiserror = "1.0"

[dev-dependencies]
async-trait = "0.1.64"
rmp-serde = "1.1.1"
rooster = { git = "https://github.com/metaplex-foundation/rooster", features = ["no-entrypoint"] }
rooster = { git = "https://github.com/metaplex-foundation/rooster", features = [
"no-entrypoint",
] }
serde = { version = "1.0.147", features = ["derive"] }
solana-program-test = ">= 1.14.13, < 1.17"
solana-sdk = ">= 1.14.13, < 1.17"
Expand Down
10 changes: 9 additions & 1 deletion programs/token-metadata/program/src/state/edition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,15 @@ impl TokenMetadataAccount for Edition {
}

fn size() -> usize {
MAX_EDITION_LEN
0
}

fn pad_length(buf: &mut Vec<u8>) -> Result<(), MetadataError> {
let padding_length = MAX_EDITION_LEN
.checked_sub(buf.len())
.ok_or(MetadataError::NumericalOverflowError)?;
buf.extend(vec![0; padding_length]);
Ok(())
}
}

Expand Down
20 changes: 18 additions & 2 deletions programs/token-metadata/program/src/state/master_edition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,15 @@ impl TokenMetadataAccount for MasterEditionV2 {
}

fn size() -> usize {
MAX_MASTER_EDITION_LEN
0
}

fn pad_length(buf: &mut Vec<u8>) -> Result<(), MetadataError> {
let padding_length = MAX_MASTER_EDITION_LEN
.checked_sub(buf.len())
.ok_or(MetadataError::NumericalOverflowError)?;
buf.extend(vec![0; padding_length]);
Ok(())
}
}

Expand Down Expand Up @@ -148,7 +156,15 @@ impl TokenMetadataAccount for MasterEditionV1 {
}

fn size() -> usize {
MAX_MASTER_EDITION_LEN
0
}

fn pad_length(buf: &mut Vec<u8>) -> Result<(), MetadataError> {
let padding_length = MAX_MASTER_EDITION_LEN
.checked_sub(buf.len())
.ok_or(MetadataError::NumericalOverflowError)?;
buf.extend(vec![0; padding_length]);
Ok(())
}
}

Expand Down
21 changes: 14 additions & 7 deletions programs/token-metadata/program/src/state/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub const MAX_SYMBOL_LENGTH: usize = 10;

pub const MAX_URI_LENGTH: usize = 200;

pub const MAX_METADATA_LEN: usize = 1 // key
pub const MAX_METADATA_LEN: usize = 1 // key
+ 32 // update auth pubkey
+ 32 // mint pubkey
+ MAX_DATA_SIZE
Expand Down Expand Up @@ -335,7 +335,15 @@ impl TokenMetadataAccount for Metadata {
}

fn size() -> usize {
MAX_METADATA_LEN
0
}

fn pad_length(buf: &mut Vec<u8>) -> Result<(), MetadataError> {
let padding_length = MAX_METADATA_LEN
.checked_sub(buf.len())
.ok_or(MetadataError::NumericalOverflowError)?;
buf.extend(vec![0; padding_length]);
Ok(())
}
}

Expand Down Expand Up @@ -484,7 +492,7 @@ mod tests {
}

#[test]
fn fail_to_deserialize_metadata_with_wrong_size() {
fn successfully_deserialize_metadata_with_different_size() {
let expected_metadata = expected_pesky_metadata();

let mut buf = Vec::new();
Expand All @@ -507,10 +515,9 @@ mod tests {
1_000_000_000,
);

// `from_account_info` should not succeed because this account is not owned
// by `token-metadata` program.
let error = Metadata::from_account_info(&account_info).unwrap_err();
assert_eq!(error, MetadataError::DataTypeMismatch.into());
let md = Metadata::from_account_info(&account_info).unwrap();
assert_eq!(md.key, Key::MetadataV1);
assert_eq!(md, expected_metadata);
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions programs/token-metadata/program/src/utils/fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use solana_program::{
sysvar::Sysvar,
};

use crate::state::{fee::CREATE_FEE, Metadata, TokenMetadataAccount, METADATA_FEE_FLAG_INDEX};
use crate::state::{fee::CREATE_FEE, MAX_METADATA_LEN, METADATA_FEE_FLAG_INDEX};

#[repr(C)]
#[derive(Debug, Clone, Copy)]
Expand All @@ -16,7 +16,7 @@ pub(crate) fn levy(args: LevyArgs) -> ProgramResult {
// Fund metadata account with rent + Metaplex fee.
let rent = Rent::get()?;

let fee = CREATE_FEE + rent.minimum_balance(Metadata::size());
let fee = CREATE_FEE + rent.minimum_balance(MAX_METADATA_LEN);

invoke(
&solana_program::system_instruction::transfer(
Expand Down
6 changes: 3 additions & 3 deletions programs/token-metadata/program/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use crate::{
error::MetadataError,
state::{
Edition, Key, MasterEditionV2, Metadata, TokenMetadataAccount, TokenStandard,
MAX_NAME_LENGTH, MAX_SYMBOL_LENGTH, MAX_URI_LENGTH,
MAX_METADATA_LEN, MAX_NAME_LENGTH, MAX_SYMBOL_LENGTH, MAX_URI_LENGTH,
},
};

Expand Down Expand Up @@ -199,7 +199,7 @@ pub(crate) fn close_program_account<'a>(
let rent_lamports = match key {
// Metadata accounts could have fees stored, so we only want to withdraw
// the actual rent lamport amount.
Key::MetadataV1 => rent.minimum_balance(Metadata::size()),
Key::MetadataV1 => rent.minimum_balance(MAX_METADATA_LEN),
// Other accounts the rent is just the current lamport balance.
_ => account_info.lamports(),
};
Expand Down Expand Up @@ -313,7 +313,7 @@ mod tests {
let corrupted_data = pesky_data();

let metadata: Metadata =
try_from_slice_checked(corrupted_data, Key::MetadataV1, MAX_METADATA_LEN).unwrap();
try_from_slice_checked(corrupted_data, Key::MetadataV1, 0).unwrap();

assert_eq!(metadata, expected_metadata);
}
Expand Down