Contracts
Not deployed. Nothing here holds money today. The contracts are written and tested on a local test network. No address exists, no key exists, and no fee has been paid.
The Mathematics page sets the arithmetic: who added what, and what a month can pay. This page is the code that repeats that arithmetic on a public chain, so the record can be checked by anyone and changed by no one. It follows the founder's decision of 2026-11-30 to build it now (decision record). The code is in contracts/ in the kun repo.
The five contracts
| Contract | What it does |
|---|---|
| Ledger | Records, once a month, the Merkle root of that month's proof lines and their total in units. Holds no money and no address |
| Points | A contributor's units as a balance that cannot be transferred. Claimed once a month with a proof |
| Pool | The Community Pool: 5% of revenue |
| NeedsFund | The Needs Fund: 2.5% of net profit |
| Payout | The monthly money, shared by points |
Pool and NeedsFund are the same contract under two names: a shared Treasury.
Ledger
Each month the owners close one record: the root of the month's proof lines, the total in units (1 point is 1000 units), and the number of lines. A month closes once and can never be changed or closed again. Months before January 2026 are refused, and so is an empty root.
The tree has two kinds of node, and each starts with its own prefix byte:
- a leaf is
sha256(0x00followed by the proof line's canonical bytes) - a parent is
sha256(0x01followed by the two children, the smaller first)
Without the prefixes, 64 bytes that happen to be two hashes could be offered as a line. With them, a line can never stand in for a whole branch. An odd node at the end of a level is carried up unchanged. ledger.mjs and the contract use the same rule, and the tests replay the script's own functions against the contract.
verify takes a month, a leaf and the sibling values, and says whether they lead to the stored root. It says no for a month that was never closed.
Points
Points count contribution units as a balance that no one can send. There is no transfer, no approve, and no function that moves a balance between people except the owner's rebind below.
A person's month is the sum over several proof lines, and a proof line names a GitHub login, not a wallet. So no single Ledger leaf can prove that a wallet earned an amount. Points uses a second tree, the claim root: one leaf per contributor, (month, wallet, units), built off-chain from the same lines. The owner sets a month's claim root once, and only after Ledger has closed that month.
What ties the claim root to Ledger is the total. The units claimed for a month can never go above the total Ledger recorded, whatever the claim tree holds. A claim goes through when:
- the month has a claim root,
- the caller is the holder of the wallet in the leaf,
- that leaf has not been claimed,
- the proof leads to the claim root,
- the units claimed so far stay within the Ledger month total.
Rebind. A teammate can lose a wallet. The owner moves it to a new one: its balance, and its right to claim every month it is named in, past or future. A month already claimed stays claimed, so the new wallet cannot claim it again, and the old wallet can no longer claim. A wallet that took part in a rebind cannot be the target of another, so chains cannot loop, and a wallet can be rebound at most 8 times in a row.
Pool and NeedsFund
The two treasuries hold one stable token each. Anyone can deposit, up to a cap. Only the owner spends. The owner can pause, and can raise or lower the cap.
The 5% and the 2.5% are decided and paid in by the owners off-chain. The contracts only hold, cap, pause and spend. A deposit that would push the balance above the cap is refused. So a bug can cost at most the cap.
Payout
Each month the owner funds one amount, once. It can only be funded after Points has that month's claim root, so nobody funds a month nobody can claim.
A contributor's share is:
share = floor(funded × units / monthTotal)
Rounding is down, in the token's smallest unit. The shares of a month add up to at most the funded amount, so the contract never owes more than it was given. The leftover dust stays in the contract. Because a month is funded once, a share never changes after anyone has claimed.
A claim needs the caller to be the holder of the wallet in the leaf, a proof against the claim root, a leaf not yet paid, and a running total of paid units that stays within the month total. A share that rounds to zero is refused. Payout has a cap, a pause and an owner, like the treasuries.
The controls
These stand in for the gates the first decision set aside.
- A multi-signature owner. Every contract is owned by a wallet of the founders, never one key. Ownership moves in two steps: the owner offers, the new address accepts.
- Caps. Each contract that can hold money has a deposit cap. It starts small, and only the owners raise it. Until an independent audit exists, the cap is the only bound on what a bug can cost.
- Pause. Every contract that moves money has a pause switch. Paused, deposits, spends, funding and claims are refused.
- No proxies. No upgrade proxy, no
delegatecall, noselfdestruct. A new version is a new deployment and a migrated root. - No native currency. No contract can receive plain coin. Each holds one stable token.
- No addresses in the repo. The repo holds no wallet address of any person. Wallet addresses are kept in Machine's local settings and in the owners' private registry.
- No key anywhere. No private key, seed phrase or wallet secret enters an agent session, a file or the repo.
The month
- Close.
node .claude/scripts/ledger.mjs close --month 2026-11reads that month's proof lines and prints the line count, the total in units, the Merkle root and each leaf. It is read-only: it signs nothing, sends nothing and reads no key. Add--jsonfor a machine form. - Check and sign. The owners check the Ledger root against the lines, and the claim root against the same lines and their registry of wallets. Then they sign both, on the multi-signature wallet. The script builds the Ledger root. The claim tree is built the same way off-chain, and today only the tests build it.
- Fund. The owners fund Payout for the month, once.
- Claim. Each person claims their units on Points and their share on Payout, each with a proof.
A close is reviewed by people on purpose. An issue counts when a named closer closes it, and a close by an agent on the owner's token cannot be told from his own.
Run the tests
cd contracts && pnpm install && pnpm test51 tests pass, on Hardhat's in-process network only. There is no deploy script, no network entry, no key and no .env in the folder.
Where it stands
Nothing is deployed. The contracts are not audited. Three choices wait for the owners on databayt/kun#199:
- A second root or the Ledger root. Today a claim is proven against a second root, the claim root, tied to Ledger by the month total. The other way is to prove claims against the Ledger root itself, which needs wallets inside the public proof lines.
- Floor or round to nearest. The contract rounds down.
ledger.mjs splitrounds to the nearest. The two can differ by a unit. The owners pick one rule, and the other side changes. - No sweep. There is no function that sweeps dust, or money no one claimed, back out of Payout. That money stays. Whether to add one, and where it goes, is theirs to say.
Which chain is a fourth open point, decided from a dated comparison on the same issue.
Payouts to a country open only after the legal check for that country.
What only the owners do
- Create the multi-signature wallet and name its owners.
- Fund the deployer. Network fees are a new kind of spend, outside the subscription-only rule. They need an explicit yes and their own cap first.
- Sign each deployment and each month's close.
- Say yes to the first test network.
An agent prepares files and transactions. It signs nothing.
See also
- Mathematics — the arithmetic these contracts repeat
- Share economy — the contract
- Decision record, 2026-11-30
- العقود بالعربية