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

/p/moul/vesting/v0

Directory · 4 Files
README.md Open

p/moul/vesting

The vesting curve the gno.land chain itself enforces, as a pure calculator.

This is not a vesting scheme of its own. It is a faithful reimplementation of tm2's std.VestingSchedule, so a realm can answer "how much of this balance can actually move right now" with the same arithmetic the ante handler uses. Divergence here would be worse than useless, so every rule is copied from tm2/pkg/std/vesting.go rather than designed.

1s, err := vesting.New(106560000000, 1789225200, 1852383600, vesting.Continuous)
2s.Vested(now)              // how much has unlocked
3s.Locked(now)              // what the chain still refuses to move
4s.Spendable(balance, now)  // what can actually leave the account
5s.PermilleVested(now)      // tenths of a percent, for display

The rules, all of them from tm2

Continuous vests linearly between Start and End
Delayed a cliff: nothing before End, everything at or after it, and Start is ignored
rounding down, always
a zero Original means no schedule, which locks nothing
times unix seconds, never compared against the chain's clock

Rounding down is the direction that matters. Reporting one ugnot more than the chain will move turns a page into a lie somebody acts on.

Spendable caps the locked part at the balance: an account that spent while its coins were free can owe the schedule more than it now holds, and the honest answer there is that nothing moves, not a negative number.

Why this is not p/moul/x/daily/cliffvesting

That package is the employee-grant shape (start, cliff, end) for amounts a person is granted. This one is the chain's shape, for amounts a chain holds, and the difference is not only the curve:

cliffvesting v0 multiplied in plain int64. Over the real mainnet term of 63,158,400 seconds that wraps for any grant above 146,036 GNOT, silently: a 318,720,000 GNOT grant returned -6,264,395,224, a negative vested amount that every caller would have treated as real. tm2 reaches for math/big at exactly this point. gno has no math/big, so Vested goes through a 128-bit intermediate via math/bits. cliffvesting v1 now does the same.

The largest schedule this has to survive is the whole genesis allocation, 1,332,999,998 GNOT, and the tests take it there.

What this package cannot do

Find out an address's schedule. Realm code cannot read one. The VM's whole view of an account is banker.GetCoins, which returns the total balance with the locked part included, and no native exposes std.VestingSchedule. The schedule has to come from the caller.

r/moul/vesting is what that constraint looks like in a page.


Part of moul/gno-contracts — moul's versioned gno.land contracts. See the repository for the full catalog, build/test tooling, and usage.

⚠️ Disclaimer: provided as-is, without warranty; not security-audited. Full disclaimer: DISCLAIMER.