Skip to content

Commit cd148f2

Browse files
authored
add deprecate func (#94)
1 parent ce68766 commit cd148f2

File tree

4 files changed

+60
-2
lines changed

4 files changed

+60
-2
lines changed

packages/manifold/contracts/gachaclaims/ERC1155GachaLazyClaim.sol

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ contract ERC1155GachaLazyClaim is IERC165, IERC1155GachaLazyClaim, ICreatorExten
4747
uint256 instanceId,
4848
ClaimParameters calldata claimParameters
4949
) external payable override creatorAdminRequired(creatorContractAddress) {
50+
if (deprecated) {
51+
revert ContractDeprecated();
52+
}
5053
if (instanceId == 0 || instanceId > MAX_UINT_56) revert IGachaLazyClaim.InvalidInstance();
5154
if (_claims[creatorContractAddress][instanceId].storageProtocol != StorageProtocol.INVALID)
5255
revert IGachaLazyClaim.ClaimAlreadyInitialized();
@@ -98,6 +101,9 @@ contract ERC1155GachaLazyClaim is IERC165, IERC1155GachaLazyClaim, ICreatorExten
98101
uint256 instanceId,
99102
UpdateClaimParameters memory updateClaimParameters
100103
) external override creatorAdminRequired(creatorContractAddress) {
104+
if (deprecated) {
105+
revert ContractDeprecated();
106+
}
101107
Claim memory claim = _getClaim(creatorContractAddress, instanceId);
102108
if (instanceId == 0 || instanceId > MAX_UINT_56) revert IGachaLazyClaim.InvalidInstance();
103109
if (updateClaimParameters.endDate != 0 && updateClaimParameters.startDate >= updateClaimParameters.endDate)
@@ -107,7 +113,6 @@ contract ERC1155GachaLazyClaim is IERC165, IERC1155GachaLazyClaim, ICreatorExten
107113
if (updateClaimParameters.storageProtocol == StorageProtocol.INVALID) revert IGachaLazyClaim.InvalidStorageProtocol();
108114
if (updateClaimParameters.cost > MAX_UINT_96) revert IGachaLazyClaim.InvalidInput();
109115

110-
111116
// Overwrite the existing values
112117
_claims[creatorContractAddress][instanceId] = Claim({
113118
storageProtocol: updateClaimParameters.storageProtocol,
@@ -156,7 +161,8 @@ contract ERC1155GachaLazyClaim is IERC165, IERC1155GachaLazyClaim, ICreatorExten
156161
Claim storage claim = _getClaim(creatorContractAddress, instanceId);
157162
// Checks for reserving
158163
if (mintCount == 0 || mintCount >= MAX_UINT_32) revert IGachaLazyClaim.InvalidMintCount();
159-
if (claim.startDate > block.timestamp || (claim.endDate > 0 && claim.endDate < block.timestamp)) revert IGachaLazyClaim.ClaimInactive();
164+
if (claim.startDate > block.timestamp || (claim.endDate > 0 && claim.endDate < block.timestamp))
165+
revert IGachaLazyClaim.ClaimInactive();
160166
if (claim.totalMax != 0 && claim.total == claim.totalMax) revert IGachaLazyClaim.ClaimSoldOut();
161167
if (claim.total == MAX_UINT_32) revert IGachaLazyClaim.TooManyRequested();
162168
if (msg.value != (claim.cost + MINT_FEE) * mintCount) revert IGachaLazyClaim.InvalidPayment();

packages/manifold/contracts/gachaclaims/GachaLazyClaim.sol

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ abstract contract GachaLazyClaim is IGachaLazyClaim, AdminControl {
2727

2828
uint256 public constant MINT_FEE = 500000000000000;
2929

30+
bool public deprecated;
31+
3032
// { contractAddress => { instanceId => { walletAddress => UserMintDetails } } }
3133
mapping(address => mapping(uint256 => mapping(address => UserMintDetails))) internal _mintDetailsPerWallet;
3234

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

50+
/**
51+
* Admin function to deprecate the contract
52+
*/
53+
function deprecate(bool _deprecated) external adminRequired {
54+
deprecated = _deprecated;
55+
}
56+
4857
/**
4958
* See {IGachaLazyClaim-withdraw}.
5059
*/

packages/manifold/contracts/gachaclaims/IGachaLazyClaim.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ interface IGachaLazyClaim {
2828
error ClaimNotInitialized();
2929
error ClaimInactive();
3030
error ClaimSoldOut();
31+
error ContractDeprecated();
3132
error TokenDNE();
3233
error FailedToTransfer();
3334
error TooManyRequested();

packages/manifold/test/gacha/ERC1155GachaLazyClaim.t.sol

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,30 @@ contract ERC1155GachaLazyClaimTest is Test {
125125
claimP.endDate = 0;
126126
example.initializeClaim(address(creatorCore1), 1, claimP);
127127
vm.stopPrank();
128+
129+
vm.startPrank(owner);
130+
example.deprecate(true);
131+
vm.stopPrank();
132+
133+
vm.startPrank(creator);
134+
// can't initialize if deprecated
135+
vm.expectRevert(IGachaLazyClaim.ContractDeprecated.selector);
136+
example.initializeClaim(address(creatorCore1), 2, claimP);
137+
vm.stopPrank();
138+
139+
vm.startPrank(owner);
140+
example.deprecate(false);
141+
vm.stopPrank();
142+
143+
vm.startPrank(creator);
144+
example.initializeClaim(address(creatorCore1), 2, claimP);
145+
vm.stopPrank();
146+
147+
// Cannot deprecate if not an admin
148+
vm.startPrank(other);
149+
vm.expectRevert(bytes("AdminControl: Must be owner or admin"));
150+
example.deprecate(true);
151+
vm.stopPrank();
128152
}
129153

130154
function testUpdateClaimSanitization() public {
@@ -205,7 +229,25 @@ contract ERC1155GachaLazyClaimTest is Test {
205229
claim = example.getClaim(address(creatorCore1), 1);
206230
assertEq(claim.startDate, nowC);
207231
assertEq(claim.endDate, 0);
232+
vm.stopPrank();
233+
234+
vm.startPrank(owner);
235+
example.deprecate(true);
236+
vm.stopPrank();
208237

238+
// can't update if deprecated
239+
vm.startPrank(creator);
240+
claimU.startDate = nowC + 2000;
241+
vm.expectRevert(IGachaLazyClaim.ContractDeprecated.selector);
242+
example.updateClaim(address(creatorCore1), 1, claimU);
243+
vm.stopPrank();
244+
245+
vm.startPrank(owner);
246+
example.deprecate(false);
247+
vm.stopPrank();
248+
249+
vm.startPrank(creator);
250+
example.updateClaim(address(creatorCore1), 1, claimU);
209251
vm.stopPrank();
210252
}
211253

0 commit comments

Comments
 (0)