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.

Playground

cliffvestingdemo.gno

// Package cliffvestingdemo is a small gnoweb demo of the vesting calculator
// provided by the [p/moul/x/daily/cliffvesting](/p/nym-moultest123/x/daily/cliffvesting/v0)
// library: the cliff step, the linear ramp, and integer rounding.
//
// It contains no vesting logic of its own and holds no coins. Stateless, so
// Render is deterministic — which is precisely what the library is for.
package cliffvestingdemo

import (
	"strconv"
	"strings"

	"gno.land/p/nym-moultest123/x/daily/cliffvesting/v0"
)

// Render renders the demo for gnoweb.
func Render(path string) string {
	var b strings.Builder
	b.WriteString("# Cliff Vesting\n\n")
	b.WriteString("A pure vesting calculator, demoing the ")
	b.WriteString("[`p/moul/x/daily/cliffvesting`](/p/nym-moultest123/x/daily/cliffvesting/v0) library.\n\n")

	// 1200 tokens over 12 months, 3-month cliff.
	s, err := cliffvesting.New(1200, 0, 3, 12)
	if err != nil {
		return "error: " + err.Error()
	}

	b.WriteString("## A 12-month grant with a 3-month cliff\n\n")
	b.WriteString("`1200` tokens, `Start = 0`, `Cliff = 3`, `End = 12`.\n\n")
	b.WriteString("| month | vested | unvested | % |\n|---|---|---|---|\n")
	for m := int64(0); m <= 12; m++ {
		note := ""
		switch m {
		case 2:
			note = " ← nothing yet"
		case 3:
			note = " ← **cliff**"
		case 12:
			note = " ← fully vested"
		}
		b.WriteString("| " + strconv.FormatInt(m, 10) + " | " +
			strconv.FormatInt(s.Vested(m), 10) + " | " +
			strconv.FormatInt(s.Unvested(m), 10) + " | " +
			strconv.FormatInt(s.PercentVested(m), 10) + "%" + note + " |\n")
	}

	b.WriteString("\nThe cliff is a **step, not a ramp**: at month 3 a quarter of the term ")
	b.WriteString("has elapsed, so `")
	b.WriteString(strconv.FormatInt(s.CliffAmount(), 10))
	b.WriteString("` tokens unlock at once. After that it accrues linearly.\n\n")

	b.WriteString("## Claiming\n\n")
	b.WriteString("The library tracks no balances — the caller supplies what has already ")
	b.WriteString("been claimed:\n\n")
	b.WriteString("| at month | already claimed | claimable |\n|---|---|---|\n")
	for _, c := range [][2]int64{{6, 0}, {6, 300}, {6, 600}, {12, 600}} {
		b.WriteString("| " + strconv.FormatInt(c[0], 10) + " | " +
			strconv.FormatInt(c[1], 10) + " | " +
			strconv.FormatInt(s.Claimable(c[0], c[1]), 10) + " |\n")
	}

	b.WriteString("\n## Integer rounding\n\n")
	b.WriteString("All arithmetic is integer — no float ever reaches consensus state. ")
	b.WriteString("Rounding is **down**, so nobody is ever paid more than they earned, ")
	b.WriteString("and the final instalment collects the remainder.\n\n")
	odd, _ := cliffvesting.NewLinear(1000, 0, 3)
	b.WriteString("`1000` over `3` periods:\n\n")
	b.WriteString("| t | vested |\n|---|---|\n")
	for m := int64(0); m <= 3; m++ {
		b.WriteString("| " + strconv.FormatInt(m, 10) + " | " +
			strconv.FormatInt(odd.Vested(m), 10) + " |\n")
	}
	b.WriteString("\n`333 + 333 + 334` — the end is exactly `1000`, never `999`.\n\n")

	b.WriteString("## The bug this avoids\n\n")
	tiny, _ := cliffvesting.NewLinear(7, 0, 1000)
	b.WriteString("When the total is smaller than the duration, computing a per-tick rate ")
	b.WriteString("first truncates it to zero and **nothing ever vests**. Multiplying ")
	b.WriteString("before dividing keeps it honest — `7` tokens over `1000` ticks:\n\n")
	b.WriteString("| t | vested |\n|---|---|\n")
	for _, m := range []int64{100, 150, 500, 1000} {
		b.WriteString("| " + strconv.FormatInt(m, 10) + " | " +
			strconv.FormatInt(tiny.Vested(m), 10) + " |\n")
	}
	return b.String()
}

gnomod.toml

module = "gno.land/r/nym-moultest123/x/daily/cliffvestingdemo/v0"
gno = "0.9"

[addpkg]
  creator = "g1ml9grtwnpzqn3hre5ve5vjdlmv2srrmpmc0dsv"
  height = 186410
  max_deposit = "5000000ugnot"

render_example_test.gno

package cliffvestingdemo

// ExampleRender pins the realm's Render output as a testable example.
func ExampleRender() {
	print(Render(""))
	// Output:
	// # Cliff Vesting
	//
	// A pure vesting calculator, demoing the [`p/moul/x/daily/cliffvesting`](/p/nym-moultest123/x/daily/cliffvesting/v0) library.
	//
	// ## A 12-month grant with a 3-month cliff
	//
	// `1200` tokens, `Start = 0`, `Cliff = 3`, `End = 12`.
	//
	// | month | vested | unvested | % |
	// |---|---|---|---|
	// | 0 | 0 | 1200 | 0% |
	// | 1 | 0 | 1200 | 0% |
	// | 2 | 0 | 1200 | 0% ← nothing yet |
	// | 3 | 300 | 900 | 25% ← **cliff** |
	// | 4 | 400 | 800 | 33% |
	// | 5 | 500 | 700 | 41% |
	// | 6 | 600 | 600 | 50% |
	// | 7 | 700 | 500 | 58% |
	// | 8 | 800 | 400 | 66% |
	// | 9 | 900 | 300 | 75% |
	// | 10 | 1000 | 200 | 83% |
	// | 11 | 1100 | 100 | 91% |
	// | 12 | 1200 | 0 | 100% ← fully vested |
	//
	// The cliff is a **step, not a ramp**: at month 3 a quarter of the term has elapsed, so `300` tokens unlock at once. After that it accrues linearly.
	//
	// ## Claiming
	//
	// The library tracks no balances — the caller supplies what has already been claimed:
	//
	// | at month | already claimed | claimable |
	// |---|---|---|
	// | 6 | 0 | 600 |
	// | 6 | 300 | 300 |
	// | 6 | 600 | 0 |
	// | 12 | 600 | 600 |
	//
	// ## Integer rounding
	//
	// All arithmetic is integer — no float ever reaches consensus state. Rounding is **down**, so nobody is ever paid more than they earned, and the final instalment collects the remainder.
	//
	// `1000` over `3` periods:
	//
	// | t | vested |
	// |---|---|
	// | 0 | 0 |
	// | 1 | 333 |
	// | 2 | 666 |
	// | 3 | 1000 |
	//
	// `333 + 333 + 334` — the end is exactly `1000`, never `999`.
	//
	// ## The bug this avoids
	//
	// When the total is smaller than the duration, computing a per-tick rate first truncates it to zero and **nothing ever vests**. Multiplying before dividing keeps it honest — `7` tokens over `1000` ticks:
	//
	// | t | vested |
	// |---|---|
	// | 100 | 0 |
	// | 150 | 1 |
	// | 500 | 3 |
	// | 1000 | 7 |
}