-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolve comments. Fix minor bug tih token size calculation based on e…
…xtensions array.
- Loading branch information
calintje
committed
Nov 14, 2024
1 parent
71a7d7b
commit 51bc3a0
Showing
5 changed files
with
180 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { fetchSysvarRent } from "@solana/sysvars" | ||
import { GetAccountInfoApi, lamports, Rpc } from "@solana/web3.js"; | ||
import type { Lamports } from "@solana/web3.js"; | ||
|
||
/** | ||
* The overhead storage size for accounts. | ||
*/ | ||
const ACCOUNT_STORAGE_OVERHEAD = 128; | ||
|
||
/** | ||
* Calculates the minimum balance required for rent exemption for a given account size. | ||
* | ||
* @param {Rpc} rpc - The Solana RPC client to fetch sysvar rent data. | ||
* @param {number} dataSize - The size of the account data in bytes. | ||
* @returns {Promise<BigInt>} The minimum balance required for rent exemption in lamports. | ||
*/ | ||
export async function calculateMinimumBalance(rpc: Rpc<GetAccountInfoApi>, dataSize: number): Promise<Lamports> { | ||
const rent = await fetchSysvarRent(rpc); | ||
const actualDataLen = BigInt(dataSize + ACCOUNT_STORAGE_OVERHEAD); | ||
const rentLamportsPerYear = rent.lamportsPerByteYear * actualDataLen; | ||
const minimumBalance = rentLamportsPerYear * BigInt(Math.floor(rent.exemptionThreshold)); | ||
|
||
return lamports(minimumBalance) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.