LUMOS + Anchor: Solana 개발을 위한 완벽한 콤보
발행: (2025년 12월 18일 오전 08:14 GMT+9)
4 min read
원문: Dev.to
Source: Dev.to
개요
LUMOS는 Anchor와 함께 작동하여 Solana 개발을 간소화합니다. 단일 .lumos 스키마에서 Anchor와 호환되는 Rust 및 TypeScript 코드를 직접 생성하며, 타입과 IDL을 자동으로 동기화합니다.
비교
| LUMOS 없이 | LUMOS와 함께 |
|---|---|
| Rust 구조체를 수동으로 작성 | .lumos 스키마에 한 번 정의 |
| TypeScript 타입을 수동으로 작성 | TypeScript 자동 생성 |
| Rust ↔ TS가 동기화되길 기대 | 동기화 보장 (동일한 소스) |
| 계정 공간을 수동으로 계산 | LEN 상수 자동 계산 |
| IDL을 수동으로 작성하거나 추출 | 스키마에서 IDL 자동 생성 |
예시 스키마 (game.lumos)
#[solana]
#[account]
struct GameConfig {
authority: PublicKey,
max_players: u32,
entry_fee: u64,
prize_pool: u64,
}
#[solana]
#[account]
struct Player {
wallet: PublicKey,
game: PublicKey,
score: u64,
joined_at: i64,
}
#[solana]
enum GameInstruction {
Initialize { max_players: u32, entry_fee: u64 },
JoinGame,
UpdateScore { score: u64 },
ClaimPrize,
}
코드 생성
lumos anchor generate game.lumos \
--name game_program \
--typescript
이 명령은 다음과 같은 프로젝트 레이아웃을 생성합니다:
game_program/
├── programs/game_program/
│ ├── src/
│ │ ├── lib.rs # Program entry point
│ │ └── state.rs # Account structs
│ └── Cargo.toml
├── target/idl/
│ └── game_program.json # Anchor IDL
└── client/
└── game_program.ts # TypeScript client
CLI 옵션
lumos anchor generate [OPTIONS]
| 옵션 | 설명 |
|---|---|
-o, --output | 출력 디렉터리 |
-n, --name | 프로그램 이름 |
-V, --version | 프로그램 버전 (기본값: 0.1.0) |
-a, --address | 프로그램 주소 |
--typescript | TypeScript 클라이언트 생성 |
--dry-run | 작성 없이 미리 보기 |
추가 플래그 예시
lumos anchor generate game.lumos \
--name my_game \
--version 1.0.0 \
--address "Game111111111111111111111111111111111111111" \
--typescript
다른 유용한 명령:
lumos anchor idl game.lumos --pretty -o target/idl/game.json
lumos anchor space game.lumos --format rust
생성된 Rust 코드 (state.rs)
use anchor_lang::prelude::*;
#[account]
pub struct GameConfig {
pub authority: Pubkey,
pub max_players: u32,
pub entry_fee: u64,
pub prize_pool: u64,
}
impl GameConfig {
pub const LEN: usize = 8 + 32 + 4 + 8 + 8; // 60 bytes
}
#[account]
pub struct Player {
pub wallet: Pubkey,
pub game: Pubkey,
pub score: u64,
pub joined_at: i64,
}
impl Player {
pub const LEN: usize = 8 + 32 + 32 + 8 + 8; // 88 bytes
}
생성된 TypeScript 클라이언트 (game_program.ts)
import { PublicKey } from '@solana/web3.js';
import * as borsh from '@coral-xyz/borsh';
export interface GameConfig {
authority: PublicKey;
maxPlayers: number;
entryFee: number;
prizePool: number;
}
export const GameConfigSchema = borsh.struct([
borsh.publicKey('authority'),
borsh.u32('maxPlayers'),
borsh.u64('entryFee'),
borsh.u64('prizePool'),
]);
사용 사례 및 권장 사항
| 시나리오 | 권장 사항 |
|---|---|
| 새 Anchor 프로젝트 시작 | ✅ LUMOS 사용 |
| 기존 프로젝트, 타입 동기화 필요 | ✅ LUMOS 사용 |
| 계정 타입이 적은 간단한 프로그램 | ⚠️ 둘 다 가능 |
| 공유 타입이 많은 복잡한 프로그램 | ✅ LUMOS 사용 |
| Rust/TS 개발자가 혼합된 팀 | ✅ LUMOS 사용 |
결론
Anchor 프로그램용 TypeScript 클라이언트를 작성한다면, LUMOS는 중복 타입 정의를 유지할 필요를 없애고 Rust와 TS를 완벽히 동기화합니다.
설치
cargo install lumos-cli
lumos anchor generate schema.lumos --typescript
참고 자료
- 문서:
- GitHub: