What Is an Interest Bearing Mint?
The Token Extension Program’sInterestBearingConfig mint extension lets a
mint store an annualized interest rate directly onchain.
Interest bearing tokens do not add more tokens to token accounts over time.
The token amount stored in each token account stays the same until a token
program instruction changes it, such as minting, transferring, or burning.
As time passes, the calculated UI amount with interest can increase even though
the token amount and token supply stay the same.
Security: Do math on raw amountsPrograms should compute balances, shares, and prices from the raw
amount
in the token account. The UI amount changes with time and with the rate the
rate authority sets, so logic that mixes UI amounts with raw amounts
produces wrong values. Convert to UI amounts only for display.How Historical Rate Changes Are Calculated
InterestBearingConfigstoresinitialization_timestamp,pre_update_average_rate,last_update_timestamp, andcurrent_rate.amount_to_ui_amountcalculates the UI amount in two steps: it first calculates interest from initialization tolast_update_timestampusingpre_update_average_rate, then calculates interest fromlast_update_timestampto the current timestamp usingcurrent_rate.- When
UpdateRateruns,process_update_ratecallstime_weighted_average_rateand updatespre_update_average_rateto a new time-weighted historical average, then records a newlast_update_timestampandcurrent_rate. - After rate changes over time, the earlier changes are represented by
pre_update_average_rate, while the period fromlast_update_timestampto the current time is calculated withcurrent_rate.
Before you start
The examples on this page run against a local validator athttp://localhost:8899 (WebSocket ws://localhost:8900) and fund their
accounts with airdrops from it. Start one in a separate terminal with
Surfpool (surfpool start) or
solana-test-validator.
Each code section below lists the packages or crates it needs. The TypeScript
examples use top-level await, so run them as ES modules, for example with
npx tsx index.ts in a project whose package.json sets "type": "module".
How to Create and Use Interest Bearing Tokens
To create and use interest bearing tokens:- Calculate the mint account size and rent needed for the mint and the
InterestBearingConfigextension. - Create the mint account with
CreateAccount, initializeInterestBearingConfig, and initialize the mint withInitializeMint. - Mint tokens as usual.
- Use
UpdateRateto change the mint’s current rate over time. - Convert token amounts into a UI amount with interest with
AmountToUiAmountor helper methods that fetch the mint account and clock sysvar, then calculate the UI amount without sending a transaction.
Offchain and Onchain UI Amount ConversionThe offchain helper path fetches the mint account and the clock sysvar, then
calculates the UI amount locally without sending a transaction. The onchain
path uses
AmountToUiAmount, which runs in the token program and returns
the UI amount in transaction return data. AmountToUiAmount can be sent
in a transaction or simulated.1
Calculate account size
Calculate the mint account size for the base mint plus the
InterestBearingConfig extension. This is the size used in
CreateAccount.2
Calculate rent
Calculate rent using the size needed for the mint plus the
InterestBearingConfig extension.3
Create the mint account
Create the mint account with the calculated space and lamports.
4
Initialize InterestBearingConfig
Initialize the
InterestBearingConfig extension on the mint.5
Initialize the mint
Initialize the mint with
InitializeMint in the same transaction.6
Create a token account and mint tokens
Create a token account for the mint, then mint tokens to that token account.
7
Calculate the UI amount with the offchain helper
Fetch the mint account and clock sysvar, then calculate the UI amount without
sending a transaction.
Instruction Order
InterestBearingMintInstruction::Initialize must come before
InitializeMint. CreateAccount,
InterestBearingMintInstruction::Initialize, and InitializeMint
must be included in the same transaction.Source Reference
| Item | Description | Source |
|---|---|---|
InterestBearingConfig | Mint extension that stores the interest rate authority, timestamps, and current and historical rates. | Source |
InterestBearingMintInstruction::Initialize | Instruction that initializes the interest bearing config before InitializeMint. | Source |
InterestBearingMintInstruction::UpdateRate | Instruction that changes the mint’s current interest rate. | Source |
AmountToUiAmount | Instruction that returns the current UI amount string for a token amount using the mint’s active config. | Source |
InterestBearingConfig::amount_to_ui_amount | Helper that converts a token amount into a UI amount with interest for a timestamp. | Source |
process_initialize | Processor logic that initializes InterestBearingConfig and records the initial timestamps and rate. | Source |
process_update_rate | Processor logic that updates the current rate, recalculates the time-weighted average rate, and records the update timestamp. | Source |
process_amount_to_ui_amount | Processor logic that returns the UI amount string using the mint’s active interest bearing configuration. | Source |
Kit
These examples use the generated Token-2022 instructions directly.Terminal
Instructions
Web3.js v3
These examples use the class-based@solana/web3.js v3 API with
@solana-program instruction builders.
Terminal
Instructions
Rust
Add these dependencies toCargo.toml (tested with Rust 1.89, 1.98, and 1.99):
Cargo.toml
Rust
Web3.js (legacy)
These examples use legacy@solana/web3.js with @solana/spl-token.
@solana/web3.js 1.x is no longer actively maintainedIt receives critical fixes only. Use Kit for new code. To migrate existing code, follow the Kit upgrade guide, or the web3.js v3 migration guide to keep the class-based API.To run this code, install 1.x with npm install @solana/web3.js@1. A plain npm install @solana/web3.js installs v3, which this code doesn’t run on.Terminal
Instructions