generated from ProjectOpenSea/shipyard
-
Notifications
You must be signed in to change notification settings - Fork 128
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
Showing
13 changed files
with
431 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,7 @@ src/clones | |
src/test/ | ||
src/shim/ | ||
|
||
src/interfaces/ITransferValidator.sol | ||
|
||
test/ | ||
lib/ |
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
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
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,21 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.17; | ||
|
||
interface ITransferValidator { | ||
/// @notice Ensure that a transfer has been authorized for a specific tokenId | ||
function validateTransfer( | ||
address caller, | ||
address from, | ||
address to, | ||
uint256 tokenId | ||
) external view; | ||
|
||
/// @notice Ensure that a transfer has been authorized for a specific amount of a specific tokenId, and reduce the transferable amount remaining | ||
function validateTransfer( | ||
address caller, | ||
address from, | ||
address to, | ||
uint256 tokenId, | ||
uint256 amount | ||
) external; | ||
} |
33 changes: 33 additions & 0 deletions
33
src-upgradeable/src/lib/ERC721AConduitPreapprovedUpgradeable.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,33 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.17; | ||
|
||
import { ERC721AUpgradeable } from "../../lib/ERC721A-Upgradeable/contracts/ERC721AUpgradeable.sol"; | ||
|
||
/** | ||
* @title ERC721AConduitPreapproved | ||
* @notice ERC721A with the OpenSea conduit preapproved. | ||
*/ | ||
abstract contract ERC721AConduitPreapprovedUpgradeable is ERC721AUpgradeable { | ||
/// @dev The canonical OpenSea conduit. | ||
address internal constant _CONDUIT = 0x1E0049783F008A0085193E00003D00cd54003c71; | ||
|
||
/** | ||
* @notice Deploy the token contract with its name and symbol. | ||
*/ | ||
function __ERC721AConduitPreapprovedUpgradeable_init_unchained( | ||
string memory name, string memory symbol | ||
) internal onlyInitializing { | ||
__ERC721A_init_unchained(name, symbol); | ||
} | ||
|
||
/** | ||
* @dev Returns if the `operator` is allowed to manage all of the | ||
* assets of `owner`. Always returns true for the conduit. | ||
*/ | ||
function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) { | ||
if (operator == _CONDUIT) { | ||
return true; | ||
} | ||
return ERC721A.isApprovedForAll(owner, operator); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src-upgradeable/src/lib/ERC721TransferValidatorUpgradeable.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,35 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.17; | ||
|
||
import {ERC721ContractMetadataStorage} from "../ERC721ContractMetadataStorage.sol"; | ||
|
||
/** | ||
* @title ERC721TransferValidatorUpgradeable | ||
* @notice Functionality to use a transfer validator. | ||
*/ | ||
contract ERC721TransferValidatorUpgradeable { | ||
using ERC721ContractMetadataStorage for ERC721ContractMetadataStorage.Layout; | ||
|
||
/// @notice Emit an event when the transfer validator is updated. | ||
event TransferValidatorUpdated(address oldValidator, address newValidator); | ||
|
||
/// @notice Revert with an error if the transfer validator is being set to the same address. | ||
error SameTransferValidator(); | ||
|
||
/// @notice Returns the currently active transfer validator. | ||
/// The null address means no transfer validator is set. | ||
function getTransferValidator() external view returns (address) { | ||
return ERC721ContractMetadataStorage.layout()._transferValidator; | ||
} | ||
|
||
/// @notice Set the transfer validator. | ||
/// The external method that uses this must include access control. | ||
function _setTransferValidator(address newValidator) internal { | ||
address oldValidator = ERC721ContractMetadataStorage.layout()._transferValidator; | ||
if (oldValidator == newValidator) { | ||
revert SameTransferValidator(); | ||
} | ||
ERC721ContractMetadataStorage.layout()._transferValidator = newValidator; | ||
emit TransferValidatorUpdated(oldValidator, newValidator); | ||
} | ||
} |
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
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,31 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.17; | ||
|
||
import { ERC721ACloneable } from "./ERC721ACloneable.sol"; | ||
|
||
/** | ||
* @title ERC721AConduitPreapprovedCloneable | ||
* @notice ERC721A with the OpenSea conduit preapproved. | ||
*/ | ||
abstract contract ERC721AConduitPreapprovedCloneable is ERC721ACloneable { | ||
/// @dev The canonical OpenSea conduit. | ||
address internal constant _CONDUIT = | ||
0x1E0049783F008A0085193E00003D00cd54003c71; | ||
|
||
/** | ||
* @dev Returns if the `operator` is allowed to manage all of the | ||
* assets of `owner`. Always returns true for the conduit. | ||
*/ | ||
function isApprovedForAll(address owner, address operator) | ||
public | ||
view | ||
virtual | ||
override | ||
returns (bool) | ||
{ | ||
if (operator == _CONDUIT) { | ||
return true; | ||
} | ||
return ERC721ACloneable.isApprovedForAll(owner, operator); | ||
} | ||
} |
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
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,22 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.17; | ||
|
||
interface ITransferValidator { | ||
/// @notice Ensure that a transfer has been authorized for a specific tokenId. | ||
function validateTransfer( | ||
address caller, | ||
address from, | ||
address to, | ||
uint256 tokenId | ||
) external view; | ||
|
||
/// @notice Ensure that a transfer has been authorized for a specific amount of | ||
// a specific tokenId, and reduce the transferable amount remaining. | ||
function validateTransfer( | ||
address caller, | ||
address from, | ||
address to, | ||
uint256 tokenId, | ||
uint256 amount | ||
) external; | ||
} |
Oops, something went wrong.