Contracts reference

Every BrainChain contract, its functions, who may call them, the events it emits and the errors it can return.

The contracts are open source at usebrainchain/brainchain. Testnet addresses are listed below and on the Network page.

flowchart LR
    DE[DecisionExecutor] -->|owns| TB[TaskBoard]
    DE -->|owns| MR[ModelRegistry]
    DE -->|owns| DL[DecisionLog]
    TB -->|reads decisions| DL
    TB -->|reads models| MR
    DE -->|reads decisions| DL

#Testnet addresses

Contract Address
TaskBoard 0x686633c82F81b99B1Ae9bAAE458Aa8280F158367
DecisionLog 0x814936Ddb508385fe46285618B271B35FbcD1d96
ModelRegistry 0xf1599642DEb9F41E4D9Bc4D4457c0D333C8C5C0F
DecisionExecutor 0xe5901d1A62938E2d03bf2d89FF0893A5e0a55df5
WorkerStaking 0x942840737560AC602f78b63C506c8996aCB4C79E
FeeRouter 0xAC1964Af981567DbB41d6AE941f5bB8a6FD05839
ProposalBonds 0x40190374ef40Ac647546288FF68cEb9033Ee3c4e
TestUSDG (tUSDG) 0x609e58dB19603b74208c86CCc64275c026C2a83A
TestBRAIN (tBRAIN) 0xaF815F0B5E9c3706928eB4A8f8FdF8B4690E0f43
TestSwap 0xDA308F4CE7c80e52665f6D74590A2c0d61C437c3

#DecisionLog

Append-only record of the decisions the chain acts on.

Function Caller Effect
record(kind, subject, inputHash, answer, confidenceBps, payloadHash, payloadURI) Brain Stores a decision and returns its id
get(id) Anyone Returns the decision; reverts with UnknownDecision for an unknown id
brain(), owner(), count() Anyone Current brain, owner and number of decisions
setBrain(address), setOwner(address) Owner Rotates the brain or hands over ownership

Kinds: 1 Hire, 2 Grade, 3 Ruling, 4 Change.

Answers: Hire, the model id (zero for no hire). Grade, 1 accept or 0 reject. Ruling, 1 pay or 0 refund. Change, 1 adopt or 0 keep.

Event: Recorded(id, kind, subject, inputHash, answer, confidenceBps, payloadHash, payloadURI).

#TaskBoard

Holds bounties and settles tasks on recorded decisions.

Function Caller Effect
post(bounty, deadline, briefHash, briefURI) Anyone Escrows the bounty and opens a task
hire(id, decisionId) Brain Hires the decided model, or holds the task open below threshold
submit(id, resultHash, resultURI) Hired model's account Records the delivery before the deadline
grade(id, decisionId) Brain Records accept or reject within the grade window
dispute(id) Poster or hired model's account Opens the one dispute within the dispute window
rule(id, decisionId) Brain Settles a dispute within the rule window
finalize(id) Anyone Settles a task whose window has closed
get(id) Anyone Returns the task
setConfig(config) Owner Updates thresholds, windows and minimum bounty
setPaused(bool) Guardian or owner Pauses new posts and hires
setFee(feeBps, feeRouter) Owner Sets the protocol fee on paid bounties, at most 10%

Configuration: hireThresholdBps, gradeThresholdBps, ruleThresholdBps, minDuration, maxDuration, gradeWindow, disputeWindow, ruleWindow, minBounty.

A task can hire a house model from the registry or a staked worker from WorkerStaking.

Events: Posted, WorkerHired, HireHeld, WorkSubmitted, WorkGraded, GradeDisputed, Ruled, BountyPaid, BountyRefunded, FeeTaken, FeeSet, ConfigSet, PausedSet, OwnerSet, GuardianSet.

Errors: NotBrain, NotWorker, NotDisputant, IsPaused, BadBounty, BadDeadline, BadStatus, BadDecision, DecisionUsed, ModelInactive, TooLate, TooEarly, TransferMismatch.

#ModelRegistry

Function Caller Effect
setModel(id, account, price, active) Owner Adds or updates a model
get(id) Anyone Returns the model; reverts with UnknownModel
ids() Anyone Every registered model id

Event: ModelSet(id, account, price, active).

#DecisionExecutor

Function Caller Effect
queue(decisionId, target, data) Brain Queues a change Jev adopted above the change threshold
execute(changeId) Anyone Runs a queued change after its timelock
veto(changeId) Guardian Cancels a queued change
postHouseTask(bounty, deadline, briefHash, briefURI) Brain Posts a task from the treasury, within the daily cap
getChange(changeId) Anyone Returns a queued change
setParameters, setGuardian, transfer The executor itself Reachable only through an executed change

Events: Queued, Executed, Vetoed, HouseTaskPosted, ParametersSet, GuardianSet.

Errors: NotBrain, NotGuardian, NotSelf, BadDecision, DecisionUsed, BelowThreshold, UnknownChange, NotReady, Closed, CallFailed, BadConfig, HouseCapReached.

#FeeRouter

Collects the protocol fee and turns it into $BRAIN.

Function Caller Effect
buyback(amountIn, minOut) Keeper or owner Swaps collected fees for $BRAIN through the adapter, burns the burn share and sends the rest to the house treasury
setBrain(token) Owner, once Sets the $BRAIN token
setAdapter(adapter) Owner Sets the swap venue
setBurnShare(bps) Owner Sets the share burned (default 50%)

Event: BoughtBack(feeIn, brainOut, burned, toTreasury). Burned $BRAIN is sent to 0x…dEaD.

#WorkerStaking

Open worker registration. A staked worker's id is its account address, left-padded to 32 bytes.

Function Caller Effect
stake(amount, price) Anyone Stakes $BRAIN and sets a price per task
requestUnstake(amount) Worker Starts the cooldown
withdraw() Worker Withdraws stake after the cooldown
slash(account) TaskBoard Burns the slash share when a worker loses a dispute it opened
worker(id) Anyone Account, whether it is hireable, and price

Testnet settings: minimum stake 500 tBRAIN, cooldown 3 days, slash 20%.

#ProposalBonds

Function Caller Effect
propose(target, data, uri) Anyone Bonds $BRAIN on an exact proposed call
settle(id, decisionId) Anyone Returns the bond if Jev adopted the call above the change threshold, burns it otherwise
expire(id) Anyone Returns the bond if Jev did not decide within the window

Testnet settings: bond 100 tBRAIN, decision window 7 days.