Stage 6.2: Poinbase perpetual futures (PSC, SPARK) with slippage, funding, insurance fund, ADL, debt and seizure

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
ZHU MINCHAOandClaude Sonnet 5.5 committed 2026-11-04 00:26:50 +08:00
1 parent 98e80412e6
commit b249747855
10 files changed
+578 -2

No files matched your search

+36
View File
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Decentralized.Domain;
@@ -107,6 +108,30 @@ namespace Decentralized
}
}
/// <summary>欠款逾期:没收物品抵债(用游戏自己的没收接口,和房贷逾期同一套,发一张没收单);抵不够的核销并拉黑永续账户。</summary>
private static void SeizeForDebt(SaveData d, int day)
{
var ps = PlayerStore.Instance;
var items = ps.FindRepoItems(ps.GetAllRepoEligibleItems(), (int)Math.Ceiling(d.Perps.Debt));
double value = 0;
var names = new System.Text.StringBuilder();
foreach (var it in items)
{
if (it == null) continue;
value += it.GetCurrentValue(useRetailMarkup: false, withChild: true, includeEvents: true, forceMarkup: false, 0L);
names.AppendLine(it.name);
}
foreach (var it in items) it?.Destroy();
var slip = DirectoryMaster.Item("slip");
slip.name = L.T("perp.slip.title");
slip.ModifyTag("SLIP_TITLE", st => st.Enable().SetString(L.T("perp.slip.title")));
slip.ModifyTag("SLIP_BODY", st => st.Enable().SetString(names.ToString()));
ps.AddDirectSellingItemToTableMiddle(slip, true);
double off = d.Perps.ApplySeizure(value, day);
Log.Info($"永续欠款没收:抵 {value:0},核销 {off:0}");
ps.AddNightLog(L.T("nightlog.perp.seize", Fmt.Credits(value)) + (off > 0.5 ? L.T("nightlog.perp.writeoff", Fmt.Credits(off), Tuning.PerpBanDays) : ""), "cc7755");
}
private static void Settle()
{
var d = Session.Data;
@@ -156,6 +181,9 @@ namespace Decentralized
d.Network.Night(day, d.Market.Price, hash);
if (d.Network.Reward < rewardBefore) d.Market.OnHalving(d.Rng);
if (d.Network.Reward < rewardBefore) News.Show("pd_news_halving_" + day, L.T("news.halving.title"), L.T("news.halving.desc"), 2);
// 永续:用今天的标记价(当日均价)结算,要在今晚的价格更新之前
var perpEvents = d.Perps.Night(day, new Dictionary<string, double> { ["PSC"] = d.Market.Mark, ["SPARK"] = d.Stable.Spark }, d.Poinbase, Session.Price);
if (perpEvents.Any(e => e.Kind == "seize")) SeizeForDebt(d, day);
var stakeEvents = d.Staking.Night(day, d.Stable.CraRate, d.WalletAt);
double crcFactor = d.Stable.Night(day, d.Rng, d.Staking.Earning);
if (d.Stable.CraWarnDay == day) News.Show("pd_news_crawarn_" + day, L.T("news.crawarn.title"), L.T("news.crawarn.desc"), 4);
@@ -192,6 +220,14 @@ namespace Decentralized
ps.AddNightLog(L.T("nightlog.drained", WalletWindow.NameOf(w), Fmt.Credits(v)), "cc7755");
}
ChainNight(d, day);
foreach (var e in perpEvents)
{
string who = e.Product + " " + L.T(e.Long ? "perp.long" : "perp.short");
if (e.Kind == "liq") ps.AddNightLog(L.T("nightlog.perp.liq", who, Fmt.Credits(e.Amount)), "cc7755");
else if (e.Kind == "adl") ps.AddNightLog(L.T("nightlog.perp.adl", who, Fmt.Credits(e.Amount)), "cc7755");
else if (e.Kind == "interest") ps.AddNightLog(L.T("nightlog.perp.interest", Fmt.Credits(e.Amount)), "cc7755");
else if (e.Kind == "repaid") ps.AddNightLog(L.T("nightlog.perp.repaid", Fmt.Credits(e.Amount)), "cc7755");
}
foreach (var e in stakeEvents)
{
var sw = d.Own(e.Wallet);