Skip to content

fix: support Anchor 0.32+ by defining LAMPORTS_PER_SOL constant#11

Open
0x-pankaj wants to merge 1 commit intomagicblock-labs:masterfrom
0x-pankaj:fix/anchor-0.32-compatibility
Open

fix: support Anchor 0.32+ by defining LAMPORTS_PER_SOL constant#11
0x-pankaj wants to merge 1 commit intomagicblock-labs:masterfrom
0x-pankaj:fix/anchor-0.32-compatibility

Conversation

@0x-pankaj
Copy link
Copy Markdown

@0x-pankaj 0x-pankaj commented Nov 16, 2025

Problem

Compilation fails with Anchor 0.32+ due to the removal of the native_token module:

error[E0432]: unresolved import `anchor_lang::solana_program::native_token`
 --> programs/gpl_session/src/lib.rs:1:47
  |
1 | use anchor_lang::{prelude::*, solana_program::native_token::LAMPORTS_PER_SOL, system_program};
  |                                               ^^^^^^^^^^^^ could not find `native_token` in `solana_program`

This breaks compatibility for all users attempting to build with Anchor 0.32.1 or higher.

Solution

Removed the import of LAMPORTS_PER_SOL from solana_program::native_token and defined it as a constant directly in the code:

const LAMPORTS_PER_SOL: u64 = 1_000_000_000;

This approach:

  • ✅ Works with all Anchor versions (0.28 - 0.32+)
  • ✅ Has no runtime impact (constant is inlined at compile time)
  • ✅ Is safe because LAMPORTS_PER_SOL is a Solana protocol constant that will never change
  • ✅ Maintains backward compatibility

Before & After Screenshots

BEFORE:

use anchor_lang::{prelude::*, solana_program::native_token::LAMPORTS_PER_SOL, system_program};

Result: ❌ Compilation error with Anchor 0.32+

AFTER:

use anchor_lang::{prelude::*, system_program};

const LAMPORTS_PER_SOL: u64 = 1_000_000_000;

Result: ✅ Compiles successfully with all Anchor versions

Other changes (e.g. bug fixes, small refactors)

None - this is a minimal focused fix affecting only the import statement.

Deploy Notes

No deployment changes required. This is purely a compilation fix with no runtime behavioral changes.

New scripts: None

New dependencies: None


Status Type ⚠️ Core Change Issue
Ready Bug No N/A

Summary by CodeRabbit

  • Chores
    • Updated internal constant management with no changes to public functionality or behavior.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Nov 16, 2025

Walkthrough

A local constant definition replaces an external import of LAMPORTS_PER_SOL in the GPL session library. The value remains unchanged at 1,000,000,000 and there are no modifications to public APIs or control flow.

Changes

Cohort / File(s) Summary
Import refactoring
programs/gpl_session/src/lib.rs
Removed external import of LAMPORTS_PER_SOL from solana_program::native_token and replaced with local constant definition having the same value.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: supporting Anchor 0.32+ by defining a local LAMPORTS_PER_SOL constant to replace a removed import.
Description check ✅ Passed The description comprehensively covers the problem, solution, before/after examples, and deployment notes, following the repository template structure.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e17bf31 and 6ddff55.

📒 Files selected for processing (1)
  • programs/gpl_session/src/lib.rs (1 hunks)
🔇 Additional comments (2)
programs/gpl_session/src/lib.rs (2)

1-1: LGTM! Import statement correctly updated.

The removal of solana_program::native_token::LAMPORTS_PER_SOL from the import statement resolves the compilation error with Anchor 0.32+ while maintaining all necessary imports.


5-5: Constant definition verified—no further action needed.

The constant value 1_000_000_000 correctly matches the official Solana definition where 1 SOL equals 1,000,000,000 lamports. The shell script search confirms this is the only file with this constant, and no other files in the codebase import the deprecated solana_program::native_token module. The implementation is correct and complete.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant