const MeterActive, MeterRetired
Meter status values.
Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.
Realm meters is usage-based billing with graduated marginal pricing: a provider publishes a METER (a unit of service,...
Realm meters is usage-based billing with graduated marginal pricing: a provider publishes a METER (a unit of service, a list price per unit, a billing period, and a tiers.Schedule of marginal volume discounts), a consumer ENROLLS and prepays a deposit, the provider RECORDS usage as it is served, and each period's accumulated usage settles from the consumer's deposit into the provider's claimable balance.
It is the usage-based complement to r/subscriptions' flat recurring plans — the one billing shape this portfolio lacked (its discovery gate's whole finding). The pricing identity is p/tiers':
1base = units × unitPrice (checked int64 multiplication)
2due = Schedule.Charge(base) (≤ base — marginal discount off list)
tiers validates every rate into [0, RateScale], so Charge(base) ≤ base is an arithmetic fact: a schedule can DISCOUNT list price and can never surcharge it. A flat price is the one-rate schedule (no edges, rates "10000") — the degenerate case, not a second code path.
Funds move on pull paths only: providers Claim, consumers WithdrawDeposit or Exit, the fee recipient WithdrawFees. Periods are fixed-length block windows anchored at Enroll height — runtime.ChainHeight() throughout, never a caller-supplied time (r/books' obligation, inherited verbatim).
REALM-CALLER CAVEAT, inherited from the siblings verbatim: coinio's receipt guard admits only EOA payers, so enrolling consumers are EOAs; assertNoSend reads the ORIGIN envelope, so every non-payable function refuses any transaction that attached coins anywhere. Providers may be EOAs or realms, but a realm provider must expose its own crossing path to Claim, or what it earns is stranded.
Meter status values.
Enrollment status values. Exited is terminal.
1const (
2 MaxTitleLen = 80
3 MaxUnitLen = 24
4
5 // MinUnitPrice keeps a meter from being free-by-rounding; a provider
6 // who wants a free tier declares a 0-rate first tier instead, which
7 // keeps the arithmetic visible in the schedule rather than implicit
8 // in a zero price.
9 MinUnitPrice = int64(1)
10 // MaxUnitPrice keeps base = units × unitPrice far from int64
11 // overflow for any usage a deposit could plausibly cover; the
12 // checked multiplication is still there and still refuses.
13 MaxUnitPrice = int64(1_000_000_000) // 1000 GNOT per unit
14
15 // MinPeriodBlocks/MaxPeriodBlocks bound a meter's billing period —
16 // the same bounds and reasoning as r/subscriptions: the floor keeps
17 // settlement from becoming a per-block treadmill, the ceiling keeps
18 // period arithmetic far from overflow.
19 MinPeriodBlocks = int64(10)
20 MaxPeriodBlocks = int64(7500000)
21
22 // MaxMetersPerProvider bounds catalog monopolization by a single
23 // address — the finding that was RED in permission_registry and
24 // service_registry, carried from the start here.
25 MaxMetersPerProvider = 20
26
27 // MaxEnrollmentsPerConsumer bounds one account's open-enrollment
28 // state. Exited enrollments free their slot.
29 MaxEnrollmentsPerConsumer = 100
30
31 // RenderLimit bounds every rendered list — an unbounded Render was
32 // YELLOW in three prior audits.
33 RenderLimit = 20
34)Input bounds.
Denom is the only asset this realm accepts.
MaxFeeBps is the hard protocol-fee cap: 1000 bps = 10%.
AcceptAdmin completes a staged admin transfer. Pending admin only.
ActiveEnrollID resolves the caller-free (meter, consumer) index.
BalanceOf is an enrollment's deposited balance as the LEDGER holds it — including a not-yet-settled elapsed period's charge; net view: subtract PendingChargeOf.
ChargeHeadroomOf is how much MORE charge the current period could absorb before Record's deposit bound refuses: balance − pending charge.
Claim sends amount ugnot of the caller's claimable balance back to the caller. Providers earn into this balance at every settlement.
ClaimAll sends the caller's entire claimable balance back to the caller. Fails if there is nothing to claim.
1func CreateMeter(cur realm, title, unit string, unitPrice, periodBlocks int64, edges, rates string, maxFeeBps int64) int64CreateMeter publishes a meter and returns its id. No coins are accepted; the storage deposit the caller pays is the anti-spam. edges and rates are comma-separated int64 lists building the tiers.Schedule over the ugnot BASE (units × unitPrice): len(rates) == len(edges)+1, each rate in [0, 10000] ten-thousandths of list price. "" edges with rates "10000" is a flat meter. The current protocol fee is snapshotted in and must not exceed maxFeeBps, the ceiling the provider signed for — pass MaxFeeBps to accept any legal fee. Meters are immutable once created: price, period or schedule changes are a new meter, so nothing a consumer agreed to can move underneath them.
CurrentPeriodOf is the period index now open for an enrollment.
Deposit adds the attached coins to the caller's own enrollment deposit. Elapsed usage settles first, so a top-up lands on a current balance.
Enroll opens an enrollment on a meter for the caller, with any attached coins credited as the initial deposit. One active enrollment per (meter, consumer); Exit frees the slot. Terms (price, schedule, period, fee) are copied in at this moment and never re-read.
Exit closes the caller's own enrollment: elapsed periods settle, the CURRENT period's recorded usage settles immediately (the provider served it; exiting is not an escape from it), the remaining deposit refunds in full, and the slot frees. Terminal.
PendingChargeOf is the charge the enrollment's current recorded usage would settle at — what WithdrawDeposit holds back.
PriceOf prices units of meter meterID at its schedule: the charge a period closing at exactly that usage would settle. The quote every consumer can take before enrolling and every provider can show beside an invoice.
Record asserts that the enrollment's consumer used units more units of the meter's service in the CURRENT period. Provider only. Fail-closed on the deposit bound: if charging the period's new total at the enrollment's schedule would exceed the deposited balance, the whole posting is refused — never clipped, because a clipped assertion is a wrong assertion with the same signature as a right one. Any elapsed period settles first, so the bound is always measured against the balance that will actually back this period.
Render shows the catalog at "", a meter at "meter/<id>", an enrollment at "enroll/<id>". Every user string is sanitized; every list is bounded by RenderLimit with the bound stated.
RetireMeter stops NEW enrollments and NEW usage on the caller's own meter. Existing enrollments keep their funds paths whole: pending usage still settles, deposits stay withdrawable, Exit still refunds. The provider's meter slot frees. Terminal.
ScheduleOf returns a meter's schedule as its edge and rate slices.
SetFeeBps sets the protocol fee snapshotted into NEW meters. Admin only. No existing meter or enrollment moves.
SetFeeRecipient points fee withdrawal and sweeps at recipient. Admin only.
Settle settles any fully-elapsed period of an enrollment. Permissionless by design — like the sibling realms' valves, no settlement's liveness may depend on either party showing up. No coins may ride on it, and calling it on an enrollment with nothing elapsed is a refused no-op so the event stream never carries empty settlements.
SweepDenom recovers out-of-band coins (sent by raw bank transfer, outside any entrypoint) to the fee recipient. For the ledger denom the reserve is Liabilities() — user balances and the fee pot are structurally unreachable. Fee recipient only.
TransferAdmin stages successor as the next admin; AcceptAdmin completes it. Two-step with consent — a one-step transfer bricked resources in two prior audits (service_registry Y4, permission_registry Y4).
WithdrawDeposit returns amount of the caller's own enrollment deposit. The current period's pending charge stays covered: withdrawable is balance − Charge(current usage), so a provider's already-recorded usage can never be defunded. Elapsed usage settles first.
WithdrawFees sends the accrued fee pot to the fee recipient. Only the fee recipient may call it, and only the pot moves.