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

bounties source realm

Realm bounties is a GNOT bounty board that COMPOSES the reusable accounting package gno.land/p/g1ut6uspuh73e02yauxpmy...

Overview

Realm bounties is a GNOT bounty board that COMPOSES the reusable accounting package gno.land/p/g1ut6uspuh73e02yauxpmyt8g3wwddaq8utagvm3/feeledger instead of re-implementing balance accounting.

STATE OWNERSHIP (the dependency boundary):

  • This realm owns the bounty state machine: bounty records (funder, title, amount, status, winner), the sum of open escrow (openTotal), and per-bounty funder authorization.
  • feeledger owns all claimable-balance accounting: per-account balances, the protocol-fee pot, fee rounding, overflow checks, and withdraw arithmetic. This realm never duplicates that logic; it only calls the ledger API and panics on its errors.

LIFECYCLE:

Example
1CreateBounty (EOA + -send)  : escrow -> openTotal, status Open
2Award (funder only)         : openTotal -> ledger.Deposit(winner,
3                              amount, snapshot fee)
4Cancel (funder only)        : openTotal -> ledger.Deposit(funder,
5                              amount, 0)       [no fee on refund]
6Claim / ClaimAll (anyone)   : pays out the caller's ledger balance
7WithdrawFees (fee recipient): pays out the fee pot

Awarded and Cancelled are terminal; a bounty transitions exactly once.

FEE MODEL: fee = floor(amount * bps / 10000), rounding favors the recipient, no minimum fee, admin-settable up to the compile-time MaxFeeBps cap, accrued to a pot withdrawable by the fee recipient role. The applicable bps is SNAPSHOTTED INTO THE BOUNTY AT CREATION and charged at Award: the funder commits to the fee they saw, and a later SetFeeBps affects only bounties created afterwards (this closes the admin front-run found in the composition audit). Refunds via Cancel are always fee-free. A failed Award (e.g. ledger overflow) leaves the bounty Open — the funder can retry or Cancel.

COMPOSED ACCOUNTING INVARIANT: let H be ugnot held at this realm's address, B = openTotal (application escrow), U+F the ledger's liabilities, S >= 0 out-of-band surplus. At every transaction boundary:

Example
1H == B + U + F + S

Derivation: CreateBounty raises H and B equally (the IsUserCall + envelope guard is the receipt-guaranteed shape, validated live on pearl-1); Award/Cancel move amount from B into U+F within one transaction, and feeledger guarantees credited + fee == amount; Claim/WithdrawFees debit the ledger before sending the identical amount (checks-effects-interactions), lowering H and U+F equally; any panic aborts the whole transaction; this realm never issues or removes coins. The application invariant B == Σ amount(Open) is maintained in lockstep with every status transition.

ONLY GNOT: CreateBounty rejects any envelope that is not exactly one positive ugnot coin. Foreign denominations force-sent to the realm sit in surplus and are recoverable via SweepDenom (fee recipient only), which never touches B, U, or F.

Constants 3

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 21

func Award

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

Award closes an open bounty in favor of winner: the escrowed amount leaves the open pool and is credited to winner's claimable balance through the ledger, charging the fee snapshotted at creation. Only the bounty's funder may award it. Terminal: an awarded bounty can never change again.

func BalanceOf

Action
1func BalanceOf(addr address) int64
source

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

func BountyInfo

Action
1func BountyInfo(id int64) (funder address, title string, amount, feeBps int64, status string, winner address)
source

BountyInfo returns a bounty's fields by value: funder, title, amount, snapshotted fee bps, status, winner (zero address unless awarded).

func Cancel

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

Cancel closes an open bounty and refunds its escrow to the funder's claimable balance, fee-free. Only the bounty's funder may cancel. Terminal: a cancelled bounty can never change again.

func Claim

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

Claim sends amount ugnot of the caller's claimable balance (won bounties 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 CreateBounty

crossing Action
1func CreateBounty(cur realm, title string) int64
source

CreateBounty escrows the attached GNOT as a new open bounty and returns its id. Only direct EOA calls with -send are accepted (the receipt-guaranteed shape). The envelope must be exactly one positive ugnot coin. The caller becomes the bounty's funder.

func FeeBps

Action
1func FeeBps() int64
source

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

func Held

Action
1func Held() int64
source

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

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 bounties (the B term).

func Render

1func Render(_ string) string
source

Render shows configuration, totals, the composed conservation check, and the most recent bounties (bounded page, newest first).

func SetFeeBps

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

SetFeeBps sets the protocol fee snapshotted into FUTURE bounties at creation. Existing bounties 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 Surplus

Action
1func Surplus() int64
source

Surplus returns Held() - Liabilities() (the S term; >= 0 unless a conservation bug exists).

func SweepDenom

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

SweepDenom sends the surplus of a single denomination to the fee recipient (the bounded escape hatch validated on the vault realm). 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, as on the vault).

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 6

Source Files 2