Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

grants source realm

Realm grants is a decentralized grants market: a creator escrows GNOT behind a grant with an application deadline, ap...

Overview

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):

Example
 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:

Example
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.

Constants 4

const MaxTitleLen, MaxDescLen, MaxPitchLen, MinDurationBlocks, MaxDurationBlocks, ExpiryGraceBlocks

 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)
source

Input bounds.

const Denom

1const Denom = "ugnot"
source

Denom is the only asset this realm accepts.

const MaxFeeBps

1const MaxFeeBps = int64(1000)
source

MaxFeeBps is the hard protocol-fee cap: 1000 bps = 10%.

Functions 27

func ApplicationOf

Action
1func ApplicationOf(id int64, addr address) (pitch string, height int64, ok bool)
source

ApplicationOf returns addr's pitch and submission height for a grant, with ok reporting whether an application exists.

func Apply

crossing Action
1func Apply(cur realm, id int64, pitch string)
source

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.

func BalanceOf

Action
1func BalanceOf(addr address) int64
source

BalanceOf returns addr's claimable balance (won grants + refunds).

func CancelGrant

crossing Action
1func CancelGrant(cur realm, id int64)
source

CancelGrant closes an open grant and refunds its escrow to the creator's claimable balance, fee-free. Only the creator may cancel. Terminal.

func Claim

crossing Action
1func Claim(cur realm, amount int64)
source

Claim sends amount ugnot of the caller's claimable balance (won grants and refunds) back to the caller.

func ClaimAll

crossing Action
1func ClaimAll(cur realm)
source

ClaimAll sends the caller's entire claimable balance back to the caller. Fails if there is nothing to claim.

func CreateGrant

crossing Action
1func CreateGrant(cur realm, title, description string, durationBlocks, maxFeeBps int64) int64
source

CreateGrant 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.

func ExpireGrant

crossing Action
1func ExpireGrant(cur realm, id int64)
source

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.

func FeeBps

Action
1func FeeBps() int64
source

FeeBps returns the fee that will be snapshotted into newly created grants (existing grants keep their own snapshot).

func FeeOn

Action
1func FeeOn(amount int64) (fee, credited int64)
source

FeeOn previews the fee and net payout for a grant of amount at the CURRENT FeeBps.

func GrantInfo

Action
1func GrantInfo(id int64) (creator address, title string, amount, feeBps, deadline int64, status string, winner address, numApplicants int64)
source

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.

func Height

Action
1func Height() int64
source

Height returns the current chain height (deadline arithmetic aid).

func Held

Action
1func Held() int64
source

Held returns the ugnot actually held at the realm address (H).

func Liabilities

Action
1func Liabilities() int64
source

Liabilities returns everything this realm owes: openTotal + UsersTotal + FeesAccrued.

func OpenTotal

Action
1func OpenTotal() int64
source

OpenTotal returns the escrow held by open grants (the G term).

func Render

1func Render(path string) string
source

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.

func SelectWinner

crossing Action
1func SelectWinner(cur realm, id int64, winner address)
source

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.

func SetFeeBps

crossing Action
1func SetFeeBps(cur realm, bps int64)
source

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].

func SetFeeRecipient

crossing Action
1func SetFeeRecipient(cur realm, next address)
source

SetFeeRecipient re-points the fee/surplus role, including the pot accrued so far. Admin only; zero address rejected.

func SweepDenom

crossing Action
1func SweepDenom(cur realm, denom string)
source

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.

func TransferAdmin

crossing Action
1func TransferAdmin(cur realm, next address)
source

TransferAdmin hands the admin role to next. Admin only; zero address rejected. One-step (documented trade-off).

func UsersTotal

Action
1func UsersTotal() int64
source

UsersTotal returns the sum of all claimable balances (the U term).

func WithdrawFees

crossing Action
1func WithdrawFees(cur realm)
source

WithdrawFees sends the accrued fee pot to the fee recipient. Only the fee recipient may call it.

Imports 8

Source Files 2