🏗️ Steel
Steel is a new framework for building smart contracts on Solana. It provides a library of helper functions, macros, and code patterns for implementing secure and maintainable smart contracts. Steel is generally designed to be unopinionated, minimizing boilerplate code and maximizing developer flexibility.
Notes
- Steel is under active development. All interfaces are subject to change.
- This code is unaudited. Use at your own risk
Todos
- Localnet toolchain.
- IDL generation.
-
Helper functions for simple lamport transfers. -
Helper functions to emit events (wrap sol_log_data). -
Custom error messages on account validation checks. -
Helper function to close AccountInfos (wrap realloc and lamport return). -
CLI with init script. -
Account parsers and validation.
Getting started
To start building with Steel, install the CLI:
Spin up a new project with new command:
To compile your program, use the standard Solana toolchain:
Folder structure
While not strictly enforced, we recommend organizing your Solana program with the following file structure. We have found this pattern improves code readability, separating the contract interface from its implementation, and scales well as contract complexity increases.
Cargo.toml (workspace)
⌙ api
⌙ Cargo.toml
⌙ src
⌙ consts.rs
⌙ error.rs
⌙ event.rs
⌙ instruction.rs
⌙ lib.rs
⌙ loaders.rs
⌙ sdk.rs
⌙ state
⌙ mod.rs
⌙ account_1.rs
⌙ account_2.rs
⌙ program
⌙ Cargo.toml
⌙ src
⌙ lib.rs
⌙ instruction_1.rs
⌙ instruction_2.rs
API
Steel offers a collection of simple macros for defining the interface and building blocks of your program.
Accounts
For accounts, Steel uses a single enum to manage discriminators and a struct for each account type. The account! macro helps link these types and implements basic serialization logic.
use *;
/// Enum for account discriminators.
/// Struct for account state.
account!;
Instructions
For instructions, Steel similarly uses a single enum to manage discriminators and a struct for each instruction args type. The instruction! macro helps link these types and implement basic serialization logic.
use *;
/// Enum for instruction discriminators.
/// Struct for instruction args.
/// Struct for instruction args.
instruction!;
instruction!;
Errors
Custom program errors can be created simply by defining an enum for your error messages and passing it to the error! macro.
use *;
/// Enum for error types.
error!;
Events
Similarly, custom program events can be created by defining the event struct and passing it to the event! macro.
use *;
/// Struct for logged events.
event!;
Program
In your contract implementation, Steel offers a series of composable functions to parse accounts, validate state, and execute CPIs.
Entrypoint
Steel provides a utility function to streamline the program entrypoint. Securely parse incoming instruction data and dispatch it to a handler.
use *;
use *;
use *;
use *;
entrypoint!;
Validation
Steel provides a library of composable functions for validating account data. You can chain these functions together to validate arbitrary account state and parse it into whatever type you need.
use *;
use *;
CPIs
Steel offers a handful of helper functions for executing common CPIs such as creating accounts, creating token accounts, minting tokens, burning tokens, and more.
use *;