Skip to content

Commit

Permalink
Merge storage structs for upgradeable. (#209)
Browse files Browse the repository at this point in the history
  • Loading branch information
kingster-will authored Aug 26, 2024
1 parent 0c3949b commit 98af8c8
Showing 1 changed file with 2 additions and 18 deletions.
20 changes: 2 additions & 18 deletions contracts/LicenseToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,13 @@ contract LicenseToken is ILicenseToken, ERC721EnumerableUpgradeable, AccessManag
string imageUrl;
uint256 totalMintedTokens;
mapping(uint256 tokenId => LicenseTokenMetadata) licenseTokenMetadatas;
}

/// @dev Storage structure for the Licensor
/// @custom:storage-location erc7201:story-protocol.Licensor
struct LicensorStorage {
mapping(address licensorIpId => uint256 totalMintedTokens) licensorIpTotalTokens;
}

// keccak256(abi.encode(uint256(keccak256("story-protocol.LicenseToken")) - 1)) & ~bytes32(uint256(0xff));
bytes32 private constant LicenseTokenStorageLocation =
0x62a0d75e37bea0c3e666dc72a74112fc6af15ce635719127e380d8ca1e555d00;

// keccak256(abi.encode(uint256(keccak256("story-protocol.Licensor")) - 1)) & ~bytes32(uint256(0xff));
bytes32 private constant LicensorStorageLocation =
0x23f0add89533cdf440c8f5cc9ffed2d19de5118ad74363071b8d1ea4f92f9a00;

modifier onlyLicensingModule() {
if (msg.sender != address(LICENSING_MODULE)) {
revert Errors.LicenseToken__CallerNotLicensingModule();
Expand Down Expand Up @@ -109,7 +100,7 @@ contract LicenseToken is ILicenseToken, ERC721EnumerableUpgradeable, AccessManag
LicenseTokenStorage storage $ = _getLicenseTokenStorage();
startLicenseTokenId = $.totalMintedTokens;
$.totalMintedTokens += amount;
_getLicensorStorage().licensorIpTotalTokens[licensorIpId] += amount;
$.licensorIpTotalTokens[licensorIpId] += amount;
for (uint256 i = 0; i < amount; i++) {
uint256 tokenId = startLicenseTokenId + i;
$.licenseTokenMetadatas[tokenId] = ltm;
Expand Down Expand Up @@ -207,7 +198,7 @@ contract LicenseToken is ILicenseToken, ERC721EnumerableUpgradeable, AccessManag
/// @param licensorIpId The ID of the licensor IP.
/// @return The total number of License Tokens minted for the licensor IP.
function getTotalTokensByLicensor(address licensorIpId) external view returns (uint256) {
return _getLicensorStorage().licensorIpTotalTokens[licensorIpId];
return _getLicenseTokenStorage().licensorIpTotalTokens[licensorIpId];
}

/// @notice Returns true if the license has been revoked (licensor IP tagged after a dispute in
Expand Down Expand Up @@ -307,13 +298,6 @@ contract LicenseToken is ILicenseToken, ERC721EnumerableUpgradeable, AccessManag
}
}

/// @dev Returns the storage struct of Licensor.
function _getLicensorStorage() private pure returns (LicensorStorage storage $) {
assembly {
$.slot := LicensorStorageLocation
}
}

/// @dev Hook to authorize the upgrade according to UUPSUpgradeable
/// @param newImplementation The address of the new implementation
function _authorizeUpgrade(address newImplementation) internal override restricted {}
Expand Down

0 comments on commit 98af8c8

Please sign in to comment.