Degen Code

Degen Code

Aave — Part IV

Borrower Discovery, Position Inspection

Dec 03, 2025
∙ Paid

Loan positions on Aave can be easily inspected, provided that you know who has them.

There is no onchain view that exposes a simple list of active loan positions or their users, so we’ll need to dig through transaction logs to discover the borrowers and look up their positions.

Each new loan operation emits a Borrow event, which is defined in the IPool.sol interface:

event Borrow(
    address indexed reserve,
    address user,
    address indexed onBehalfOf,
    uint256 amount,
    DataTypes.InterestRateMode interestRateMode,
    uint256 borrowRate,
    uint16 indexed referralCode
);

Using Ape, connect to Ethereum mainnet and query for Borrow events starting at block 23,000,000:

btd@dev:~$ ape console --network :mainnet
INFO:     Connecting to existing Reth node at http://localhost:8545.

In [1]: pool = Contract('0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2')

In [2]: borrows = pool.Borrow.query('*', start_block=23_000_000)

In [3]: borrows
Out[3]: 
0       0x807c5ad511680ecb97cc3a9f9caaacb6f55c98799596... 
1       0xa40948b206cde4493e8772bb9cf2dd38ef020151a453... 
2       0x8ed9da1f0a1c0daedd0b1c7a98811078cb09945076e0... 
3       0xab6b82ec1d7df25fcf8826d9410013d7813b9c5fb514... 
4       0x6f8dd67ab48078d522144126929d194d12b49b89196c... 
...
...
191965  0xc24c257bbdfd99a3693912169190f863874c134e2ec0... 
191966  0xf906e5d7b5926444dabd3750a510df36e13658433383... 
191967  0x8c0a4488312fda581f4a5d01e7bab4446d8aa9412628... 
191968  0x893e30290be406185abc59cabfef540335f53428a80d... 
191969  0xcd5c580418e3cb18cd5b2e730f671459dd90cf03e63e... 

[191970 rows x 8 columns]

Calls to query() return a Pandas DataFrame with columns corresponding to the event’s position in the block, its transaction, and the data in the event itself. You can view these via the columns attribute on the DataFrame:

In [4]: borrows.columns
Out[4]: 
Index(
    [
        ’block_hash’, 
        ‘block_number’, 
        ‘contract_address’, 
        ‘event_arguments’,
        ‘event_name’, 
        ‘log_index’, 
        ‘transaction_hash’, 
        ‘transaction_index’
    ],
    dtype=’object’
)

Keep reading with a 7-day free trial

Subscribe to Degen Code to keep reading this post and get 7 days of free access to the full post archives.

Already a paid subscriber? Sign in
© 2025 BowTiedDevil · Privacy ∙ Terms ∙ Collection notice
Start your SubstackGet the app
Substack is the home for great culture