Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add deprecate func for gacha extension #94

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ contract ERC1155GachaLazyClaim is IERC165, IERC1155GachaLazyClaim, ICreatorExten
uint256 instanceId,
ClaimParameters calldata claimParameters
) external payable override creatorAdminRequired(creatorContractAddress) {
if (deprecated) {
revert ContractDeprecated();
}
if (instanceId == 0 || instanceId > MAX_UINT_56) revert IGachaLazyClaim.InvalidInstance();
if (_claims[creatorContractAddress][instanceId].storageProtocol != StorageProtocol.INVALID)
revert IGachaLazyClaim.ClaimAlreadyInitialized();
Expand Down Expand Up @@ -98,6 +101,9 @@ contract ERC1155GachaLazyClaim is IERC165, IERC1155GachaLazyClaim, ICreatorExten
uint256 instanceId,
UpdateClaimParameters memory updateClaimParameters
) external override creatorAdminRequired(creatorContractAddress) {
if (deprecated) {
revert ContractDeprecated();
}
Claim memory claim = _getClaim(creatorContractAddress, instanceId);
if (instanceId == 0 || instanceId > MAX_UINT_56) revert IGachaLazyClaim.InvalidInstance();
if (updateClaimParameters.endDate != 0 && updateClaimParameters.startDate >= updateClaimParameters.endDate)
Expand All @@ -107,7 +113,6 @@ contract ERC1155GachaLazyClaim is IERC165, IERC1155GachaLazyClaim, ICreatorExten
if (updateClaimParameters.storageProtocol == StorageProtocol.INVALID) revert IGachaLazyClaim.InvalidStorageProtocol();
if (updateClaimParameters.cost > MAX_UINT_96) revert IGachaLazyClaim.InvalidInput();


// Overwrite the existing values
_claims[creatorContractAddress][instanceId] = Claim({
storageProtocol: updateClaimParameters.storageProtocol,
Expand Down Expand Up @@ -156,7 +161,8 @@ contract ERC1155GachaLazyClaim is IERC165, IERC1155GachaLazyClaim, ICreatorExten
Claim storage claim = _getClaim(creatorContractAddress, instanceId);
// Checks for reserving
if (mintCount == 0 || mintCount >= MAX_UINT_32) revert IGachaLazyClaim.InvalidMintCount();
if (claim.startDate > block.timestamp || (claim.endDate > 0 && claim.endDate < block.timestamp)) revert IGachaLazyClaim.ClaimInactive();
if (claim.startDate > block.timestamp || (claim.endDate > 0 && claim.endDate < block.timestamp))
revert IGachaLazyClaim.ClaimInactive();
if (claim.totalMax != 0 && claim.total == claim.totalMax) revert IGachaLazyClaim.ClaimSoldOut();
if (claim.total == MAX_UINT_32) revert IGachaLazyClaim.TooManyRequested();
if (msg.value != (claim.cost + MINT_FEE) * mintCount) revert IGachaLazyClaim.InvalidPayment();
Expand Down
9 changes: 9 additions & 0 deletions packages/manifold/contracts/gachaclaims/GachaLazyClaim.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ abstract contract GachaLazyClaim is IGachaLazyClaim, AdminControl {

uint256 public constant MINT_FEE = 500000000000000;

bool public deprecated;

// { contractAddress => { instanceId => { walletAddress => UserMintDetails } } }
mapping(address => mapping(uint256 => mapping(address => UserMintDetails))) internal _mintDetailsPerWallet;

Expand All @@ -45,6 +47,13 @@ abstract contract GachaLazyClaim is IGachaLazyClaim, AdminControl {
_transferOwnership(initialOwner);
}

/**
* Admin function to deprecate the contract
*/
function deprecate(bool _deprecated) external adminRequired {
deprecated = _deprecated;
}
Comment on lines +53 to +55
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

o neat


/**
* See {IGachaLazyClaim-withdraw}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ interface IGachaLazyClaim {
error ClaimNotInitialized();
error ClaimInactive();
error ClaimSoldOut();
error ContractDeprecated();
error TokenDNE();
error FailedToTransfer();
error TooManyRequested();
Expand Down
42 changes: 42 additions & 0 deletions packages/manifold/test/gacha/ERC1155GachaLazyClaim.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,30 @@ contract ERC1155GachaLazyClaimTest is Test {
claimP.endDate = 0;
example.initializeClaim(address(creatorCore1), 1, claimP);
vm.stopPrank();

vm.startPrank(owner);
example.deprecate(true);
vm.stopPrank();

vm.startPrank(creator);
// can't initialize if deprecated
vm.expectRevert(IGachaLazyClaim.ContractDeprecated.selector);
example.initializeClaim(address(creatorCore1), 2, claimP);
vm.stopPrank();

vm.startPrank(owner);
example.deprecate(false);
vm.stopPrank();

vm.startPrank(creator);
example.initializeClaim(address(creatorCore1), 2, claimP);
vm.stopPrank();

// Cannot deprecate if not an admin
vm.startPrank(other);
vm.expectRevert(bytes("AdminControl: Must be owner or admin"));
example.deprecate(true);
vm.stopPrank();
}

function testUpdateClaimSanitization() public {
Expand Down Expand Up @@ -205,7 +229,25 @@ contract ERC1155GachaLazyClaimTest is Test {
claim = example.getClaim(address(creatorCore1), 1);
assertEq(claim.startDate, nowC);
assertEq(claim.endDate, 0);
vm.stopPrank();

vm.startPrank(owner);
example.deprecate(true);
vm.stopPrank();

// can't update if deprecated
vm.startPrank(creator);
claimU.startDate = nowC + 2000;
vm.expectRevert(IGachaLazyClaim.ContractDeprecated.selector);
example.updateClaim(address(creatorCore1), 1, claimU);
vm.stopPrank();

vm.startPrank(owner);
example.deprecate(false);
vm.stopPrank();

vm.startPrank(creator);
example.updateClaim(address(creatorCore1), 1, claimU);
vm.stopPrank();
}

Expand Down
Loading