-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: apply small changes after the audit
- Add a few interfaces related to quad operations and metadata registry to suppportInteface - Make UNKNOWN_NEIGHBORHOOD constant private in the land contract so it is not exposed in the abi. - This PR include some minor changes that we are fixing in advance as a result of some comments from the auditors. If needed they will be split in separated PRs before merging this one.
- Loading branch information
Andres Adjimann
committed
Jun 27, 2024
1 parent
3911872
commit 4d9654b
Showing
7 changed files
with
78 additions
and
43 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 |
---|---|---|
|
@@ -2,36 +2,13 @@ | |
|
||
pragma solidity ^0.8.0; | ||
|
||
import {IQuad} from "./IQuad.sol"; | ||
|
||
/// @title ILandToken | ||
/// @author The Sandbox | ||
/// @custom:security-contact [email protected] | ||
/// @notice Interface of the LAND token including quad methods | ||
interface ILandToken { | ||
/// @notice transfer multiple quad (aligned to a quad tree with size 3, 6, 12 or 24 only) | ||
/// @param from current owner of the quad | ||
/// @param to destination | ||
/// @param sizes list of sizes for each quad | ||
/// @param xs list of bottom left x coordinates for each quad | ||
/// @param ys list of bottom left y coordinates for each quad | ||
/// @param data additional data | ||
function batchTransferQuad( | ||
address from, | ||
address to, | ||
uint256[] calldata sizes, | ||
uint256[] calldata xs, | ||
uint256[] calldata ys, | ||
bytes calldata data | ||
) external; | ||
|
||
/// @notice transfer one quad (aligned to a quad tree with size 3, 6, 12 or 24 only) | ||
/// @param from current owner of the quad | ||
/// @param to destination | ||
/// @param size size of the quad | ||
/// @param x The bottom left x coordinate of the quad | ||
/// @param y The bottom left y coordinate of the quad | ||
/// @param data additional data | ||
function transferQuad(address from, address to, uint256 size, uint256 x, uint256 y, bytes calldata data) external; | ||
|
||
interface ILandToken is IQuad { | ||
/// @notice Mint a new quad (aligned to a quad tree with size 1, 3, 6, 12 or 24 only) | ||
/// @param to The recipient of the new quad | ||
/// @param size The size of the new quad | ||
|
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.0; | ||
|
||
/// @title IQuad | ||
/// @author The Sandbox | ||
/// @custom:security-contact [email protected] | ||
/// @notice Interface of the LAND token (quad methods) | ||
interface IQuad { | ||
/// @notice transfer multiple quad (aligned to a quad tree with size 3, 6, 12 or 24 only) | ||
/// @param from current owner of the quad | ||
/// @param to destination | ||
/// @param sizes list of sizes for each quad | ||
/// @param xs list of bottom left x coordinates for each quad | ||
/// @param ys list of bottom left y coordinates for each quad | ||
/// @param data additional data | ||
function batchTransferQuad( | ||
address from, | ||
address to, | ||
uint256[] calldata sizes, | ||
uint256[] calldata xs, | ||
uint256[] calldata ys, | ||
bytes calldata data | ||
) external; | ||
|
||
/// @notice transfer one quad (aligned to a quad tree with size 3, 6, 12 or 24 only) | ||
/// @param from current owner of the quad | ||
/// @param to destination | ||
/// @param size size of the quad | ||
/// @param x The bottom left x coordinate of the quad | ||
/// @param y The bottom left y coordinate of the quad | ||
/// @param data additional data | ||
function transferQuad(address from, address to, uint256 size, uint256 x, uint256 y, bytes calldata data) 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,11 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.23; | ||
|
||
import {AccessControlEnumerableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/extensions/AccessControlEnumerableUpgradeable.sol"; | ||
|
||
/// @title LandMetadataRegistry | ||
/// @author The Sandbox | ||
/// @custom:security-contact [email protected] | ||
/// @notice Store information about the lands (premiumness and neighborhood) | ||
abstract contract LandMetadataBase is AccessControlEnumerableUpgradeable { | ||
abstract contract LandMetadataBase { | ||
/// @notice the base token id used for a batch operation is wrong | ||
/// @param tokenId the id of the token | ||
error InvalidBaseTokenId(uint256 tokenId); | ||
|
@@ -30,7 +28,7 @@ abstract contract LandMetadataBase is AccessControlEnumerableUpgradeable { | |
uint256 public constant NEIGHBORHOOD_MASK = PREMIUM_MASK - 1; | ||
|
||
struct LandMetadataStorage { | ||
/// @dev tokenId / 32 => premiumness + neighborhood metadata | ||
/// @dev tokenId / LANDS_PER_WORD => premiumness + neighborhood metadata | ||
/// @dev zero means no metadata definition | ||
mapping(uint256 tokenId => uint256 metadataType) _metadata; | ||
/// @dev neighborhood number to string mapping | ||
|
@@ -61,7 +59,7 @@ abstract contract LandMetadataBase is AccessControlEnumerableUpgradeable { | |
} | ||
|
||
/// @notice get the packed metadata for a single land | ||
/// @param tokenId the base token id floor 32 | ||
/// @param tokenId the base token id floor LANDS_PER_WORD | ||
/// @return neighborhoodId the number that identifies the neighborhood | ||
/// @return premium true if is premium | ||
function _getMetadataForTokenId(uint256 tokenId) internal view returns (uint256 neighborhoodId, bool premium) { | ||
|
@@ -71,16 +69,16 @@ abstract contract LandMetadataBase is AccessControlEnumerableUpgradeable { | |
premium = (metadata & PREMIUM_MASK) != 0; | ||
} | ||
|
||
/// @notice set the packed metadata for 32 lands at once | ||
/// @param tokenId the base token id floor 32 | ||
/// @param metadata the packed metadata for 32 lands | ||
/// @notice set the packed metadata for LANDS_PER_WORD lands at once | ||
/// @param tokenId the base token id floor LANDS_PER_WORD | ||
/// @param metadata the packed metadata for LANDS_PER_WORD lands | ||
function _setMetadata(uint256 tokenId, uint256 metadata) internal { | ||
LandMetadataStorage storage $ = _getLandMetadataStorage(); | ||
$._metadata[_getKey(tokenId)] = metadata; | ||
} | ||
|
||
/// @notice return the packed metadata for 32 lands at once | ||
/// @param tokenId the base token id floor 32 | ||
/// @notice return the packed metadata for LANDS_PER_WORD lands at once | ||
/// @param tokenId the base token id floor LANDS_PER_WORD | ||
function _getMetadata(uint256 tokenId) internal view returns (uint256) { | ||
LandMetadataStorage storage $ = _getLandMetadataStorage(); | ||
return $._metadata[_getKey(tokenId)]; | ||
|
@@ -110,7 +108,7 @@ abstract contract LandMetadataBase is AccessControlEnumerableUpgradeable { | |
return (tokenId % LANDS_PER_WORD) * BITS_PER_LAND; | ||
} | ||
|
||
/// @notice return the tokenId floor 32 | ||
/// @notice return the tokenId floor LANDS_PER_WORD | ||
/// @param tokenId the token id | ||
function _getKey(uint256 tokenId) internal pure returns (uint256) { | ||
return LANDS_PER_WORD * (tokenId / LANDS_PER_WORD); | ||
|
@@ -123,7 +121,7 @@ abstract contract LandMetadataBase is AccessControlEnumerableUpgradeable { | |
if (neighborhoodId == 0) { | ||
revert InvalidNeighborhoodId(neighborhoodId); | ||
} | ||
// NEIGHBORHOOD_MASK (32767) is left out to use as escape char if needed. | ||
// the last id: NEIGHBORHOOD_MASK is left out to use as escape char if needed in the future. | ||
if (neighborhoodId >= NEIGHBORHOOD_MASK) { | ||
revert InvalidNeighborhoodId(neighborhoodId); | ||
} | ||
|
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
4d9654b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverage for this commit
Coverage Report