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

README.md

4.59 Kb · 146 lines

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