Skip to content

Commit

Permalink
Merge pull request #16 from ourzora/add_batch_minting_and_further_tests
Browse files Browse the repository at this point in the history
final code updates / cleanup
  • Loading branch information
iainnash authored Apr 25, 2022
2 parents 0e5d809 + 88a99b0 commit bf44f88
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 24 deletions.
29 changes: 17 additions & 12 deletions contracts/ERC721Drop.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ contract ERC721Drop is
IZoraDrop,
OwnableSkeleton
{
uint256 private constant VERSION = 2;
/// @dev This is the underlying contract version that is implemented by the interface
uint256 private constant VERSION = 3;
/// @dev This is the max mint batch size for the optimized ERC721A mint contract
uint256 private constant MAX_MINT_BATCH_SIZE = 8;

using AddressUpgradeable for address payable;

Expand Down Expand Up @@ -378,13 +381,16 @@ contract ERC721Drop is
return firstMintedTokenId;
}

/// @dev Function to mint NFTs
/// @notice (important: Does not enforce max supply limit, enforce that limit earlier)
/// @notice Function to mint NFTs
/// @dev (important: Does not enforce max supply limit, enforce that limit earlier)
/// @dev This batches in size of 8 as per recommended by ERC721A creators
/// @param to address to mint NFTs to
/// @param quantity number of NFTs to mint
function _mintNFTs(address to, uint256 quantity) internal {
do {
uint256 toMint = quantity > 8 ? 8 : quantity;
uint256 toMint = quantity > MAX_MINT_BATCH_SIZE
? MAX_MINT_BATCH_SIZE
: quantity;
_mint({to: to, quantity: toMint, _data: "", safe: false});
quantity -= toMint;
} while (quantity > 0);
Expand Down Expand Up @@ -420,10 +426,9 @@ contract ERC721Drop is
"Needs to be approved"
);
require(msg.value == pricePerToken * quantity, "Wrong price");
require(
presaleMintsByAddress[_msgSender()] + quantity <= maxQuantity,
TOO_MANY
);

presaleMintsByAddress[_msgSender()] += quantity;
require(presaleMintsByAddress[_msgSender()] <= maxQuantity, TOO_MANY);

_mintNFTs(_msgSender(), quantity);
uint256 firstMintedTokenId = _lastMintedTokenId() - quantity;
Expand All @@ -435,8 +440,6 @@ contract ERC721Drop is
firstPurchasedTokenId: firstMintedTokenId
});

presaleMintsByAddress[_msgSender()] += quantity;

return firstMintedTokenId;
}

Expand Down Expand Up @@ -540,8 +543,10 @@ contract ERC721Drop is
);

// No need for gas limit to trusted address.
feeRecipient.sendValue(zoraFee);
funds -= zoraFee;
if (zoraFee > 0) {
feeRecipient.sendValue(zoraFee);
funds -= zoraFee;
}
// No need for gas limit to trusted address.
config.fundsRecipient.sendValue(funds);
}
Expand Down
60 changes: 48 additions & 12 deletions scripts/snapshot.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,48 @@
import 'isomorphic-fetch'

const indexer_result = await fetch("https://indexer-prod-mainnet.zora.co/v1/graphql", {
headers: {
Accept: "*/*",
"Content-Type": "application/json",
},
body: '{"query":"query Token {\\n Token(where:{\\n tokenContract:{address:{_eq:\\"0xC9677Cd8e9652F1b1aaDd3429769b0Ef8D7A0425\\"}}\\n }\\n limit: 100\\n\\toffset: 0\\n) {\\n tokenId\\n owner\\n metadata {\\n json\\n }\\n }\\n}","variables":null,"operationName":"Token"}',
method: "POST",
});

console.log(indexer_result)
import "isomorphic-fetch";
import { writeFile } from "fs/promises";
import esMain from "es-main";

async function fetchIndexer(contract, offset) {
const query = `{"query":"query Token {\\n Token(where:{\\n tokenContract:{address:{_eq:\\"${contract}\\"}}\\n }\\n limit: 100\\n\\toffset: ${offset}\\n) {\\n tokenId\\n owner\\n metadata {\\n json\\n }\\n }\\n}","variables":null,"operationName":"Token"}`;
console.log(query);
const result = await fetch(
"https://indexer-prod-mainnet.zora.co/v1/graphql",
{
headers: {
Accept: "*/*",
"Content-Type": "application/json",
},
body: query,
method: "POST",
}
);
const jsonResult = await result.json();
const tokenData = jsonResult.data.Token;
return tokenData;
}

async function fetchLoop(contract) {
let resultPart = [];
let results = [];
let offset = 0;
do {
resultPart = await fetchIndexer(contract, offset);
results = results.concat(resultPart);
console.log({ offset });
offset += 100;
} while (resultPart.length > 0);
return results;
}

async function fetchAllAddresses(contract) {
const results = await fetchLoop(contract);
console.log(`[results] has ${results.length} nfts`);
writeFile("./results.json", JSON.stringify(results, null, 2));
}

if (esMain(import.meta)) {
const contract = process.argv[2];
console.log(`[result] fetching for contract: ${contract}`);
await fetchAllAddresses(contract);
console.log(`[result] done`);
}

0 comments on commit bf44f88

Please sign in to comment.