Skip to content

💥 Make owner Explicit in Constructor #217

@pcaversaccio

Description

@pcaversaccio

Currently, the owner role is assigned to the msg.sender at construction time in ownable, ownable_2step, and access_control (here specifically the role DEFAULT_ADMIN_ROLE is assigned to msg.sender). If you deploy, for example, via a factory contract, this can become an issue as in this case you make the factory the owner. To improve the overall devex, we should make it possible to make the owner explicit.

As discussed here, we will use the yet-to-be-implemented Vyper @deploy decorator (vyperlang/vyper#3740) to implement this feature:

# access_control.vy

@deploy
def init_with_caller_as_default_admin():
    self._grant_role(DEFAULT_ADMIN_ROLE, msg.sender)


@deploy
def init_with_explicit_default_admin(default_admin: address):
    self._grant_role(DEFAULT_ADMIN_ROLE, default_admin)

...

And after that the user will be able to do:

from snekmate.auth import access_control as ac
initializes: ac

@deploy
def __init__():
    ac.init_with_caller_as_default_admin()

# OR

@deploy
def __init__(default_admin: address):
    ac.init_with_explicit_default_admin(default_admin)

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions