Decode Aave v3 user configuration using reserve IDs

The pool stores borrowing and collateral flags as bit pairs. Using a token’s current list position instead of its assigned reserve ID can silently attribute collateral to the wrong asset.

Map a bit pair to the deployed reserve

Read the reserve’s recorded id and the user configuration at the same block. In the reference v3 layout the borrowing flag uses bit 2 times id and the collateral flag the next bit. The example sets only the collateral flag for reserve three.

reserve ID = 3
borrow flag = bit 6
collateral flag = bit 7
user word = 0x80 → collateral set, borrowing clear for ID 3

For a multi-asset account, map each nonzero bit pair to the underlying asset through the pool’s ID mapping. Preserve gaps left by removed or unavailable reserves; do not renumber a filtered list.

Use flags as configuration, not quantities

The bitmap contains no debt or token amount. Read current aToken and debt balances separately before describing the size of a position. Keep chain and pool addresses in cache keys because ID three can denote another asset in another market. github.com UserConfiguration.sol