Domain core: seeded RNG, asset registry, wallets, AMM pairs, mining

Pure logic layer with no game references: xoshiro128** RNG with savable
state, asset registry (PSC, CRC, CRT, CRA, SPARK, Ponero), wallets whose
taint and cost basis move with transfers, constant-product pools with
nightly reversion, and mining (Probidia/PMD GPUs, RatDigg ASICs, network
hash response, halving, wear and sudden death). 35 checks pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ZHU MINCHAOandClaude Opus 5.5 committed 2026-11-03 08:52:32 +08:00
commit ce3bed1467
14 files changed
+702

No files matched your search

+54
View File
@@ -0,0 +1,54 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace Decentralized.Domain
{
/// <summary>
/// 一个链上地址:各币种余额,加上整个地址的污点额与成本(信用点等值)。
/// 污点和成本按转出的价值比例随币走。
/// </summary>
public sealed class Wallet
{
public string Address;
public Dictionary<string, double> Balances = new Dictionary<string, double>();
/// <summary>污点额(信用点等值)。</summary>
public double Taint;
/// <summary>成本(信用点):出金时只对超出成本的部分征税。</summary>
public double Basis;
/// <summary>被执法标记。</summary>
public bool Flagged;
public double Get(string asset) => Balances.TryGetValue(asset, out var v) ? v : 0;
public void Add(string asset, double amount)
{
if (amount == 0) return;
double v = Get(asset) + amount;
if (v < -1e-9) throw new InvalidOperationException($"{Address}: {asset} 余额不足");
if (Math.Abs(v) < 1e-12) Balances.Remove(asset);
else Balances[asset] = v;
}
/// <summary>按价格表估值(信用点)。</summary>
public double Value(Func<string, double> price) => Balances.Sum(kv => kv.Value * price(kv.Key));
/// <summary>
/// 转出:taint 和 basis 按转出价值占地址总价值的比例带走。Ponero 等不可追踪资产转入时,污点不随之进入目标地址。
/// </summary>
public static void Transfer(Wallet from, Wallet to, string asset, double amount, Func<string, double> price)
{
if (amount <= 0) return;
double total = from.Value(price);
double share = total > 0 ? Math.Min(1.0, amount * price(asset) / total) : 0;
double taint = from.Taint * share, basis = from.Basis * share;
from.Add(asset, -amount);
from.Taint -= taint;
from.Basis -= basis;
to.Add(asset, amount);
var spec = Assets.Get(asset);
if (spec == null || spec.Traceable) to.Taint += taint;
to.Basis += basis;
}
}
}