factory.sol

The Factory Contract

The factory contract is the heart of the empact protocol ecosystem. It encompasses various features and functionalities for minting, managing, and interacting with empact protocol. Some of the contract's key features include:

  • Minting: Authorized addresses can create new vaults and mint vault tokens using signed mint requests.

  • Customizable Fees: The contract allows for setting fees for creating new empact vaults and for withdrawing assets from them.

  • ERC-1155 Compliance: empact vaults implement the ERC-1155 standard, making them tradable and transferable NFTs.

  • Operator Roles: Roles such as SIGNER_ROLE and DEFAULT_ADMIN_ROLE are defined to control contract operations.

Solidity API

SignatureMint

TYPEHASH

bytes32 TYPEHASH

constructor

constructor() internal

verify

function verify(struct ISignatureMint.MintRequest _req, bytes _signature) public view returns (bool success, address signer)

Verifies that a mint request is signed by an account holding SIGNER_ROLE (at the time of the function call).

_canSignMintRequest

function _canSignMintRequest(address _signer) internal view virtual returns (bool)

Returns whether a given address is authorized to sign mint requests.

_processRequest

function _processRequest(struct ISignatureMint.MintRequest _req, bytes _signature) internal view returns (address signer)

Verifies a mint request

_recoverAddress

function _recoverAddress(struct ISignatureMint.MintRequest _req, bytes _signature) internal view returns (address)

Returns the address of the signer of the mint request.

_encodeRequest

function _encodeRequest(struct ISignatureMint.MintRequest _req) internal pure returns (bytes)

Resolves 'stack too deep' error in recoverAddress.

Factory

This contract handles the creation, management, and interaction with individual vaults, and is compliant with ERC1155 standards.

The contract inherits from ERC1155, ContractMetadata, SignatureMint, and AccessControl.

SIGNER_ROLE

bytes32 SIGNER_ROLE

VaultDeployed

event VaultDeployed(address vault, address msgSender)

Emitted when a new vault is deployed

FeeRecipientUpdated

event FeeRecipientUpdated(address recipient)

Emitted when the fee recipient is updated

MakeVaultFeeUpdated

event MakeVaultFeeUpdated(uint256 fee)

Emitted when the fee for vault creation is updated

BreakVaultBpsUpdated

event BreakVaultBpsUpdated(uint16 bps)

Emitted when the fee for vault withdrawal is updated

VaultImplementationUpdated

event VaultImplementationUpdated(address implementation)

GeneratorUpdated

event GeneratorUpdated(address generator)

TreasuryUpdated

event TreasuryUpdated(address treasury)

Payout

event Payout(address vaultAddress, uint256 tokenId)

nextTokenIdToMint_

uint256 nextTokenIdToMint_

The tokenId of the next NFT to mint.

makeVaultFee

uint256 makeVaultFee

The fee to create a new Vault.

withdrawalFeeBps

uint16 withdrawalFeeBps

The fee deducted with each withdrawal from a vault, in basis points

vaultImplementation

contract IVault vaultImplementation

The Vault implementation contract that is cloned for each new vault

generator

contract IGenerator generator

The contract that generates the on-chain metadata

treasury

contract ITreasury treasury

The contract that handles open vaults

feeRecipient

address payable feeRecipient

The address that receives all fees.

totalSupply

mapping(uint256 => uint256) totalSupply

@notice Returns the total supply of NFTs of a given tokenId @dev Mapping from tokenId => total circulating supply of NFTs of that tokenId.

vaults

mapping(uint256 => address) vaults

Vaults are mapped to the tokenId of the NFT they are tethered to

tokenExists

modifier tokenExists(uint256 tokenId)

checks to ensure that the token exists before referencing it

constructor

constructor(address payable _feeRecipient) public

Parameters

NameTypeDescription
_feeRecipientaddress payableThe address that will receive fees collected by the contract

uri

function uri(uint256 tokenId) public view returns (string)

mintWithSignature

function mintWithSignature(struct ISignatureMint.MintRequest _req, bytes _signature) external payable returns (address signer)

Mints new tokens with a signature from an authorized signer, and creates an associated vault

Minting logic includes creating a new erc1155 token, and deploying a new vault

Parameters

NameTypeDescription
_reqstruct ISignatureMint.MintRequestThe signed mint request data
_signaturebytesThe signature of an address with the SIGNER role

Return Values

NameTypeDescription
signeraddressThe address of the signer who authorized the mint

_deployProxyByImplementation

function _deployProxyByImplementation(struct IVault.Attr _vaultData, bytes32 _salt) internal returns (address deployedProxy)

Every time a new token is minted, a Vault proxy contract is deployed to hold the vaults

payout

function payout(uint256 tokenId) external

Executes the payout process for a given token ID, burning the sender's token balance and calling the payout function in the associated vault contract.

This function first checks the caller's balance of the specified token ID. If the balance is greater than zero, it burns the tokens to prevent double claiming. It then calls the payout function of the corresponding vault contract. If the vault's state changes to 'Open', it updates the treasury contract.

Parameters

NameTypeDescription
tokenIduint256The ID of the token for which the payout is being processed.

setMakeVaultFee

function setMakeVaultFee(uint256 fee) external

Sets the fee for creating a new vault

setBreakVaultBps

function setBreakVaultBps(uint16 bps) external

Sets the fee for withdrawing the vaults from a Vault - does not affect existing vaults

setFeeRecipient

function setFeeRecipient(address payable _feeRecipient) external

@notice Updates recipient of make & break vault fees @param _feeRecipient Address to be set as new recipient of primary sales.

setVaultImplementation

function setVaultImplementation(contract IVault _vaultImplementationAddress) external

@notice Sets an implementation for the vault clones ** Ensure this is called before using this contract! **

setGenerator

function setGenerator(contract IGenerator _generatorAddress) external

@notice Sets an implementation for generator contract This allows us to change the metadata and artwork of the NFTs

setTreasury

function setTreasury(contract ITreasury _treasuryAddress) external

@notice Sets an implementation for treasury contract

grantSignerRole

function grantSignerRole(address account) external

Grants the SIGNER role to a specified account.

Only an account with the DEFAULT_ADMIN_ROLE can assign the SIGNER_ROLE.

Parameters

NameTypeDescription
accountaddressThe address of the account to be granted the SIGNER_ROLE.

revokeSignerRole

function revokeSignerRole(address account) external

Revokes the SIGNER_ROLE from a specified account.

Only an account with the DEFAULT_ADMIN_ROLE can revoke the SIGNER_ROLE.

Parameters

NameTypeDescription
accountaddressThe address of the account from which the SIGNER_ROLE will be revoked.

supportsInterface

function supportsInterface(bytes4 interfaceId) public view virtual returns (bool)

nextTokenIdToMint

function nextTokenIdToMint() external view returns (uint256)

The tokenId assigned to the next new NFT to be minted.

_canSetContractURI

function _canSetContractURI() internal view virtual returns (bool)

Returns whether contract metadata can be set in the given execution context.

_canSignMintRequest

function _canSignMintRequest(address _signer) internal view virtual returns (bool)

Returns whether a given address is authorized to sign mint requests.

_beforeTokenTransfer

function _beforeTokenTransfer(address operator, address from, address to, uint256[] ids, uint256[] amounts, bytes data) internal virtual

Runs before every token transfer / mint / burn.

_collectMakeVaultFee

function _collectMakeVaultFee() internal virtual

Collects and distributes the primary sale value of NFTs being claimed.