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

assert.gno

1.45 Kb · 54 lines
 1package protocol_fee
 2
 3import (
 4	prbac "gno.land/p/gnoswap/rbac/v1"
 5	ufmt "gno.land/p/nt/ufmt/v0"
 6
 7	"gno.land/r/gnoswap/access/v1"
 8)
 9
10// assertIsPoolOrPositionOrRouterOrStaker panics if the caller is not the pool, router, or staker contract.
11func assertIsPoolOrPositionOrRouterOrStaker(caller address) {
12	if access.IsAuthorized(prbac.ROLE_POOL.String(), caller) ||
13		access.IsAuthorized(prbac.ROLE_POSITION.String(), caller) ||
14		access.IsAuthorized(prbac.ROLE_ROUTER.String(), caller) ||
15		access.IsAuthorized(prbac.ROLE_STAKER.String(), caller) {
16		return
17	}
18
19	panic(ufmt.Errorf("unauthorized: caller %s is not pool or position or router or staker", caller))
20}
21
22// assertIsAdminOrGovStaker panics if the caller is not admin or gov/staker.
23func assertIsAdminOrGovStaker(caller address) {
24	if access.IsAuthorized(prbac.ROLE_ADMIN.String(), caller) {
25		return
26	}
27
28	if access.IsAuthorized(prbac.ROLE_GOV_STAKER.String(), caller) {
29		return
30	}
31
32	panic(ufmt.Errorf("unauthorized: caller %s is not admin or gov/staker", caller))
33}
34
35// assertIsValidPercent panics if the percentage is invalid (not between 0-10000).
36func assertIsValidPercent(pct int64) {
37	if pct > 10000 {
38		panic(makeErrorWithDetail(
39			errInvalidPct,
40			ufmt.Sprintf("pct(%d) should not be bigger than 10000", pct),
41		))
42	}
43
44	if pct < 0 {
45		panic(makeErrorWithDetail(
46			errInvalidPct,
47			ufmt.Sprintf("pct(%d) should not be smaller than 0", pct),
48		))
49	}
50}
51
52func assertNotImplementYet() {
53	panic("NotImplementYet")
54}