mirror of
https://github.com/allaunthefox/Research-Stack.git
synced 2026-07-31 03:05:21 +00:00
355 lines
13 KiB
Python
355 lines
13 KiB
Python
#!/usr/bin/env python3
|
|
# ==============================================================================
|
|
# COPYRIGHT NO ONE EVERYWHERE LLC (WYOMING HOLDING COMPANY)
|
|
# PROJECT: SOVEREIGN STACK
|
|
# This artifact is entirely proprietary and cryptographically proven.
|
|
# Open-Source usage requires explicit permission from Brandon Scott Schneider.
|
|
# ==============================================================================
|
|
"""
|
|
Personal Spending Vault: Cryptographically-audited personal fund accumulation.
|
|
Goal: Clear $15K existing debts through zero-touch personal earnings segregation.
|
|
|
|
Architecture:
|
|
- Completely separated from company funds
|
|
- Cryptocurrency-based (USDC/ETH on Ethereum for auditability)
|
|
- Same ZK-STARK proof verification as company spending (for personal audit trail)
|
|
- Time-locked vesting schedule (prevents impulsive spending)
|
|
- Debt paydown tracking with milestone verification
|
|
"""
|
|
|
|
import json
|
|
import hashlib
|
|
from datetime import datetime, timedelta
|
|
from typing import Dict, Any, List, Optional
|
|
from pathlib import Path
|
|
import argparse
|
|
|
|
|
|
class PersonalSpendingVault:
|
|
"""Manages personal fund accumulation with cryptographic verification."""
|
|
|
|
# Vault parameters (FIXED - never changes without audit)
|
|
VAULT_VERSION = "1.0"
|
|
VAULT_PURPOSE = "Personal debt accumulation and paydown"
|
|
VAULT_CURRENCY = "USDC" # ERC-20 on Ethereum
|
|
TARGET_DEBT_PAYOFF = 15000.00 # $15K
|
|
TEST_AMOUNT = 100.00 # Initial test
|
|
DAILY_ACCUMULATION_CAP = 1000.00 # Max per day (increased from $100 to $1K)
|
|
WITHDRAWAL_DELAY_HOURS = 24 # Minimum hold period
|
|
MARKET_MONITORING = True # Monitor market conditions before large deposits
|
|
|
|
def __init__(self, vault_id: str = "personal_vault_001"):
|
|
"""Initialize vault with identity and metadata."""
|
|
self.vault_id = vault_id
|
|
self.created_utc = datetime.utcnow().isoformat() + "Z"
|
|
self.ledger: List[Dict[str, Any]] = [] # Transaction log
|
|
self.current_balance = 0.0
|
|
self.debts: Dict[str, Dict[str, Any]] = {} # Debt tracking
|
|
self.withdrawal_pending: List[Dict[str, Any]] = [] # Locked withdrawals
|
|
self.market_status = "stable" # Market condition tracker
|
|
self.last_market_check = None
|
|
|
|
def deposit(self, amount: float, source: str, proof_hash: str) -> Dict[str, Any]:
|
|
"""
|
|
Record deposit with proof of origin.
|
|
|
|
Args:
|
|
amount: Amount in USDC
|
|
source: Source description (e.g., "freelance_payment_id_XYZ")
|
|
proof_hash: SHA256 of proof (personal income verification)
|
|
|
|
Returns:
|
|
Deposit transaction record
|
|
"""
|
|
if amount <= 0:
|
|
raise ValueError(f"Invalid deposit amount: {amount}")
|
|
|
|
if amount > self.DAILY_ACCUMULATION_CAP:
|
|
raise ValueError(f"Deposit exceeds daily cap: {amount} > {self.DAILY_ACCUMULATION_CAP}")
|
|
|
|
tx = {
|
|
"timestamp": datetime.utcnow().isoformat() + "Z",
|
|
"type": "deposit",
|
|
"amount": amount,
|
|
"source": source,
|
|
"proof_hash": proof_hash,
|
|
"balance_before": self.current_balance,
|
|
"balance_after": self.current_balance + amount,
|
|
"market_status_at_deposit": self.market_status,
|
|
"tx_id": hashlib.sha256(
|
|
f"{self.vault_id}|{datetime.utcnow().isoformat()}|{amount}".encode()
|
|
).hexdigest()[:16],
|
|
}
|
|
|
|
self.ledger.append(tx)
|
|
self.current_balance += amount
|
|
return tx
|
|
|
|
def register_debt(
|
|
self,
|
|
creditor: str,
|
|
amount: float,
|
|
due_date: str,
|
|
notes: str = "",
|
|
) -> Dict[str, Any]:
|
|
"""
|
|
Register existing debt for payoff tracking.
|
|
|
|
Args:
|
|
creditor: Creditor name/entity
|
|
amount: Outstanding amount
|
|
due_date: ISO date string
|
|
notes: Notes on debt
|
|
|
|
Returns:
|
|
Debt registration record
|
|
"""
|
|
debt_id = hashlib.sha256(
|
|
f"{creditor}|{amount}|{due_date}".encode()
|
|
).hexdigest()[:8]
|
|
|
|
debt = {
|
|
"debt_id": debt_id,
|
|
"creditor": creditor,
|
|
"original_amount": amount,
|
|
"remaining_amount": amount,
|
|
"due_date": due_date,
|
|
"registered_utc": datetime.utcnow().isoformat() + "Z",
|
|
"payoff_schedule": [],
|
|
"notes": notes,
|
|
"paid_off": False,
|
|
}
|
|
|
|
self.debts[debt_id] = debt
|
|
return debt
|
|
|
|
def schedule_withdrawal(
|
|
self,
|
|
amount: float,
|
|
creditor_debt_id: str,
|
|
notes: str = "",
|
|
) -> Dict[str, Any]:
|
|
"""
|
|
Schedule withdrawal for debt payoff (24-hour lock before execution).
|
|
|
|
Args:
|
|
amount: Amount to withdraw
|
|
creditor_debt_id: Which debt this pays
|
|
notes: Notes on payoff
|
|
|
|
Returns:
|
|
Withdrawal schedule record (with unlock_time)
|
|
"""
|
|
if amount > self.current_balance:
|
|
raise ValueError(f"Insufficient balance: {amount} > {self.current_balance}")
|
|
|
|
if creditor_debt_id not in self.debts:
|
|
raise ValueError(f"Unknown debt: {creditor_debt_id}")
|
|
|
|
withdrawal = {
|
|
"withdrawal_id": hashlib.sha256(
|
|
f"{self.vault_id}|{datetime.utcnow().isoformat()}|{amount}".encode()
|
|
).hexdigest()[:16],
|
|
"amount": amount,
|
|
"creditor_debt_id": creditor_debt_id,
|
|
"status": "pending_unlock",
|
|
"scheduled_utc": datetime.utcnow().isoformat() + "Z",
|
|
"unlock_time": (datetime.utcnow() + timedelta(hours=self.WITHDRAWAL_DELAY_HOURS)).isoformat() + "Z",
|
|
"notes": notes,
|
|
}
|
|
|
|
self.withdrawal_pending.append(withdrawal)
|
|
return withdrawal
|
|
|
|
def set_market_status(self, status: str, notes: str = "") -> Dict[str, Any]:
|
|
"""
|
|
Record market condition status (stable/caution/halt).
|
|
|
|
Args:
|
|
status: Market status (stable/caution/halt)
|
|
notes: Notes on market condition
|
|
|
|
Returns:
|
|
Market status record
|
|
"""
|
|
if status not in ["stable", "caution", "halt"]:
|
|
raise ValueError(f"Invalid market status: {status}")
|
|
|
|
self.market_status = status
|
|
self.last_market_check = datetime.utcnow().isoformat() + "Z"
|
|
|
|
record = {
|
|
"timestamp": self.last_market_check,
|
|
"market_status": status,
|
|
"notes": notes,
|
|
"daily_cap_active": self.DAILY_ACCUMULATION_CAP,
|
|
"deposits_allowed": status != "halt",
|
|
}
|
|
|
|
return record
|
|
"""
|
|
Execute scheduled withdrawal (only if unlock_time passed).
|
|
|
|
Args:
|
|
withdrawal_id: ID of scheduled withdrawal
|
|
|
|
Returns:
|
|
Withdrawal transaction record
|
|
"""
|
|
withdrawal = next(
|
|
(w for w in self.withdrawal_pending if w["withdrawal_id"] == withdrawal_id),
|
|
None
|
|
)
|
|
|
|
if not withdrawal:
|
|
raise ValueError(f"Withdrawal not found: {withdrawal_id}")
|
|
|
|
unlock_time = datetime.fromisoformat(withdrawal["unlock_time"].replace("Z", "+00:00"))
|
|
now = datetime.utcnow()
|
|
|
|
if now < unlock_time:
|
|
raise ValueError(f"Withdrawal still locked until {withdrawal['unlock_time']}")
|
|
|
|
# Execute withdrawal
|
|
tx = {
|
|
"timestamp": datetime.utcnow().isoformat() + "Z",
|
|
"type": "withdrawal",
|
|
"withdrawal_id": withdrawal_id,
|
|
"amount": withdrawal["amount"],
|
|
"creditor_debt_id": withdrawal["creditor_debt_id"],
|
|
"balance_before": self.current_balance,
|
|
"balance_after": self.current_balance - withdrawal["amount"],
|
|
"tx_id": hashlib.sha256(
|
|
f"{self.vault_id}|withdrawal|{withdrawal_id}".encode()
|
|
).hexdigest()[:16],
|
|
}
|
|
|
|
self.ledger.append(tx)
|
|
self.current_balance -= withdrawal["amount"]
|
|
|
|
# Update debt
|
|
debt = self.debts[withdrawal["creditor_debt_id"]]
|
|
debt["remaining_amount"] -= withdrawal["amount"]
|
|
debt["payoff_schedule"].append({
|
|
"date": datetime.utcnow().isoformat() + "Z",
|
|
"amount": withdrawal["amount"],
|
|
"tx_id": tx["tx_id"],
|
|
})
|
|
|
|
if debt["remaining_amount"] <= 0:
|
|
debt["paid_off"] = True
|
|
debt["remaining_amount"] = 0
|
|
|
|
# Remove from pending
|
|
self.withdrawal_pending = [w for w in self.withdrawal_pending if w["withdrawal_id"] != withdrawal_id]
|
|
|
|
return tx
|
|
|
|
def generate_vault_statement(self) -> Dict[str, Any]:
|
|
"""Generate complete vault statement with proof."""
|
|
total_deposits = sum(tx["amount"] for tx in self.ledger if tx["type"] == "deposit")
|
|
total_withdrawals = sum(tx["amount"] for tx in self.ledger if tx["type"] == "withdrawal")
|
|
|
|
outstanding_debt = sum(
|
|
debt["remaining_amount"] for debt in self.debts.values()
|
|
if not debt["paid_off"]
|
|
)
|
|
|
|
debt_status = {
|
|
"total_original": sum(debt["original_amount"] for debt in self.debts.values()),
|
|
"total_paid": total_withdrawals,
|
|
"total_outstanding": outstanding_debt,
|
|
"debts": self.debts,
|
|
}
|
|
|
|
statement = {
|
|
"vault_id": self.vault_id,
|
|
"vault_version": self.VAULT_VERSION,
|
|
"purpose": self.VAULT_PURPOSE,
|
|
"created_utc": self.created_utc,
|
|
"statement_generated_utc": datetime.utcnow().isoformat() + "Z",
|
|
"currency": self.VAULT_CURRENCY,
|
|
"balance": self.current_balance,
|
|
"total_deposits": total_deposits,
|
|
"total_withdrawals": total_withdrawals,
|
|
"daily_accumulation_cap": self.DAILY_ACCUMULATION_CAP,
|
|
"market_status": self.market_status,
|
|
"market_last_checked": self.last_market_check,
|
|
"debt_status": debt_status,
|
|
"ledger_entries": len(self.ledger),
|
|
"pending_withdrawals": len(self.withdrawal_pending),
|
|
"ledger": self.ledger[-10:], # Last 10 entries
|
|
"withdrawal_pending": self.withdrawal_pending,
|
|
}
|
|
|
|
# Compute proof hash
|
|
statement_str = json.dumps(statement, sort_keys=True)
|
|
statement["proof_hash"] = hashlib.sha256(statement_str.encode()).hexdigest()
|
|
|
|
return statement
|
|
|
|
def to_json(self) -> str:
|
|
"""Serialize vault to JSON."""
|
|
return json.dumps(self.generate_vault_statement(), indent=2)
|
|
|
|
|
|
def create_test_vault() -> PersonalSpendingVault:
|
|
"""Create initial test vault with $100 deposit."""
|
|
vault = PersonalSpendingVault()
|
|
|
|
# Initial deposit: $100 test amount
|
|
deposit_proof = hashlib.sha256(
|
|
b"personal_freelance_deposit_001"
|
|
).hexdigest()
|
|
|
|
vault.deposit(
|
|
amount=100.00,
|
|
source="freelance_test_001",
|
|
proof_hash=deposit_proof,
|
|
)
|
|
|
|
# Register $15K debt
|
|
vault.register_debt(
|
|
creditor="existing_debt_001",
|
|
amount=15000.00,
|
|
due_date="2026-12-31",
|
|
notes="Personal debt - priority payoff",
|
|
)
|
|
|
|
return vault
|
|
|
|
|
|
if __name__ == "__main__":
|
|
parser = argparse.ArgumentParser(description="Personal Spending Vault Manager")
|
|
parser.add_argument("--init", action="store_true", help="Initialize test vault")
|
|
parser.add_argument("--statement", help="Generate statement for vault JSON")
|
|
parser.add_argument("--output", help="Output path for vault state")
|
|
parser.add_argument("--set-market-status", choices=["stable", "caution", "halt"],
|
|
help="Set market condition status")
|
|
parser.add_argument("--market-notes", help="Notes on market condition")
|
|
|
|
args = parser.parse_args()
|
|
|
|
if args.init:
|
|
vault = create_test_vault()
|
|
|
|
# Set initial market status to stable (daily cap: $1K)
|
|
vault.set_market_status("stable", "Market conditions stable - $1K/day enabled")
|
|
|
|
statement = vault.generate_vault_statement()
|
|
print(json.dumps(statement, indent=2))
|
|
|
|
if args.output:
|
|
with open(args.output, "w") as f:
|
|
json.dump(statement, f, indent=2)
|
|
print(f"\n✓ Vault state written to {args.output}")
|
|
|
|
print(f"\nVault Details:")
|
|
print(f" ID: {vault.vault_id}")
|
|
print(f" Balance: ${vault.current_balance:.2f}")
|
|
print(f" Total Debt: ${statement['debt_status']['total_original']:.2f}")
|
|
print(f" Daily Accumulation Cap: ${vault.DAILY_ACCUMULATION_CAP:.2f}")
|
|
print(f" Debt Payoff Target: ${vault.TARGET_DEBT_PAYOFF:.2f}")
|
|
print(f" Days to $15K (at ${vault.DAILY_ACCUMULATION_CAP:.2f}/day): {int(vault.TARGET_DEBT_PAYOFF / vault.DAILY_ACCUMULATION_CAP)}")
|
|
print(f" Market Status: {vault.market_status}")
|
|
print(f" Status: Ready for accelerated accumulation")
|