Skip to content

Commit

Permalink
SC-23 T.R.A.C.E. (#44)
Browse files Browse the repository at this point in the history
Finishing coding and test the TRACE creator contract
  • Loading branch information
mpeyfuss authored Jan 3, 2024
2 parents 2a3f144 + 320a432 commit 5b72f15
Show file tree
Hide file tree
Showing 16 changed files with 1,656 additions and 1,102 deletions.
68 changes: 50 additions & 18 deletions src/erc-1155/ERC1155TL.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.22;

import {
ERC1155Upgradeable,
IERC1155,
IERC165
} from "openzeppelin-upgradeable/token/ERC1155/ERC1155Upgradeable.sol";
import {Strings} from "openzeppelin/utils/Strings.sol";
import {ERC1155Upgradeable, IERC1155, IERC165} from "openzeppelin-upgradeable/token/ERC1155/ERC1155Upgradeable.sol";
import {EIP2981TLUpgradeable} from "tl-sol-tools/upgradeable/royalties/EIP2981TLUpgradeable.sol";
import {OwnableAccessControlUpgradeable} from "tl-sol-tools/upgradeable/access/OwnableAccessControlUpgradeable.sol";
import {IStory} from "src/interfaces/IStory.sol";
Expand All @@ -18,7 +15,21 @@ import {ITLNftDelegationRegistry} from "src/interfaces/ITLNftDelegationRegistry.
/// @notice Transient Labs ERC-1155 Creator Contract
/// @author transientlabs.xyz
/// @custom:version 3.0.0
contract ERC1155TL is ERC1155Upgradeable, EIP2981TLUpgradeable, OwnableAccessControlUpgradeable, ICreatorBase, IERC1155TL, IStory {
contract ERC1155TL is
ERC1155Upgradeable,
EIP2981TLUpgradeable,
OwnableAccessControlUpgradeable,
ICreatorBase,
IERC1155TL,
IStory
{
/*//////////////////////////////////////////////////////////////////////////
Custom Types
//////////////////////////////////////////////////////////////////////////*/

/// @dev String representation for address
using Strings for address;

/*//////////////////////////////////////////////////////////////////////////
State Variables
//////////////////////////////////////////////////////////////////////////*/
Expand All @@ -29,6 +40,9 @@ contract ERC1155TL is ERC1155Upgradeable, EIP2981TLUpgradeable, OwnableAccessCon
uint256 private _counter;
string public name;
string public symbol;
bool public storyEnabled;
ITLNftDelegationRegistry public tlNftDelegationRegistry;
IBlockListRegistry public blocklistRegistry;
mapping(uint256 => Token) private _tokens;

/*//////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -107,13 +121,12 @@ contract ERC1155TL is ERC1155Upgradeable, EIP2981TLUpgradeable, OwnableAccessCon
General Functions
//////////////////////////////////////////////////////////////////////////*/

/// @inheritdoc IERC1155TL
/// @inheritdoc ICreatorBase
function totalSupply() external view returns (uint256) {
return _counter;
}

/// @notice Function to get token creation details
/// @param tokenId The token to lookup
/// @inheritdoc IERC1155TL
function getTokenDetails(uint256 tokenId) external view returns (Token memory) {
return _tokens[tokenId];
}
Expand All @@ -122,7 +135,7 @@ contract ERC1155TL is ERC1155Upgradeable, EIP2981TLUpgradeable, OwnableAccessCon
Access Control Functions
//////////////////////////////////////////////////////////////////////////*/

/// @inheritdoc IERC1155TL
/// @inheritdoc ICreatorBase
function setApprovedMintContracts(address[] calldata minters, bool status) external onlyRoleOrOwner(ADMIN_ROLE) {
_setRole(APPROVED_MINT_CONTRACT, minters, status);
}
Expand Down Expand Up @@ -212,12 +225,12 @@ contract ERC1155TL is ERC1155Upgradeable, EIP2981TLUpgradeable, OwnableAccessCon
Royalty Functions
//////////////////////////////////////////////////////////////////////////*/

/// @inheritdoc IERC1155TL
/// @inheritdoc ICreatorBase
function setDefaultRoyalty(address newRecipient, uint256 newPercentage) external onlyOwner {
_setDefaultRoyaltyInfo(newRecipient, newPercentage);
}

/// @inheritdoc IERC1155TL
/// @inheritdoc ICreatorBase
function setTokenRoyalty(uint256 tokenId, address newRecipient, uint256 newPercentage) external onlyOwner {
_overrideTokenRoyaltyInfo(tokenId, newRecipient, newPercentage);
}
Expand All @@ -244,19 +257,37 @@ contract ERC1155TL is ERC1155Upgradeable, EIP2981TLUpgradeable, OwnableAccessCon
Story Inscriptions
//////////////////////////////////////////////////////////////////////////*/


/// @inheritdoc IStory
function addCollectionStory(string calldata creatorName, string calldata story)
external
onlyRoleOrOwner(ADMIN_ROLE)
{}

/*//////////////////////////////////////////////////////////////////////////
BlockList Functions
//////////////////////////////////////////////////////////////////////////*/
/// @inheritdoc IStory
function addCreatorStory(uint256 tokenId, string calldata creatorName, string calldata story)
external
onlyRoleOrOwner(ADMIN_ROLE)
{}

/// @inheritdoc IStory
function addStory(uint256 tokenId, string calldata collectorName, string calldata story) external {}

/// @inheritdoc ICreatorBase
function setStoryStatus(bool status) external {}

/*//////////////////////////////////////////////////////////////////////////
TL NFT Delegation Registry
BlockList
//////////////////////////////////////////////////////////////////////////*/

/// @inheritdoc ICreatorBase
function setBlockListRegistry(address newBlockListRegistry) external {}

/*//////////////////////////////////////////////////////////////////////////
NFT Delegation Registry
//////////////////////////////////////////////////////////////////////////*/

/// @inheritdoc ICreatorBase
function setNftDelegationRegistry(address newNftDelegationRegistry) external {}

/*//////////////////////////////////////////////////////////////////////////
ERC-165 Support
Expand All @@ -271,7 +302,8 @@ contract ERC1155TL is ERC1155Upgradeable, EIP2981TLUpgradeable, OwnableAccessCon
{
return (
ERC1155Upgradeable.supportsInterface(interfaceId) || EIP2981TLUpgradeable.supportsInterface(interfaceId)
|| interfaceId == type(IStory).interfaceId || interfaceId == 0x0d23ecb9 // previous story contract version that is still supported
|| interfaceId == type(ICreatorBase).interfaceId || interfaceId == type(IStory).interfaceId
|| interfaceId == 0x0d23ecb9 // previous story contract version that is still supported
|| interfaceId == type(IERC1155TL).interfaceId
);
}
Expand Down
6 changes: 6 additions & 0 deletions src/erc-1155/IERC1155TL.sol
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,10 @@ interface IERC1155TL {
/// @param tokenIds Array of tokens to burn
/// @param amounts Amount of each token to burn
function burn(address from, uint256[] calldata tokenIds, uint256[] calldata amounts) external;

/// @notice Function to set a token uri
/// @dev Requires owner or admin
/// @param tokenId The token to mint
/// @param newUri The new token uri
function setTokenUri(uint256 tokenId, string calldata newUri) external;
}
74 changes: 39 additions & 35 deletions src/erc-721/ERC721TL.sol
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.22;

import {IERC2309} from "openzeppelin/interfaces/IERC2309.sol";
import {IERC4906} from "openzeppelin/interfaces/IERC4906.sol";
import {Strings} from "openzeppelin/utils/Strings.sol";
import {
ERC721Upgradeable, IERC165
} from "openzeppelin-upgradeable/token/ERC721/ERC721Upgradeable.sol";
import {ERC721Upgradeable, IERC165} from "openzeppelin-upgradeable/token/ERC721/ERC721Upgradeable.sol";
import {OwnableAccessControlUpgradeable} from "tl-sol-tools/upgradeable/access/OwnableAccessControlUpgradeable.sol";
import {EIP2981TLUpgradeable} from "tl-sol-tools/upgradeable/royalties/EIP2981TLUpgradeable.sol";
import {IERC721TL} from "src/erc-721/IERC721TL.sol";
Expand All @@ -28,7 +25,6 @@ contract ERC721TL is
IERC721TL,
ISynergy,
IStory,
IERC2309,
IERC4906
{
/*//////////////////////////////////////////////////////////////////////////
Expand All @@ -46,6 +42,9 @@ contract ERC721TL is
/// @dev String representation of uint256
using Strings for uint256;

/// @dev String representation for address
using Strings for address;

/*//////////////////////////////////////////////////////////////////////////
State Variables
//////////////////////////////////////////////////////////////////////////*/
Expand Down Expand Up @@ -195,24 +194,6 @@ contract ERC721TL is
}
}

/// @inheritdoc IERC721TL
function batchMintUltra(address recipient, uint128 numTokens, string calldata baseUri)
external
onlyRoleOrOwner(ADMIN_ROLE)
{
if (recipient == address(0)) revert MintToZeroAddress();
if (bytes(baseUri).length == 0) revert EmptyTokenURI();
if (numTokens < 2) revert BatchSizeTooSmall();
uint256 start = _counter + 1;
uint256 end = start + numTokens - 1;
_counter += numTokens;
_batchMints.push(BatchMint(recipient, start, end, baseUri));

_increaseBalance(recipient, numTokens); // this function adds the number of tokens to the recipient address

emit ConsecutiveTransfer(start, end, address(0), recipient);
}

/// @inheritdoc IERC721TL
function airdrop(address[] calldata addresses, string calldata baseUri) external onlyRoleOrOwner(ADMIN_ROLE) {
if (bytes(baseUri).length == 0) revert EmptyTokenURI();
Expand Down Expand Up @@ -251,12 +232,12 @@ contract ERC721TL is
Royalty Functions
//////////////////////////////////////////////////////////////////////////*/

/// @inheritdoc IERC721TL
/// @inheritdoc ICreatorBase
function setDefaultRoyalty(address newRecipient, uint256 newPercentage) external onlyRoleOrOwner(ADMIN_ROLE) {
_setDefaultRoyaltyInfo(newRecipient, newPercentage);
}

/// @inheritdoc IERC721TL
/// @inheritdoc ICreatorBase
function setTokenRoyalty(uint256 tokenId, address newRecipient, uint256 newPercentage)
external
onlyRoleOrOwner(ADMIN_ROLE)
Expand All @@ -268,7 +249,7 @@ contract ERC721TL is
Synergy Functions
//////////////////////////////////////////////////////////////////////////*/

/// @inheritdoc IERC721TL
/// @inheritdoc ISynergy
function proposeNewTokenUri(uint256 tokenId, string calldata newUri) external onlyRoleOrOwner(ADMIN_ROLE) {
if (!_exists(tokenId)) revert TokenDoesntExist();
if (bytes(newUri).length == 0) revert EmptyTokenURI();
Expand All @@ -283,7 +264,7 @@ contract ERC721TL is
}
}

/// @inheritdoc IERC721TL
/// @inheritdoc ISynergy
function acceptTokenUriUpdate(uint256 tokenId) external {
if (ownerOf(tokenId) != msg.sender) revert CallerNotTokenOwner();
string memory uri = _proposedTokenUris[tokenId];
Expand All @@ -294,9 +275,7 @@ contract ERC721TL is
emit SynergyStatusChange(msg.sender, tokenId, SynergyAction.Accepted, uri);
}

/// @notice function to reject a proposed token uri update for a specific token
/// @dev requires owner of the token to call the function
/// @param tokenId the token to reject the metadata update for
/// @inheritdoc ISynergy
function rejectTokenUriUpdate(uint256 tokenId) external {
if (ownerOf(tokenId) != msg.sender) revert CallerNotTokenOwner();
string memory uri = _proposedTokenUris[tokenId];
Expand All @@ -323,14 +302,38 @@ contract ERC721TL is
Story Inscriptions
//////////////////////////////////////////////////////////////////////////*/

/// @inheritdoc IStory
function addCollectionStory(string calldata creatorName, string calldata story)
external
onlyRoleOrOwner(ADMIN_ROLE)
{}

/// @inheritdoc IStory
function addCreatorStory(uint256 tokenId, string calldata creatorName, string calldata story)
external
onlyRoleOrOwner(ADMIN_ROLE)
{}

/// @inheritdoc IStory
function addStory(uint256 tokenId, string calldata collectorName, string calldata story) external {}

/// @inheritdoc ICreatorBase
function setStoryStatus(bool status) external {}

/*//////////////////////////////////////////////////////////////////////////
BlockList
BlockList
//////////////////////////////////////////////////////////////////////////*/

/// @inheritdoc ICreatorBase
function setBlockListRegistry(address newBlockListRegistry) external {}

/*//////////////////////////////////////////////////////////////////////////
TL NFT Delegation Registry
NFT Delegation Registry
//////////////////////////////////////////////////////////////////////////*/

/// @inheritdoc ICreatorBase
function setNftDelegationRegistry(address newNftDelegationRegistry) external {}

/*//////////////////////////////////////////////////////////////////////////
ERC-165 Support
//////////////////////////////////////////////////////////////////////////*/
Expand All @@ -344,9 +347,10 @@ contract ERC721TL is
{
return (
ERC721Upgradeable.supportsInterface(interfaceId) || EIP2981TLUpgradeable.supportsInterface(interfaceId)
|| interfaceId == type(IERC2309).interfaceId
|| interfaceId == type(IERC4906).interfaceId
|| interfaceId == type(IStory).interfaceId || interfaceId == 0x0d23ecb9 // previous story contract version that is still supported
|| interfaceId == 0x49064906 // ERC-4906
|| interfaceId == type(ICreatorBase).interfaceId
|| interfaceId == type(ISynergy).interfaceId || interfaceId == type(IStory).interfaceId
|| interfaceId == 0x0d23ecb9 // previous story contract version that is still supported
|| interfaceId == type(IERC721TL).interfaceId
);
}
Expand Down
12 changes: 1 addition & 11 deletions src/erc-721/IERC721TL.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity 0.8.22;

/// @title IERC721TL.sol
/// @notice Interface for ERC721TL
/// @dev Interface id =
/// @dev Interface id = 0xc74089ae0
/// @author transientlabs.xyz
/// @custom:version 3.0.0
interface IERC721TL {
Expand Down Expand Up @@ -34,16 +34,6 @@ interface IERC721TL {
/// @param baseUri The base uri for the batch, expecting json to be in order, starting at file name 0, and SHOULD NOT have a trailing `/`
function batchMint(address recipient, uint128 numTokens, string calldata baseUri) external;

/// @notice Function to batch mint tokens with ultra gas savings using ERC-2309
/// @dev Requires owner or admin
/// @dev Usage of ERC-2309 MAY NOT be supported on all platforms
/// @dev The `baseUri` folder should have the same number of json files in it as `numTokens`
/// @dev The `baseUri` folder should have files named without any file extension
/// @param recipient The recipient of the token - assumed as able to receive 721 tokens
/// @param numTokens Number of tokens in the batch mint
/// @param baseUri The base uri for the batch, expecting json to be in order, starting at file name 0, and SHOULD NOT have a trailing `/`
function batchMintUltra(address recipient, uint128 numTokens, string calldata baseUri) external;

/// @notice Function to airdrop tokens to addresses
/// @dev Requires owner or admin
/// @dev Utilizes batch mint token uri values to save some gas but still ultimately mints individual tokens to people
Expand Down
Loading

0 comments on commit 5b72f15

Please sign in to comment.