@seasonkoh/webaz 0.1.22 → 0.1.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/layer0-foundation/L0-2-state-machine/engine.js +11 -16
- package/dist/layer1-agent/L1-1-mcp-server/server.js +697 -250
- package/dist/pwa/economic-participation.js +1 -1
- package/dist/pwa/integration-contract.js +4 -0
- package/dist/pwa/public/index.html +2 -1
- package/dist/pwa/routes/public-utils.js +17 -0
- package/dist/pwa/routes/referral.js +81 -0
- package/package.json +1 -1
|
@@ -13,20 +13,9 @@ import { generateId } from '../L0-1-database/schema.js';
|
|
|
13
13
|
import { appendOrderEvent } from './order-chain.js';
|
|
14
14
|
import { VALID_TRANSITIONS, CURRENT_RESPONSIBLE, CURRENT_RESPONSIBLE_SELF_FULFILL } from './transitions.js';
|
|
15
15
|
// RFC-014 PR2 — 资金算术统一走整数 base-units;分配用 allocate 保证精确守恒。
|
|
16
|
-
import { toUnits,
|
|
16
|
+
import { toUnits, mulRate, allocate } from '../../money.js';
|
|
17
17
|
// RFC-014 PR3 — 钱包落库 helper 抽到共享 ledger 模块(原私有于此),防多份漂移。
|
|
18
18
|
import { walletUnits, applyWalletDelta } from '../../ledger.js';
|
|
19
|
-
// ─── RFC-014 公池入金 helper ───────────────────────────────────
|
|
20
|
-
function creditReserveUnits(db, fromUserId, amountUnits, orderId, note) {
|
|
21
|
-
if (amountUnits <= 0)
|
|
22
|
-
return;
|
|
23
|
-
const cur = db.prepare("SELECT COALESCE(balance,0) balance, COALESCE(total_orphan_sponsor,0) tos FROM commission_reserve WHERE id='main'").get();
|
|
24
|
-
const newBal = toDecimal(toUnits(cur?.balance ?? 0) + amountUnits);
|
|
25
|
-
const newTos = toDecimal(toUnits(cur?.tos ?? 0) + amountUnits);
|
|
26
|
-
db.prepare(`UPDATE commission_reserve SET balance = ?, total_orphan_sponsor = ?, updated_at = datetime('now') WHERE id = 'main'`).run(newBal, newTos);
|
|
27
|
-
db.prepare(`INSERT INTO commission_reserve_txns (id, kind, from_user_id, amount, related_order_id, note) VALUES (?,?,?,?,?,?)`)
|
|
28
|
-
.run(generateId('crt'), 'redirect_orphan_sponsor', fromUserId, toDecimal(amountUnits), orderId, note);
|
|
29
|
-
}
|
|
30
19
|
// ─── 核心函数 ────────────────────────────────────────────────
|
|
31
20
|
/**
|
|
32
21
|
* 执行状态转移
|
|
@@ -260,9 +249,10 @@ export function settleFault(db, orderId, faultState) {
|
|
|
260
249
|
// 新规则(全部用订单快照,可复算,绝不印钱):
|
|
261
250
|
// 1. 协议只回收【原本该收的平台费】protocolTake = min(F, total × protocol_fee_rate)
|
|
262
251
|
// —— 协议不从违约牟利;fund_base(1%) 排除(无成交=无 GMV,社区基金不应从罚没获利)。
|
|
263
|
-
// 2. R = F − protocolTake;买家补偿 = R × 50%(
|
|
252
|
+
// 2. R = F − protocolTake;买家补偿 = R × 50% 起(受损对手方基础份额)。
|
|
264
253
|
// 3. 推广人 = R 的另一半,按 l1/l2/l3 原始佣金比例分,【封顶各自原始佣金】—— 永不超过其真实损失。
|
|
265
|
-
// 4. 推广半残值(超封顶 / 无推广人)→
|
|
254
|
+
// 4. 推广半残值(超封顶 / 无推广人)→ 【买家】(受损方吸收违约方罚金剩余,故买家可超 50%)。
|
|
255
|
+
// 决策 A(2026-06-07,对齐 RFC-007 Invariant #2):残值是罚金且无成交,归被坑方,不入 commission_reserve。
|
|
266
256
|
// 守恒:protocolTake + buyerComp + promotersPaid + reserveResidual ≡ F(按构造,残值兜底)。
|
|
267
257
|
const FORFEIT_LEVEL_RATES = { 1: 0.70, 2: 0.20, 3: 0.10 };
|
|
268
258
|
const protocolFeeRate = () => {
|
|
@@ -315,8 +305,13 @@ export function settleFault(db, orderId, faultState) {
|
|
|
315
305
|
promotersPaid += share;
|
|
316
306
|
});
|
|
317
307
|
}
|
|
318
|
-
// 4. 推广半残值(超封顶 / 无推广人 / 取整余数)→
|
|
319
|
-
|
|
308
|
+
// 4. 推广半残值(超封顶 / 无推广人 / 取整余数)→ 【买家】(受损方吸收违约方罚金剩余,可超 50%)。
|
|
309
|
+
// 决策 A(2026-06-07):对齐 RFC-007 Invariant #2「buyer absorbs the residual」+ 公开 economic.json。
|
|
310
|
+
// 理由:残值是【卖家罚金 + 无成交】,非正常单的未归属销售 margin,故归被坑的对手方,不入 commission_reserve。
|
|
311
|
+
// 守恒:protocolTake + (buyerComp+residual) + promotersPaid = protocolTake + R = F。绝不印钱。
|
|
312
|
+
const residual = promoterHalf - promotersPaid;
|
|
313
|
+
if (residual > 0)
|
|
314
|
+
applyWalletDelta(db, buyerId, { balance: residual });
|
|
320
315
|
return F;
|
|
321
316
|
};
|
|
322
317
|
// P0.1:RFQ 路径的 bid_stake_held — fault 时由各分支按规则处理
|