Skip to content

feat: Add mnemonic phrase support and enhanced logging to api_trading.py#15

Open
James-4u wants to merge 4 commits intosportstensor:mainfrom
James-4u:feat/add-mnemonic
Open

feat: Add mnemonic phrase support and enhanced logging to api_trading.py#15
James-4u wants to merge 4 commits intosportstensor:mainfrom
James-4u:feat/add-mnemonic

Conversation

@James-4u
Copy link
Copy Markdown

@James-4u James-4u commented Dec 8, 2025

Summary

This PR adds mnemonic phrase support to api_trading.py, allowing miners to use 12/24-word mnemonic phrases instead of requiring direct private key export. Additionally, comprehensive logging and detailed comments have been added throughout the codebase to improve debugging and maintainability.

Changes

✨ New Features

  1. Mnemonic Phrase Support

    • Miners can now use EOA_WALLET_MNEMONIC (12/24-word phrase) instead of EOA_WALLET_PK
    • Supports standard BIP44 derivation path (m/44'/60'/0'/0/0) for Ethereum
    • Falls back gracefully between bip-utils (recommended) and hdwallet libraries
    • Private key takes precedence if both are provided
  2. Enhanced Logging

    • Added Python logging module with timestamps and log levels
    • Logs key operations: credential loading, session creation, order placement
    • DEBUG level for detailed tracing, INFO for important operations
    • Helps troubleshoot issues during trading operations
  3. Improved Code Documentation

    • Added comprehensive comments explaining:
      • BIP44 derivation process
      • EIP-191/EIP-712 signing standards
      • Credential management flow
      • Order placement logic

🔧 Technical Improvements

  • Fixed hdwallet library API compatibility issues
  • Added support for both bip-utils and hdwallet with automatic fallback
  • Enhanced error messages with installation instructions
  • Improved credential detection and validation

📦 Dependencies

Updated requirements.txt with new dependencies:

  • python-dotenv>=1.0.0 - Environment variable management
  • py-clob-client>=1.0.0 - Polymarket CLOB API client
  • eth-account>=0.8.0 - Ethereum account and signing
  • mnemonic>=0.20 - Mnemonic phrase validation
  • bip-utils>=2.9.0 - BIP44 derivation (recommended)
  • hdwallet>=2.2.0 - Alternative mnemonic derivation

Usage

Using Mnemonic Phrase

In api_trading.env:
EOA_WALLET_ADDRESS=0x...
EOA_WALLET_MNEMONIC=word1 word2 word3 ... word12
EOA_PROXY_FUNDER=0x...

Using Private Key (existing method)

EOA_WALLET_ADDRESS=0x...
EOA_WALLET_PK=0x...
EOA_PROXY_FUNDER=0x...

Installation

pip install -r requirements.txt

Benefits

  1. Better Security: Miners can use mnemonic phrases from wallet extensions that don't allow private key export
  2. Easier Debugging: Comprehensive logging helps identify issues quickly
  3. Better Maintainability: Detailed comments make the code easier to understand and modify
  4. Flexibility: Supports both mnemonic and private key methods

Testing

  • ✅ Mnemonic phrase validation
  • ✅ BIP44 derivation with bip-utils
  • ✅ Fallback to hdwallet if bip-utils unavailable
  • ✅ Private key precedence when both are provided
  • ✅ Logging output verification
  • ✅ Credential set detection with mnemonic support

Notes

  • If both EOA_WALLET_PK and EOA_WALLET_MNEMONIC are provided, the private key takes precedence
  • bip-utils is recommended over hdwallet for better reliability
  • All existing functionality remains unchanged and backward compatible

Contribution by Gittensor, learn more at https://gittensor.io/

@James-4u
Copy link
Copy Markdown
Author

James-4u commented Dec 8, 2025

@conidig @xzistance Could you review check my pr?

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.

1 participant