Search Apps Documentation Source Content File Folder Download Copy Actions Download

assert.gno

1.45 Kb · 52 lines
 1package emission
 2
 3import (
 4	ufmt "gno.land/p/nt/ufmt/v0"
 5)
 6
 7// assertValidDistributionTarget panics if the given distribution target is invalid.
 8func assertValidDistributionTarget(target int) {
 9	validTargets := map[int]bool{
10		LIQUIDITY_STAKER: false,
11		DEVOPS:           false,
12		COMMUNITY_POOL:   false,
13		GOV_STAKER:       false,
14	}
15
16	if _, ok := validTargets[target]; !ok {
17		panic(makeErrorWithDetails(
18			errInvalidEmissionTarget,
19			ufmt.Sprintf("invalid target(%d)", target),
20		))
21	}
22}
23
24// assertValidDistributionPct ensures the sum of all distribution percentages equals 10000 (100%).
25// Panics if the sum does not equal exactly 10000 basis points.
26func assertValidDistributionPct(liquidityStakerPct, devOpsPct, communityPoolPct, govStakerPct int64) {
27	// Validate individual percentages are non-negative and reasonable
28	percentages := []int64{liquidityStakerPct, devOpsPct, communityPoolPct, govStakerPct}
29	for i, pct := range percentages {
30		if pct < 0 {
31			panic(makeErrorWithDetails(
32				errInvalidEmissionPct,
33				ufmt.Sprintf("percentage %d cannot be negative: %d", i+1, pct),
34			))
35		}
36
37		if pct > 10000 {
38			panic(makeErrorWithDetails(
39				errInvalidEmissionPct,
40				ufmt.Sprintf("percentage %d cannot exceed 100%%: %d", i+1, pct),
41			))
42		}
43	}
44
45	sum := liquidityStakerPct + devOpsPct + communityPoolPct + govStakerPct
46	if sum != 10000 {
47		panic(makeErrorWithDetails(
48			errInvalidEmissionPct,
49			ufmt.Sprintf("sum of percentages must be 10000, got %d", sum),
50		))
51	}
52}