Skip to content

Commit f3d50b4

Browse files
Bumping anchor version and adding discrim for compatibility (#245)
* Bumping anchor version and adding discrim for compatibility * Making const static to reflect trait
1 parent 8614f4b commit f3d50b4

File tree

5 files changed

+112
-13
lines changed

5 files changed

+112
-13
lines changed

CLAUDE.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Essential Commands
6+
7+
### Building and Development
8+
- `pnpm install` - Install workspace dependencies
9+
- `pnpm programs:build` - Build all Rust programs and fetch dependencies
10+
- `pnpm programs:test` - Run Rust program tests
11+
- `pnpm programs:debug` - Run Rust program tests with logs enabled
12+
- `pnpm clients:js:test` - Run JavaScript client tests
13+
- `pnpm clients:rust:test` - Run Rust client tests
14+
- `pnpm generate` - Generate IDLs and clients (shortcut for both commands below)
15+
- `pnpm generate:idls` - Generate IDLs from Rust programs using Shank
16+
- `pnpm generate:clients` - Generate client libraries using Kinobi
17+
18+
### Testing and Quality
19+
- `pnpm lint` - Run linting for both JS client and Rust programs
20+
- `pnpm lint:fix` - Auto-fix linting issues and format code
21+
- `cd clients/js && pnpm test` - Run specific JS client tests
22+
- `cd clients/js && pnpm build` - Build JS client
23+
- `cargo test-bpf` - Run Rust program tests (from program directory)
24+
- `cargo build-bpf` - Build Rust program (from program directory)
25+
26+
### Local Development
27+
- `pnpm validator` - Start local validator with program deployed
28+
- `pnpm validator:debug` - Start local validator with logs
29+
- `pnpm validator:stop` - Stop local validator
30+
- `pnpm validator:logs` - Show validator logs
31+
32+
## Architecture Overview
33+
34+
### Multi-Language Workspace Structure
35+
This repository contains both Rust programs and multiple client libraries:
36+
- **Rust Program**: `programs/mpl-core/` - The on-chain Solana program
37+
- **JavaScript Client**: `clients/js/` - Umi-compatible JS library
38+
- **Rust Client**: `clients/rust/` - Rust client library
39+
- **Python Client**: `clients/python/` - Python client (minimal)
40+
41+
### Program Architecture (Rust)
42+
The core program follows a modular plugin-based architecture:
43+
- **State Management**: `state/` - Asset, Collection, and other core data structures
44+
- **Plugin System**: `plugins/` - Extensible plugin architecture with three categories:
45+
- `internal/authority_managed/` - Collection-level plugins (royalties, attributes, etc.)
46+
- `internal/owner_managed/` - Asset-level plugins (freeze, burn, transfer delegates)
47+
- `internal/permanent/` - Immutable plugins (edition, permanent delegates)
48+
- `external/` - External plugin adapters for third-party extensions
49+
- **Processors**: `processor/` - Instruction handlers for all program operations
50+
- **Instructions**: Core operations like create, transfer, burn, plugin management
51+
52+
### Client Generation Workflow
53+
1. Rust program code defines the on-chain interface using Shank annotations
54+
2. `pnpm generate:idls` extracts IDL (Interface Definition Language) files
55+
3. `pnpm generate:clients` uses Kinobi to generate client code from IDLs
56+
4. Generated client code appears in `clients/js/src/generated/`
57+
5. Hand-written client code in `clients/js/src/` provides higher-level APIs
58+
59+
### Key Plugin Types
60+
- **FreezeDelegate**: Allows freezing/unfreezing assets
61+
- **BurnDelegate**: Permits burning assets
62+
- **TransferDelegate**: Enables transfers on behalf of owner
63+
- **Royalties**: Collection-level royalty enforcement
64+
- **Attributes**: On-chain metadata storage
65+
- **MasterEdition**: Print/edition functionality
66+
- **External Adapters**: Third-party plugin integration (Oracle, AppData, etc.)
67+
68+
## Development Patterns
69+
70+
### Code Generation
71+
- Never edit files in `clients/js/src/generated/` - they are auto-generated
72+
- Run `pnpm generate` after making changes to Rust program interfaces
73+
- Use Kinobi visitors in `configs/kinobi.cjs` for client customization
74+
75+
### Testing
76+
- Program tests are written in Rust using the standard test framework
77+
- Client tests use AVA framework and require a running validator
78+
- Tests often use generated keypairs and work with both individual assets and collections
79+
80+
### Plugin Development
81+
- New internal plugins go in appropriate `plugins/internal/` subdirectory
82+
- External plugin adapters use the external plugin system
83+
- Plugins have distinct authority models (owner-managed vs authority-managed)
84+
85+
### Asset Hierarchy
86+
- **Collections**: Optional grouping mechanism with shared plugins
87+
- **Assets**: Core NFT-like digital assets that can belong to collections
88+
- **Plugin Inheritance**: Assets inherit authority-managed plugins from their collection

Cargo.lock

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

clients/rust/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ version = "0.11.0"
1111
crate-type = ["cdylib", "lib"]
1212

1313
[features]
14-
anchor = ["dep:anchor-lang"]
14+
anchor = ["dep:anchor-lang", "kaigan/anchor"]
1515
serde = ["dep:serde", "dep:serde_with"]
1616
test-sbf = []
1717

1818
[dependencies]
19-
anchor-lang = { version = "0.31.0", optional = true }
19+
anchor-lang = { version = "0.31.1", optional = true }
2020
base64 = "0.22.0"
2121
borsh = "^0.10"
2222
modular-bitfield = "0.11.2"
@@ -29,7 +29,7 @@ serde_with = { version = "^3.0", optional = true }
2929
solana-program = "2.2.1"
3030
thiserror = "^1.0"
3131

32-
kaigan = { version = "0.2.6", features = ["serde"], optional = false }
32+
kaigan = { version = "0.3.0",features = ["serde"], optional = false }
3333

3434
[dev-dependencies]
3535
assert_matches = "1.5.0"

clients/rust/src/hooked/advanced_types.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ use crate::{
1010
types::{
1111
AddBlocker, AppData, Attributes, Autograph, BubblegumV2, BurnDelegate, DataSection,
1212
Edition, ExternalCheckResult, ExternalPluginAdapter, ExternalPluginAdapterKey,
13-
ExternalPluginAdapterType, FreezeDelegate, FreezeExecute, ImmutableMetadata, Key,
14-
LifecycleHook, LinkedAppData, LinkedLifecycleHook, MasterEdition, Oracle,
15-
PermanentBurnDelegate, PermanentFreezeDelegate, PermanentTransferDelegate, PluginAuthority,
16-
Royalties, TransferDelegate, UpdateDelegate, VerifiedCreators,
13+
FreezeDelegate, FreezeExecute, ImmutableMetadata, Key, LifecycleHook, LinkedAppData,
14+
LinkedLifecycleHook, MasterEdition, Oracle, PermanentBurnDelegate, PermanentFreezeDelegate,
15+
PermanentTransferDelegate, PluginAuthority, Royalties, TransferDelegate, UpdateDelegate,
16+
VerifiedCreators,
1717
},
1818
};
1919

clients/rust/src/hooked/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ mod anchor_impl {
9696

9797
// Not used but needed for Anchor.
9898
impl Discriminator for BaseAssetV1 {
99-
const DISCRIMINATOR: &[u8] = &[0u8; 8];
99+
const DISCRIMINATOR: &'static [u8] = &[Key::AssetV1 as u8];
100100
}
101101

102102
impl Owner for BaseAssetV1 {
@@ -118,7 +118,7 @@ mod anchor_impl {
118118

119119
// Not used but needed for Anchor.
120120
impl Discriminator for BaseCollectionV1 {
121-
const DISCRIMINATOR: &[u8] = &[0u8; 8];
121+
const DISCRIMINATOR: &'static [u8] = &[Key::CollectionV1 as u8];
122122
}
123123

124124
impl Owner for BaseCollectionV1 {

0 commit comments

Comments
 (0)