AbstractFactory
Author: cosimo.demedici.eth (https://github.com/ninfa-labs/ninfa-contracts)
Abstract implementation for clone factory contracts
State Variables
_TOTAL_BPS
uint256 private constant _TOTAL_BPS = 10_000;_salesFeeRecipient
fee recipient for sales
address private _salesFeeRecipient;_salesFeeBps
fee fraction for sales fee calculation (e.g. 1000 = 10%)
uint256 private _salesFeeBps;_mastersWhitelist
whitelisted implementations' addresses; i.e. allowlist of clonable contracts
mapping(address => bool) private _mastersWhitelist;_clonesDeployed
cloned instances' addresses, needed by external contracts for access control
Functions
constructor
The constructor sets the sales fee information.
ownership information must be set in derived contracts.
Parameters
salesFeeBps_
uint256
The numerator of the fee fraction.
salesFeeRecipient_
address
The address to receive the fee.
salesFeeInfo
*sets contract-wide fee information defined as a percentage (of the sale price), in order for self-sovereign contracts to be able to pay a fee to the factory if needed, this allows clones to fetch up to date fee information rather than hardcoding it. e.g. see {ERC1155OpenEdition-mint}, here is an extract:
Parameters
_salePrice
uint256
The price of the sale.
exists
Checks if a contract instance exists.
This function may be used by other contracts for access control, i.e. a marketplace like contract using this factory as a source of truth for whitelisted collections.
Parameters
_clone
address
Address of the instance to check.
Returns
<none>
bool
A boolean indicating if the instance exists.
predictDeterministicAddress
Predicts the deterministic address for a given implementation and salt.
Parameters
_master
address
The address of the master implementation.
_salt
bytes32
The salt to use for prediction.
Returns
<none>
address
The predicted address.
_cloneDeterministic
Clone function to create a new instance of a contract.
"Using the same implementation and salt multiple time will revert, since the clones cannot be cloneed twice at the same address." - https://docs.openzeppelin.com/contracts/4.x/api/proxy#Clones-cloneDeterministic-address-bytes32-
Initializes clones upon deployment via a low-level call (more gas-efficient) to invoke the initialize function atomically, because a constructor cannot be used while deploying proxy contracts such as clones.
Parameters
_master
address
MUST be one of this factory's whhitelisted collections
_salt
bytes32
_salt is a random number of our choice. generated with https://web3js.readthedocs.io/en/v1.2.11/web3-utils.html#randomhex _salt could also be dynamically calculated in order to avoid duplicate clones and for a way of finding predictable clones if salt the parameters are known, for example: address _clone = erc1155Minter.cloneDeterministic(β bytes32(keccak256(abi.encode(_name, _symbol, _msgSender))));
_data
bytes
The initialization data for the clone. It is the calldata that will be passed to the clone's initialize function.
_setMaster
The function selector is calculated as bytes4(keccak256('initialize(bytes)')) == 0x439fab91
Whitelist or unwhitelist a master implementation.
External visibility because it is meant to be needed by all derived contracts, i.e. no point in having a public getter for it, to avoid extra code.
Parameters
_master
address
Address of the master implementation to whitelist.
_isWhitelisted
bool
Bool to set the implementation as whitelisted or not.
_setSalesFeeInfo
see {AbstractFactory-salesFeeInfo}
Parameters
salesFeeRecipient_
address
The address to receive the fee.
salesFeeBps_
uint256
The numerator of the fee fraction.
Events
NewClone
Event emitted when a new clone is created.
Parameters
master
address
The address of the master implementation.
instance
address
The address of the new clone.
owner
address
is needed in order to keep a local database of owners to instance addresses; this avoids keeping track of them on-chain via a mapping.
MastersWhitelistUpdated
Event emitted when a master implementation is updated.
Parameters
master
address
The address of the master implementation.
isWhitelisted
bool
Bool to set the implementation as whitelisted or not.
SalesFeeInfoUpdated
Event emitted when the sales fee information is updated.
Parameters
feeRecipient
address
The address to receive the fee.
salesFeeBps
uint256
The numerator of the fee fraction.
Last updated