In Compound III, principal is the signed, index-normalized base-asset amount stored for an account. Positive principal converts to supplied balance with the supply index; negative principal converts to debt with the borrow index. Present balances include accrued interest. Reproduce them with Comet's 10^15 index scale and integer rounding, using indices projected to the same block as the balance read.
This walkthrough follows Compound III's CometWithExtendedAssetList and its accounting helpers at revision f766f51, inspected on 28 October 2026. It is a reference-source calculation. Match a particular market's proxy, implementation and base token before applying it to that deployment.
Read the sign before choosing the index
Comet keeps one signed base principal per account. Positive means supplied base; negative means borrowed base; zero means neither. That sign selects the interest multiplier. The official borrowing documentation calls principal a day-zero balance: an amount normalized back through the protocol's index.
"Day zero" does not mean the day you opened the account. An index can already exceed one when you first supply. Nor is principal a record of your original deposit, cumulative transfers or tax cost basis. Those require transaction history. A principal of 123.456789 normalized units can correspond to more than 123.456789 base tokens when its applicable index exceeds one.
The storage definition uses an int104 for userBasic(account).principal. Collateral quantities live in a separate mapping. A collateral token's own balance does not receive the base supply multiplier; the base asset versus collateral walkthrough explains that boundary.
| Stored principal | Account's base position | Relevant public balance |
|---|---|---|
| Positive | Supplied base | balanceOf(account) |
| Negative | Base debt | borrowBalanceOf(account) |
| Zero | Neither | Both return zero |
Both getters return unsigned amounts. A borrower can therefore have balanceOf equal to zero and a substantial debt in borrowBalanceOf. To build a signed display, subtract the latter from the former. Do not treat the borrow getter's positive return value as a positive supply claim. These getter conventions are documented in the official helper reference.
Keep token decimals separate from index scaling
Three scales appear in a reconstruction. Base-token decimals format the final token quantity. The base indices use 10^15. Interest-rate outputs use 10^18. A six-decimal base token does not turn its index into a six-decimal number.
Let P be signed raw principal, Q equal 10^15, and Is and Ib be raw supply and borrow indices. For positive P, raw supply is:
floor(P × Is / Q)
For negative P, raw debt magnitude is:
floor(abs(P) × Ib / Q)
Apply the minus sign afterward if a signed present balance is needed. The pinned CometCore implementation floors both unsigned magnitudes. It then negates the borrow result. Dividing a negative numerator with a language's floor-division operator can produce a different answer.
The reverse conversion has a separate rule. A nonnegative present amount becomes principal by dividing its scaled amount by Is and rounding down. A debt magnitude becomes principal magnitude by dividing by Ib and rounding up, then applying a negative sign. That asymmetry matters when a transaction changes the balance; it does not mean the public debt getter rounds up.
The earlier Aave liquidity and borrow index comparison illustrates why indices must remain separate. Its ray scale and token rounding rules belong to Aave. Comet's constants and conversion functions govern this calculation.
Reproduce two accounts through one day
Everything in this example is hypothetical. Token U has six decimals. Account A has principal +123,456,789; account B has principal −80,000,001. They are separate accounts in the same market. Assume B's collateral supports its opening debt; collateral valuation is outside this fixture.
At checkpoint t0, use supply index 1.10 and borrow index 1.25. Their raw values are 1,100,000,000,000,000 and 1,250,000,000,000,000. The principal quantities are already normalized account records, rather than fresh deposits at t0.
For A, multiplying 123,456,789 by 1.10 gives 135,802,467.9 raw units. Flooring produces 135,802,467, displayed as 135.802467 U.
For B, the magnitude calculation gives 100,000,001.25 raw units. The borrow getter returns 100,000,001, displayed as 100.000001 U owed. Its signed present balance is −100,000,001. Directly flooring the negative decimal product would give −100,000,002, a one-unit error.
Now let exactly 86,400 seconds pass with no intervening market transaction. Stipulate per-second supply and borrow rate outputs of 1,000,000,000 and 2,000,000,000, respectively. These are invented rate outputs, not observed market quotes or rates derived from the two example accounts. The official rate documentation specifies their per-second, 10^18 scale.
For each side, the index calculation adds an increment to its stored index:
floor(index × rate × seconds / 10^18)
The supply increment is 95,040,000,000. The borrow increment is 216,000,000,000. Thus the projected indices at t1 are 1.10009504 and 1.250216.
| Reconstructed value | t0 checkpoint | t1, one day later |
|---|---|---|
| Supply index | 1.10 | 1.10009504 |
| Borrow index | 1.25 | 1.250216 |
| A's supplied U | 135.802467 | 135.814201 |
| B's debt in U | 100.000001 | 100.017281 |
Both principals remain unchanged. A's displayed supply grew by 0.011734 U; B's displayed debt grew by 0.017280 U. Those differences follow integer calculations before formatting. Rounding the indices or balances early can obscure the final micro-unit.
A stored checkpoint can lag a balance view
At t1, totalsBasic() still reports the t0 indices and lastAccrualTime if nothing has persisted a new accrual. Its extension implementation returns stored fields directly.
The public balance getters instead call accruedInterestIndices for elapsed time. The view computes projected indices in memory. Consequently, multiplying principal by the unadvanced totalsBasic indices reproduces t0, even when every read uses the same t1 block.
For this fixture, the mismatch has a specific cause: omitted accrual projection. Persisting an accrual at t1 would bring the stored indices to the projected values without changing these accounts' principal. A later interval starts from that new checkpoint. Reconstruct the actual sequence of checkpoints; today's displayed APR cannot recover an arbitrary history of rates and flows.
A repayment can switch the applicable index
Consider two alternative transactions against B's original t1 debt of 100.017281 U. Each starts from that same snapshot, with no further elapsed time. Assume an ordinary token transfer credits the full requested amount.
In the first alternative, B supplies 100 U from an external wallet. The signed present balance becomes −0.017281 U, or −17,281 raw units. Its new borrow principal magnitude is the ceiling of 17,281 multiplied by 10^15 and divided by 1,250,216,000,000,000: 13,823.
The resulting stored principal is −13,823. Converting that magnitude forward reproduces debt of 17,281 raw units. Rounding the inverse conversion down would store −13,822 and reproduce only 17,280. A one-unit mismatch is evidence to check the rounding direction before blaming a data provider.
In the second alternative, B supplies 101 U. Debt is cleared, leaving a positive present remainder of 0.982719 U. This remainder must use the supply index. Dividing 982,719 multiplied by 10^15 by 1,100,095,040,000,000 and flooring gives +893,303 principal.
Reading that principal forward returns 982,718 raw units, or 0.982718 U supplied. The one-unit difference from the intermediate remainder comes from converting back to integer principal and then forward again.
| Alternative at t1 | New stored principal | Supply getter, U | Borrow getter, U |
|---|---|---|---|
| Supply 100 U | −13,823 | 0 | 0.017281 |
| Supply 101 U | +893,303 | 0.982718 | 0 |
These branches follow the reference supplyBase sequence: receive the transferred base, accrue, add the received amount to signed present balance, then normalize the result. Applying the borrow index to the positive remainder, or subtracting the payment directly from old principal, skips that conversion. The indices describe different sides of the account after the transaction.
Validate a balance before using it elsewhere
Save the market identity and one observation block before calculating. A usable reconciliation record contains:
| Evidence | Why it belongs in the record |
|---|---|
| Chain, proxy and implementation | Identifies the accounting rules |
| Account and base-token address | Prevents symbol or account mix-ups |
| Block hash and timestamp | Fixes the observation and elapsed time |
| Principal, both indices and last accrual time | Preserves the normalized amount and checkpoint |
| Rate outputs and protocol scales | Makes the projection reproducible |
| Both balance getters and token decimals | Tests raw results before display formatting |
| Intervening account transactions | Explains changes in principal between snapshots |
First compare raw integer outputs. If they disagree, check sign selection, elapsed time, index scale, magnitude rounding and implementation version. Only then format the values. Keep indices and intermediate products in integer-capable arithmetic; ordinary floating-point numbers can discard low digits before the division.
When comparing two dates, a change in present balance can combine interest with supplies, repayments, withdrawals and transfers. A constant-principal interval isolates index growth. A changed-principal interval needs its flow history, including any transition through zero. Reward-tracking fields also need their own interpretation; they are not substitutes for the base interest indices.
A reproduced balance establishes an account quantity. Assessing another borrow requires collateral prices and the relevant factors, as the Compound III borrowing versus liquidation factor guide explains. Assessing an exit also needs transferable market liquidity and transaction checks. The withdrawal liquidity and headroom example demonstrates that distinction for Aave; its numerical limits do not transfer to Comet.
For the constructed t1 snapshot, retain A's 135.814201 U supply and B's 100.017281 U debt alongside both principals and the projected indices. For either repayment branch, retain the newly stored principal and read both getters again. That evidence shows which side of zero the account occupies and which index the next balance calculation must use.
