@wuwei-labs/srsly
Version:
TypeScript SDK for SRSLY
39 lines • 1.38 kB
TypeScript
/**
* @purpose SOL parameter conversion utilities
*
* Converts user-friendly SOL amounts to lamports (smallest unit) for use with Solana programs.
* 1 SOL = 1,000,000,000 lamports (9 decimal places)
*/
/**
* SOL parameter type
*
* Accepts either:
* - Plain `number` / `bigint` — interpreted as **lamports** (smallest unit)
* - `{ sol: number }` — convenience form for whole SOL with decimals
* - `{ lamports: number | bigint }` — explicit smallest unit (same as a bare number)
*
* Bare numbers default to lamports because the on-chain program operates
* in lamports — `convertSol(1)` is 1 lamport, not 1 SOL. Pass `{ sol: 1 }`
* for one whole SOL.
*/
export type SolParam = number | bigint | {
sol: number;
} | {
lamports: number | bigint;
};
/**
* Convert SOL parameter to lamports (smallest unit)
*
* @param amount - Amount in any supported format
* @returns Amount in lamports as bigint (u64 for Solana program)
* @throws Error if amount is invalid, negative, or non-integer lamports
*
* @example
* ```typescript
* convertSol(10_000_000) // 10_000_000n lamports (0.01 SOL)
* convertSol({ sol: 0.1 }) // 100_000_000n lamports (0.1 SOL)
* convertSol({ lamports: 10_000_000 }) // 10_000_000n lamports
* ```
*/
export declare function convertSol(amount: SolParam): bigint;
//# sourceMappingURL=sol.d.ts.map