Skip to content

FluidContractFactory ​

Git Source

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

solidity
mapping(address => uint16) public deployer;

totalContracts ​

total number of contracts deployed

solidity
uint256 public totalContracts;

Functions ​

constructor ​

Constructor to initialize the contract

solidity
constructor(address owner_) Owned(owner_);

Parameters

NameTypeDescription
owner_addressThe address of the contract owner

updateDeployer ​

Updates the allowed deployments count for a specific deployer

Only callable by the contract owner

solidity
function updateDeployer(address deployer_, uint16 count_) public onlyOwner;

Parameters

NameTypeDescription
deployer_addressThe address of the deployer
count_uint16The new count for the deployer

deployContract ​

Deploys a new contract

Decrements the deployer's allowed deployments count if not the owner

solidity
function deployContract(bytes calldata contractCode_) external returns (address contractAddress_);

Parameters

NameTypeDescription
contractCode_bytesThe bytecode of the contract to deploy

Returns

NameTypeDescription
contractAddress_addressThe address of the deployed contract

getContractAddress ​

Calculates the address of a contract for a given nonce

solidity
function getContractAddress(uint256 nonce_) public view returns (address contractAddress_);

Parameters

NameTypeDescription
nonce_uint256The nonce to use for address calculation

Returns

NameTypeDescription
contractAddress_addressThe calculated contract address

_deploy ​

Internal function to deploy a contract

Uses inline assembly for efficient deployment

solidity
function _deploy(bytes memory bytecode_) internal returns (address address_);

Parameters

NameTypeDescription
bytecode_bytesThe bytecode of the contract to deploy

Returns

NameTypeDescription
address_addressThe address of the deployed contract

Events ​

LogContractDeployed ​

Emitted when a new contract is deployed

solidity
event LogContractDeployed(address indexed addr, uint256 indexed nonce);

Parameters

NameTypeDescription
addraddressThe address of the deployed contract
nonceuint256The nonce used for deployment

LogUpdateDeployer ​

Emitted when a deployer's count is updated

solidity
event LogUpdateDeployer(address indexed deployer, uint16 indexed count);

Parameters

NameTypeDescription
deployeraddressThe address of the deployer
countuint16The new count for the deployer

Errors ​

FluidContractFactory__InvalidOperation ​

Thrown when an invalid operation is attempted

solidity
error FluidContractFactory__InvalidOperation();