Docs

Program

One Anchor program, breaker. It owns the rules; the token program enforces the limit on every payment.

Program id

Built with Anchor. It reaches tokens through the token interface, so a budget can hold a mint of SPL Token or of Token-2022.

How it is built

The agent key is the standard delegate of a token account, approved for an amount. A payment is a TransferChecked signed by that delegate, straight to the token program. The Breaker program takes no part in it.

The program learns what was paid the next time it touches the budget, by reading how far the token account’s delegated amount has fallen below what it last approved. It adds that difference to the period’s spend and to the lifetime spend, then carries out the instruction. Every budget instruction starts with this step.

spent since the last touch  =  approved_at_touch - delegated_amount
remaining                   =  limit - (spent_at_touch - reset_spent_at_touch)
                               while the budget is on and not expired, else 0

The allowance is set with the token program’s Approve and removed with Revoke, signed by the Budget address through a cross-program call. No key held by a person or a server can sign for a budget.

Accounts

AccountHoldsSize
ConfigThe admin and the fee rate. One per program.43 bytes
PanelThe owner and the count of budgets. One per wallet.45 bytes
BudgetThe terms and the running totals of one budget.303 bytes
Budget accountThe budget’s money: a token account for its mint, owned by the Budget address, with the agent key as delegate.A token account
DrawerMarks a budget that draws on its panel’s reserve. One per drawing budget.73 bytes
ReserveThe panel’s money for one mint: a token account owned by the Panel address. Budgets that draw fill from it.A token account
Fee accountThe funding fees for one mint, owned by a program address that no key signs for.A token account
ChannelRecordOne payment channel a budget opened: what it deposited and the period that deposit counts against.225 bytes
ChannelsHow many channels a budget has open. It exists only while one is.77 bytes
LineOne service a budget on lines pays: its payout address, its cap per period and its spend.105 bytes
LinesHow many lines a budget has. While it exists the budget is on lines.45 bytes
MemberA wallet the owner lets sign some of the panel’s instructions, with its roles.74 bytes

Config

FieldTypeWhat it is
adminPubkeyWho may set the fee. Set once, when the Config is created by the program’s upgrade authority.
fee_bpsu16The funding fee in basis points, 0 to 10,000.
bumpu8The address bump.

Panel

FieldTypeWhat it is
ownerPubkeyThe wallet that owns the panel and every budget in it.
budget_countu32How many budgets are open.
bumpu8The address bump.

Budget

FieldTypeWhat it is
panelPubkeyThe panel it belongs to.
seed_agent_keyPubkeyThe agent key it opened with. Part of the address; it never changes.
agent_keyPubkeyThe key now approved as delegate.
mintPubkeyThe mint the budget holds and pays in.
token_programPubkeySPL Token or Token-2022.
labelString1 to 64 bytes.
limitu64The allowance granted per period, in base units.
period_secondsi64The length of a period.
period_starti64When the current period started, in unix seconds.
expiryOption<i64>When the budget stops paying, if it does.
onboolWhether it is switched on.
spent_at_touchu64This period’s spend as of the last instruction.
approved_at_touchu64The allowance the program last set.
lifetime_spentu64Everything the budget has paid, as of the last instruction.
bumpu8The address bump.
reset_spent_at_touchu64This period’s spend at the last reset. What was spent since then counts against the limit.

Drawer

FieldTypeWhat it is
budgetPubkeyThe budget that draws.
panelPubkeyThe panel whose reserve it draws on.
bumpu8The address bump.

ChannelRecord

FieldTypeWhat it is
budgetPubkeyThe budget that pays into the channel.
channelPubkeyThe channel, an account of the payment-channels program.
payeePubkeyThe channel’s payee: the key of the facilitator that opened it.
recipientPubkeyWho the channel pays out to: the service’s payTo.
authorized_signerPubkeyThe key that signs the channel’s vouchers: the agent key for a session, the service’s for a metered call.
depositu64Everything put into the channel.
countedu64The part of the deposit counted against the period in period_start.
period_starti64The period the deposit counts against. A top-up in a later period starts the count again.
rent_payerPubkeyWho paid the record’s rent, and gets it back when it closes.
bumpu8The address bump.

Channels

FieldTypeWhat it is
budgetPubkeyThe budget.
openu32How many of its channels are open.
rent_payerPubkeyWho paid its rent, returned when the last channel closes.
bumpu8The address bump.

Line

FieldTypeWhat it is
budgetPubkeyThe budget.
recipientPubkeyThe service’s payout address, its payTo. A channel charged to this line pays out to it alone.
capu64The most the service may take in one period.
spentu64What the line was charged in the period period_start names.
committedu64What that spend still holds in open channels: the most their closing can give back to the line.
period_starti64The period spent belongs to. A charge in a later period starts spent and committed at zero.
bumpu8The address bump.

Lines

FieldTypeWhat it is
budgetPubkeyThe budget.
countu32How many lines it has.
bumpu8The address bump.

Member

FieldTypeWhat it is
panelPubkeyThe panel.
keyPubkeyThe member’s wallet.
rolesu8Bit 1 is Switch, bit 2 is Limits; one or both.
bumpu8The address bump.

To read a budget’s live figures between instructions, add what the token account shows:

remaining now          =  token account's delegated_amount
spent this period now  =  spent_at_touch + approved_at_touch - delegated_amount

Instructions

InstructionSignerWhat it does
open_panelOwnerCreates the owner’s panel.
open_budgetOwner; a Limits member with no fundingCreates the budget and its account, moves the funding in less the fee, approves the agent key for the limit, and starts the first period.
fundOwnerMoves an amount from the owner to the budget account, less the fee to the fee account.
withdrawOwnerMoves an amount from the budget account to the owner.
set_limitOwner or a Limits memberSets the limit, period and expiry. The allowance becomes what now remains.
rollNoneOnce the period has ended: records its spend, starts the next and approves the limit again. Past expiry it revokes instead.
resetOwner or a Limits memberApproves the full limit now. The period keeps its end.
switch_offOwner or a Switch memberRevokes the delegate.
switch_onOwner or a Limits memberApproves what remained.
rotate_keyOwner or a Limits memberReplaces the agent key; the new approval replaces the old one.
close_budgetOwnerReturns the balance and the rent to the owner and closes the budget.
init_configAdminCreates the Config. Only the program’s upgrade authority can.
set_feeAdminSets the fee rate.
fund_reserveOwnerMoves an amount from the owner to the panel’s reserve, less the fee to the fee account.
withdraw_reserveOwnerMoves an amount from the reserve to the owner.
draw_onOwner or a Limits memberCreates the budget’s Drawer, so it draws on the reserve.
draw_offOwner or a Limits memberCloses the Drawer and returns its rent to the owner. The budget keeps its balance.
drawNoneMoves from the reserve what brings the budget account’s balance up to its delegated amount, as far as the reserve holds. Signed by the Panel address.
open_channelAgent key, rent payerCounts the deposit against the period’s limit and lowers the allowance by it, then opens a payment channel with the budget as payer and records it.
top_up_channelAgent keyCounts an amount against the period’s limit the same way, then adds it to an open channel.
distribute_channelNoneRuns the channel program’s distribute. For a sealed channel it pays the service, returns the rest to the budget account and, if counted this period, to the allowance, and closes the record. An open channel pays out what is settled and stays open.
close_channelNoneCloses the record of a channel distributed outside Breaker, crediting what it returned while the channel program still holds it.
request_channel_closeOwner or a Switch member; anyone while the budget is off or expiredRuns the channel program’s request_close, which starts the channel’s grace.
set_lineOwner or a Limits memberAdds a line for a service, or sets a new cap on one. The first creates Lines and revokes the agent key’s delegation.
remove_lineOwner or a Limits memberCloses a line and returns its rent to the owner. The last one closes Lines and approves the key for what remains.
add_memberOwnerCreates a Member for a wallet with its roles. The owner pays its rent.
set_rolesOwnerSets a member’s roles.
remove_memberOwnerCloses the Member and returns its rent; the wallet is refused from the next instruction on.

Arguments

InstructionArgumentsChecks
open_budgetlabel, limit, period_seconds, expiry, fundingThe label is 1 to 64 bytes. The limit is above zero; the funding may be zero. The period is 60 seconds or more. The expiry, if any, is in the future.
fundamountAbove zero.
withdrawamountAbove zero and within the balance.
set_limitlimit, period_seconds, expiryAs for open_budget.
reset, switch_onNoneThe budget is not expired.
rotate_keyNone; the new key is an accountThe new key differs from the current one.
rollNoneThe period has ended, or the budget is past its expiry.
fund_reserveamountAbove zero.
withdraw_reserveamountAbove zero and within the reserve.
draw_on, draw_off, drawNoneThe budget belongs to the panel. draw needs the budget’s Drawer.
init_config, set_feefee_bps0 to 10,000.
open_channeldeposit, salt, open_slot, grace_period, recipientsThe budget is on and not expired. The deposit is above zero, within what remains this period and within the balance. The channel program checks the rest of the open.
top_up_channelamountAs for open_channel. The channel is the record’s.
distribute_channelrecipientsThe channel is the record’s and still held by the channel program.
close_channelNoneThe channel is distributed, or no longer exists.
request_channel_closeNoneThe signer is the owner, or the budget is off or expired.
set_linerecipient, capThe cap is above zero. The first line needs the budget to have no channel open.
remove_linerecipientThe budget has a line for that recipient.

Amounts are u64 in the mint’s base units and times are unix seconds. The app offers periods of an hour, a day and a week. recipients is a list of { recipient: Pubkey, bps: u16 }, the channel program’s payout split; the SDK and Breaker’s facilitator send one entry, the service’s payTo at 10,000.

The roll

roll takes no signer: whoever pays its network fee may send it, and it can only do the one thing the budget’s own terms call for. It moves period_start forward by whole periods, so a budget that sat through several keeps the rhythm it opened with. Breaker’s keeper sends it for every budget at the earlier of its period end and its expiry.

The draw

draw takes no signer either. It moves only from the budget’s own panel reserve into the budget’s own account, and only what the allowance the program set calls for. For a drawing budget, the keeper sends roll and draw in one transaction, and the app adds draw to Reset, Switch on and Change in the transaction the owner signs.

The channels

A budget pays into a channel of the payment-channels program, CHNLxYvVA28MJP9PrFuDXccuoGXAx7jBacfLEkahyGsX, through cross-program calls signed with the budget’s seeds: open, top_up, request_close and distribute. Vouchers, settlement and sealing are the channel program’s own. Money a channel returns goes only to the budget account, so distribute_channel and close_channel take no signer.

On a budget on lines, open_channel must name one recipient at the full share, 10,000, and pass that recipient’s Line; top_up_channel passes the line of the channel’s recipient. The amount has to fit the line’s cap less its spend this period as well as the budget, and is added to both.

distribute_channel reads the channel’s deposit and what was settled before it distributes: the channel program frees a channel past its open window as it distributes, and after that nothing on chain says what it returned. The credit to the allowance is the smaller of what came back and counted, and never takes the period’s spend below where it stood at the last reset. close_budget takes the budget’s Channels address as its one remaining account and refuses while that account exists. On a budget on lines, the part that comes back is credited to the channel’s line too, up to what that line still has committed in the period.

On lines

Allowance is granted in one place, set_allowance, and every instruction that calls it passes the budget’s Lines address. While that account exists the grant is zero: a budget on lines leaves its agent key with no delegation, and money leaves the budget account only through open_channel and top_up_channel, which move it as the account’s owner and are charged to a line.

Takes the Lines addressWhy
set_limit, reset, switch_off, switch_on, rotate_key, rollThey set the allowance, which is zero on lines.
drawOn lines it fills the balance up to what remains of the limit, not up to a delegated amount.
open_channel, top_up_channel, distribute_channel, close_channelThey charge or credit the line, passed as an optional Line account.
close_budgetIt refuses while Lines exists. The API’s Close build removes every line first, in the same transaction.

Members

The instructions a member may sign take an authority signer where they took the owner, and an optional Member account. The program accepts the authority when it is the panel’s owner, or when the Member at ["member", panel, authority] holds the instruction’s role. draw_off and remove_line also name the owner, where the rent of what they close returns. open_budget signed by a member refuses any funding, and its two token accounts for the funding are optional. Everything else stays the owner’s alone: fund, withdraw, fund_reserve, withdraw_reserve, close_budget and the three member instructions. The Team page has the roles in full.

RoleBitInstructions
Switch1switch_off, request_channel_close
Limits2set_limit, reset, switch_on, rotate_key, open_budget with no funding, draw_on, draw_off, set_line, remove_line

A panel owned by a Squads v4 vault needs nothing from the program: the vault signs as the owner when a vault transaction executes.

Events

Every instruction emits one event. Breaker’s indexer follows them, together with each budget account’s outgoing transfers, to build the ledger you read in the panel. Payments themselves are plain token transfers that anyone can read from the chain.

EventEmitted byCarries
ConfigChangedinit_config, set_feeThe admin, the fee rate and the time.
PanelOpenedopen_panelThe panel, its owner and the time.
BudgetChangedEvery budget instructionThe action and a full picture of the budget after it.
ReserveChangedfund_reserve, withdraw_reserve, drawThe action, the amount, the fee and the reserve’s balance after it.
DrawChangeddraw_on, draw_offThe budget and whether it now draws.
ChannelChangedopen_channel, top_up_channel, distribute_channel, close_channel, request_channel_closeThe channel, its record, and the budget after the change.
LineChangedset_line, remove_line, and a channel instruction that charges or credits a lineThe line after the change and how many lines the budget has.
MemberChangedadd_member, set_roles, remove_memberThe member and its roles after the change.

BudgetChanged, LineChanged, ChannelChanged and DrawChanged end with signer: the wallet that signed the instruction, the owner, a member, or for a permissionless instruction whoever sent it.

BudgetChanged

FieldWhat it is
actionOne of Open, Fund, Withdraw, SetLimit, Roll, Reset, SwitchOff, SwitchOn, RotateKey, Close.
budget, panel, ownerThe budget and whose it is.
seed_agent_key, agent_keyThe key it opened with and the key now approved.
mint, token_program, token_accountWhat it holds and where.
label, limit, period_seconds, period_start, expiry, onThe terms.
spent_at_touch, approved_at_touch, lifetime_spent, reset_spent_at_touchThe running totals.
balance, delegated_amountThe token account after the instruction.
funding, feeThe amount put in and the fee taken, on Open and Fund.
closed_periodOn Roll: the closed period’s start, end and spent.
atThe chain’s time.

ReserveChanged

FieldWhat it is
actionOne of Fund, Withdraw, Draw.
panel, ownerThe panel and whose it is.
mint, token_program, reserveThe mint and the reserve’s token account.
budgetOn Draw: the budget that drew.
amount, feeWhat moved, and the fee taken on Fund.
balanceThe reserve after the instruction.
atThe chain’s time.

DrawChanged

FieldWhat it is
budget, panel, ownerThe budget and whose it is.
onWhether the budget now draws.
atThe chain’s time.

ChannelChanged

FieldWhat it is
actionOne of Open, TopUp, Distribute, Close, RequestClose. Distribute is a payout from a channel that stays open; Close ends the record.
budget, panel, channel, mintThe budget, its panel, the channel and the mint.
payee, recipient, authorized_signerAs on the ChannelRecord.
deposit, counted, period_startThe record after the change.
amountOn Open and TopUp, the deposit added; on Close, what came back to the budget account.
settledWhat the service has been paid from the channel, on Distribute and Close.
open_channels, remainingThe budget’s open channels, and what its key may still pay, after the change.
budget_afterThe budget account’s balance and delegated_amount and the budget’s running totals after the change. None on RequestClose, which changes neither.
atThe chain’s time.

LineChanged

FieldWhat it is
actionOne of Set, Remove, Charge, Credit.
budget, panel, recipientThe budget, its panel and the line’s service.
cap, spentThe cap, and the line’s spend in the budget’s current period.
period_startThe budget’s current period.
linesHow many lines the budget has after the change; 0 once it is off lines.
atThe chain’s time.

MemberChanged

FieldWhat it is
actionOne of Add, SetRoles, Remove.
panel, owner, keyThe panel, its owner and the member’s wallet.
rolesThe roles after the change; on Remove, the roles it held. Bit 1 is Switch, bit 2 Limits.
atThe chain’s time.

Errors

The program has twenty-three errors of its own, numbered 6000 to 6022. Each one, with what raises it, is on the Errors page.

Addresses

Every address is derived from the program id and seeds you already hold.

AddressSeeds
Config"config"
Panel"panel", the owner’s wallet
Budget"budget", the panel, the agent key the budget opened with
Budget accountThe associated token account of the Budget address for the mint.
Drawer"draw", the budget
ReserveThe associated token account of the Panel address for the mint.
Fee accountThe associated token account of the "protocol" address for the mint.
ChannelRecord"channel", the budget, the channel
Channels"channels", the budget
Line"line", the budget, the service’s payout address
Lines"lines", the budget
Member"member", the panel, the member’s wallet
A budget’s channelOf the payment-channels program: "channel", the budget, the payee, the mint, the authorized signer, then salt and open_slot as u64 little-endian
import { PublicKey } from '@solana/web3.js'
import { getAssociatedTokenAddressSync } from '@solana/spl-token'
import { PROGRAM_ID } from '@breaker/sdk'

const program = new PublicKey(PROGRAM_ID)
const [panel] = PublicKey.findProgramAddressSync([Buffer.from('panel'), owner.toBuffer()], program)
const [budget] = PublicKey.findProgramAddressSync([Buffer.from('budget'), panel.toBuffer(), firstAgentKey.toBuffer()], program)
const [drawer] = PublicKey.findProgramAddressSync([Buffer.from('draw'), budget.toBuffer()], program)
const reserve = getAssociatedTokenAddressSync(mint, panel, true, tokenProgram)
const [record] = PublicKey.findProgramAddressSync([Buffer.from('channel'), budget.toBuffer(), channel.toBuffer()], program)
const [channels] = PublicKey.findProgramAddressSync([Buffer.from('channels'), budget.toBuffer()], program)
const [line] = PublicKey.findProgramAddressSync([Buffer.from('line'), budget.toBuffer(), payTo.toBuffer()], program)
const [lines] = PublicKey.findProgramAddressSync([Buffer.from('lines'), budget.toBuffer()], program)

A budget’s address is fixed by the key it opened with, so rotating the key changes who can pay and leaves the budget, its account and its money where they are.