assert.gno
1.88 Kb · 65 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// Order protocol role names. They are not RBAC system roles: admin or
11// governance registers them via rbac.RegisterRole, mapped to the order proxy
12// realm addresses (gno.land/r/gnoswap/order/dca and gno.land/r/gnoswap/order/limit).
13const (
14 roleOrderDCA = "order_dca"
15 roleOrderLimit = "order_limit"
16)
17
18// assertIsAuthorizedFeeCaller panics unless the caller is a fee-producing realm:
19// pool, position, router, staker, or the DCA/limit order realms.
20func assertIsAuthorizedFeeCaller(caller address) {
21 if access.IsAuthorized(prbac.ROLE_POOL.String(), caller) ||
22 access.IsAuthorized(prbac.ROLE_POSITION.String(), caller) ||
23 access.IsAuthorized(prbac.ROLE_ROUTER.String(), caller) ||
24 access.IsAuthorized(prbac.ROLE_STAKER.String(), caller) ||
25 access.IsAuthorized(roleOrderDCA, caller) ||
26 access.IsAuthorized(roleOrderLimit, caller) {
27 return
28 }
29
30 panic(ufmt.Errorf("unauthorized: caller %s is not pool or position or router or staker or order", caller))
31}
32
33// assertIsAdminOrGovStaker panics if the caller is not admin or gov/staker.
34func assertIsAdminOrGovStaker(caller address) {
35 if access.IsAuthorized(prbac.ROLE_ADMIN.String(), caller) {
36 return
37 }
38
39 if access.IsAuthorized(prbac.ROLE_GOV_STAKER.String(), caller) {
40 return
41 }
42
43 panic(ufmt.Errorf("unauthorized: caller %s is not admin or gov/staker", caller))
44}
45
46// assertIsValidPercent panics if the percentage is invalid (not between 0-10000).
47func assertIsValidPercent(pct int64) {
48 if pct > 10000 {
49 panic(makeErrorWithDetail(
50 errInvalidPct,
51 ufmt.Sprintf("pct(%d) should not be bigger than 10000", pct),
52 ))
53 }
54
55 if pct < 0 {
56 panic(makeErrorWithDetail(
57 errInvalidPct,
58 ufmt.Sprintf("pct(%d) should not be smaller than 0", pct),
59 ))
60 }
61}
62
63func assertNotImplementYet() {
64 panic("NotImplementYet")
65}