Skip to content

p-token: Add interface and p-token to workspace #24

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

Merged
merged 7 commits into from
Mar 10, 2025
Merged
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
3,281 changes: 3,209 additions & 72 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
[workspace]
resolver = "2"
members = ["program"]
members = ["interface", "p-token", "program"]

[workspace.package]
authors = ["Anza Maintainers <[email protected]>"]
repository = "https://github.com/solana-program/token"
license = "Apache-2.0"
edition = "2021"

[workspace.lints.rust.unexpected_cfgs]
level = "warn"
Expand Down
15 changes: 8 additions & 7 deletions interface/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
[package]
name = "token-interface"
name = "spl-token-interface"
version = "0.0.0"
edition = { workspace = true }
description = "Instructions and types for interacting with SPL Token program"
authors = { workspace = true}
repository = { workspace = true}
license = { workspace = true}
edition = { workspace = true}
readme = "./README.md"
license = { workspace = true }
repository = { workspace = true }
publish = false

[lib]
crate-type = ["rlib"]

[dependencies]
pinocchio = { workspace = true }
pinocchio-pubkey = { workspace = true }
pinocchio = { version = "0.7", git = "https://github.com/febo/pinocchio.git", branch = "febo/close-unstable" }
pinocchio-pubkey = { version = "0.2", git = "https://github.com/febo/pinocchio.git", branch = "febo/close-unstable" }
25 changes: 25 additions & 0 deletions interface/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<p align="center">
<a href="https://solana.com">
<img alt="Solana" src="https://github.com/user-attachments/assets/534af75d-6347-48dc-8943-129423b2ba63" height="80" />
</a>
</p>

# SPL Token Interface

This crate contains instructions and constructors for interacting with the [SPL Token program](https://spl.solana.com/token).

The Token program defines a common implementation for Fungible and Non Fungible tokens.

## Getting Started

From your project folder:

```bash
cargo add spl-token-interface
```

This will add the `spl-token-interface` dependency to your `Cargo.toml` file.

## Documentation

Read more about the SPL Token program on the crate [documentation](https://docs.rs/spl-token-interface).
24 changes: 11 additions & 13 deletions p-token/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
[package]
name = "token-program"
name = "pinocchio-token-program"
version = "0.0.0"
edition = { workspace = true }
description = "A pinocchio-based Token (aka 'p-token') program"
authors = { workspace = true}
repository = { workspace = true}
license = { workspace = true}
edition = { workspace = true}
readme = "./README.md"
license = { workspace = true }
repository = { workspace = true }
publish = false

[package.metadata.solana]
program-id = "PToken1111111111111111111111111111111111111"

[lib]
crate-type = ["cdylib"]
Expand All @@ -18,13 +16,13 @@ logging = []
test-sbf = []

[dependencies]
pinocchio = { workspace = true }
pinocchio-log = { workspace = true }
token-interface = { version = "^0", path = "../interface" }
pinocchio = { version = "0.7", git = "https://github.com/febo/pinocchio.git", branch = "febo/close-unstable" }
pinocchio-log = { version = "0.3", git = "https://github.com/febo/pinocchio.git", branch = "febo/close-unstable" }
spl-token-interface = { version = "^0", path = "../interface" }

[dev-dependencies]
assert_matches = "1.5.0"
solana-program-test = "~1.18"
solana-sdk = "~1.18"
solana-program-test = "2.1"
solana-sdk = "2.1"
spl-token = { version="^4", features=["no-entrypoint"] }
test-case = "3.3.1"
15 changes: 15 additions & 0 deletions p-token/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# `p-token`

A `pinocchio`-based Token program.

## Overview

`p-token` is a reimplementation of the SPL Token program, one of the most popular programs on Solana, using [`pinocchio`](https://github.com/anza-xyz/pinocchio). The purpose is to have an implementation that optimizes the compute units, while being fully compatible with the original implementation &mdash; i.e., support the exact same instruction and account layouts as SPL Token, byte for byte.

## Features

- `no_std` crate
- Same instruction and account layout as SPL Token
- Minimal CU usage


## License

The code is licensed under the [Apache License Version 2.0](LICENSE)
1 change: 0 additions & 1 deletion p-token/keypair.json

This file was deleted.

2 changes: 1 addition & 1 deletion p-token/src/processor/amount_to_ui_amount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use pinocchio::{
account_info::AccountInfo, program::set_return_data, program_error::ProgramError, ProgramResult,
};
use pinocchio_log::logger::{Argument, Logger};
use token_interface::{
use spl_token_interface::{
error::TokenError,
state::{load, mint::Mint},
};
Expand Down
2 changes: 1 addition & 1 deletion p-token/src/processor/close_account.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use pinocchio::{
account_info::AccountInfo, program_error::ProgramError, pubkey::Pubkey, ProgramResult,
};
use token_interface::{
use spl_token_interface::{
error::TokenError,
state::{account::Account, load},
};
Expand Down
2 changes: 1 addition & 1 deletion p-token/src/processor/get_account_data_size.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use pinocchio::{
account_info::AccountInfo, program::set_return_data, program_error::ProgramError, ProgramResult,
};
use token_interface::{
use spl_token_interface::{
error::TokenError,
state::{account::Account, load, mint::Mint, RawType},
};
Expand Down
2 changes: 1 addition & 1 deletion p-token/src/processor/initialize_immutable_owner.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use pinocchio::{account_info::AccountInfo, msg, program_error::ProgramError, ProgramResult};
use token_interface::{
use spl_token_interface::{
error::TokenError,
state::{account::Account, load_unchecked, Initializable},
};
Expand Down
2 changes: 1 addition & 1 deletion p-token/src/processor/initialize_mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use pinocchio::{
sysvars::{rent::Rent, Sysvar},
ProgramResult,
};
use token_interface::{
use spl_token_interface::{
error::TokenError,
state::{load_mut_unchecked, mint::Mint, Initializable},
};
Expand Down
2 changes: 1 addition & 1 deletion p-token/src/processor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use pinocchio::{
account_info::AccountInfo, memory::sol_memcpy, program_error::ProgramError, pubkey::Pubkey,
ProgramResult,
};
use token_interface::{
use spl_token_interface::{
error::TokenError,
program::ID as TOKEN_PROGRAM_ID,
state::{
Expand Down
2 changes: 1 addition & 1 deletion p-token/src/processor/revoke.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use pinocchio::{account_info::AccountInfo, program_error::ProgramError, ProgramResult};
use token_interface::{
use spl_token_interface::{
error::TokenError,
state::{account::Account, load_mut},
};
Expand Down
2 changes: 1 addition & 1 deletion p-token/src/processor/set_authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use core::marker::PhantomData;
use pinocchio::{
account_info::AccountInfo, program_error::ProgramError, pubkey::Pubkey, ProgramResult,
};
use token_interface::{
use spl_token_interface::{
error::TokenError,
instruction::AuthorityType,
state::{account::Account, load_mut, mint::Mint, RawType},
Expand Down
2 changes: 1 addition & 1 deletion p-token/src/processor/shared/approve.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use pinocchio::{account_info::AccountInfo, program_error::ProgramError, ProgramResult};
use token_interface::{
use spl_token_interface::{
error::TokenError,
state::{account::Account, load, load_mut, mint::Mint},
};
Expand Down
2 changes: 1 addition & 1 deletion p-token/src/processor/shared/burn.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use pinocchio::{account_info::AccountInfo, program_error::ProgramError, ProgramResult};
use token_interface::{
use spl_token_interface::{
error::TokenError,
state::{account::Account, load_mut, mint::Mint},
};
Expand Down
2 changes: 1 addition & 1 deletion p-token/src/processor/shared/initialize_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use pinocchio::{
sysvars::{rent::Rent, Sysvar},
ProgramResult,
};
use token_interface::{
use spl_token_interface::{
error::TokenError,
native_mint::is_native_mint,
state::{
Expand Down
2 changes: 1 addition & 1 deletion p-token/src/processor/shared/initialize_multisig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use pinocchio::{
sysvars::{rent::Rent, Sysvar},
ProgramResult,
};
use token_interface::{
use spl_token_interface::{
error::TokenError,
state::{load_mut_unchecked, multisig::Multisig, Initializable},
};
Expand Down
2 changes: 1 addition & 1 deletion p-token/src/processor/shared/mint_to.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use pinocchio::{account_info::AccountInfo, program_error::ProgramError, ProgramResult};
use token_interface::{
use spl_token_interface::{
error::TokenError,
state::{account::Account, load_mut, mint::Mint},
};
Expand Down
2 changes: 1 addition & 1 deletion p-token/src/processor/shared/toggle_account_state.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use pinocchio::{account_info::AccountInfo, program_error::ProgramError, ProgramResult};
use token_interface::{
use spl_token_interface::{
error::TokenError,
state::{account::Account, account_state::AccountState, load, load_mut, mint::Mint},
};
Expand Down
2 changes: 1 addition & 1 deletion p-token/src/processor/shared/transfer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use pinocchio::{account_info::AccountInfo, program_error::ProgramError, ProgramResult};
use token_interface::{
use spl_token_interface::{
error::TokenError,
state::{account::Account, load, load_mut, load_mut_unchecked, mint::Mint},
};
Expand Down
2 changes: 1 addition & 1 deletion p-token/src/processor/sync_native.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use pinocchio::{account_info::AccountInfo, program_error::ProgramError, ProgramResult};
use token_interface::{
use spl_token_interface::{
error::TokenError,
state::{account::Account, load_mut},
};
Expand Down
2 changes: 1 addition & 1 deletion p-token/src/processor/ui_amount_to_amount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use core::str::from_utf8;
use pinocchio::{
account_info::AccountInfo, program::set_return_data, program_error::ProgramError, ProgramResult,
};
use token_interface::{
use spl_token_interface::{
error::TokenError,
state::{load, mint::Mint},
};
Expand Down
2 changes: 1 addition & 1 deletion p-token/tests/initialize_mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use solana_sdk::{
system_instruction,
transaction::Transaction,
};
use token_interface::state::mint::Mint;
use spl_token_interface::state::mint::Mint;

#[test_case::test_case(TOKEN_PROGRAM_ID ; "p-token")]
#[tokio::test]
Expand Down
2 changes: 1 addition & 1 deletion p-token/tests/initialize_mint2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use solana_sdk::{
system_instruction,
transaction::Transaction,
};
use token_interface::state::mint::Mint;
use spl_token_interface::state::mint::Mint;

#[test_case::test_case(TOKEN_PROGRAM_ID ; "p-token")]
#[tokio::test]
Expand Down
2 changes: 1 addition & 1 deletion p-token/tests/setup/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use solana_sdk::{
program_error::ProgramError, pubkey::Pubkey, signature::Keypair, signer::Signer,
system_instruction, transaction::Transaction,
};
use token_interface::state::mint::Mint;
use spl_token_interface::state::mint::Mint;

pub async fn initialize(
context: &mut ProgramTestContext,
Expand Down
2 changes: 1 addition & 1 deletion p-token/tests/setup/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ pub mod account;
#[allow(dead_code)]
pub mod mint;

pub const TOKEN_PROGRAM_ID: Pubkey = Pubkey::new_from_array(token_interface::program::ID);
pub const TOKEN_PROGRAM_ID: Pubkey = Pubkey::new_from_array(spl_token_interface::program::ID);
8 changes: 4 additions & 4 deletions program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
name = "spl-token"
version = "7.0.0"
description = "Solana Program Library Token"
authors = ["Anza Maintainers <[email protected]>"]
repository = "https://github.com/solana-program/token"
license = "Apache-2.0"
edition = "2021"
authors = { workspace = true}
repository = { workspace = true}
license = { workspace = true}
edition = { workspace = true}

[features]
no-entrypoint = []
Expand Down
7 changes: 5 additions & 2 deletions scripts/utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,11 @@ export function getProgramFolders() {
}

export function getAllProgramFolders() {
return getCargo().workspace.members.filter((member) =>
(getCargo(member).lib?.['crate-type'] ?? []).includes('cdylib')
return getCargo().workspace.members.filter(
(member) =>
(getCargo(member).lib?.['crate-type'] ?? []).includes('cdylib') &&
// Exclude the pinocchio-token-program crate.
getCargo(member).package?.name !== 'pinocchio-token-program'
);
}

Expand Down
Loading