cPay is a decentralized, on-chain payment system designed specifically for merchants on the Celo blockchain. Built with Solidity and Foundry, cPay enables seamless invoice creation and payment processing using stablecoins, providing a secure and efficient alternative to traditional payment methods.
- Merchant Registry: Secure registration and management of merchants with metadata support
- Invoice System: Create and manage payment invoices with flexible payer specifications
- Stablecoin Payments: Native support for ERC-20 stablecoins (optimized for cUSD on Celo)
- Gas-Efficient: Custom errors and optimized Solidity patterns for minimal transaction costs
- Secure by Design: Built with OpenZeppelin standards and comprehensive access controls
- Celo-Optimized: Tailored for the Celo ecosystem with fast finality and low fees
cPay v1 consists of two core smart contracts:
- Purpose: Manages merchant onboarding and metadata
- Access Control: Owner-only registration for security
- Events:
MerchantRegistered,MerchantUnregistered
- Purpose: Handles invoice lifecycle and payment processing
- Data Model: Structured invoices with merchant, payer, amount, and status
- Functions:
createInvoice(),payInvoice(),getInvoice() - Security: Custom error handling and ERC-20 transfer validation
-
Clone the repository
git clone https://github.com/your-org/cpay-contract.git cd cpay-contract -
Install dependencies
forge install
-
Build the contracts
forge build
-
Run tests
forge test
-
Start local Celo node (optional)
anvil --fork-url https://alfajores-forno.celo-testnet.org
-
Deploy contracts locally
forge script script/DeployCPay.s.sol --rpc-url http://localhost:8545 --private-key <your_private_key>
-
Set environment variables
export PRIVATE_KEY=your_private_key_without_0x_prefix export CELO_RPC_URL=https://alfajores-forno.celo-testnet.org export CUSD_ADDRESS=0x765DE816845861e75A25fCA122bb6898B8B1282a
-
Deploy to Celo Alfajores
forge script script/DeployCPay.s.sol --rpc-url $CELO_RPC_URL --private-key $PRIVATE_KEY --broadcast --verify
Replace the RPC URL with Celo Mainnet:
export CELO_RPC_URL=https://forno.celo.org
export CUSD_ADDRESS=0x765DE816845861e75A25fCA122bb6898B8B1282a # Update with mainnet cUSDRun the comprehensive test suite:
forge testTest coverage includes:
- Merchant registration and unregistration
- Invoice creation by registered merchants
- Successful payment processing with ERC-20 transfers
- Error handling for invalid operations
function registerMerchant(address merchant, string memory metadata) external onlyOwner
function unregisterMerchant(address merchant) external onlyOwner
function isRegistered(address merchant) external view returns (bool)
function metadata(address merchant) external view returns (string memory)function createInvoice(uint256 amount, address payer) external returns (uint256 invoiceId)
function payInvoice(uint256 invoiceId) external
function getInvoice(uint256 invoiceId) external view returns (Invoice memory)
function token() external view returns (address)
function registry() external view returns (address)- Access Control: Owner-only merchant management prevents unauthorized registrations
- Input Validation: Comprehensive checks for invoice validity and payment authorization
- ERC-20 Safety: Proper transferFrom handling with approval requirements
- Custom Errors: Gas-efficient error handling without string comparisons
- No Reentrancy: Stateless operations minimize attack surfaces
- ✅ Merchant registry
- ✅ Basic invoice system
- ✅ Single stablecoin support
- ✅ Foundry testing suite
- 🔄 Multi-token support
- 🔄 Off-ramp integration
- 🔄 Subscription payments
- 🔄 AI-powered automation
- 🔄 Enhanced merchant dashboards
We welcome contributions! Please see our Contributing Guide for details.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
For questions and support:
- Open an issue on GitHub
- Join the Celo Discord
- Check out the Celo Forum
Built with ❤️ for the Celo ecosystem