FluidContractFactory ​
Inherits: Owned
A contract that allows deployers to deploy any contract by passing the contract data in bytes
The main objective of this contract is to avoid storing contract addresses in our protocols which requires 160 bits of storage Instead, we can just store the nonce & deployment of this address to calculate the address realtime using "AddressCalcs" library
State Variables ​
deployer ​
Mapping to store the deployment count for each deployer
mapping(address => uint16) public deployer;
totalContracts ​
total number of contracts deployed
uint256 public totalContracts;
Functions ​
constructor ​
Constructor to initialize the contract
constructor(address owner_) Owned(owner_);
Parameters
Name | Type | Description |
---|---|---|
owner_ | address | The address of the contract owner |
updateDeployer ​
Updates the allowed deployments count for a specific deployer
Only callable by the contract owner
function updateDeployer(address deployer_, uint16 count_) public onlyOwner;
Parameters
Name | Type | Description |
---|---|---|
deployer_ | address | The address of the deployer |
count_ | uint16 | The new count for the deployer |
deployContract ​
Deploys a new contract
Decrements the deployer's allowed deployments count if not the owner
function deployContract(bytes calldata contractCode_) external returns (address contractAddress_);
Parameters
Name | Type | Description |
---|---|---|
contractCode_ | bytes | The bytecode of the contract to deploy |
Returns
Name | Type | Description |
---|---|---|
contractAddress_ | address | The address of the deployed contract |
getContractAddress ​
Calculates the address of a contract for a given nonce
function getContractAddress(uint256 nonce_) public view returns (address contractAddress_);
Parameters
Name | Type | Description |
---|---|---|
nonce_ | uint256 | The nonce to use for address calculation |
Returns
Name | Type | Description |
---|---|---|
contractAddress_ | address | The calculated contract address |
_deploy ​
Internal function to deploy a contract
Uses inline assembly for efficient deployment
function _deploy(bytes memory bytecode_) internal returns (address address_);
Parameters
Name | Type | Description |
---|---|---|
bytecode_ | bytes | The bytecode of the contract to deploy |
Returns
Name | Type | Description |
---|---|---|
address_ | address | The address of the deployed contract |
Events ​
LogContractDeployed ​
Emitted when a new contract is deployed
event LogContractDeployed(address indexed addr, uint256 indexed nonce);
Parameters
Name | Type | Description |
---|---|---|
addr | address | The address of the deployed contract |
nonce | uint256 | The nonce used for deployment |
LogUpdateDeployer ​
Emitted when a deployer's count is updated
event LogUpdateDeployer(address indexed deployer, uint16 indexed count);
Parameters
Name | Type | Description |
---|---|---|
deployer | address | The address of the deployer |
count | uint16 | The new count for the deployer |
Errors ​
FluidContractFactory__InvalidOperation ​
Thrown when an invalid operation is attempted
error FluidContractFactory__InvalidOperation();