/** Central Exchange (marketplace plaza) staff + letter copy. */ export const MARKET_ORDER_MAX_AGE_MS = 30 * 24 * 60 * 60 * 1000; /** Named clerks; sex drives humanoid body. */ export const CENTRAL_EXCHANGE_STAFF = Object.freeze([ Object.freeze({ name: "Bobby Pennies", sex: "male" }), Object.freeze({ name: "Ada Ledger", sex: "female" }), Object.freeze({ name: "Clive Quill", sex: "male" }), Object.freeze({ name: "Marge Tally", sex: "female" }), Object.freeze({ name: "Nigel Coinwright", sex: "male" }), Object.freeze({ name: "Pearl Balance", sex: "female" }), Object.freeze({ name: "Otto Vault", sex: "male" }), Object.freeze({ name: "Iris Counter", sex: "female" }) ]); export function centralExchangeStaffCount () { return CENTRAL_EXCHANGE_STAFF.length; } export function pickExchangeClerk (random = Math.random) { const index = Math.floor(random() * CENTRAL_EXCHANGE_STAFF.length) % CENTRAL_EXCHANGE_STAFF.length; return CENTRAL_EXCHANGE_STAFF[index].name; } /** Listing fee charged when placing a buy or sell order (non-refundable). */ export const MARKET_ORDER_FEE_RATE = 0.03; /** Fee = ceil(3% of unitPrice × quantity), minimum 1 when the notional is positive. */ export function marketOrderListingFee (unitPrice, quantity) { const notional = Math.max(0, Math.floor(Number(unitPrice) || 0)) * Math.max(0, Math.floor(Number(quantity) || 0)); if (notional <= 0) { return 0; } return Math.max(1, Math.ceil(notional * MARKET_ORDER_FEE_RATE)); } export function soldLetterBody ({ itemName, quantity, unitPrice, clerkName }) { void clerkName; return [ `Good news — your sell order for ${quantity}× ${itemName} has been filled at ${unitPrice} coins each.`, "", "The proceeds have been deposited in your bank vault." ].join("\n"); } export function buyFilledLetterBody ({ itemName, quantity, unitPrice, clerkName }) { void clerkName; return [ `Your buy order for ${quantity}× ${itemName} has been filled at ${unitPrice} coins each.`, "", "The goods have been deposited in your bank vault." ].join("\n"); } export function orderExpiredLetterBody ({ side, itemName, quantity, escrowLabel, clerkName }) { void clerkName; if (side === "buy") { return [ `Unfortunately your buy order for ${quantity}× ${itemName} could not be filled within one month.`, "", "Your reserved coins have been returned to your bank." ].join("\n"); } if (escrowLabel === "written cheque") { return [ `Unfortunately your sell order for ${quantity}× ${itemName} could not be filled within one month.`, "", "Your reserved written cheque has been returned to your bank." ].join("\n"); } return [ `Unfortunately your sell order for ${quantity}× ${itemName} could not be filled within one month.`, "", "The listed goods have been returned to your bank." ].join("\n"); } export function orderCancelledLetterBody ({ side, itemName, quantity, escrowLabel, clerkName }) { void clerkName; if (side === "buy") { return [ `Your buy order for ${quantity}× ${itemName} was cancelled.`, "", "Your reserved coins have been returned to your bank." ].join("\n"); } if (escrowLabel === "written cheque") { return [ `Your sell order for ${quantity}× ${itemName} was cancelled.`, "", "Your reserved written cheque has been returned to your bank." ].join("\n"); } return [ `Your sell order for ${quantity}× ${itemName} was cancelled.`, "", "The listed goods have been returned to your bank." ].join("\n"); } /** Deterministic midpoint unit price for integer coins (half rounds away from zero via Math.round). */ export function midpointTradePrice (buyerMaximum, sellerMinimum) { const high = Math.max(0, Math.floor(Number(buyerMaximum) || 0)); const low = Math.max(0, Math.floor(Number(sellerMinimum) || 0)); return Math.max(0, Math.round((high + low) / 2)); }