diff --git a/PiRC1/4-allocation/4-allocation design 1.md b/PiRC1/4-allocation/4-allocation design 1.md index f5620c2f..04c85c2c 100644 --- a/PiRC1/4-allocation/4-allocation design 1.md +++ b/PiRC1/4-allocation/4-allocation design 1.md @@ -151,4 +151,56 @@ xychart-beta - Starting LP spot price is $p_{list} = \frac{C}{T}$ - Highly engaged participants pay $0.909p_{list}$. Medimum engaged participants pay $0.952p_{list}$. Least engaged participants pay $p_{list}$ +--- + +## 4.X Allocation Invariants and Consistency Conditions + +To preserve economic integrity and deterministic behavior of the allocation model, +the following invariants must hold: + +### (1) Emission Conservation + +Total tokens distributed to participants must equal: + +Tpurchase + Tengage + +Formally: + +Σ_i (t_i^base + t_i^engage) = Tpurchase + Tengage + +--- + +### (2) Liquidity Conservation + +All committed Pi must enter the Liquidity Pool: + +Σ_i c_i = C + +The LP must be initialized strictly with: + +(C, Tliquidity) + +No intermediate swap operation is allowed during initialization. + +--- + +### (3) Monotonicity + +For any two participants i and j within the same engagement tier: + +If c_i > c_j ⇒ t_i^base > t_j^base +If c_i > c_j ⇒ t_i^engage ≥ t_j^engage + +--- + +### (4) Determinism + +Given identical inputs: + +{c_i}, engagement ranks {r_i}, and fixed parameters, + +the allocation outcome must be uniquely determined. + +No stochastic or discretionary adjustment may alter final token amounts. + Next: [`5-tge-state`](<../5-tge-state/5-tge-state design 1.md>) diff --git a/PiRC1/6-adaptive-proof-of-contribution.md b/PiRC1/6-adaptive-proof-of-contribution.md new file mode 100644 index 00000000..97caedd0 --- /dev/null +++ b/PiRC1/6-adaptive-proof-of-contribution.md @@ -0,0 +1,166 @@ +# 6 — Adaptive Proof of Contribution (APoC) + +## Overview +Adaptive Proof of Contribution (APoC) is an AI-assisted reward allocation layer designed to complement the existing ecosystem token allocation models. + +Instead of distributing tokens purely based on activity quantity, APoC evaluates **quality, authenticity, economic impact, and trustworthiness** of contributions. + +Goal: +Transform token distribution from "activity mining" → "value mining". + +--- + +## Problem Addressed + +Traditional Web3 incentive models suffer from: + +- Bot farming +- Sybil attacks +- Engagement spam +- Liquidity extraction behavior +- Short-term participation incentives + +Even activity-based models can be gamed if quantity > quality. + +APoC introduces a dynamic scoring layer to ensure: +> Tokens flow to contributors who create real economic value. + +--- + +## Core Concept + +Each participant receives a dynamic **Contribution Score (CS)**: + +CS = Activity × Impact × Trust × NetworkEffect × Integrity + +Reward emission is proportional to CS instead of raw activity. + +--- + +## Contribution Score Components + +### 1. Activity Score (A) +Measures measurable actions: +- Transactions +- Purchases +- Listings +- Development commits +- Service usage + +Normalized logarithmically to prevent spam inflation. + +--- + +### 2. Impact Score (I) +Measures economic usefulness: +- User retention caused +- Volume generated +- Repeat usage +- External adoption + +--- + +### 3. Trust Score (T) +Derived from: +- Account age +- KYC confidence +- Historical behavior +- Dispute history +- Counterparty feedback + +Non-transferable and slowly changing. + +--- + +### 4. Network Effect Score (N) +Rewards users who bring valuable participants: +- Active referrals +- Builder ecosystems +- Marketplace creation + +Not based on count — based on downstream contribution quality. + +--- + +### 5. Integrity Score (G) +AI fraud detection output: +- Bot probability +- Sybil clustering detection +- Abnormal interaction patterns +- Velocity anomalies + +If flagged → reward decay multiplier applies. + +--- + +## Final Formula + +RewardShare = CS_user / Σ(CS_all_users) + +TokenReward = DailyEmission × RewardShare + +--- + +## Emission Dampening +To prevent reward draining: + +If ecosystem velocity spikes: +EmissionRate decreases + +If ecosystem utility increases: +EmissionRate increases + +--- + +## Anti-Manipulation Design + +| Attack Type | Mitigation | +|-----------|------| +| Bot farms | Behavioral clustering AI | +| Sybil accounts | Graph identity analysis | +| Wash trading | Economic circularity detection | +| Spam actions | Log normalization | +| Referral abuse | Downstream contribution weighting | + +--- + +## Architecture + +Client Activity → App Server → AI Scoring Engine → Oracle → Smart Contract + +AI does NOT distribute tokens. +AI only produces a signed Contribution Score. + +Smart contract verifies signature and releases rewards trustlessly. + +--- + +## Smart Contract Pseudocode + +```solidity +struct Contribution { + uint256 score; + uint256 timestamp; +} + +mapping(address => Contribution) public contributions; + +function submitScore( + address user, + uint256 score, + bytes calldata oracleSignature +) external { + + require(verifyOracle(user, score, oracleSignature), "Invalid oracle"); + + contributions[user] = Contribution(score, block.timestamp); +} + +function claimReward() external { + + uint256 reward = calculateReward(msg.sender); + + require(reward > 0, "No reward"); + + token.mint(msg.sender, reward); +} diff --git a/PiRC2_Implementation_Pack/PROPOSAL_V2.md b/PiRC2_Implementation_Pack/PROPOSAL_V2.md new file mode 100644 index 00000000..36d68bb5 --- /dev/null +++ b/PiRC2_Implementation_Pack/PROPOSAL_V2.md @@ -0,0 +1,14 @@ +# PiRC2 & PiRC-45: Integrated Economic & Technical Framework + +## 1. Mathematical Specification (WCF) +The Working Capital Factor (WCF) is calculated as: +$$WCF_{t} = (WCF_{t-1} \cdot e^{-\lambda \Delta t}) + \alpha \sum \ln(V_i + 1)$$ + +## 2. Technical Scope +- **PiRC-45:** Standardizes Metadata Schema to resolve Issue #16. +- **PiRC2:** Introduces the "Justice Engine" on Soroban Smart Contracts. + +## 3. Threat Model & Mitigations +- **Sybil Attacks:** Mitigated via PoV (Proof of Value) using PiRC-45 metadata. +- **State Bloat:** Mitigated via Lazy State Initialization. + diff --git a/PiRC2_Implementation_Pack/PiRC2Connect.js b/PiRC2_Implementation_Pack/PiRC2Connect.js new file mode 100644 index 00000000..7d893919 --- /dev/null +++ b/PiRC2_Implementation_Pack/PiRC2Connect.js @@ -0,0 +1,35 @@ +/** + * PiRC2 Connect SDK v1.0 + * Unified interface for Retail, Gaming, and Services. + */ +class PiRC2Connect { + constructor(apiKey, sector) { + this.apiKey = apiKey; + this.sector = sector; + this.protocolFee = 0.005; // 0.5% fixed fee + } + + async createPayment(amount, description) { + const feeAmount = amount * this.protocolFee; + console.log(`[PiRC2-${this.sector}] Initiating Payment...`); + + const txPayload = { + total: amount, + net_to_merchant: amount - feeAmount, + protocol_fee: feeAmount, + metadata: { + desc: description, + pirc2_compliant: true, + timestamp: Date.now() + } + }; + + // Logic to interface with Pi Wallet goes here + return txPayload; + } +} + +// Usage Example: +// const retailApp = new PiRC2Connect("STORE_001", "Retail"); +// retailApp.createPayment(100, "Coffee & Sandwich"); + diff --git a/PiRC2_Implementation_Pack/PiRC2JusticeEngine.sol b/PiRC2_Implementation_Pack/PiRC2JusticeEngine.sol new file mode 100644 index 00000000..66535b7b --- /dev/null +++ b/PiRC2_Implementation_Pack/PiRC2JusticeEngine.sol @@ -0,0 +1,37 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; + +/** + * @title PiRC2 Justice Engine + * @author Muhammad Kamel Qadah + * @notice Protects Mined Pi by applying the 10,000,000:1 Weighted Contribution Factor. + */ +contract PiRC2JusticeEngine { + // Constants for WCF (Weighted Contribution Factor) + uint256 public constant W_MINED = 10**7; // Weight: 1.0 (internal precision) + uint256 public constant W_EXTERNAL = 1; // Weight: 0.0000001 + + struct PioneerProfile { + uint256 minedBalance; // Captured from Mainnet Snapshot + uint256 externalBalance; // Bought from exchanges + uint256 engagementScore; // Bonus for real-world usage + } + + mapping(address => PioneerProfile) public registry; + uint256 public totalGlobalPower; + + // Updates the power (L_eff) of a wallet + function getEffectivePower(address _pioneer) public view returns (uint256) { + PioneerProfile memory p = registry[_pioneer]; + // Formula: L_eff = (Mined * 10,000,000) + (External * 1) + uint256 basePower = (p.minedBalance * W_MINED) + (p.externalBalance * W_EXTERNAL); + + if (p.engagementScore > 0) { + return basePower + (basePower * p.engagementScore / 100); + } + return basePower; + } + + // Records fee contribution to the global pool + receive() external payable {} +} diff --git a/PiRC2_Implementation_Pack/PiRC2Metadata.json b/PiRC2_Implementation_Pack/PiRC2Metadata.json new file mode 100644 index 00000000..78dac14d --- /dev/null +++ b/PiRC2_Implementation_Pack/PiRC2Metadata.json @@ -0,0 +1,21 @@ +{ + "protocol": "PiRC2", + "version": "2.0", + "asset_classification": { + "type": "Mined_Pi", + "wcf_multiplier": 10000000, + "liquidity_status": "Locked_Escrow", + "provenance": "Original_Mining_Phase" + }, + "utility_sectors": [ + "Retail", + "Gaming", + "Advertising", + "RealEstate" + ], + "compliance": { + "product_first": true, + "zero_inflation": true + } +} + diff --git a/PiRC2_Implementation_Pack/PiRC2Simulator.py b/PiRC2_Implementation_Pack/PiRC2Simulator.py new file mode 100644 index 00000000..8c2448cb --- /dev/null +++ b/PiRC2_Implementation_Pack/PiRC2Simulator.py @@ -0,0 +1,26 @@ +import math + +class PiRC2Economy: + def __init__(self, initial_tvl=0, fee_rate=0.005): + self.tvl = initial_tvl + self.fee_rate = fee_rate + + def simulate_growth(self, daily_volume, days=365): + print(f"{'Day':<10} | {'Daily Volume (Pi)':<20} | {'Total TVL (Pi)':<20}") + print("-" * 55) + + current_volume = daily_volume + for day in range(1, days + 1): + fees = current_volume * self.fee_rate + self.tvl += fees + + if day % 30 == 0: # Print update every month + print(f"{day:<10} | {current_volume:<20,.2f} | {self.tvl:<20,.2f}") + + # 1% organic growth in daily usage due to PiRC2 adoption + current_volume *= 1.01 + +# Example Run: Start with 1 Million Pi daily transaction volume +pirc2 = PiRC2Economy() +pirc2.simulate_growth(daily_volume=1000000) + diff --git a/PiRC2_Implementation_Pack/README.md b/PiRC2_Implementation_Pack/README.md new file mode 100644 index 00000000..388ee943 --- /dev/null +++ b/PiRC2_Implementation_Pack/README.md @@ -0,0 +1,90 @@ +ض.md +PiRC-45: Standardized Transaction Metadata & Interoperability Protocol +📌 Overview +PiRC-45 introduces a unified framework for transaction metadata handling within the Pi Network ecosystem. This standard resolves long-standing inconsistencies in dApp-to-Wallet communication (Issue #16) and adheres to the structural governance defined in PR #2. +By implementing this protocol, developers ensure their applications are Mainnet-ready, secure, and fully compatible with the Pi Browser's latest security layers. +🚀 Key Benefits + * Zero-Ambiguity Transactions: Eliminates "Unknown Transaction" errors in the Pi Wallet. + * Integrity Verification: Built-in cryptographic checksums to prevent payload tampering. + * Developer Efficiency: Standardized error codes and response schemas for faster debugging. + * Scalability: Stateless validation logic designed for high-frequency micro-payments. +🛠 Technical Specification +1. Unified Metadata Schema +All payment requests must now include the metadata object following this JSON structure: +{ + "pirc_version": "45.1", + "app_id": "YOUR_APP_ID", + "transaction_context": { + "type": "goods_and_services", + "memo_id": "unique_identifier_string", + "integrity_hash": "sha256_checksum_of_payload" + }, + "callback_config": { + "url": "https://api.yourdomain.com/pi-callback", + "retry_policy": "exponential_backoff" + } +} + +2. Validation Rules (Compliance with #16) +To pass the PiRC-45 validation layer, the following conditions must be met: + * memo_id: Must be a non-empty string (max 128 chars). + * integrity_hash: Must be generated using the SHA-256 algorithm combining the amount, recipient, and app_id. + * pirc_version: Must match the current supported protocol version. +💻 Implementation Guide +Step 1: Install the Validation Hook +Ensure your backend or smart contract interface includes the PiRC-45 validation logic: +// Example: Validating metadata before initiating payment +const validatePiRC45 = (metadata) => { + if (metadata.pirc_version !== "45.1") { + throw new Error("Unsupported PiRC Version. Please update to PiRC-45."); + } + // Additional logic for checksum verification + return true; +}; + +Step 2: Update Payment Call +When calling the Pi.createPayment() function, inject the compliant metadata object: +Pi.createPayment({ + amount: 3.14, + memo: "Order #9982", + metadata: pirc45_compliant_object, // The object defined in Section 1 +}, { + onReadyForServerApproval: (paymentId) => { /* ... */ }, + onReadyForServerCompletion: (paymentId, txid) => { /* ... */ }, + onCancel: (paymentId) => { /* ... */ }, + onError: (error, payment) => { /* ... */ }, +}); + +⚠️ Error Handling & Troubleshooting +| Error Code | Meaning | Resolution | +|---|---|---| +| ERR_PIRC45_VERSION_MISMATCH | Outdated protocol version. | Update to the latest PiRC-45 SDK. | +| ERR_PIRC45_INTEGRITY_FAIL | Metadata hash does not match payload. | Ensure no fields were modified after hashing. | +| ERR_PIRC45_CONTEXT_MISSING | Required field transaction_context is null. | Verify your JSON construction. | +🤝 Contribution & Standards +This documentation is part of the PiRC (Pi Request for Comments) initiative. To propose changes, please reference PR #2 for formatting guidelines. + * Lead Contributor: [Ze0ro99] + * References: [Issue #16], [PR #45], [PR #2] +Final Pro-Tip for Submission: +When you post this on GitHub, make sure to link the text [Issue #16] and [PR #2] to their respective URLs so the maintainers can navigate easily. + +# PiRC Unified Standards Repository + +## Overview +This repository contains the official specifications for **PiRC-45** and **PiRC2**. + +### Quick Start for Developers +1. **Compliance:** All dApp transactions must follow the JSON schema in `/schemas/pirc45_standard.json`. +2. **Implementation:** + ```javascript + // Example Metadata Generation + const metadata = { + version: "45.1", + app_id: "your_app_name", + payload: { + memo_id: "order_123", + integrity_hash: "sha256_hash_here", + type: "goods" + } + }; + diff --git a/PiRC2_Implementation_Pack/schemas/pirc45_standard.json b/PiRC2_Implementation_Pack/schemas/pirc45_standard.json new file mode 100644 index 00000000..41e3ffba --- /dev/null +++ b/PiRC2_Implementation_Pack/schemas/pirc45_standard.json @@ -0,0 +1,20 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "PiRC-45 Transaction Metadata", + "type": "object", + "properties": { + "version": { "type": "string", "enum": ["45.1"] }, + "app_id": { "type": "string" }, + "payload": { + "type": "object", + "properties": { + "memo_id": { "type": "string", "maxLength": 128 }, + "integrity_hash": { "type": "string", "pattern": "^[a-fA-F0-9]{64}$" }, + "type": { "type": "string", "enum": ["goods", "services", "transfer"] } + }, + "required": ["memo_id", "integrity_hash", "type"] + } + }, + "required": ["version", "app_id", "payload"] +} +