-
Notifications
You must be signed in to change notification settings - Fork 15
Feat/predictfun exchange #54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Add Predict.fun exchange configuration to .env.example - Update pyproject.toml and uv.lock to include predict-sdk dependency - Enhance ExchangeClient and ExchangeConfig to support Predict.fun - Introduce PredictFun class for handling API interactions with Predict.fun - Update strategy to manage insufficient funds and improve order handling This integration allows users to trade on the Predict.fun platform, enhancing the overall functionality of the trading system.
- Moved the import of InsufficientFunds to the correct location in strategy.py for better organization. - Renamed constants in predictfun.py for consistency and clarity (PRECISION to precision, MAX_SALT to max_salt). - Updated test for list_exchanges to include the new "predictfun" exchange, increasing the expected count from 3 to 4. These changes improve code readability and maintainability while ensuring the integration of the Predict.fun exchange is properly reflected in the tests.
- Adjusted formatting in exchange_factory.py, strategy.py, and predictfun.py for better code clarity. - Enhanced the readability of environment variable loading and logging messages. - Ensured consistent line breaks and indentation across multiple files. These changes contribute to a cleaner codebase, making it easier to maintain and understand.
This comment was marked as outdated.
This comment was marked as outdated.
- Replaced the random module with secrets for generating secure random values. - Enhanced error handling in the order book fetching method to include verbose logging of exceptions. - Added validation to ensure order size is greater than zero, improving input validation. These changes enhance the security and robustness of the PredictFun class, ensuring better error reporting and input validation.
Pull Request Review: Predict.fun Exchange IntegrationSummaryThis PR adds support for the Predict.fun exchange on BNB Chain, introducing 1,495 lines of new code in predictfun.py plus integration changes across the codebase. The implementation closes issue #43. Code Quality & Best PracticesStrengths
Critical Issues1. VIOLATION: CLAUDE.md Rule #4 - Too Many .env VariablesLocation: .env.example:16-29 The PR adds 7 new environment variables for configuration. CLAUDE.md Rule #4 states: "Single Source of Truth: DO NOT place many variables in .env file. Place them in the code instead." Recommendation: Move non-sensitive configuration (PREDICTFUN_USE_SMART_WALLET, PREDICTFUN_TESTNET) to code constants. Only API keys and private keys should be in .env. 2. Hardcoded Magic NumbersLocation: predictfun.py:1220 Magic number 4102444800 for order expiration should be a named constant NO_EXPIRY_TIMESTAMP. Precision values like 1e13, 1e18, 1e24 scattered throughout should also be named constants. 3. Insufficient Funds State Management BugLocation: dr_manhattan/base/strategy.py:88, 476-549 The _insufficient_funds flag permanently stops trading with no recovery mechanism. If users deposit more funds, trading won't resume automatically. Recommendation: Add a reset method or check balance before each order cycle to auto-recover. Potential Bugs1. Re-authentication Smart Wallet CheckLocation: predictfun.py:367 Checks self._account but should check self._owner_account for smart wallet mode. Fix: if self.api_key and (self._account or self._owner_account): 2. Division by Zero Edge CaseLocation: predictfun.py:537-540 If both amount conditions fail, price remains 0.0 which may not be intended. 3. Hardcoded Gas LimitLocation: predictfun.py:1089 Gas limit of 100,000 may be insufficient during BNB Chain congestion. Recommendation: Use estimateGas with 20% buffer. Security Concerns1. CRITICAL: Private Key Exposure RiskLocation: .env.example:25-27 Issues:
Recommendations:
2. Unlimited Token ApprovalLocation: predictfun.py:1061, 1084 Grants unlimited USDT spending to exchange contracts. If compromised, all USDT can be drained. Recommendation: Use limited approvals (2-5x trade size) with refresh as needed. Document this trade-off clearly. Performance Issues1. Synchronous Approval ChecksLocation: predictfun.py:1071-1107 Sequential on-chain calls for 4 contracts could take 10-20 seconds. Recommendation: Parallelize allowance checks or only approve contracts needed for current market. Test Coverage - INSUFFICIENTIssues:
Recommendation: Add comprehensive unit tests, integration tests with testnet, and mock tests for Web3 interactions. CLAUDE.md Compliance
Summary & VerdictSOLID IMPLEMENTATION with good architecture and Web3 understanding, BUT has critical issues. Must Fix (Blocking):
Should Fix:
Nice to Have:
Recommendation: REQUEST CHANGES before merging The core implementation demonstrates solid understanding of EIP-712 and Web3, but security concerns, lack of tests, and CLAUDE.md violations must be addressed first. |
…edictFun class - Introduced NO_EXPIRY_TIMESTAMP constant for clarity and maintainability. - Updated order expiration logic to use the new constant instead of a hardcoded value. - Enhanced account authentication check to include owner account, improving flexibility. These changes improve code readability and maintainability while ensuring consistent handling of no-expiry orders.
PR Review: Predict.fun Exchange IntegrationSummaryThis PR adds Predict.fun exchange integration to dr-manhattan, introducing support for BNB Chain-based prediction markets with both EOA and Smart Wallet trading modes. The implementation is comprehensive and well-structured. Code Quality ✅Strengths:
Observations:
Security Concerns
|
| Rule | Status | Notes |
|---|---|---|
| 1. Focused, clean code | ✅ | Code is well-structured |
| 2. No unnecessary docs | 15+ new env vars in .env.example |
|
| 3. Use UV for deps | ✅ | pyproject.toml updated correctly |
| 4. Single Source of Truth | ❌ | Too many env variables (violates spirit) |
| 5. Run and Debug | ❓ | Need to verify integration works |
Recommendations
High Priority
- Test the integration - CLAUDE.md rule Create debugging frontend for trading strategies #5 says "Run and Debug yourself PROACTIVELY"
- Add test coverage for Predict.fun exchange
- Document security implications of unlimited approvals
- Consider reducing env vars - can some have code defaults?
Medium Priority
- Add caching for
fetch_balance()to reduce RPC calls - Add fallback in
get_orderbook()for unmapped token_ids - Document the difference between EOA and Smart Wallet modes more clearly
- Add integration examples to help users get started
Low Priority
- Consider extracting EIP-712 signing to a shared utility
- Add more detailed logging for debugging auth issues
Conclusion
This is a solid implementation of a complex integration. The code quality is high, error handling is comprehensive, and it follows existing patterns well. However:
⚠️ Security: Review unlimited approval approach⚠️ Testing: Needs comprehensive test coverage⚠️ Configuration: Too many environment variables (violates CLAUDE.md fix: polymarket impl #4)- ✅ Code Quality: Well-structured and documented
- ✅ Error Handling: Excellent use of custom exceptions
Recommendation: Approve with minor changes
The integration is production-ready from a code perspective, but should address the configuration bloat and add tests before merging.
Review generated by Claude Code
- Added Predict.fun logo to README for better visibility. - Updated architecture section to include the new predictfun.py file. - Introduced PredictFun class in the codebase for handling API interactions with Predict.fun. - Updated list_exchanges function to reflect the addition of the Predict.fun exchange. - Included example command for listing markets on Predict.fun in the usage section. These changes improve documentation and enhance the functionality of the trading system by integrating the Predict.fun exchange.
PR Review: Predict.fun Exchange IntegrationThank you for this comprehensive implementation! This PR adds a significant new exchange integration. Below is my detailed review: ✅ Strengths
🔍 Code Quality & Best PracticesCritical Issues
Security Concerns
Performance Considerations
Potential Bugs
Code Organization
🧪 TestingConcerns:
Recommendation: Add comprehensive test coverage including:
📝 DocumentationGood:
Recommendations:
🎯 SummaryOverall Assessment: This is a solid implementation that follows the existing architectural patterns. The code is well-structured and functional, but has several areas for improvement particularly around:
Recommendation: Request changes focusing on:
The implementation is feature-complete and demonstrates good understanding of the codebase, but needs refinement before merging to production. Review generated by Claude Code |
- Removed the _insufficient_funds attribute and related checks from the Strategy class. - Cleaned up order placement methods by eliminating unnecessary conditions for insufficient funds. - Enhanced logging by removing warnings related to insufficient funds during order processing. These changes streamline the order handling process and improve code clarity by focusing on essential trading logic.
Pull Request Review: Predict.fun Exchange IntegrationThank you for this comprehensive integration of Predict.fun! This is a significant addition that brings BNB Chain prediction markets to dr-manhattan. Here's my detailed review: ✅ Strengths1. Excellent Code Organization
2. Strong Security Practices
3. Feature Completeness
4. Integration Quality
🔍 Issues & RecommendationsHIGH PRIORITY1. ❌ CLAUDE.md Violation: Excessive .env VariablesLocation: The project's CLAUDE.md explicitly states:
However, this PR adds 8 new environment variables for Predict.fun configuration. This violates the project's core principle. Recommendation: Move non-sensitive configuration to code constants: # In predictfun.py - add these as class constants with sensible defaults
DEFAULT_USE_SMART_WALLET = False
DEFAULT_TESTNET = FalseOnly keep sensitive credentials in .env:
Remove boolean flags and non-sensitive config from .env. 2.
|
| Category | Count |
|---|---|
| High Priority Issues | 3 |
| Medium Priority Issues | 5 |
| Low Priority Issues | 3 |
Overall Assessment: This is high-quality work with comprehensive functionality. The main concerns are:
- .env variable overuse (CLAUDE.md violation)
- Missing tests (CLAUDE.md violation)
- Insufficient funds flag never resets (bug)
Recommendation: Request changes for HIGH priority items. The integration is solid but needs to align with project conventions and include basic tests.
✨ Positive Highlights
- Excellent handling of EIP-712 signing complexity
- Smart Wallet support is impressive and well-implemented
- Error handling is thorough and uses proper exception types
- Code is well-commented and self-documenting
- Integration follows existing patterns perfectly
Great work overall! 🚀
PR Review: Predict.fun Exchange IntegrationSummaryThis PR adds Predict.fun exchange support to dr-manhattan, a ~1500 line implementation that integrates a BNB Chain-based prediction market with CLOB-style orderbook. The implementation follows the existing patterns and adds USDT support alongside USDC. Code Quality & Best PracticesStrengths ✅
Areas for Improvement
|
Pull Request Review: Predict.fun Exchange IntegrationOverviewThis PR adds comprehensive support for the Predict.fun prediction market exchange on BNB Chain. The integration is well-structured and follows the existing codebase patterns established for Polymarket, Opinion, and Limitless. Code Quality ✅Strengths:
Areas for improvement:
Best Practices ✅Excellent:
Minor issues:
Potential Bugs 🐛
Performance Considerations ⚡Good:
Potential improvements:
Security Concerns 🔒Critical:
Recommendations:
Test Coverage 📊Current coverage:
Missing tests:
Recommendation: Add at least basic unit tests for:
Additional ObservationsConfiguration (.env.example)
Strategy Integration (strategy.py)
Exchange Factory (exchange_factory.py)
Documentation (README.md)
SummaryOverall Assessment: Good Quality ⭐⭐⭐⭐☆ This is a solid implementation that follows the codebase patterns well. The main concern is the potential bug in Must Fix Before Merge:
Strongly Recommended:
Nice to Have:
Great work on this integration! The code is well-structured and thoughtfully implemented. Once the critical bug is fixed and tests are added, this will be a solid addition to dr-manhattan. Reviewed with ❤️ by Claude Code |
- Introduced a new method to enrich markets with orderbook prices, improving market data accuracy. - Refactored market fetching logic to streamline the process and handle fallback scenarios more effectively. - Added detailed error handling for orderbook fetching, ensuring robustness in price retrieval. These changes enhance the functionality and reliability of the PredictFun class, providing users with more accurate market information.
PR Review: Predict.fun Exchange IntegrationThank you for this comprehensive implementation! This is a substantial addition (1,539 lines) that adds Predict.fun exchange support to dr-manhattan. Here's my detailed review: ✅ Strengths1. Comprehensive Implementation
2. Code Quality
3. Smart Wallet Support
4. Configuration Management
🔴 Critical Issues1. SECURITY: Violation of CLAUDE.md Rule #4 - Environment VariablesIssue: The implementation heavily uses
Files affected:
Recommendation:
2. SECURITY: Hardcoded Private Keys RiskFile: # Initialize account if private key provided (skip in smart wallet mode)
if self.private_key and not self.use_smart_wallet:
self._account = Account.from_key(self.private_key)
self._address = self._account.address
# Initialize owner account for smart wallet mode
if self.smart_wallet_owner_private_key:
self._owner_account = Account.from_key(self.smart_wallet_owner_private_key)Recommendation: Add validation to ensure private keys are never logged or exposed in error messages. Consider adding warning in docstring about secure key management.
|
…andling - Added logic to set the _address attribute for smart wallet mode, ensuring proper initialization. - Updated authentication checks to differentiate between standard and smart wallet modes, improving error handling for wallet initialization. These changes enhance the robustness of the PredictFun class, ensuring accurate wallet management in different modes.
PR Review: Predict.fun Exchange IntegrationThis PR adds support for Predict.fun, a prediction market on BNB Chain. Here's my comprehensive review: ✅ Code Quality & Best PracticesStrengths:
Areas for Improvement:
🐛 Potential Bugs & Issues
🔒 Security Concerns
⚡ Performance Considerations
🧪 Test CoverageMissing Tests:
Recommendations:
📚 Documentation & Code CommentsGood:
Needs Improvement:
🎯 Recommendations SummaryHigh Priority:
Medium Priority:
Low Priority:
✨ Overall AssessmentThis is a solid implementation that follows the existing codebase patterns well. The dual wallet mode support (EOA + Smart Wallet) is particularly well-executed with proper Kernel v0.3.1 EIP-712 signing. Main concerns:
Recommendation: Approve with minor changes requested. The implementation is functional but would benefit from addressing the high-priority items before merging. Reviewed with: Claude Sonnet 4.5 via Claude Code |
close #43