Skip to main content

RoleManager

Git Source

Inherits: Positions

State Variables

PENDING_GOVERNANCE

Position ID for "Pending Governance".

bytes32 public constant PENDING_GOVERNANCE = keccak256("Pending Governance");

GOVERNANCE

Position ID for "Governance".

bytes32 public constant GOVERNANCE = keccak256("Governance");

MANAGEMENT

Position ID for "Brain".

bytes32 public constant MANAGEMENT = keccak256("Management");

KEEPER

Position ID for "Keeper".

bytes32 public constant KEEPER = keccak256("Keeper");

REGISTRY

Position ID for the "Registry".

bytes32 public constant REGISTRY = keccak256("Registry");

ACCOUNTANT

Position ID for the "Accountant".

bytes32 public constant ACCOUNTANT = keccak256("Accountant");

DEBT_ALLOCATOR

Position ID for the "Debt Allocator".

bytes32 public constant DEBT_ALLOCATOR = keccak256("Debt Allocator");

chad

Immutable address that the role_manager position

address public chad;

vaults

Array storing addresses of all managed vaults.

address[] public vaults;

projectName

string internal projectName;

defaultProfitMaxUnlockTime

Default time until profits are fully unlocked for new vaults.

uint256 public defaultProfitMaxUnlockTime;

vaultConfig

Mapping of vault addresses to its config.

mapping(address => VaultConfig) public vaultConfig;

_assetToVault

Mapping of underlying asset, api version and category to vault.

mapping(address => mapping(string => mapping(uint256 => address))) internal _assetToVault;

Functions

constructor

constructor();

initialize

function initialize(
string calldata _projectName,
address _governance,
address _management,
address _keeper,
address _registry,
address _accountant,
address _debtAllocator
) external;

newVault

Creates a new endorsed vault with default profit max unlock time.

function newVault(address _asset, uint256 _category, string calldata _name, string calldata _symbol)
external
virtual
onlyPositionHolder(GOVERNANCE)
returns (address);

Parameters

NameTypeDescription
_assetaddressAddress of the underlying asset.
_categoryuint256Category of the vault.
_namestringName of the vault.
_symbolstringSymbol of the vault.

Returns

NameTypeDescription
<none>address_vault Address of the newly created vault.

newVault

Creates a new endorsed vault with default profit max unlock time.

function newVault(
address _asset,
uint256 _category,
string calldata _name,
string calldata _symbol,
uint256 _depositLimit
) external virtual onlyPositionHolder(GOVERNANCE) returns (address);

Parameters

NameTypeDescription
_assetaddressAddress of the underlying asset.
_categoryuint256Category of the vault.
_namestringName of the vault.
_symbolstringSymbol of the vault.
_depositLimituint256The deposit limit to start the vault with.

Returns

NameTypeDescription
<none>address_vault Address of the newly created vault.

_newVault

Creates a new endorsed vault.

function _newVault(address _asset, uint256 _category, string memory _name, string memory _symbol, uint256 _depositLimit)
internal
virtual
returns (address _vault);

Parameters

NameTypeDescription
_assetaddressAddress of the underlying asset.
_categoryuint256Category of the vault.
_namestringName of the vault.
_symbolstringSymbol of the vault.
_depositLimituint256The deposit limit to start the vault with.

Returns

NameTypeDescription
_vaultaddressAddress of the newly created vault.

_sanctify

Assigns roles to the newly added vault. This will override any previously set roles for the holders. But not effect the roles held by other addresses.

function _sanctify(address _vault, address _debtAllocator) internal virtual;

Parameters

NameTypeDescription
_vaultaddressAddress of the vault to sanctify.
_debtAllocatoraddressAddress of the debt allocator for the vault.

_setRole

Used internally to set the roles on a vault for a given position. Will not set the roles if the position holder is address(0). This does not check that the roles are !=0 because it is expected that the holder will be set to 0 if the position is not being used.

function _setRole(address _vault, Position memory _position) internal virtual;

Parameters

NameTypeDescription
_vaultaddressAddress of the vault.
_positionPositionHolder address and roles to set.

_setAccountant

Sets the accountant on the vault and adds the vault to the accountant. This temporarily gives the ACCOUNTANT_MANAGER role to this contract.

function _setAccountant(address _vault) internal virtual;

Parameters

NameTypeDescription
_vaultaddressAddress of the vault to set up the accountant for.

_setDepositLimit

Used to set an initial deposit limit when a new vault is deployed. Any further updates to the limit will need to be done by an address that holds the DEPOSIT_LIMIT_MANAGER role.

function _setDepositLimit(address _vault, uint256 _depositLimit) internal virtual;

Parameters

NameTypeDescription
_vaultaddressAddress of the newly deployed vault.
_depositLimituint256The deposit limit to set.

addNewVault

Adds a new vault to the RoleManager with the specified category.

If not already endorsed this function will endorse the vault. A new debt allocator will be deployed and configured.

function addNewVault(address _vault, uint256 _category) external virtual;

Parameters

NameTypeDescription
_vaultaddressAddress of the vault to be added.
_categoryuint256Category associated with the vault.

addNewVault

Adds a new vault to the RoleManager with the specified category and debt allocator.

If not already endorsed this function will endorse the vault.

function addNewVault(address _vault, uint256 _category, address _debtAllocator)
public
virtual
onlyPositionHolder(GOVERNANCE);

Parameters

NameTypeDescription
_vaultaddressAddress of the vault to be added.
_categoryuint256Category associated with the vault.
_debtAllocatoraddressAddress of the debt allocator for the vault.

updateDebtAllocator

Update a _vaults debt allocator.

This will use the default Debt Allocator currently set.

function updateDebtAllocator(address _vault) external virtual returns (address _newDebtAllocator);

Parameters

NameTypeDescription
_vaultaddressAddress of the vault to update the allocator for.

updateDebtAllocator

Update a _vaults debt allocator to a specified _debtAllocator.

function updateDebtAllocator(address _vault, address _debtAllocator) public virtual onlyPositionHolder(MANAGEMENT);

Parameters

NameTypeDescription
_vaultaddressAddress of the vault to update the allocator for.
_debtAllocatoraddressAddress of the new debt allocator.

updateKeeper

Update a _vaults keeper to a specified _keeper.

function updateKeeper(address _vault, address _keeper) external virtual onlyPositionHolder(MANAGEMENT);

Parameters

NameTypeDescription
_vaultaddressAddress of the vault to update the keeper for.
_keeperaddressAddress of the new keeper.

updateVaultName

function updateVaultName(address _vault, string calldata _name) external onlyPositionHolder(GOVERNANCE);

updateVaultSymbol

function updateVaultSymbol(address _vault, string calldata _symbol) external onlyPositionHolder(GOVERNANCE);

removeVault

Removes a vault from the RoleManager.

This will NOT un-endorse the vault from the registry.

function removeVault(address _vault) external virtual onlyPositionHolder(MANAGEMENT);

Parameters

NameTypeDescription
_vaultaddressAddress of the vault to be removed.

removeRoles

Removes a specific role(s) for a _holder from the _vaults.

Can be used to remove one specific role or multiple.

function removeRoles(address[] calldata _vaults, address _holder, uint256 _role)
external
virtual
onlyPositionHolder(GOVERNANCE);

Parameters

NameTypeDescription
_vaultsaddress[]Array of vaults to adjust.
_holderaddressAddress who's having a role removed.
_roleuint256The role or roles to remove from the _holder.

setPositionRoles

Setter function for updating a positions roles.

function setPositionRoles(bytes32 _position, uint256 _newRoles) external virtual onlyPositionHolder(GOVERNANCE);

Parameters

NameTypeDescription
_positionbytes32Identifier for the position.
_newRolesuint256New roles for the position.

setPositionHolder

Setter function for updating a positions holder.

Updating Governance requires setting PENDING_GOVERNANCE and then the pending address calling acceptGovernance.

function setPositionHolder(bytes32 _position, address _newHolder) external virtual onlyPositionHolder(GOVERNANCE);

Parameters

NameTypeDescription
_positionbytes32Identifier for the position.
_newHolderaddressNew address for position.

setDefaultProfitMaxUnlockTime

Sets the default time until profits are fully unlocked for new vaults.

function setDefaultProfitMaxUnlockTime(uint256 _newDefaultProfitMaxUnlockTime)
external
virtual
onlyPositionHolder(GOVERNANCE);

Parameters

NameTypeDescription
_newDefaultProfitMaxUnlockTimeuint256New value for defaultProfitMaxUnlockTime.

acceptGovernance

Accept the Governance role.

Caller must be the Pending Governance.

function acceptGovernance() external virtual onlyPositionHolder(PENDING_GOVERNANCE);

name

Get the name of this contract.

function name() external view virtual returns (string memory);

getAllVaults

Get all vaults that this role manager controls..

function getAllVaults() external view virtual returns (address[] memory);

Returns

NameTypeDescription
<none>address[]The full array of vault addresses.

getVault

Get the vault for a specific asset, api and category.

This will return address(0) if one has not been added or deployed.

function getVault(address _asset, string memory _apiVersion, uint256 _category)
external
view
virtual
returns (address);

Parameters

NameTypeDescription
_assetaddressThe underlying asset used.
_apiVersionstringThe version of the vault.
_categoryuint256The category of the vault.

Returns

NameTypeDescription
<none>addressThe vault for the specified _asset, _apiVersion and _category.

latestVault

Get the latest vault for a specific asset.

This will default to using category 1.

function latestVault(address _asset) external view virtual returns (address);

Parameters

NameTypeDescription
_assetaddressThe underlying asset used.

Returns

NameTypeDescription
<none>address_vault latest vault for the specified _asset if any.

latestVault

Get the latest vault for a specific asset.

function latestVault(address _asset, uint256 _category) public view virtual returns (address _vault);

Parameters

NameTypeDescription
_assetaddressThe underlying asset used.
_categoryuint256The category of the vault.

Returns

NameTypeDescription
_vaultaddresslatest vault for the specified _asset if any.

isVaultsRoleManager

Check if a vault is managed by this contract.

This will check if the asset variable in the struct has been set for an easy external view check. Does not check the vaults role_manager position since that can be set by anyone for a random vault.

function isVaultsRoleManager(address _vault) external view virtual returns (bool);

Parameters

NameTypeDescription
_vaultaddressAddress of the vault to check.

Returns

NameTypeDescription
<none>bool. The vaults role manager status.

getDebtAllocator

Get the debt allocator for a specific vault.

Will return address(0) if the vault is not managed by this contract.

function getDebtAllocator(address _vault) external view virtual returns (address);

Parameters

NameTypeDescription
_vaultaddressAddress of the vault.

Returns

NameTypeDescription
<none>address. Address of the debt allocator if any.

getCategory

Get the category for a specific vault.

Will return 0 if the vault is not managed by this contract.

function getCategory(address _vault) external view virtual returns (uint256);

Parameters

NameTypeDescription
_vaultaddressAddress of the vault.

Returns

NameTypeDescription
<none>uint256. The category of the vault if any.

getGovernance

Get the address assigned to the Governance position.

function getGovernance() external view virtual returns (address);

Returns

NameTypeDescription
<none>addressThe address assigned to the Governance position.

getPendingGovernance

Get the address assigned to the Pending Governance position.

function getPendingGovernance() external view virtual returns (address);

Returns

NameTypeDescription
<none>addressThe address assigned to the Pending Governance position.

getManagement

Get the address assigned to the Management position.

function getManagement() external view virtual returns (address);

Returns

NameTypeDescription
<none>addressThe address assigned to the Management position.

getKeeper

Get the address assigned to the Keeper position.

function getKeeper() external view virtual returns (address);

Returns

NameTypeDescription
<none>addressThe address assigned to the Keeper position.

getRegistry

Get the address assigned to the Registry.

function getRegistry() external view virtual returns (address);

Returns

NameTypeDescription
<none>addressThe address assigned to the Registry.

getAccountant

Get the address assigned to the accountant.

function getAccountant() external view virtual returns (address);

Returns

NameTypeDescription
<none>addressThe address assigned to the accountant.

getDebtAllocator

Get the address assigned to be the debt allocator if any.

function getDebtAllocator() external view virtual returns (address);

Returns

NameTypeDescription
<none>addressThe address assigned to be the debt allocator if any.

getGovernanceRoles

Get the roles given to the Governance position.

function getGovernanceRoles() external view virtual returns (uint256);

Returns

NameTypeDescription
<none>uint256The roles given to the Governance position.

getManagementRoles

Get the roles given to the Management position.

function getManagementRoles() external view virtual returns (uint256);

Returns

NameTypeDescription
<none>uint256The roles given to the Management position.

getKeeperRoles

Get the roles given to the Keeper position.

function getKeeperRoles() external view virtual returns (uint256);

Returns

NameTypeDescription
<none>uint256The roles given to the Keeper position.

getDebtAllocatorRoles

Get the roles given to the debt allocators.

function getDebtAllocatorRoles() external view virtual returns (uint256);

Returns

NameTypeDescription
<none>uint256The roles given to the debt allocators.

Events

AddedNewVault

Emitted when a new vault has been deployed or added.

event AddedNewVault(address indexed vault, address indexed debtAllocator, uint256 category);

UpdateDebtAllocator

Emitted when a vaults debt allocator is updated.

event UpdateDebtAllocator(address indexed vault, address indexed debtAllocator);

RemovedVault

Emitted when a vault is removed.

event RemovedVault(address indexed vault);

UpdateDefaultProfitMaxUnlockTime

Emitted when the defaultProfitMaxUnlockTime variable is updated.

event UpdateDefaultProfitMaxUnlockTime(uint256 newDefaultProfitMaxUnlockTime);

Errors

AlreadyDeployed

Revert message for when a vault has already been deployed.

error AlreadyDeployed(address _vault);

Structs

VaultConfig

Config that holds all vault info.

struct VaultConfig {
address asset;
uint256 category;
address debtAllocator;
uint256 index;
}