Skip to content

Commit

Permalink
use string location, even for address references (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
wwhchung authored May 28, 2024
1 parent 3afe2ea commit 8cd0585
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ contract ERC1155LazyPayableClaim is IERC165, IERC1155LazyPayableClaim, ICreatorE

// Sanity checks
if (claimParameters.storageProtocol == StorageProtocol.INVALID) revert ILazyPayableClaim.InvalidStorageProtocol();
if (claimParameters.storageProtocol == StorageProtocol.ADDRESS && claimParameters.location.length != 20) revert ILazyPayableClaim.InvalidStorageProtocol();
if (claimParameters.storageProtocol == StorageProtocol.ADDRESS && bytes(claimParameters.location).length != 20) revert ILazyPayableClaim.InvalidStorageProtocol();
if (claimParameters.endDate != 0 && claimParameters.startDate >= claimParameters.endDate) revert ILazyPayableClaim.InvalidStartDate();
require(claimParameters.merkleRoot == "" || claimParameters.walletMax == 0, "Cannot provide both walletMax and merkleRoot");

Expand Down Expand Up @@ -90,7 +90,7 @@ contract ERC1155LazyPayableClaim is IERC165, IERC1155LazyPayableClaim, ICreatorE
) external override creatorAdminRequired(creatorContractAddress) {
Claim memory claim = _getClaim(creatorContractAddress, instanceId);
if (claimParameters.storageProtocol == StorageProtocol.INVALID) revert ILazyPayableClaim.InvalidStorageProtocol();
if (claimParameters.storageProtocol == StorageProtocol.ADDRESS && claimParameters.location.length != 20) revert ILazyPayableClaim.InvalidStorageProtocol();
if (claimParameters.storageProtocol == StorageProtocol.ADDRESS && bytes(claimParameters.location).length != 20) revert ILazyPayableClaim.InvalidStorageProtocol();
if (claimParameters.endDate != 0 && claimParameters.startDate >= claimParameters.endDate) revert ILazyPayableClaim.InvalidStartDate();
if (claimParameters.erc20 != claim.erc20) revert ILazyPayableClaim.CannotChangePaymentToken();
if (claimParameters.totalMax != 0 && claim.total > claimParameters.totalMax) {
Expand Down Expand Up @@ -122,11 +122,11 @@ contract ERC1155LazyPayableClaim is IERC165, IERC1155LazyPayableClaim, ICreatorE
function updateTokenURIParams(
address creatorContractAddress, uint256 instanceId,
StorageProtocol storageProtocol,
bytes calldata location
string calldata location
) external override creatorAdminRequired(creatorContractAddress) {
Claim storage claim = _getClaim(creatorContractAddress, instanceId);
if (storageProtocol == StorageProtocol.INVALID) revert ILazyPayableClaim.InvalidStorageProtocol();
if (storageProtocol == StorageProtocol.ADDRESS && location.length != 20) revert ILazyPayableClaim.InvalidStorageProtocol();
if (storageProtocol == StorageProtocol.ADDRESS && bytes(location).length != 20) revert ILazyPayableClaim.InvalidStorageProtocol();

claim.storageProtocol = storageProtocol;
claim.location = location;
Expand All @@ -138,11 +138,11 @@ contract ERC1155LazyPayableClaim is IERC165, IERC1155LazyPayableClaim, ICreatorE
*/
function extendTokenURI(
address creatorContractAddress, uint256 instanceId,
bytes calldata locationChunk
string calldata locationChunk
) external override creatorAdminRequired(creatorContractAddress) {
Claim storage claim = _getClaim(creatorContractAddress, instanceId);
if (claim.storageProtocol != StorageProtocol.NONE) revert ILazyPayableClaim.InvalidStorageProtocol();
claim.location = abi.encodePacked(claim.location, locationChunk);
claim.location = string(abi.encodePacked(claim.location, locationChunk));
}

/**
Expand Down Expand Up @@ -345,7 +345,7 @@ contract ERC1155LazyPayableClaim is IERC165, IERC1155LazyPayableClaim, ICreatorE
Claim memory claim = _claims[creatorContractAddress][instanceId];

if (claim.storageProtocol == StorageProtocol.ADDRESS) {
return IERC1155LazyPayableClaimMetadata(_bytesToAddress(claim.location)).tokenURI(creatorContractAddress, tokenId, instanceId);
return IERC1155LazyPayableClaimMetadata(_bytesToAddress(bytes(claim.location))).tokenURI(creatorContractAddress, tokenId, instanceId);
}

string memory prefix = "";
Expand Down
14 changes: 7 additions & 7 deletions packages/manifold/contracts/lazyclaim/ERC721LazyPayableClaim.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ contract ERC721LazyPayableClaim is IERC165, IERC721LazyPayableClaim, ICreatorExt

// Sanity checks
if (claimParameters.storageProtocol == StorageProtocol.INVALID) revert ILazyPayableClaim.InvalidStorageProtocol();
if (claimParameters.storageProtocol == StorageProtocol.ADDRESS && claimParameters.location.length != 20) revert ILazyPayableClaim.InvalidStorageProtocol();
if (claimParameters.storageProtocol == StorageProtocol.ADDRESS && bytes(claimParameters.location).length != 20) revert ILazyPayableClaim.InvalidStorageProtocol();
if (claimParameters.endDate != 0 && claimParameters.startDate >= claimParameters.endDate) revert ILazyPayableClaim.InvalidStartDate();
require(claimParameters.merkleRoot == "" || claimParameters.walletMax == 0, "Cannot provide both walletMax and merkleRoot");

Expand Down Expand Up @@ -100,7 +100,7 @@ contract ERC721LazyPayableClaim is IERC165, IERC721LazyPayableClaim, ICreatorExt
// Sanity checks
Claim memory claim = _getClaim(creatorContractAddress, instanceId);
if (claimParameters.storageProtocol == StorageProtocol.INVALID) revert ILazyPayableClaim.InvalidStorageProtocol();
if (claimParameters.storageProtocol == StorageProtocol.ADDRESS && claimParameters.location.length != 20) revert ILazyPayableClaim.InvalidStorageProtocol();
if (claimParameters.storageProtocol == StorageProtocol.ADDRESS && bytes(claimParameters.location).length != 20) revert ILazyPayableClaim.InvalidStorageProtocol();
if (claimParameters.endDate != 0 && claimParameters.startDate >= claimParameters.endDate) revert ILazyPayableClaim.InvalidStartDate();
if (claimParameters.erc20 != claim.erc20) revert ILazyPayableClaim.CannotChangePaymentToken();
if (claimParameters.totalMax != 0 && claim.total > claimParameters.totalMax) {
Expand Down Expand Up @@ -134,11 +134,11 @@ contract ERC721LazyPayableClaim is IERC165, IERC721LazyPayableClaim, ICreatorExt
address creatorContractAddress, uint256 instanceId,
StorageProtocol storageProtocol,
bool identical,
bytes calldata location
string calldata location
) external override creatorAdminRequired(creatorContractAddress) {
Claim storage claim = _getClaim(creatorContractAddress, instanceId);
if (storageProtocol == StorageProtocol.INVALID) revert ILazyPayableClaim.InvalidStorageProtocol();
if (storageProtocol == StorageProtocol.ADDRESS && location.length != 20) revert ILazyPayableClaim.InvalidStorageProtocol();
if (storageProtocol == StorageProtocol.ADDRESS && bytes(location).length != 20) revert ILazyPayableClaim.InvalidStorageProtocol();

claim.storageProtocol = storageProtocol;
claim.location = location;
Expand All @@ -151,11 +151,11 @@ contract ERC721LazyPayableClaim is IERC165, IERC721LazyPayableClaim, ICreatorExt
*/
function extendTokenURI(
address creatorContractAddress, uint256 instanceId,
bytes calldata locationChunk
string calldata locationChunk
) external override creatorAdminRequired(creatorContractAddress) {
Claim storage claim = _getClaim(creatorContractAddress, instanceId);
if (claim.storageProtocol != StorageProtocol.NONE || !claim.identical) revert ILazyPayableClaim.InvalidStorageProtocol();
claim.location = abi.encodePacked(claim.location, locationChunk);
claim.location = string(abi.encodePacked(claim.location, locationChunk));
emit ClaimUpdated(creatorContractAddress, instanceId);
}

Expand Down Expand Up @@ -403,7 +403,7 @@ contract ERC721LazyPayableClaim is IERC165, IERC721LazyPayableClaim, ICreatorExt
}

if (claim.storageProtocol == StorageProtocol.ADDRESS) {
return IERC721LazyPayableClaimMetadata(_bytesToAddress(claim.location)).tokenURI(creatorContractAddress, tokenId, instanceId, mintOrder);
return IERC721LazyPayableClaimMetadata(_bytesToAddress(bytes(claim.location))).tokenURI(creatorContractAddress, tokenId, instanceId, mintOrder);
}

string memory prefix = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface IERC1155LazyPayableClaim is ILazyPayableClaim {
uint48 endDate;
StorageProtocol storageProtocol;
bytes32 merkleRoot;
bytes location;
string location;
uint256 cost;
address payable paymentReceiver;
address erc20;
Expand All @@ -33,7 +33,7 @@ interface IERC1155LazyPayableClaim is ILazyPayableClaim {
uint48 endDate;
StorageProtocol storageProtocol;
bytes32 merkleRoot;
bytes location;
string location;
uint256 tokenId;
uint256 cost;
address payable paymentReceiver;
Expand Down Expand Up @@ -64,15 +64,15 @@ interface IERC1155LazyPayableClaim is ILazyPayableClaim {
* @param storageProtocol the new storage protocol
* @param location the new location
*/
function updateTokenURIParams(address creatorContractAddress, uint256 instanceId, StorageProtocol storageProtocol, bytes calldata location) external;
function updateTokenURIParams(address creatorContractAddress, uint256 instanceId, StorageProtocol storageProtocol, string calldata location) external;

/**
* @notice extend tokenURI parameters for an existing claim at instanceId. Must have NONE StorageProtocol
* @param creatorContractAddress the creator contract corresponding to the claim
* @param instanceId the claim instanceId for the creator contract
* @param locationChunk the additional location chunk
*/
function extendTokenURI(address creatorContractAddress, uint256 instanceId, bytes calldata locationChunk) external;
function extendTokenURI(address creatorContractAddress, uint256 instanceId, string calldata locationChunk) external;

/**
* @notice get a claim corresponding to a creator contract and instanceId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface IERC721LazyPayableClaim is ILazyPayableClaim {
StorageProtocol storageProtocol;
bool identical;
bytes32 merkleRoot;
bytes location;
string location;
uint256 cost;
address payable paymentReceiver;
address erc20;
Expand All @@ -35,7 +35,7 @@ interface IERC721LazyPayableClaim is ILazyPayableClaim {
uint8 contractVersion;
bool identical;
bytes32 merkleRoot;
bytes location;
string location;
uint256 cost;
address payable paymentReceiver;
address erc20;
Expand Down Expand Up @@ -66,15 +66,15 @@ interface IERC721LazyPayableClaim is ILazyPayableClaim {
* @param identical the new value of identical
* @param location the new location
*/
function updateTokenURIParams(address creatorContractAddress, uint256 instanceId, StorageProtocol storageProtocol, bool identical, bytes calldata location) external;
function updateTokenURIParams(address creatorContractAddress, uint256 instanceId, StorageProtocol storageProtocol, bool identical, string calldata location) external;

/**
* @notice extend tokenURI parameters for an existing claim at instanceId. Must have NONE StorageProtocol
* @param creatorContractAddress the creator contract corresponding to the claim
* @param instanceId the claim instanceId for the creator contract
* @param locationChunk the additional location chunk
*/
function extendTokenURI(address creatorContractAddress, uint256 instanceId, bytes calldata locationChunk) external;
function extendTokenURI(address creatorContractAddress, uint256 instanceId, string calldata locationChunk) external;

/**
* @notice get a claim corresponding to a creator contract and instanceId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ contract ERC1155LazyPayableClaimTest is Test {

IERC1155LazyPayableClaim.ClaimParameters memory claimP = IERC1155LazyPayableClaim.ClaimParameters({
merkleRoot: "",
location: abi.encodePacked(address(metadata)),
location: string(abi.encodePacked(address(metadata))),
totalMax: 11,
walletMax: 3,
startDate: nowC,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ contract ERC721LazyPayableClaimTest is Test {

IERC721LazyPayableClaim.ClaimParameters memory claimP = IERC721LazyPayableClaim.ClaimParameters({
merkleRoot: "",
location: abi.encodePacked(address(metadata)),
location: string(abi.encodePacked(address(metadata))),
totalMax: 11,
walletMax: 3,
startDate: nowC,
Expand Down

0 comments on commit 8cd0585

Please sign in to comment.