Skip to content

Commit e916adf

Browse files
committed
Fix eslint errors: convert require() to ES6 imports/exports and remove unused variables
1 parent 0db92bc commit e916adf

64 files changed

Lines changed: 10633 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 274 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,274 @@
1+
# Workspace instructions for tipschain-ecosystem
2+
3+
This repo is **TipsChain Ecosystem** - a complete blockchain platform combining a Next.js frontend with Hardhat contracts, integrated DEX, wallet, explorer, and gassless transaction relayer.
4+
5+
## 🎯 System Overview
6+
7+
**TipsChain** is a production-ready blockchain ecosystem featuring:
8+
9+
- **Native Gas Token**: TIPS (Tipscoin) - used for all blockchain fees (18 decimals)
10+
- **Gassless Transactions**: Relayer system for user-friendly transactions via TrustedForwarder
11+
- **Integrated DEX**: Decentralized exchange for swapping TIPS and tokens without gas fees
12+
- **Web3 Wallet**: Multi-chain wallet integration with TIPS balance management
13+
- **Block Explorer**: Full blockchain explorer at scan.tipspay.org with TIPS gas display
14+
15+
## 📁 What this workspace is
16+
17+
- `pages/` - React/Next.js frontend (wallet, DEX, explorer UI)
18+
- `pages/api/` - API routes (wallet, DEx, explorer endpoints)
19+
- `services/` - Backend business logic (blockchain, relayer, DEX, explorer)
20+
- `contracts/` - Solidity smart contracts (Tipscoin, USDTC, TrustedForwarder, Tipsnameserver)
21+
- `scripts/` - Deployment, initialization, and production scripts
22+
- `config/` - Configuration files (production settings, relayer config, deployed addresses)
23+
- `styles/` - CSS modules (wallet, DEX, explorer styling)
24+
- `test/` - Hardhat unit tests
25+
- `hardhat.config.js` - Blockchain development environment
26+
- `SETUP.md` - Complete setup and deployment guide
27+
- `ARCHITECTURE.md` - System architecture and data flow diagrams
28+
29+
## ⚡ TIPS - Native Gas Token
30+
31+
### Critical: Tipscoin (TIPS) is the native gas token
32+
33+
- All transaction fees paid in TIPS (not ETH)
34+
- 18 decimals (same as ETH)
35+
- 1,000,000,000 total supply
36+
- Displayed in wallet/explorer as "TIPS"
37+
- Relayer uses TIPS to pay for user transactions
38+
- Use `blockchainProvider.formatTips()` for all balance displays
39+
40+
## 🚀 Common Tasks
41+
42+
### Development
43+
44+
```bash
45+
npm install # Install dependencies
46+
npm run dev # Run Next.js frontend locally
47+
npm run build # Build Next.js app
48+
npm run node # Start local blockchain
49+
```
50+
51+
### Smart Contracts
52+
53+
```bash
54+
npm run compile # Compile Solidity contracts
55+
npm run test # Run Hardhat tests
56+
npm run test:coverage # Run with coverage report
57+
npm run lint # Run ESLint
58+
npm run format # Run Prettier
59+
npm run clean # Clean artifacts
60+
```
61+
62+
### Deployment
63+
64+
```bash
65+
npm run deploy:localhost # Deploy to local blockchain
66+
npm run deploy:testnet # Deploy to Sepolia testnet
67+
npm run deploy:mainnet # Deploy to mainnet
68+
npm run deploy:production # Full production deployment
69+
npm run deploy:relayer # Deploy relayer contract
70+
npm run verify -- mainnet # Verify contracts on explorer
71+
```
72+
73+
### Production Scripts
74+
75+
```bash
76+
bash scripts/deploy-all.sh # Complete deployment
77+
bash scripts/start.sh # Start all services
78+
bash scripts/production-checklist.sh # Review production readiness
79+
node scripts/initialize.js # Initialize all services
80+
node scripts/deploy-production.js # Production contracts
81+
node scripts/deploy-relayer.js # Deploy relayer
82+
```
83+
84+
## 🔧 Key Components
85+
86+
### Smart Contracts
87+
88+
| Contract | Role | Notes |
89+
|----------|------|-------|
90+
| **Tipscoin.sol** | ERC20 token | Native gas coin (TPS), 18 decimals |
91+
| **USDTC.sol** | ERC20 stablecoin | Trading pair with TPS on DEX |
92+
| **TrustedForwarder.sol** | Meta-tx forwarder | Enables gassless transactions |
93+
| **Tipsnameserver.sol** | Name registry | ENS-like address resolution |
94+
95+
### Backend Services
96+
97+
| File | Purpose |
98+
| ------ | ------- |
99+
| `blockchainProvider.js` | RPC connection, contract interactions, unit conversions |
100+
| `relayerService.js` | Gassless transactions, relayer wallet management |
101+
| `walletService.js` | Balance checks, token queries, signature verification |
102+
| `dexService.js` | Token prices, swap quotes, liquidity info |
103+
| `explorerService.js` | Block indexing, transaction tracking, stats |
104+
105+
### Frontend Pages
106+
107+
| Page | Purpose |
108+
| ------ | ------- |
109+
| `/wallet` | Balance display, send/receive, token management |
110+
| `/dex` | Swap interface, gassless swaps via relayer |
111+
| `/explorer` | Block explorer, transaction search, address details |
112+
113+
### API Endpoints
114+
115+
```
116+
Wallet:
117+
GET /api/wallet/balance
118+
GET /api/wallet/token-balance
119+
POST /api/wallet/verify
120+
121+
DEX:
122+
GET /api/dex/tokens
123+
GET /api/dex/price
124+
POST /api/dex/swap-quote
125+
POST /api/dex/gassless-swap
126+
127+
Explorer:
128+
GET /api/explorer/blocks
129+
GET /api/explorer/block
130+
GET /api/explorer/transaction
131+
GET /api/explorer/address
132+
GET /api/explorer/search
133+
GET /api/explorer/stats
134+
```
135+
136+
## 💡 Gassless Transaction Flow
137+
138+
```
139+
1. User initiates transaction (e.g., swap on DEX)
140+
2. Frontend sends request to /api/dex/gassless-swap
141+
3. Backend relayerService creates meta-transaction
142+
4. relayerService calls TrustedForwarder contract
143+
5. TrustedForwarder validates (trusted consumer, rate limits, etc.)
144+
6. Relayer broadcasts transaction (pays gas in TIPS)
145+
7. Smart contract executes (e.g., DEX swap)
146+
8. User sees tokens received, no gas paid by user!
147+
```
148+
149+
## 🌐 Service Domains
150+
151+
```
152+
Domain | Service
153+
----------------------------|-------------------
154+
https://tipschain.sbs | Web3 Wallet
155+
https://dex.tipschain.sbs | Decentralized Exchange
156+
https://scan.tipspay.org | Block Explorer
157+
https://api.tipspay.org | API Gateway
158+
```
159+
160+
## ⚙️ Environment Configuration
161+
162+
```bash
163+
# Blockchain
164+
BLOCKCHAIN_RPC_URL=http://localhost:8545
165+
BLOCKCHAIN_CHAIN_ID=1
166+
167+
# Contracts
168+
TIPSCOIN_ADDRESS=0x...
169+
USDTC_ADDRESS=0x...
170+
TIPS_DECIMALS=18
171+
172+
# Relayer (Gassless Transactions)
173+
TRUSTED_FORWARDER_ADDRESS=0x...
174+
RELAYER_PRIVATE_KEY=0x...
175+
RELAYER_GAS_LIMIT=500000
176+
177+
# Service Domains
178+
WALLET_DOMAIN=https://tipschain.sbs
179+
DEX_DOMAIN=https://dex.tipschain.sbs
180+
EXPLORER_DOMAIN=https://scan.tipspay.org
181+
```
182+
183+
See `.env.example` for complete list.
184+
185+
## 👨‍💻 Developer Guidance
186+
187+
### Code Organization
188+
189+
- Contract logic → `contracts/`
190+
- Frontend UI → `pages/` and `styles/`
191+
- Business logic → `services/`
192+
- API routes → `pages/api/`
193+
- Deployment logic → `scripts/`
194+
- Configuration → `config/`
195+
196+
### Key Rules
197+
198+
1. **Always use TIPS, not ETH** - Use `blockchainProvider.formatTips()` for displays
199+
2. **Keep relayer funded** - Needs >100 TIPS to operate
200+
3. **Test gassless flow** - Core functionality is meta-transactions
201+
4. **Verify contract changes** - Run `npm run compile && npm run test`
202+
5. **Use environment variables** - Never hardcode addresses
203+
6. **Never commit .env** - Use `.env.example` template
204+
205+
### Code Examples
206+
207+
```javascript
208+
// Get TIPS balance
209+
const balance = blockchainProvider.formatTips(balanceWei);
210+
211+
// Parse TIPS to wei
212+
const weiValue = blockchainProvider.parseTips("100");
213+
214+
// Format for display
215+
const displayValue = `${parseFloat(balance).toFixed(4)} TIPS`;
216+
217+
// Gassless swap
218+
const result = await dexService.executeGasslessSwap(userAddress, swapData);
219+
```
220+
221+
## 📚 Important Files
222+
223+
| File | Purpose |
224+
|------|---------|
225+
| `SETUP.md` | Complete setup and deployment guide |
226+
| `ARCHITECTURE.md` | System architecture, data flow, security |
227+
| `package.json` | Scripts and dependencies |
228+
| `.env.example` | Environment template with all variables |
229+
| `hardhat.config.js` | Blockchain configuration |
230+
| `config/production.js` | Production environment settings |
231+
232+
## ⚠️ What to Avoid
233+
234+
- ❌ Don't hardcode contract addresses - use environment variables
235+
- ❌ Don't display balances in ETH - use TIPS (18 decimals)
236+
- ❌ Don't let relayer balance get too low - needs TIPS to pay for users
237+
- ❌ Don't skip relayer tests - gassless transactions are core
238+
- ❌ Don't commit `.env` file - it contains secrets
239+
- ❌ Don't modify `artifacts/`, `cache/`, `.next/` - build outputs
240+
- ❌ Don't assume fixed gas prices - TIPS prices vary
241+
- ❌ Don't forget explorer indexing - transactions need to be searchable
242+
243+
## 📋 Example Development Tasks
244+
245+
- "Add a new ERC20 token and integrate into DEX"
246+
- "Create endpoint to show current relayer balance"
247+
- "Write test for gassless swap via TrustedForwarder"
248+
- "Implement rate limiting on relayer"
249+
- "Add token whitelist for DEX swaps"
250+
- "Monitor and alert when relayer balance is low"
251+
- "Update explorer to show TIPS gas fees"
252+
- "Create cron job for relayer maintenance"
253+
254+
## 🚢 Production Deployment
255+
256+
1. Review `SETUP.md` for complete deployment guide
257+
2. Run `bash scripts/production-checklist.sh` to verify readiness
258+
3. Run `bash scripts/deploy-all.sh` for production deployment
259+
4. Configure production domains (tipschain.sbs, dex.tipschain.sbs, scan.tipspay.org)
260+
5. Enable SSL/TLS on all domains
261+
6. Verify all API endpoints responding correctly
262+
7. Test gassless transactions end-to-end
263+
8. Monitor relayer balance and key metrics
264+
265+
## 📞 Support
266+
267+
- See `SETUP.md` for deployment walkthrough
268+
- See `ARCHITECTURE.md` for system design
269+
- Check `docs/api.md` for API documentation
270+
- Review `scripts/` for deployment examples
271+
272+
---
273+
274+
**TipsChain Ecosystem** - Fast, cheap, accessible blockchain with native TIPS gas token and gassless transactions.

0 commit comments

Comments
 (0)