Skip to content

Commit

Permalink
refactor: name as simply serendipity
Browse files Browse the repository at this point in the history
  • Loading branch information
jaxonL committed Jun 28, 2024
1 parent 7236cb2 commit 37bfc1f
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 184 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import "@openzeppelin/contracts/utils/Strings.sol";
import "@openzeppelin/contracts/utils/Address.sol";
import "@openzeppelin/contracts/utils/math/Math.sol";

import "./SerendipityLazyClaim.sol";
import "./IERC1155SerendipityLazyClaim.sol";
import "./Serendipity.sol";
import "./IERC1155Serendipity.sol";

/**
* @title Serendipity Lazy Payable Claim - ERC-1155
* @author manifold.xyz
* @notice
*/
contract ERC1155SerendipityLazyClaim is IERC165, IERC1155SerendipityLazyClaim, ICreatorExtensionTokenURI, SerendipityLazyClaim {
contract ERC1155Serendipity is IERC165, IERC1155Serendipity, ICreatorExtensionTokenURI, Serendipity {
using Strings for uint256;

// stores mapping from contractAddress/instanceId to the claim it represents
Expand All @@ -30,17 +30,17 @@ contract ERC1155SerendipityLazyClaim is IERC165, IERC1155SerendipityLazyClaim, I

function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, AdminControl) returns (bool) {
return
interfaceId == type(IERC1155SerendipityLazyClaim).interfaceId ||
interfaceId == type(ISerendipityLazyClaim).interfaceId ||
interfaceId == type(IERC1155Serendipity).interfaceId ||
interfaceId == type(ISerendipity).interfaceId ||
interfaceId == type(ICreatorExtensionTokenURI).interfaceId ||
interfaceId == type(IAdminControl).interfaceId ||
interfaceId == type(IERC165).interfaceId;
}

constructor(address initialOwner) SerendipityLazyClaim(initialOwner) {}
constructor(address initialOwner) Serendipity(initialOwner) {}

/**
* See {IERC1155SerendipityLazyClaim-initializeClaim}.
* See {IERC1155Serendipity-initializeClaim}.
*/
function initializeClaim(
address creatorContractAddress,
Expand All @@ -50,24 +50,24 @@ contract ERC1155SerendipityLazyClaim is IERC165, IERC1155SerendipityLazyClaim, I
if (deprecated) {
revert ContractDeprecated();
}
if (instanceId == 0 || instanceId > MAX_UINT_56) revert ISerendipityLazyClaim.InvalidInstance();
if (instanceId == 0 || instanceId > MAX_UINT_56) revert ISerendipity.InvalidInstance();
if (_claims[creatorContractAddress][instanceId].storageProtocol != StorageProtocol.INVALID)
revert ISerendipityLazyClaim.ClaimAlreadyInitialized();
revert ISerendipity.ClaimAlreadyInitialized();
// Checks
if (claimParameters.storageProtocol == StorageProtocol.INVALID) revert ISerendipityLazyClaim.InvalidStorageProtocol();
if (claimParameters.storageProtocol == StorageProtocol.INVALID) revert ISerendipity.InvalidStorageProtocol();
if (claimParameters.endDate != 0 && claimParameters.startDate >= claimParameters.endDate)
revert ISerendipityLazyClaim.InvalidDate();
if (claimParameters.totalMax > MAX_UINT_32) revert ISerendipityLazyClaim.InvalidInput();
if (claimParameters.tokenVariations > MAX_UINT_8) revert ISerendipityLazyClaim.InvalidInput();
if (claimParameters.cost > MAX_UINT_96) revert ISerendipityLazyClaim.InvalidInput();
revert ISerendipity.InvalidDate();
if (claimParameters.totalMax > MAX_UINT_32) revert ISerendipity.InvalidInput();
if (claimParameters.tokenVariations > MAX_UINT_8) revert ISerendipity.InvalidInput();
if (claimParameters.cost > MAX_UINT_96) revert ISerendipity.InvalidInput();

address[] memory receivers = new address[](1);
receivers[0] = msg.sender;
uint256[] memory amounts = new uint256[](claimParameters.tokenVariations);
string[] memory uris = new string[](claimParameters.tokenVariations);
uint256[] memory newTokenIds = IERC1155CreatorCore(creatorContractAddress).mintExtensionNew(receivers, amounts, uris);

if (newTokenIds[0] > MAX_UINT_80) revert ISerendipityLazyClaim.InvalidStartingTokenId();
if (newTokenIds[0] > MAX_UINT_80) revert ISerendipity.InvalidStartingTokenId();

// Create the claim
_claims[creatorContractAddress][instanceId] = Claim({
Expand All @@ -94,7 +94,7 @@ contract ERC1155SerendipityLazyClaim is IERC165, IERC1155SerendipityLazyClaim, I
}

/**
* See {IERC1155SerendipityLazyClaim-updateClaim}.
* See {IERC1155Serendipity-updateClaim}.
*/
function updateClaim(
address creatorContractAddress,
Expand All @@ -105,13 +105,13 @@ contract ERC1155SerendipityLazyClaim is IERC165, IERC1155SerendipityLazyClaim, I
revert ContractDeprecated();
}
Claim memory claim = _getClaim(creatorContractAddress, instanceId);
if (instanceId == 0 || instanceId > MAX_UINT_56) revert ISerendipityLazyClaim.InvalidInstance();
if (instanceId == 0 || instanceId > MAX_UINT_56) revert ISerendipity.InvalidInstance();
if (updateClaimParameters.endDate != 0 && updateClaimParameters.startDate >= updateClaimParameters.endDate)
revert ISerendipityLazyClaim.InvalidDate();
if (updateClaimParameters.totalMax != 0 && updateClaimParameters.totalMax < claim.total) revert ISerendipityLazyClaim.CannotLowerTotalMaxBeyondTotal();
if (updateClaimParameters.totalMax > MAX_UINT_32) revert ISerendipityLazyClaim.InvalidInput();
if (updateClaimParameters.storageProtocol == StorageProtocol.INVALID) revert ISerendipityLazyClaim.InvalidStorageProtocol();
if (updateClaimParameters.cost > MAX_UINT_96) revert ISerendipityLazyClaim.InvalidInput();
revert ISerendipity.InvalidDate();
if (updateClaimParameters.totalMax != 0 && updateClaimParameters.totalMax < claim.total) revert ISerendipity.CannotLowerTotalMaxBeyondTotal();
if (updateClaimParameters.totalMax > MAX_UINT_32) revert ISerendipity.InvalidInput();
if (updateClaimParameters.storageProtocol == StorageProtocol.INVALID) revert ISerendipity.InvalidStorageProtocol();
if (updateClaimParameters.cost > MAX_UINT_96) revert ISerendipity.InvalidInput();

// Overwrite the existing values
_claims[creatorContractAddress][instanceId] = Claim({
Expand All @@ -131,14 +131,14 @@ contract ERC1155SerendipityLazyClaim is IERC165, IERC1155SerendipityLazyClaim, I
}

/**
* See {IERC1155SerendipityLazyClaim-getClaim}.
* See {IERC1155Serendipity-getClaim}.
*/
function getClaim(address creatorContractAddress, uint256 instanceId) public view override returns (Claim memory) {
return _getClaim(creatorContractAddress, instanceId);
}

/**
* See {IERC1155SerendipityLazyClaim-getClaimForToken}.
* See {IERC1155Serendipity-getClaimForToken}.
*/
function getClaimForToken(
address creatorContractAddress,
Expand All @@ -150,22 +150,22 @@ contract ERC1155SerendipityLazyClaim is IERC165, IERC1155SerendipityLazyClaim, I

function _getClaim(address creatorContractAddress, uint256 instanceId) private view returns (Claim storage claim) {
claim = _claims[creatorContractAddress][instanceId];
if (claim.storageProtocol == StorageProtocol.INVALID) revert ISerendipityLazyClaim.ClaimNotInitialized();
if (claim.storageProtocol == StorageProtocol.INVALID) revert ISerendipity.ClaimNotInitialized();
}

/**
* See {ISerendipityLazyClaim-mintReserve}.
* See {ISerendipity-mintReserve}.
*/
function mintReserve(address creatorContractAddress, uint256 instanceId, uint32 mintCount) external payable override {
if (Address.isContract(msg.sender)) revert ISerendipityLazyClaim.CannotMintFromContract();
if (Address.isContract(msg.sender)) revert ISerendipity.CannotMintFromContract();
Claim storage claim = _getClaim(creatorContractAddress, instanceId);
// Checks for reserving
if (mintCount == 0 || mintCount >= MAX_UINT_32) revert ISerendipityLazyClaim.InvalidMintCount();
if (mintCount == 0 || mintCount >= MAX_UINT_32) revert ISerendipity.InvalidMintCount();
if (claim.startDate > block.timestamp || (claim.endDate > 0 && claim.endDate < block.timestamp))
revert ISerendipityLazyClaim.ClaimInactive();
if (claim.totalMax != 0 && claim.total == claim.totalMax) revert ISerendipityLazyClaim.ClaimSoldOut();
if (claim.total == MAX_UINT_32) revert ISerendipityLazyClaim.TooManyRequested();
if (msg.value != (claim.cost + MINT_FEE) * mintCount) revert ISerendipityLazyClaim.InvalidPayment();
revert ISerendipity.ClaimInactive();
if (claim.totalMax != 0 && claim.total == claim.totalMax) revert ISerendipity.ClaimSoldOut();
if (claim.total == MAX_UINT_32) revert ISerendipity.TooManyRequested();
if (msg.value != (claim.cost + MINT_FEE) * mintCount) revert ISerendipity.InvalidPayment();
// calculate the amount to reserve and update totals
uint32 amountToReserve = mintCount;
if (claim.totalMax != 0) {
Expand All @@ -185,9 +185,9 @@ contract ERC1155SerendipityLazyClaim is IERC165, IERC1155SerendipityLazyClaim, I
}

/**
* See {ISerendipityLazyClaim-deliverMints}.
* See {ISerendipity-deliverMints}.
*/
function deliverMints(ISerendipityLazyClaim.ClaimMint[] calldata mints) external override {
function deliverMints(ISerendipity.ClaimMint[] calldata mints) external override {
_validateSigner();
for (uint256 i; i < mints.length; ) {
ClaimMint calldata mintData = mints[i];
Expand All @@ -198,19 +198,19 @@ contract ERC1155SerendipityLazyClaim is IERC165, IERC1155SerendipityLazyClaim, I

for (uint256 j; j < mintData.variationMints.length; ) {
VariationMint calldata variationMint = mintData.variationMints[j];
if (variationMint.variationIndex > MAX_UINT_8) revert ISerendipityLazyClaim.InvalidVariationIndex();
if (variationMint.variationIndex > MAX_UINT_8) revert ISerendipity.InvalidVariationIndex();
uint8 variationIndex = variationMint.variationIndex;
if (variationIndex > claim.tokenVariations || variationIndex < 1) revert ISerendipityLazyClaim.InvalidVariationIndex();
if (variationIndex > claim.tokenVariations || variationIndex < 1) revert ISerendipity.InvalidVariationIndex();
address recipient = variationMint.recipient;
if (variationMint.amount > MAX_UINT_32) revert ISerendipityLazyClaim.TooManyRequested();
if (variationMint.amount > MAX_UINT_32) revert ISerendipity.TooManyRequested();
uint32 amount = variationMint.amount;
UserMintDetails storage userMintDetails = _mintDetailsPerWallet[mintData.creatorContractAddress][
mintData.instanceId
][recipient];

if (userMintDetails.deliveredCount + amount > userMintDetails.reservedCount)
revert ISerendipityLazyClaim.CannotMintMoreThanReserved();
if (claim.startingTokenId > MAX_UINT_80) revert ISerendipityLazyClaim.InvalidStartingTokenId();
revert ISerendipity.CannotMintMoreThanReserved();
if (claim.startingTokenId > MAX_UINT_80) revert ISerendipity.InvalidStartingTokenId();
tokenIds[j] = claim.startingTokenId + variationIndex - 1;
amounts[j] = amount;
receivers[j] = recipient;
Expand All @@ -228,7 +228,7 @@ contract ERC1155SerendipityLazyClaim is IERC165, IERC1155SerendipityLazyClaim, I
}

/**
* See {ISerendipityLazyClaim-getUserMints}.
* See {ISerendipity-getUserMints}.
*/
function getUserMints(
address minter,
Expand All @@ -243,7 +243,7 @@ contract ERC1155SerendipityLazyClaim is IERC165, IERC1155SerendipityLazyClaim, I
*/
function tokenURI(address creatorContractAddress, uint256 tokenId) external view override returns (string memory uri) {
uint256 instanceId = _tokenInstances[creatorContractAddress][tokenId];
if (instanceId == 0) revert ISerendipityLazyClaim.TokenDNE();
if (instanceId == 0) revert ISerendipity.TokenDNE();
Claim memory claim = _getClaim(creatorContractAddress, instanceId);

string memory prefix = "";
Expand All @@ -256,7 +256,7 @@ contract ERC1155SerendipityLazyClaim is IERC165, IERC1155SerendipityLazyClaim, I
}

/**
* See {IERC1155SerendipityLazyClaim-updateTokenURIParams}.
* See {IERC1155Serendipity-updateTokenURIParams}.
*/
function updateTokenURIParams(
address creatorContractAddress,
Expand All @@ -265,7 +265,7 @@ contract ERC1155SerendipityLazyClaim is IERC165, IERC1155SerendipityLazyClaim, I
string calldata location
) external override creatorAdminRequired(creatorContractAddress) {
Claim storage claim = _getClaim(creatorContractAddress, instanceId);
if (storageProtocol == StorageProtocol.INVALID) revert ISerendipityLazyClaim.InvalidStorageProtocol();
if (storageProtocol == StorageProtocol.INVALID) revert ISerendipity.InvalidStorageProtocol();
claim.storageProtocol = storageProtocol;
claim.location = location;
emit SerendipityClaimUpdated(creatorContractAddress, instanceId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ pragma solidity ^0.8.0;

/// @author: manifold.xyz

import "./ISerendipityLazyClaim.sol";
import "./ISerendipity.sol";

/**
* Serendipity Lazy Claim interface for ERC-1155
*/
interface IERC1155SerendipityLazyClaim is ISerendipityLazyClaim {
interface IERC1155Serendipity is ISerendipity {
struct Claim {
StorageProtocol storageProtocol;
uint32 total;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pragma solidity ^0.8.0;
/**
* Serendipity Lazy Claim interface
*/
interface ISerendipityLazyClaim {
interface ISerendipity {
enum StorageProtocol {
INVALID,
NONE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ pragma solidity ^0.8.0;

import "@manifoldxyz/libraries-solidity/contracts/access/AdminControl.sol";

import "./ISerendipityLazyClaim.sol";
import "./ISerendipity.sol";

/**
* @title Serendipity Lazy Claim
* @author manifold.xyz
*/
abstract contract SerendipityLazyClaim is ISerendipityLazyClaim, AdminControl {
abstract contract Serendipity is ISerendipity, AdminControl {
using EnumerableSet for EnumerableSet.AddressSet;

string internal constant ARWEAVE_PREFIX = "https://arweave.net/";
Expand Down Expand Up @@ -55,22 +55,22 @@ abstract contract SerendipityLazyClaim is ISerendipityLazyClaim, AdminControl {
}

/**
* See {ISerendipityLazyClaim-withdraw}.
* See {ISerendipity-withdraw}.
*/
function withdraw(address payable receiver, uint256 amount) external override adminRequired {
(bool sent, ) = receiver.call{ value: amount }("");
if (!sent) revert ISerendipityLazyClaim.FailedToTransfer();
if (!sent) revert ISerendipity.FailedToTransfer();
}

/**
* See {ISerendipityLazyClaim-setSigner}.
* See {ISerendipity-setSigner}.
*/
function setSigner(address signer) external override adminRequired {
_signer = signer;
}

function _validateSigner() internal view {
if (msg.sender != _signer) revert ISerendipityLazyClaim.InvalidSignature();
if (msg.sender != _signer) revert ISerendipity.InvalidSignature();
}

function _getUserMints(
Expand Down
12 changes: 6 additions & 6 deletions packages/manifold/script/ERC1155SerendipityLazyClaim.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
pragma solidity ^0.8.13;

import "forge-std/Script.sol";
import "../contracts/gachaclaims/ERC1155SerendipityLazyClaim.sol";
import "../contracts/gachaclaims/ERC1155Serendipity.sol";

/**
Pro tip for testing! The private key can be whatever. This is what I did to test.
1. Uncomment the lines below and follow the instructions there to change the code.
2. Run the script, like `forge script script/ERC1155SerendipityLazyClaim.s.sol:DeployERC1155SerendipityLazyClaim --rpc-url https://eth-sepolia.g.alchemy.com/v2/xxx --broadcast`
2. Run the script, like `forge script script/ERC1155Serendipity.s.sol:DeployERC1155Serendipity --rpc-url https://eth-sepolia.g.alchemy.com/v2/xxx --broadcast`
3. It will print out the address, but give you an out of eth error.
4. Now you have the address, use your real wallet and send it some sepolia eth.
5. Now, run the script again. It will deploy and transfer the contract to your wallet.
In the end, you just basically used a random pk in the moment to deploy. You never had
to expose your personal pk to your mac's environment variable or anything.
*/
contract DeployERC1155SerendipityLazyClaim is Script {
contract DeployERC1155Serendipity is Script {
function run() external {
// address initialOwner = <your wallet address>; // uncomment this and put in your desired owner address
address initialOwner = vm.envAddress("INITIAL_OWNER"); // comment this out on sepolia
Expand All @@ -31,9 +31,9 @@ contract DeployERC1155SerendipityLazyClaim is Script {
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); // comment this out when testing on goerli
vm.startBroadcast(deployerPrivateKey);

// forge script script/ERC1155SerendipityLazyClaim.s.sol:DeployERC1155SerendipityLazyClaim --optimizer-runs 1000 --rpc-url <YOUR_NODE> --broadcast
// forge verify-contract --compiler-version 0.8.17 --optimizer-runs 1000 --chain sepolia <DEPLOYED_ADDRESS> contracts/gachaclaims/ERC1155SerendipityLazyClaim.sol:ERC1155SerendipityLazyClaim --constructor-args $(cast abi-encode "constructor(address)" "${INITIAL_OWNER}") --watch
new ERC1155SerendipityLazyClaim{salt: 0x16091cc3cd908d7d973f650f59bd476ac79090f0358f87c50a7f5caee0835a84}(initialOwner);
// forge script script/ERC1155Serendipity.s.sol:DeployERC1155Serendipity --optimizer-runs 1000 --rpc-url <YOUR_NODE> --broadcast
// forge verify-contract --compiler-version 0.8.17 --optimizer-runs 1000 --chain sepolia <DEPLOYED_ADDRESS> contracts/gachaclaims/ERC1155Serendipity.sol:ERC1155Serendipity --constructor-args $(cast abi-encode "constructor(address)" "${INITIAL_OWNER}") --watch
new ERC1155Serendipity{salt: 0x16091cc3cd908d7d973f650f59bd476ac79090f0358f87c50a7f5caee0835a84}(initialOwner);
vm.stopBroadcast();
}
}
Loading

0 comments on commit 37bfc1f

Please sign in to comment.