refactor: ♻️ Reduce the number of fetches in idle_balances adapter#96
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the idle_balances adapter to optimize asset fetching by reducing redundant API calls. Instead of fetching supported assets once per subvault (in each fetch_assets call), the refactored code now fetches them once per fetch_all_assets call and passes them as a parameter.
Key Changes:
- Added optional
supported_assetsparameter tofetch_assetsmethod to allow passing pre-fetched asset lists - Modified
fetch_all_assetsto fetch supported assets once and pass them to eachfetch_assetscall - Updated tests to verify the new parameter is correctly passed and used
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/tq_oracle/adapters/asset_adapters/idle_balances.py |
Added optional supported_assets parameter to fetch_assets and modified fetch_all_assets to fetch supported assets once and pass them to each call |
tests/adapters/asset_adapters/test_idle_balances.py |
Updated test to verify supported_assets parameter is correctly passed in fetch_all_assets flow |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| async def fetch_assets( | ||
| self, subvault_address: str, *, supported_assets: list[str] | None = None | ||
| ) -> list[AssetData]: |
There was a problem hiding this comment.
The fetch_assets method signature now differs from the abstract method in BaseAssetAdapter which expects only subvault_address: str. Adding the optional supported_assets parameter is fine for backward compatibility, but it creates an inconsistency with the base class contract. Consider whether this parameter should be documented as an implementation detail or if the base class should be updated to allow implementation-specific parameters.
This pull request updates the asset fetching logic in the
idle_balancesadapter to improve consistency and testability. The main change is reduce the number of times to fetch supported assets from once per fetch_all call instead of the current once-per-fetch call.