Skip to content Search Apps Documentation Source Content Run Reset Eval Playground File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

mimir source pure

Package mimir holds the pure helpers Mimir's market realms share: stake history checkpoints (settlement cutoffs) and ...

Overview

Package mimir holds the pure helpers Mimir's market realms share: stake history checkpoints (settlement cutoffs) and overflow-safe arithmetic.

Constants 1

const TimelockSeconds

1const TimelockSeconds = int64(2 * 24 * 60 * 60)
source

TimelockSeconds delays ownership, oracle and fee-recipient changes.

Functions 6

func Add

1func Add(a, b int64) int64
source

Add returns a+b, panicking on overflow, so a sum of stakes can never wrap.

func Escape

1func Escape(s string) string
source

Escape makes user text safe to place in gnoweb markdown: it cannot open links, images, HTML or headings.

func FormatUSD

1func FormatUSD(units int64) string
source

FormatUSD renders 6-decimal units as a dollar amount with two decimals, rounded down.

func MulDiv

1func MulDiv(a, b, d int64) int64
source

MulDiv returns floor(a*b/d) without overflowing the 128-bit product. It panics on negative inputs, a zero divisor or a result above int64.

func Quote

1func Quote(s string) string
source

Quote returns s as a JSON string literal.

func NewRoles

1func NewRoles(owner, arbiter, oracle, feeRecipient address) *Roles
source

NewRoles validates the initial roles as the EVM constructors did.

Types 4

type Amounts

struct
1type Amounts struct {
2	A, B, CopiedA, CopiedB int64
3}
source

Amounts are cumulative net deposits on each side, and the copied part of each.

type Checkpoint

struct
1type Checkpoint struct {
2	At      int64 // unix seconds
3	Amounts Amounts
4}
source

type History

struct
1type History struct {
2	points []Checkpoint
3}
source

History is an append-only list of checkpoints in time order. Deposits in the same second coalesce into one checkpoint. Settlement never scans all deposits.

Methods on History

func Before

method on History
1func (h *History) Before(cutoff int64) Amounts
source

Before returns the totals recorded strictly before cutoff. A cutoff of 0 means no cutoff: the latest totals.

func Len

method on History
1func (h *History) Len() int
source

func Record

method on History
1func (h *History) Record(now int64, a Amounts)
source

Record stores the running totals as of `now`.

type Roles

struct
 1type Roles struct {
 2	Owner               address
 3	Arbiter             address
 4	AuditAgent          address
 5	Oracle              address
 6	FeeRecipient        address
 7	PendingOwner        address
 8	PendingOwnerEta     int64
 9	PendingOracle       address
10	PendingOracleEta    int64
11	PendingFeeRecipient address
12	PendingFeeEta       int64
13	Paused              bool
14	MaxAccountStake     int64
15	MaxMarketStake      int64
16}
source

Roles holds a market realm's roles, pause flag and guarded-launch caps, and enforces the same rules the EVM contracts do:

  • two-step ownership with a timelock;
  • a timelocked oracle change the owner can revoke at once;
  • the oracle is never also the owner, the arbiter or the fee recipient;
  • the audit agent may only dispute, and never holds another role;
  • a timelocked fee-recipient change;
  • queued changes are executed by anyone once due.

Every method takes the caller and the block time from the realm, which owns the Roles value.

Methods on Roles

func AcceptOwnership

method on Roles
1func (r *Roles) AcceptOwnership(caller address, now int64)
source

func AssertOwner

method on Roles
1func (r *Roles) AssertOwner(caller address)
source

func CheckCaps

method on Roles
1func (r *Roles) CheckCaps(mine, total int64)
source

CheckCaps panics when an account's stake or a market's total is over its cap.

func QueueFeeRecipient

method on Roles
1func (r *Roles) QueueFeeRecipient(caller, next address, now int64)
source

func QueueOracle

method on Roles
1func (r *Roles) QueueOracle(caller, next address, now int64)
source

func RevokeOracle

method on Roles
1func (r *Roles) RevokeOracle(caller address)
source

RevokeOracle is the emergency stop: the oracle loses its power at once.

func SetArbiter

method on Roles
1func (r *Roles) SetArbiter(caller, next address)
source

func SetAuditAgent

method on Roles
1func (r *Roles) SetAuditAgent(caller, next address)
source

SetAuditAgent appoints the reviewer that may dispute with a bond; "" disables it.

func SetCaps

method on Roles
1func (r *Roles) SetCaps(caller address, market, account int64)
source

SetCaps sets guarded launch caps in mUSD units (0 = none). They only gate new positions.

func SetPaused

method on Roles
1func (r *Roles) SetPaused(caller address, p bool)
source

func TransferOwnership

method on Roles
1func (r *Roles) TransferOwnership(caller, next address, now int64)
source

Dependencies

Imports 4

/p/g12dcsmwccgdxasqde2eumua88tlrkw83kqf6tcz/mimir

Imported by indexer

Source Files 6