Skip to content

Conversation

@matias-gonz
Copy link
Member

@matias-gonz matias-gonz commented Oct 23, 2025

Closes #28

* 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
* 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.
…rom config and enforce required ETH and USDC addresses
… addresses from config for improved consistency
@matias-gonz matias-gonz changed the title refactor: constants as typed dicts refactor: asset addresses constants as typed dicts Oct 23, 2025
Copy link
Collaborator

@timbrinded timbrinded left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@timbrinded timbrinded marked this pull request as ready for review October 23, 2025 13:54
Copilot AI review requested due to automatic review settings October 23, 2025 13:54
@timbrinded timbrinded merged commit c95160f into feat/config-file Oct 23, 2025
6 checks passed
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors asset address management by introducing typed dictionaries for network-specific asset addresses. The changes replace hardcoded asset address constants with a more flexible, network-aware configuration system.

Key changes:

  • Introduced NetworkAssets TypedDict and network-specific asset dictionaries (mainnet, sepolia, base)
  • Added Network enum and corresponding settings to support multiple networks
  • Updated all adapters to retrieve asset addresses from configuration instead of constants

Reviewed Changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/tq_oracle/constants.py Introduced NetworkAssets TypedDict and network-specific asset dictionaries, reorganized constants
src/tq_oracle/settings.py Added Network enum and assets property to retrieve network-specific asset addresses
src/tq_oracle/main.py Added --network CLI option for network selection
src/tq_oracle/adapters/price_adapters/base.py Added validate_prices method to ensure all prices are positive
src/tq_oracle/adapters/price_adapters/wsteth.py Updated to use config-based asset addresses with validation
src/tq_oracle/adapters/price_adapters/cow_swap.py Updated to use config-based asset addresses and network-specific API URLs
src/tq_oracle/adapters/price_adapters/chainlink.py Updated to use config-based asset addresses
src/tq_oracle/adapters/asset_adapters/idle_balances.py Updated to use config-based ETH and USDC addresses
src/tq_oracle/adapters/asset_adapters/hyperliquid.py Updated to use config-based USDC address
src/tq_oracle/processors/total_assets.py Added validation to reject non-positive prices
tests/**/*.py Updated all tests to use fixtures for asset addresses instead of constants

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +92 to 98
self.usdc_address,
self.usdt_address,
self.usds_address,
}

supported_assets = [asset for asset in supported_assets if asset is not None]

Copy link

Copilot AI Oct 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 97 redefines supported_assets from a set to a list, which conflicts with the loop on line 99 that expects to check membership in the original set. The filtering of None values should happen during set construction or the variable should be renamed to avoid confusion.

Suggested change
self.usdc_address,
self.usdt_address,
self.usds_address,
}
supported_assets = [asset for asset in supported_assets if asset is not None]
asset for asset in [self.usdc_address, self.usdt_address, self.usds_address] if asset is not None
}

Copilot uses AI. Check for mistakes.
Comment on lines +53 to +56
ETH_MAINNET_ASSETS["USDC"]: 6,
SEPOLIA_ASSETS["USDC"]: 6,
ETH_MAINNET_ASSETS["USDT"]: 6,
ETH_MAINNET_ASSETS["USDS"]: 18,
Copy link

Copilot AI Oct 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using dictionary values as keys in TOKEN_DECIMALS can fail at module import time if any asset address is None. This occurs for SEPOLIA_ASSETS["USDC"] which is guaranteed to be a string, but the pattern is fragile. Consider using a more explicit mapping or checking for None values.

Suggested change
ETH_MAINNET_ASSETS["USDC"]: 6,
SEPOLIA_ASSETS["USDC"]: 6,
ETH_MAINNET_ASSETS["USDT"]: 6,
ETH_MAINNET_ASSETS["USDS"]: 18,
"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48": 6, # USDC Mainnet
"0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238": 6, # USDC Sepolia
"0xdAC17F958D2ee523a2206206994597C13D831ec7": 6, # USDT Mainnet
"0xdC035D45d973E3EC169d2276DDab16f1e407384F": 18, # USDS Mainnet

Copilot uses AI. Check for mistakes.
@timbrinded timbrinded deleted the refactor/constants-as-typed-dicts branch October 23, 2025 19:45
timbrinded added a commit that referenced this pull request Oct 24, 2025
* 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]>
timbrinded added a commit that referenced this pull request Oct 25, 2025
* 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants