repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources15d ago| #1 | """Test Bags API Integration""" |
| #2 | |
| #3 | import asyncio |
| #4 | import sys |
| #5 | from pathlib import Path |
| #6 | |
| #7 | # Add parent to path |
| #8 | sys.path.insert(0, str(Path(__file__).parent)) |
| #9 | |
| #10 | from config import load_config |
| #11 | from clients.bags_client import BagsClient |
| #12 | |
| #13 | |
| #14 | async def test_bags_api(): |
| #15 | """Test Bags API connection and functionality""" |
| #16 | |
| #17 | print("🧪 Testing Bags API Integration...\n") |
| #18 | |
| #19 | # Load config |
| #20 | config = load_config() |
| #21 | print(f"✓ Config loaded") |
| #22 | print(f" BAGS_API_KEY: {config.bags_api_key[:20]}...") |
| #23 | print(f" BAGS_CONFIG_KEY: {config.bags_config_key}") |
| #24 | print(f" Wallet: {config.wallet_address}\n") |
| #25 | |
| #26 | # Create Bags client |
| #27 | bags_client = BagsClient( |
| #28 | api_key=config.bags_api_key, |
| #29 | config_key=config.bags_config_key, |
| #30 | rpc_url=config.helius_rpc_url, |
| #31 | private_key=config.private_key, |
| #32 | ) |
| #33 | |
| #34 | print(f"✓ Bags client created") |
| #35 | print(f" Wallet pubkey: {bags_client.wallet_pubkey}\n") |
| #36 | |
| #37 | try: |
| #38 | # ===================== |
| #39 | # Test 1: Health Check |
| #40 | # ===================== |
| #41 | print("=" * 60) |
| #42 | print("Test 1: Health Check") |
| #43 | print("=" * 60) |
| #44 | |
| #45 | is_healthy = await bags_client.health_check() |
| #46 | if is_healthy: |
| #47 | print("✅ Bags API is healthy (pong received)") |
| #48 | else: |
| #49 | print("⚠️ Bags API health check failed") |
| #50 | print() |
| #51 | |
| #52 | # ===================== |
| #53 | # Test 2: Get Swap Quote |
| #54 | # ===================== |
| #55 | print("=" * 60) |
| #56 | print("Test 2: Get Swap Quote (0.01 SOL → BONK)") |
| #57 | print("=" * 60) |
| #58 | |
| #59 | try: |
| #60 | # BONK token mint |
| #61 | BONK_MINT = "DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263" |
| #62 | WRAPPED_SOL_MINT = "So11111111111111111111111111111111111111112" |
| #63 | |
| #64 | quote = await bags_client.get_quote( |
| #65 | input_mint=WRAPPED_SOL_MINT, |
| #66 | output_mint=BONK_MINT, |
| #67 | amount=10_000_000, # 0.01 SOL in lamports |
| #68 | slippage_bps=300, # 3% slippage |
| #69 | ) |
| #70 | |
| #71 | print("✅ Quote received successfully") |
| #72 | print(f" Input: {int(quote.in_amount) / 1e9:.4f} SOL") |
| #73 | print(f" Output: {int(quote.out_amount):,} BONK tokens") |
| #74 | print(f" Min output: {int(quote.min_out_amount):,} BONK tokens") |
| #75 | print(f" Price impact: {quote.price_impact_pct}%") |
| #76 | print(f" Slippage: {quote.slippage_bps} bps ({quote.slippage_bps / 100}%)") |
| #77 | print(f" Request ID: {quote.request_id}") |
| #78 | print(f" Route steps: {len(quote.route_plan)}") |
| #79 | |
| #80 | except Exception as e: |
| #81 | print(f"❌ Quote failed: {e}") |
| #82 | |
| #83 | print() |
| #84 | |
| #85 | # ===================== |
| #86 | # Test 3: Get Claimable Fees |
| #87 | # ===================== |
| #88 | print("=" * 60) |
| #89 | print("Test 3: Get Claimable Fees") |
| #90 | print("=" * 60) |
| #91 | |
| #92 | try: |
| #93 | claimable = await bags_client.get_claimable_fees() |
| #94 | |
| #95 | if claimable: |
| #96 | print(f"✅ Found {len(claimable)} claimable fee position(s)") |
| #97 | for i, position in enumerate(claimable, 1): |
| #98 | print(f"\n Position {i}:") |
| #99 | print(f" Token: {position.get('baseMint', 'Unknown')[:8]}...") |
| #100 | print(f" Amount: {position.get('amount', 0)}") |
| #101 | print(f" Config Key: {position.get('configKey', 'Unknown')[:8]}...") |
| #102 | else: |
| #103 | print("✅ No claimable fees found (wallet has no fee positions)") |
| #104 | |
| #105 | except Exception as e: |
| #106 | print(f"⚠️ Claimable fees check: {e}") |
| #107 | |
| #108 | print() |
| #109 | |
| #110 | # ===================== |
| #111 | # Test 4: Get Jito Fees |
| #112 | # ===================== |
| #113 | print("=" * 60) |
| #114 | print("Test 4: Get Jito Fee Percentiles") |
| #115 | print("=" * 60) |
| #116 | |
| #117 | try: |
| #118 | jito_fees = await bags_client.get_jito_fees() |
| #119 | |
| #120 | print("✅ Jito fees retrieved") |
| #121 | |
| #122 | # Extract percentile data if available |
| #123 | if isinstance(jito_fees, dict): |
| #124 | for key, value in jito_fees.items(): |
| #125 | if isinstance(value, (int, float)): |
| #126 | print(f" {key}: {value:,.0f} lamports ({value / 1e9:.6f} SOL)") |
| #127 | else: |
| #128 | print(f" {key}: {value}") |
| #129 | else: |
| #130 | print(f" Raw response: {jito_fees}") |
| #131 | |
| #132 | except Exception as e: |
| #133 | print(f"⚠️ Jito fees: {e}") |
| #134 | |
| #135 | print() |
| #136 | |
| #137 | # ===================== |
| #138 | # Test 5: Token Info (BONK) |
| #139 | # ===================== |
| #140 | print("=" * 60) |
| #141 | print("Test 5: Get Token Fees (BONK)") |
| #142 | print("=" * 60) |
| #143 | |
| #144 | try: |
| #145 | BONK_MINT = "DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263" |
| #146 | token_fees = await bags_client.get_token_fees(BONK_MINT) |
| #147 | |
| #148 | print("✅ Token fees retrieved") |
| #149 | |
| #150 | if isinstance(token_fees, dict): |
| #151 | for key, value in token_fees.items(): |
| #152 | if isinstance(value, (int, float)) and key != 'baseMint': |
| #153 | print(f" {key}: {value:,.0f}") |
| #154 | else: |
| #155 | print(f" {key}: {value}") |
| #156 | else: |
| #157 | print(f" Raw response: {token_fees}") |
| #158 | |
| #159 | except Exception as e: |
| #160 | print(f"⚠️ Token fees: {e}") |
| #161 | |
| #162 | print() |
| #163 | |
| #164 | # ===================== |
| #165 | # Summary |
| #166 | # ===================== |
| #167 | print("=" * 60) |
| #168 | print("✅ Bags API Integration Test Complete!") |
| #169 | print("=" * 60) |
| #170 | print() |
| #171 | print("Verified Components:") |
| #172 | print(" ✅ API Authentication (x-api-key header)") |
| #173 | print(" ✅ Health Check Endpoint") |
| #174 | print(" ✅ Trade Quote Generation") |
| #175 | print(" ✅ Fee Position Queries") |
| #176 | print(" ✅ Jito Fee Information") |
| #177 | print(" ✅ Token Fee Queries") |
| #178 | print() |
| #179 | print("Available Functionality:") |
| #180 | print(" • Token swaps (buy/sell)") |
| #181 | print(" • Token launches with fee sharing") |
| #182 | print(" • Fee claiming from positions") |
| #183 | print(" • Jito bundle submission") |
| #184 | print(" • Quote generation with slippage") |
| #185 | print() |
| #186 | print("Configuration:") |
| #187 | print(f" • BAGS_API_KEY: Configured ✓") |
| #188 | print(f" • BAGS_CONFIG_KEY: {config.bags_config_key} ✓") |
| #189 | print(f" • Wallet: {bags_client.wallet_pubkey} ✓") |
| #190 | print() |
| #191 | |
| #192 | except KeyboardInterrupt: |
| #193 | print("\n\n⚠️ Test interrupted by user") |
| #194 | except Exception as e: |
| #195 | print(f"\n❌ Unexpected error: {e}") |
| #196 | import traceback |
| #197 | traceback.print_exc() |
| #198 | finally: |
| #199 | # Close client |
| #200 | print("Closing Bags client...") |
| #201 | await bags_client.close() |
| #202 | print("✓ Closed\n") |
| #203 | print("Test finished!") |
| #204 | |
| #205 | |
| #206 | if __name__ == "__main__": |
| #207 | asyncio.run(test_bags_api()) |
| #208 |