|
| 1 | +# Contributing to Matchbook |
| 2 | + |
| 3 | +Thank you for your interest in contributing to Matchbook! This document provides guidelines and instructions for contributing. |
| 4 | + |
| 5 | +## Code of Conduct |
| 6 | + |
| 7 | +By participating in this project, you agree to maintain a respectful and inclusive environment for everyone. |
| 8 | + |
| 9 | +## Getting Started |
| 10 | + |
| 11 | +### Prerequisites |
| 12 | + |
| 13 | +- Rust 1.75+ |
| 14 | +- Solana CLI 1.18+ |
| 15 | +- Node.js 18+ (for TypeScript SDK) |
| 16 | +- Docker (for local development) |
| 17 | + |
| 18 | +### Setup |
| 19 | + |
| 20 | +1. Fork the repository |
| 21 | +2. Clone your fork: |
| 22 | + ```bash |
| 23 | + git clone https://github.com/YOUR_USERNAME/matchbook.git |
| 24 | + cd matchbook |
| 25 | + ``` |
| 26 | +3. Add upstream remote: |
| 27 | + ```bash |
| 28 | + git remote add upstream https://github.com/joaquinbejar/matchbook.git |
| 29 | + ``` |
| 30 | +4. Install dependencies: |
| 31 | + ```bash |
| 32 | + # Rust |
| 33 | + cargo build |
| 34 | + |
| 35 | + # TypeScript SDK |
| 36 | + cd ts-sdk && npm install |
| 37 | + ``` |
| 38 | + |
| 39 | +## Development Workflow |
| 40 | + |
| 41 | +### 1. Create a Branch |
| 42 | + |
| 43 | +```bash |
| 44 | +git checkout -b feature/your-feature-name |
| 45 | +# or |
| 46 | +git checkout -b fix/your-bug-fix |
| 47 | +``` |
| 48 | + |
| 49 | +### 2. Make Changes |
| 50 | + |
| 51 | +- Follow the coding standards (see below) |
| 52 | +- Write tests for new functionality |
| 53 | +- Update documentation as needed |
| 54 | + |
| 55 | +### 3. Test Your Changes |
| 56 | + |
| 57 | +```bash |
| 58 | +# Run all tests |
| 59 | +cargo test --all-features |
| 60 | + |
| 61 | +# Run clippy |
| 62 | +cargo clippy --all-targets --all-features -- -D warnings |
| 63 | + |
| 64 | +# Check formatting |
| 65 | +cargo fmt --all --check |
| 66 | + |
| 67 | +# TypeScript SDK |
| 68 | +cd ts-sdk && npm test |
| 69 | +``` |
| 70 | + |
| 71 | +### 4. Commit Your Changes |
| 72 | + |
| 73 | +Write clear, concise commit messages: |
| 74 | + |
| 75 | +```bash |
| 76 | +git commit -m "feat: add new order type support" |
| 77 | +git commit -m "fix: resolve race condition in matching" |
| 78 | +git commit -m "docs: update API reference" |
| 79 | +``` |
| 80 | + |
| 81 | +Follow [Conventional Commits](https://www.conventionalcommits.org/): |
| 82 | + |
| 83 | +| Prefix | Description | |
| 84 | +|--------|-------------| |
| 85 | +| `feat` | New feature | |
| 86 | +| `fix` | Bug fix | |
| 87 | +| `docs` | Documentation | |
| 88 | +| `refactor` | Code refactoring | |
| 89 | +| `test` | Adding tests | |
| 90 | +| `chore` | Maintenance | |
| 91 | + |
| 92 | +### 5. Push and Create PR |
| 93 | + |
| 94 | +```bash |
| 95 | +git push origin feature/your-feature-name |
| 96 | +``` |
| 97 | + |
| 98 | +Then create a Pull Request on GitHub. |
| 99 | + |
| 100 | +## Coding Standards |
| 101 | + |
| 102 | +### Rust |
| 103 | + |
| 104 | +Follow the guidelines in `.internalDoc/09-rust-guidelines.md`: |
| 105 | + |
| 106 | +- Use `#[must_use]` on pure functions |
| 107 | +- Use checked arithmetic (no `.unwrap()` in production code) |
| 108 | +- Write doc comments on all public items |
| 109 | +- Keep functions focused and small |
| 110 | +- Use meaningful variable names |
| 111 | + |
| 112 | +Example: |
| 113 | + |
| 114 | +```rust |
| 115 | +/// Calculates the total value of an order. |
| 116 | +/// |
| 117 | +/// # Arguments |
| 118 | +/// |
| 119 | +/// * `price` - The price per unit in base units |
| 120 | +/// * `quantity` - The quantity in base units |
| 121 | +/// |
| 122 | +/// # Returns |
| 123 | +/// |
| 124 | +/// The total value, or `None` if overflow occurs. |
| 125 | +#[must_use] |
| 126 | +pub fn calculate_total(price: u64, quantity: u64) -> Option<u64> { |
| 127 | + price.checked_mul(quantity) |
| 128 | +} |
| 129 | +``` |
| 130 | + |
| 131 | +### TypeScript |
| 132 | + |
| 133 | +- Use TypeScript strict mode |
| 134 | +- Document public APIs with TSDoc |
| 135 | +- Use meaningful variable names |
| 136 | +- Prefer `const` over `let` |
| 137 | + |
| 138 | +Example: |
| 139 | + |
| 140 | +```typescript |
| 141 | +/** |
| 142 | + * Calculates the total value of an order. |
| 143 | + * @param price - The price per unit |
| 144 | + * @param quantity - The quantity |
| 145 | + * @returns The total value |
| 146 | + */ |
| 147 | +export function calculateTotal(price: bigint, quantity: bigint): bigint { |
| 148 | + return price * quantity; |
| 149 | +} |
| 150 | +``` |
| 151 | + |
| 152 | +## Pull Request Guidelines |
| 153 | + |
| 154 | +### Before Submitting |
| 155 | + |
| 156 | +- [ ] Tests pass locally |
| 157 | +- [ ] Code follows style guidelines |
| 158 | +- [ ] Documentation is updated |
| 159 | +- [ ] Commit messages are clear |
| 160 | +- [ ] PR description explains the changes |
| 161 | + |
| 162 | +### PR Description Template |
| 163 | + |
| 164 | +```markdown |
| 165 | +## Summary |
| 166 | + |
| 167 | +[Brief description of changes] |
| 168 | + |
| 169 | +## Changes |
| 170 | + |
| 171 | +- [Change 1] |
| 172 | +- [Change 2] |
| 173 | + |
| 174 | +## Testing |
| 175 | + |
| 176 | +- [ ] Unit tests added/updated |
| 177 | +- [ ] Integration tests added/updated |
| 178 | +- [ ] Manual testing performed |
| 179 | + |
| 180 | +## Related Issues |
| 181 | + |
| 182 | +Closes #[issue_number] |
| 183 | +``` |
| 184 | + |
| 185 | +### Review Process |
| 186 | + |
| 187 | +1. Automated CI checks must pass |
| 188 | +2. At least one maintainer review required |
| 189 | +3. Address review feedback promptly |
| 190 | +4. Squash commits before merge (if requested) |
| 191 | + |
| 192 | +## Testing |
| 193 | + |
| 194 | +### Unit Tests |
| 195 | + |
| 196 | +```rust |
| 197 | +#[cfg(test)] |
| 198 | +mod tests { |
| 199 | + use super::*; |
| 200 | + |
| 201 | + #[test] |
| 202 | + fn test_calculate_total() { |
| 203 | + assert_eq!(calculate_total(100, 10), Some(1000)); |
| 204 | + assert_eq!(calculate_total(u64::MAX, 2), None); |
| 205 | + } |
| 206 | +} |
| 207 | +``` |
| 208 | + |
| 209 | +### Integration Tests |
| 210 | + |
| 211 | +Place integration tests in `tests/` directory: |
| 212 | + |
| 213 | +```rust |
| 214 | +// tests/integration_test.rs |
| 215 | +use matchbook_program::*; |
| 216 | + |
| 217 | +#[tokio::test] |
| 218 | +async fn test_place_order_flow() { |
| 219 | + // Test implementation |
| 220 | +} |
| 221 | +``` |
| 222 | + |
| 223 | +### Property-Based Tests |
| 224 | + |
| 225 | +For critical algorithms, use property-based testing: |
| 226 | + |
| 227 | +```rust |
| 228 | +use proptest::prelude::*; |
| 229 | + |
| 230 | +proptest! { |
| 231 | + #[test] |
| 232 | + fn test_price_conversion_roundtrip(price in 1u64..u64::MAX) { |
| 233 | + let converted = to_human(price); |
| 234 | + let back = to_native(converted); |
| 235 | + prop_assert_eq!(price, back); |
| 236 | + } |
| 237 | +} |
| 238 | +``` |
| 239 | + |
| 240 | +## Documentation |
| 241 | + |
| 242 | +### Code Documentation |
| 243 | + |
| 244 | +- Document all public items |
| 245 | +- Include examples in doc comments |
| 246 | +- Use `# Examples` section for code samples |
| 247 | + |
| 248 | +### User Documentation |
| 249 | + |
| 250 | +- Update relevant docs in `docs/` |
| 251 | +- Keep examples up to date |
| 252 | +- Use clear, concise language |
| 253 | + |
| 254 | +## Getting Help |
| 255 | + |
| 256 | +- **Questions**: Open a [Discussion](https://github.com/joaquinbejar/matchbook/discussions) |
| 257 | +- **Bugs**: Open an [Issue](https://github.com/joaquinbejar/matchbook/issues) |
| 258 | +- **Security**: See [SECURITY.md](SECURITY.md) |
| 259 | +- **Chat**: Join our [Discord](https://discord.gg/matchbook) |
| 260 | + |
| 261 | +## License |
| 262 | + |
| 263 | +By contributing, you agree that your contributions will be licensed under the MIT License. |
0 commit comments