Skip to content

cypherpulse/cPay-Contract

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cPay: On-Chain Payments for Celo Merchants

Built with Foundry Celo Network License: MIT

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.

🌟 Features

  • 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

🏗️ Architecture

cPay v1 consists of two core smart contracts:

MerchantRegistry

  • Purpose: Manages merchant onboarding and metadata
  • Access Control: Owner-only registration for security
  • Events: MerchantRegistered, MerchantUnregistered

cPayPayments

  • 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

🚀 Quick Start

Prerequisites

  • Foundry (latest version)
  • Node.js (v16+)
  • A Celo wallet with testnet funds

Installation

  1. Clone the repository

    git clone https://github.com/your-org/cpay-contract.git
    cd cpay-contract
  2. Install dependencies

    forge install
  3. Build the contracts

    forge build
  4. Run tests

    forge test

📋 Usage

Local Development

  1. Start local Celo node (optional)

    anvil --fork-url https://alfajores-forno.celo-testnet.org
  2. Deploy contracts locally

    forge script script/DeployCPay.s.sol --rpc-url http://localhost:8545 --private-key <your_private_key>

Testnet Deployment

  1. 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
  2. Deploy to Celo Alfajores

    forge script script/DeployCPay.s.sol --rpc-url $CELO_RPC_URL --private-key $PRIVATE_KEY --broadcast --verify

Mainnet Deployment

Replace the RPC URL with Celo Mainnet:

export CELO_RPC_URL=https://forno.celo.org
export CUSD_ADDRESS=0x765DE816845861e75A25fCA122bb6898B8B1282a  # Update with mainnet cUSD

🧪 Testing

Run the comprehensive test suite:

forge test

Test coverage includes:

  • Merchant registration and unregistration
  • Invoice creation by registered merchants
  • Successful payment processing with ERC-20 transfers
  • Error handling for invalid operations

📚 API Reference

MerchantRegistry

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)

cPayPayments

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)

🔒 Security

  • 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

🛣️ Roadmap

v1.0 (Current)

  • ✅ Merchant registry
  • ✅ Basic invoice system
  • ✅ Single stablecoin support
  • ✅ Foundry testing suite

v2.0 (Planned)

  • 🔄 Multi-token support
  • 🔄 Off-ramp integration
  • 🔄 Subscription payments
  • 🔄 AI-powered automation
  • 🔄 Enhanced merchant dashboards

🤝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🌐 Links

📞 Support

For questions and support:


Built with ❤️ for the Celo ecosystem

About

cPay contract for a decentralized, on-chain payment system designed specifically for merchants on the Celo blockchain

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors