CapitalAccountFacet
Inherits: AccessControl
Author: CMX Protocol Team
Diamond facet for managing capital accounts and investor tracking
*This facet handles all capital account operations including:
Investor account creation and management
Capital commitment and contribution tracking
Distribution recording and audit trails
Management fee and carried interest allocation
Comprehensive investor analytics Key Features:
Complete audit trail for all transactions
Investor type differentiation (LP/GP)
Pro-rata calculations for distributions
Management fee and carry tracking
Account lifecycle management
Comprehensive reporting capabilities Integration:
Works with CapitalCallFacet for contribution processing
Integrates with DistributionFacet for distribution tracking
Supports InvestmentFacet for performance calculations
Now includes event bubbling to diamond level for subgraph indexing*
State Variables
FUND_ROLE
Role for fund operations
bytes32 public constant FUND_ROLE = keccak256("FUND_ROLE");
OPERATOR_ROLE
Role for operators
bytes32 public constant OPERATOR_ROLE = keccak256("OPERATOR_ROLE");
GP_ROLE
Role for general partner
bytes32 public constant GP_ROLE = keccak256("GP_ROLE");
PLACEMENT_AGENT_ROLE
Role for placement agents
bytes32 public constant PLACEMENT_AGENT_ROLE = keccak256("PLACEMENT_AGENT_ROLE");
INVESTOR_TYPE_LP
uint8 public constant INVESTOR_TYPE_LP = 0;
INVESTOR_TYPE_GP
uint8 public constant INVESTOR_TYPE_GP = 1;
ENTRY_TYPE_COMMITMENT
uint8 public constant ENTRY_TYPE_COMMITMENT = 0;
ENTRY_TYPE_CONTRIBUTION
uint8 public constant ENTRY_TYPE_CONTRIBUTION = 1;
ENTRY_TYPE_DISTRIBUTION
uint8 public constant ENTRY_TYPE_DISTRIBUTION = 2;
ENTRY_TYPE_FEE
uint8 public constant ENTRY_TYPE_FEE = 3;
ENTRY_TYPE_CARRY
uint8 public constant ENTRY_TYPE_CARRY = 4;
Functions
onlyFundOrGP
modifier onlyFundOrGP();
onlyOperatorOrGP
modifier onlyOperatorOrGP();
validInvestor
modifier validInvestor(address investor);
createAccount
Create a new capital account for an investor
Creates account with initial commitment and sets up tracking
function createAccount(address investor, uint8 investorType, uint256 commitment) external onlyFundOrGP;
Parameters
investor
address
The investor address
investorType
uint8
Whether LP (0) or GP (1)
commitment
uint256
Initial commitment amount
recordCommitment
Record additional commitment from an investor
Adds to existing commitment and updates tracking
function recordCommitment(address investor, uint256 amount) external onlyFundOrGP validInvestor(investor);
Parameters
investor
address
The investor address
amount
uint256
Additional commitment amount
recordContribution
Record a capital contribution from an investor
Records contribution and reduces unfunded commitment
function recordContribution(address investor, uint256 amount, uint256 callNumber)
external
onlyFundOrGP
validInvestor(investor);
Parameters
investor
address
The investor address
amount
uint256
Contribution amount
callNumber
uint256
The capital call number
recordDistribution
Record a distribution to an investor
Records distribution and updates totals
function recordDistribution(address investor, uint256 amount, uint256 distributionType)
external
onlyFundOrGP
validInvestor(investor);
Parameters
investor
address
The investor address
amount
uint256
Distribution amount
distributionType
uint256
Type of distribution (0=capital, 1=preferred, 2=profit)
deductManagementFee
Deduct management fee from an investor's account
Records fee deduction for tracking purposes
function deductManagementFee(address investor, uint256 amount) external onlyFundOrGP validInvestor(investor);
Parameters
investor
address
The investor address
amount
uint256
Fee amount
allocateCarriedInterest
Allocate carried interest to a GP
Records carried interest allocation for GP
function allocateCarriedInterest(address gp, uint256 amount) external onlyFundOrGP validInvestor(gp);
Parameters
gp
address
The GP address
amount
uint256
Carry amount
updatePreferredReturn
Update preferred return accrual for an investor
Updates the preferred return amount owed
function updatePreferredReturn(address investor, uint256 amount) external onlyFundOrGP validInvestor(investor);
Parameters
investor
address
The investor address
amount
uint256
Preferred return amount
closeAccount
Close an investor's account
Deactivates account after ensuring no unfunded commitments
function closeAccount(address investor) external onlyOperatorOrGP validInvestor(investor);
Parameters
investor
address
The investor address
getAccount
Get complete capital account information for an investor
function getAccount(address investor) external view returns (UniversalFundStorage.CapitalAccount memory account);
Parameters
investor
address
The investor address
Returns
account
UniversalFundStorage.CapitalAccount
Complete capital account details
getAccountEntries
Get account entries (audit trail) for an investor
function getAccountEntries(address investor, uint256 offset, uint256 limit)
external
view
returns (UniversalFundStorage.AccountEntry[] memory entries);
Parameters
investor
address
The investor address
offset
uint256
Starting index for pagination
limit
uint256
Maximum number of entries to return
Returns
entries
UniversalFundStorage.AccountEntry[]
Array of account entries
getTotalCommitments
Get total commitments across all investors
function getTotalCommitments() external view returns (uint256 totalCommitments);
Returns
totalCommitments
uint256
Total committed capital
getTotalContributions
Get total contributions across all investors
function getTotalContributions() external view returns (uint256 totalContributions);
Returns
totalContributions
uint256
Total contributed capital
getTotalDistributions
Get total distributions across all investors
function getTotalDistributions() external view returns (uint256 totalDistributions);
Returns
totalDistributions
uint256
Total distributed capital
getUnfundedCommitments
Get total unfunded commitments
function getUnfundedCommitments() external view returns (uint256 unfundedCommitments);
Returns
unfundedCommitments
uint256
Total unfunded commitments
getInvestorsByType
Get investors by type (LP or GP)
function getInvestorsByType(uint8 investorType) external view returns (address[] memory investors);
Parameters
investorType
uint8
Type of investor (0=LP, 1=GP)
Returns
investors
address[]
Array of investor addresses
calculateOwnershipPercentage
Calculate ownership percentage for an investor
function calculateOwnershipPercentage(address investor) external view returns (uint256 percentage);
Parameters
investor
address
The investor address
Returns
percentage
uint256
Ownership percentage in basis points (10000 = 100%)
calculateProRataShare
Calculate pro-rata share for an investor
function calculateProRataShare(address investor, uint256 totalAmount) external view returns (uint256 share);
Parameters
investor
address
The investor address
totalAmount
uint256
Total amount to distribute
Returns
share
uint256
Pro-rata share amount
isInvestor
Check if an address is an active investor
function isInvestor(address account) external view returns (bool);
Parameters
account
address
The address to check
Returns
<none>
bool
isInvestor True if the address is an active investor
getActiveInvestorCount
Get the number of active investors
function getActiveInvestorCount() external view returns (uint256 count);
Returns
count
uint256
Number of active investors
_recordEntry
Record an account entry for audit trail
function _recordEntry(address investor, uint8 entryType, uint256 amount, uint256 balance, string memory description)
internal;
Parameters
investor
address
The investor address
entryType
uint8
Type of entry
amount
uint256
Transaction amount
balance
uint256
New balance after transaction
description
string
Human-readable description
_toString
Convert uint256 to string
function _toString(uint256 value) internal pure returns (string memory);
Parameters
value
uint256
The number to convert
Returns
<none>
string
String representation of the number
Events
AccountCreated
Emitted when a new capital account is created
event AccountCreated(address indexed investor, uint8 investorType, uint256 commitment);
CapitalCommitted
Emitted when capital is committed
event CapitalCommitted(address indexed investor, uint256 amount);
CapitalContributed
Emitted when capital is contributed
event CapitalContributed(address indexed investor, uint256 amount, uint256 callNumber);
DistributionRecorded
Emitted when distribution is recorded
event DistributionRecorded(address indexed investor, uint256 amount, uint256 distributionType);
ManagementFeeDeducted
Emitted when management fee is deducted
event ManagementFeeDeducted(address indexed investor, uint256 amount);
CarriedInterestAllocated
Emitted when carried interest is allocated
event CarriedInterestAllocated(address indexed gp, uint256 amount);
AccountClosed
Emitted when an account is closed
event AccountClosed(address indexed investor);
Errors
CapitalAccountFacet__InvalidInvestor
error CapitalAccountFacet__InvalidInvestor();
CapitalAccountFacet__AccountExists
error CapitalAccountFacet__AccountExists();
CapitalAccountFacet__AccountNotFound
error CapitalAccountFacet__AccountNotFound();
CapitalAccountFacet__InactiveAccount
error CapitalAccountFacet__InactiveAccount();
CapitalAccountFacet__InvalidCommitment
error CapitalAccountFacet__InvalidCommitment();
CapitalAccountFacet__InvalidAmount
error CapitalAccountFacet__InvalidAmount();
CapitalAccountFacet__ExceedsUnfunded
error CapitalAccountFacet__ExceedsUnfunded();
CapitalAccountFacet__NotGP
error CapitalAccountFacet__NotGP();
CapitalAccountFacet__HasUnfundedCommitment
error CapitalAccountFacet__HasUnfundedCommitment();
CapitalAccountFacet__Unauthorized
error CapitalAccountFacet__Unauthorized();
Last updated
Was this helpful?