Access Level Guide
Purpose
The purpose of access levels is to provide a tiered approach to user verification and/or categorization before a user can receive certain assets and privileges in an application. Access levels may be defined using built-in protocol functionality or an external provider:
Access levels are used with the following rules:
- Maximum Account Value By Access Level Rule.
- Withdrawal Limit By Access Level.
- Account Deny For No Access Level.
Quick Start
Deploy the protocol and your application manager using the deployment guide. Before you start be sure that you have also registered a rule admin and assumed that the $RULE_ADMIN
private key is equivalent to $RULE_ADMIN_KEY
in the following example.
For example, we can set a rule for the user to only be able to withdraw 1000 USDC from their account once they’ve reached access level 1 using the Withdrawal Limit By Access Level rule. In order to set this up we first will call the function addAccountMaxValueOutByAccessLevel(address,uint48[])
on the protocol address using our ruleAdministrator account with the address in the function signature being the address of the application manager and the array of uints being [0, 10000000, 10000000, 10000000, 10000000].
The number is slightly larger to account for the 4 decimal places of the USDC token and repeated so that we account for all levels available when crafting an access level. This will return a uint32 which is the ID of the rule. Because cast doesn’t wrangle the calls well, we’re going to have to take the tx id and parse for the event logs. Take note of the receipt that was generated from the last command and be mindful of the to
and the blockNumber
fields:
The output should look something like this:
The topics field is where you are going to want to pay attention to as this contains the variable you want. In our particular case above because this is a fresh deployment on a local machine, we are taking the 0th position in the rules list. Therefore our ruleId
is 0 and we can pass that along to our application manager. It should be noted that if you were to run this in a smart contract script, you would just need to take the return value generated from addAccountMaxValueOutByAccessLevel
. Once we have this ruleId, we can add it to our access level using the setAccountMaxValueOutByAccessLevelId(uint32 _ruleId)
function on the application handler.
Once you have that set up, it’s time to start setting up your access levels.
The above command will add the user in $USER_ADDRESS to the access level 1. This user now has an elevated status above other users and can move assets more freely in your setup than a user with an access level of 0.