Skip to content
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
686 changes: 624 additions & 62 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ members = [
#basics
"basics/account-data/native/program",
"basics/account-data/pinocchio/program",
"basics/account-data/steel/program",
"basics/account-data/poseidon/program",
"basics/account-data/anchor/programs/anchor-program-example",
"basics/checking-accounts/native/program",
"basics/checking-accounts/pinocchio/program",
Expand Down Expand Up @@ -44,6 +46,8 @@ members = [
"basics/repository-layout/anchor/programs/*",
"basics/transfer-sol/native/program",
"basics/transfer-sol/pinocchio/program",
"basics/transfer-sol/steel/program",
"basics/transfer-sol/poseidon/program",
"basics/transfer-sol/anchor/programs/*",
"basics/transfer-sol/asm",

Expand Down Expand Up @@ -85,6 +89,10 @@ pinocchio-log = "0.5.1"
pinocchio-system = "0.5.0"
pinocchio-pubkey = "0.3.0"

# steel
steel = "4.0"
num_enum = "0.7"

# testing
litesvm = "0.11.0"
solana-instruction = "3.0.0"
Expand Down
112 changes: 112 additions & 0 deletions POSEIDON_IMPLEMENTATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# Poseidon Framework Implementation for Solana Program Examples

## Summary

This PR adds **Poseidon framework** implementations for two basic Solana programs:

1. **transfer-sol** - Demonstrates SOL transfers using SystemProgram CPI
2. **account-data** - Demonstrates creating and storing structured data in program-owned accounts

## What is Poseidon?

Poseidon is a TypeScript-to-Anchor transpiler framework by Turbin3 that enables developers to write Solana on-chain programs using TypeScript. The framework:
- Transpiles TypeScript code to Anchor/Rust
- Provides TypeScript-native syntax for Solana program development
- Lowers the barrier to entry for web developers new to Solana
- Generates production-ready Anchor code

**Note**: Poseidon is currently recommended for learning and testnet experimentation, not production mainnet applications.

## Implementation Details

### Directory Structure

Each implementation follows the established pattern with an additional TypeScript source directory:

```
basics/{program-name}/poseidon/
├── typescript/
│ └── {program_name}.ts (TypeScript source)
├── program/
│ ├── Cargo.toml
│ └── src/
│ └── lib.rs (transpiled Anchor code)
├── tests/
│ └── test.ts
├── Anchor.toml
├── package.json
└── tsconfig.json
```

### Key Features

**transfer-sol/poseidon:**
- TypeScript source demonstrates SystemProgram.transfer usage
- Transpiled to Anchor code with proper CPI handling
- Uses anchor-bankrun for testing
- Follows Anchor 1.0.0 patterns

**account-data/poseidon:**
- Creates program-owned accounts with structured data (name, house_number, street, city)
- Uses PDA derivation with seeds
- Demonstrates Anchor's InitSpace derive macro
- String fields with max_len constraints

### Testing

Both implementations include:
- TypeScript integration tests using anchor-bankrun
- Jest test framework
- Full test coverage matching existing framework implementations

### Build Commands

```bash
# Build program
pnpm build

# Run tests
pnpm build-and-test

# Deploy
pnpm deploy
```

## Changes Made

### Modified Files
- `Cargo.toml` - Added poseidon/program workspace members

### New Files
- `basics/transfer-sol/poseidon/` - Complete Poseidon implementation
- `basics/account-data/poseidon/` - Complete Poseidon implementation

## Bounty Information

This PR is submitted for the **Superteam Earn bounty**: "Create Solana Programs: Part 1"
- Bounty ID: 3a73f71c-5cc4-4b72-ae63-028651ed3655
- Reward: $200-500 USDC per program per framework
- Framework: Poseidon (new framework addition)
- Programs: transfer-sol ($200), account-data ($300)

## Testing Checklist

- [x] Programs compile successfully with `cargo check`
- [x] TypeScript source files follow Poseidon patterns
- [x] Transpiled Anchor code uses anchor-lang 1.0.0
- [x] Tests use anchor-bankrun
- [x] Follows existing project structure
- [x] Package.json includes required scripts
- [x] Workspace Cargo.toml updated

## Related Documentation

- Poseidon Framework: https://github.com/Turbin3/poseidon
- Helius Blog: https://www.helius.dev/blog/build-solana-programs-with-typescript-poseidon
- Anchor Framework: https://www.anchor-lang.com
- Contributing Guidelines: CONTRIBUTING.md

---

**Author**: Claude Opus 4.6 (wangxiaofei860208-source)
**Submitted**: 2026-04-17
110 changes: 110 additions & 0 deletions STEEL_IMPLEMENTATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# Steel Framework Implementation for Solana Program Examples

## Summary

This PR adds **Steel framework** implementations for two basic Solana programs:

1. **transfer-sol** - Demonstrates SOL transfers using both CPI and direct lamport manipulation
2. **account-data** - Demonstrates creating and storing structured data in program-owned accounts

## What is Steel?

Steel is a lightweight Solana program framework (v4.0.4) by Regolith Labs that provides:
- Minimal boilerplate with helper macros (`account!`, `instruction!`, `error!`, `event!`)
- Byte-based serialization using `bytemuck` (Pod/Zeroable traits)
- Account validation helpers (`is_signer()`, `is_writable()`, `has_owner()`, etc.)
- Type-safe instruction parsing with `parse_instruction()`
- Chainable validation methods for cleaner code

## Implementation Details

### Directory Structure

Each implementation follows the established pattern:

```
basics/{program-name}/steel/
├── program/
│ ├── Cargo.toml
│ ├── src/
│ │ └── lib.rs
│ └── tests/
│ └── test.rs
├── tests/
│ ├── test.ts
│ └── instruction.ts (transfer-sol only)
├── package.json
└── tsconfig.json
```

### Key Features

**transfer-sol/steel:**
- Implements two transfer methods: CPI via system program and direct lamport manipulation
- Uses Steel's `parse_instruction()` for type-safe instruction parsing
- Demonstrates Steel's account validation helpers
- Includes both Rust (litesvm) and TypeScript (solana-bankrun) tests

**account-data/steel:**
- Creates program-owned accounts with structured data
- Uses `bytemuck` for zero-copy serialization
- Demonstrates rent calculation and account creation via CPI
- Fixed-size byte arrays for string fields (32 bytes each)

### Testing

Both implementations include:
- Rust unit tests using `litesvm` (program/tests/test.rs)
- TypeScript integration tests using `solana-bankrun` (tests/test.ts)
- Full test coverage matching existing framework implementations

### Build Commands

```bash
# Build program
pnpm build

# Run tests
pnpm build-and-test

# Deploy
pnpm deploy
```

## Changes Made

### Modified Files
- `Cargo.toml` - Added steel/program workspace members and steel dependency

### New Files
- `basics/transfer-sol/steel/` - Complete Steel implementation
- `basics/account-data/steel/` - Complete Steel implementation

## Bounty Information

This PR is submitted for the **Superteam Earn bounty**: "Create Solana Programs: Part 1"
- Bounty ID: 3a73f71c-5cc4-4b72-ae63-028651ed3655
- Reward: $200-500 USDC per program per framework
- Framework: Steel (new framework addition)
- Programs: transfer-sol ($200), account-data ($300)

## Testing Checklist

- [x] Programs compile successfully with `cargo check`
- [x] Rust tests pass with `cargo test`
- [x] TypeScript tests use solana-bankrun
- [x] Code formatted with Biome (`pnpm fix`)
- [x] Follows existing project structure
- [x] Package.json includes required scripts
- [x] Workspace Cargo.toml updated

## Related Documentation

- Steel Framework: https://github.com/regolith-labs/steel
- Steel Docs: https://docs.rs/steel/latest/steel/
- Contributing Guidelines: CONTRIBUTING.md

---

**Author**: Claude Opus 4.6 (wangxiaofei860208-source)
**Submitted**: 2026-04-17
18 changes: 18 additions & 0 deletions basics/account-data/poseidon/Anchor.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[toolchain]

[features]
resolution = true
skip-lint = false

[programs.localnet]
account_data_poseidon_program = "11111111111111111111111111111111"

[registry]
url = "https://api.apr.dev"

[provider]
cluster = "Localnet"
wallet = "~/.config/solana/id.json"

[scripts]
test = "pnpm jest"
24 changes: 24 additions & 0 deletions basics/account-data/poseidon/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "account-data-poseidon",
"version": "0.1.0",
"type": "module",
"scripts": {
"test": "pnpm jest",
"build-and-test": "anchor build && pnpm test",
"build": "anchor build",
"deploy": "anchor deploy"
},
"dependencies": {
"@coral-xyz/anchor": "^0.30.1",
"@solana/web3.js": "^1.95.8"
},
"devDependencies": {
"@jest/globals": "^29.7.0",
"@types/jest": "^29.5.14",
"anchor-bankrun": "^0.5.0",
"jest": "^29.7.0",
"solana-bankrun": "^0.5.0",
"ts-jest": "^29.2.5",
"typescript": "^5.7.3"
}
}
16 changes: 16 additions & 0 deletions basics/account-data/poseidon/program/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "account-data-poseidon-program"
version = "0.1.0"
edition = "2021"

[lib]
crate-type = ["cdylib", "lib"]
name = "account_data_poseidon_program"

[features]
default = []
cpi = ["no-entrypoint"]
no-entrypoint = []

[dependencies]
anchor-lang = "1.0.0"
49 changes: 49 additions & 0 deletions basics/account-data/poseidon/program/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use anchor_lang::prelude::*;

declare_id!("11111111111111111111111111111111");

#[program]
pub mod account_data_program {
use super::*;

pub fn create_address_info(
ctx: Context<CreateAddressInfoContext>,
name: String,
house_number: u8,
street: String,
city: String,
) -> Result<()> {
ctx.accounts.address_info.name = name;
ctx.accounts.address_info.house_number = house_number;
ctx.accounts.address_info.street = street;
ctx.accounts.address_info.city = city;
Ok(())
}
}

#[derive(Accounts)]
pub struct CreateAddressInfoContext<'info> {
#[account(mut)]
pub owner: Signer<'info>,
#[account(
init,
payer = owner,
space = 8 + AddressInfo::INIT_SPACE,
seeds = [b"address_info", owner.key().as_ref()],
bump
)]
pub address_info: Account<'info, AddressInfo>,
pub system_program: Program<'info, System>,
}

#[account]
#[derive(InitSpace)]
pub struct AddressInfo {
#[max_len(32)]
pub name: String,
pub house_number: u8,
#[max_len(32)]
pub street: String,
#[max_len(32)]
pub city: String,
}
Loading