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

deployer.gno

2.15 Kb · 50 lines
 1package access
 2
 3import (
 4	"gno.land/p/onbloc/access/manager"
 5	"gno.land/p/onbloc/ibc/union/types"
 6)
 7
 8const (
 9	CoreRealmPath       = "gno.land/r/onbloc/ibc/union/core"
10	DefaultAdminAddress = address("g1qgr7980ry7f6rqr9cs6d45y09k5u6dzhjksksn")
11)
12
13func init() {
14	resetAccess(DefaultAdminAddress)
15}
16
17// resetAccess mirrors the deploy-time setup that Union performs through its
18// deployer after instantiating AccessManager. Gno has no instantiate message, so
19// this realm uses DefaultAdminAddress as its initial admin during init.
20func resetAccess(initialAdmin address) {
21	accessState = manager.NewState()
22
23	// Mirrors initial admin bootstrap only:
24	// OZ AccessManager constructor:
25	// https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v5.6.1/contracts/access/manager/AccessManager.sol#L133-L136
26	// Union access-manager init:
27	// https://github.com/unionlabs/union/blob/8cff0ff34f6baa4cdb1e4650a08985dd05de0c5a/cosmwasm/access-manager/src/lib.rs#L148-L154
28	//
29	// RELAYER membership is separate deployer policy in Union and is granted by
30	// GrantRole, not by AccessManager initialization:
31	// https://github.com/unionlabs/union/blob/8cff0ff34f6baa4cdb1e4650a08985dd05de0c5a/cosmwasm/deployer/src/main.rs#L1143-L1152
32	accessState.GrantRole(manager.AdminRole, initialAdmin)
33	access := accessState.Roles[manager.AdminRole].Members[initialAdmin]
34	emitRoleGrantedEvent(manager.AdminRole, initialAdmin, access.Since, true)
35	setupRoles()
36}
37
38// Union reference:
39// https://github.com/unionlabs/union/blob/8cff0ff34f6baa4cdb1e4650a08985dd05de0c5a/cosmwasm/deployer/src/main.rs#L1779
40func setupRoles() {
41	accessState.SetTargetFunctionRoles(CoreRealmPath, types.RelayerSelectors(), RelayerRole)
42	for _, selector := range types.RelayerSelectors() {
43		emitTargetFunctionRoleUpdatedEvent(CoreRealmPath, selector, RelayerRole)
44	}
45	// Union deployer labels all production roles. We only bootstrap RELAYER for
46	// now; PAUSER/UNPAUSER/RATE_LIMITER are added when their roles are adopted.
47	// https://github.com/unionlabs/union/blob/8cff0ff34f6baa4cdb1e4650a08985dd05de0c5a/cosmwasm/deployer/src/main.rs#L1871-L1908
48	manager.RequireUnlockedConfigRole(RelayerRole)
49	emitRoleLabelEvent(RelayerRole, "RELAYER")
50}