Skip to main content

Assign Component Royalty Roles

Assign AccessRules for Component Royalty Roles

Components may optionally include Component Royalties. If so, a set of component royalty roles will be defined for that component:

RoleAuthority DescriptionMethods Accessible
royalty_setterUpdate royalty amount for a methodComponentRoyalty::set_royalty
royalty_setter_updaterUpdate the AccessRule of the royalty_setterRoleAssignment::set(ModuleId::Royalty, "royalty_setter", ..)
royalty_lockerLock the royalty amount for a method such that they are no longer updateableComponentRoyalty::lock_royalty
royalty_locker_updaterUpdate the AccessRule of the royalty_lockerRoleAssignment::set(ModuleId::Royalty, "royalty_locker", ..)
royalty_claimerWithdraw the royalties accumulated by the componentComponentRoyalty::claim_royalties
royalty_claimer_updaterUpdate the AccessRule of the royalty_claimerRoleAssignment::set(ModuleId::Royalty, "royalty_claimer", ..)

By default, the Owner Role will inherit all Metadata Roles.

Assign Custom AccessRules for Component Royalty Roles

If custom access rules for each component royalty role are required (rather than the Owner role inheriting all roles) then add roles to the component_royalties! macro during component globalization:

#[blueprint]
mod my_token_sale {
enable_method_auth! {
roles {
super_admin_role => updatable_by: [];
admin_role => updatable_by: [super_admin_role];
},
methods { .. }
}

struct MyTokenSale { .. }

impl MyTokenSale {
pub fn create() {
let owner_badge: Bucket = { .. };
let owner_access_rule: AccessRule = { .. };
let royalty_setter_access_rule: AccessRule = { .. };
let royalty_locker_access_rule: AccessRule = { .. };
let royalty_locker_updater_access_rule: AccessRule = { .. };

MyTokenSale { .. }
.instantiate()
.prepare_to_globalize(OwnerRole::Fixed(owner_access_rule))
.enable_component_royalties(component_royalties! {
roles {
royalty_setter => royalty_setter_access_rule; // #1
royalty_setter_updater => rule!(deny_all); // #2
royalty_locker => royalty_locker_access_rule;
royalty_locker_updater => royalty_locker_updater_access_rule;
royalty_claimer => OWNER; // #3
royalty_claimer_updater => OWNER;
},
init { .. }
})
.globalize()

..
}
..
}
}
  1. The royalty_setter_access_rule is assigned to the royalty_setter role

  2. The royaty_setter_updater role is not accessible by anyone effectively “locking” in the AccessRule of royalty_setter

  3. Using OWNER specifies that the owner role will inherit the royalty_claimer role