Skip to content

Commit

Permalink
feat(nfts): non-transferable snaefell nfts (#17373)
Browse files Browse the repository at this point in the history
  • Loading branch information
bearni95 authored May 27, 2024
1 parent 1867d39 commit cde9683
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
22 changes: 21 additions & 1 deletion packages/nfts/contracts/snaefell/SnaefellToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ pragma solidity 0.8.24;

import { ERC721EnumerableUpgradeable } from
"@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721EnumerableUpgradeable.sol";

import { MerkleWhitelist } from "./MerkleWhitelist.sol";

/// @title TaikoonToken
Expand All @@ -21,6 +20,7 @@ contract SnaefellToken is ERC721EnumerableUpgradeable, MerkleWhitelist {
error MAX_SUPPLY_REACHED();
error MINTER_NOT_WHITELISTED();
error TOKEN_NOT_MINTED();
error TOKEN_CANNOT_BE_TRANSFERRED();

/// @notice Contract initializer
/// @param _rootURI Base URI for the token metadata
Expand Down Expand Up @@ -100,4 +100,24 @@ contract SnaefellToken is ERC721EnumerableUpgradeable, MerkleWhitelist {
_mint(_to, tokenIds[i]);
}
}

/// @notice Allow minting, and block all other token transfers
/// @param to The address to transfer to
/// @param tokenId The token id to transfer
/// @param auth The authorizer of the transfer
function _update(
address to,
uint256 tokenId,
address auth
)
internal
virtual
override
returns (address)
{
if (_ownerOf(tokenId) != address(0)) {
revert TOKEN_CANNOT_BE_TRANSFERRED();
}
return super._update(to, tokenId, auth);
}
}
9 changes: 9 additions & 0 deletions packages/nfts/test/snaefell/SnaefellToken.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,13 @@ contract SnaefellTokenTest is Test {
assertEq(token.balanceOf(owner), 5);
assertEq(tokenIds.length, 5);
}

function test_revert_tokenCannotBeTransferred() public {
vm.startBroadcast(owner);
uint256[] memory tokenIds = token.mint(owner, 5);

vm.expectRevert();
token.transferFrom(owner, minters[0], tokenIds[0]);
vm.stopBroadcast();
}
}

0 comments on commit cde9683

Please sign in to comment.