Topics Decimal Precision

The Challenge

LegacyVault interacts with two different precision standards:

  • USDC (Asset): 6 Decimals (e.g., 1.000000)

  • Rust Math (Logic): strict U256 integers

Normalization Strategy

When funds enter the Lending Pool, we maintain the raw U256 value but treat the interest calculation as a Ratio.

1

Deposit flow

User sends 100 USDC (100,000,000 units). Rust contract stores:

principal = 100,000,000
2

Interest flow

Day 1 calculation:

100,000,000×101100=101,000,000100{,}000{,}000 \times \frac{101}{100} = 101{,}000{,}000

(User now has 101 USDC)

Precision loss prevention: because we multiply before we divide, we maintain maximum precision even for small amounts.

circle-info

Order of operations is critical for precision: multiply first, then divide.

Code Implementation:

lending-pool/src/lib.rs
// Order of operations is critical for precision
current_value = (current_value * hundred_one) / hundred;