Skip to content

Commit

Permalink
final code updates / cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
iainnash committed Apr 25, 2022
1 parent ce1b6fd commit d63153b
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 22 deletions.
26 changes: 16 additions & 10 deletions contracts/ERC721Drop.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,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 @@ -303,7 +306,7 @@ contract ERC721Drop is
*** ***
*** ---------------------------------- ***
***
** */
***/

/**
@dev This allows the user to purchase a edition edition
Expand Down Expand Up @@ -339,13 +342,14 @@ 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 @@ -381,7 +385,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 @@ -393,8 +399,6 @@ contract ERC721Drop is
firstPurchasedTokenId: firstMintedTokenId
});

presaleMintsByAddress[_msgSender()] += quantity;

return firstMintedTokenId;
}

Expand Down Expand Up @@ -487,8 +491,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 d63153b

Please sign in to comment.