### Install and Run Pre-commit Hooks Source: https://github.com/charli3-official/charli3-dendrite/blob/main/CONTRIBUTING.md Install pre-commit hooks locally to lint and format code before committing. This helps catch issues early. ```bash pre-commit install && pre-commit run --all-files ``` -------------------------------- ### Install Charli3 Dendrite Source: https://github.com/charli3-official/charli3-dendrite/blob/main/docs/index.md Install the Charli3 Dendrite library using pip or Poetry. ```bash # Using pip pip install charli3_dendrite # Using Poetry poetry add charli3_dendrite ``` -------------------------------- ### Build and Serve Documentation Locally Source: https://github.com/charli3-official/charli3-dendrite/blob/main/CONTRIBUTING.md Install project dependencies using poetry and serve the MkDocs documentation locally. Changes will auto-update in the browser. ```bash poetry install && poetry run mkdocs serve ``` -------------------------------- ### Install Charli3 Dendrite with Pip Source: https://github.com/charli3-official/charli3-dendrite/blob/main/README.md Install the Charli3 Dendrite SDK using pip. This is the standard method for adding Python packages to your project. ```bash pip install charli3_dendrite ``` -------------------------------- ### Install Charli3 Dendrite with Poetry Source: https://github.com/charli3-official/charli3-dendrite/blob/main/README.md Add the Charli3 Dendrite SDK to your project using Poetry. This is useful for projects managed with Poetry for dependency management. ```bash poetry add charli3_dendrite ``` -------------------------------- ### Create VyFi Advanced Order Examples Source: https://github.com/charli3-official/charli3-dendrite/blob/main/docs/vyfi.md Demonstrates how to construct various advanced order types for VyFi, including Zap In, Withdraw, and standard A to B swaps. This is useful for understanding and implementing complex trading logic. ```python from pycardano import Address, Assets def create_vyfi_advanced_orders(): """Demonstrate VyFi's advanced order types and capabilities.""" source_address = Address.from_bech32("addr1...") # Example: Zap In A (single asset to LP tokens) zap_in_order = VyFiOrderDatum( address=source_address.payment_part.to_primitive() + source_address.staking_part.to_primitive(), order=ZapInA(min_lp_receive=1000000) # Minimum 1 LP token ) # Example: Withdraw (LP tokens to underlying assets) withdraw_order = VyFiOrderDatum( address=source_address.payment_part.to_primitive() + source_address.staking_part.to_primitive(), order=Withdraw( min_lp_receive=WithdrawPair( min_amount_a=500000, # Minimum asset A min_amount_b=500000 # Minimum asset B ) ) ) # Example: Standard A to B swap swap_order = VyFiOrderDatum( address=source_address.payment_part.to_primitive() + source_address.staking_part.to_primitive(), order=AtoB(min_receive=1000000) # Minimum receive amount ) order_types = { 'zap_in_a': { 'description': 'Single asset entry to LP position', 'use_case': 'Simplified liquidity provision', 'order': zap_in_order }, 'withdraw': { 'description': 'LP tokens to underlying assets', 'use_case': 'Exit liquidity position', 'order': withdraw_order }, 'standard_swap': { 'description': 'Traditional A to B swap', 'use_case': 'Regular token exchange', 'order': swap_order } } print("šŸ“‹ VyFi Advanced Order Types:") for order_type, details in order_types.items(): print(f" {order_type.replace('_', ' ').title()}:") print(f" Description: {details['description']}") print(f" Use Case: {details['use_case']}") print(f" Order Type: {type(details['order'].order).__name__}") return order_types # Create advanced order examples advanced_orders = create_vyfi_advanced_orders() ``` -------------------------------- ### Analyze GeniusYield Fee Structures Source: https://github.com/charli3-official/charli3-dendrite/blob/main/docs/geniusyield.md Analyzes and prints the fee structures for different versions of GeniusYield orders. It includes example calculations for various amounts to illustrate fee application. ```python def analyze_genius_yield_fees(order_version: str = "v1.1"): """Analyze GeniusYield fee structures.""" fee_structure = { 'v1': { 'base_fee': 30, # 0.3% 'rounding': 'ceil', # Round up for V1 'calculation': 'fee = ceil(amount * 30 / 10000)' }, 'v1.1': { 'base_fee': 30, # 0.3% 'rounding': 'floor', # Floor for V1.1 'calculation': 'fee = amount * 30 // 10000' } } version_data = fee_structure.get(order_version, fee_structure['v1.1']) print(f"GeniusYield {order_version.upper()} Fee Structure:") print(f" Base Fee: {version_data['base_fee']}bp ({version_data['base_fee']/100}%)") print(f" Rounding: {version_data['rounding']}") print(f" Calculation: {version_data['calculation']}") # Example calculations for different amounts test_amounts = [1000000, 10000000, 100000000, 1000000000] print(f"\nFee Examples:") for amount in test_amounts: if order_version == "v1": fee = -(-amount * 30 // 10000) # Ceiling division else: fee = amount * 30 // 10000 print(f" {amount/1000000} ADA -> {fee} lovelace fee ({fee/amount*100:.3f}%)") return version_data # Analyze both versions v1_fees = analyze_genius_yield_fees("v1") print("\n" + "="*50) v1_1_fees = analyze_genius_yield_fees("v1.1") ``` -------------------------------- ### Calculate V2 Pool Fees Source: https://github.com/charli3-official/charli3-dendrite/blob/main/docs/wingriders.md Provides an example of calculating the total fee for V2 WingRiders pools. It sums up swap, protocol, and project fees based on the pool's fee basis. ```python # Ensure correct fee calculation for V2 pools pool_datum = pool.pool_datum calculated_fee = ( pool_datum.swap_fee_in_basis + pool_datum.protocol_fee_in_basis + pool_datum.project_fee_in_basis ) * 10000 / pool_datum.fee_basis ``` -------------------------------- ### Implement VyFi API Integration Best Practices Source: https://github.com/charli3-official/charli3-dendrite/blob/main/docs/vyfi.md Guides on implementing efficient pool management for VyFi API integration. It covers practices like targeted asset filtering, cache management, error handling, and batch processing to optimize performance and robustness. ```python def implement_vyfi_best_practices(): """Implement best practices for VyFi API integration.""" best_practices = { 'pool_discovery': { 'practice': 'Use targeted asset filtering', 'implementation': 'VyFiCPPState.pool_selector(assets=["specific", "assets"])', 'benefit': 'Faster discovery, reduced overhead' }, 'cache_management': { 'practice': 'Respect cache refresh intervals', 'implementation': 'Allow automatic refresh every 3600 seconds', 'benefit': 'Optimal balance of freshness and performance' }, 'error_handling': { 'practice': 'Handle API unavailability gracefully', 'implementation': 'Catch exceptions during pool refresh', 'benefit': 'Robust application behavior' }, 'batch_processing': { 'practice': 'Process multiple pools efficiently', 'implementation': 'Group operations on similar pools', 'benefit': 'Improved throughput and reduced latency' } } print("šŸ“‹ VyFi Integration Best Practices:") for practice_area, details in best_practices.items(): print(f"\n {practice_area.replace('_', ' ').title()}:") print(f" Practice: {details['practice']}") print(f" Implementation: {details['implementation']}") print(f" Benefit: {details['benefit']}") return best_practices # Get best practices guide best_practices = implement_vyfi_best_practices() ``` -------------------------------- ### Trade on DJED/USDC Stable Pool Source: https://github.com/charli3-official/charli3-dendrite/blob/main/docs/minswap.md Example of performing a swap on a DJED/USDC stable pool. This snippet shows how to calculate the output amount of USDC for a given input of DJED and the associated slippage. ```python # Example: Trading on DJED/USDC stable pool from charli3_dendrite import MinswapDJEDUSDCStableState from pycardano import Assets pool = MinswapDJEDUSDCStableState.model_validate(pool_data) # Swap 100 DJED for USDC with minimal slippage djed_input = Assets({"djed_policy": 100000000}) # 100 DJED (6 decimals) usdc_output, slippage = pool.get_amount_out(djed_input) print(f"Input: 100 DJED") print(f"Output: {usdc_output} USDC") print(f"Slippage: {slippage:.6f}%") ``` -------------------------------- ### Get V1 Stable Swap Pool Data and Calculate Slippage Source: https://github.com/charli3-official/charli3-dendrite/blob/main/docs/wingriders.md Fetches data for V1 Stable Swap Pools (SSP) and demonstrates how to calculate the output amount and slippage for a given stable asset input. This is useful for stablecoin pairs where low slippage is crucial. ```python from charli3_dendrite import WingRidersSSPState # Get V1 SSP pool data for stablecoin pairs selector = WingRidersSSPState.pool_selector() pools = backend.get_pool_utxos(**selector.model_dump()) for pool_info in pools: pool = WingRidersSSPState.model_validate(pool_info.model_dump()) print(f"Stable Pool: {pool.pool_id}") print(f"Fee: {pool.fee}bp (0.06%)") print(f"Assets: {pool.unit_a} / {pool.unit_b}") # Low slippage calculation for stable assets from pycardano import Assets stable_input = Assets({"usdc_policy": 1000000}) # 1 USDC stable_output, slippage = pool.get_amount_out(stable_input) print(f"Slippage: {slippage:.6f}%") ``` -------------------------------- ### Get Splash CPP Pools Source: https://github.com/charli3-official/charli3-dendrite/blob/main/docs/splash.md Retrieves and processes data for Splash Constant Product Pools (CPP). It fetches pool UTXOs and prints their total value locked (TVL) and current price. ```python from charli3_dendrite import SplashCPPState, SplashSSPState, SplashCPPBidirState from charli3_dendrite.backend import get_backend # Get Splash CPP pools backend = get_backend() selector = SplashCPPState.pool_selector() pools = backend.get_pool_utxos(**selector.model_dump()) # Process pool data for pool_info in pools: pool = SplashCPPState.model_validate(pool_info.model_dump()) print(f"Pool TVL: {pool.tvl}") print(f"Pool Price: {pool.price}") ``` -------------------------------- ### Get V1 Constant Product Pool Data Source: https://github.com/charli3-official/charli3-dendrite/blob/main/docs/wingriders.md Retrieves and processes data for V1 Constant Product Pools (CPP) using the charli3-dendrite library. This snippet shows how to fetch pool UTXOs and display basic pool information like ID, assets, TVL, fee, and price. ```python from charli3_dendrite import WingRidersCPPState from charli3_dendrite.backend import get_backend # Get V1 CPP pool data backend = get_backend() selector = WingRidersCPPState.pool_selector() pools = backend.get_pool_utxos(**selector.model_dump()) # Process pool information for pool_info in pools: pool = WingRidersCPPState.model_validate(pool_info.model_dump()) print(f"Pool ID: {pool.pool_id}") print(f"Assets: {pool.unit_a} / {pool.unit_b}") print(f"TVL: {pool.tvl}") print(f"Fee: {pool.fee}bp (0.35%)") print(f"Price: {pool.price}") ``` -------------------------------- ### Get MuesliSwap Concentrated Liquidity Pool Data Source: https://github.com/charli3-official/charli3-dendrite/blob/main/docs/muesliswap.md Retrieves data for Concentrated Liquidity Pools (CLP) on MuesliSwap. This snippet is a starting point for interacting with advanced CLP features. ```python from charli3_dendrite import MuesliSwapCLPState # Get MuesliSwap CLP pool data selector = MuesliSwapCLPState.pool_selector() cl_pools = backend.get_pool_utxos(**selector.model_dump()) ``` -------------------------------- ### Initialize Backend and Retrieve Data Source: https://github.com/charli3-official/charli3-dendrite/blob/main/README.md Initialize the Charli3 Dendrite backend and prepare to retrieve orders and pool data. Uncomment the desired backend initialization. ```python from charli3_dendrite.backend import set_backend, get_backend from charli3_dendrite.backend.dbsync import DbsyncBackend from charli3_dendrite.backend.blockfrost import BlockFrostBackend from charli3_dendrite.backend.ogmios_kupo import OgmiosKupoBackend from pycardano import Network # Choose one of the following backends: # set_backend(DbsyncBackend()) ``` -------------------------------- ### Get V1 Pool Data Source: https://github.com/charli3-official/charli3-dendrite/blob/main/docs/sundae.md Retrieves and processes information for SundaeSwap V1 pools. Requires the charli3-dendrite backend and SundaeSwapCPPState. ```python from charli3_dendrite import SundaeSwapCPPState from charli3_dendrite.backend import get_backend # Get V1 pool data backend = get_backend() selector = SundaeSwapCPPState.pool_selector() pools = backend.get_pool_utxos(**selector.model_dump()) # Process pool information for pool_info in pools: pool = SundaeSwapCPPState.model_validate(pool_info.model_dump()) print(f"Pool ID: {pool.pool_id}") print(f"Assets: {pool.unit_a} / {pool.unit_b}") print(f"TVL: {pool.tvl}") print(f"Fee: {pool.fee}bp") print(f"DEX: {pool.dex()}") ``` -------------------------------- ### Configure DBSync Backend Source: https://github.com/charli3-official/charli3-dendrite/blob/main/README.md Set environment variables to configure the DBSync backend for Charli3 Dendrite. Ensure these variables point to your running DBSync instance. ```bash DBSYNC_HOST="your-dbsync-host" DBSYNC_PORT="your-dbsync-port" DBSYNC_DB_NAME="your-dbsync-database-name" DBSYNC_USER="your-dbsync-username" DBSYNC_PASS="your-dbsync-password" ``` -------------------------------- ### Get V3 Pool Data Source: https://github.com/charli3-official/charli3-dendrite/blob/main/docs/sundae.md Retrieves and processes information for SundaeSwap V3 pools, highlighting dynamic fees. Uses SundaeSwapV3CPPState. ```python from charli3_dendrite import SundaeSwapV3CPPState # Get V3 pool data with dynamic fees selector = SundaeSwapV3CPPState.pool_selector() pools = backend.get_pool_utxos(**selector.model_dump()) for pool_info in pools: pool = SundaeSwapV3CPPState.model_validate(pool_info.model_dump()) print(f"V3 Pool ID: {pool.pool_id}") print(f"Assets: {pool.unit_a} / {pool.unit_b}") print(f"Dynamic Fees: {pool.fee}" ) # [bid_fee, ask_fee] print(f"Script Version: {pool.default_script_class()}") print(f"Batcher Fee: {pool.batcher_fee()}") ``` -------------------------------- ### Configure Ogmios/Kupo Backend Source: https://github.com/charli3-official/charli3-dendrite/blob/main/README.md Set environment variables to configure the Ogmios/Kupo backend. Provide the URLs for your Ogmios and Kupo instances and the Cardano network. ```bash OGMIOS_URL="ws://your-ogmios-url:port" KUPO_URL="http://your-kupo-url:port" CARDANO_NETWORK="mainnet" # or "testnet" for the Cardano testnet ``` -------------------------------- ### Get All WingRiders Pools Source: https://github.com/charli3-official/charli3-dendrite/blob/main/docs/wingriders.md Retrieves all available WingRiders pools, categorized by pool type. This is a foundational step before performing any pool analysis or trades. ```python all_pools = await get_all_wing_riders_pools() for pool_type, pools in all_pools.items(): print(f"{pool_type}: {len(pools)} pools") ``` -------------------------------- ### Migrate V1 Pools to V2 Source: https://github.com/charli3-official/charli3-dendrite/blob/main/docs/wingriders.md Demonstrates querying V1 and V2 pools using their respective selectors and highlights migration benefits like dynamic fees and PlutusV2 efficiency. ```python # V1 to V2 Migration Example from charli3_dendrite import WingRidersCPPState, WingRidersV2CPPState # V1 Pool Query v1_selector = WingRidersCPPState.pool_selector() v1_pools = backend.get_pool_utxos(**v1_selector.model_dump()) # V2 Equivalent v2_selector = WingRidersV2CPPState.pool_selector() v2_pools = backend.get_pool_utxos(**v2_selector.model_dump()) print("Migration Benefits:") print("āœ… Dynamic fees instead of fixed rates") print("āœ… PlutusV2 script efficiency") print("āœ… Enhanced treasury management") print("āœ… Better capital utilization") ``` -------------------------------- ### Optimize Spectrum Trading with Reference UTxO Source: https://github.com/charli3-official/charli3-dendrite/blob/main/docs/spectrum.md Demonstrates how to use Spectrum's reference UTxO for significant cost savings and performance improvements in trading operations. This method minimizes transaction size and optimizes validation speed. ```python def optimize_spectrum_trading(): """Demonstrate Spectrum's reference UTxO optimization.""" # Get reference UTxO for script optimization ref_utxo = SpectrumCPPState.reference_utxo() if ref_utxo: print("šŸš€ Spectrum Reference UTxO Found:") print(f" Transaction: {ref_utxo.input.transaction_id}") print(f" Output Index: {ref_utxo.input.index}") print(f" Script Class: {SpectrumCPPState.default_script_class()}") # This enables significant cost savings and performance improvements optimization_benefits = { 'script_execution_cost': 'Reduced by ~50%', 'transaction_size': 'Minimized through reference', 'validation_speed': 'Significantly improved', 'fee_efficiency': 'Optimized for large volumes' } print("\nšŸ’” Optimization Benefits:") for benefit, description in optimization_benefits.items(): print(f" {benefit}: {description}") else: print("āš ļø Reference UTxO not available - using standard execution") return ref_utxo # Optimize trading operations ref_utxo = optimize_spectrum_trading() ``` -------------------------------- ### Get and Process Spectrum Pool Data Source: https://github.com/charli3-official/charli3-dendrite/blob/main/docs/spectrum.md Retrieves cross-chain pool information from Spectrum using the SpectrumCPPState model and backend. Useful for understanding available liquidity and pool configurations. ```python from charli3_dendrite import SpectrumCPPState from charli3_dendrite.backend import get_backend # Get Spectrum pool data backend = get_backend() selector = SpectrumCPPState.pool_selector() pools = backend.get_pool_utxos(**selector.model_dump()) # Process cross-chain pool information for pool_info in pools: pool = SpectrumCPPState.model_validate(pool_info.model_dump()) print(f"Pool ID: {pool.pool_id}") print(f"Cross-Chain Assets: {pool.unit_a} / {pool.unit_b}") print(f"TVL: {pool.tvl}") print(f"Fee Model: {pool.fee}bp") print(f"DEX: {pool.dex()}") print(f"Reference UTxO: {pool.reference_utxo()}") ``` -------------------------------- ### Configure BlockFrost Backend Source: https://github.com/charli3-official/charli3-dendrite/blob/main/README.md Set environment variables to configure the BlockFrost backend. You need your BlockFrost project ID and the desired Cardano network. ```bash BLOCKFROST_PROJECT_ID="your-blockfrost-project-id" CARDANO_NETWORK="mainnet" # or "testnet" for the Cardano testnet ``` -------------------------------- ### Query Minswap V1 and V2 Pool UTXOs Source: https://github.com/charli3-official/charli3-dendrite/blob/main/docs/minswap.md Demonstrates how to query for V1 and V2 pool UTXOs using their respective selectors. This is useful for migrating or comparing pool states. ```python # V1 pool query v1_selector = MinswapCPPState.pool_selector() v1_pools = backend.get_pool_utxos(**v1_selector.model_dump()) # V2 equivalent v2_selector = MinswapV2CPPState.pool_selector() v2_pools = backend.get_pool_utxos(**v2_selector.model_dump()) # V2 offers dynamic fees and better efficiency for pool_info in v2_pools: pool = MinswapV2CPPState.model_validate(pool_info.model_dump()) print(f"Dynamic fees: {pool.fee}") ``` -------------------------------- ### Get MuesliSwap Constant Product Pool Data Source: https://github.com/charli3-official/charli3-dendrite/blob/main/docs/muesliswap.md Retrieves and processes data for traditional Constant Product Pools (CPP) on MuesliSwap. This snippet is useful for understanding the basic properties of existing CPPs. ```python from charli3_dendrite import MuesliSwapCPPState from charli3_dendrite.backend import get_backend # Get MuesliSwap CPP pool data backend = get_backend() selector = MuesliSwapCPPState.pool_selector() pools = backend.get_pool_utxos(**selector.model_dump()) # Process traditional AMM pools for pool_info in pools: pool = MuesliSwapCPPState.model_validate(pool_info.model_dump()) print(f"CPP Pool ID: {pool.pool_id}") print(f"Assets: {pool.unit_a} / {pool.unit_b}") print(f"TVL: {pool.tvl}") print(f"Fee: {pool.fee}bp (0.3%)") print(f"Pool Type: Traditional AMM") print(f"DEX: {pool.dex()}") ``` -------------------------------- ### Query V1 Constant Product Pools Source: https://github.com/charli3-official/charli3-dendrite/blob/main/docs/minswap.md Retrieves and displays information for V1 Constant Product Pools. Requires initialization of the backend and uses MinswapCPPState. ```python from charli3_dendrite import MinswapCPPState from charli3_dendrite.backend import get_backend # Get V1 pool data backend = get_backend() selector = MinswapCPPState.pool_selector() pools = backend.get_pool_utxos(**selector.model_dump()) # Process pool information for pool_info in pools: pool = MinswapCPPState.model_validate(pool_info.model_dump()) print(f"Pool ID: {pool.pool_id}") print(f"Assets: {pool.unit_a} / {pool.unit_b}") print(f"TVL: {pool.tvl}") print(f"Price A->B: {pool.price[0]}") print(f"Fee: {pool.fee}bp") ``` -------------------------------- ### Access Minswap LP Token Information Source: https://github.com/charli3-official/charli3-dendrite/blob/main/docs/minswap.md Retrieve LP token policies for V1 and V2 pools. Also demonstrates how to get the unit identifier for LP tokens from a specific V2 pool. ```python # Access LP token information v1_lp_policy = MinswapCPPState.lp_policy() v2_lp_policy = MinswapV2CPPState.lp_policy() print(f"V1 LP Policy: {v1_lp_policy}") print(f"V2 LP Policy: {v2_lp_policy}") # Get pool-specific LP tokens pool = MinswapV2CPPState.model_validate(pool_data) lp_token_unit = pool.lp_tokens.unit() ``` -------------------------------- ### Query All Minswap Pool Types Source: https://github.com/charli3-official/charli3-dendrite/blob/main/docs/minswap.md Demonstrates querying all available Minswap pool types by iterating through a list of pool classes. This allows for a comprehensive overview of available pools. ```python # Query all Minswap pool types from charli3_dendrite import ( MinswapCPPState, MinswapV2CPPState, MinswapDJEDiUSDStableState, MinswapDJEDUSDCStableState ) all_minswap_pools = [ MinswapCPPState, # V1 CPP MinswapV2CPPState, # V2 CPP MinswapDJEDiUSDStableState, # DJED/iUSD Stable MinswapDJEDUSDCStableState, # DJED/USDC Stable # Add other stable pools as needed ] for pool_class in all_minswap_pools: selector = pool_class.pool_selector() pools = backend.get_pool_utxos(**selector.model_dump()) print(f"{pool_class.__name__}: {len(pools)} pools") ``` -------------------------------- ### Compare V1 and V2 Pool Features Source: https://github.com/charli3-official/charli3-dendrite/blob/main/docs/wingriders.md Compares features between V1 and V2 Constant Product Pools (CPP) by analyzing pool data. This snippet demonstrates how to access fixed fees and DEX information for V1 pools. ```python # Compare V1 vs V2 pool features from charli3_dendrite import WingRidersCPPState, WingRidersV2CPPState # V1 Pool Analysis v1_pool = WingRidersCPPState.model_validate(v1_pool_data) print(f"V1 Fixed Fee: {v1_pool.fee}bp") print(f"V1 DEX: {v1_pool.dex()}") ``` -------------------------------- ### Get and Process CSwap ADA-paired Pools Source: https://github.com/charli3-official/charli3-dendrite/blob/main/docs/cswap.md Retrieves CSwap pool data using the CSwapCPPState and backend functionalities. It iterates through ADA-paired pools, printing key information like Pool ID, TVL, and fees. ```python from charli3_dendrite import CSwapCPPState from charli3_dendrite.backend import get_backend from charli3_dendrite.dataclasses.models import Assets # Get CSwap pool data backend = get_backend() selector = CSwapCPPState.pool_selector() pools = backend.get_pool_utxos(**selector.model_dump()) # Process ADA-paired pools for pool_info in pools: pool = CSwapCPPState.model_validate(pool_info.model_dump()) print(f"Pool ID: {pool.pool_id}") print(f"ADA Pair: {pool.unit_a} / {pool.unit_b}") print(f"TVL: {pool.tvl}") print(f"Fee: {pool.fee}bp") print(f"DEX: {pool.dex()}") ``` -------------------------------- ### Implement Concentrated Liquidity Best Practices Source: https://github.com/charli3-official/charli3-dendrite/blob/main/docs/muesliswap.md This Python function defines and prints best practices for concentrated liquidity position management, including range selection, capital allocation, rebalancing strategies, and risk management. It also generates a management checklist. ```python def implement_cl_best_practices(): """Implement best practices for concentrated liquidity position management.""" best_practices = { 'range_selection': { 'principle': 'Choose ranges based on expected price volatility', 'tight_ranges': 'Use for stable pairs and active management', 'wide_ranges': 'Use for volatile pairs and passive strategies', 'monitoring': 'Regular price monitoring and range health checks' }, 'capital_allocation': { 'principle': 'Diversify across multiple ranges and strategies', 'single_position': 'High risk, high reward - requires active management', 'multiple_positions': 'Lower risk, diversified returns', 'portfolio_approach': 'Combine different range strategies' }, 'rebalancing_strategy': { 'principle': 'Proactive position management for optimal returns', 'triggers': 'Price approaching range boundaries', 'frequency': 'Based on volatility and range width', 'automation': 'Consider automated rebalancing tools' }, 'risk_management': { 'principle': 'Understand and mitigate concentrated liquidity risks', 'impermanent_loss': 'Higher in concentrated positions', 'range_risk': 'Risk of price moving outside range', 'diversification': 'Spread risk across multiple positions' } } # Create position management checklist management_checklist = [ "āœ“ Define clear range strategy (tight, moderate, or wide)", "āœ“ Set up price monitoring and alerts", "āœ“ Plan rebalancing triggers and frequency", "āœ“ Calculate expected returns vs risks", "āœ“ Prepare emergency exit strategy", "āœ“ Monitor pool health and liquidity", "āœ“ Track fee generation and efficiency", "āœ“ Regular portfolio review and optimization" ] print("šŸ“š Concentrated Liquidity Best Practices:") for practice, details in best_practices.items(): print(f"\n {practice.replace('_', ' ').title()}:") for key, value in details.items(): print(f" {key.replace('_', ' ').title()}: {value}") print(f"\n Position Management Checklist:") for item in management_checklist: print(f" {item}") return { 'practices': best_practices, 'checklist': management_checklist } # Implement best practices cl_best_practices = implement_cl_best_practices() ``` -------------------------------- ### Dynamic Pool Discovery and Processing in VyFi Source: https://github.com/charli3-official/charli3-dendrite/blob/main/docs/vyfi.md This snippet demonstrates how to use VyFi's `VyFiCPPState` to dynamically discover available liquidity pools via the API. It retrieves pool information, validates it, and prints key details such as pool ID, assets, TVL, dynamic fees, and live status. ```python from charli3_dendrite import VyFiCPPState from charli3_dendrite.backend import get_backend # Get VyFi pools with dynamic discovery backend = get_backend() # VyFi automatically discovers available pools selector = VyFiCPPState.pool_selector() pools = backend.get_pool_utxos(**selector.model_dump()) # Process dynamically discovered pools for pool_info in pools: pool = VyFiCPPState.model_validate(pool_info.model_dump()) print(f"Pool ID: {pool.pool_id}") print(f"API-Managed Assets: {pool.unit_a} / {pool.unit_b}") print(f"TVL: {pool.tvl}") print(f"Dynamic Fees: LP={pool.lp_fee}bp, Bar={pool.bar_fee}bp") print(f"Pool Status: {'Live' if pool.is_live else 'Inactive'}") ``` -------------------------------- ### Migrate V1 SSP to V2 SSP Source: https://github.com/charli3-official/charli3-dendrite/blob/main/docs/wingriders.md Compares V1 and V2 SSP pool configurations, highlighting V2's dynamic multipliers and precise decimal handling. ```python # V1 SSP to V2 SSP Migration from charli3_dendrite import WingRidersSSPState, WingRidersV2SSPState v1_ssp = WingRidersSSPState.model_validate(v1_ssp_data) v2_ssp = WingRidersV2SSPState.model_validate(v2_ssp_data) print("SSP Enhancements:") print(f"V1 Fixed Multipliers: [1, 1]") print(f"V2 Dynamic Multipliers: {v2_ssp.asset_mulitipliers}") print("āœ… Configurable scaling factors") print("āœ… Precise decimal handling") ``` -------------------------------- ### Optimize Capital Efficiency with MuesliSwap CLP Source: https://github.com/charli3-official/charli3-dendrite/blob/main/docs/muesliswap.md This Python function analyzes MuesliSwap Concentrated Liquidity Pools (CLP) to suggest capital efficiency strategies. It retrieves pool data, categorizes pools based on their price range, and prints a summary of strategies and real pool examples. ```python def optimize_capital_efficiency(): """Optimize capital efficiency using MuesliSwap's concentrated liquidity pools.""" # Get CLP pools for efficiency analysis selector = MuesliSwapCLPState.pool_selector() clp_pools = backend.get_pool_utxos(**selector.model_dump()) efficiency_strategies = { 'tight_range_strategy': { 'description': 'Concentrate liquidity in narrow price ranges', 'capital_multiplier': '10-100x', 'risk_level': 'High', 'best_for': 'Stable pairs, market making', 'management_required': 'Active' }, 'moderate_range_strategy': { 'description': 'Balanced range width for steady returns', 'capital_multiplier': '3-10x', 'risk_level': 'Medium', 'best_for': 'Major trading pairs', 'management_required': 'Moderate' }, 'wide_range_strategy': { 'description': 'Wide ranges for passive liquidity provision', 'capital_multiplier': '1.5-3x', 'risk_level': 'Low', 'best_for': 'Volatile pairs, passive income', 'management_required': 'Minimal' } } # Analyze actual pool efficiency efficiency_examples = [] for pool_info in clp_pools: try: pool = MuesliSwapCLPState.model_validate(pool_info.model_dump()) if not pool.inactive and hasattr(pool, 'pool_datum') and pool.pool_datum: datum = pool.pool_datum if hasattr(datum, 'upper') and hasattr(datum, 'lower'): lower = datum.lower.numerator / datum.lower.denominator upper = datum.upper.numerator / datum.upper.denominator range_ratio = upper / lower if lower > 0 else 0 # Estimate efficiency based on range if range_ratio < 1.1: # Very tight range efficiency_tier = 'tight_range_strategy' elif range_ratio < 2.0: # Moderate range efficiency_tier = 'moderate_range_strategy' else: # Wide range efficiency_tier = 'wide_range_strategy' efficiency_examples.append({ 'pool_id': pool.pool_id[:16] + '...', 'range_ratio': range_ratio, 'strategy': efficiency_tier, 'estimated_multiplier': efficiency_strategies[efficiency_tier]['capital_multiplier'] }) except Exception: continue print("šŸ’° Capital Efficiency Optimization Strategies:") for strategy, details in efficiency_strategies.items(): print(f"\n {strategy.replace('_', ' ').title()}:") for key, value in details.items(): print(f" {key.replace('_', ' ').title()}: {value}") if efficiency_examples: print(f"\n Real Pool Examples:") for example in efficiency_examples[:5]: print(f" Pool {example['pool_id']}: {example['strategy']} ({example['estimated_multiplier']} efficiency)") return { 'strategies': efficiency_strategies, 'examples': efficiency_examples } # Optimize capital efficiency efficiency_optimization = optimize_capital_efficiency() ``` -------------------------------- ### Set Ogmios/Kupo Backend Source: https://github.com/charli3-official/charli3-dendrite/blob/main/README.md Configure the Charli3 Dendrite backend to use Ogmios and Kupo for blockchain data. Ensure the correct URLs and network are specified. ```python set_backend(OgmiosKupoBackend("ws://ogmios-url:port", "http://kupo-url:port", Network.MAINNET)) ``` -------------------------------- ### Get V2 Enhanced Pool Data Source: https://github.com/charli3-official/charli3-dendrite/blob/main/docs/wingriders.md Retrieves data for V2 Constant Product Pools (CPP) and V2 Stable Swap Pools (SSP). This snippet shows how to access dynamic fee information for V2 CPP pools and advanced configuration parameters like asset multipliers for V2 SSP pools. ```python from charli3_dendrite import WingRidersV2CPPState, WingRidersV2SSPState # Get V2 CPP pools with dynamic fees v2_selector = WingRidersV2CPPState.pool_selector() v2_pools = backend.get_pool_utxos(**v2_selector.model_dump()) for pool_info in v2_pools: pool = WingRidersV2CPPState.model_validate(pool_info.model_dump()) print(f"V2 Pool: {pool.pool_id}") print(f"Dynamic Fee: {pool.fee}bp") print(f"Script: {pool.default_script_class()}") # Get V2 SSP pools with advanced configuration v2_ssp_selector = WingRidersV2SSPState.pool_selector() v2_ssp_pools = backend.get_pool_utxos(**v2_ssp_selector.model_dump()) for pool_info in v2_ssp_pools: pool = WingRidersV2SSPState.model_validate(pool_info.model_dump()) print(f"V2 Stable Pool: {pool.pool_id}") print(f"Asset Multipliers: {pool.asset_mulitipliers}") ```