Skip to content

Commit 8305ca9

Browse files
committed
Fix anchor build: drop #[constant] from u128 constants
`anchor build`'s IDL generation compiles a generated test under the idl-build feature, where the `#[constant]` macro mis-evaluates the 1e18 u128 literal as i32 ("literal out of range for i32"), failing CI. These values don't need to be in the IDL, so they're plain `pub const`s now. https://claude.ai/code/session_01RwE8f8ahP5S6SDNTsXmpj9
1 parent 49398b5 commit 8305ca9

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

finance/lending/anchor/programs/lending/src/constants.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use anchor_lang::prelude::*;
1+
// These are plain `pub const`s rather than Anchor `#[constant]`s: `#[constant]`
2+
// only re-exports a value into the IDL, and anchor's idl-build mis-evaluates a
3+
// u128 literal this large as i32 ("literal out of range for i32"). None of these
4+
// need to appear in the IDL, so plain consts both compile and keep the IDL clean.
25

36
/// Fixed-point scale for every ratio in the program: interest rates, the
47
/// cumulative borrow-rate index, the share-token exchange rate, and obligation
@@ -8,7 +11,6 @@ use anchor_lang::prelude::*;
811
/// keeps a single slot's interest — which can be a tiny fraction of the index —
912
/// from truncating to zero, while u128's ~3.4e38 ceiling leaves headroom for the
1013
/// index to grow and for intermediate products before the final narrowing cast.
11-
#[constant]
1214
pub const FIXED_POINT_SCALE: u128 = 1_000_000_000_000_000_000;
1315

1416
/// log10(FIXED_POINT_SCALE). Used to fold the price exponent and the fixed-point
@@ -17,12 +19,10 @@ pub const FIXED_POINT_SCALE: u128 = 1_000_000_000_000_000_000;
1719
pub const FIXED_POINT_SCALE_DECIMALS: i32 = 18;
1820

1921
/// Denominator for every basis-point config value. 100% == 10_000 bps.
20-
#[constant]
2122
pub const BPS_DENOMINATOR: u128 = 10_000;
2223

2324
/// Slots per year, for turning an APR (in bps) into a per-slot rate.
2425
/// Solana targets ~2.5 slots/second: 2.5 * 60 * 60 * 24 * 365 = 78_840_000.
25-
#[constant]
2626
pub const SLOTS_PER_YEAR: u128 = 78_840_000;
2727

2828
/// Maximum distinct reserves an obligation may use as collateral, and
@@ -33,7 +33,6 @@ pub const MAX_OBLIGATION_RESERVES: usize = 4;
3333
/// A price feed older than this many slots is rejected as stale (~10s at 2.5
3434
/// slots/second). Freshness is measured in slots, not unix time, because the
3535
/// runtime guarantees slot progression while the timestamp is validator-influenced.
36-
#[constant]
3736
pub const MAX_PRICE_STALENESS_SLOTS: u64 = 25;
3837

3938
// PDA seeds.

0 commit comments

Comments
 (0)