const StatusOpen, StatusAwarded, StatusCancelled, StatusExpired
Grant status values.
Realm grants is a decentralized grants market: a creator escrows GNOT behind a grant with an application deadline, ap...
Realm grants is a decentralized grants market: a creator escrows GNOT behind a grant with an application deadline, applicants apply on-chain, the creator selects one applicant, and the winner claims the funding minus a transparent protocol fee.
COMPOSITION (per the recorded DISCOVERY / REUSE ANALYSIS): all balance accounting is delegated to feeledger, all coin movement to coinio, and all free-text render output to the ecosystem sanitizer p/nt/markdown/sanitize/v0. This realm owns only the grants state machine: grant records, per-grant applications, open-escrow total, deadlines, and roles.
LIFECYCLE (terminal states are frozen; one transition per grant):
1CreateGrant (EOA + -send) : escrow -> openTotal, status Open,
2 fee bps SNAPSHOTTED at creation
3Apply (also re-apply/update) : while Open and height < deadline;
4 keyed by the caller's own address
5SelectWinner (creator only) : Open -> Awarded; winner MUST be an
6 applicant; escrow -> winner's
7 claimable balance minus the
8 snapshotted fee
9CancelGrant (creator only) : Open -> Cancelled; fee-free refund
10 to the creator's claimable balance
11ExpireGrant (ANYONE) : Open -> Expired once height >=
12 deadline + ExpiryGraceBlocks;
13 fee-free refund to the creator —
14 the permissionless valve that makes
15 fund-trapping impossible
16Claim / ClaimAll (anyone) : pays out the caller's own ledger
17 balance (winners and refunds)
18WithdrawFees (fee recipient) : pays out the fee pot
AUTHORIZATION: every identity is derived from the crossing entrypoint's cur.Previous().Address() — no function takes a caller identity as a parameter. Applications and claimable balances are keyed by that runtime-derived address, so altering another user's application or claiming another user's grant is impossible by construction. The creator cannot apply to their own grant, and SelectWinner only accepts addresses that actually applied.
DEADLINE SEMANTICS: deadline = ChainHeight() + durationBlocks, fixed at creation (bounded by [MinDurationBlocks, MaxDurationBlocks]). The deadline gates NEW/UPDATED applications only; the creator may select or cancel at any time while the grant is Open. After deadline + ExpiryGraceBlocks anyone may expire the grant.
FEE MODEL: fee = floor(amount * bps / 10000), rounding favors the winner; no minimum fee; bps snapshotted into the grant at creation, so SetFeeBps affects future grants only (closes the AWARD-time admin race), and CreateGrant takes the caller's own maxFeeBps ceiling, rejecting creation if the live fee exceeds what the creator signed for (closes the CREATION-time race — audit Y1); hard compile-time cap MaxFeeBps (10%); refunds (cancel/expire) are always fee-free; the pot is withdrawable by the fee-recipient role.
MONETARY INVARIANT (conservation): let H be ugnot held at this realm's address, G = openTotal (Σ amount over Open grants), U the ledger's claimable balances, F the fee pot, S >= 0 out-of-band surplus:
1H == G + U + F + S
Every transition moves value between exactly two terms inside one transaction: CreateGrant raises H and G together (coinio.Receive is the receipt-guaranteed shape, validated live on pearl-1); SelectWinner/CancelGrant/ExpireGrant move amount from G into U+F with feeledger guaranteeing credited + fee == amount; claims and fee withdrawal debit the ledger before coinio.Payout moves the identical amount out (checks-effects-interactions); any panic aborts the whole transaction; this realm never issues or removes coins. Surplus is recoverable only via SweepDenom (fee recipient), which reserves Liabilities() = G + U + F.
ONLY GNOT: CreateGrant rejects any envelope that is not exactly one positive ugnot coin (coinio.Receive). Foreign denominations sit in surplus.
Grant status values.
1const (
2 MaxTitleLen = 80
3 MaxDescLen = 2000
4 MaxPitchLen = 1000
5
6 // MinDurationBlocks / MaxDurationBlocks bound the application
7 // window a creator may configure (~5s blocks: 1 block to ~580 days).
8 MinDurationBlocks = int64(1)
9 MaxDurationBlocks = int64(10_000_000)
10
11 // ExpiryGraceBlocks after the deadline, an Open grant becomes
12 // expirable by anyone (~8 minutes at 5s blocks — short because
13 // this is a testnet deployment; a production fork would raise it).
14 ExpiryGraceBlocks = int64(100)
15)Input bounds.
Denom is the only asset this realm accepts.
MaxFeeBps is the hard protocol-fee cap: 1000 bps = 10%.
ApplicationOf returns addr's pitch and submission height for a grant, with ok reporting whether an application exists.
Apply submits (or re-submits) the caller's application to an open grant before its deadline. One application per address per grant — re-applying replaces the caller's own pitch only. The creator cannot apply to their own grant.
BalanceOf returns addr's claimable balance (won grants + refunds).
CancelGrant closes an open grant and refunds its escrow to the creator's claimable balance, fee-free. Only the creator may cancel. Terminal.
Claim sends amount ugnot of the caller's claimable balance (won grants and refunds) back to the caller.
ClaimAll sends the caller's entire claimable balance back to the caller. Fails if there is nothing to claim.
1func CreateGrant(cur realm, title, description string, durationBlocks, maxFeeBps int64) int64CreateGrant escrows the attached GNOT as a new open grant and returns its id. Only direct EOA calls with -send are accepted. The current protocol fee is snapshotted into the grant — and must not exceed maxFeeBps, the ceiling the caller signed for (rejects a fee raise sequenced ahead of this transaction); pass MaxFeeBps to accept any legal fee. The application window is durationBlocks from now.
Description returns a grant's raw description text.
ExpireGrant closes an open grant whose deadline passed more than ExpiryGraceBlocks ago, refunding the creator fee-free. ANYONE may call it — this is the permissionless valve that guarantees escrow can never be trapped by an inactive creator. Terminal.
FeeBps returns the fee that will be snapshotted into newly created grants (existing grants keep their own snapshot).
FeeOn previews the fee and net payout for a grant of amount at the CURRENT FeeBps.
FeesAccrued returns the fee pot (the F term).
1func GrantInfo(id int64) (creator address, title string, amount, feeBps, deadline int64, status string, winner address, numApplicants int64)GrantInfo returns a grant's fields by value: creator, title, amount, snapshotted fee bps, application deadline (block height), status, winner (zero unless awarded), and number of applicants.
Height returns the current chain height (deadline arithmetic aid).
Held returns the ugnot actually held at the realm address (H).
Liabilities returns everything this realm owes: openTotal + UsersTotal + FeesAccrued.
NumGrants returns how many grants have ever been created.
OpenTotal returns the escrow held by open grants (the G term).
Render shows the market at "" and a grant detail at "<id>". Free text (titles are charset-restricted; descriptions are not) passes through the ecosystem sanitizer before hitting markdown.
SelectWinner awards an open grant to one of its applicants: the escrow leaves the open pool and is credited to the winner's claimable balance through the ledger, charging the fee snapshotted at creation. Only the grant's creator may select, and only an address that actually applied can win. Terminal.
SetFeeBps sets the protocol fee snapshotted into FUTURE grants at creation. Existing grants keep the fee they were created under. Admin only; bounded by [0, MaxFeeBps].
SetFeeRecipient re-points the fee/surplus role, including the pot accrued so far. Admin only; zero address rejected.
Surplus returns Held() - Liabilities() (the S term).
SweepDenom sends the surplus of a single denomination to the fee recipient. For ugnot only the excess over Liabilities() moves; other denoms move wholly. Only the fee recipient may call it.
TransferAdmin hands the admin role to next. Admin only; zero address rejected. One-step (documented trade-off).
UsersTotal returns the sum of all claimable balances (the U term).
WithdrawFees sends the accrued fee pot to the fee recipient. Only the fee recipient may call it.