Full lesson
inflation-resistant-token
This a set of Solana contracts written in Rust that implement an inflation-resistant token on Meteora.
What it does
From the project README:
This is a set of Solana contracts started in solang (now continuing in Rust for easy integration with Anchor) that implement a flatcoin using a DEX (Meteora) and switching over to Rust to make it easy to integrate with Solana. This is now patent pending.
- Original
- PureMoney/inflation-resistant-token
- SuperStack fork
- Blockchains/inflation-resistant-token @
8e92d49 - Stars
- 0
- Last push (original)
- 2026-10-27
- Languages
- Rust, TypeScript, JavaScript, HTML, Shell, Makefile
- Detected stack
- @solana/kitAnchorMetaplexweb3.js
- Categories
- Other
- Licence
- CC0-1.0
Architecture
62 source files. By extension: .rs ×41, .ts ×15, .js ×6.
| Top-level directory | Source files |
|---|---|
irma | 62 |
On-chain programs: irma/programs/irma
Dapp: deploying
This fork is queued for its own live dapp on Sol.College, with a Devnet/Mainnet switch. It appears here, at /dapps/inflation-resistant-token/, once it is deployed and checked on devnet. Until then, run it locally with the commands below.
Key code, explained
Excerpts chosen automatically where the code uses the most Solana concepts, pinned to the fork's commit.
irma/programs/irma/src/lib.rs L73–96 @ 8e92d49 · CC0-1.0 · original // ====================================================================// START: DEFINE ALL INSTRUCTION ACCOUNT STRUCTS HERE// ==================================================================== #[derive(Accounts)]pub struct Init<'info> { // Note: We need to qualify MAX_BACKING_COUNT with its module #[account( init, space=32 + 8 + size_of::<StableState>()*pricing::MAX_BACKING_COUNT, payer=irma_admin, seeds=[b"state_v5".as_ref()], bump )] pub state: Account<'info, StateMap>, #[account(mut)] pub irma_admin: Signer<'info>, // Space calculation for Core: // 8 bytes for discriminator // 32 bytes for owner (Pubkey) // 4 bytes for config Vec length + (max 10 configs * ~200 bytes each) = 2004 bytes // AllPosition struct: // - 4 bytes for all_positions Vec length + (max 10 positions * ~300 bytes each) = 3004 bytes // - 4 bytes for tokens Vec length + (max 20 tokens * ~200 bytes each) = 4004 bytes- Line 82
init,: Creates and pays for a new account. Space and payer must be specified. - Line 84
payer=irma_admin, seeds=[b"state_v5".as_ref()],: Declares the PDA seeds. Anchor re-derives the address and rejects the account if it doesn't match. - Line 85
bump: Uses the bump seed, the extra byte that pushes the derived address off the ed25519 curve. - Line 89
pub irma_admin: Signer<'info>,: Requires this account to have signed the transaction.
irma/commons/src/quote.rs L145–168 @ 8e92d49 · CC0-1.0 · original .ok_or("MathOverflow").unwrap(); } else { let amount_in = Bin::get_amount_in(amount_out, price, swap_for_y)?; let fee = lb_pair.compute_fee(amount_in)?; total_amount_in = total_amount_in .checked_add(amount_in) .ok_or("MathOverflow").unwrap(); total_fee = total_fee.checked_add(fee).ok_or("MathOverflow").unwrap(); amount_out = 0; } } msg!("-----> amount_out left to quote: {}, total_amount_in: {}", amount_out, total_amount_in); iterations += 1; require!(iterations < MAX_ITERATIONS, CustomError::ExceededMaxIterationsQuoteExactOut); if amount_out > 0 { lb_pair.advance_active_bin(swap_for_y)?; } else { break;- Line 151
.checked_add(amount_in): Uses checked arithmetic so overflow fails instead of wrapping. - Line 159
msg!("-----> amount_out left to quote: {}, total_amount_in: {}", amount_out, total_amount_: Logs to the program log, which is visible in explorers and the test output. - Line 162
require!(iterations < MAX_ITERATIONS, CustomError::ExceededMaxIterationsQuoteExactOut);: An explicit validation that aborts the instruction with an error.
irma/programs/irma/src/utils.rs L157–180 @ 8e92d49 · CC0-1.0 · original Ok(u64::from_le_bytes(amount_bytes))} /// Update token balance in token account datapub fn set_token_balance_in_data(token_account_data: &mut [u8], new_balance: u64) -> anyhow::Result<()> { if token_account_data.len() < 72 { msg!("Invalid token account data length"); return Ok(()); } token_account_data[64..72].copy_from_slice(&new_balance.to_le_bytes()); Ok(())} /// Create program-derived address for testingpub fn create_program_derived_address(seeds: &[&[u8]], program_id: &Pubkey) -> (Pubkey, u8) { Pubkey::find_program_address(seeds, program_id)} /// Simulate time passage for time-dependent on-chain logicpub fn simulate_time_passage(clock: &mut Clock, seconds: i64) { clock.unix_timestamp += seconds; // Approximate slot advancement (400ms per slot) clock.slot += (seconds * 1000 / 400) as u64;- Line 163
msg!("Invalid token account data length");: Logs to the program log, which is visible in explorers and the test output. - Line 173
Pubkey::find_program_address(seeds, program_id): Derives a PDA from seeds and the program ID and returns the address with its canonical bump. - Line 178
clock.unix_timestamp += seconds;: Reads on-chain time from the Clock sysvar.
irma/programs/irma/src/pricing.rs L301–324 @ 8e92d49 · CC0-1.0 · originalimpl StateMap { pub fn new() -> Self { StateMap { reserves: Vec::with_capacity(MAX_BACKING_COUNT), // Initialize with capacity for MAX_BACKING_COUNT stablecoins bump: 0, padding: [0; 7], // padding to make the size of the struct 25 * EnumCount + 8 } } /// Add a stablecoin to the reserves, maintaining the order by symbol. pub fn add_reserve(&mut self, stablecoin: StableState) { if self.contains_reserve(&stablecoin.symbol) { msg!("Stablecoin {} already exists in reserves, skipping addition.", stablecoin.symbol); return; } let clone = stablecoin.clone(); let symbol = clone.symbol; // Get the symbol from the stablecoin let i = self.reserves.partition_point(|e| e.symbol.as_str() < symbol.as_str()); self.reserves.insert(i, stablecoin); } /// Get a stablecoin by its symbol. pub fn get_stablecoin(&self, symbol: &str) -> Result<StableState> { require!(symbol.len() <= 8 && symbol.len() > 0, CustomError::InvalidBackingSymbol);- Line 305
bump: 0,: Uses the bump seed, the extra byte that pushes the derived address off the ed25519 curve. - Line 313
msg!("Stablecoin {} already exists in reserves, skipping addition.", stablecoin.symbol);: Logs to the program log, which is visible in explorers and the test output. - Line 324
require!(symbol.len() <= 8 && symbol.len() > 0, CustomError::InvalidBackingSymbol);: An explicit validation that aborts the instruction with an error.
How to run, build and test
These commands come from the repo's own manifests (package.json scripts, Anchor.toml, Cargo, go.mod, Makefile). Check the README for prerequisites and environment variables.
| Directory | Command | Runs |
|---|---|---|
irma | npm run test | ts-mocha --timeout 20000 --reporter spec --require ts-node/register tests/**/*.ts |
irma | npm run lint | prettier */*.js "*/**/*{.js,.ts}" --check |
irma/cloudflareworker_swap | npm run dev | wrangler dev |
irma/cloudflareworker_swap | npm run start | wrangler dev |
irma/cloudflareworker_swap | npm run deploy | wrangler deploy |
irma | anchor build | compile programs and generate IDLs |
irma | anchor test | local validator + test suite |
irma | anchor run test | yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/read_protocol_state.ts |
What you could build from it
- Fork the SuperStack copy and extend it within the Other gaps listed on the idea page.
- Learn the pattern first: Program Derived Addresses (PDAs)
- Learn the pattern first: Cross-Program Invocations (CPIs)