SafeP2P — Trustless P2P Escrow for Pakistan 🇵🇰
"Binance P2P asks you to trust a company. SafeP2P asks you to trust math."
SafeP2P is a trustless escrow smart contract for peer-to-peer USDT ↔ PKR trades in Pakistan. It eliminates fake payment screenshot scams by locking USDT in a smart contract — released only when the seller confirms PKR was received off-chain. Deployed & Verified on Sepolia: 0x712240bf4a3cf0f4E6e9C56d3A26347B2E71fA06
The Problem Pakistan's P2P crypto market runs on Binance P2P. The core scam:
Buyer places order for USDT Buyer sends a fake bank transfer screenshot to seller Seller believes PKR was received and clicks "Release" USDT is gone — PKR was never sent Seller has no recourse
SafeP2P eliminates the need to trust anyone — including the contract deployer.
How It Works
Seller deposits USDT ──► [Escrow Contract] ◄── Buyer pays fee │ USDT locked here │ ┌───────────────────┼───────────────────┐ │ │ │ Seller confirms Buyer raises Timeout (30 min) PKR received dispute → cancel │ │ USDT → Buyer 3 Arbitrators vote │ 2/3 majority wins │ USDT → winner
Happy Path
Seller calls createTrade(amount, rate) — deposits USDT + 0.5% fee Buyer calls joinTrade(tradeId) — pays 0.5% fee Buyer sends PKR to seller via bank transfer (off-chain) Seller calls confirmPayment(tradeId) — USDT released to buyer
Dispute Path
Buyer calls raiseDispute(tradeId) if seller is unresponsive 3 arbitrators each cast one vote (2/3 majority wins) Winner receives the locked USDT Voting arbitrators share the 1% fee pool
Fee Structure ActionWho PaysAmountcreateTradeSeller0.5% of trade amountjoinTradeBuyer0.5% of trade amountDispute resolution—1% total, split among voting arbitratorsCancel OPEN trade—Full refund to sellerCancel ACTIVE tradeBuyerLoses 0.5% fee (penalty)
Arbitrator System
Anyone can stake 50 USDT to become an arbitrator (max 3 slots) Arbitrators vote on disputed trades and earn a share of the 1% fee pool Stake is locked while holding the role Admin can slash stake for bad actors Self-removal refunds full balance (stake + earnings)
Stack
Solidity ^0.8.18 Foundry (forge, cast, anvil) OpenZeppelin AccessControl Polygon Mainnet (target) / Sepolia (testnet) USDT ERC20, 6 decimals
Getting Started Prerequisites
Foundry A funded wallet
git clone https://github.com/Iamanas309/SafeP2P.git cd SafeP2P forge install
forge build
forge test -vvvv
cp .env.example .env
forge script script/EscrowScript.s.sol:EscrowScript
--rpc-url $SEPOLIA_RPC_URL
--account <your_keystore_account>
--broadcast
--verify
--etherscan-api-key $ETHERSCAN_API_KEY
-vvvv
Security Considerations
Checks-Effects-Interactions pattern throughout — reentrancy safe without nonReentrant OpenZeppelin AccessControl for granular role management Admin cannot touch trade funds — only resolves deadlocks after 2 days Built-in overflow protection via Solidity ^0.8.18 All transfer / transferFrom return values checked
Known Limitations (V1)
Fixed 3 arbitrator slots — collusion risk at small scale Admin is a single point of failure for deadlock resolution Off-chain PKR transfer is unverifiable by design Unclaimed fees accumulate in contract permanently No frontend (V2)
Roadmap (V2)
Frontend interface Marketplace / order book Larger arbitrator pool with randomized selection Reputation system Multisig / DAO admin for deadlock resolution Configurable fee tiers and timeouts Multi-token support
Author Anas — @Iamanas309 Built to solve a real problem in Pakistan's P2P crypto market.
License MIT