Skip to content

Commit

Permalink
feat: added lamportsToSol (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
nickfrosty authored Feb 24, 2025
1 parent 5dd8366 commit 9e01463
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/silver-pumas-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"gill": minor
---

added `lamportsToSol` function
13 changes: 11 additions & 2 deletions packages/gill/src/core/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { SolanaClusterMoniker } from "../types";
import { GENESIS_HASH } from "./const";
import type { KeyPairSigner } from "@solana/signers";
import type { Address } from "@solana/addresses";
import type { SolanaClusterMoniker } from "../types";
import { GENESIS_HASH, LAMPORTS_PER_SOL } from "./const";

/**
* Determine the Solana moniker from its genesis hash
Expand All @@ -24,3 +24,12 @@ export function getMonikerFromGenesisHash(hash: string): SolanaClusterMoniker |
export function checkedAddress(input: KeyPairSigner | Address): Address {
return typeof input == "string" ? input : input.address;
}

/**
* Convert a lamport number to the human readable string of a SOL value
*/
export function lamportsToSol(lamports: bigint | number): string {
return new Intl.NumberFormat("en-US", { maximumFractionDigits: 9 }).format(
Number(lamports) / LAMPORTS_PER_SOL,
);
}

0 comments on commit 9e01463

Please sign in to comment.