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
9 changed files
with
403 additions
and
37 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
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,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; | ||
} |
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,34 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.17; | ||
|
||
/** | ||
* @title TokenTransferValidator | ||
* @notice Functionality to use a transfer validator. | ||
*/ | ||
contract TokenTransferValidator { | ||
/// @dev Store the transfer validator. The null address means no transfer validator is set. | ||
address internal _transferValidator; | ||
|
||
/// @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 _transferValidator; | ||
} | ||
|
||
/// @notice Set the transfer validator. | ||
/// The external method that uses this must include access control. | ||
function _setTransferValidator(address newValidator) internal { | ||
address oldValidator = _transferValidator; | ||
if (oldValidator == newValidator) { | ||
revert SameTransferValidator(); | ||
} | ||
_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// SPDX-License-Identifier: Unlicense | ||
pragma solidity ^0.8.17; | ||
|
||
import { ITransferValidator } from "../interfaces/ITransferValidator.sol"; | ||
|
||
contract MockTransferValidator is ITransferValidator { | ||
bool internal _revertOnValidate; | ||
|
||
constructor(bool revertOnValidate) { | ||
_revertOnValidate = revertOnValidate; | ||
} | ||
|
||
function validateTransfer( | ||
address, | ||
/* caller */ | ||
address, | ||
/* from */ | ||
address, | ||
/* to */ | ||
uint256 /* tokenId */ | ||
) external view { | ||
if (_revertOnValidate) { | ||
revert("MockTransferValidator: always reverts"); | ||
} | ||
} | ||
|
||
function validateTransfer( | ||
address, /* caller */ | ||
address, /* from */ | ||
address, /* to */ | ||
uint256, /* tokenId */ | ||
uint256 /* amount */ | ||
) external view { | ||
if (_revertOnValidate) { | ||
revert("MockTransferValidator: always reverts"); | ||
} | ||
} | ||
} |
Oops, something went wrong.