KnowledgeBase #2

The Knowledge Base #2 is composed of the following:

  • Grimoire Library

The Grimoire contains some of the Component keys that are stored in the organization's database:

bytes32 constant public COMPONENT_KEY_TREASURY_SPLITTER_MANAGER = 0x87a92f6bd20613c184485be8eadb46851dd4294a8359f902606085b8be6e7ae6;
bytes32 constant public COMPONENT_KEY_SUBDAOS_MANAGER = 0x5b87d6e94145c2e242653a71b7d439a3638a93c3f0d32e1ea876f9fb1feb53e2;
bytes32 constant public COMPONENT_KEY_DELEGATIONS_MANAGER = 0x49b87f4ee20613c184485be8eadb46851dd4294a8359f902606085b8be6e7ae6;
bytes32 constant public COMPONENT_KEY_INVESTMENTS_MANAGER = 0x4f3ad97a91794a00945c0ead3983f793d34044c6300048d8b4ef95636edd234b;
  • Delegations Grimoire Library

The Delegations Grimoire contains the Tokens Manager Component key that is stored in the organization's database:

bytes32 constant public COMPONENT_KEY_TOKENS_MANAGER = 0x62b56c3ab20613c184485be8eadb46851dd4294a8359f902606085b8be9f7dc5;
  • Getters & Setters

These contain the syntactic sugar required to give the organization its concrete shape at the state of art.

The Getters contain the functions for automatic retrieval of the component addresses (which have their keys saved in the Grimoire) to make calls like "organization.subDAOsManager()", which obtains the SubDAOManager address, rather than passing the key that corresponds to the SubDAOManager.

function treasurySplitterManager(IOrganization organization) internal view returns(ITreasurySplitterManager) {
    return ITreasurySplitterManager(organization.get(Grimoire.COMPONENT_KEY_TREASURY_SPLITTER_MANAGER));
}

function subDAOsManager(IOrganization organization) internal view returns(ISubDAOsManager) {
    return ISubDAOsManager(organization.get(Grimoire.COMPONENT_KEY_SUBDAOS_MANAGER));
}

function delegationsManager(IOrganization organization) internal view returns(IDelegationsManager) {
    return IDelegationsManager(organization.get(Grimoire.COMPONENT_KEY_DELEGATIONS_MANAGER));
}

function investmentsManager(IOrganization organization) internal view returns(IInvestmentsManager) {
    return IInvestmentsManager(organization.get(Grimoire.COMPONENT_KEY_INVESTMENTS_MANAGER));
}

The Setters contain utility code that can be used in a Proposal to change a specific component; i.e, can be used to make calls like "organization.replaceTreasurySplitterManager(address)", which sets a new Treasury Splitter Manager.

function replaceTreasurySplitterManager(IOrganization organization, address newComponentAddress) internal returns(ITreasurySplitterManager oldComponent) {
    require(newComponentAddress != address(0), "void");
    oldComponent = ITreasurySplitterManager(organization.set(IOrganization.Component(Grimoire.COMPONENT_KEY_TREASURY_SPLITTER_MANAGER, newComponentAddress, false, true)));
}

function replaceSubDAOsManager(IOrganization organization, address newComponentAddress) internal returns(ISubDAOsManager oldComponent) {
    require(newComponentAddress != address(0), "void");
    oldComponent = ISubDAOsManager(organization.set(IOrganization.Component(Grimoire.COMPONENT_KEY_SUBDAOS_MANAGER, newComponentAddress, true, true)));
}

function replaceDelegationsManager(IOrganization organization, address newComponentAddress) internal returns(IDelegationsManager oldComponent) {
    require(newComponentAddress != address(0), "void");
    oldComponent = IDelegationsManager(organization.set(IOrganization.Component(Grimoire.COMPONENT_KEY_DELEGATIONS_MANAGER, newComponentAddress, false, true)));
}

function replaceInvestmentsManager(IOrganization organization, address newComponentAddress) internal returns(IInvestmentsManager oldComponent) {
    require(newComponentAddress != address(0), "void");
    oldComponent = IInvestmentsManager(organization.set(IOrganization.Component(Grimoire.COMPONENT_KEY_INVESTMENTS_MANAGER, newComponentAddress, false, true)));
}
  • Delegation Getters

It contains a specific getter to retrieve a Delegation Tokens Manager Component.

function tokensManager(IOrganization organization) internal view returns(IDelegationTokensManager) {
    return IDelegationTokensManager(organization.get(DelegationGrimoire.COMPONENT_KEY_TOKENS_MANAGER));
}
  • Delegation Utilities

It contains the extractVotingTokens function. It is a fundamental utility function used by Delegations Proposals to be able to automatically retrieve the token that must be used to vote a specific Proposal. Remember that a Delegation can be attached to multiple Organizations at the same time and each Proposal must be voted using the Delegation token corresponding to the Proposal of the organization being voted on. Look here for more info.

function extractVotingTokens(address delegationsManagerAddress, address delegationAddress) internal view returns (bytes memory) {
    IDelegationsManager delegationsManager = IDelegationsManager(delegationsManagerAddress);
    (bool exists,,) = delegationsManager.exists(delegationAddress);
    require(exists, "wrong address");
    (address collection, uint256 tokenId) = delegationsManager.supportedToken();
    (collection, tokenId) = IOrganization(delegationAddress).tokensManager().wrapped(collection, tokenId, delegationsManagerAddress);
    require(collection != address(0) || tokenId != 0, "Wrap tokens first");
    address[] memory collections = new address[](1);
    uint256[] memory tokenIds = new uint256[](1);
    uint256[] memory weights = new uint256[](1);
    collections[0] = collection;
    tokenIds[0] = tokenId;
    weights[0] = 1;
    return abi.encode(collections, tokenIds, weights);
}

Last updated