Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
189 changes: 189 additions & 0 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
# Copilot Instructions for Toban Project

## Project Overview
Toban is a role-based rewards distribution system built on blockchain technology. It simplifies contribution tracking and reward distribution for collaborative projects using Hats Protocol, Splits, and custom smart contracts.

## Architecture & Technology Stack

### Monorepo Structure (pnpm workspace)
- `pkgs/contract/` - Solidity smart contracts (Hardhat)
- `pkgs/frontend/` - React app (Remix + Vite + Chakra UI)
- `pkgs/subgraph/` - The Graph Protocol indexing
- `pkgs/cli/` - TypeScript CLI tools
- `pkgs/document/` - Docusaurus documentation

### Key Technologies
- **Smart Contracts**: Solidity ^0.8.24, Hardhat, OpenZeppelin
- **Frontend**: React, Remix, Vite, Chakra UI, Privy (Web3 auth)
- **Backend**: The Graph Protocol, Apollo Client (GraphQL)
- **Deployment**: Sepolia (testnet), Base (mainnet)

## Development Guidelines

### Code Style & Conventions
- Use **Biome** for formatting and linting (not ESLint/Prettier)
- **TypeScript strict mode** throughout the project
- **PascalCase** for contracts and components, **camelCase** for functions/variables
- Use **pnpm** for package management (never npm or yarn)

### Smart Contract Development
- Follow **UUPS upgradeable pattern** for contracts
- Use **OpenZeppelin** contracts for security
- Write comprehensive **NatSpec documentation**
- Always include **test coverage** for new functions
- Use **Hardhat** tasks for contract interactions

### Frontend Development
- Use **Chakra UI** components consistently
- Implement **responsive design** patterns
- Handle **Web3 connection states** properly with Privy
- Use **Apollo Client** for GraphQL queries
- Follow **Remix** conventions for routing and data loading

### Key Smart Contracts
- `BigBang.sol` - Main project initialization contract
- `HatsTimeFrameModule.sol` - Time-based role management
- `HatsHatCreatorModule.sol` - Dynamic role creation
- `SplitsCreator.sol` - Reward distribution mechanism
- `FractionToken.sol` - Thanks Token (Assist Credit) implementation

## Command Patterns

### Package-specific Commands
```bash
# Frontend development
pnpm frontend dev
pnpm frontend build
pnpm frontend test:e2e:dev

# Contract development
pnpm contract compile
pnpm contract test
pnpm contract deploy:all
pnpm contract coverage

# Code quality
pnpm biome:format
pnpm biome:check
```

### Common Development Tasks
- **New contract**: Create in appropriate `/contracts/` subdirectory with tests
- **Frontend components**: Place in `/app/components/` with proper typing
- **GraphQL queries**: Use codegen with `pnpm frontend codegen`
- **Documentation**: Update relevant `/docs/` files

## Important Patterns & Best Practices

### Smart Contract Patterns
- Always use **initializer** functions instead of constructors for upgradeable contracts
- Implement proper **access control** using OpenZeppelin's AccessControl
- Use **events** for important state changes
- Include **input validation** and **error handling**

### Frontend Patterns
- Use **React hooks** for state management
- Implement **loading states** for blockchain interactions
- Handle **transaction errors** gracefully
- Use **TypeScript interfaces** for all data structures

### Security Considerations
- **Validate all inputs** in smart contracts
- Use **reentrancy guards** where appropriate
- Implement **proper access controls**
- **Test edge cases** thoroughly
- Follow **principle of least privilege**

## Project-Specific Context

### Core Domain Concepts
- **Roles**: Managed via Hats Protocol for permissions and responsibilities
- **Thanks Tokens**: P2P transferable tokens for contribution tracking
- **Splits**: Automated reward distribution based on contribution
- **Time Frames**: Period-based role assignments and reward calculations
- **Workspaces**: Project containers with their own governance

### Key User Flows
1. **Workspace Creation**: BigBang contract initialization
2. **Role Management**: Hat creation and assignment
3. **Contribution Tracking**: Thanks Token transfers
4. **Reward Distribution**: Split creation and execution

### Testing Strategy
- **Unit tests** for all smart contracts
- **Integration tests** for contract interactions
- **E2E tests** using Cypress for critical user flows
- **Coverage reports** for contract code

## Environment & Deployment
- **Development**: Local Hardhat network
- **Testnet**: Sepolia with deployed contract addresses
- **Production**: Base network
- **Frontend**: https://toban.xyz

## Serena MCP Integration

### Project Management with Serena
This project uses **Serena MCP** for enhanced development workflow and project management:

#### Essential Serena Workflow
1. **Project Activation**: Always start with `mcp_serena_activate_project` for the toban project
2. **Symbol Discovery**: Use `mcp_serena_find_symbol` for code exploration and understanding
3. **Code Editing**: Prefer `mcp_serena_replace_symbol_body` for symbol-level edits
4. **Memory System**: Leverage project memories for context retention across sessions

#### Serena Best Practices
- **Symbol-first approach**: Use symbol-based tools (`find_symbol`, `replace_symbol_body`) over regex when possible
- **Memory utilization**: Check `mcp_serena_list_memories` and `mcp_serena_read_memory` for project context
- **Pattern searching**: Use `mcp_serena_search_for_pattern` for cross-codebase searches
- **Code references**: Use `mcp_serena_find_referencing_symbols` to understand symbol usage

#### Available Memories
The project maintains memories for:
- Project overview and architecture
- Development commands and workflows
- Code style conventions
- macOS environment specifics
- Task completion checklists

## When Helping with Code

1. **Start with Serena activation** - Always activate the toban project first
2. **Use symbol-based operations** - Prefer Serena's symbol tools for precise code manipulation
3. **Leverage project memories** - Check existing memories for context before starting tasks
4. **Consider monorepo structure** - Commands should be run with pnpm workspace syntax
5. **Prioritize type safety** - Use TypeScript strictly throughout
6. **Follow existing patterns** - Maintain consistency with current codebase
7. **Consider gas optimization** for smart contracts
8. **Implement proper error handling** for Web3 interactions
9. **Write tests** for new functionality
10. **Update documentation** when adding new features
11. **Think before acting** - Use `mcp_serena_think_about_task_adherence` for complex tasks

## Development Workflow with Serena

### For New Features
1. Activate project with Serena
2. Use `mcp_serena_find_symbol` to understand existing code structure
3. Use `mcp_serena_search_for_pattern` to find similar implementations
4. Implement using symbol-based editing tools
5. Use `mcp_serena_think_about_whether_you_are_done` to validate completion

### For Bug Fixes
1. Activate project and check relevant memories
2. Use `mcp_serena_find_referencing_symbols` to understand impact
3. Use symbol-based tools for precise fixes
4. Validate changes don't break existing functionality

### For Code Exploration
1. Start with `mcp_serena_get_symbols_overview` for file understanding
2. Use `mcp_serena_find_symbol` with depth parameter for detailed exploration
3. Leverage `mcp_serena_search_for_pattern` for cross-file analysis

## Common Issues & Solutions
- **MetaMask connection issues**: Check Privy configuration
- **Contract deployment failures**: Verify network configuration and gas settings
- **GraphQL schema mismatches**: Run codegen after subgraph updates
- **Build failures**: Ensure all dependencies are installed with pnpm install
- **Serena symbol not found**: Use pattern search or check file structure with `mcp_serena_list_dir`
- **Memory context missing**: Create new memories with `mcp_serena_write_memory` for future reference
1 change: 1 addition & 0 deletions .vscode/config/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GITHUB_PERSONAL_ACCESS_TOKEN=
36 changes: 36 additions & 0 deletions .vscode/mcp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"inputs": [],
"servers": {
"context7": {
"type": "http",
"url": "https://mcp.context7.com/mcp"
},
"sequential-thinking": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-sequential-thinking"]
},
"serena": {
"command": "uvx",
"args": [
"--from",
"git+https://github.com/oraios/serena",
"serena",
"start-mcp-server",
"--context",
"ide-assistant"
]
},
"github": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"-e",
"GITHUB_PERSONAL_ACCESS_TOKEN",
"ghcr.io/github/github-mcp-server"
],
"envFile": "${workspaceFolder}/.vscode/config/.env"
}
}
}
35 changes: 20 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,18 +228,6 @@ These solutions were combined with ideas from [Hats Protocol](https://www.hatspr
pnpm contract getChainInfo --network sepolia
```

- #### **deploy Sample Contract**

```bash
pnpm contract deploy:Lock --network sepolia
```

- #### **verify deployed contract**

```bash
pnpm contract deploy:Lock --verify --network sepolia
```

- #### **deploy all contract**

```bash
Expand Down Expand Up @@ -272,10 +260,19 @@ These solutions were combined with ideas from [Hats Protocol](https://www.hatspr

- #### **call bigbang task**

Please set params when you execute.
ワークスペースを作成する際に実行されるメソッド.
必要なコントラクトが一式デプロイされる

```bash
pnpm contract bigbang --owner 0x51908F598A5e0d8F1A3bAbFa6DF76F9704daD072 --tophatdetails "tophatDetails" --tophatimageuri "tophatURI" --hatterhatdetails "hatterhatURI" --hatterhatimageuri "tophatDetails" --forwarder 0x51908F598A5e0d8F1A3bAbFa6DF76F9704daD072 --network sepolia
pnpm contract bigbang \
--owner 0x51908F598A5e0d8F1A3bAbFa6DF76F9704daD072 \
--tophatdetails "Dev Top Hat" \
--tophatimageuri "dev-tophat" \
--hatterhatdetails "Dev Hatter Hat" \
--hatterhatimageuri "dev-hatterhat" \
--memberhatdetails "Dev Member Hat" \
--memberhatimageuri "dev-memberhat" \
--network sepolia
```

- #### **call getWoreTime task**
Expand All @@ -287,5 +284,13 @@ These solutions were combined with ideas from [Hats Protocol](https://www.hatspr
- #### **call mintHat task**

```bash
pnpm contract mintHat --hatid 17011726346972053710434886519909386955065038130623101235576378067255296 --wearer 0x1295BDc0C102EB105dC0198fdC193588fe66A1e4 --network sepolia
# --module には bigBangコントラクトの時に出力される hatsTimeFrameModule のアドレスを当てはめること!
pnpm contract mintHat --hatid 39145842972085145413893403125858635166881967613628980006401871953526784 --wearer 0xEef377Bdf67A227a744e386231fB3f264C158CDF --module 0xA193a4CE929168A594744A53Fb17Ba4caBb507a4 --network sepolia
```

- #### **call batchMintHats task**

```bash
# --module には bigBangコントラクトの時に出力される hatsTimeFrameModule のアドレスを当てはめること!
pnpm contract batchMintHat --hatid 39145842972085145413893403125858635166881967613628980006401871953526784 --csv ./data/example-wearers.csv --module 0xA193a4CE929168A594744A53Fb17Ba4caBb507a4 --network sepolia
```
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,46 @@ contract HatsTimeFrameModule is HatsModule, IHatsTimeFrameModule {
emit HatMinted(hatId, wearer, time == 0 ? block.timestamp : time);
}

/**
* @dev Batch mint hats for multiple addresses with the same hat ID.
* @param hatId The ID of the hat to be minted for all wearers.
* @param wearers Array of addresses to receive the hat.
* @param times Array of specific timestamps when each hat was minted (0 for current time).
*/
function batchMintHat(
uint256 hatId,
address[] calldata wearers,
uint256[] calldata times
) external {
// 権限チェック
require(hasAuthority(msg.sender), "Not authorized");

// 入力検証
require(wearers.length > 0, "Empty wearers array");
require(wearers.length == times.length, "Array length mismatch");
require(wearers.length <= 100, "Batch size too large");

// 事前検証(全てのwearerが有効かチェック)
for (uint256 i = 0; i < wearers.length; i++) {
require(wearers[i] != address(0), "Invalid wearer address");
require(woreTime[hatId][wearers[i]] == 0, "Hat already minted");
}

// 一括ミント実行
for (uint256 i = 0; i < wearers.length; i++) {
address wearer = wearers[i];
uint256 time = times[i];

_setWoreTime(wearer, hatId, time);
isActive[hatId][wearer] = true;
HATS().mintHat(hatId, wearer);

emit HatMinted(hatId, wearer, time == 0 ? block.timestamp : time);
}

emit BatchMintCompleted(hatId, wearers.length);
}

/**
* @dev Deactivate the hat, pausing the contribution time.
* Calculate the contribution time up to deactivation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ interface IHatsTimeFrameModule {
uint256 hatId
) external view returns (uint256);

/**
* @dev Batch mint hats for multiple addresses with the same hat ID.
* @param hatId The ID of the hat to be minted for all wearers.
* @param wearers Array of addresses to receive the hat.
* @param times Array of specific timestamps when each hat was minted (0 for current time).
*/
function batchMintHat(
uint256 hatId,
address[] calldata wearers,
uint256[] calldata times
) external;

function woreTime(
uint256 hatId,
address wearer
Expand Down Expand Up @@ -84,4 +96,9 @@ interface IHatsTimeFrameModule {
* @notice Emitted when a hat is renounced
*/
event HatRenounced(uint256 indexed hatId, address indexed wearer);

/**
* @notice Emitted when batch mint is completed
*/
event BatchMintCompleted(uint256 indexed hatId, uint256 count);
}
5 changes: 5 additions & 0 deletions pkgs/contract/data/example-wearers.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
address,timestamp
0x1431ea8af860C3862A919968C71f901aEdE1910E,1640995200
0xC66a0700d1578C83752E6b7518819abc0ecc4f18, 1640995200
0x402fb9124a11396D5F7e596855CB59aBEB3459AD,1672531200
0xef902bbE4967ac7A5Ec22039cA2d994325A36dB9, 1640995200
Loading
Loading