A web3 application for decentralized profit sharing and unit management with a hierarchical token system.
PiePay is a lightweight, focused web3 application that enables projects to manage contributors and distribute rewards through a sophisticated unit-based system. It implements a decentralized autonomous organization (DAO) structure with configurable profit-sharing mechanisms.
- Frontend Framework: React 19 with TypeScript
- Build Tool: Vite
- Web3 Integration: Wagmi v2 + Viem for blockchain interaction
- Wallet Connection: RainbowKit for wallet connectivity
- UI Framework: Mantine v8 (components, forms, notifications)
- State Management: TanStack React Query for server state
- Styling: Mantine's CSS-in-JS with dark theme
main.tsx- Application bootstrap and renderingApp.tsx- Root component with provider setup- WagmiProvider (blockchain connection)
- QueryClientProvider (data fetching)
- RainbowKitProvider (wallet UI)
- MantineProvider (UI theming)
config.ts- Blockchain and contract configuration- Supported chains: Sepolia (testnet), Localhost, Mainnet
- Contract addresses: PiePay, MockUSDC
- Chain selection helpers
vite.config.ts- Development server configuration
hooks/usePiePayContract.ts- Central hub for all contract interactions- Unified interface for read/write operations
- Defines unit types: Profit (0), Debt (1), Capital (2)
- Defines contribution states: None (0), Pending (1), Approved (2), Rejected (3)
- Connects to all components requiring contract data
abi/PiePay.json- Contract interface definition- Type-safe contract calls
- Comprehensive event definitions
PiePayDashboard.tsx- Application shell with wallet connection & navigation- Currently active tabs: "Contract Info" and "Admin"
- Inactive tabs ready for activation: Contributors, Contributions, Units, Payroll
-
SimpleContractInfo.tsx- Primary active component- Displays contract state, roles, balances
- Shows: project lead, payroll manager, token info, conversion multipliers
- Uses:
usePiePayContracthook
-
AdminPanel.tsx- Administrative functions- Role management (project lead, payroll manager)
- Conversion multiplier configuration
- Unit capacity settings
- Access control: Role-based permissions
ContributorManagement.tsx- Whitelist managementContributionWorkflow.tsx- Submit/review contributionsUnitManagement.tsx- Unit balances and conversionsPayrollManagement.tsx- Funding and distributions
User Action → Component → usePiePayContract Hook → Blockchain
↓
UI Updates ← React Query Cache ← Contract Events
- Read Operations: React Query + Wagmi for caching and synchronization
- Write Operations: Transaction submission with status tracking
- State Synchronization: Automatic re-fetching on transaction confirmation
- Contract Information: View contract details, roles, and current state
- Contributor Management: Whitelist/remove contributors (Project Lead only)
- Contribution Workflow: Submit and review contributions
- Unit Management: View and convert between P-Units, D-Units, and C-Units
- Payroll Management: Fund payroll and execute payouts (Payroll Manager only)
- Admin Panel: Manage contract settings and roles
- P-Units (Profit) - Entry level, earned through contributions
- D-Units (Debt) - Middle tier, convertible from P-Units
- C-Units (Capital) - Highest tier, permanent ownership rights
- P→D Multiplier: 1.5x (basis points: 15000)
- P→C Multiplier: 0.3x (basis points: 3000)
- D→C Multiplier: 0.2x (basis points: 2000)
- P-Units & D-Units: Buyback behavior (units consumed on payout)
- C-Units: Dividend behavior (units persist through payouts)
- Project Lead: Full administrative control, contribution approval
- Payroll Manager: Payroll funding and distribution
- Whitelisted Contributors: Contribution submission and unit conversion
- Public: Read-only access to contract information
- Address Validation: Ethereum address format checking
- Numeric Validation: Positive values, range checking
- Transaction Validation: Role verification before execution
- Node.js 18+
- npm or yarn
- Local blockchain (Anvil/Hardhat)
🚀 PiePay Full Stack Startup Guide
Prerequisites:
- ✅ Docker Desktop (for the indexer database)
- ✅ Node.js/npm (for frontend)
- ✅ pnpm (for indexer)
- Start Docker Desktop
Make sure Docker Desktop is running on your Mac.
- Start the Indexer (First!)
cd /piepay/piepay-indexer pnpm dev What this does:
- Starts PostgreSQL + Hasura GraphQL on http://localhost:8080
- Begins indexing events from Arbitrum Sepolia
- Provides GraphQL API for the frontend
Wait for: "✅ All chains are up to date" or similar success message
- Start the Frontend
cd /piepay/piepay-frontend npm run dev What this does:
- Starts React app on http://localhost:5173
- Connects to your wallet (MetaMask)
- Connects to the indexer at localhost:8080
- Optional: Backend/Other Services
cd /piepay/piepay-backend npm run dev # (if needed)
🔗 URLs You'll Access:
| Service | URL | Purpose |
|---|---|---|
| Frontend | http://localhost:5173 | Main PiePay UI |
| Indexer GraphQL | http://localhost:8080 | GraphQL Playground |
| Indexer DB | localhost:5433 | PostgreSQL (internal) |
📱 Quick Test Flow:
- Open Frontend: http://localhost:5173
- Connect Wallet: Make sure you're on Arbitrum Sepolia
- Check "Submit P Unit" tab: Should show the contribution form
- Submit a contribution: Watch it go through the pipeline
- Check "Contributions" tab: Should show your submission updating in real-time
🛠 Troubleshooting:
Indexer won't start:
- Check Docker Desktop is running
- Run docker system prune if needed
- Try pnpm install in the indexer directory
Frontend can't connect:
- Make sure indexer is running on port 8080
- Check browser console for errors
- Verify wallet is on Arbitrum Sepolia network
Transactions failing:
- Make sure you have ETH on Arbitrum Sepolia
- Check if you're whitelisted (you should be as project lead)
⚡ Development Workflow:
- Start indexer first (needs to be running for frontend)
- Start frontend second (connects to indexer)
- Make changes and hot-reload works for both
- Check GraphQL playground at localhost:8080 for data
Want me to create a startup script to automate this? I can make a simple shell script that starts everything in the right order with proper wait times.
npm run devnpm run buildnpm run lint- Deploy contracts using the PiePay contracts repository
- Update contract addresses in
src/config.ts - Ensure ABI is current in
src/abi/PiePay.json
-
Add localhost network to MetaMask:
- Network name: Localhost 8545
- RPC URL: http://localhost:8545
- Chain ID: 31337
- Currency symbol: ETH
-
Import test account private key for testing
The application includes comprehensive contract interaction testing through the UI. All contract functions can be tested through the respective component interfaces.
projectLead()- Get project lead addresspayrollManager()- Get payroll manager addresspaymentToken()- Get payment token addresspayrollPool()- Get available payroll fundsgetContributorCount()- Get total number of contributorsgetContributorUnits(address)- Get units for a contributorgetContributionDetails(id)- Get contribution detailswhitelistedContributors(address)- Check if address is whitelistedgetTotalUnitsOutstanding(unitType)- Get total units by typegetUnitHolders(unitType)- Get holders of a unit type
whitelistContributor(address)- Add contributor to whitelistremoveContributor(address)- Remove contributor from whitelistsubmitContribution(unitType, units, description)- Submit contributionreviewContribution(id, approved)- Approve/reject contributionconvertUnits(fromType, toType, amount)- Convert between unit typesfundPayroll(amount)- Add funds to payroll poolexecuteUnitPayout(unitType, amount)- Distribute funds to unit holderssetProjectLead(address)- Change project leadsetPayrollManager(address)- Change payroll managersetConversionMultipliers(pToD, pToC, dToC)- Update conversion ratessetUnitCapacity(unitType, capacity)- Set unit capacity limits
- P-Units (Profit): Decrease on payout, earned through contributions
- D-Units (Debt): Decrease on payout, converted from P-Units with 1.5x multiplier
- C-Units (Capital): Persist on payout (dividend-like), highest in hierarchy
- Project Lead: Manage contributors, review contributions, set new project lead
- Payroll Manager: Fund payroll, execute payouts, manage conversion rates and capacities
- Contributors: Submit contributions, convert units (if whitelisted)
| Aspect | PiePay | Grantships |
|---|---|---|
| Scope | Single contract focus | Multi-contract ecosystem |
| State Management | React Query only | GraphQL + local state |
| Navigation | Simple tabs | Complex routing |
| Data Flow | Direct contract calls | Indexer + subgraph |
| Complexity | Lightweight | Feature-rich |
The architecture is designed for easy expansion:
- Activate Additional Tabs: Uncomment components in
PiePayDashboard.tsx - Add New Features: Extend
usePiePayContracthook - Enhanced UI: Leverage Mantine's component library
- Multi-chain Support: Extend chain configuration
- Update the contract address in
src/config.ts - Build the application:
npm run build - Deploy the
distfolder to your hosting platform
The contract ABI is automatically included from src/abi/PiePay.json. If you redeploy the contract, make sure to update this file with the new ABI.