assert.gno
1.36 Kb ยท 50 lines
1package v1
2
3import (
4 prbac "gno.land/p/gnoswap/rbac"
5 "gno.land/p/nt/ufmt"
6
7 "gno.land/r/gnoswap/access"
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}