Skip to content

Commit c76f29b

Browse files
authored
Merge pull request OFFER-HUB#568 from sedaceva2005-create/main
feat: contracts_overview
2 parents 93dcfbb + 99aead9 commit c76f29b

1 file changed

Lines changed: 248 additions & 1 deletion

File tree

docs/CONTRACTS_OVERVIEW.md

Lines changed: 248 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,36 @@ User → Publication Contract (publish project)
164164
→ Fee Manager (calculate fees)
165165
```
166166

167+
**Code Example:**
168+
```typescript
169+
// Publish a new project
170+
const publicationTx = await publicationContract.publish({
171+
title: "Website Development",
172+
description: "Build a modern React website",
173+
budget: 5000,
174+
deadline: "2024-02-01",
175+
category: "Web Development"
176+
});
177+
178+
// Deploy escrow contract
179+
const escrowAddress = await escrowFactory.deploy({
180+
projectId: publicationTx.projectId,
181+
clientAddress: userAddress,
182+
freelancerAddress: selectedFreelancer,
183+
totalAmount: 5000
184+
});
185+
186+
// Initialize escrow with milestones
187+
await escrowContract.initialize({
188+
escrowAddress,
189+
milestones: [
190+
{ id: "design", amount: 1500, description: "UI/UX Design" },
191+
{ id: "development", amount: 2500, description: "Frontend Development" },
192+
{ id: "testing", amount: 1000, description: "Testing & Deployment" }
193+
]
194+
});
195+
```
196+
167197
### 2. Payment Flow
168198
```
169199
Client → Escrow Contract (deposit funds)
@@ -172,6 +202,30 @@ Client → Escrow Contract (deposit funds)
172202
→ Freelancer (release funds)
173203
```
174204

205+
**Code Example:**
206+
```typescript
207+
// Client deposits funds
208+
await escrowContract.deposit({
209+
escrowAddress,
210+
amount: 5000,
211+
token: "USDC"
212+
});
213+
214+
// Fee manager calculates and collects fees
215+
const feeAmount = await feeManager.calculateFee({
216+
amount: 5000,
217+
userType: "premium",
218+
operation: "escrow_deposit"
219+
});
220+
221+
// Release funds for completed milestone
222+
await escrowContract.releaseFunds({
223+
escrowAddress,
224+
milestoneId: "design",
225+
freelancerAddress: freelancerAddress
226+
});
227+
```
228+
175229
### 3. Dispute Flow
176230
```
177231
Client/Freelancer → Dispute Contract (open dispute)
@@ -181,6 +235,33 @@ Client/Freelancer → Dispute Contract (open dispute)
181235
→ Fee Manager (collect dispute fees)
182236
```
183237

238+
**Code Example:**
239+
```typescript
240+
// Open a dispute
241+
const disputeId = await disputeContract.openDispute({
242+
escrowAddress,
243+
initiator: userAddress,
244+
reason: "Work quality not meeting requirements",
245+
evidence: ["ipfs://evidence1", "ipfs://evidence2"]
246+
});
247+
248+
// Submit additional evidence
249+
await disputeContract.submitEvidence({
250+
disputeId,
251+
evidence: "ipfs://additional_evidence",
252+
submitter: userAddress
253+
});
254+
255+
// Mediator resolves dispute
256+
await disputeContract.resolveDispute({
257+
disputeId,
258+
resolution: "partial_payment",
259+
freelancerAmount: 3000,
260+
clientRefund: 2000,
261+
mediatorAddress: mediatorAddress
262+
});
263+
```
264+
184265
### 4. Reputation Flow
185266
```
186267
Client/Freelancer → Rating Contract (submit rating)
@@ -240,6 +321,72 @@ Reputation NFT | ✓ | ✓ | ✗ | ✓
240321
Emergency | ✓ | ✗ | ✗ | ✓
241322
```
242323

324+
## API Reference
325+
326+
### User Registry Contract
327+
```typescript
328+
// User management
329+
registerUser(userData: UserData): Promise<TransactionResult>
330+
verifyUser(userId: string, level: VerificationLevel): Promise<boolean>
331+
blacklistUser(userId: string, reason: string): Promise<void>
332+
getUserStatus(userId: string): Promise<UserStatus>
333+
334+
// Admin functions
335+
setAdminRole(userId: string, role: AdminRole): Promise<void>
336+
bulkVerifyUsers(userIds: string[], level: VerificationLevel): Promise<void>
337+
```
338+
339+
### Escrow Contract
340+
```typescript
341+
// Payment management
342+
deposit(amount: number, token: string): Promise<TransactionResult>
343+
releaseFunds(milestoneId: string): Promise<TransactionResult>
344+
withdrawFunds(amount: number): Promise<TransactionResult>
345+
346+
// Milestone management
347+
createMilestone(milestone: MilestoneData): Promise<string>
348+
updateMilestone(milestoneId: string, updates: Partial<MilestoneData>): Promise<void>
349+
completeMilestone(milestoneId: string): Promise<void>
350+
351+
// Dispute integration
352+
openDispute(reason: string, evidence: string[]): Promise<string>
353+
```
354+
355+
### Escrow Factory Contract
356+
```typescript
357+
// Contract deployment
358+
deployEscrow(config: EscrowConfig): Promise<string>
359+
batchDeployEscrows(configs: EscrowConfig[]): Promise<string[]>
360+
361+
// Management
362+
getEscrowAddress(projectId: string): Promise<string>
363+
archiveEscrow(escrowAddress: string): Promise<void>
364+
getActiveEscrows(): Promise<string[]>
365+
```
366+
367+
### Dispute Resolution Contract
368+
```typescript
369+
// Dispute management
370+
openDispute(disputeData: DisputeData): Promise<string>
371+
submitEvidence(disputeId: string, evidence: string): Promise<void>
372+
resolveDispute(disputeId: string, resolution: DisputeResolution): Promise<void>
373+
374+
// Mediation
375+
assignMediator(disputeId: string, mediatorId: string): Promise<void>
376+
escalateToArbitration(disputeId: string): Promise<void>
377+
```
378+
379+
### Fee Manager Contract
380+
```typescript
381+
// Fee calculation
382+
calculateFee(amount: number, userType: UserType, operation: OperationType): Promise<number>
383+
collectFee(amount: number, userAddress: string): Promise<TransactionResult>
384+
385+
// Configuration
386+
setFeeRate(operation: OperationType, rate: number): Promise<void>
387+
setPremiumDiscount(discount: number): Promise<void>
388+
```
389+
243390
## Event System
244391

245392
### Cross-Contract Events
@@ -277,6 +424,83 @@ All contracts emit events that enable:
277424
9. Reputation NFT Contract
278425
```
279426

427+
**Deployment Code Example:**
428+
```typescript
429+
// Deploy contracts in correct order
430+
const deploymentOrder = [
431+
'UserRegistry',
432+
'FeeManager',
433+
'Emergency',
434+
'Escrow',
435+
'EscrowFactory',
436+
'DisputeResolution',
437+
'Publication',
438+
'Rating',
439+
'ReputationNFT'
440+
];
441+
442+
for (const contractName of deploymentOrder) {
443+
const contract = await deployContract(contractName, {
444+
network: 'testnet',
445+
gasLimit: 1000000
446+
});
447+
448+
console.log(`${contractName} deployed at: ${contract.address}`);
449+
450+
// Verify deployment
451+
await verifyContract(contract.address, contractName);
452+
}
453+
```
454+
455+
## Error Handling
456+
457+
### Common Error Scenarios
458+
```typescript
459+
// Escrow contract errors
460+
try {
461+
await escrowContract.releaseFunds(milestoneId);
462+
} catch (error) {
463+
switch (error.code) {
464+
case 'INSUFFICIENT_FUNDS':
465+
console.error('Not enough funds in escrow');
466+
break;
467+
case 'DISPUTE_ACTIVE':
468+
console.error('Cannot release funds during active dispute');
469+
break;
470+
case 'MILESTONE_NOT_COMPLETE':
471+
console.error('Milestone must be completed before release');
472+
break;
473+
case 'UNAUTHORIZED':
474+
console.error('Only authorized parties can release funds');
475+
break;
476+
default:
477+
console.error('Unknown error:', error.message);
478+
}
479+
}
480+
481+
// User registry errors
482+
try {
483+
await userRegistry.verifyUser(userId, 'premium');
484+
} catch (error) {
485+
if (error.code === 'USER_NOT_FOUND') {
486+
console.error('User does not exist');
487+
} else if (error.code === 'INSUFFICIENT_PERMISSIONS') {
488+
console.error('Admin permissions required');
489+
}
490+
}
491+
492+
// Dispute resolution errors
493+
try {
494+
await disputeContract.resolveDispute(disputeId, resolution);
495+
} catch (error) {
496+
if (error.code === 'DISPUTE_NOT_FOUND') {
497+
console.error('Dispute does not exist');
498+
} else if (error.code === 'DISPUTE_ALREADY_RESOLVED') {
499+
console.error('Dispute has already been resolved');
500+
}
501+
}
502+
```
503+
280504
## Testing Strategy
281505

282506
### Integration Testing
@@ -334,4 +558,27 @@ Each contract is designed to work independently while integrating seamlessly wit
334558

335559
---
336560

337-
For detailed information about individual contracts, refer to their specific documentation files in the `/docs` folder.
561+
## Related Documentation
562+
563+
For detailed information about individual contracts, refer to their specific documentation files:
564+
565+
### Core Infrastructure
566+
- **[User Registry Contract](./USER_REGISTRY_CONTRACT.md)** - User verification and access control
567+
- **[Emergency Contract](./EMERGENCY_CONTRACT.md)** - Platform safety and crisis management
568+
- **[Fee Manager Contract](./FEE_MANAGER_CONTRACT.md)** - Centralized fee calculation and collection
569+
570+
### Payment System
571+
- **[Escrow Contract](./ESCROW_CONTRACT.md)** - Secure payment management with milestone support
572+
- **[Escrow Factory](./ESCROW_FACTORY.md)** - Standardized deployment and batch management
573+
574+
### Dispute & Content
575+
- **[Dispute Resolution Contract](./DISPUTE_CONTRACT.md)** - Two-tier mediation and arbitration system
576+
- **[Publication Contract](./PUBLICATION_CONTRACT.md)** - On-chain registry for services and projects
577+
578+
### Reputation System
579+
- **[Rating System Integration](./RATING_SYSTEM_INTEGRATION.md)** - User rating and feedback system
580+
- **[Reputation NFT Contract](./REPUTATION_NFT_CONTRACT.md)** - Achievement-based NFT rewards
581+
582+
### Implementation Guides
583+
- **[Freelancer Profile Implementation](./FREELANCER_PROFILE_IMPLEMENTATION.md)** - Frontend profile system integration
584+
- **[Contributors Guideline](./CONTRIBUTORS_GUIDELINE.md)** - Development and contribution guidelines

0 commit comments

Comments
 (0)