diff --git a/economics/ai_central_bank_enhanced.py b/economics/ai_central_bank_enhanced.py new file mode 100644 index 00000000..62d3ce89 --- /dev/null +++ b/economics/ai_central_bank_enhanced.py @@ -0,0 +1,22 @@ + +def stabilize_ippr(current_ippr: float, supply: int, target: int = 314_000_000) -> float: + error = (target - supply) / target + updated = current_ippr * (1 + 0.05 * error) + return max(0.0, updated) + + +def run_policy_path(start_ippr=0.02, start_supply=300_000_000, years=10): + ippr = start_ippr + supply = start_supply + history = [] + + for year in range(1, years + 1): + ippr = stabilize_ippr(ippr, supply) + supply = int(supply * (1 + ippr * 0.2)) + history.append({"year": year, "ippr": round(ippr, 6), "supply": supply}) + + return history + + +if __name__ == "__main__": + print(run_policy_path()) diff --git a/economics/ai_economic_stabilizer.py b/economics/ai_economic_stabilizer.py new file mode 100644 index 00000000..a4e6c090 --- /dev/null +++ b/economics/ai_economic_stabilizer.py @@ -0,0 +1,40 @@ +import numpy as np + +class EconomicStabilizer: + + def __init__(self): + self.target_liquidity = 50 + self.reward_multiplier = 1.0 + + def update(self, liquidity, transaction_volume): + + if liquidity < self.target_liquidity: + self.reward_multiplier *= 1.05 + + elif liquidity > self.target_liquidity * 1.5: + self.reward_multiplier *= 0.95 + + if transaction_volume > 1000: + self.reward_multiplier *= 0.98 + + return self.reward_multiplier + + +def simulate(): + + stabilizer = EconomicStabilizer() + + liquidity_levels = np.random.normal(50, 10, 100) + volumes = np.random.normal(800, 200, 100) + + multipliers = [] + + for l, v in zip(liquidity_levels, volumes): + multipliers.append(stabilizer.update(l, v)) + + return multipliers + + +if __name__ == "__main__": + results = simulate() + print("Simulation multipliers:", results[:10]) diff --git a/economics/ai_human_economy_simulator.py b/economics/ai_human_economy_simulator.py new file mode 100644 index 00000000..08de5633 --- /dev/null +++ b/economics/ai_human_economy_simulator.py @@ -0,0 +1,113 @@ +""" +AI + Human Economy Simulator +Models future Pi ecosystem workforce economy +""" + +import random +import statistics +from dataclasses import dataclass, field +from typing import List + + +@dataclass +class Task: + difficulty: float + ai_accuracy: float + reward: float + + +@dataclass +class HumanWorker: + skill: float + tasks_completed: int = 0 + earnings: float = 0.0 + + +@dataclass +class AISystem: + accuracy: float + + +@dataclass +class EconomyState: + humans: List[HumanWorker] + ai: AISystem + tasks: List[Task] + reward_pool: float = 0 + + +class HumanAIEconomySimulator: + + def __init__(self, human_count=1000): + humans = [ + HumanWorker(skill=random.uniform(0.4, 1.0)) + for _ in range(human_count) + ] + + self.state = EconomyState( + humans=humans, + ai=AISystem(accuracy=0.75), + tasks=[] + ) + + def generate_tasks(self, n=500): + tasks = [] + for _ in range(n): + difficulty = random.uniform(0.2, 1.0) + reward = difficulty * random.uniform(0.5, 2.0) + + tasks.append(Task( + difficulty=difficulty, + ai_accuracy=self.state.ai.accuracy, + reward=reward + )) + + self.state.tasks = tasks + + def ai_attempt(self, task): + success = random.random() < (self.state.ai.accuracy - task.difficulty * 0.3) + return success + + def human_attempt(self, worker, task): + probability = worker.skill - task.difficulty * 0.4 + success = random.random() < probability + + if success: + worker.tasks_completed += 1 + worker.earnings += task.reward + self.state.reward_pool += task.reward + + return success + + def run_round(self): + + for task in self.state.tasks: + + if self.ai_attempt(task): + continue + + worker = random.choice(self.state.humans) + self.human_attempt(worker, task) + + def summary(self): + + earnings = [h.earnings for h in self.state.humans] + + return { + "total_rewards": sum(earnings), + "avg_worker_income": statistics.mean(earnings), + "median_worker_income": statistics.median(earnings), + "top_worker": max(earnings), + "tasks_completed": sum(h.tasks_completed for h in self.state.humans) + } + + +if __name__ == "__main__": + + sim = HumanAIEconomySimulator() + + for _ in range(30): + sim.generate_tasks(500) + sim.run_round() + + print(sim.summary()) diff --git a/economics/autonomous_pi_economy.py b/economics/autonomous_pi_economy.py new file mode 100644 index 00000000..a66c9da7 --- /dev/null +++ b/economics/autonomous_pi_economy.py @@ -0,0 +1,28 @@ +import random + +years = 10 + +supply = 1000000000 +liquidity = 50000000 +activity = 100000 + +for year in range(1, years+1): + + activity_growth = random.uniform(0.05,0.20) + liquidity_growth = random.uniform(0.03,0.15) + + activity *= (1 + activity_growth) + liquidity *= (1 + liquidity_growth) + + fees = activity * 0.01 + rewards = fees * 1.2 + + supply += rewards + + print("Year:",year) + print("Supply:",int(supply)) + print("Liquidity:",int(liquidity)) + print("Activity:",int(activity)) + print("Fees:",int(fees)) + print("Rewards:",int(rewards)) + print("--------------------") diff --git a/economics/economic_model.md b/economics/economic_model.md new file mode 100644 index 00000000..7cee78ab --- /dev/null +++ b/economics/economic_model.md @@ -0,0 +1,60 @@ +# PiRC Economic Model + +## Overview + +The PiRC economic model defines the relationship between token supply, +liquidity growth, economic activity, and reward distribution. + +The objective is to create a sustainable economic loop within the Pi ecosystem. + +Core variables: + +S = token supply +L = liquidity +A = economic activity +F = protocol fees +R = rewards distributed + +The PiRC loop can be expressed as: + +S → L → A → F → R → S + +This reflexive loop ensures that reward issuance is linked to real economic activity. + +--- + +## Economic Flow + +1 Pioneer Supply increases available tokens. + +2 Liquidity providers deposit tokens into liquidity pools. + +3 Economic activity generates transaction fees. + +4 Fees are partially routed to the treasury. + +5 Rewards are distributed to participants. + +--- + +## Economic Stability + +To prevent inflation, the protocol introduces several constraints: + +reward_emission ≤ fee_generation × emission_multiplier + +Where: + +emission_multiplier ∈ [0.5 , 2.0] + +These bounds ensure that reward emissions remain tied to real activity. + +--- + +## Long-Term Objective + +The model attempts to stabilize the ecosystem by aligning: + +• token incentives +• liquidity incentives +• user participation diff --git a/economics/global_pi_economy_simulator.py b/economics/global_pi_economy_simulator.py new file mode 100644 index 00000000..10596dbb --- /dev/null +++ b/economics/global_pi_economy_simulator.py @@ -0,0 +1,68 @@ +import random +from dataclasses import dataclass + +@dataclass +class EconomyState: + + pioneers: int + apps: int + transactions: int + circulating_pi: float + price: float + + +class GlobalPiEconomySimulator: + + def __init__(self): + + self.state = EconomyState( + pioneers=17000000, + apps=200, + transactions=1000000, + circulating_pi=2000000000, + price=0.5 + ) + + def simulate_growth(self): + + new_users = int(self.state.pioneers * random.uniform(0.01, 0.05)) + new_apps = int(self.state.apps * random.uniform(0.02, 0.1)) + + self.state.pioneers += new_users + self.state.apps += new_apps + + def simulate_activity(self): + + self.state.transactions = int( + self.state.pioneers * + random.uniform(0.05, 0.3) + ) + + def price_model(self): + + demand = self.state.transactions * 0.00001 + supply = self.state.circulating_pi + + self.state.price = demand / supply * 100000 + + def run_year(self): + + self.simulate_growth() + self.simulate_activity() + self.price_model() + + def summary(self): + + return vars(self.state) + + +if __name__ == "__main__": + + sim = GlobalPiEconomySimulator() + + for year in range(10): + + sim.run_year() + + print("YEAR", year) + print(sim.summary()) diff --git a/economics/liquidity_model.md b/economics/liquidity_model.md new file mode 100644 index 00000000..88039d3d --- /dev/null +++ b/economics/liquidity_model.md @@ -0,0 +1,26 @@ +# Liquidity Model + +## Liquidity Objective + +Liquidity stabilizes token markets and supports trading activity. + +Liquidity growth function: + +Lt+1 = Lt + αD − βW + +Where: + +D = deposits +W = withdrawals +α = liquidity growth factor +β = liquidity decay factor + +--- + +## Liquidity Incentives + +Liquidity providers receive rewards proportional to: + +• deposited capital +• duration of liquidity provision +• trading volume supported diff --git a/economics/merchant_pricing_sim.py b/economics/merchant_pricing_sim.py new file mode 100644 index 00000000..6fb10c15 --- /dev/null +++ b/economics/merchant_pricing_sim.py @@ -0,0 +1,20 @@ +import statistics + + +def stable_price(kraken, kucoin, binance, phi=0.05): + median_price = statistics.median([kraken, kucoin, binance]) + return round(median_price * (1 + phi), 6) + + +def simulate_quotes(quotes): + computed = [stable_price(k, ku, b) for k, ku, b in quotes] + return { + "samples": len(computed), + "avg_stable_price": round(sum(computed) / len(computed), 6) if computed else 0, + "latest_stable_price": computed[-1] if computed else 0, + } + + +if __name__ == "__main__": + sample_quotes = [(0.81, 0.79, 0.83), (0.84, 0.82, 0.85), (0.88, 0.87, 0.89)] + print(simulate_quotes(sample_quotes)) diff --git a/economics/network_growth_ai_model.py b/economics/network_growth_ai_model.py new file mode 100644 index 00000000..a9c7e095 --- /dev/null +++ b/economics/network_growth_ai_model.py @@ -0,0 +1,48 @@ +import numpy as np +from sklearn.linear_model import LinearRegression + + +class NetworkGrowthAIModel: + + def __init__(self): + + self.model = LinearRegression() + + def generate_training_data(self): + + users = [] + activity = [] + + for year in range(1, 15): + + user_count = year * 2000000 + np.random.randint(100000) + + tx_activity = user_count * np.random.uniform(0.05, 0.2) + + users.append([year]) + activity.append(tx_activity) + + return np.array(users), np.array(activity) + + def train(self): + + X, y = self.generate_training_data() + + self.model.fit(X, y) + + def predict_activity(self, year): + + prediction = self.model.predict(np.array([[year]])) + + return float(prediction[0]) + + +if __name__ == "__main__": + + ai = NetworkGrowthAIModel() + + ai.train() + + for year in range(15, 25): + + print("Year", year, "Predicted Activity:", ai.predict_activity(year)) diff --git a/economics/pi_economic_equilibrium_model.py b/economics/pi_economic_equilibrium_model.py new file mode 100644 index 00000000..11f6628b --- /dev/null +++ b/economics/pi_economic_equilibrium_model.py @@ -0,0 +1,222 @@ +""" +Pi Economic Equilibrium Model + +Research-grade economic equilibrium calculator for a utility blockchain. + +Model components: +- supply vs demand +- velocity of money +- network effect +- liquidity multiplier +- utility demand from applications + +Inspired by macro monetary equation: +MV = PQ + +Where: +M = money supply +V = velocity +P = price +Q = real transaction output +""" + +from dataclasses import dataclass +import math +import random + + +# -------------------------------------- +# State +# -------------------------------------- + +@dataclass +class EconomicState: + + pioneers: int + apps: int + + circulating_supply: float + locked_supply: float + + liquidity: float + + velocity: float + + transaction_volume: float + + price: float + + +# -------------------------------------- +# Model +# -------------------------------------- + +class PiEconomicEquilibriumModel: + + def __init__(self): + + self.state = EconomicState( + + pioneers=17_700_000, + apps=300, + + circulating_supply=3_000_000_000, + locked_supply=7_000_000_000, + + liquidity=100_000_000, + + velocity=2.0, + + transaction_volume=0, + + price=0.5 + ) + + + # ---------------------------------- + # Utility demand + # ---------------------------------- + + def utility_demand(self): + + app_factor = math.log(self.state.apps + 1) + + user_factor = math.log(self.state.pioneers) + + demand = app_factor * user_factor * 100000 + + return demand + + + # ---------------------------------- + # Network effect + # ---------------------------------- + + def network_effect(self): + + # Metcalfe-style scaling + + users = self.state.pioneers + + effect = math.sqrt(users) + + return effect + + + # ---------------------------------- + # Velocity update + # ---------------------------------- + + def update_velocity(self): + + utility = self.utility_demand() + + self.state.velocity = 1 + utility / 1_000_000 + + + # ---------------------------------- + # Transaction volume + # ---------------------------------- + + def update_transactions(self): + + demand = self.utility_demand() + + self.state.transaction_volume = demand * self.state.velocity + + + # ---------------------------------- + # Liquidity multiplier + # ---------------------------------- + + def liquidity_multiplier(self): + + liquidity_ratio = self.state.liquidity / self.state.circulating_supply + + multiplier = 1 + liquidity_ratio * 5 + + return multiplier + + + # ---------------------------------- + # Equilibrium price + # ---------------------------------- + + def compute_equilibrium_price(self): + + self.update_velocity() + + self.update_transactions() + + demand = self.state.transaction_volume + + supply = self.state.circulating_supply + + base_price = demand / supply + + network_multiplier = self.network_effect() / 1000 + + liquidity_multiplier = self.liquidity_multiplier() + + price = base_price * network_multiplier * liquidity_multiplier + + self.state.price = price + + return price + + + # ---------------------------------- + # Growth simulation + # ---------------------------------- + + def simulate_growth(self): + + new_users = int(self.state.pioneers * random.uniform(0.03, 0.12)) + + self.state.pioneers += new_users + + new_apps = int(self.state.apps * random.uniform(0.05, 0.20)) + + self.state.apps += new_apps + + liquidity_growth = self.state.liquidity * random.uniform(0.02, 0.10) + + self.state.liquidity += liquidity_growth + + + # ---------------------------------- + # Year step + # ---------------------------------- + + def run_year(self): + + self.simulate_growth() + + price = self.compute_equilibrium_price() + + return { + + "pioneers": self.state.pioneers, + "apps": self.state.apps, + "velocity": round(self.state.velocity, 3), + "transaction_volume": round(self.state.transaction_volume, 2), + "liquidity": round(self.state.liquidity, 2), + "price_equilibrium": round(price, 4) + } + + +# -------------------------------------- +# Run Simulation +# -------------------------------------- + +if __name__ == "__main__": + + model = PiEconomicEquilibriumModel() + + YEARS = 30 + + for year in range(YEARS): + + result = model.run_year() + + print("Year", year + 1, result) diff --git a/economics/pi_full_ecosystem_simulator.py b/economics/pi_full_ecosystem_simulator.py new file mode 100644 index 00000000..5f68feda --- /dev/null +++ b/economics/pi_full_ecosystem_simulator.py @@ -0,0 +1,209 @@ +""" +Pi Full Ecosystem Simulator + +Simulates long-term Pi Network economy: +- user growth +- app ecosystem expansion +- token liquidity +- human task economy +- price discovery + +Designed for research / macro modeling. +""" + +import random +from dataclasses import dataclass + + +# ----------------------------- +# State Objects +# ----------------------------- + +@dataclass +class NetworkState: + + year: int + pioneers: int + apps: int + transactions: int + + circulating_pi: float + locked_pi: float + + dex_liquidity: float + human_task_rewards: float + + price: float + + +# ----------------------------- +# Simulator +# ----------------------------- + +class PiFullEcosystemSimulator: + + def __init__(self): + + self.state = NetworkState( + + year=0, + + pioneers=17_700_000, + apps=300, + transactions=2_000_000, + + circulating_pi=3_000_000_000, + locked_pi=7_000_000_000, + + dex_liquidity=100_000_000, + human_task_rewards=0, + + price=0.5 + ) + + # ------------------------- + # Network Growth + # ------------------------- + + def simulate_user_growth(self): + + growth_rate = random.uniform(0.03, 0.12) + + new_users = int(self.state.pioneers * growth_rate) + + self.state.pioneers += new_users + + + # ------------------------- + # App Ecosystem Growth + # ------------------------- + + def simulate_app_growth(self): + + growth = int(self.state.apps * random.uniform(0.05, 0.25)) + + self.state.apps += growth + + + # ------------------------- + # Activity + # ------------------------- + + def simulate_transactions(self): + + tx_per_user = random.uniform(0.1, 0.6) + + self.state.transactions = int( + self.state.pioneers * tx_per_user + ) + + + # ------------------------- + # Human Task Economy + # ------------------------- + + def simulate_human_tasks(self): + + tasks = int(self.state.pioneers * random.uniform(0.01, 0.05)) + + reward = tasks * random.uniform(0.02, 0.08) + + self.state.human_task_rewards += reward + + self.state.circulating_pi += reward + + + # ------------------------- + # DEX Liquidity + # ------------------------- + + def simulate_dex_liquidity(self): + + new_liquidity = self.state.transactions * random.uniform(0.001, 0.01) + + self.state.dex_liquidity += new_liquidity + + + # ------------------------- + # Token Locking + # ------------------------- + + def simulate_token_locking(self): + + lock_rate = random.uniform(0.01, 0.04) + + locked = self.state.circulating_pi * lock_rate + + self.state.circulating_pi -= locked + self.state.locked_pi += locked + + + # ------------------------- + # Price Model + # ------------------------- + + def price_discovery(self): + + demand = ( + self.state.transactions * 0.00005 + + self.state.dex_liquidity * 0.000002 + + self.state.apps * 0.01 + ) + + supply = self.state.circulating_pi + + new_price = demand / supply * 100000 + + self.state.price = max(new_price, 0.01) + + + # ------------------------- + # Year Simulation + # ------------------------- + + def run_year(self): + + self.state.year += 1 + + self.simulate_user_growth() + self.simulate_app_growth() + self.simulate_transactions() + self.simulate_human_tasks() + self.simulate_dex_liquidity() + self.simulate_token_locking() + self.price_discovery() + + + # ------------------------- + # Summary + # ------------------------- + + def summary(self): + + return { + "year": self.state.year, + "pioneers": self.state.pioneers, + "apps": self.state.apps, + "transactions": self.state.transactions, + "circulating_pi": round(self.state.circulating_pi, 2), + "locked_pi": round(self.state.locked_pi, 2), + "dex_liquidity": round(self.state.dex_liquidity, 2), + "price_estimate": round(self.state.price, 4) + } + + +# ----------------------------- +# Run Simulation +# ----------------------------- + +if __name__ == "__main__": + + sim = PiFullEcosystemSimulator() + + YEARS = 50 + + for _ in range(YEARS): + + sim.run_year() + + print(sim.summary()) diff --git a/economics/pi_macro_economic_model.py b/economics/pi_macro_economic_model.py new file mode 100644 index 00000000..f4af2f1b --- /dev/null +++ b/economics/pi_macro_economic_model.py @@ -0,0 +1,220 @@ +""" +Pi Macro Economic Model + +Research-grade macro simulation: +- supply inflation +- velocity of money +- adoption growth +- equilibrium price discovery +""" + +import random +from dataclasses import dataclass + + +# ----------------------------- +# State +# ----------------------------- + +@dataclass +class MacroState: + + year: int + + population: int + adoption_rate: float + pioneers: int + + circulating_supply: float + locked_supply: float + + velocity: float + transactions_value: float + + apps: int + utility_index: float + + price: float + + +# ----------------------------- +# Model +# ----------------------------- + +class PiMacroEconomicModel: + + def __init__(self): + + global_population = 8_000_000_000 + + pioneers = 17_700_000 + + self.state = MacroState( + + year=0, + + population=global_population, + adoption_rate=pioneers / global_population, + pioneers=pioneers, + + circulating_supply=3_000_000_000, + locked_supply=7_000_000_000, + + velocity=2.0, + transactions_value=0, + + apps=300, + utility_index=0.2, + + price=0.5 + ) + + # ------------------------- + # Adoption + # ------------------------- + + def simulate_adoption(self): + + growth = random.uniform(0.02, 0.10) + + new_users = int(self.state.pioneers * growth) + + self.state.pioneers += new_users + + self.state.adoption_rate = self.state.pioneers / self.state.population + + + # ------------------------- + # App ecosystem + # ------------------------- + + def simulate_apps(self): + + growth = int(self.state.apps * random.uniform(0.05, 0.20)) + + self.state.apps += growth + + self.state.utility_index = min( + 1.0, + self.state.apps / 10000 + ) + + + # ------------------------- + # Supply dynamics + # ------------------------- + + def simulate_supply(self): + + inflation = random.uniform(0.01, 0.03) + + minted = self.state.circulating_supply * inflation + + self.state.circulating_supply += minted + + lock_ratio = random.uniform(0.01, 0.05) + + locked = self.state.circulating_supply * lock_ratio + + self.state.circulating_supply -= locked + self.state.locked_supply += locked + + + # ------------------------- + # Velocity of money + # ------------------------- + + def simulate_velocity(self): + + activity_factor = self.state.utility_index * 5 + + self.state.velocity = 1 + activity_factor + + + # ------------------------- + # Transaction value + # ------------------------- + + def simulate_transactions(self): + + avg_payment = random.uniform(0.5, 5) + + self.state.transactions_value = ( + self.state.pioneers * + avg_payment * + self.state.velocity + ) + + + # ------------------------- + # Price equilibrium + # ------------------------- + + def equilibrium_price(self): + + demand = self.state.transactions_value + + supply = self.state.circulating_supply + + equilibrium = demand / supply + + network_effect = 1 + (self.state.adoption_rate * 20) + + self.state.price = equilibrium * network_effect + + + # ------------------------- + # One year step + # ------------------------- + + def run_year(self): + + self.state.year += 1 + + self.simulate_adoption() + self.simulate_apps() + self.simulate_supply() + self.simulate_velocity() + self.simulate_transactions() + self.equilibrium_price() + + + # ------------------------- + # Summary + # ------------------------- + + def summary(self): + + return { + + "year": self.state.year, + "pioneers": self.state.pioneers, + "adoption_rate": round(self.state.adoption_rate, 6), + "apps": self.state.apps, + + "velocity": round(self.state.velocity, 2), + + "circulating_supply": round(self.state.circulating_supply, 2), + "locked_supply": round(self.state.locked_supply, 2), + + "transaction_value": round(self.state.transactions_value, 2), + + "price_estimate": round(self.state.price, 4) + } + + +# ----------------------------- +# Run +# ----------------------------- + +if __name__ == "__main__": + + model = PiMacroEconomicModel() + + YEARS = 50 + + for _ in range(YEARS): + + model.run_year() + + print(model.summary()) diff --git a/economics/pi_tokenomics_engine.py b/economics/pi_tokenomics_engine.py new file mode 100644 index 00000000..e4c8d8f0 --- /dev/null +++ b/economics/pi_tokenomics_engine.py @@ -0,0 +1,206 @@ +""" +Pi Tokenomics Engine + +Simulates long-term tokenomics dynamics: +- mining rate decay +- reward distribution +- validator economy +- staking / locking +- circulating supply evolution +""" + +import random +from dataclasses import dataclass + + +# -------------------------------- +# State +# -------------------------------- + +@dataclass +class TokenomicsState: + + year: int + + pioneers: int + miners: int + + mining_rate: float + mined_supply: float + + circulating_supply: float + locked_supply: float + + staking_ratio: float + validator_count: int + + validator_rewards: float + staking_rewards: float + + +# -------------------------------- +# Engine +# -------------------------------- + +class PiTokenomicsEngine: + + def __init__(self): + + pioneers = 17_700_000 + + self.state = TokenomicsState( + + year=0, + + pioneers=pioneers, + miners=int(pioneers * 0.6), + + mining_rate=0.02, + mined_supply=0, + + circulating_supply=3_000_000_000, + locked_supply=7_000_000_000, + + staking_ratio=0.1, + validator_count=1_000_000, + + validator_rewards=0, + staking_rewards=0 + ) + + + # ----------------------------- + # Mining + # ----------------------------- + + def simulate_mining(self): + + mined = self.state.miners * self.state.mining_rate + + self.state.mined_supply += mined + self.state.circulating_supply += mined + + + # ----------------------------- + # Mining rate decay + # ----------------------------- + + def mining_decay(self): + + decay_factor = random.uniform(0.85, 0.95) + + self.state.mining_rate *= decay_factor + + + # ----------------------------- + # Staking + # ----------------------------- + + def simulate_staking(self): + + stake = self.state.circulating_supply * self.state.staking_ratio + + self.state.circulating_supply -= stake + self.state.locked_supply += stake + + + # ----------------------------- + # Validator economy + # ----------------------------- + + def simulate_validators(self): + + reward_pool = self.state.circulating_supply * 0.005 + + per_validator = reward_pool / self.state.validator_count + + self.state.validator_rewards = per_validator + + self.state.circulating_supply -= reward_pool + + + # ----------------------------- + # Staking rewards + # ----------------------------- + + def distribute_staking_rewards(self): + + rewards = self.state.locked_supply * 0.02 + + self.state.staking_rewards = rewards + + self.state.circulating_supply += rewards + + + # ----------------------------- + # Network growth + # ----------------------------- + + def simulate_growth(self): + + growth = int(self.state.pioneers * random.uniform(0.02, 0.08)) + + self.state.pioneers += growth + + self.state.miners = int(self.state.pioneers * 0.6) + + + # ----------------------------- + # Year step + # ----------------------------- + + def run_year(self): + + self.state.year += 1 + + self.simulate_growth() + + self.simulate_mining() + + self.mining_decay() + + self.simulate_staking() + + self.simulate_validators() + + self.distribute_staking_rewards() + + + # ----------------------------- + # Summary + # ----------------------------- + + def summary(self): + + return { + + "year": self.state.year, + "pioneers": self.state.pioneers, + "miners": self.state.miners, + + "mining_rate": round(self.state.mining_rate, 6), + "mined_supply": round(self.state.mined_supply, 2), + + "circulating_supply": round(self.state.circulating_supply, 2), + "locked_supply": round(self.state.locked_supply, 2), + + "validator_reward_per_node": round(self.state.validator_rewards, 6), + "staking_rewards": round(self.state.staking_rewards, 2) + } + + +# -------------------------------- +# Run Simulation +# -------------------------------- + +if __name__ == "__main__": + + engine = PiTokenomicsEngine() + + YEARS = 50 + + for _ in range(YEARS): + + engine.run_year() + + print(engine.summary()) diff --git a/economics/pi_whitepaper_economic_model.py b/economics/pi_whitepaper_economic_model.py new file mode 100644 index 00000000..0ba55dd9 --- /dev/null +++ b/economics/pi_whitepaper_economic_model.py @@ -0,0 +1,261 @@ +""" +Pi Whitepaper Economic Model + +Unified research model combining: +- network growth +- tokenomics +- liquidity +- utility demand +- macro equilibrium + +Designed for long-term simulation (50–100 years). +""" + +from dataclasses import dataclass +import random +import math + + +# -------------------------------------- +# State +# -------------------------------------- + +@dataclass +class WhitepaperState: + + year: int + + pioneers: int + apps: int + + circulating_supply: float + locked_supply: float + + liquidity: float + + velocity: float + transaction_volume: float + + mining_rate: float + price: float + + +# -------------------------------------- +# Model +# -------------------------------------- + +class PiWhitepaperEconomicModel: + + def __init__(self): + + self.state = WhitepaperState( + + year=0, + + pioneers=17_700_000, + apps=300, + + circulating_supply=3_000_000_000, + locked_supply=7_000_000_000, + + liquidity=100_000_000, + + velocity=2.0, + transaction_volume=0, + + mining_rate=0.02, + + price=0.5 + ) + + + # -------------------------------------- + # Network Growth + # -------------------------------------- + + def network_growth(self): + + growth = random.uniform(0.03, 0.10) + + new_users = int(self.state.pioneers * growth) + + self.state.pioneers += new_users + + + # -------------------------------------- + # App Ecosystem Growth + # -------------------------------------- + + def app_growth(self): + + growth = int(self.state.apps * random.uniform(0.05, 0.20)) + + self.state.apps += growth + + + # -------------------------------------- + # Tokenomics + # -------------------------------------- + + def mining(self): + + mined = self.state.pioneers * self.state.mining_rate + + self.state.circulating_supply += mined + + + def mining_decay(self): + + self.state.mining_rate *= random.uniform(0.85, 0.95) + + + def staking_and_locking(self): + + lock = self.state.circulating_supply * random.uniform(0.01, 0.05) + + self.state.circulating_supply -= lock + self.state.locked_supply += lock + + + # -------------------------------------- + # Utility Demand + # -------------------------------------- + + def utility_demand(self): + + app_factor = math.log(self.state.apps + 1) + + user_factor = math.log(self.state.pioneers) + + return app_factor * user_factor * 100000 + + + # -------------------------------------- + # Velocity + # -------------------------------------- + + def update_velocity(self): + + demand = self.utility_demand() + + self.state.velocity = 1 + demand / 1_000_000 + + + # -------------------------------------- + # Transactions + # -------------------------------------- + + def update_transactions(self): + + demand = self.utility_demand() + + self.state.transaction_volume = demand * self.state.velocity + + + # -------------------------------------- + # Liquidity + # -------------------------------------- + + def update_liquidity(self): + + new_liquidity = self.state.transaction_volume * random.uniform(0.001, 0.01) + + self.state.liquidity += new_liquidity + + + # -------------------------------------- + # Network Effect + # -------------------------------------- + + def network_effect(self): + + return math.sqrt(self.state.pioneers) + + + # -------------------------------------- + # Price Discovery + # -------------------------------------- + + def compute_price(self): + + demand = self.state.transaction_volume + + supply = self.state.circulating_supply + + base_price = demand / supply + + network_multiplier = self.network_effect() / 1000 + + liquidity_multiplier = 1 + (self.state.liquidity / supply) * 5 + + price = base_price * network_multiplier * liquidity_multiplier + + self.state.price = price + + + # -------------------------------------- + # Year Step + # -------------------------------------- + + def run_year(self): + + self.state.year += 1 + + self.network_growth() + + self.app_growth() + + self.mining() + + self.mining_decay() + + self.staking_and_locking() + + self.update_velocity() + + self.update_transactions() + + self.update_liquidity() + + self.compute_price() + + + # -------------------------------------- + # Summary + # -------------------------------------- + + def summary(self): + + return { + + "year": self.state.year, + "pioneers": self.state.pioneers, + "apps": self.state.apps, + + "circulating_supply": round(self.state.circulating_supply, 2), + "locked_supply": round(self.state.locked_supply, 2), + + "velocity": round(self.state.velocity, 3), + "transaction_volume": round(self.state.transaction_volume, 2), + + "liquidity": round(self.state.liquidity, 2), + + "price_estimate": round(self.state.price, 4) + } + + +# -------------------------------------- +# Run Simulation +# -------------------------------------- + +if __name__ == "__main__": + + model = PiWhitepaperEconomicModel() + + YEARS = 100 + + for _ in range(YEARS): + + model.run_year() + + print(model.summary()) diff --git a/economics/pirc-economic-model.md b/economics/pirc-economic-model.md new file mode 100644 index 00000000..c4c23699 --- /dev/null +++ b/economics/pirc-economic-model.md @@ -0,0 +1,8 @@ +Effective Liquidity Model + +L_eff = Wm * Pm + We * Pe + +Pm = mined Pi supply +Pe = external Pi supply +Wm = pioneer weight +We = external liquidity weight diff --git a/economics/reward_model.md b/economics/reward_model.md new file mode 100644 index 00000000..7b24390e --- /dev/null +++ b/economics/reward_model.md @@ -0,0 +1,36 @@ +# PiRC Reward Model + +## Reward Sources + +Rewards may originate from: + +1 protocol minting +2 transaction fees +3 treasury allocations +4 liquidity incentives + +--- + +## Reward Function + +Reward for participant i: + +Ri = B × Ai × Li + +Where: + +B = base reward multiplier +Ai = activity score +Li = liquidity contribution score + +--- + +## Reward Limits + +To prevent excessive emission: + +total_rewards ≤ treasury_reserves × emission_limit + +Typical emission limit: + +5% – 10% per year diff --git a/economics/reward_projection.py b/economics/reward_projection.py new file mode 100644 index 00000000..02c68d57 --- /dev/null +++ b/economics/reward_projection.py @@ -0,0 +1,24 @@ + +def allocate_rewards(total_vault, active_ratio): + base = total_vault * 0.0314 + return int(base * (1 + max(0.0, min(active_ratio, 1.0)))) + + +def project_supply(years=10, base_supply=314_000_000, yearly_vault=25_000_000): + active_curve = [0.35, 0.38, 0.42, 0.47, 0.51, 0.56, 0.6, 0.63, 0.66, 0.7] + supply = base_supply + + for year in range(years): + ratio = active_curve[min(year, len(active_curve) - 1)] + supply += allocate_rewards(yearly_vault, ratio) + + return { + "years": years, + "starting_supply": base_supply, + "ending_supply": supply, + "target_theme": "314M", + } + + +if __name__ == "__main__": + print(project_supply()) diff --git a/economics/token_supply_model.md b/economics/token_supply_model.md new file mode 100644 index 00000000..69368ffd --- /dev/null +++ b/economics/token_supply_model.md @@ -0,0 +1,25 @@ +# Token Supply Model + +## Supply Components + +Total supply consists of: + +S = Sm + Sr + St + +Where: + +Sm = mining rewards +Sr = reward distribution +St = treasury allocations + +--- + +## Inflation Control + +Supply growth should remain bounded: + +ΔS ≤ annual_supply_cap + +Example cap: + +2% – 5% yearly expansion diff --git a/economics/utility_simulator.py b/economics/utility_simulator.py new file mode 100644 index 00000000..d38eb7e5 --- /dev/null +++ b/economics/utility_simulator.py @@ -0,0 +1,24 @@ +import numpy as np + + +def simulate_utility_gate(years=10, initial_pioneers=314_000_000, base_retention=0.65, seed=42): + rng = np.random.default_rng(seed) + samples = min(initial_pioneers, 200_000) + + scores = rng.normal(6000, 2000, samples) + gated_ratio = float((scores >= 5000).mean()) + + annual_retention = min(0.99, base_retention * (1 + 3.14 * gated_ratio)) + projected_supply = int(initial_pioneers * (annual_retention ** years)) + + return { + "years": years, + "initial_pioneers": initial_pioneers, + "projected_supply": projected_supply, + "gated_ratio": round(gated_ratio, 4), + "retention_multiplier": 3.14, + } + + +if __name__ == "__main__": + print(simulate_utility_gate()) diff --git "a/economics/\342\224\224\342\224\200 ai_central_bank.py" "b/economics/\342\224\224\342\224\200 ai_central_bank.py" new file mode 100644 index 00000000..f1572b12 --- /dev/null +++ "b/economics/\342\224\224\342\224\200 ai_central_bank.py" @@ -0,0 +1,123 @@ +import numpy as np +import random + + +class EconomicState: + + def __init__(self): + + self.liquidity = 50 + self.volume = 500 + self.supply = 1000 + self.reward_multiplier = 1.0 + + +class AICentralBank: + + def __init__(self): + + self.target_liquidity = 60 + self.target_volume = 800 + self.target_supply_growth = 5 + + def evaluate(self, state): + + liquidity_gap = self.target_liquidity - state.liquidity + volume_gap = self.target_volume - state.volume + + return liquidity_gap, volume_gap + + + def monetary_policy(self, state): + + liquidity_gap, volume_gap = self.evaluate(state) + + if liquidity_gap > 10: + state.reward_multiplier *= 1.05 + + elif liquidity_gap < -10: + state.reward_multiplier *= 0.95 + + if volume_gap > 100: + state.reward_multiplier *= 1.02 + + return state.reward_multiplier + + + def liquidity_policy(self, state): + + injection = 0 + + if state.liquidity < self.target_liquidity: + + injection = random.uniform(5,15) + state.liquidity += injection + + return injection + + + def treasury_policy(self, state): + + burn = 0 + + if state.supply > 1500: + + burn = random.uniform(10,30) + state.supply -= burn + + return burn + + +class EconomySimulator: + + def __init__(self): + + self.state = EconomicState() + self.bank = AICentralBank() + + def step(self): + + reward_multiplier = self.bank.monetary_policy(self.state) + + liquidity_injection = self.bank.liquidity_policy(self.state) + + burn = self.bank.treasury_policy(self.state) + + liquidity_change = np.random.normal(reward_multiplier*2, 3) + volume_change = np.random.normal(reward_multiplier*10, 20) + + self.state.liquidity += liquidity_change + self.state.volume += volume_change + + self.state.supply += reward_multiplier*2 + + return { + "liquidity": self.state.liquidity, + "volume": self.state.volume, + "supply": self.state.supply, + "reward_multiplier": reward_multiplier, + "liquidity_injection": liquidity_injection, + "burn": burn + } + + +def run_simulation(): + + sim = EconomySimulator() + + history = [] + + for i in range(200): + + metrics = sim.step() + history.append(metrics) + + return history + + +if __name__ == "__main__": + + results = run_simulation() + + for r in results[:10]: + print(r) diff --git "a/economics/\342\224\224\342\224\200 ai_economic_governor_rl.py" "b/economics/\342\224\224\342\224\200 ai_economic_governor_rl.py" new file mode 100644 index 00000000..f4aee008 --- /dev/null +++ "b/economics/\342\224\224\342\224\200 ai_economic_governor_rl.py" @@ -0,0 +1,138 @@ +import numpy as np +import random + +# ------------------------------ +# Environment Model +# ------------------------------ + +class PiEconomyEnv: + + def __init__(self): + + self.liquidity = 50 + self.tx_volume = 500 + self.reward_multiplier = 1.0 + + def get_state(self): + + liquidity_state = int(self.liquidity // 10) + volume_state = int(self.tx_volume // 100) + + return (liquidity_state, volume_state) + + def step(self, action): + + # Actions + # 0 = decrease rewards + # 1 = keep rewards + # 2 = increase rewards + + if action == 0: + self.reward_multiplier *= 0.95 + + elif action == 2: + self.reward_multiplier *= 1.05 + + # Simulate economic response + liquidity_change = np.random.normal(self.reward_multiplier * 2, 3) + volume_change = np.random.normal(self.reward_multiplier * 5, 10) + + self.liquidity += liquidity_change + self.tx_volume += volume_change + + reward = self.calculate_reward() + + return self.get_state(), reward + + def calculate_reward(self): + + # target values + target_liquidity = 60 + target_volume = 800 + + liquidity_score = -abs(self.liquidity - target_liquidity) + volume_score = -abs(self.tx_volume - target_volume) + + return liquidity_score + volume_score + + +# ------------------------------ +# RL Agent +# ------------------------------ + +class EconomicGovernorRL: + + def __init__(self): + + self.q_table = {} + self.actions = [0,1,2] + + self.alpha = 0.1 + self.gamma = 0.9 + self.epsilon = 0.1 + + def get_q(self, state, action): + + return self.q_table.get((state, action), 0) + + def choose_action(self, state): + + if random.random() < self.epsilon: + return random.choice(self.actions) + + qs = [self.get_q(state,a) for a in self.actions] + + return self.actions[np.argmax(qs)] + + def update(self, state, action, reward, next_state): + + old_q = self.get_q(state, action) + + future_q = max([self.get_q(next_state,a) for a in self.actions]) + + new_q = old_q + self.alpha * (reward + self.gamma * future_q - old_q) + + self.q_table[(state,action)] = new_q + + +# ------------------------------ +# Training Loop +# ------------------------------ + +def train(): + + env = PiEconomyEnv() + agent = EconomicGovernorRL() + + episodes = 1000 + + for ep in range(episodes): + + state = env.get_state() + + for step in range(50): + + action = agent.choose_action(state) + + next_state, reward = env.step(action) + + agent.update(state, action, reward, next_state) + + state = next_state + + return agent + + +# ------------------------------ +# Run Simulation +# ------------------------------ + +if __name__ == "__main__": + + agent = train() + + print("Training complete.") + print("Learned policy sample:") + + for key,val in list(agent.q_table.items())[:10]: + print(key,val) diff --git "a/economics/\342\224\224\342\224\200 autonomous_pi_economy.py" "b/economics/\342\224\224\342\224\200 autonomous_pi_economy.py" new file mode 100644 index 00000000..42e2e36f --- /dev/null +++ "b/economics/\342\224\224\342\224\200 autonomous_pi_economy.py" @@ -0,0 +1,78 @@ +import random + + +class EconomyState: + + def __init__(self): + + self.liquidity = 50 + self.volume = 500 + self.price = 1 + self.supply = 1000 + + +class AutonomousEconomy: + + def __init__(self): + + self.state = EconomyState() + + def simulate_market(self): + + self.state.price += random.uniform(-0.05,0.05) + + self.state.volume += random.uniform(-50,50) + + self.state.liquidity += random.uniform(-5,5) + + def reward_policy(self): + + if self.state.volume > 700: + + self.state.supply += 5 + + else: + + self.state.supply += 2 + + def liquidity_policy(self): + + if self.state.liquidity < 40: + + self.state.liquidity += 10 + + def stabilize_price(self): + + if self.state.price > 1.5: + + self.state.supply += 10 + + elif self.state.price < 0.8: + + self.state.supply -= 5 + + def step(self): + + self.simulate_market() + + self.reward_policy() + + self.liquidity_policy() + + self.stabilize_price() + + return { + "price": self.state.price, + "liquidity": self.state.liquidity, + "volume": self.state.volume, + "supply": self.state.supply + } + + +if __name__ == "__main__": + + eco = AutonomousEconomy() + + for i in range(20): + + print(eco.step()) diff --git "a/economics/\342\224\224\342\224\200 dex_liquidity_ai.py" "b/economics/\342\224\224\342\224\200 dex_liquidity_ai.py" new file mode 100644 index 00000000..c9555802 --- /dev/null +++ "b/economics/\342\224\224\342\224\200 dex_liquidity_ai.py" @@ -0,0 +1,135 @@ +import numpy as np +import random + + +class LiquidityPool: + + def __init__(self): + + self.pi_reserve = 10000 + self.usd_reserve = 10000 + self.fee = 0.003 + + + def price(self): + + return self.usd_reserve / self.pi_reserve + + + def liquidity_depth(self): + + return np.sqrt(self.pi_reserve * self.usd_reserve) + + +class DexLiquidityAI: + + def __init__(self): + + self.target_liquidity = 15000 + self.target_volume = 1000 + + + def evaluate(self, pool, volume): + + liquidity = pool.liquidity_depth() + + liquidity_gap = self.target_liquidity - liquidity + volume_gap = self.target_volume - volume + + return liquidity_gap, volume_gap + + + def adjust_liquidity(self, pool, volume): + + liquidity_gap, volume_gap = self.evaluate(pool, volume) + + injection = 0 + + if liquidity_gap > 1000: + + injection = random.uniform(500,1500) + + pool.pi_reserve += injection + pool.usd_reserve += injection + + return injection + + + def adjust_fee(self, pool, volume): + + if volume > self.target_volume * 1.5: + + pool.fee = min(pool.fee + 0.0005, 0.01) + + elif volume < self.target_volume * 0.5: + + pool.fee = max(pool.fee - 0.0005, 0.001) + + return pool.fee + + + def rebalance_pool(self, pool): + + price = pool.price() + + target_price = 1 + + deviation = target_price - price + + adjust = deviation * 100 + + pool.pi_reserve -= adjust + pool.usd_reserve += adjust + + return adjust + + +class DexSimulation: + + def __init__(self): + + self.pool = LiquidityPool() + self.ai = DexLiquidityAI() + + def step(self): + + volume = random.uniform(200,2000) + + injection = self.ai.adjust_liquidity(self.pool, volume) + + fee = self.ai.adjust_fee(self.pool, volume) + + rebalance = self.ai.rebalance_pool(self.pool) + + price = self.pool.price() + + return { + "volume": volume, + "liquidity": self.pool.liquidity_depth(), + "price": price, + "fee": fee, + "liquidity_injection": injection, + "rebalance": rebalance + } + + +def run_simulation(): + + sim = DexSimulation() + + results = [] + + for i in range(200): + + results.append(sim.step()) + + return results + + +if __name__ == "__main__": + + data = run_simulation() + + for d in data[:10]: + + print(d) diff --git "a/economics/\342\224\224\342\224\200 treasury_ai.py" "b/economics/\342\224\224\342\224\200 treasury_ai.py" new file mode 100644 index 00000000..9924a7df --- /dev/null +++ "b/economics/\342\224\224\342\224\200 treasury_ai.py" @@ -0,0 +1,77 @@ +import numpy as np +import random + + +class Treasury: + + def __init__(self): + + self.pi_reserve = 100000 + self.stable_reserve = 50000 + self.liquidity_fund = 20000 + + +class TreasuryInvestmentAI: + + def __init__(self): + + self.target_liquidity = 15000 + self.target_reserve_ratio = 0.5 + + def allocate(self, treasury, market_price): + + decisions = {} + + # liquidity support + if treasury.liquidity_fund < self.target_liquidity: + + add = random.uniform(1000,5000) + + treasury.liquidity_fund += add + treasury.pi_reserve -= add + + decisions["liquidity_support"] = add + + # rebalance reserves + reserve_ratio = treasury.pi_reserve / (treasury.pi_reserve + treasury.stable_reserve) + + if reserve_ratio > self.target_reserve_ratio: + + convert = random.uniform(2000,5000) + + treasury.pi_reserve -= convert + treasury.stable_reserve += convert + + decisions["diversification"] = convert + + return decisions + + +class TreasurySimulation: + + def __init__(self): + + self.treasury = Treasury() + self.ai = TreasuryInvestmentAI() + + def step(self): + + price = random.uniform(0.5,2) + + actions = self.ai.allocate(self.treasury, price) + + return { + "price": price, + "pi_reserve": self.treasury.pi_reserve, + "stable_reserve": self.treasury.stable_reserve, + "liquidity_fund": self.treasury.liquidity_fund, + "actions": actions + } + + +if __name__ == "__main__": + + sim = TreasurySimulation() + + for i in range(10): + print(sim.step())