fermat-solana
Solana/Anchor integration for fermat-core.
Provides Borsh serialization, SPL token amount conversions, and Anchor account helpers for the Decimal type.
Features
DecimalBorsh— 17-byte on-chain encoding (i128LE +u8scale), validatesscale <= 28on deserialization- SPL token conversions —
token_amount_to_decimal,decimal_to_token_amountwith explicit rounding - Anchor account helpers —
DECIMAL_SPACE = 17,DecimalBorsh::zero_with_scalefor accountinit
Installation
[]
= "0.1"
= "0.1"
Quick Start
use RoundingMode;
use ;
// 1_500_000 raw USDC lamports -> 1.500000 Decimal
let price = token_amount_to_decimal?;
// Convert back — round down on withdrawal (conservative)
let raw = decimal_to_token_amount?;
assert_eq!;
Anchor Account Usage
use ;
Modules
| Module | Contents |
|---|---|
borsh_impl |
DecimalBorsh wrapper — 17-byte encoding, adversarial scale validation |
token |
token_amount_to_decimal, decimal_to_token_amount, align_to_mint |
account |
DECIMAL_SPACE = 17, DecimalBorsh::zero_with_scale for Anchor init |
See Also
- fermat-core — core arithmetic library
- GitHub — full repository
- fermatmath.net — project website
License
Licensed under either MIT or Apache-2.0 at your option.
Copyright 2026 XXIX Labs