assert.gno
1.71 Kb · 51 lines
1package whitelist
2
3import (
4 "gno.land/p/gnoswap/order/access/manager/v0"
5 pwhitelist "gno.land/p/gnoswap/order/whitelist/v0"
6 prbac "gno.land/p/gnoswap/rbac/v1"
7 ufmt "gno.land/p/nt/ufmt/v0"
8
9 "gno.land/r/gnoswap/access/v1"
10 "gno.land/r/gnoswap/common"
11 "gno.land/r/gnoswap/order/keeper"
12 "gno.land/r/gnoswap/pool"
13)
14
15func assertIsManagerCall(_ int, rlm realm, selector manager.Selector) realm {
16 access.AssertIsRlmCurrent(0, rlm)
17 common.AssertIsNotHandleNativeCoin()
18
19 prev := rlm.Previous()
20 caller := prev.Address()
21
22 if access.IsAuthorized(prbac.ROLE_ADMIN.String(), caller) || access.IsAuthorized(prbac.ROLE_GOVERNANCE.String(), caller) || keeper.IsAuthorized(rlm.PkgPath(), selector, caller) {
23 return prev
24 }
25
26 panic(makeErrorWithDetails(errUnauthorized, ufmt.Sprintf("caller(%s) selector(%s)", caller.String(), string(selector))).Error())
27}
28
29func assertIsValidTarget(target string) {
30 if target != TargetDCA && target != TargetLimit {
31 panic(makeErrorWithDetails(errInvalidTarget, ufmt.Sprintf("target(%s)", target)).Error())
32 }
33}
34
35func assertIsExistingPool(poolPath string) {
36 if !pool.ExistsPoolPath(poolPath) {
37 panic(makeErrorWithDetails(errInvalidPool, ufmt.Sprintf("poolPath(%s) does not exist", poolPath)).Error())
38 }
39}
40
41func assertIsNotWhitelistedPool(state *pwhitelist.State, target, poolPath string) {
42 if state.HasPool(poolPath) {
43 panic(makeErrorWithDetails(errInvalidPool, ufmt.Sprintf("target(%s) poolPath(%s) is already whitelisted", target, poolPath)).Error())
44 }
45}
46
47func assertIsWhitelistedPool(state *pwhitelist.State, target, poolPath string) {
48 if !state.HasPool(poolPath) {
49 panic(makeErrorWithDetails(errInvalidPool, ufmt.Sprintf("target(%s) poolPath(%s) is not whitelisted", target, poolPath)).Error())
50 }
51}