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

v1 source realm

Readme View source

RBAC

Role-based access control management realm.

Overview

RBAC realm manages role addresses and permissions for the GnoSwap protocol, integrating with the access package.

Configuration

  • Admin/Governance Control: Role management by admin or governance
  • Dynamic Roles: Add/remove at runtime
  • Access Integration: Syncs with access package
  • Owner-Managed Admin Role: admin role is bound to RBAC owner and cannot be updated via UpdateRoleAddress

Key Functions

RegisterRole(cur realm, roleName string, roleAddress address)

Registers new role in system. Only callable by admin or governance.

RemoveRole(cur realm, roleName string)

Removes existing role. Only callable by admin or governance. System roles cannot be removed.

UpdateRoleAddress(cur realm, roleName string, addr address)

Updates address for role. Only callable by admin or governance. The admin role is not updatable via this function and is managed through ownership transfer.

GetRoleAddress(roleName string) (address, error)

Returns address for role.

IsOwner(addr address) bool

Returns true if addr is the current owner.

IsPendingOwner(addr address) bool

Returns true if addr is the pending owner.

GetOwner() address

Returns the current owner address.

GetPendingOwner() address

Returns the pending owner address.

TransferOwnership(cur realm, newOwner address)

Initiates two-step ownership transfer. Only callable by current owner.

AcceptOwnership(cur realm)

Accepts pending ownership transfer. Only callable by pending owner. Also updates the admin role address and syncs it to the access package.

Gnoweb

Render("") shows the owner, pending owner (None when absent), and the fixed system-role assignments. Unassigned roles are explicit; custom roles are not enumerated. Unsupported paths return 404.

Usage

 1// Register new role (requires admin or governance)
 2RegisterRole(cross(cur), "new_role", roleAddress)
 3
 4// Update role address
 5UpdateRoleAddress(cross(cur), "staker", newAddress)
 6
 7// Admin role is updated via ownership transfer
 8TransferOwnership(cross(cur), newAdmin)
 9AcceptOwnership(cross(cur))
10
11// Get role address
12addr, err := GetRoleAddress("router")
13
14// Transfer ownership (two-step)
15TransferOwnership(cross(cur), newAdmin) // Step 1: Initiate
16AcceptOwnership(cross(cur))             // Step 2: Accept (by newAdmin)

Contract Upgrade

RBAC supports contract upgrades by changing role addresses. Versioned implementations live under component-specific realm paths (for example, gno.land/r/gnoswap/pool/v1), while the stable realm resolves calls through the current role address.

Upgrade Process

  1. Deploy a new component version under its versioned realm path.
  2. Update the relevant role address to point to the new implementation.
  3. Verify distribution and call flows use the new role address.

Versioned Components

This checkout contains versioned implementations for:

  • pool
  • position
  • router
  • staker
  • gov/governance
  • gov/staker
  • launchpad
  • protocol_fee

The community_pool role is a distribution and treasury destination, not a versioned component. Updating that role redirects distributions to the selected address.

Example: GNS Distribution Upgrade

1func changeDistributionTarget(cur realm) {
2    // Update role addresses through the RBAC realm.
3    rbac.UpdateRoleAddress(cross(cur), "staker", newStakerAddr)
4    rbac.UpdateRoleAddress(cross(cur), "gov_staker", newGovStakerAddr)
5    rbac.UpdateRoleAddress(cross(cur), "devops", newDevOpsAddr)
6    // community_pool is a distribution target, not a versioned implementation.
7    rbac.UpdateRoleAddress(cross(cur), "community_pool", newCommunityPoolAddr)
8}

Test Example

The upgrade mechanism is demonstrated in the upgrade scenario test.

1// The scenario initializes distribution targets, updates role addresses,
2// and verifies that subsequent GNS distributions use the new addresses.
3func changeDistributionTarget(cur realm) {
4    rbac.UpdateRoleAddress(cross(cur), "staker", newStakerAddr)
5    rbac.UpdateRoleAddress(cross(cur), "gov_staker", newGovStakerAddr)
6    rbac.UpdateRoleAddress(cross(cur), "devops", newDevOpsAddr)
7    rbac.UpdateRoleAddress(cross(cur), "community_pool", newCommunityPoolAddr)
8}

Security

  • Admin or governance authorization is required for role management
  • Ownership transfer is restricted to the current owner and pending owner
  • Role updates are synchronized with the access package
  • Role validation is performed before updates

Variables 1

var EMISSION_ADDR, POOL_ADDR, POSITION_ADDR, ROUTER_ADDR, STAKER_ADDR, PROTOCOL_FEE_ADDR, COMMUNITY_POOL_ADDR, GOV_GOVERNANCE_ADDR, GOV_STAKER_ADDR, GOV_XGNS_ADDR, LAUNCHPAD_ADDR

 1var (
 2	EMISSION_ADDR       = chain.PackageAddress("gno.land/r/gnoswap/emission")
 3	POOL_ADDR           = chain.PackageAddress("gno.land/r/gnoswap/pool")
 4	POSITION_ADDR       = chain.PackageAddress("gno.land/r/gnoswap/position")
 5	ROUTER_ADDR         = chain.PackageAddress("gno.land/r/gnoswap/router")
 6	STAKER_ADDR         = chain.PackageAddress("gno.land/r/gnoswap/staker")
 7	PROTOCOL_FEE_ADDR   = chain.PackageAddress("gno.land/r/gnoswap/protocol_fee")
 8	COMMUNITY_POOL_ADDR = chain.PackageAddress("gno.land/r/gnoswap/community_pool/v1")
 9	GOV_GOVERNANCE_ADDR = chain.PackageAddress("gno.land/r/gnoswap/gov/governance")
10	GOV_STAKER_ADDR     = chain.PackageAddress("gno.land/r/gnoswap/gov/staker")
11	GOV_XGNS_ADDR       = chain.PackageAddress("gno.land/r/gnoswap/gov/xgns")
12	LAUNCHPAD_ADDR      = chain.PackageAddress("gno.land/r/gnoswap/launchpad")
13)
source

Derived package addresses — computed deterministically from deployment paths so they stay correct if packages are renamed or re-deployed.

Functions 8

func AcceptOwnership

crossing Action
1func AcceptOwnership(cur realm)
source

AcceptOwnership completes a pending ownership transfer and synchronizes the admin role with the new owner.

Parameters:

  • cur: current realm context; callers use cross(cur) when crossing into this realm

Only callable by the pending owner.

func IsOwner

Action
1func IsOwner(addr address) bool
source

IsOwner reports whether addr is the current owner address.

Parameters:

  • addr: address to compare with the configured owner

Returns:

  • owner: true when addr equals the current owner; false otherwise

func IsPendingOwner

Action
1func IsPendingOwner(addr address) bool
source

IsPendingOwner reports whether addr is the address awaiting ownership acceptance.

Parameters:

  • addr: address to compare with the configured pending owner

Returns:

  • pending: true when addr equals the pending owner; false otherwise

func RegisterRole

crossing Action
1func RegisterRole(cur realm, roleName string, roleAddress address)
source

RegisterRole registers a new role in the RBAC system.

Parameters:

  • cur: Current realm context; callers use cross(cur) when crossing into this realm.
  • roleName: nonempty role name to register in the RBAC manager.
  • roleAddress: address assigned to the new role and mirrored in access control.

Only callable by admin or governance.

func RemoveRole

crossing Action
1func RemoveRole(cur realm, roleName string)
source

RemoveRole removes a role from the RBAC system.

Parameters:

  • cur: Current realm context; callers use cross(cur) when crossing into this realm.
  • roleName: existing non-admin role name to remove from RBAC and access control.

Only callable by admin or governance.

func Render

1func Render(path string) string
source

Render returns ownership and assignments for the protocol's fixed system roles.

func TransferOwnership

crossing Action
1func TransferOwnership(cur realm, addr address)
source

TransferOwnership starts a two-step ownership transfer to addr.

Parameters:

  • cur: current realm context; callers use cross(cur) when crossing into this realm
  • addr: valid address that will become pending owner and may later accept ownership

Only callable by the current owner.

func UpdateRoleAddress

crossing Action
1func UpdateRoleAddress(cur realm, roleName string, addr address)
source

UpdateRoleAddress updates the address assigned to a role.

Parameters:

  • cur: Current realm context; callers use cross(cur) when crossing into this realm.
  • roleName: existing non-admin role name whose address is changed.
  • addr: valid replacement address assigned to the role and access-control mapping.

Only callable by admin or governance.

Imports 7

Source Files 9