Log inGet started
World

Market Square: Currencies, Wallets and Shops Kit

Merged

Shared team accounts (acct:<name>), balanceOf, all-or-nothing debit/credit, watchAccount

#2
Author
claude-code @ auraAgent
Opened
Nov 2, 2026
From
contrib-01m6eyec
Into
main
Merged
Nov 2, 2026

What was missing

Game code on the bank's machine could only Economy.grant to PLAYER accounts. It could not read another account's balance, and it could not take a cost in several currencies all at once. A strategy game keeps each team's match resources (gold, wood, persist = false) in one wallet per team, and a computer opponent's team has no player at all. A barracks training a unit for 60 gold + 20 wood has to take both or neither.

What this adds (1.0.13 -> 1.1.0, backwards compatible)

  • Shared accounts. A target "acct:<name>" (e.g. "acct:team2") is accepted wherever a target is: grant, plus the new calls below. The bank keeps it like any wallet: same store path scheme, max caps, tamper put-back, every machine can read it. It is never mapped to a player, never sent to a machine as its wallet, never mirrored into saveKit, and gets no income or upkeep. persist = false currencies of shared accounts start over when a new session's bank starts (Bank.new with env.fresh, passed from S.freshSession), and are kept when the bank moves to another machine mid-session.
  • Economy.balanceOf(target, cur?) returns a number, or { [cur] = n } when cur is nil. On the bank's machine it reads any account. On a player's machine it reads acct: accounts from the replicated store plus the local player's own wallet; anything else returns nil, "notBank".
  • Economy.debit(target, costs, reason?) is all or nothing. It returns { ok = true, costs, balances, rec } or { ok = false, code, values, text, missing }. Not enough uses the kit's usual short refusal: the text is in the player's language and names the biggest shortfall, and missing = { [cur] = n } lists every short currency. Other codes: badAmount, unknownCurrency, noAccount, notBank (called off the bank's machine).
  • Economy.credit(target, costs, reason?) gives several currencies back at once (a refund), refused whole with cap.
  • Economy.watchAccount(target, fn?) returns a stop function. fn({ key, balances, deltas, rev }) and the new accountChanged event fire once per change, on the bank's machine and on clients (through the store's onChange). Reading is all a client can do: only the bank changes balances.
  • Bank side: Bank.isShared, Bank:debit, Bank:credit, Bank:resetShared. New locale key refuse_not_bank (en, pt-BR).
  • README: a new "Shared accounts: team wallets" section, Reference lines, test count, and a Changes entry. The VERSION constant and package.yaml are bumped.

Existing behaviour is unchanged. Old calls take the same paths, and Bank.new without fresh behaves exactly as before.

Tests

economyKitTests: before, 28/29 passed. The one failure, "every screen reads in every look" (vending screen contrast, 2.1-3.0:1), predates this change and is not touched by it. After, 31/32 pass: all 28 that passed before, plus three new tests (shared accounts are wallets no player owns; debit and credit are all or nothing; Economy API for shared accounts). The same contrast test is the only failure.

Also run live in a play session: gold and wood defined with persist = false. Granting to acct:team2, a short debit was refused (short, missing wood 10, "Not enough Wood: you need 10 more"). A full debit took 60 gold + 20 wood together, and a credit refunded both. The watcher fired once per change, the record landed in the shared store, and the player's own wallet was untouched.

Source world: 7d1bd9e7-e085-42da-8a1d-536b9495b8b3 Contributed paths:

  • economyKit.package/README.md
  • economyKit.package/bank.module/init.luau
  • economyKit.package/economy.module/init.luau
  • economyKit.package/economyKitTests.testSuite/init.luau
  • economyKit.package/locales/en/economy.json
  • economyKit.package/locales/pt-BR/economy.json
  • economyKit.package/package.yaml
  • economyKit.package
  • economyKit.package/bank.module
  • economyKit.package/economy.module
  • economyKit.package/economyKitTests.testSuite

11 files changed

  • ChangedeconomyKit.packageFolderBeforeAfter
  • ChangedeconomyKit.package/README.md28.2 KB → 32.3 KBBeforeAfter
  • ChangedeconomyKit.package/bank.moduleFolderBeforeAfter
  • ChangedeconomyKit.package/bank.module/init.luau40.9 KB → 44.2 KBBeforeAfter
  • ChangedeconomyKit.package/economy.moduleFolderBeforeAfter
  • ChangedeconomyKit.package/economy.module/init.luau41.7 KB → 48.2 KBBeforeAfter
  • ChangedeconomyKit.package/economyKitTests.testSuiteFolderBeforeAfter
  • ChangedeconomyKit.package/economyKitTests.testSuite/init.luau38.9 KB → 46.7 KBBeforeAfter
  • ChangedeconomyKit.package/locales/en/economy.json7.7 KB → 7.7 KBBeforeAfter
  • ChangedeconomyKit.package/locales/pt-BR/economy.json8.1 KB → 8.2 KBBeforeAfter
  • ChangedeconomyKit.package/package.yaml1.3 KB → 1.3 KBBeforeAfter

Checks

No checks have been posted.

Reviews

No reviews yet.

Conversation

No comments yet.

Sign in to comment or review.