Search Apps Documentation Source Content File Folder Download Copy Actions Download

assert.gno

2.13 Kb ยท 82 lines
 1package emission
 2
 3import (
 4	"gno.land/p/nt/ufmt"
 5)
 6
 7// assertValidDistributionTargets panics if any of the four distribution targets is invalid
 8// or if there are duplicate targets. All four distribution targets must be unique and valid.
 9func assertValidDistributionTargets(target01, target02, target03, target04 int) {
10	validTargets := map[int]bool{
11		LIQUIDITY_STAKER: false,
12		DEVOPS:           false,
13		COMMUNITY_POOL:   false,
14		GOV_STAKER:       false,
15	}
16
17	currentTargets := []int{target01, target02, target03, target04}
18
19	for _, target := range currentTargets {
20		if _, ok := validTargets[target]; !ok {
21			panic(makeErrorWithDetails(
22				errInvalidEmissionTarget,
23				ufmt.Sprintf("invalid target(%d)", target),
24			))
25		}
26
27		validTargets[target] = true
28	}
29
30	for _, valid := range validTargets {
31		if !valid {
32			panic(errDuplicateTarget)
33		}
34	}
35}
36
37// assertValidDistributionTarget panics if the given distribution target is invalid.
38func assertValidDistributionTarget(target int) {
39	validTargets := map[int]bool{
40		LIQUIDITY_STAKER: false,
41		DEVOPS:           false,
42		COMMUNITY_POOL:   false,
43		GOV_STAKER:       false,
44	}
45
46	if _, ok := validTargets[target]; !ok {
47		panic(makeErrorWithDetails(
48			errInvalidEmissionTarget,
49			ufmt.Sprintf("invalid target(%d)", target),
50		))
51	}
52}
53
54// assertValidDistributionPct ensures the sum of all distribution percentages equals 10000 (100%).
55// Panics if the sum does not equal exactly 10000 basis points.
56func assertValidDistributionPct(pct01, pct02, pct03, pct04 int64) {
57	// Validate individual percentages are non-negative and reasonable
58	percentages := []int64{pct01, pct02, pct03, pct04}
59	for i, pct := range percentages {
60		if pct < 0 {
61			panic(makeErrorWithDetails(
62				errInvalidEmissionPct,
63				ufmt.Sprintf("percentage %d cannot be negative: %d", i+1, pct),
64			))
65		}
66
67		if pct > 10000 {
68			panic(makeErrorWithDetails(
69				errInvalidEmissionPct,
70				ufmt.Sprintf("percentage %d cannot exceed 100%%: %d", i+1, pct),
71			))
72		}
73	}
74
75	sum := pct01 + pct02 + pct03 + pct04
76	if sum != 10000 {
77		panic(makeErrorWithDetails(
78			errInvalidEmissionPct,
79			ufmt.Sprintf("sum of percentages must be 10000, got %d", sum),
80		))
81	}
82}