Warning! Contract bytecode has been changed and doesn't match the verified one. Therefore, interaction with this smart contract may be risky.
- Contract name:
- Factory
- Optimization enabled
- true
- Compiler version
- v0.8.20+commit.a1b79de6
- Optimization runs
- 100
- EVM Version
- paris
- Verified at
- 2025-06-08T13:25:55.361869Z
Constructor Arguments
0x000000000000000000000000d5248ed905a803c74aa753fc36a5a936945625b7000000000000000000000000ce5b6f27c495aeb6edc1547da15248b109bda66d000000000000000000000000d52cc3e13984b763ddc83409df4612968dc40e1e000000000000000000000000804c3dc3d8a578741b9fa5e991456524b3f73fa4
Arg [0] (address) : 0xd5248ed905a803c74aa753fc36a5a936945625b7
Arg [1] (address) : 0xce5b6f27c495aeb6edc1547da15248b109bda66d
Arg [2] (address) : 0xd52cc3e13984b763ddc83409df4612968dc40e1e
Arg [3] (address) : 0x804c3dc3d8a578741b9fa5e991456524b3f73fa4
Contract source code
// Sources flattened with hardhat v2.24.2 https://hardhat.org
// SPDX-License-Identifier: MIT
// File @openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol@v5.3.0
// Original license: SPDX_License_Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (proxy/utils/Initializable.sol)
pragma solidity ^0.8.20;
/**
* @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
* behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
* external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
* function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
*
* The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
* reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
* case an upgrade adds a module that needs to be initialized.
*
* For example:
*
* [.hljs-theme-light.nopadding]
* ```solidity
* contract MyToken is ERC20Upgradeable {
* function initialize() initializer public {
* __ERC20_init("MyToken", "MTK");
* }
* }
*
* contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
* function initializeV2() reinitializer(2) public {
* __ERC20Permit_init("MyToken");
* }
* }
* ```
*
* TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
* possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
*
* CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
* that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
*
* [CAUTION]
* ====
* Avoid leaving a contract uninitialized.
*
* An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
* contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
* the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
*
* [.hljs-theme-light.nopadding]
* ```
* /// @custom:oz-upgrades-unsafe-allow constructor
* constructor() {
* _disableInitializers();
* }
* ```
* ====
*/
abstract contract Initializable {
/**
* @dev Storage of the initializable contract.
*
* It's implemented on a custom ERC-7201 namespace to reduce the risk of storage collisions
* when using with upgradeable contracts.
*
* @custom:storage-location erc7201:openzeppelin.storage.Initializable
*/
struct InitializableStorage {
/**
* @dev Indicates that the contract has been initialized.
*/
uint64 _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool _initializing;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Initializable")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant INITIALIZABLE_STORAGE = 0xf0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00;
/**
* @dev The contract is already initialized.
*/
error InvalidInitialization();
/**
* @dev The contract is not initializing.
*/
error NotInitializing();
/**
* @dev Triggered when the contract has been initialized or reinitialized.
*/
event Initialized(uint64 version);
/**
* @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
* `onlyInitializing` functions can be used to initialize parent contracts.
*
* Similar to `reinitializer(1)`, except that in the context of a constructor an `initializer` may be invoked any
* number of times. This behavior in the constructor can be useful during testing and is not expected to be used in
* production.
*
* Emits an {Initialized} event.
*/
modifier initializer() {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
// Cache values to avoid duplicated sloads
bool isTopLevelCall = !$._initializing;
uint64 initialized = $._initialized;
// Allowed calls:
// - initialSetup: the contract is not in the initializing state and no previous version was
// initialized
// - construction: the contract is initialized at version 1 (no reinitialization) and the
// current contract is just being deployed
bool initialSetup = initialized == 0 && isTopLevelCall;
bool construction = initialized == 1 && address(this).code.length == 0;
if (!initialSetup && !construction) {
revert InvalidInitialization();
}
$._initialized = 1;
if (isTopLevelCall) {
$._initializing = true;
}
_;
if (isTopLevelCall) {
$._initializing = false;
emit Initialized(1);
}
}
/**
* @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
* contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
* used to initialize parent contracts.
*
* A reinitializer may be used after the original initialization step. This is essential to configure modules that
* are added through upgrades and that require initialization.
*
* When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
* cannot be nested. If one is invoked in the context of another, execution will revert.
*
* Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
* a contract, executing them in the right order is up to the developer or operator.
*
* WARNING: Setting the version to 2**64 - 1 will prevent any future reinitialization.
*
* Emits an {Initialized} event.
*/
modifier reinitializer(uint64 version) {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
if ($._initializing || $._initialized >= version) {
revert InvalidInitialization();
}
$._initialized = version;
$._initializing = true;
_;
$._initializing = false;
emit Initialized(version);
}
/**
* @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
* {initializer} and {reinitializer} modifiers, directly or indirectly.
*/
modifier onlyInitializing() {
_checkInitializing();
_;
}
/**
* @dev Reverts if the contract is not in an initializing state. See {onlyInitializing}.
*/
function _checkInitializing() internal view virtual {
if (!_isInitializing()) {
revert NotInitializing();
}
}
/**
* @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
* Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
* to any version. It is recommended to use this to lock implementation contracts that are designed to be called
* through proxies.
*
* Emits an {Initialized} event the first time it is successfully executed.
*/
function _disableInitializers() internal virtual {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
if ($._initializing) {
revert InvalidInitialization();
}
if ($._initialized != type(uint64).max) {
$._initialized = type(uint64).max;
emit Initialized(type(uint64).max);
}
}
/**
* @dev Returns the highest version that has been initialized. See {reinitializer}.
*/
function _getInitializedVersion() internal view returns (uint64) {
return _getInitializableStorage()._initialized;
}
/**
* @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
*/
function _isInitializing() internal view returns (bool) {
return _getInitializableStorage()._initializing;
}
/**
* @dev Pointer to storage slot. Allows integrators to override it with a custom storage location.
*
* NOTE: Consider following the ERC-7201 formula to derive storage locations.
*/
function _initializableStorageSlot() internal pure virtual returns (bytes32) {
return INITIALIZABLE_STORAGE;
}
/**
* @dev Returns a pointer to the storage namespace.
*/
// solhint-disable-next-line var-name-mixedcase
function _getInitializableStorage() private pure returns (InitializableStorage storage $) {
bytes32 slot = _initializableStorageSlot();
assembly {
$.slot := slot
}
}
}
// File @openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol@v5.3.0
// Original license: SPDX_License_Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract ContextUpgradeable is Initializable {
function __Context_init() internal onlyInitializing {
}
function __Context_init_unchained() internal onlyInitializing {
}
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
// File @openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol@v5.3.0
// Original license: SPDX_License_Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is set to the address provided by the deployer. This can
* later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {
/// @custom:storage-location erc7201:openzeppelin.storage.Ownable
struct OwnableStorage {
address _owner;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Ownable")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant OwnableStorageLocation = 0x9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c199300;
function _getOwnableStorage() private pure returns (OwnableStorage storage $) {
assembly {
$.slot := OwnableStorageLocation
}
}
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
function __Ownable_init(address initialOwner) internal onlyInitializing {
__Ownable_init_unchained(initialOwner);
}
function __Ownable_init_unchained(address initialOwner) internal onlyInitializing {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
OwnableStorage storage $ = _getOwnableStorage();
return $._owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
OwnableStorage storage $ = _getOwnableStorage();
address oldOwner = $._owner;
$._owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
// File @openzeppelin/contracts/utils/Context.sol@v5.3.0
// Original license: SPDX_License_Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
// File @openzeppelin/contracts/access/Ownable.sol@v5.3.0
// Original license: SPDX_License_Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is set to the address provided by the deployer. This can
* later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
constructor(address initialOwner) {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
// File @openzeppelin/contracts/utils/Errors.sol@v5.3.0
// Original license: SPDX_License_Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Errors.sol)
pragma solidity ^0.8.20;
/**
* @dev Collection of common custom errors used in multiple contracts
*
* IMPORTANT: Backwards compatibility is not guaranteed in future versions of the library.
* It is recommended to avoid relying on the error API for critical functionality.
*
* _Available since v5.1._
*/
library Errors {
/**
* @dev The ETH balance of the account is not enough to perform the operation.
*/
error InsufficientBalance(uint256 balance, uint256 needed);
/**
* @dev A call to an address target failed. The target may have reverted.
*/
error FailedCall();
/**
* @dev The deployment failed.
*/
error FailedDeployment();
/**
* @dev A necessary precompile is missing.
*/
error MissingPrecompile(address);
}
// File @openzeppelin/contracts/utils/Create2.sol@v5.3.0
// Original license: SPDX_License_Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Create2.sol)
pragma solidity ^0.8.20;
/**
* @dev Helper to make usage of the `CREATE2` EVM opcode easier and safer.
* `CREATE2` can be used to compute in advance the address where a smart
* contract will be deployed, which allows for interesting new mechanisms known
* as 'counterfactual interactions'.
*
* See the https://eips.ethereum.org/EIPS/eip-1014#motivation[EIP] for more
* information.
*/
library Create2 {
/**
* @dev There's no code to deploy.
*/
error Create2EmptyBytecode();
/**
* @dev Deploys a contract using `CREATE2`. The address where the contract
* will be deployed can be known in advance via {computeAddress}.
*
* The bytecode for a contract can be obtained from Solidity with
* `type(contractName).creationCode`.
*
* Requirements:
*
* - `bytecode` must not be empty.
* - `salt` must have not been used for `bytecode` already.
* - the factory must have a balance of at least `amount`.
* - if `amount` is non-zero, `bytecode` must have a `payable` constructor.
*/
function deploy(uint256 amount, bytes32 salt, bytes memory bytecode) internal returns (address addr) {
if (address(this).balance < amount) {
revert Errors.InsufficientBalance(address(this).balance, amount);
}
if (bytecode.length == 0) {
revert Create2EmptyBytecode();
}
assembly ("memory-safe") {
addr := create2(amount, add(bytecode, 0x20), mload(bytecode), salt)
// if no address was created, and returndata is not empty, bubble revert
if and(iszero(addr), not(iszero(returndatasize()))) {
let p := mload(0x40)
returndatacopy(p, 0, returndatasize())
revert(p, returndatasize())
}
}
if (addr == address(0)) {
revert Errors.FailedDeployment();
}
}
/**
* @dev Returns the address where a contract will be stored if deployed via {deploy}. Any change in the
* `bytecodeHash` or `salt` will result in a new destination address.
*/
function computeAddress(bytes32 salt, bytes32 bytecodeHash) internal view returns (address) {
return computeAddress(salt, bytecodeHash, address(this));
}
/**
* @dev Returns the address where a contract will be stored if deployed via {deploy} from a contract located at
* `deployer`. If `deployer` is this contract's address, returns the same value as {computeAddress}.
*/
function computeAddress(bytes32 salt, bytes32 bytecodeHash, address deployer) internal pure returns (address addr) {
assembly ("memory-safe") {
let ptr := mload(0x40) // Get free memory pointer
// | | ↓ ptr ... ↓ ptr + 0x0B (start) ... ↓ ptr + 0x20 ... ↓ ptr + 0x40 ... |
// |-------------------|---------------------------------------------------------------------------|
// | bytecodeHash | CCCCCCCCCCCCC...CC |
// | salt | BBBBBBBBBBBBB...BB |
// | deployer | 000000...0000AAAAAAAAAAAAAAAAAAA...AA |
// | 0xFF | FF |
// |-------------------|---------------------------------------------------------------------------|
// | memory | 000000...00FFAAAAAAAAAAAAAAAAAAA...AABBBBBBBBBBBBB...BBCCCCCCCCCCCCC...CC |
// | keccak(start, 85) | ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ |
mstore(add(ptr, 0x40), bytecodeHash)
mstore(add(ptr, 0x20), salt)
mstore(ptr, deployer) // Right-aligned with 12 preceding garbage bytes
let start := add(ptr, 0x0b) // The hashed data starts at the final garbage byte which we will set to 0xff
mstore8(start, 0xff)
addr := and(keccak256(start, 85), 0xffffffffffffffffffffffffffffffffffffffff)
}
}
}
// File @openzeppelin/contracts/proxy/Clones.sol@v5.3.0
// Original license: SPDX_License_Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (proxy/Clones.sol)
pragma solidity ^0.8.20;
/**
* @dev https://eips.ethereum.org/EIPS/eip-1167[ERC-1167] is a standard for
* deploying minimal proxy contracts, also known as "clones".
*
* > To simply and cheaply clone contract functionality in an immutable way, this standard specifies
* > a minimal bytecode implementation that delegates all calls to a known, fixed address.
*
* The library includes functions to deploy a proxy using either `create` (traditional deployment) or `create2`
* (salted deterministic deployment). It also includes functions to predict the addresses of clones deployed using the
* deterministic method.
*/
library Clones {
error CloneArgumentsTooLong();
/**
* @dev Deploys and returns the address of a clone that mimics the behavior of `implementation`.
*
* This function uses the create opcode, which should never revert.
*/
function clone(address implementation) internal returns (address instance) {
return clone(implementation, 0);
}
/**
* @dev Same as {xref-Clones-clone-address-}[clone], but with a `value` parameter to send native currency
* to the new contract.
*
* NOTE: Using a non-zero value at creation will require the contract using this function (e.g. a factory)
* to always have enough balance for new deployments. Consider exposing this function under a payable method.
*/
function clone(address implementation, uint256 value) internal returns (address instance) {
if (address(this).balance < value) {
revert Errors.InsufficientBalance(address(this).balance, value);
}
assembly ("memory-safe") {
// Cleans the upper 96 bits of the `implementation` word, then packs the first 3 bytes
// of the `implementation` address with the bytecode before the address.
mstore(0x00, or(shr(0xe8, shl(0x60, implementation)), 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000))
// Packs the remaining 17 bytes of `implementation` with the bytecode after the address.
mstore(0x20, or(shl(0x78, implementation), 0x5af43d82803e903d91602b57fd5bf3))
instance := create(value, 0x09, 0x37)
}
if (instance == address(0)) {
revert Errors.FailedDeployment();
}
}
/**
* @dev Deploys and returns the address of a clone that mimics the behavior of `implementation`.
*
* This function uses the create2 opcode and a `salt` to deterministically deploy
* the clone. Using the same `implementation` and `salt` multiple times will revert, since
* the clones cannot be deployed twice at the same address.
*/
function cloneDeterministic(address implementation, bytes32 salt) internal returns (address instance) {
return cloneDeterministic(implementation, salt, 0);
}
/**
* @dev Same as {xref-Clones-cloneDeterministic-address-bytes32-}[cloneDeterministic], but with
* a `value` parameter to send native currency to the new contract.
*
* NOTE: Using a non-zero value at creation will require the contract using this function (e.g. a factory)
* to always have enough balance for new deployments. Consider exposing this function under a payable method.
*/
function cloneDeterministic(
address implementation,
bytes32 salt,
uint256 value
) internal returns (address instance) {
if (address(this).balance < value) {
revert Errors.InsufficientBalance(address(this).balance, value);
}
assembly ("memory-safe") {
// Cleans the upper 96 bits of the `implementation` word, then packs the first 3 bytes
// of the `implementation` address with the bytecode before the address.
mstore(0x00, or(shr(0xe8, shl(0x60, implementation)), 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000))
// Packs the remaining 17 bytes of `implementation` with the bytecode after the address.
mstore(0x20, or(shl(0x78, implementation), 0x5af43d82803e903d91602b57fd5bf3))
instance := create2(value, 0x09, 0x37, salt)
}
if (instance == address(0)) {
revert Errors.FailedDeployment();
}
}
/**
* @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}.
*/
function predictDeterministicAddress(
address implementation,
bytes32 salt,
address deployer
) internal pure returns (address predicted) {
assembly ("memory-safe") {
let ptr := mload(0x40)
mstore(add(ptr, 0x38), deployer)
mstore(add(ptr, 0x24), 0x5af43d82803e903d91602b57fd5bf3ff)
mstore(add(ptr, 0x14), implementation)
mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73)
mstore(add(ptr, 0x58), salt)
mstore(add(ptr, 0x78), keccak256(add(ptr, 0x0c), 0x37))
predicted := and(keccak256(add(ptr, 0x43), 0x55), 0xffffffffffffffffffffffffffffffffffffffff)
}
}
/**
* @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}.
*/
function predictDeterministicAddress(
address implementation,
bytes32 salt
) internal view returns (address predicted) {
return predictDeterministicAddress(implementation, salt, address(this));
}
/**
* @dev Deploys and returns the address of a clone that mimics the behavior of `implementation` with custom
* immutable arguments. These are provided through `args` and cannot be changed after deployment. To
* access the arguments within the implementation, use {fetchCloneArgs}.
*
* This function uses the create opcode, which should never revert.
*/
function cloneWithImmutableArgs(address implementation, bytes memory args) internal returns (address instance) {
return cloneWithImmutableArgs(implementation, args, 0);
}
/**
* @dev Same as {xref-Clones-cloneWithImmutableArgs-address-bytes-}[cloneWithImmutableArgs], but with a `value`
* parameter to send native currency to the new contract.
*
* NOTE: Using a non-zero value at creation will require the contract using this function (e.g. a factory)
* to always have enough balance for new deployments. Consider exposing this function under a payable method.
*/
function cloneWithImmutableArgs(
address implementation,
bytes memory args,
uint256 value
) internal returns (address instance) {
if (address(this).balance < value) {
revert Errors.InsufficientBalance(address(this).balance, value);
}
bytes memory bytecode = _cloneCodeWithImmutableArgs(implementation, args);
assembly ("memory-safe") {
instance := create(value, add(bytecode, 0x20), mload(bytecode))
}
if (instance == address(0)) {
revert Errors.FailedDeployment();
}
}
/**
* @dev Deploys and returns the address of a clone that mimics the behavior of `implementation` with custom
* immutable arguments. These are provided through `args` and cannot be changed after deployment. To
* access the arguments within the implementation, use {fetchCloneArgs}.
*
* This function uses the create2 opcode and a `salt` to deterministically deploy the clone. Using the same
* `implementation`, `args` and `salt` multiple times will revert, since the clones cannot be deployed twice
* at the same address.
*/
function cloneDeterministicWithImmutableArgs(
address implementation,
bytes memory args,
bytes32 salt
) internal returns (address instance) {
return cloneDeterministicWithImmutableArgs(implementation, args, salt, 0);
}
/**
* @dev Same as {xref-Clones-cloneDeterministicWithImmutableArgs-address-bytes-bytes32-}[cloneDeterministicWithImmutableArgs],
* but with a `value` parameter to send native currency to the new contract.
*
* NOTE: Using a non-zero value at creation will require the contract using this function (e.g. a factory)
* to always have enough balance for new deployments. Consider exposing this function under a payable method.
*/
function cloneDeterministicWithImmutableArgs(
address implementation,
bytes memory args,
bytes32 salt,
uint256 value
) internal returns (address instance) {
bytes memory bytecode = _cloneCodeWithImmutableArgs(implementation, args);
return Create2.deploy(value, salt, bytecode);
}
/**
* @dev Computes the address of a clone deployed using {Clones-cloneDeterministicWithImmutableArgs}.
*/
function predictDeterministicAddressWithImmutableArgs(
address implementation,
bytes memory args,
bytes32 salt,
address deployer
) internal pure returns (address predicted) {
bytes memory bytecode = _cloneCodeWithImmutableArgs(implementation, args);
return Create2.computeAddress(salt, keccak256(bytecode), deployer);
}
/**
* @dev Computes the address of a clone deployed using {Clones-cloneDeterministicWithImmutableArgs}.
*/
function predictDeterministicAddressWithImmutableArgs(
address implementation,
bytes memory args,
bytes32 salt
) internal view returns (address predicted) {
return predictDeterministicAddressWithImmutableArgs(implementation, args, salt, address(this));
}
/**
* @dev Get the immutable args attached to a clone.
*
* - If `instance` is a clone that was deployed using `clone` or `cloneDeterministic`, this
* function will return an empty array.
* - If `instance` is a clone that was deployed using `cloneWithImmutableArgs` or
* `cloneDeterministicWithImmutableArgs`, this function will return the args array used at
* creation.
* - If `instance` is NOT a clone deployed using this library, the behavior is undefined. This
* function should only be used to check addresses that are known to be clones.
*/
function fetchCloneArgs(address instance) internal view returns (bytes memory) {
bytes memory result = new bytes(instance.code.length - 45); // revert if length is too short
assembly ("memory-safe") {
extcodecopy(instance, add(result, 32), 45, mload(result))
}
return result;
}
/**
* @dev Helper that prepares the initcode of the proxy with immutable args.
*
* An assembly variant of this function requires copying the `args` array, which can be efficiently done using
* `mcopy`. Unfortunately, that opcode is not available before cancun. A pure solidity implementation using
* abi.encodePacked is more expensive but also more portable and easier to review.
*
* NOTE: https://eips.ethereum.org/EIPS/eip-170[EIP-170] limits the length of the contract code to 24576 bytes.
* With the proxy code taking 45 bytes, that limits the length of the immutable args to 24531 bytes.
*/
function _cloneCodeWithImmutableArgs(
address implementation,
bytes memory args
) private pure returns (bytes memory) {
if (args.length > 24531) revert CloneArgumentsTooLong();
return
abi.encodePacked(
hex"61",
uint16(args.length + 45),
hex"3d81600a3d39f3363d3d373d3d3d363d73",
implementation,
hex"5af43d82803e903d91602b57fd5bf3",
args
);
}
}
// File @openzeppelin/contracts/utils/introspection/IERC165.sol@v5.3.0
// Original license: SPDX_License_Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/IERC165.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[ERC].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
// File @openzeppelin/contracts/token/ERC1155/IERC1155.sol@v5.3.0
// Original license: SPDX_License_Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (token/ERC1155/IERC1155.sol)
pragma solidity ^0.8.20;
/**
* @dev Required interface of an ERC-1155 compliant contract, as defined in the
* https://eips.ethereum.org/EIPS/eip-1155[ERC].
*/
interface IERC1155 is IERC165 {
/**
* @dev Emitted when `value` amount of tokens of type `id` are transferred from `from` to `to` by `operator`.
*/
event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value);
/**
* @dev Equivalent to multiple {TransferSingle} events, where `operator`, `from` and `to` are the same for all
* transfers.
*/
event TransferBatch(
address indexed operator,
address indexed from,
address indexed to,
uint256[] ids,
uint256[] values
);
/**
* @dev Emitted when `account` grants or revokes permission to `operator` to transfer their tokens, according to
* `approved`.
*/
event ApprovalForAll(address indexed account, address indexed operator, bool approved);
/**
* @dev Emitted when the URI for token type `id` changes to `value`, if it is a non-programmatic URI.
*
* If an {URI} event was emitted for `id`, the standard
* https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[guarantees] that `value` will equal the value
* returned by {IERC1155MetadataURI-uri}.
*/
event URI(string value, uint256 indexed id);
/**
* @dev Returns the value of tokens of token type `id` owned by `account`.
*/
function balanceOf(address account, uint256 id) external view returns (uint256);
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {balanceOf}.
*
* Requirements:
*
* - `accounts` and `ids` must have the same length.
*/
function balanceOfBatch(
address[] calldata accounts,
uint256[] calldata ids
) external view returns (uint256[] memory);
/**
* @dev Grants or revokes permission to `operator` to transfer the caller's tokens, according to `approved`,
*
* Emits an {ApprovalForAll} event.
*
* Requirements:
*
* - `operator` cannot be the zero address.
*/
function setApprovalForAll(address operator, bool approved) external;
/**
* @dev Returns true if `operator` is approved to transfer ``account``'s tokens.
*
* See {setApprovalForAll}.
*/
function isApprovedForAll(address account, address operator) external view returns (bool);
/**
* @dev Transfers a `value` amount of tokens of type `id` from `from` to `to`.
*
* WARNING: This function can potentially allow a reentrancy attack when transferring tokens
* to an untrusted contract, when invoking {IERC1155Receiver-onERC1155Received} on the receiver.
* Ensure to follow the checks-effects-interactions pattern and consider employing
* reentrancy guards when interacting with untrusted contracts.
*
* Emits a {TransferSingle} event.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - If the caller is not `from`, it must have been approved to spend ``from``'s tokens via {setApprovalForAll}.
* - `from` must have a balance of tokens of type `id` of at least `value` amount.
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
* acceptance magic value.
*/
function safeTransferFrom(address from, address to, uint256 id, uint256 value, bytes calldata data) external;
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}.
*
* WARNING: This function can potentially allow a reentrancy attack when transferring tokens
* to an untrusted contract, when invoking {IERC1155Receiver-onERC1155BatchReceived} on the receiver.
* Ensure to follow the checks-effects-interactions pattern and consider employing
* reentrancy guards when interacting with untrusted contracts.
*
* Emits either a {TransferSingle} or a {TransferBatch} event, depending on the length of the array arguments.
*
* Requirements:
*
* - `ids` and `values` must have the same length.
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
* acceptance magic value.
*/
function safeBatchTransferFrom(
address from,
address to,
uint256[] calldata ids,
uint256[] calldata values,
bytes calldata data
) external;
}
// File @openzeppelin/contracts/token/ERC1155/IERC1155Receiver.sol@v5.3.0
// Original license: SPDX_License_Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC1155/IERC1155Receiver.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface that must be implemented by smart contracts in order to receive
* ERC-1155 token transfers.
*/
interface IERC1155Receiver is IERC165 {
/**
* @dev Handles the receipt of a single ERC-1155 token type. This function is
* called at the end of a `safeTransferFrom` after the balance has been updated.
*
* NOTE: To accept the transfer, this must return
* `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`
* (i.e. 0xf23a6e61, or its own function selector).
*
* @param operator The address which initiated the transfer (i.e. msg.sender)
* @param from The address which previously owned the token
* @param id The ID of the token being transferred
* @param value The amount of tokens being transferred
* @param data Additional data with no specified format
* @return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` if transfer is allowed
*/
function onERC1155Received(
address operator,
address from,
uint256 id,
uint256 value,
bytes calldata data
) external returns (bytes4);
/**
* @dev Handles the receipt of a multiple ERC-1155 token types. This function
* is called at the end of a `safeBatchTransferFrom` after the balances have
* been updated.
*
* NOTE: To accept the transfer(s), this must return
* `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`
* (i.e. 0xbc197c81, or its own function selector).
*
* @param operator The address which initiated the batch transfer (i.e. msg.sender)
* @param from The address which previously owned the token
* @param ids An array containing ids of each token being transferred (order and length must match values array)
* @param values An array containing amounts of each token being transferred (order and length must match ids array)
* @param data Additional data with no specified format
* @return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` if transfer is allowed
*/
function onERC1155BatchReceived(
address operator,
address from,
uint256[] calldata ids,
uint256[] calldata values,
bytes calldata data
) external returns (bytes4);
}
// File @openzeppelin/contracts/utils/introspection/ERC165.sol@v5.3.0
// Original license: SPDX_License_Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/ERC165.sol)
pragma solidity ^0.8.20;
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC-165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
// File @openzeppelin/contracts/token/ERC1155/utils/ERC1155Holder.sol@v5.3.0
// Original license: SPDX_License_Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC1155/utils/ERC1155Holder.sol)
pragma solidity ^0.8.20;
/**
* @dev Simple implementation of `IERC1155Receiver` that will allow a contract to hold ERC-1155 tokens.
*
* IMPORTANT: When inheriting this contract, you must include a way to use the received tokens, otherwise they will be
* stuck.
*/
abstract contract ERC1155Holder is ERC165, IERC1155Receiver {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return interfaceId == type(IERC1155Receiver).interfaceId || super.supportsInterface(interfaceId);
}
function onERC1155Received(
address,
address,
uint256,
uint256,
bytes memory
) public virtual override returns (bytes4) {
return this.onERC1155Received.selector;
}
function onERC1155BatchReceived(
address,
address,
uint256[] memory,
uint256[] memory,
bytes memory
) public virtual override returns (bytes4) {
return this.onERC1155BatchReceived.selector;
}
}
// File @openzeppelin/contracts/token/ERC721/IERC721.sol@v5.3.0
// Original license: SPDX_License_Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC721/IERC721.sol)
pragma solidity ^0.8.20;
/**
* @dev Required interface of an ERC-721 compliant contract.
*/
interface IERC721 is IERC165 {
/**
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
*/
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
*/
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
/**
* @dev Returns the number of tokens in ``owner``'s account.
*/
function balanceOf(address owner) external view returns (uint256 balance);
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function ownerOf(uint256 tokenId) external view returns (address owner);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon
* a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC-721 protocol to prevent tokens from being forever locked.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must have been allowed to move this token by either {approve} or
* {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon
* a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(address from, address to, uint256 tokenId) external;
/**
* @dev Transfers `tokenId` token from `from` to `to`.
*
* WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC-721
* or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must
* understand this adds an external call which potentially creates a reentrancy vulnerability.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 tokenId) external;
/**
* @dev Gives permission to `to` to transfer `tokenId` token to another account.
* The approval is cleared when the token is transferred.
*
* Only a single account can be approved at a time, so approving the zero address clears previous approvals.
*
* Requirements:
*
* - The caller must own the token or be an approved operator.
* - `tokenId` must exist.
*
* Emits an {Approval} event.
*/
function approve(address to, uint256 tokenId) external;
/**
* @dev Approve or remove `operator` as an operator for the caller.
* Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
*
* Requirements:
*
* - The `operator` cannot be the address zero.
*
* Emits an {ApprovalForAll} event.
*/
function setApprovalForAll(address operator, bool approved) external;
/**
* @dev Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function getApproved(uint256 tokenId) external view returns (address operator);
/**
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
*
* See {setApprovalForAll}
*/
function isApprovedForAll(address owner, address operator) external view returns (bool);
}
// File @openzeppelin/contracts/token/ERC721/IERC721Receiver.sol@v5.3.0
// Original license: SPDX_License_Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC721/IERC721Receiver.sol)
pragma solidity ^0.8.20;
/**
* @title ERC-721 token receiver interface
* @dev Interface for any contract that wants to support safeTransfers
* from ERC-721 asset contracts.
*/
interface IERC721Receiver {
/**
* @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
* by `operator` from `from`, this function is called.
*
* It must return its Solidity selector to confirm the token transfer.
* If any other value is returned or the interface is not implemented by the recipient, the transfer will be
* reverted.
*
* The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`.
*/
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
) external returns (bytes4);
}
// File @openzeppelin/contracts/token/ERC721/utils/ERC721Holder.sol@v5.3.0
// Original license: SPDX_License_Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/utils/ERC721Holder.sol)
pragma solidity ^0.8.20;
/**
* @dev Implementation of the {IERC721Receiver} interface.
*
* Accepts all token transfers.
* Make sure the contract is able to use its token with {IERC721-safeTransferFrom}, {IERC721-approve} or
* {IERC721-setApprovalForAll}.
*/
abstract contract ERC721Holder is IERC721Receiver {
/**
* @dev See {IERC721Receiver-onERC721Received}.
*
* Always returns `IERC721Receiver.onERC721Received.selector`.
*/
function onERC721Received(address, address, uint256, bytes memory) public virtual returns (bytes4) {
return this.onERC721Received.selector;
}
}
// File contracts/interfaces/INft721.sol
// Original license: SPDX_License_Identifier: MIT
pragma solidity ^0.8.20;
interface INft721 {
struct NFTDetails {
string name;
string description;
string uri;
address creator;
}
event NFTCreated(string name, string description,uint256 indexed tokenId, address indexed creator);
function initialize(
string memory name,
string memory symbol,
address owner
) external;
function createNFT(
string memory name,
string memory description,
string memory _tokenURI,
address user
) external returns (uint256);
function getCreator(uint256 tokenId) external view returns (address);
function getRoyaltyPercentage() external view returns(uint16);
function updateRoyaltyPercentage(uint16 _royaltyPercentage) external;
}
// File @openzeppelin/contracts/token/ERC20/IERC20.sol@v5.3.0
// Original license: SPDX_License_Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-20 standard as defined in the ERC.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}
// File @openzeppelin/contracts/utils/ReentrancyGuard.sol@v5.3.0
// Original license: SPDX_License_Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/ReentrancyGuard.sol)
pragma solidity ^0.8.20;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If EIP-1153 (transient storage) is available on the chain you're deploying at,
* consider using {ReentrancyGuardTransient} instead.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant NOT_ENTERED = 1;
uint256 private constant ENTERED = 2;
uint256 private _status;
/**
* @dev Unauthorized reentrant call.
*/
error ReentrancyGuardReentrantCall();
constructor() {
_status = NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be NOT_ENTERED
if (_status == ENTERED) {
revert ReentrancyGuardReentrantCall();
}
// Any calls to nonReentrant after this point will fail
_status = ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == ENTERED;
}
}
// File contracts/interfaces/ICollection.sol
// Original license: SPDX_License_Identifier: MIT
pragma solidity ^0.8.20;
interface ICollection {
struct NFTDetails {
string name;
string description;
string uri;
uint256 maxSupply;
address creator;
}
event NFTCreated(string name, string description,uint256 indexed tokenId, address indexed creator, uint256 maxSupply);
function initialize(
string memory name,
string memory symbol,
address owner
) external;
function createNFT(
string memory name,
string memory description,
string memory _tokenURI,
uint256 maxSupply,
address user
) external returns (uint256);
function getCreator(uint256 tokenId) external view returns (address);
function getRoyaltyPercentage() external view returns(uint16);
function updateRoyaltyPercentage(uint16 _royaltyPercentage) external;
}
// File contracts/NFTMarketplace.sol
// Original license: SPDX_License_Identifier: MIT
pragma solidity ^0.8.20;
contract NFTMarketplace is Ownable, ERC1155Holder, ERC721Holder, ReentrancyGuard {
enum ListingType { FIXED_PRICE, AUCTION }
enum AuctionStatus { ACTIVE, ENDED, CANCELLED }
enum OfferStatus { PENDING, ACCEPTED, REJECTED, CANCELLED }
enum TokenStandard { ERC1155, ERC721 }
struct Listing {
address seller;
uint256 price;
uint256 quantity; // Always 1 for ERC721
ListingType listingType;
uint256 auctionId; // 0 for fixed price listings
TokenStandard tokenStandard;
}
struct AuctionDetails {
address seller;
uint256 startPrice;
uint256 currentPrice;
uint256 minBidIncrement;
uint256 startTime;
uint256 endTime;
uint256 tokenId;
uint256 quantity;
address highestBidder;
AuctionStatus status;
TokenStandard tokenStandard;
}
struct Offer {
address buyer;
address seller;
uint256 price;
uint256 quantity;
uint256 createTime;
OfferStatus status;
TokenStandard tokenStandard;
}
struct FilterParams {
address collection;
uint256 tokenId;
address user;
uint8 filterType;
TokenStandard tokenStandard;
}
struct BatchPurchaseParams {
address collection;
uint256 tokenId;
address seller;
uint256 quantity;
TokenStandard tokenStandard;
}
uint256 public primaryFee;
uint256 public secondaryFee;
address public collectionFactory;
uint256 public totalCollections;
IERC20 public immutable designatedToken;
uint256 private _auctionIds;
uint256 private _offerIds;
uint256 public minAuctionDuration;
uint256 public maxAuctionDuration;
uint256 public auctionExtensionInterval;
mapping(address => mapping(uint256 => mapping(address => Listing))) public listings;
mapping(address => bool) public registeredCollections;
mapping(uint256 => address) private collectionIndex;
mapping(uint256 => AuctionDetails) public auctions;
mapping(uint256 => mapping(address => uint256)) public bids;
mapping(uint256 => address) public auctionCollections;
// Offer mappings
mapping(address => mapping(uint256 => mapping(uint256 => Offer))) public offers; // collection => tokenId => offerId => Offer
mapping(address => uint256[]) private userOfferIds; // buyer => offerIds
mapping(uint256 => address) private offerCollections; // offerId => collection
mapping(uint256 => uint256) private offerTokenIds; // offerId => tokenId
mapping(address => uint256[]) private sellerReceivedOffers; // seller => offerIds
mapping(address => mapping(uint256 => uint256[])) private tokenOffers; // collection => tokenId => offerIds
event NFTListed(
address indexed collection,
uint256 indexed tokenId,
address seller,
uint256 price,
uint256 quantity,
ListingType listingType,
uint256 auctionId,
TokenStandard tokenStandard
);
event NFTSold(
address indexed collection,
uint256 indexed tokenId,
address seller,
address buyer,
uint256 price,
uint256 quantity,
TokenStandard tokenStandard
);
event ListingRemoved(address indexed collection, uint256 indexed tokenId, address seller, string reason);
event ListingQuantityUpdated(
address indexed collection,
uint256 indexed tokenId,
address seller,
uint256 newQuantity
);
event AuctionCreated(
uint256 indexed auctionId,
address indexed collection,
uint256 indexed tokenId,
address seller,
uint256 startPrice,
uint256 minBidIncrement,
uint256 startTime,
uint256 endTime,
uint256 quantity,
TokenStandard tokenStandard
);
event BidPlaced(
uint256 indexed auctionId,
address indexed bidder,
uint256 amount
);
event AuctionSettled(
uint256 indexed auctionId,
address indexed winner,
uint256 amount
);
event AuctionCancelled(uint256 indexed auctionId);
event AuctionExtended(uint256 indexed auctionId, uint256 newEndTime);
event FeeUpdated(bool isPrimary, uint256 newFee);
event CollectionRegistered(address indexed collection);
event AuctionExtensionIntervalUpdated(uint256 newInterval);
event OfferCreated(
uint256 indexed offerId,
address indexed collection,
uint256 indexed tokenId,
address buyer,
address seller,
uint256 price,
uint256 quantity,
TokenStandard tokenStandard
);
event OfferAccepted(uint256 indexed offerId, address indexed seller);
event OfferRejected(uint256 indexed offerId, address indexed seller);
event OfferCancelled(uint256 indexed offerId, address indexed buyer);
constructor(
address _designatedToken,
uint256 _primaryFee,
uint256 _secondaryFee
) Ownable(msg.sender) {
require(_designatedToken != address(0), "Invalid token address");
require(_primaryFee <= 1000, "Primary fee too high");
require(_secondaryFee <= 1000, "Secondary fee too high");
designatedToken = IERC20(_designatedToken);
primaryFee = _primaryFee;
secondaryFee = _secondaryFee;
minAuctionDuration = 1 hours;
maxAuctionDuration = 30 days;
auctionExtensionInterval = 10 minutes;
}
function registerCollection(address collection) external {
require(msg.sender == collectionFactory, "Only factory can register");
require(collection != address(0), "Invalid collection address");
require(!registeredCollections[collection], "Already registered");
registeredCollections[collection] = true;
collectionIndex[totalCollections] = collection;
totalCollections++;
emit CollectionRegistered(collection);
}
function setPrimaryFee(uint256 _fee) external onlyOwner {
require(_fee <= 1000, "Fee too high");
primaryFee = _fee;
emit FeeUpdated(true, _fee);
}
function setSecondaryFee(uint256 _fee) external onlyOwner {
require(_fee <= 1000, "Fee too high");
secondaryFee = _fee;
emit FeeUpdated(false, _fee);
}
function listNFT(
address collection,
uint256 tokenId,
uint256 price,
uint256 quantity,
TokenStandard tokenStandard
) external nonReentrant {
require(registeredCollections[collection], "Collection not registered");
require(price > 0, "Invalid price");
require(quantity > 0, "Invalid quantity");
if (tokenStandard == TokenStandard.ERC721) {
require(quantity == 1, "ERC721 quantity must be 1");
require(IERC721(collection).ownerOf(tokenId) == msg.sender, "Not token owner");
require(IERC721(collection).getApproved(tokenId) == address(this) ||
IERC721(collection).isApprovedForAll(msg.sender, address(this)), "Not approved");
} else {
require(IERC1155(collection).balanceOf(msg.sender, tokenId) >= quantity, "Insufficient balance");
require(IERC1155(collection).isApprovedForAll(msg.sender, address(this)), "Not approved");
}
// Check if NFT is already listed by this seller
Listing storage existingListing = listings[collection][tokenId][msg.sender];
require(
existingListing.quantity == 0 ||
(existingListing.listingType == ListingType.AUCTION &&
auctions[existingListing.auctionId].status != AuctionStatus.ACTIVE),
"Already listed"
);
listings[collection][tokenId][msg.sender] = Listing({
seller: msg.sender,
price: price,
quantity: quantity,
listingType: ListingType.FIXED_PRICE,
auctionId: 0,
tokenStandard: tokenStandard
});
emit NFTListed(
collection,
tokenId,
msg.sender,
price,
quantity,
ListingType.FIXED_PRICE,
0,
tokenStandard
);
}
function removeListing(
address collection,
uint256 tokenId
) external nonReentrant {
Listing storage listing = listings[collection][tokenId][msg.sender];
require(listing.seller == msg.sender && listing.quantity > 0, "No active listing");
if (listing.listingType == ListingType.AUCTION) {
AuctionDetails storage auction = auctions[listing.auctionId];
require(auction.status == AuctionStatus.ACTIVE, "Auction not active");
require(auction.highestBidder == address(0), "Bids already placed");
auction.status = AuctionStatus.CANCELLED;
if (listing.tokenStandard == TokenStandard.ERC721) {
IERC721(collection).safeTransferFrom(address(this), msg.sender, tokenId);
} else {
IERC1155(collection).safeTransferFrom(
address(this),
msg.sender,
tokenId,
listing.quantity,
""
);
}
emit AuctionCancelled(listing.auctionId);
}
delete listings[collection][tokenId][msg.sender];
emit ListingRemoved(collection, tokenId, msg.sender, "REMOVED_BY_SELLER");
}
function buyListedNFT(
address collection,
uint256 tokenId,
address seller,
uint256 quantity,
TokenStandard tokenStandard
) external nonReentrant {
require(registeredCollections[collection], "Collection not registered");
Listing storage listing = listings[collection][tokenId][seller];
require(listing.seller == seller && listing.quantity > 0, "Invalid listing");
require(listing.listingType == ListingType.FIXED_PRICE, "Not a fixed price listing");
require(listing.quantity >= quantity, "Insufficient quantity");
require(listing.tokenStandard == tokenStandard, "Token standard mismatch");
if (tokenStandard == TokenStandard.ERC721) {
require(quantity == 1, "ERC721 quantity must be 1");
}
address nftCreator = ICollection(collection).getCreator(tokenId);
uint256 fee = secondaryFee;
if(nftCreator == seller) {
fee = primaryFee;
}
uint16 royaltyPercentage = ICollection(collection).getRoyaltyPercentage();
uint256 totalPrice = listing.price * quantity;
uint256 platformFee = (totalPrice * fee) / 1000;
uint256 royaltyFee = (totalPrice * royaltyPercentage) / 1000;
uint256 sellerAmount = totalPrice - platformFee - royaltyFee;
designatedToken.transferFrom(msg.sender, address(this), platformFee);
designatedToken.transferFrom(msg.sender, seller, sellerAmount);
if(royaltyFee > 0) {
designatedToken.transferFrom(msg.sender, nftCreator, royaltyFee);
}
if (tokenStandard == TokenStandard.ERC721) {
IERC721(collection).safeTransferFrom(seller, msg.sender, tokenId);
} else {
IERC1155(collection).safeTransferFrom(seller, msg.sender, tokenId, quantity, "");
}
listing.quantity -= quantity;
if (listing.quantity == 0) {
delete listings[collection][tokenId][seller];
emit ListingRemoved(collection, tokenId, seller, "SOLD_OUT");
}
emit NFTSold(collection, tokenId, seller, msg.sender, listing.price, quantity, tokenStandard);
}
function getRegisteredCollections(uint256 offset, uint256 limit)
public
view
returns (address[] memory collections)
{
require(offset <= totalCollections, "Invalid offset");
uint256 size = totalCollections - offset;
if (size > limit) {
size = limit;
}
collections = new address[](size);
for (uint256 i = 0; i < size; i++) {
collections[i] = collectionIndex[offset + i];
}
return collections;
}
function getCollectionsByOwner(address _owner, uint256 offset, uint256 limit)
external
view
returns (address[] memory _collections, uint256 total)
{
uint256 count = 0;
for (uint256 i = 0; i < totalCollections; i++) {
address collection = collectionIndex[i];
if (OwnableUpgradeable(collection).owner() == _owner) {
count++;
}
}
require(offset <= count, "Invalid offset");
uint256 size = count - offset;
if (size > limit) {
size = limit;
}
_collections = new address[](size);
uint256 currentIndex = 0;
uint256 skipped = 0;
for (uint256 i = 0; i < totalCollections && currentIndex < size; i++) {
address collection = collectionIndex[i];
if (OwnableUpgradeable(collection).owner() == _owner) {
if (skipped < offset) {
skipped++;
continue;
}
_collections[currentIndex] = collection;
currentIndex++;
}
}
return (_collections, count);
}
function withdrawFees() external onlyOwner {
uint256 balance = designatedToken.balanceOf(address(this));
if (balance > 0) {
designatedToken.transfer(owner(), balance);
}
}
function getListing(
address collection,
uint256 tokenId,
address seller
) external view returns (Listing memory) {
return listings[collection][tokenId][seller];
}
function createAuction(
address collection,
uint256 tokenId,
uint256 quantity,
uint256 startPrice,
uint256 minBidIncrement,
uint256 duration,
TokenStandard tokenStandard
) external nonReentrant returns (uint256) {
_validateAuctionParams(
collection,
tokenId,
quantity,
startPrice,
minBidIncrement,
duration,
tokenStandard
);
_auctionIds++;
uint256 auctionId = _auctionIds;
_createAuctionListing(
collection,
tokenId,
quantity,
startPrice,
auctionId,
tokenStandard
);
_setupAuction(
auctionId,
collection,
tokenId,
quantity,
startPrice,
minBidIncrement,
duration,
tokenStandard
);
return auctionId;
}
function _validateAuctionParams(
address collection,
uint256 tokenId,
uint256 quantity,
uint256 startPrice,
uint256 minBidIncrement,
uint256 duration,
TokenStandard tokenStandard
) internal view {
require(registeredCollections[collection], "Collection not registered");
require(quantity > 0, "Invalid quantity");
require(startPrice > 0, "Invalid start price");
require(minBidIncrement > 0, "Invalid min bid increment");
require(duration >= minAuctionDuration && duration <= maxAuctionDuration, "Invalid duration");
if (tokenStandard == TokenStandard.ERC721) {
require(quantity == 1, "ERC721 quantity must be 1");
require(IERC721(collection).ownerOf(tokenId) == msg.sender, "Not token owner");
require(IERC721(collection).getApproved(tokenId) == address(this) ||
IERC721(collection).isApprovedForAll(msg.sender, address(this)), "Not approved");
} else {
require(IERC1155(collection).balanceOf(msg.sender, tokenId) >= quantity, "Insufficient balance");
require(IERC1155(collection).isApprovedForAll(msg.sender, address(this)), "Not approved");
}
Listing storage existingListing = listings[collection][tokenId][msg.sender];
require(
existingListing.quantity == 0 ||
(existingListing.listingType == ListingType.AUCTION &&
auctions[existingListing.auctionId].status != AuctionStatus.ACTIVE),
"Already listed"
);
}
function _createAuctionListing(
address collection,
uint256 tokenId,
uint256 quantity,
uint256 startPrice,
uint256 auctionId,
TokenStandard tokenStandard
) internal {
listings[collection][tokenId][msg.sender] = Listing({
seller: msg.sender,
price: startPrice,
quantity: quantity,
listingType: ListingType.AUCTION,
auctionId: auctionId,
tokenStandard: tokenStandard
});
emit NFTListed(
collection,
tokenId,
msg.sender,
startPrice,
quantity,
ListingType.AUCTION,
auctionId,
tokenStandard
);
}
function _setupAuction(
uint256 auctionId,
address collection,
uint256 tokenId,
uint256 quantity,
uint256 startPrice,
uint256 minBidIncrement,
uint256 duration,
TokenStandard tokenStandard
) internal {
uint256 startTime = block.timestamp;
uint256 endTime = startTime + duration;
auctions[auctionId] = AuctionDetails({
seller: msg.sender,
startPrice: startPrice,
currentPrice: startPrice,
minBidIncrement: minBidIncrement,
startTime: startTime,
endTime: endTime,
tokenId: tokenId,
quantity: quantity,
highestBidder: address(0),
status: AuctionStatus.ACTIVE,
tokenStandard: tokenStandard
});
auctionCollections[auctionId] = collection;
if (tokenStandard == TokenStandard.ERC721) {
IERC721(collection).safeTransferFrom(msg.sender, address(this), tokenId);
} else {
IERC1155(collection).safeTransferFrom(msg.sender, address(this), tokenId, quantity, "");
}
emit AuctionCreated(
auctionId,
collection,
tokenId,
msg.sender,
startPrice,
minBidIncrement,
startTime,
endTime,
quantity,
tokenStandard
);
}
function placeBid(uint256 auctionId, uint256 bidAmount) external nonReentrant {
AuctionDetails storage auction = auctions[auctionId];
require(auction.status == AuctionStatus.ACTIVE, "Auction not active");
require(block.timestamp <= auction.endTime, "Auction ended");
require(bidAmount >= auction.currentPrice + auction.minBidIncrement, "Bid too low");
// Check if bid is placed near the end
if (auction.endTime - block.timestamp <= auctionExtensionInterval) {
auction.endTime = block.timestamp + auctionExtensionInterval;
emit AuctionExtended(auctionId, auction.endTime);
}
address previousBidder = auction.highestBidder;
uint256 previousBid = bids[auctionId][previousBidder];
if (previousBidder != address(0)) {
designatedToken.transfer(previousBidder, previousBid);
}
require(
designatedToken.transferFrom(msg.sender, address(this), bidAmount),
"Transfer failed"
);
auction.highestBidder = msg.sender;
auction.currentPrice = bidAmount;
bids[auctionId][msg.sender] = bidAmount;
emit BidPlaced(auctionId, msg.sender, bidAmount);
}
function settleAuction(uint256 auctionId) external nonReentrant {
AuctionDetails storage auction = auctions[auctionId];
require(auction.status == AuctionStatus.ACTIVE, "Auction not active");
require(block.timestamp > auction.endTime, "Auction not ended");
require(auction.highestBidder != address(0), "No bids placed");
auction.status = AuctionStatus.ENDED;
address collection = auctionCollections[auctionId];
uint256 finalPrice = auction.currentPrice;
address creator = ICollection(collection).getCreator(auction.tokenId);
uint256 fee = secondaryFee;
if(creator == auction.seller) {
fee = primaryFee;
}
uint16 royaltyPercentage = ICollection(collection).getRoyaltyPercentage();
// Calculate fees
uint256 platformFee = (finalPrice * fee) / 1000;
uint256 royaltyFee = (finalPrice * royaltyPercentage) / 1000;
uint256 sellerAmount = finalPrice - platformFee - royaltyFee;
// Distribute funds
designatedToken.transfer(auction.seller, sellerAmount);
if(royaltyFee>0) {
designatedToken.transfer(creator, royaltyFee);
}
// Transfer NFT
if (auction.tokenStandard == TokenStandard.ERC721) {
IERC721(collection).safeTransferFrom(address(this), auction.highestBidder, auction.tokenId);
} else {
IERC1155(collection).safeTransferFrom(
address(this),
auction.highestBidder,
auction.tokenId,
auction.quantity,
""
);
}
// Remove listing
address seller = auction.seller;
delete listings[collection][auction.tokenId][seller];
emit ListingRemoved(collection, auction.tokenId, seller, "AUCTION_SETTLED");
emit AuctionSettled(auctionId, auction.highestBidder, finalPrice);
}
function cancelAuction(uint256 auctionId) external nonReentrant {
AuctionDetails storage auction = auctions[auctionId];
require(auction.status == AuctionStatus.ACTIVE, "Auction not active");
require(msg.sender == auction.seller, "Not seller");
require(auction.highestBidder == address(0), "Bids already placed");
auction.status = AuctionStatus.CANCELLED;
address collection = auctionCollections[auctionId];
if (auction.tokenStandard == TokenStandard.ERC721) {
IERC721(collection).safeTransferFrom(address(this), auction.seller, auction.tokenId);
} else {
IERC1155(collection).safeTransferFrom(
address(this),
auction.seller,
auction.tokenId,
auction.quantity,
""
);
}
// Remove listing
delete listings[collection][auction.tokenId][auction.seller];
emit ListingRemoved(collection, auction.tokenId, auction.seller, "AUCTION_CANCELLED");
emit AuctionCancelled(auctionId);
}
function setAuctionExtensionInterval(uint256 _interval) external onlyOwner {
require(_interval > 0, "Invalid interval");
auctionExtensionInterval = _interval;
emit AuctionExtensionIntervalUpdated(_interval);
}
function makeOffer(
address collection,
uint256 tokenId,
address seller,
uint256 quantity,
uint256 price,
TokenStandard tokenStandard
) external nonReentrant {
require(registeredCollections[collection], "Collection not registered");
require(quantity > 0, "Invalid quantity");
require(price > 0, "Invalid price");
require(seller != address(0), "Invalid seller");
require(seller != msg.sender, "Cannot make offer to self");
if (tokenStandard == TokenStandard.ERC721) {
require(quantity == 1, "ERC721 quantity must be 1");
require(IERC721(collection).ownerOf(tokenId) == seller, "Seller not owner");
} else {
require(IERC1155(collection).balanceOf(seller, tokenId) >= quantity, "Insufficient seller balance");
}
_offerIds++;
uint256 offerId = _offerIds;
offers[collection][tokenId][offerId] = Offer({
buyer: msg.sender,
seller: seller,
price: price,
quantity: quantity,
createTime: block.timestamp,
status: OfferStatus.PENDING,
tokenStandard: tokenStandard
});
userOfferIds[msg.sender].push(offerId);
sellerReceivedOffers[seller].push(offerId);
tokenOffers[collection][tokenId].push(offerId);
offerCollections[offerId] = collection;
offerTokenIds[offerId] = tokenId;
// Pre-approve marketplace for token transfer
designatedToken.transferFrom(msg.sender, address(this), price * quantity);
emit OfferCreated(offerId, collection, tokenId, msg.sender, seller, price, quantity,tokenStandard);
}
function acceptOffer(uint256 offerId) external nonReentrant {
(address collection, uint256 tokenId, Offer storage offer) = _validateAndGetOffer(offerId);
uint256 totalBalance = _validateSellerBalance(collection, tokenId, offer);
_validateAndUpdateListing(collection, tokenId, offer.quantity, totalBalance);
_processOfferAcceptance(collection, tokenId, offer, offerId);
}
function _validateAndGetOffer(uint256 offerId) private view returns (
address collection,
uint256 tokenId,
Offer storage offer
) {
collection = offerCollections[offerId];
require(collection != address(0), "Offer does not exist");
tokenId = offerTokenIds[offerId];
offer = offers[collection][tokenId][offerId];
require(offer.status == OfferStatus.PENDING, "Invalid offer status");
require(msg.sender == offer.seller, "Not offer recipient");
return (collection, tokenId, offer);
}
function _validateSellerBalance(
address collection,
uint256 tokenId,
Offer memory offer
) private view returns (uint256) {
if (offer.tokenStandard == TokenStandard.ERC721) {
require(IERC721(collection).ownerOf(tokenId) == msg.sender, "Not token owner");
return 1;
} else {
uint256 totalBalance = IERC1155(collection).balanceOf(msg.sender, tokenId);
require(totalBalance >= offer.quantity, "Insufficient balance");
return totalBalance;
}
}
function _validateAndUpdateListing(
address collection,
uint256 tokenId,
uint256 offerQuantity,
uint256 totalBalance
) private {
Listing storage listing = listings[collection][tokenId][msg.sender];
// Check if NFT is not in active auction
if(listing.listingType == ListingType.AUCTION) {
require(
auctions[listing.auctionId].status != AuctionStatus.ACTIVE,
"Active auction exists"
);
}
// Calculate available quantities
uint256 listedQuantity = listing.quantity;
uint256 unlistedQuantity = totalBalance - listedQuantity;
// Calculate how many NFTs to take from unlisted and listed
uint256 takeFromUnlisted = unlistedQuantity >= offerQuantity ?
offerQuantity : unlistedQuantity;
uint256 takeFromListed = offerQuantity - takeFromUnlisted;
// Update listing if needed
if(takeFromListed > 0) {
if(takeFromListed == listedQuantity) {
delete listings[collection][tokenId][msg.sender];
emit ListingRemoved(collection, tokenId, msg.sender, "ZERO_QUANTITY");
} else {
listing.quantity = listedQuantity - takeFromListed;
emit ListingQuantityUpdated(
collection,
tokenId,
msg.sender,
listing.quantity
);
}
}
}
function _processOfferAcceptance(
address collection,
uint256 tokenId,
Offer storage offer,
uint256 offerId
) private {
require(
offer.tokenStandard == TokenStandard.ERC721 ?
IERC721(collection).getApproved(tokenId) == address(this) ||
IERC721(collection).isApprovedForAll(msg.sender, address(this)) :
IERC1155(collection).isApprovedForAll(msg.sender, address(this)),
"Not approved"
);
address creator = ICollection(collection).getCreator(tokenId);
uint256 fee = secondaryFee;
if(creator == msg.sender) {
fee = primaryFee;
}
uint16 royaltyPercentage = ICollection(collection).getRoyaltyPercentage();
// Calculate fees
uint256 totalPrice = offer.price * offer.quantity;
uint256 platformFee = (totalPrice * fee) / 1000;
uint256 royaltyFee = (totalPrice * royaltyPercentage) / 1000;
uint256 sellerAmount = totalPrice - platformFee - royaltyFee;
if (offer.tokenStandard == TokenStandard.ERC721) {
IERC721(collection).safeTransferFrom(msg.sender, offer.buyer, tokenId);
} else {
IERC1155(collection).safeTransferFrom(msg.sender, offer.buyer, tokenId, offer.quantity, "");
}
// Distribute payments
designatedToken.transfer(msg.sender, sellerAmount);
if(royaltyFee>0) {
designatedToken.transfer(creator, royaltyFee);
}
offer.status = OfferStatus.ACCEPTED;
emit OfferAccepted(offerId, msg.sender);
}
function rejectOffer(uint256 offerId) external nonReentrant {
address collection = offerCollections[offerId];
uint256 tokenId = offerTokenIds[offerId];
require(collection != address(0), "Offer does not exist");
Offer storage offer = offers[collection][tokenId][offerId];
require(offer.status == OfferStatus.PENDING, "Invalid offer status");
require(
offer.tokenStandard == TokenStandard.ERC721 ?
IERC721(collection).ownerOf(tokenId) == msg.sender :
IERC1155(collection).balanceOf(msg.sender, tokenId) > 0,
"Not token owner"
);
offer.status = OfferStatus.REJECTED;
// Refund buyer
designatedToken.transfer(offer.buyer, offer.price * offer.quantity);
emit OfferRejected(offerId, msg.sender);
}
function cancelOffer(uint256 offerId) external nonReentrant {
address collection = offerCollections[offerId];
uint256 tokenId = offerTokenIds[offerId];
require(collection != address(0), "Offer does not exist");
Offer storage offer = offers[collection][tokenId][offerId];
require(offer.buyer == msg.sender, "Not offer creator");
require(offer.status == OfferStatus.PENDING, "Invalid offer status");
offer.status = OfferStatus.CANCELLED;
// Refund buyer
designatedToken.transfer(msg.sender, offer.price * offer.quantity);
emit OfferCancelled(offerId, msg.sender);
}
function getOffersByToken(
address collection,
uint256 tokenId,
uint256 offset,
uint256 limit,
TokenStandard tokenStandard
) external view returns (uint256[] memory offerIdList, uint256 total) {
return _getOffersWithFilter(
collection,
tokenId,
address(0), // no user filter
offset,
limit,
0,// filter type: BY_TOKEN
tokenStandard
);
}
function getOffersToSeller(
address seller,
uint256 offset,
uint256 limit
) external view returns (uint256[] memory offerIdList, uint256 total) {
return _getOffersWithFilter(
address(0), // no collection filter
0, // no tokenId filter
seller,
offset,
limit,
1, // filter type: BY_SELLER
TokenStandard.ERC1155
);
}
function getOffersByBuyer(
address buyer,
uint256 offset,
uint256 limit
) external view returns (uint256[] memory offerIdList, uint256 total) {
return _getOffersWithFilter(
address(0), // no collection filter
0, // no tokenId filter
buyer,
offset,
limit,
2, // filter type: BY_BUYER
TokenStandard.ERC1155
);
}
function _getOffersWithFilter(
address collection,
uint256 tokenId,
address user,
uint256 offset,
uint256 limit,
uint8 filterType,
TokenStandard tokenStandard
) private view returns (uint256[] memory offerIdList, uint256 total) {
FilterParams memory params = FilterParams(collection, tokenId, user, filterType, tokenStandard);
uint256[] storage sourceOffers = _getSourceOffers(user, filterType, params);
// Get total count first
uint256 count = _countValidOffers(sourceOffers, params);
if(count == 0 || offset >= count) {
return (new uint256[](0), count);
}
return _getFilteredOffers(sourceOffers, params, offset, limit, count);
}
function _getSourceOffers(address user, uint8 filterType, FilterParams memory params) private view returns (uint256[] storage) {
if (filterType == 0) { // BY_TOKEN
return tokenOffers[params.collection][params.tokenId];
} else if (filterType == 1) { // BY_SELLER
return sellerReceivedOffers[user];
} else { // BY_BUYER
return userOfferIds[user];
}
}
function _countValidOffers(
uint256[] storage sourceOffers,
FilterParams memory params
) private view returns (uint256) {
uint256 count;
for(uint256 i = 0; i < sourceOffers.length; i++) {
if(_isValidOffer(sourceOffers[i], params)) {
count++;
}
}
return count;
}
function _getFilteredOffers(
uint256[] storage sourceOffers,
FilterParams memory params,
uint256 offset,
uint256 limit,
uint256 count
) private view returns (uint256[] memory offerIdList, uint256) {
uint256 size = count - offset;
if(size > limit) {
size = limit;
}
offerIdList = new uint256[](size);
uint256 currentIndex;
uint256 skipped;
for(uint256 i = 0; i < sourceOffers.length && currentIndex < size; i++) {
uint256 offerId = sourceOffers[i];
if(_isValidOffer(offerId, params)) {
if(skipped < offset) {
skipped++;
continue;
}
offerIdList[currentIndex++] = offerId;
}
}
return (offerIdList, count);
}
function _isValidOffer(
uint256 offerId,
FilterParams memory params
) private view returns (bool) {
address offerCollection = offerCollections[offerId];
uint256 offerTokenId = offerTokenIds[offerId];
Offer storage offer = offers[offerCollection][offerTokenId][offerId];
if (params.filterType == 0) { // BY_TOKEN
return offerCollection == params.collection &&
offerTokenId == params.tokenId &&
offer.status == OfferStatus.PENDING;
} else if (params.filterType == 1) { // BY_SELLER
return offer.seller == params.user &&
offer.status == OfferStatus.PENDING;
} else { // BY_BUYER
return offer.buyer == params.user &&
offer.status == OfferStatus.PENDING;
}
}
function getOffer(uint256 offerId) external view returns (
address collection,
uint256 tokenId,
Offer memory offer
) {
collection = offerCollections[offerId];
require(collection != address(0), "Offer does not exist");
tokenId = offerTokenIds[offerId];
offer = offers[collection][tokenId][offerId];
return (collection, tokenId, offer);
}
}
// File contracts/Factory.sol
// Original license: SPDX_License_Identifier: MIT
pragma solidity ^0.8.20;
contract Factory is Ownable {
using Clones for address;
address public immutable collectionImplementation;
address public immutable nftImplementation;
address public marketplace;
mapping(address => address) public collectionsOwnedByUser;
mapping(address => address[]) public userCollections;
mapping(address => address[]) public userNFTs;
mapping(address => bool) public isCollectionCreatedByUs;
event CollectionCreated(address indexed collection, address indexed owner);
event NFT1155Created(address indexed collection, string name, string description, uint tokenId , address user, uint maxSupply);
event NFT712Created(string name, string description, uint tokenId , address user);
event MarketplaceUpdated(address indexed newMarketplace);
constructor(
address _owner,
address _collectionImpl,
address _nftImpl,
address _marketplace
) Ownable(_owner) {
require(_collectionImpl != address(0), "Invalid collection implementation");
require(_nftImpl != address(0), "Invalid NFT implementation");
require(_marketplace != address(0), "Invalid marketplace");
require(_owner != address(0), "Invalid owner address");
collectionImplementation = _collectionImpl;
nftImplementation = _nftImpl;
// INft721(_nftImpl).initialize("KyMatic NFT","KYMTIC-NFT",address(this));
transferOwnership(_owner);
marketplace = _marketplace;
}
function setMarketplace(address _marketplace) external onlyOwner {
require(_marketplace != address(0), "Invalid marketplace address");
marketplace = _marketplace;
emit MarketplaceUpdated(_marketplace);
}
function createCollection(
string memory name,
string memory symbol
) external returns (address) {
require(bytes(name).length > 0, "Invalid name");
require(bytes(symbol).length > 0, "Invalid symbol");
address implementation = collectionImplementation;
address clone = Clones.clone(implementation);
ICollection(clone).initialize(
name,
symbol,
address(this)
);
collectionsOwnedByUser[clone] = msg.sender;
userCollections[msg.sender].push(clone);
isCollectionCreatedByUs[clone] = true;
NFTMarketplace(marketplace).registerCollection(clone);
emit CollectionCreated(clone, msg.sender);
return clone;
}
function createNFT1155(
address collection,
string memory name,
string memory description,
string memory tokenURI,
uint maxSupply
) external returns (uint256){
require(collectionsOwnedByUser[collection] == msg.sender, "You do not own this collection");
require(isCollectionCreatedByUs[collection], "Collection not created by us");
require(bytes(name).length > 0, "Invalid name");
require(bytes(description).length > 0, "Invalid description");
require(bytes(tokenURI).length > 0, "Invalid tokenURI");
require(maxSupply > 0, "Invalid max supply");
uint tokenId = ICollection(collection).createNFT(
name,
description,
tokenURI,
maxSupply,
msg.sender
);
emit NFT1155Created(collection, name, description, tokenId, msg.sender, maxSupply);
return tokenId;
}
function createNFT721(
string memory name,
string memory description,
string memory tokenURI
) external returns (uint256){
require(bytes(name).length > 0, "Invalid name");
require(bytes(description).length > 0, "Invalid description");
require(bytes(tokenURI).length > 0, "Invalid tokenURI");
uint tokenId = INft721(nftImplementation).createNFT(
name,
description,
tokenURI,
msg.sender
);
emit NFT712Created( name, description, tokenId, msg.sender);
return tokenId;
}
function updateRoyaltyPercent1155(address _collection, uint16 _royaltyPercentage) external {
require(collectionsOwnedByUser[_collection] == msg.sender, "You do not own this collection");
ICollection(_collection).updateRoyaltyPercentage(_royaltyPercentage);
}
function updateRoyaltyPercent1155( uint16 _royaltyPercentage) external onlyOwner {
INft721(nftImplementation).updateRoyaltyPercentage(_royaltyPercentage);
}
function verifyCollection(address collection) external view returns (bool) {
return isCollectionCreatedByUs[collection];
}
function getUserCollections(address user) external view returns (address[] memory) {
return userCollections[user];
}
}
Contract ABI
[{"type":"constructor","stateMutability":"nonpayable","inputs":[{"type":"address","name":"_owner","internalType":"address"},{"type":"address","name":"_collectionImpl","internalType":"address"},{"type":"address","name":"_nftImpl","internalType":"address"},{"type":"address","name":"_marketplace","internalType":"address"}]},{"type":"error","name":"FailedDeployment","inputs":[]},{"type":"error","name":"InsufficientBalance","inputs":[{"type":"uint256","name":"balance","internalType":"uint256"},{"type":"uint256","name":"needed","internalType":"uint256"}]},{"type":"error","name":"OwnableInvalidOwner","inputs":[{"type":"address","name":"owner","internalType":"address"}]},{"type":"error","name":"OwnableUnauthorizedAccount","inputs":[{"type":"address","name":"account","internalType":"address"}]},{"type":"event","name":"CollectionCreated","inputs":[{"type":"address","name":"collection","internalType":"address","indexed":true},{"type":"address","name":"owner","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"MarketplaceUpdated","inputs":[{"type":"address","name":"newMarketplace","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"NFT1155Created","inputs":[{"type":"address","name":"collection","internalType":"address","indexed":true},{"type":"string","name":"name","internalType":"string","indexed":false},{"type":"string","name":"description","internalType":"string","indexed":false},{"type":"uint256","name":"tokenId","internalType":"uint256","indexed":false},{"type":"address","name":"user","internalType":"address","indexed":false},{"type":"uint256","name":"maxSupply","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"NFT712Created","inputs":[{"type":"string","name":"name","internalType":"string","indexed":false},{"type":"string","name":"description","internalType":"string","indexed":false},{"type":"uint256","name":"tokenId","internalType":"uint256","indexed":false},{"type":"address","name":"user","internalType":"address","indexed":false}],"anonymous":false},{"type":"event","name":"OwnershipTransferred","inputs":[{"type":"address","name":"previousOwner","internalType":"address","indexed":true},{"type":"address","name":"newOwner","internalType":"address","indexed":true}],"anonymous":false},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"collectionImplementation","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"collectionsOwnedByUser","inputs":[{"type":"address","name":"","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"createCollection","inputs":[{"type":"string","name":"name","internalType":"string"},{"type":"string","name":"symbol","internalType":"string"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"createNFT1155","inputs":[{"type":"address","name":"collection","internalType":"address"},{"type":"string","name":"name","internalType":"string"},{"type":"string","name":"description","internalType":"string"},{"type":"string","name":"tokenURI","internalType":"string"},{"type":"uint256","name":"maxSupply","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"createNFT721","inputs":[{"type":"string","name":"name","internalType":"string"},{"type":"string","name":"description","internalType":"string"},{"type":"string","name":"tokenURI","internalType":"string"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address[]","name":"","internalType":"address[]"}],"name":"getUserCollections","inputs":[{"type":"address","name":"user","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"isCollectionCreatedByUs","inputs":[{"type":"address","name":"","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"marketplace","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"nftImplementation","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"owner","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"renounceOwnership","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setMarketplace","inputs":[{"type":"address","name":"_marketplace","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"transferOwnership","inputs":[{"type":"address","name":"newOwner","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"updateRoyaltyPercent1155","inputs":[{"type":"uint16","name":"_royaltyPercentage","internalType":"uint16"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"updateRoyaltyPercent1155","inputs":[{"type":"address","name":"_collection","internalType":"address"},{"type":"uint16","name":"_royaltyPercentage","internalType":"uint16"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"userCollections","inputs":[{"type":"address","name":"","internalType":"address"},{"type":"uint256","name":"","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"userNFTs","inputs":[{"type":"address","name":"","internalType":"address"},{"type":"uint256","name":"","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"verifyCollection","inputs":[{"type":"address","name":"collection","internalType":"address"}]}]
Contract Creation Code
0x60c06040523480156200001157600080fd5b506040516200160b3803806200160b833981016040819052620000349162000305565b836001600160a01b0381166200006557604051631e4fbdf760e01b8152600060048201526024015b60405180910390fd5b620000708162000223565b506001600160a01b038316620000d35760405162461bcd60e51b815260206004820152602160248201527f496e76616c696420636f6c6c656374696f6e20696d706c656d656e746174696f6044820152603760f91b60648201526084016200005c565b6001600160a01b0382166200012b5760405162461bcd60e51b815260206004820152601a60248201527f496e76616c6964204e465420696d706c656d656e746174696f6e00000000000060448201526064016200005c565b6001600160a01b038116620001835760405162461bcd60e51b815260206004820152601360248201527f496e76616c6964206d61726b6574706c6163650000000000000000000000000060448201526064016200005c565b6001600160a01b038416620001db5760405162461bcd60e51b815260206004820152601560248201527f496e76616c6964206f776e65722061646472657373000000000000000000000060448201526064016200005c565b6001600160a01b03808416608052821660a052620001f98462000273565b600180546001600160a01b0319166001600160a01b03929092169190911790555062000362915050565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6200027d620002b7565b6001600160a01b038116620002a957604051631e4fbdf760e01b8152600060048201526024016200005c565b620002b48162000223565b50565b6000546001600160a01b03163314620002e65760405163118cdaa760e01b81523360048201526024016200005c565b565b80516001600160a01b03811681146200030057600080fd5b919050565b600080600080608085870312156200031c57600080fd5b6200032785620002e8565b93506200033760208601620002e8565b92506200034760408601620002e8565b91506200035760608601620002e8565b905092959194509250565b60805160a05161126e6200039d600039600081816102c8015281816105bb01526106a10152600081816101380152610359015261126e6000f3fe608060405234801561001057600080fd5b50600436106100f65760003560e01c8063715018a611610092578063715018a61461021557806373ad6c2d1461021d5780638b7f46e7146102305780638da5cb5b146102435780639aa5ad8c14610254578063abc8c7af14610274578063e077db0f14610287578063f2fde38b146102b0578063f61ac58b146102c357600080fd5b80630bd11491146100fb5780630f3b901f14610133578063176b9b7514610167578063291c73c31461017a5780633908cc931461018d578063428a6171146101b95780635057a065146101cc57806352b82af7146101ed5780635bcb013214610202575b600080fd5b61011e610109366004610c68565b60056020526000908152604090205460ff1681565b60405190151581526020015b60405180910390f35b61015a7f000000000000000000000000000000000000000000000000000000000000000081565b60405161012a9190610c8a565b61015a610175366004610d41565b6102ea565b61015a610188366004610da5565b6104e9565b61011e61019b366004610c68565b6001600160a01b031660009081526005602052604090205460ff1690565b61015a6101c7366004610da5565b610521565b6101df6101da366004610dcf565b61053d565b60405190815260200161012a565b6102006101fb366004610e69565b610680565b005b610200610210366004610e84565b610708565b6102006107a2565b61020061022b366004610c68565b6107b6565b6101df61023e366004610eb7565b61085e565b6000546001600160a01b031661015a565b610267610262366004610c68565b610a78565b60405161012a9190610f58565b60015461015a906001600160a01b031681565b61015a610295366004610c68565b6002602052600090815260409020546001600160a01b031681565b6102006102be366004610c68565b610aee565b61015a7f000000000000000000000000000000000000000000000000000000000000000081565b6000808351116103155760405162461bcd60e51b815260040161030c90610fa5565b60405180910390fd5b60008251116103575760405162461bcd60e51b815260206004820152600e60248201526d125b9d985b1a59081cde5b589bdb60921b604482015260640161030c565b7f0000000000000000000000000000000000000000000000000000000000000000600061038382610b2c565b6040516303bf912560e11b81529091506001600160a01b0382169063077f224a906103b690889088903090600401611011565b600060405180830381600087803b1580156103d057600080fd5b505af11580156103e4573d6000803e3d6000fd5b505050506001600160a01b0381811660008181526002602090815260408083208054336001600160a01b03199182168117909255908452600383528184208054600181810183559186528486200180549092168617909155938352600590915290819020805460ff191683179055905490516320e202bb60e11b81529116906341c4057690610477908490600401610c8a565b600060405180830381600087803b15801561049157600080fd5b505af11580156104a5573d6000803e3d6000fd5b50506040513392506001600160a01b03841691507f5d0de243db1669e3a7056744cd715c625f0c1c348736c2c2d53d0ddebff1a6c790600090a39150505b92915050565b6004602052816000526040600020818154811061050557600080fd5b6000918252602090912001546001600160a01b03169150829050565b6003602052816000526040600020818154811061050557600080fd5b60008084511161055f5760405162461bcd60e51b815260040161030c90610fa5565b60008351116105805760405162461bcd60e51b815260040161030c9061104f565b60008251116105a15760405162461bcd60e51b815260040161030c9061107c565b604051635ecd55f760e11b81526000906001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063bd9aabee906105f69088908890889033906004016110a6565b6020604051808303816000875af1158015610615573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061063991906110f9565b90507fc0f07814b57730c5d143982c321d605266305b47c8f64d1a8bad4dba35869b15858583336040516106709493929190611112565b60405180910390a1949350505050565b610688610b39565b604051630a41faf360e21b815261ffff821660048201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690632907ebcc90602401600060405180830381600087803b1580156106ed57600080fd5b505af1158015610701573d6000803e3d6000fd5b5050505050565b6001600160a01b038281166000908152600260205260409020541633146107415760405162461bcd60e51b815260040161030c90611159565b604051630a41faf360e21b815261ffff821660048201526001600160a01b03831690632907ebcc90602401600060405180830381600087803b15801561078657600080fd5b505af115801561079a573d6000803e3d6000fd5b505050505050565b6107aa610b39565b6107b46000610b66565b565b6107be610b39565b6001600160a01b0381166108145760405162461bcd60e51b815260206004820152601b60248201527f496e76616c6964206d61726b6574706c61636520616464726573730000000000604482015260640161030c565b600180546001600160a01b0319166001600160a01b0383169081179091556040517f210690abd7fd6cdbb8f2beb202b2a253d58d7a0813b2175c4172c14c0c1af6dc90600090a250565b6001600160a01b0385811660009081526002602052604081205490911633146108995760405162461bcd60e51b815260040161030c90611159565b6001600160a01b03861660009081526005602052604090205460ff166109015760405162461bcd60e51b815260206004820152601c60248201527f436f6c6c656374696f6e206e6f74206372656174656420627920757300000000604482015260640161030c565b60008551116109225760405162461bcd60e51b815260040161030c90610fa5565b60008451116109435760405162461bcd60e51b815260040161030c9061104f565b60008351116109645760405162461bcd60e51b815260040161030c9061107c565b600082116109a95760405162461bcd60e51b8152602060048201526012602482015271496e76616c6964206d617820737570706c7960701b604482015260640161030c565b604051630a72e71960e11b81526000906001600160a01b038816906314e5ce32906109e09089908990899089903390600401611190565b6020604051808303816000875af11580156109ff573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a2391906110f9565b9050866001600160a01b03167fed7e2cb9ffe7ff43e2b8fb0721f7c26e848e43370690542d506fe0cb3af1723b8787843388604051610a669594939291906111ec565b60405180910390a29695505050505050565b6001600160a01b038116600090815260036020908152604091829020805483518184028101840190945280845260609392830182828015610ae257602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311610ac4575b50505050509050919050565b610af6610b39565b6001600160a01b038116610b20576000604051631e4fbdf760e01b815260040161030c9190610c8a565b610b2981610b66565b50565b60006104e3826000610bb6565b6000546001600160a01b031633146107b4573360405163118cdaa760e01b815260040161030c9190610c8a565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b600081471015610be25760405163cf47918160e01b81524760048201526024810183905260440161030c565b763d602d80600a3d3981f3363d3d373d3d3d363d730000008360601b60e81c176000526e5af43d82803e903d91602b57fd5bf38360781b176020526037600983f090506001600160a01b0381166104e35760405163b06ebf3d60e01b815260040160405180910390fd5b80356001600160a01b0381168114610c6357600080fd5b919050565b600060208284031215610c7a57600080fd5b610c8382610c4c565b9392505050565b6001600160a01b0391909116815260200190565b634e487b7160e01b600052604160045260246000fd5b600082601f830112610cc557600080fd5b813567ffffffffffffffff80821115610ce057610ce0610c9e565b604051601f8301601f19908116603f01168101908282118183101715610d0857610d08610c9e565b81604052838152866020858801011115610d2157600080fd5b836020870160208301376000602085830101528094505050505092915050565b60008060408385031215610d5457600080fd5b823567ffffffffffffffff80821115610d6c57600080fd5b610d7886838701610cb4565b93506020850135915080821115610d8e57600080fd5b50610d9b85828601610cb4565b9150509250929050565b60008060408385031215610db857600080fd5b610dc183610c4c565b946020939093013593505050565b600080600060608486031215610de457600080fd5b833567ffffffffffffffff80821115610dfc57600080fd5b610e0887838801610cb4565b94506020860135915080821115610e1e57600080fd5b610e2a87838801610cb4565b93506040860135915080821115610e4057600080fd5b50610e4d86828701610cb4565b9150509250925092565b803561ffff81168114610c6357600080fd5b600060208284031215610e7b57600080fd5b610c8382610e57565b60008060408385031215610e9757600080fd5b610ea083610c4c565b9150610eae60208401610e57565b90509250929050565b600080600080600060a08688031215610ecf57600080fd5b610ed886610c4c565b9450602086013567ffffffffffffffff80821115610ef557600080fd5b610f0189838a01610cb4565b95506040880135915080821115610f1757600080fd5b610f2389838a01610cb4565b94506060880135915080821115610f3957600080fd5b50610f4688828901610cb4565b95989497509295608001359392505050565b6020808252825182820181905260009190848201906040850190845b81811015610f995783516001600160a01b031683529284019291840191600101610f74565b50909695505050505050565b6020808252600c908201526b496e76616c6964206e616d6560a01b604082015260600190565b6000815180845260005b81811015610ff157602081850181015186830182015201610fd5565b506000602082860101526020601f19601f83011685010191505092915050565b6060815260006110246060830186610fcb565b82810360208401526110368186610fcb565b91505060018060a01b0383166040830152949350505050565b60208082526013908201527224b73b30b634b2103232b9b1b934b83a34b7b760691b604082015260600190565b60208082526010908201526f496e76616c696420746f6b656e55524960801b604082015260600190565b6080815260006110b96080830187610fcb565b82810360208401526110cb8187610fcb565b905082810360408401526110df8186610fcb565b91505060018060a01b038316606083015295945050505050565b60006020828403121561110b57600080fd5b5051919050565b6080815260006111256080830187610fcb565b82810360208401526111378187610fcb565b604084019590955250506001600160a01b039190911660609091015292915050565b6020808252601e908201527f596f7520646f206e6f74206f776e207468697320636f6c6c656374696f6e0000604082015260600190565b60a0815260006111a360a0830188610fcb565b82810360208401526111b58188610fcb565b905082810360408401526111c98187610fcb565b606084019590955250506001600160a01b03919091166080909101529392505050565b60a0815260006111ff60a0830188610fcb565b82810360208401526112118188610fcb565b604084019690965250506001600160a01b039290921660608301526080909101529291505056fea264697066735822122001f25437b490aa195f8a0ec8244994b465812cee7824dc374c2246f13a0abc3064736f6c63430008140033000000000000000000000000d5248ed905a803c74aa753fc36a5a936945625b7000000000000000000000000ce5b6f27c495aeb6edc1547da15248b109bda66d000000000000000000000000d52cc3e13984b763ddc83409df4612968dc40e1e000000000000000000000000804c3dc3d8a578741b9fa5e991456524b3f73fa4
Deployed ByteCode
0x608060405234801561001057600080fd5b50600436106100f65760003560e01c8063715018a611610092578063715018a61461021557806373ad6c2d1461021d5780638b7f46e7146102305780638da5cb5b146102435780639aa5ad8c14610254578063abc8c7af14610274578063e077db0f14610287578063f2fde38b146102b0578063f61ac58b146102c357600080fd5b80630bd11491146100fb5780630f3b901f14610133578063176b9b7514610167578063291c73c31461017a5780633908cc931461018d578063428a6171146101b95780635057a065146101cc57806352b82af7146101ed5780635bcb013214610202575b600080fd5b61011e610109366004610c68565b60056020526000908152604090205460ff1681565b60405190151581526020015b60405180910390f35b61015a7f000000000000000000000000ce5b6f27c495aeb6edc1547da15248b109bda66d81565b60405161012a9190610c8a565b61015a610175366004610d41565b6102ea565b61015a610188366004610da5565b6104e9565b61011e61019b366004610c68565b6001600160a01b031660009081526005602052604090205460ff1690565b61015a6101c7366004610da5565b610521565b6101df6101da366004610dcf565b61053d565b60405190815260200161012a565b6102006101fb366004610e69565b610680565b005b610200610210366004610e84565b610708565b6102006107a2565b61020061022b366004610c68565b6107b6565b6101df61023e366004610eb7565b61085e565b6000546001600160a01b031661015a565b610267610262366004610c68565b610a78565b60405161012a9190610f58565b60015461015a906001600160a01b031681565b61015a610295366004610c68565b6002602052600090815260409020546001600160a01b031681565b6102006102be366004610c68565b610aee565b61015a7f000000000000000000000000d52cc3e13984b763ddc83409df4612968dc40e1e81565b6000808351116103155760405162461bcd60e51b815260040161030c90610fa5565b60405180910390fd5b60008251116103575760405162461bcd60e51b815260206004820152600e60248201526d125b9d985b1a59081cde5b589bdb60921b604482015260640161030c565b7f000000000000000000000000ce5b6f27c495aeb6edc1547da15248b109bda66d600061038382610b2c565b6040516303bf912560e11b81529091506001600160a01b0382169063077f224a906103b690889088903090600401611011565b600060405180830381600087803b1580156103d057600080fd5b505af11580156103e4573d6000803e3d6000fd5b505050506001600160a01b0381811660008181526002602090815260408083208054336001600160a01b03199182168117909255908452600383528184208054600181810183559186528486200180549092168617909155938352600590915290819020805460ff191683179055905490516320e202bb60e11b81529116906341c4057690610477908490600401610c8a565b600060405180830381600087803b15801561049157600080fd5b505af11580156104a5573d6000803e3d6000fd5b50506040513392506001600160a01b03841691507f5d0de243db1669e3a7056744cd715c625f0c1c348736c2c2d53d0ddebff1a6c790600090a39150505b92915050565b6004602052816000526040600020818154811061050557600080fd5b6000918252602090912001546001600160a01b03169150829050565b6003602052816000526040600020818154811061050557600080fd5b60008084511161055f5760405162461bcd60e51b815260040161030c90610fa5565b60008351116105805760405162461bcd60e51b815260040161030c9061104f565b60008251116105a15760405162461bcd60e51b815260040161030c9061107c565b604051635ecd55f760e11b81526000906001600160a01b037f000000000000000000000000d52cc3e13984b763ddc83409df4612968dc40e1e169063bd9aabee906105f69088908890889033906004016110a6565b6020604051808303816000875af1158015610615573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061063991906110f9565b90507fc0f07814b57730c5d143982c321d605266305b47c8f64d1a8bad4dba35869b15858583336040516106709493929190611112565b60405180910390a1949350505050565b610688610b39565b604051630a41faf360e21b815261ffff821660048201527f000000000000000000000000d52cc3e13984b763ddc83409df4612968dc40e1e6001600160a01b031690632907ebcc90602401600060405180830381600087803b1580156106ed57600080fd5b505af1158015610701573d6000803e3d6000fd5b5050505050565b6001600160a01b038281166000908152600260205260409020541633146107415760405162461bcd60e51b815260040161030c90611159565b604051630a41faf360e21b815261ffff821660048201526001600160a01b03831690632907ebcc90602401600060405180830381600087803b15801561078657600080fd5b505af115801561079a573d6000803e3d6000fd5b505050505050565b6107aa610b39565b6107b46000610b66565b565b6107be610b39565b6001600160a01b0381166108145760405162461bcd60e51b815260206004820152601b60248201527f496e76616c6964206d61726b6574706c61636520616464726573730000000000604482015260640161030c565b600180546001600160a01b0319166001600160a01b0383169081179091556040517f210690abd7fd6cdbb8f2beb202b2a253d58d7a0813b2175c4172c14c0c1af6dc90600090a250565b6001600160a01b0385811660009081526002602052604081205490911633146108995760405162461bcd60e51b815260040161030c90611159565b6001600160a01b03861660009081526005602052604090205460ff166109015760405162461bcd60e51b815260206004820152601c60248201527f436f6c6c656374696f6e206e6f74206372656174656420627920757300000000604482015260640161030c565b60008551116109225760405162461bcd60e51b815260040161030c90610fa5565b60008451116109435760405162461bcd60e51b815260040161030c9061104f565b60008351116109645760405162461bcd60e51b815260040161030c9061107c565b600082116109a95760405162461bcd60e51b8152602060048201526012602482015271496e76616c6964206d617820737570706c7960701b604482015260640161030c565b604051630a72e71960e11b81526000906001600160a01b038816906314e5ce32906109e09089908990899089903390600401611190565b6020604051808303816000875af11580156109ff573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a2391906110f9565b9050866001600160a01b03167fed7e2cb9ffe7ff43e2b8fb0721f7c26e848e43370690542d506fe0cb3af1723b8787843388604051610a669594939291906111ec565b60405180910390a29695505050505050565b6001600160a01b038116600090815260036020908152604091829020805483518184028101840190945280845260609392830182828015610ae257602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311610ac4575b50505050509050919050565b610af6610b39565b6001600160a01b038116610b20576000604051631e4fbdf760e01b815260040161030c9190610c8a565b610b2981610b66565b50565b60006104e3826000610bb6565b6000546001600160a01b031633146107b4573360405163118cdaa760e01b815260040161030c9190610c8a565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b600081471015610be25760405163cf47918160e01b81524760048201526024810183905260440161030c565b763d602d80600a3d3981f3363d3d373d3d3d363d730000008360601b60e81c176000526e5af43d82803e903d91602b57fd5bf38360781b176020526037600983f090506001600160a01b0381166104e35760405163b06ebf3d60e01b815260040160405180910390fd5b80356001600160a01b0381168114610c6357600080fd5b919050565b600060208284031215610c7a57600080fd5b610c8382610c4c565b9392505050565b6001600160a01b0391909116815260200190565b634e487b7160e01b600052604160045260246000fd5b600082601f830112610cc557600080fd5b813567ffffffffffffffff80821115610ce057610ce0610c9e565b604051601f8301601f19908116603f01168101908282118183101715610d0857610d08610c9e565b81604052838152866020858801011115610d2157600080fd5b836020870160208301376000602085830101528094505050505092915050565b60008060408385031215610d5457600080fd5b823567ffffffffffffffff80821115610d6c57600080fd5b610d7886838701610cb4565b93506020850135915080821115610d8e57600080fd5b50610d9b85828601610cb4565b9150509250929050565b60008060408385031215610db857600080fd5b610dc183610c4c565b946020939093013593505050565b600080600060608486031215610de457600080fd5b833567ffffffffffffffff80821115610dfc57600080fd5b610e0887838801610cb4565b94506020860135915080821115610e1e57600080fd5b610e2a87838801610cb4565b93506040860135915080821115610e4057600080fd5b50610e4d86828701610cb4565b9150509250925092565b803561ffff81168114610c6357600080fd5b600060208284031215610e7b57600080fd5b610c8382610e57565b60008060408385031215610e9757600080fd5b610ea083610c4c565b9150610eae60208401610e57565b90509250929050565b600080600080600060a08688031215610ecf57600080fd5b610ed886610c4c565b9450602086013567ffffffffffffffff80821115610ef557600080fd5b610f0189838a01610cb4565b95506040880135915080821115610f1757600080fd5b610f2389838a01610cb4565b94506060880135915080821115610f3957600080fd5b50610f4688828901610cb4565b95989497509295608001359392505050565b6020808252825182820181905260009190848201906040850190845b81811015610f995783516001600160a01b031683529284019291840191600101610f74565b50909695505050505050565b6020808252600c908201526b496e76616c6964206e616d6560a01b604082015260600190565b6000815180845260005b81811015610ff157602081850181015186830182015201610fd5565b506000602082860101526020601f19601f83011685010191505092915050565b6060815260006110246060830186610fcb565b82810360208401526110368186610fcb565b91505060018060a01b0383166040830152949350505050565b60208082526013908201527224b73b30b634b2103232b9b1b934b83a34b7b760691b604082015260600190565b60208082526010908201526f496e76616c696420746f6b656e55524960801b604082015260600190565b6080815260006110b96080830187610fcb565b82810360208401526110cb8187610fcb565b905082810360408401526110df8186610fcb565b91505060018060a01b038316606083015295945050505050565b60006020828403121561110b57600080fd5b5051919050565b6080815260006111256080830187610fcb565b82810360208401526111378187610fcb565b604084019590955250506001600160a01b039190911660609091015292915050565b6020808252601e908201527f596f7520646f206e6f74206f776e207468697320636f6c6c656374696f6e0000604082015260600190565b60a0815260006111a360a0830188610fcb565b82810360208401526111b58188610fcb565b905082810360408401526111c98187610fcb565b606084019590955250506001600160a01b03919091166080909101529392505050565b60a0815260006111ff60a0830188610fcb565b82810360208401526112118188610fcb565b604084019690965250506001600160a01b039290921660608301526080909101529291505056fea264697066735822122001f25437b490aa195f8a0ec8244994b465812cee7824dc374c2246f13a0abc3064736f6c63430008140033