A decentralized pawn protocol built on zkSync Era for educational purposes, featuring real-time Chainlink oracle integration to demonstrate DeFi concepts and smart contract development.
- Live Chainlink Price Feeds on zkSync Sepolia testnet
- Real-time ETH/USD pricing from decentralized oracle network
- Price validation with circuit breakers and deviation checks
- Fallback mechanisms for maximum reliability
- 70% Loan-to-Value (LTV) ratio for ETH collateral
- 10% interest rate on loans
- 1-year loan duration with early redemption options
- Automatic liquidation when collateral value drops below threshold
- Reentrancy protection on all functions
- Price feed validation with age and deviation checks
- Circuit breakers for price manipulation protection
- Pausable contracts for emergency situations
- Responsive React frontend with Material-UI components
- Real-time transaction feedback in modal dialogs
- Wallet integration with MetaMask support
- Live price updates from Chainlink oracles
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β Frontend β β Backend β β Smart β
β (React) βββββΊβ (Node.js) βββββΊβ Contracts β
β β β β β (Solidity) β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β β
βΌ βΌ
ββββββββββββββββββββ βββββββββββββββββββ
β Docker β β Chainlink β
β Containers β β Oracles β
ββββββββββββββββββββ βββββββββββββββββββ
- Node.js 18+
- Docker & Docker Compose
- MetaMask wallet
- zkSync Sepolia testnet ETH
git clone https://github.com/yourusername/bullpawn.git
cd bullpawncp env.example .env
# Edit .env with your private key and configuration# Deploy with real Chainlink oracle integration
PRIVATE_KEY=your_private_key node scripts/deploy-chainlink-oracle.js# Start all services with Docker
docker-compose up --build -d- Frontend: http://localhost:3000
- Backend API: http://localhost:9001
- Health Check: http://localhost:9001/health
| Asset Pair | Contract Address | Deviation | Heartbeat |
|---|---|---|---|
| ETH/USD | 0xfEefF7c3fB57d18C5C6Cdd71e45D2D0b4F9377bF |
0.5% | 24h |
| BTC/USD | 0x95Bc57e794aeb02E4a16eff406147f3ce2531F83 |
0.5% | 24h |
| USDT/USD | 0x07F05C2aFeb54b68Ea425CAbCcbF53E2d5605d76 |
0.3% | 24h |
- β Positive Price Check: Ensures prices > 0
- β Age Validation: Rejects prices older than 24 hours
- β Deviation Protection: 10% max deviation from last valid price
- β Circuit Breakers: Uses last valid price if current fails validation
- β Fallback Mechanisms: CoinGecko API backup if oracle fails
PawnSystem.sol: Main pawn protocol contractChainlinkPriceFeed.sol: Oracle wrapper with validationMockUSDT.sol: Test USDT token for developmentIPriceFeed.sol: Standardized oracle interface
// Create a new pawn position
function createPawn() external payable
// Redeem ETH collateral
function redeemPawn(uint256 positionId) external
// Check if position should be liquidated
function shouldLiquidate(uint256 positionId) public view returns (bool)
// Get current ETH price from oracle
function getETHPrice() public view returns (uint256)// Frontend API call
const result = await apiService.createPawn("0.1"); // 0.1 ETH
console.log(`Position created: ${result.positionId}`);
console.log(`Transaction: ${result.txHash}`);// Get live price from Chainlink oracle
const price = await apiService.getETHPrice();
console.log(`Current ETH price: $${price} USD`);// Redeem with 10% interest
const repaymentAmount = (loanAmount * 1.1).toFixed(2);
const result = await apiService.redeemPawn(positionId, repaymentAmount);
console.log(`Redeemed: ${result.txHash}`);POST /api/pawn/create- Create new pawn positionPOST /api/pawn/redeem- Redeem existing positionGET /api/pawn/position/:id- Get position detailsGET /api/pawn/price/eth- Get current ETH price
GET /api/pawn/price/eth- Live ETH price from Chainlink- Oracle health monitoring and validation
# Test oracle connection and price feeds
node test-oracle.js# Check USDT liquidity and wallet balances
node check-balance.js# Add USDT liquidity to the contract
node setup-liquidity.jsThis project is created for educational and learning purposes only. It is NOT recommended for production use.
- Testnet Deployment: Uses zkSync Sepolia testnet with test tokens
- Mock Contracts: Includes MockUSDT for demonstration purposes
- Limited Security Audits: Has not undergone comprehensive security audits
- Simplified Implementation: Focuses on core concepts rather than production robustness
- No Real Value: All transactions use testnet tokens with no real monetary value
- Understanding DeFi pawn protocol mechanics
- Working with Chainlink oracles and price feeds
- Smart contract development on zkSync Era
- Frontend integration with Web3 wallets
- Docker containerization for blockchain applications
- Replace
MockUSDTwith real USDT contract - Use mainnet Chainlink price feeds
- Implement multi-signature wallet for admin functions
- Add additional oracle sources for redundancy
- Set up monitoring and alerting systems
- Comprehensive security audits by professional firms
- Formal verification of smart contracts
- Insurance and risk management protocols
- Regular oracle health checks
- Price deviation monitoring
- Emergency pause functionality
- Environment variable management
- Proper error handling
# Install dependencies
npm install
# Compile contracts
cd contracts && npx hardhat compile
# Run tests
npm test
# Start development servers
npm run dev# Build and start all services
docker-compose up --build
# View logs
docker-compose logs -f
# Stop services
docker-compose downbullpawn/
βββ contracts/ # Smart contracts
β βββ contracts/ # Solidity source files
β βββ scripts/ # Deployment scripts
β βββ artifacts-zk/ # Compiled contracts
βββ backend/ # Node.js backend
β βββ src/ # TypeScript source
β βββ dist/ # Compiled JavaScript
βββ frontend/ # React frontend
β βββ src/ # React components
β βββ public/ # Static assets
βββ scripts/ # Utility scripts
βββ docker-compose.yml # Docker configuration
βββ README.md # This file
- Chain ID: 300
- RPC URL: https://sepolia.era.zksync.dev
- Explorer: https://sepolia.explorer.zksync.io
- Faucet: https://sepoliafaucet.com/
- 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.
- Chainlink for providing decentralized oracle infrastructure
- zkSync for the Layer 2 scaling solution
- OpenZeppelin for secure smart contract libraries
- Material-UI for the beautiful React components
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Documentation: Wiki
This project demonstrates:
- DeFi Protocol Design: How pawn protocols work in decentralized finance
- Oracle Integration: Real-world Chainlink oracle implementation
- Smart Contract Security: Reentrancy protection, validation, and circuit breakers
- Full-Stack Development: React frontend, Node.js backend, and Solidity contracts
- Docker Deployment: Containerized blockchain application architecture
- Web3 Integration: MetaMask wallet connection and transaction handling
π Built with: React, TypeScript, Solidity, zkSync Era, Chainlink Oracles, Docker