-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
67e750f
commit a447b5d
Showing
7 changed files
with
519 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
src/tokens/ERC1155/presets/operator-enforced/ERC1155OperatorEnforced.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.8.19; | ||
|
||
import {ERC1155Items} from "@0xsequence/contracts-library/tokens/ERC1155/presets/items/ERC1155Items.sol"; | ||
import {OperatorAllowlistEnforced} from | ||
"@0xsequence/contracts-library/tokens/common/immutable/OperatorAllowlistEnforced.sol"; | ||
|
||
/** | ||
* An implementation of ERC-1155 that prevents transfers. | ||
*/ | ||
contract ERC1155OperatorEnforced is ERC1155Items, OperatorAllowlistEnforced { | ||
constructor() ERC1155Items() {} | ||
|
||
/** | ||
* Initialize the contract. | ||
* @param owner Owner address | ||
* @param tokenName Token name | ||
* @param tokenBaseURI Base URI for token metadata | ||
* @param tokenContractURI Contract URI for token metadata | ||
* @param royaltyReceiver Address of who should be sent the royalty payment | ||
* @param royaltyFeeNumerator The royalty fee numerator in basis points (e.g. 15% would be 1500) | ||
* @param operatorAllowlist Address of the operator allowlist | ||
* @dev This should be called immediately after deployment. | ||
*/ | ||
function initialize( | ||
address owner, | ||
string memory tokenName, | ||
string memory tokenBaseURI, | ||
string memory tokenContractURI, | ||
address royaltyReceiver, | ||
uint96 royaltyFeeNumerator, | ||
address operatorAllowlist | ||
) public virtual { | ||
_setOperatorAllowlistRegistry(operatorAllowlist); | ||
ERC1155Items.initialize(owner, tokenName, tokenBaseURI, tokenContractURI, royaltyReceiver, royaltyFeeNumerator); | ||
} | ||
|
||
// | ||
// Operator Allowlist | ||
// | ||
|
||
/** | ||
* Set the operator allowlist registry. | ||
* @param operatorAllowlist Address of the operator allowlist | ||
*/ | ||
function setOperatorAllowlistRegistry(address operatorAllowlist) external onlyRole(DEFAULT_ADMIN_ROLE) { | ||
_setOperatorAllowlistRegistry(operatorAllowlist); | ||
} | ||
|
||
function setApprovalForAll(address operator, bool approved) public override validateApproval(operator) { | ||
super.setApprovalForAll(operator, approved); | ||
} | ||
|
||
function _safeTransferFrom(address from, address to, uint256 id, uint256 amount) internal virtual override { | ||
if (from != address(0)) { | ||
// Ignore validation on minting | ||
_validateTransfer(from, to); | ||
} | ||
super._safeTransferFrom(from, to, id, amount); | ||
} | ||
|
||
function _safeBatchTransferFrom(address from, address to, uint256[] memory ids, uint256[] memory amounts) | ||
internal | ||
virtual | ||
override | ||
{ | ||
if (from != address(0)) { | ||
// Ignore validation on minting | ||
_validateTransfer(from, to); | ||
} | ||
super._safeBatchTransferFrom(from, to, ids, amounts); | ||
} | ||
|
||
function _burn(address from, uint256 id, uint256 amount) | ||
internal | ||
virtual | ||
override | ||
validateTransfer(from, address(0)) | ||
{ | ||
super._burn(from, id, amount); | ||
} | ||
|
||
function _batchBurn(address from, uint256[] memory ids, uint256[] memory amounts) | ||
internal | ||
virtual | ||
override | ||
validateTransfer(from, address(0)) | ||
{ | ||
super._batchBurn(from, ids, amounts); | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
src/tokens/ERC1155/presets/operator-enforced/ERC1155OperatorEnforcedFactory.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.8.19; | ||
|
||
import { | ||
IERC1155OperatorEnforcedFactory, | ||
IERC1155OperatorEnforcedFactoryFunctions | ||
} from "@0xsequence/contracts-library/tokens/ERC1155/presets/operator-enforced/IERC1155OperatorEnforcedFactory.sol"; | ||
import {ERC1155OperatorEnforced} from | ||
"@0xsequence/contracts-library/tokens/ERC1155/presets/operator-enforced/ERC1155OperatorEnforced.sol"; | ||
import {SequenceProxyFactory} from "@0xsequence/contracts-library/proxies/SequenceProxyFactory.sol"; | ||
|
||
/** | ||
* Deployer of ERC-1155 Operator Enforced proxies. | ||
*/ | ||
contract ERC1155OperatorEnforcedFactory is IERC1155OperatorEnforcedFactory, SequenceProxyFactory { | ||
/** | ||
* Creates an ERC-1155 Operator Enforced Factory. | ||
* @param factoryOwner The owner of the ERC-1155 Operator Enforced Factory | ||
*/ | ||
constructor(address factoryOwner) { | ||
ERC1155OperatorEnforced impl = new ERC1155OperatorEnforced(); | ||
SequenceProxyFactory._initialize(address(impl), factoryOwner); | ||
} | ||
|
||
/// @inheritdoc IERC1155OperatorEnforcedFactoryFunctions | ||
function deploy( | ||
address proxyOwner, | ||
address tokenOwner, | ||
string memory tokenName, | ||
string memory tokenBaseURI, | ||
string memory tokenContractURI, | ||
address royaltyReceiver, | ||
uint96 royaltyFeeNumerator, | ||
address operatorAllowlist | ||
) external returns (address proxyAddr) { | ||
bytes32 salt = keccak256( | ||
abi.encode( | ||
tokenOwner, | ||
tokenName, | ||
tokenBaseURI, | ||
tokenContractURI, | ||
royaltyReceiver, | ||
royaltyFeeNumerator, | ||
operatorAllowlist | ||
) | ||
); | ||
proxyAddr = _createProxy(salt, proxyOwner, ""); | ||
ERC1155OperatorEnforced(proxyAddr).initialize( | ||
tokenOwner, | ||
tokenName, | ||
tokenBaseURI, | ||
tokenContractURI, | ||
royaltyReceiver, | ||
royaltyFeeNumerator, | ||
operatorAllowlist | ||
); | ||
emit ERC1155OperatorEnforcedDeployed(proxyAddr); | ||
return proxyAddr; | ||
} | ||
|
||
/// @inheritdoc IERC1155OperatorEnforcedFactoryFunctions | ||
function determineAddress( | ||
address proxyOwner, | ||
address tokenOwner, | ||
string memory tokenName, | ||
string memory tokenBaseURI, | ||
string memory tokenContractURI, | ||
address royaltyReceiver, | ||
uint96 royaltyFeeNumerator, | ||
address operatorAllowlist | ||
) external view returns (address proxyAddr) { | ||
bytes32 salt = keccak256( | ||
abi.encode( | ||
tokenOwner, | ||
tokenName, | ||
tokenBaseURI, | ||
tokenContractURI, | ||
royaltyReceiver, | ||
royaltyFeeNumerator, | ||
operatorAllowlist | ||
) | ||
); | ||
return _computeProxyAddress(salt, proxyOwner, ""); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
src/tokens/ERC1155/presets/operator-enforced/IERC1155OperatorEnforcedFactory.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.8.19; | ||
|
||
interface IERC1155OperatorEnforcedFactoryFunctions { | ||
/** | ||
* Creates an ERC-1155 Operator Enforced proxy. | ||
* @param proxyOwner The owner of the ERC-1155 Operator Enforced proxy | ||
* @param tokenOwner The owner of the ERC-1155 Operator Enforced implementation | ||
* @param tokenName Token name | ||
* @param tokenBaseURI Base URI for token metadata | ||
* @param tokenContractURI Contract URI for token metadata | ||
* @param royaltyReceiver Address of who should be sent the royalty payment | ||
* @param royaltyFeeNumerator The royalty fee numerator in basis points (e.g. 15% would be 1500) | ||
* @param operatorAllowlist Address of the operator allowlist | ||
* @return proxyAddr The address of the ERC-1155 Operator Enforced Proxy | ||
*/ | ||
function deploy( | ||
address proxyOwner, | ||
address tokenOwner, | ||
string memory tokenName, | ||
string memory tokenBaseURI, | ||
string memory tokenContractURI, | ||
address royaltyReceiver, | ||
uint96 royaltyFeeNumerator, | ||
address operatorAllowlist | ||
) external returns (address proxyAddr); | ||
|
||
/** | ||
* Computes the address of a proxy instance. | ||
* @param proxyOwner The owner of the ERC-1155 Operator Enforced proxy | ||
* @param tokenOwner The owner of the ERC-1155 Operator Enforced implementation | ||
* @param tokenName Token name | ||
* @param tokenBaseURI Base URI for token metadata | ||
* @param tokenContractURI Contract URI for token metadata | ||
* @param royaltyReceiver Address of who should be sent the royalty payment | ||
* @param royaltyFeeNumerator The royalty fee numerator in basis points (e.g. 15% would be 1500) | ||
* @param operatorAllowlist Address of the operator allowlist | ||
* @return proxyAddr The address of the ERC-1155 Operator Enforced Proxy | ||
*/ | ||
function determineAddress( | ||
address proxyOwner, | ||
address tokenOwner, | ||
string memory tokenName, | ||
string memory tokenBaseURI, | ||
string memory tokenContractURI, | ||
address royaltyReceiver, | ||
uint96 royaltyFeeNumerator, | ||
address operatorAllowlist | ||
) external returns (address proxyAddr); | ||
} | ||
|
||
interface IERC1155OperatorEnforcedFactorySignals { | ||
/** | ||
* Event emitted when a new ERC-1155 Operator Enforced proxy contract is deployed. | ||
* @param proxyAddr The address of the deployed proxy. | ||
*/ | ||
event ERC1155OperatorEnforcedDeployed(address proxyAddr); | ||
} | ||
|
||
interface IERC1155OperatorEnforcedFactory is | ||
IERC1155OperatorEnforcedFactoryFunctions, | ||
IERC1155OperatorEnforcedFactorySignals | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.