LedgerDeploymentFacet
Facet providing ledger deployment functionality for LedgerFactory diamond
Handles the creation and initialization of Ledger instances using stored bytecode
State Variables
LEDGER_DEPLOYMENT_STORAGE_SLOT
bytes32 private constant LEDGER_DEPLOYMENT_STORAGE_SLOT = keccak256("ledger.deployment.storage");
Functions
deployDiamond
Deploy a diamond using FactoryBase pattern
function deployDiamond(IDiamond.FacetCut[] memory cuts, bytes memory initData, bytes32 salt)
external
returns (address diamondAddress);
Parameters
cuts
IDiamond.FacetCut[]
Array of facet cuts to install
initData
bytes
Initialization data for the diamond
salt
bytes32
Salt for deterministic deployment
Returns
diamondAddress
address
The address of the deployed diamond
setLedgerBytecode
Set the bytecode for Ledger deployment
function setLedgerBytecode(bytes calldata bytecode) external;
Parameters
bytecode
bytes
The creation bytecode of the Ledger contract
getLedgerBytecode
Get the bytecode for Ledger deployment
function getLedgerBytecode() external view returns (bytes memory bytecode);
Returns
bytecode
bytes
The creation bytecode
createLedger
Creates a new Ledger instance for a user with default settings (2 decimals, USD)
Each user is limited to exactly one ledger
function createLedger() external returns (address);
Returns
<none>
address
The address of the newly created Ledger
createLedger
Creates a new Ledger instance for a user with custom currency settings
Each user is limited to exactly one ledger
function createLedger(uint8 _decimals, string memory _currencyCode) public returns (address);
Parameters
_decimals
uint8
The number of decimal places (e.g., 2 for cents)
_currencyCode
string
The ISO currency code (e.g., "USD", "EUR")
Returns
<none>
address
The address of the newly created Ledger
getTotalLedgerCount
Gets the total number of ledgers created by this factory
function getTotalLedgerCount() external view returns (uint256);
Returns
<none>
uint256
The total count of created ledgers
getLedgerByUser
Gets the ledger address for a specific user
function getLedgerByUser(address user) external view returns (address);
Parameters
user
address
The address of the user
Returns
<none>
address
The address of the user's ledger
getUserLedger
Gets the caller's ledger address
function getUserLedger() external view returns (address);
Returns
<none>
address
The address of the caller's ledger
getLedgerInfo
Gets ledger information by index
function getLedgerInfo(uint256 index) external view returns (LedgerInfo memory ledgerInfo);
Parameters
index
uint256
The index of the ledger
Returns
ledgerInfo
LedgerInfo
The ledger information
isInitialized
Check if the deployment facet is initialized
function isInitialized() external view returns (bool);
Returns
<none>
bool
True if initialized
_getLedgerDeploymentStorage
Get the storage for this facet
function _getLedgerDeploymentStorage() internal pure returns (LedgerDeploymentStorage storage s);
Returns
s
LedgerDeploymentStorage
The storage struct
Events
LedgerCreated
event LedgerCreated(address indexed ledgerAddress, address indexed owner, uint8 decimals, string currencyCode);
LedgerFactoryCreated
event LedgerFactoryCreated(address factoryAddress);
LedgerBytecodeSet
event LedgerBytecodeSet(uint256 bytecodeLength);
Errors
UserAlreadyHasLedger
error UserAlreadyHasLedger();
LedgerDeploymentFailed
error LedgerDeploymentFailed();
BytecodeNotSet
error BytecodeNotSet();
Structs
LedgerDeploymentStorage
struct LedgerDeploymentStorage {
address initialized;
mapping(uint256 => LedgerInfo) ledgers;
uint256 ledgerCount;
mapping(address => address) userLedgers;
bytes ledgerBytecode;
}
LedgerInfo
struct LedgerInfo {
address ledgerAddress;
address owner;
uint256 createdAt;
uint8 decimals;
string currencyCode;
}
Last updated
Was this helpful?