#entrypoint #solana #programs

nitrate

A custom lightweight entrypoint for Solana programs

2 unstable releases

0.1.0 May 2, 2024
0.0.0 Apr 29, 2024

#4 in #entrypoint

Apache-2.0

40KB
455 lines

nitrate

Nitrate

A custom lightweight entrypoint for Solana programs.

Getting started

From your project folder:

cargo add nitrate

On your entrypoint definition:

use nitrate::{entrypoint, program::AccountInfo};
use solana_program::{
    entrypoint::ProgramResult,
    msg,
    pubkey::Pubkey,
};

// custom entrypoint definition:
//
//   1. name of the process instruction function
//   2. expected number of accounts
entrypoint!(process_instruction, 10);

pub fn process_instruction(
    program_id: &Pubkey,
    accounts: &[AccountInfo],
    instruction_data: &[u8],
) -> ProgramResult {
    msg!("Hello from my program!");

    Ok(())
}

The main difference from the standard entrypoint! macro is that nitrate represents an entrypoint that does not perform allocations or copies when reading the input buffer, and therefore uses less compute units to parse the input accounts.

The entrypoint is bundled with a companion macro and program types crates.

[!IMPORTANT] A program can receive more than the specified maximum number of accounts, but any account exceeding the maximum will be ignored. On an ideal scenario, this number should be equal to the number of accounts required by the largest instruction of your program.

License

Copyright (c) 2024 nifty-oss maintainers

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Dependencies

~17–26MB
~433K SLoC