solores
Solana IDL to Rust client / CPI interface generator.
solita, light of my life, fire of my loins
This software is still in its early stages of development. USE AT YOUR OWN RISK.
Contents
Supported IDL Formats
Installation
cargo install solores
to install the CLI binary.
Examples
Shank IDL
Lets say you had the following shank generated IDL, my_token_idl.json
:
Running solores my_token_idl.json
should generate a my_token_interface
rust crate that allows you to use it in an on-chain program as so:
use ;
use ;
or in a client-side app:
use ;
The crate will also export the instructions' discriminant as consts, and any error types defined in the IDL as an enum convertible to/from u32.
Anchor IDL
The usage for anchor IDLs is essentially the same as Shank IDL's. The crate will also export all accounts' discriminant as consts.
Features
Instruction Function Generics
The generated *_ix()
function parameters are genericized over any type that impls Into<*Keys>
for the first arg and any type that impls Into<*Args>
for the second arg. This allows users to easily implement, for example, account structs that compute/retrieve known pubkeys (like PDAs) at runtime:
use ;
use Pubkey;
;
// Now you can do:
// let ix = transfer_ix(
// &MyTransferKeys { src: my_pubkey },
// MyTransferArgs {},
// );
Comparison to similar libs
anchor-gen
Compared to anchor-gen, solores:
-
Has no dependency on anchor. The generated crate's dependencies are borsh + solana-program, and also thiserror + num-derive + num-traits if the idl contains error enum definitions.
-
Produces (almost) human-readable rust code in a new, separate crate instead of using a proc-macro.
-
Exposes lower-level constructs such as functions for creating the
solana_program::instruction::Instruction
struct to allow for greater customizability.
Known Missing Features
Please check the repo's issues list for more.
Anchor
- Does not handle account namespaces
- Does not handle the state instruction namespace