Is it possible to track a function's dependencies in Postgres?
Since functions are stored as strings in PostgreSQL, and there is no limit to the languages a function could be written in, PostgreSQL cannot analyze the code to add dependencies.

The best option you have is to manually figure out the dependencies.

If you store that information in a database table, you could make sure that all REFRESH MATERIALIZED VIEW statements are executed in the correct order.