-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add validation for asset prices in total_assets calculation #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add validation for asset prices in total_assets calculation #35
Conversation
matias-gonz
commented
Oct 22, 2025
- Implemented checks for invalid prices (<= 0) in the calculate_total_assets function.
- Added error handling to raise ValueError with details of invalid prices.
- Introduced a new test to ensure that invalid prices trigger the appropriate exception.
- Implemented checks for invalid prices (<= 0) in the calculate_total_assets function. - Added error handling to raise ValueError with details of invalid prices. - Introduced a new test to ensure that invalid prices trigger the appropriate exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Adds validation to reject invalid asset prices (≤ 0) in the total assets calculation, preventing incorrect computations from bad price data.
- Validates that all asset prices are positive before performing calculations
- Raises descriptive ValueError with details of which assets have invalid prices
- Adds test coverage for the new validation logic
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/tq_oracle/processors/total_assets.py | Adds validation loop to check for non-positive prices and raises ValueError with invalid price details |
| tests/processors/test_total_assets.py | Adds test case verifying ValueError is raised when prices are zero or negative |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merge when comment addressed
* feat: add validation for asset prices in total_assets calculation (#35) * feat: add validation for asset prices in total_assets calculation - Implemented checks for invalid prices (<= 0) in the calculate_total_assets function. - Added error handling to raise ValueError with details of invalid prices. - Introduced a new test to ensure that invalid prices trigger the appropriate exception. * refactor: turn invalid prices computation into list comprehension * feat: add price validation for price adapter (#36) * fix: update WstETHAdapter and tests to set ETH base asset price to 1 - Changed the base asset price for ETH in WstETHAdapter from 0 to 1 to ensure accurate pricing. - Updated related tests to verify that the ETH price is now correctly set to 1 instead of 0. - Adjusted documentation to clarify the base asset pricing behavior. * feat: add price validation to BasePriceAdapter * refactor: change validate_prices method to synchronous in price adapters - Updated the validate_prices method in BasePriceAdapter to be synchronous instead of asynchronous. - Adjusted calls to validate_prices in ChainlinkAdapter, CowSwapAdapter, and WstETHAdapter accordingly. * feat: add TypedDict for network addresses in constants.py * feat: add NetworkAddresses instances * refactor: rename NetworkAddresses to NetworkTokens and update address constants * feat: add network configuration and asset retrieval to OracleCLIConfig * refactor: update WstETHAdapter to use dynamic asset addresses from config * refactor: enhance WstETHAdapter to enforce required ETH address and simplify checks * refactor: update CowSwapAdapter to use dynamic asset addresses and improve network configuration * refactor: update ChainlinkAdapter to use dynamic asset addresses from config and enforce required ETH address * refactor: update IdleBalancesAdapter to use dynamic asset addresses from config and enforce required ETH and USDC addresses * refactor: remove optional asset address attributes from Chainlink, CowSwap, and WstETH adapters * refactor: enforce required USDC address in HyperliquidAdapter and update asset address retrieval from config * refactor: update Chainlink test suite to use dynamic asset addresses from config * refactor: update WstETHAdapter tests to utilize dynamic asset addresses from config * refactor: enhance HyperliquidAdapter tests to utilize dynamic USDC addresses from config * refactor: update tests to utilize dynamic asset addresses from config for improved consistency * refactor: update Chainlink and CowSwap tests to utilize dynamic asset addresses from config for improved consistency * refactor: update Chainlink tests to include dynamic ETH address in price fetching for USDT and USDS on testnet * refactor: update import paths from config to settings in CowSwap and Hyperliquid test files
* feat: ✨ Added config file support * tidy * tidy * lint * refactor: ♻️ tidy * ci: 💚 fix ci * fix: 🐛 fix asset order * fix: 🐛 fix oraclehelper issue * fix * refactor: ♻️ tidy * fmt * fix default overriding * Refactor/big refactor (#39) * refactor: ♻️ big refactor * refactor: ♻️ Tidy * docs: 📝 update readme * refactor: ♻️ pr comments * refactor: asset addresses constants as typed dicts (#38) * feat: add validation for asset prices in total_assets calculation (#35) * feat: add validation for asset prices in total_assets calculation - Implemented checks for invalid prices (<= 0) in the calculate_total_assets function. - Added error handling to raise ValueError with details of invalid prices. - Introduced a new test to ensure that invalid prices trigger the appropriate exception. * refactor: turn invalid prices computation into list comprehension * feat: add price validation for price adapter (#36) * fix: update WstETHAdapter and tests to set ETH base asset price to 1 - Changed the base asset price for ETH in WstETHAdapter from 0 to 1 to ensure accurate pricing. - Updated related tests to verify that the ETH price is now correctly set to 1 instead of 0. - Adjusted documentation to clarify the base asset pricing behavior. * feat: add price validation to BasePriceAdapter * refactor: change validate_prices method to synchronous in price adapters - Updated the validate_prices method in BasePriceAdapter to be synchronous instead of asynchronous. - Adjusted calls to validate_prices in ChainlinkAdapter, CowSwapAdapter, and WstETHAdapter accordingly. * feat: add TypedDict for network addresses in constants.py * feat: add NetworkAddresses instances * refactor: rename NetworkAddresses to NetworkTokens and update address constants * feat: add network configuration and asset retrieval to OracleCLIConfig * refactor: update WstETHAdapter to use dynamic asset addresses from config * refactor: enhance WstETHAdapter to enforce required ETH address and simplify checks * refactor: update CowSwapAdapter to use dynamic asset addresses and improve network configuration * refactor: update ChainlinkAdapter to use dynamic asset addresses from config and enforce required ETH address * refactor: update IdleBalancesAdapter to use dynamic asset addresses from config and enforce required ETH and USDC addresses * refactor: remove optional asset address attributes from Chainlink, CowSwap, and WstETH adapters * refactor: enforce required USDC address in HyperliquidAdapter and update asset address retrieval from config * refactor: update Chainlink test suite to use dynamic asset addresses from config * refactor: update WstETHAdapter tests to utilize dynamic asset addresses from config * refactor: enhance HyperliquidAdapter tests to utilize dynamic USDC addresses from config * refactor: update tests to utilize dynamic asset addresses from config for improved consistency * refactor: update Chainlink and CowSwap tests to utilize dynamic asset addresses from config for improved consistency * refactor: update Chainlink tests to include dynamic ETH address in price fetching for USDT and USDS on testnet * refactor: update import paths from config to settings in CowSwap and Hyperliquid test files * test fix * refactor: ♻️ pr comments * pr comments * Update constants.py Co-authored-by: Copilot <[email protected]> * Feat/improved docs checks (#40) * docs * docs * Update src/tq_oracle/adapters/asset_adapters/idle_balances.py Co-authored-by: Copilot <[email protected]> * Update tq-oracle-example.toml Co-authored-by: Copilot <[email protected]> * Update README.md Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Matías Ignacio González <[email protected]> Co-authored-by: Copilot <[email protected]>
* feat: ✨ Added config file support * tidy * tidy * lint * refactor: ♻️ tidy * ci: 💚 fix ci * fix: 🐛 fix asset order * fix: 🐛 fix oraclehelper issue * fix * refactor: ♻️ tidy * fmt * fix default overriding * Refactor/big refactor (#39) * refactor: ♻️ big refactor * refactor: ♻️ Tidy * docs: 📝 update readme * refactor: ♻️ pr comments * refactor: asset addresses constants as typed dicts (#38) * feat: add validation for asset prices in total_assets calculation (#35) * feat: add validation for asset prices in total_assets calculation - Implemented checks for invalid prices (<= 0) in the calculate_total_assets function. - Added error handling to raise ValueError with details of invalid prices. - Introduced a new test to ensure that invalid prices trigger the appropriate exception. * refactor: turn invalid prices computation into list comprehension * feat: add price validation for price adapter (#36) * fix: update WstETHAdapter and tests to set ETH base asset price to 1 - Changed the base asset price for ETH in WstETHAdapter from 0 to 1 to ensure accurate pricing. - Updated related tests to verify that the ETH price is now correctly set to 1 instead of 0. - Adjusted documentation to clarify the base asset pricing behavior. * feat: add price validation to BasePriceAdapter * refactor: change validate_prices method to synchronous in price adapters - Updated the validate_prices method in BasePriceAdapter to be synchronous instead of asynchronous. - Adjusted calls to validate_prices in ChainlinkAdapter, CowSwapAdapter, and WstETHAdapter accordingly. * feat: add TypedDict for network addresses in constants.py * feat: add NetworkAddresses instances * refactor: rename NetworkAddresses to NetworkTokens and update address constants * feat: add network configuration and asset retrieval to OracleCLIConfig * refactor: update WstETHAdapter to use dynamic asset addresses from config * refactor: enhance WstETHAdapter to enforce required ETH address and simplify checks * refactor: update CowSwapAdapter to use dynamic asset addresses and improve network configuration * refactor: update ChainlinkAdapter to use dynamic asset addresses from config and enforce required ETH address * refactor: update IdleBalancesAdapter to use dynamic asset addresses from config and enforce required ETH and USDC addresses * refactor: remove optional asset address attributes from Chainlink, CowSwap, and WstETH adapters * refactor: enforce required USDC address in HyperliquidAdapter and update asset address retrieval from config * refactor: update Chainlink test suite to use dynamic asset addresses from config * refactor: update WstETHAdapter tests to utilize dynamic asset addresses from config * refactor: enhance HyperliquidAdapter tests to utilize dynamic USDC addresses from config * refactor: update tests to utilize dynamic asset addresses from config for improved consistency * refactor: update Chainlink and CowSwap tests to utilize dynamic asset addresses from config for improved consistency * refactor: update Chainlink tests to include dynamic ETH address in price fetching for USDT and USDS on testnet * refactor: update import paths from config to settings in CowSwap and Hyperliquid test files * test fix * refactor: ♻️ pr comments * pr comments * Update constants.py Co-authored-by: Copilot <[email protected]> * Feat/improved docs checks (#40) * docs * docs * Update src/tq_oracle/adapters/asset_adapters/idle_balances.py Co-authored-by: Copilot <[email protected]> * Update tq-oracle-example.toml Co-authored-by: Copilot <[email protected]> * Update README.md Co-authored-by: Copilot <[email protected]> * update cli opts * fix: 🐛 working with base now * rename l1->vault * fix private key * price fix * fix tests * update tests * give steth disclaimer * fmt --------- Co-authored-by: Matías Ignacio González <[email protected]> Co-authored-by: Copilot <[email protected]>