### Start veYFI Exporter on Ethereum (Bash) Source: https://github.com/yearn/yearn-exporter/blob/master/readme.md Starts the veYFI (vote-escrowed Yearn Finance) exporter specifically for the Ethereum network. This command is a shortcut for this particular exporter and network. Environment variables from .env should be loaded. ```bash # Start veYFI exporter on ethereum: make veYFI ``` -------------------------------- ### Start Treasury Exporter Across All Networks (Bash) Source: https://github.com/yearn/yearn-exporter/blob/master/readme.md Starts the treasury exporter for all supported networks. This command is a shortcut for collecting treasury-related data across the ecosystem. Environment variables from .env should be loaded. ```bash # Start only the treasury exporters for all supported networks: make treasury ``` -------------------------------- ### Build and Run All Exporters (Bash) Source: https://github.com/yearn/yearn-exporter/blob/master/readme.md Builds the Docker image and starts all Yearn exporters across all supported networks. Requires significant CPU resources. Environment variables from .env should be loaded. ```bash # Make sure all .env variables loaded (`source .env`), check with `echo $variable_name_here` make build && make up ``` -------------------------------- ### Start Specific Exporter by Network and Command (Bash) Source: https://github.com/yearn/yearn-exporter/blob/master/readme.md Starts a specific exporter (e.g., vaults) on a specified network (e.g., ethereum). This allows for targeted data collection and reduces resource usage. Environment variables from .env should be loaded. ```bash # Start only the vaults exporter for ethereum: make up network=ethereum commands="exporters/vaults" ``` -------------------------------- ### Start All Exporters on a Specific Network (Bash) Source: https://github.com/yearn/yearn-exporter/blob/master/readme.md Starts all available exporters but filters them to run only on a specified network (e.g., arbitrum). This is useful for focusing on a single network's data. Environment variables from .env should be loaded. ```bash # Start all available exporters on arbitrum: make up network=arbitrum ``` -------------------------------- ### Start APY Exporter on Ethereum (Bash) Source: https://github.com/yearn/yearn-exporter/blob/master/readme.md Starts the Annual Percentage Yield (APY) exporter for the Ethereum network. This command is used to collect and expose APY data for Yearn products on Ethereum. Environment variables from .env should be loaded. ```bash # Start APY exporter on ethereum: make apy network=eth ``` -------------------------------- ### Start Specific Exporter Across All Networks (Bash) Source: https://github.com/yearn/yearn-exporter/blob/master/readme.md Starts a specific exporter (e.g., vaults) across all supported networks. This is useful for comprehensive data collection for a particular product. Environment variables from .env should be loaded. ```bash # Start only the vaults exporter for all supported networks: make up commands="exporters/vaults" ``` -------------------------------- ### V2 Vault Registry Operations (Python) Source: https://context7.com/yearn/yearn-exporter/llms.txt Shows how to interact with the Yearn V2 Vault Registry, which automatically discovers vaults via on-chain events. Examples include initializing the registry, accessing endorsed and experimental vaults, describing vaults, getting TVL, and listing active vaults at a specific block. ```python import asyncio from yearn.v2.registry import Registry async def main(): # Initialize V2 registry (auto-discovers vaults from on-chain registry) registry = Registry(include_experimental=True) # Access endorsed vaults vaults = await registry.vaults print(f"Found {len(vaults)} endorsed vaults") # Access experimental vaults experiments = await registry.experiments # Describe all vaults at current block descriptions = await registry.describe(block=None) # Returns: {'yvUSDC 0.4.6': {'totalAssets': 1000000, 'tvl': 1000000, ...}, ...} # Get TVL for all vaults tvl_data = await registry.total_value_at(block=None) # Get active vaults at specific block active = await registry.active_vaults_at(block=17000000) asyncio.run(main()) ``` -------------------------------- ### Build and Run Grafana Dashboards and Exporters (Bash) Source: https://github.com/yearn/yearn-exporter/blob/master/readme.md Builds the Docker image and starts the exporters along with the Grafana dashboard. Access the dashboard at http://localhost:3000 with default credentials admin:admin. Environment variables from .env should be loaded. ```bash # Make sure all .env variables loaded (`source .env`), check with `echo $variable_name_here` make build && make dashboards ``` -------------------------------- ### Build Docker Image (Bash) Source: https://github.com/yearn/yearn-exporter/blob/master/readme.md Builds the Docker image for the Yearn Exporter. This command is typically run before starting any exporters to ensure the latest code is containerized. ```bash # build the docker image: make build ``` -------------------------------- ### Build and Run Historical TVL Exporter (Bash) Source: https://github.com/yearn/yearn-exporter/blob/master/readme.md Builds the Docker image and starts the exporter for historical Total Value Locked (TVL). The TVL data will be accessible via a REST endpoint. Environment variables from .env should be loaded. ```bash # Make sure all .env variables loaded (`source .env`), check with `echo $variable_name_here` make build && make tvl ``` -------------------------------- ### Running Yearn Exporter Scripts (Bash) Source: https://context7.com/yearn/yearn-exporter/llms.txt Provides bash commands for setting up and running various Yearn data exporters. It includes setting essential environment variables such as the web3 provider, network, Victoria Metrics URL, and concurrency level. Examples cover running vault, APY, partners, and treasury exporters, as well as debugging specific APY calculations. ```bash # Set environment variables export WEB3_PROVIDER=https://eth-mainnet.g.alchemy.com/v2/YOUR_KEY export NETWORK=mainnet export VM_URL=http://victoria-metrics:8428 export CONCURRENCY=10 # Run vault exporter (historical + real-time) brownie run scripts/exporters/vaults --network mainnet # Run APY calculations brownie run scripts/apy --network mainnet # Run partners exporter brownie run scripts/exporters/partners --network mainnet # Run treasury exporter brownie run scripts/exporters/treasury --network mainnet # Debug specific vault APY brownie run scripts/debug_apy dai --network mainnet ``` -------------------------------- ### Yearn MetaRegistry Operations (Python) Source: https://context7.com/yearn/yearn-exporter/llms.txt Demonstrates how to use the Yearn MetaRegistry to aggregate data from all Yearn product registries. It shows initialization, describing products, getting total value locked (TVL), listing active vaults, and exporting data for metrics collection. ```python import asyncio from yearn.yearn import Yearn async def main(): # Initialize the Yearn meta-registry yearn = Yearn(exclude_ib_tvl=True) # Describe all products at current block data = await yearn.describe(block=None) # Returns: {'earn': {...}, 'v1': {...}, 'v2': {...}, 'ib': {...}, 'special': {...}} # Get total value locked across all products tvl = await yearn.total_value_at(block=None) # Returns: {'earn': {'yDAIv2': 1234.56, ...}, 'v2': {'yvUSDC': 5678.90, ...}, ...} # Get all active vaults at a specific block active_vaults = await yearn.active_vaults_at(block=15000000) # Export data for metrics collection block = 18000000 timestamp = 1693526400 metrics = await yearn.data_for_export(block, timestamp) # Returns list of metric items ready for Victoria Metrics asyncio.run(main()) ``` -------------------------------- ### Special Yearn Contracts Handling (Python) Source: https://context7.com/yearn/yearn-exporter/llms.txt Provides examples for interacting with special Yearn Finance contracts like Backscratcher, Ygov, and yveCRVJar. It demonstrates how to retrieve their TVL, APY, and other relevant financial data using the 'yearn' library. Includes usage of the special contracts registry. ```python import asyncio from yearn.special import Backscratcher, Ygov, YveCRVJar, Registry from yearn.apy import get_samples async def main(): # Backscratcher (yveCRV) - locked CRV earning protocol fees backscratcher = Backscratcher() bs_desc = await backscratcher.describe(block=None) print(f"Backscratcher TVL: ${bs_desc['tvl']:,.2f}") samples = get_samples() bs_apy = await backscratcher.apy(samples) print(f"Backscratcher APY: {bs_apy.net_apy:.2%}") print(f"Current Boost: {bs_apy.composite['currentBoost']:.2f}x") # yGov - YFI governance staking ygov = Ygov() ygov_desc = await ygov.describe(block=None) print(f"yGov Total Assets: {ygov_desc['totalAssets']:.2f} YFI") # Special contracts registry registry = Registry() all_special = await registry.describe(block=None) for name, data in all_special.items(): print(f"{name}: TVL ${data.get('tvl', 0):,.2f}") asyncio.run(main()) ``` -------------------------------- ### V1 Vault Registry Operations (Python) Source: https://context7.com/yearn/yearn-exporter/llms.txt Provides examples for interacting with the Yearn V1 Vault Registry, which is specific to Ethereum Mainnet and no longer has new vaults deployed. It covers accessing the vaults, describing them, and retrieving their total value locked (TVL). ```python import asyncio from yearn.v1.registry import Registry as RegistryV1 async def main(): # V1 registry (Mainnet only, no new vaults deployed) registry = RegistryV1() # Access V1 vaults vaults = registry.vaults print(f"Found {len(vaults)} V1 vaults") # Describe V1 vaults descriptions = await registry.describe(block=None) # Get TVL for V1 vaults tvl = await registry.total_value_at(block=None) asyncio.run(main()) ``` -------------------------------- ### Get Universal Token Prices (Python) Source: https://context7.com/yearn/yearn-exporter/llms.txt Provides a universal price lookup function for various token types, including LP tokens, vault shares, and wrapped assets. Supports fetching prices at specific blocks and unwrapping token addresses. Requires the 'yearn' library. ```python import asyncio from yearn.prices.magic import get_price, find_price, unwrap_token async def main(): # Get price for any token (sync version) dai_price = get_price("0x6B175474E89094C44Da98b954EesdeB131e561Ebe", block=None) print(f"DAI price: ${dai_price}") # Get price at specific block eth_price = get_price("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", block=17000000) print(f"WETH price at block 17M: ${eth_price}") # Unwrap wrapped tokens to get underlying unwrapped = unwrap_token("0x4da27a545c0c5B758a6BA100e3a049001de870f5") # stkAAVE print(f"stkAAVE unwraps to: {unwrapped}") # Returns AAVE address # Price lookup handles: # - Yearn vault shares # - Uniswap/Balancer LP tokens # - Curve LP tokens # - Compound/IronBank cTokens # - Aave aTokens # - And many more... asyncio.run(main()) ``` -------------------------------- ### V2 Vault Operations (Python) Source: https://context7.com/yearn/yearn-exporter/llms.txt Details individual Yearn V2 Vault operations, including creating a vault instance from its address, retrieving detailed descriptions with metrics, calculating APY (net and gross), and accessing strategy information. It also shows how to get the vault's TVL. ```python import asyncio from yearn.v2.vaults import Vault from yearn.apy import get_samples async def main(): # Create vault instance from address vault = Vault.from_address("0xdA816459F1AB5631232FE5e97a05BBBb94970c95") # yvDAI # Get vault description with all metrics description = await vault.describe(block=None) # Returns: { # 'totalAssets': 50000000.0, # 'pricePerShare': 1.05, # 'tvl': 52500000.0, # 'token price': 1.0, # 'strategies': {'StrategyName': {...}, ...}, # 'experimental': False, # 'address': '0xdA816459F1AB5631232FE5e97a05BBBb94970c95', # 'version': 'v2' # } # Calculate APY samples = get_samples() apy = await vault.apy(samples) print(f"Net APY: {apy.net_apy:.2%}") print(f"Gross APR: {apy.gross_apr:.2%}") print(f"Performance Fee: {apy.fees.performance:.2%}") print(f"Management Fee: {apy.fees.management:.2%}") # Get TVL tvl = await vault.tvl(block=None) print(f"TVL: ${tvl.tvl:,.2f}") # Access strategies strategies = await vault.strategies for strategy in strategies: desc = await strategy.describe(block=None) print(f"Strategy: {strategy.name}, Debt: {desc.get('totalDebt', 0)}") asyncio.run(main()) ``` -------------------------------- ### Interact with Iron Bank Registry (Python) Source: https://context7.com/yearn/yearn-exporter/llms.txt Demonstrates how to initialize the Iron Bank registry, access lending market data, and retrieve detailed descriptions including supply, borrow rates, and TVL. Requires the 'yearn' library. ```python import asyncio from yearn.ironbank import Registry as IronBankRegistry async def main(): # Initialize Iron Bank registry registry = IronBankRegistry(exclude_ib_tvl=False) # Access markets markets = registry.vaults print(f"Found {len(markets)} Iron Bank markets") for market in markets: print(f"Market: {market.name}, Underlying: {market.token_name}") # Describe markets with rates descriptions = await registry.describe(block=None) # Returns: { # 'cyUSDC': { # 'total supply': 1000000, # 'total borrows': 500000, # 'supply apy': 0.05, # 'borrow apy': 0.08, # 'utilization': 0.5, # 'tvl': 1500000, # ... # }, ... # } asyncio.run(main()) ``` -------------------------------- ### Victoria Metrics Output Formatting and Posting (Python) Source: https://context7.com/yearn/yearn-exporter/llms.txt Demonstrates how to build and post metrics to Victoria Metrics using the 'yearn' library. It includes functions for formatting metric items with labels and values, and for sending these metrics to a Victoria Metrics endpoint. It also shows how to check for existing data. ```python import asyncio from yearn.outputs.victoria.victoria import _build_item, _post, has_data async def main(): # Build a metric item item = _build_item( metric="yearn_vault", label_names=["vault", "param"], label_values=["yvUSDC", "tvl"], value=50000000.0, timestamp=1693526400 # Unix timestamp in seconds ) # Returns: { # 'metric': {'__name__': 'yearn_vault', 'vault': 'yvUSDC', 'param': 'tvl', 'network': 'ETH Mainnet'}, # 'values': [50000000.0], # 'timestamps': [1693526400000] # Converted to milliseconds # } # Post metrics to Victoria Metrics metrics = [item] await _post(metrics) # Check if data exists for a timestamp exists = await has_data(1693526400, 'yearn_vault{network="ETH Mainnet"}') print(f"Data exists: {exists}") asyncio.run(main()) ``` -------------------------------- ### List Supported Exporter Commands (Bash) Source: https://github.com/yearn/yearn-exporter/blob/master/readme.md Lists all the available exporter commands (scripts) located in the ./scripts/ directory that can be executed. This helps in understanding the different types of data that can be exported. ```bash # list supported exporter commands: make list-commands ``` -------------------------------- ### List Supported Networks (Bash) Source: https://github.com/yearn/yearn-exporter/blob/master/readme.md Lists all the blockchain networks that the Yearn Exporter currently supports data collection from. This is a utility command to understand the exporter's capabilities. ```bash # list supported networks: make list-networks ``` -------------------------------- ### Show Logs for Exporters on a Specific Network (Bash) Source: https://github.com/yearn/yearn-exporter/blob/master/readme.md Displays the logs for all running exporters on a specified network (e.g., arbitrum). This is helpful for debugging and monitoring exporter activity. Environment variables from .env should be loaded. ```bash # Show the logs of all exporters on arbitrum: make logs network=arbitrum ``` -------------------------------- ### Debug ypm Prices on Optimism (Bash) Source: https://github.com/yearn/yearn-exporter/blob/master/readme.md Enables debug mode for ypm (Yearn Price Module) price fetching on the Optimism network. This is useful for troubleshooting price oracle issues. Environment variables from .env should be loaded. ```bash # debug ypm prices: make debug-price network=optimism ``` -------------------------------- ### Run Full APY Report using Python Source: https://context7.com/yearn/yearn-exporter/llms.txt This Python snippet demonstrates how to execute the `main` function from the `apy` module to generate and print a sorted table of APYs for all Yearn vaults. This is useful for a comprehensive overview of vault performance. ```python from scripts.apy import main # Run full APY report main() # Prints sorted table of all vault APYs ``` -------------------------------- ### Preview Curve Pool APYs (Bash) Source: https://github.com/yearn/yearn-exporter/blob/master/readme.md Initiates a preview of APY calculations for Curve pools. This command is useful for testing or observing APY estimations for specific DeFi integrations. Environment variables from .env should be loaded. ```bash # Start APY preview for curve pools: make curve-apy-previews ``` -------------------------------- ### Perform Multicall Operations (Python) Source: https://context7.com/yearn/yearn-exporter/llms.txt Illustrates efficient batch contract calls using Multicall2. Supports synchronous and asynchronous fetching of multiple contract data points, including a matrix format for calling the same methods across different contracts. Requires 'yearn' and 'y' libraries. ```python import asyncio from yearn.multicall2 import fetch_multicall, fetch_multicall_async, multicall_matrix_async from y import Contract async def main(): # Batch multiple contract calls vault1 = Contract("0xdA816459F1AB5631232FE5e97a05BBBb94970c95") vault2 = Contract("0xa354F35829Ae975e850e23e9615b11Da1B3dC4DE") # Synchronous multicall results = fetch_multicall( [vault1, "totalAssets"], [vault1, "pricePerShare"], [vault2, "totalAssets"], [vault2, "pricePerShare"], block=None ) print(f"Vault1 assets: {results[0]}, PPS: {results[1]}") print(f"Vault2 assets: {results[2]}, PPS: {results[3]}") # Async multicall results_async = await fetch_multicall_async( [vault1, "totalAssets"], [vault1, "decimals"], [vault2, "totalAssets"], block=18000000 ) # Matrix multicall - call same methods on multiple contracts contracts = [vault1, vault2] params = ["totalAssets", "pricePerShare", "decimals"] matrix = await multicall_matrix_async(contracts, params, block=None) # Returns: {vault1: {'totalAssets': X, 'pricePerShare': Y, 'decimals': 18}, ...} asyncio.run(main()) ``` -------------------------------- ### Stop All Docker Infrastructure (Bash) Source: https://github.com/yearn/yearn-exporter/blob/master/readme.md Stops and removes all Docker containers and associated infrastructure defined in the Docker Compose file, effectively cleaning up the entire environment. Environment variables from .env should be loaded. ```bash # stop all docker infrastructure: make down filter=infra ``` -------------------------------- ### Debug APY for a Specific Vault on Ethereum (Bash) Source: https://github.com/yearn/yearn-exporter/blob/master/readme.md Enables debug mode for the APY exporter on Ethereum, focusing on a specific vault. Requires setting the DEBUG_ADDRESS environment variable to the vault's contract address. Environment variables from .env should be loaded. ```bash # Start APY Debug on ethereum for a specific vault: export DEBUG_ADDRESS=vault_address_here && make debug-apy network=eth ``` -------------------------------- ### iEarn Registry Operations (Python) Source: https://context7.com/yearn/yearn-exporter/llms.txt Details how to use the iEarn registry to interact with legacy yield-bearing tokens. It shows how to list vaults, retrieve detailed descriptions of each vault (including supply, balance, price, and TVL), and calculate the total value locked across all iEarn vaults. ```python import asyncio from yearn.iearn import Registry, Earn async def main(): # iEarn registry (Mainnet only) registry = Registry() # List all iEarn vaults for vault in registry.vaults: print(f"Vault: {vault.name}, Address: {vault.vault.address}") # Describe all vaults descriptions = await registry.describe(block=None) # Returns: { # 'yDAIv2': { # 'total supply': 1000000, # 'available balance': 100000, # 'pooled balance': 900000, # 'price per share': 1.05, # 'token price': 1.0, # 'tvl': 945000, # ... # }, ... # } # Get TVL tvl = await registry.total_value_at(block=None) asyncio.run(main()) ``` -------------------------------- ### Calculate APY for Yearn Vaults (Python) Source: https://context7.com/yearn/yearn-exporter/llms.txt Shows how to calculate APY for Yearn V2 vaults and Curve vaults using historical block data. It utilizes the 'yearn.apy' module and requires block samples. Handles potential APY calculation errors. ```python import asyncio import dataclasses from yearn.apy import get_samples, v2, curve from yearn.apy.common import Apy, ApySamples, ApyError from yearn.v2.vaults import Vault async def main(): # Get block samples for APY calculation samples = get_samples() print(f"Current block: {samples.now}") print(f"Week ago block: {samples.week_ago}") print(f"Month ago block: {samples.month_ago}") # Calculate V2 vault APY (averaged method for v0.3.2+) vault = Vault.from_address("0xa354F35829Ae975e850e23e9615b11Da1B3dC4DE") # yvUSDC try: apy = await v2.average(vault, samples) print(f"APY Type: {apy.type}") print(f"Net APY: {apy.net_apy:.2%}") print(f"Gross APR: {apy.gross_apr:.2%}") print(f"Week APY: {apy.points.week_ago:.2%}") print(f"Month APY: {apy.points.month_ago:.2%}") print(f"Inception APY: {apy.points.inception:.2%}") except ApyError as e: print(f"APY calculation failed: {e}") # For Curve vaults, use curve-specific APY calculation curve_vault = Vault.from_address("0xd88dBBA3f9c4391Ee46f5FF548f289054db6E51C") curve_apy = await curve.simple(curve_vault, samples) print(f"Curve APY composite: {curve_apy.composite}") asyncio.run(main()) ``` -------------------------------- ### Custom Data Export to Victoria Metrics (Python) Source: https://context7.com/yearn/yearn-exporter/llms.txt Defines a custom data fetching function and configures an Exporter to send vault TVL metrics to Victoria Metrics. It requires the 'yearn' library and handles data transformation into a metrics format. The exporter can run historically or in real-time. ```python import asyncio from datetime import datetime, timezone from yearn.helpers.exporter import Exporter from yearn.outputs.victoria.victoria import _post from yearn.yearn import Yearn from y.time import closest_block_after_timestamp async def custom_data_fn(block: int, timestamp: int): """Custom data fetching function.""" yearn = Yearn() data = await yearn.describe(block) # Transform data into metrics format metrics = [] for product, vaults in data.items(): for vault_name, params in vaults.items(): if isinstance(params, dict) and 'tvl' in params: metrics.append({ 'metric': {'__name__': 'vault_tvl', 'vault': vault_name}, 'values': [params['tvl']], 'timestamps': [timestamp * 1000] }) return metrics # Create exporter start = datetime(2020, 2, 12, tzinfo=timezone.utc) exporter = Exporter( name='custom_vaults', data_query='vault_tvl{network="ETH Mainnet"}', data_fn=custom_data_fn, export_fn=_post, start_block=closest_block_after_timestamp(int(start.timestamp())) - 1, concurrency=4 ) # Run exporter (blocks forever, exports historical + future data) # exporter.run() # Or run specific direction # exporter.run(direction="historical") # Only backfill # exporter.run(direction="forward") # Only future blocks ``` -------------------------------- ### Calculate APY for a Specific Vault using Python Source: https://context7.com/yearn/yearn-exporter/llms.txt This Python snippet shows how to calculate the Annual Percentage Yield (APY) for a specific Yearn vault by calling the `calculate_apy` function with the vault's address. It imports necessary functions from the `apy` module. ```python from scripts.apy import calculate_apy # Calculate APY for specific vault calculate_apy("0xdA816459F1AB5631232FE5e97a05BBBb94970c95") # yvDAI ``` -------------------------------- ### Stop All Exporters (Bash) Source: https://github.com/yearn/yearn-exporter/blob/master/readme.md Stops all running Yearn Exporter Docker containers. This is a comprehensive command to halt all data collection processes. Environment variables from .env should be loaded. ```bash # stop all exporters: make down ``` -------------------------------- ### Stop Containers Matching a Filter (Bash) Source: https://github.com/yearn/yearn-exporter/blob/master/readme.md Stops Docker containers whose names contain a specific substring (filter). This allows for targeted stopping of services, such as stopping all 'treasury' related containers. Environment variables from .env should be loaded. ```bash # Stop all containers matching a string in their name, e.g. treasury: make down filter=treasury ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.