Skip to content

Commit

Permalink
Soullbound tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
ScreamingHawk committed Sep 11, 2024
1 parent 8fbefab commit 7b7cddd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
4 changes: 4 additions & 0 deletions scripts/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ export const DEPLOYABLE_CONTRACT_NAMES = [
'ERC20ItemsFactory',
'ERC721ItemsFactory',
'ERC721SaleFactory',
'ERC721SoulboundFactory',
'ERC1155ItemsFactory',
'ERC1155SaleFactory',
'ERC1155SoulboundFactory',
'PaymentCombiner',
'Clawback',
'ClawbackMetadata',
Expand All @@ -13,6 +15,8 @@ export const TOKEN_CONTRACT_NAMES = [
'ERC20Items',
'ERC721Items',
'ERC721Sale',
'ERC721Soulbound',
'ERC1155Items',
'ERC1155Sale',
'ERC1155Soulbound',
]
25 changes: 16 additions & 9 deletions src/tokens/ERC721/presets/soulbound/ERC721Soulbound.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
pragma solidity ^0.8.19;

import {ERC721Items} from "@0xsequence/contracts-library/tokens/ERC721/presets/items/ERC721Items.sol";
import {IERC721Soulbound, IERC721SoulboundFunctions} from "@0xsequence/contracts-library/tokens/ERC721/presets/soulbound/IERC721Soulbound.sol";
import {
IERC721Soulbound,
IERC721SoulboundFunctions
} from "@0xsequence/contracts-library/tokens/ERC721/presets/soulbound/IERC721Soulbound.sol";

/**
* An implementation of ERC-721 that prevents transfers.
*/
contract ERC721Soulbound is ERC721Items, IERC721Soulbound {

bytes32 public constant TRANSFER_ADMIN_ROLE = keccak256("TRANSFER_ADMIN_ROLE");

bool internal _transferLocked;
Expand All @@ -27,7 +29,9 @@ contract ERC721Soulbound is ERC721Items, IERC721Soulbound {
) public virtual override {
_transferLocked = true;
_grantRole(TRANSFER_ADMIN_ROLE, owner);
super.initialize(owner, tokenName, tokenSymbol, tokenBaseURI, tokenContractURI, royaltyReceiver, royaltyFeeNumerator);
super.initialize(
owner, tokenName, tokenSymbol, tokenBaseURI, tokenContractURI, royaltyReceiver, royaltyFeeNumerator
);
}

/// @inheritdoc IERC721SoulboundFunctions
Expand All @@ -40,16 +44,19 @@ contract ERC721Soulbound is ERC721Items, IERC721Soulbound {
return _transferLocked;
}

function _beforeTokenTransfers(
address from,
address to,
uint256 startTokenId,
uint256 quantity
) internal virtual override {
function _beforeTokenTransfers(address from, address to, uint256 startTokenId, uint256 quantity)
internal
virtual
override
{
// Mint transactions allowed
if (_transferLocked && from != address(0)) {
revert TransfersLocked();
}
super._beforeTokenTransfers(from, to, startTokenId, quantity);
}

function supportsInterface(bytes4 interfaceId) public view override returns (bool) {
return type(IERC721SoulboundFunctions).interfaceId == interfaceId || super.supportsInterface(interfaceId);
}
}
4 changes: 2 additions & 2 deletions test/tokens/ERC721/presets/ERC721Soulbound.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ contract ERC721SoulboundTest is TestHelper, IERC721ItemsSignals, IERC721Soulboun
token.transferFrom(holder, receiver, 0);
}

function testTransferUnLocked(address holder, address receiver) public {
function testTransferUnlocked(address holder, address receiver) public {
vm.assume(holder != receiver);
assumeSafeAddress(holder);
assumeSafeAddress(receiver);
Expand All @@ -199,7 +199,7 @@ contract ERC721SoulboundTest is TestHelper, IERC721ItemsSignals, IERC721Soulboun
vm.assertEq(token.ownerOf(0), receiver);
}

function testTransferUnLockedOperator(address holder, address operator, address receiver) public {
function testTransferUnlockedOperator(address holder, address operator, address receiver) public {
vm.assume(holder != receiver);
vm.assume(holder != operator);
assumeSafeAddress(holder);
Expand Down

0 comments on commit 7b7cddd

Please sign in to comment.