-
Notifications
You must be signed in to change notification settings - Fork 41
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
Random Games #143
base: main
Are you sure you want to change the base?
Random Games #143
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
//SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.4; | ||
|
||
import {ERC721CM, ERC721ACQueryable, IERC721A} from "./ERC721CM.sol"; | ||
|
||
/** | ||
* @title RandomGamesMinting | ||
*/ | ||
contract RandomGamesMinting is ERC721CM { | ||
address private _proxyContract; | ||
|
||
constructor( | ||
string memory collectionName, | ||
string memory collectionSymbol, | ||
string memory tokenURISuffix, | ||
uint256 maxMintableSupply, | ||
uint256 globalWalletLimit, | ||
address cosigner, | ||
uint64 timestampExpirySeconds, | ||
address mintCurrency, | ||
address fundReceiver, | ||
address proxyContract | ||
) | ||
ERC721CM( | ||
collectionName, | ||
collectionSymbol, | ||
tokenURISuffix, | ||
maxMintableSupply, | ||
globalWalletLimit, | ||
cosigner, | ||
timestampExpirySeconds, | ||
mintCurrency, | ||
fundReceiver | ||
) | ||
{ | ||
_proxyContract = proxyContract; | ||
} | ||
|
||
function setProxyContract(address newProxyContract) external onlyOwner { | ||
_proxyContract = newProxyContract; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If you want to be able to disable the proxy by setting it to the zero address then I would do the recommendation of adding the check in the mint. |
||
} | ||
|
||
function mint( | ||
uint32 qty, | ||
bytes32[] calldata proof, | ||
uint64 timestamp, | ||
bytes calldata signature | ||
) external override payable virtual nonReentrant { | ||
_mintInternal(qty, msg.sender, 0, proof, timestamp, signature); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think it handles qty 0 gracefully and the results are benign depending on the proxy contract behavior. But the require could save some gas. |
||
|
||
address[] memory minters = new address[](qty); | ||
for (uint256 i = 0; i < qty; i++) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is 20,000 gas to write to an array. So there is a theoretical limit here to how large qty could be before the loop will run out of gas. It will probably in the range of 1,000 - 1,500 on the high end. |
||
minters[i] = msg.sender; | ||
} | ||
(bool success, ) = _proxyContract.call(abi.encodeWithSignature("mint(address[])", minters)); | ||
|
||
require(success, "Proxy call failed"); | ||
} | ||
|
||
function mintWithLimit( | ||
uint32 qty, | ||
uint32 limit, | ||
bytes32[] calldata proof, | ||
uint64 timestamp, | ||
bytes calldata signature | ||
) external override payable virtual nonReentrant { | ||
_mintInternal(qty, msg.sender, limit, proof, timestamp, signature); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe the same qty check here? |
||
|
||
address[] memory minters = new address[](qty); | ||
for (uint256 i = 0; i < qty; i++) { | ||
minters[i] = msg.sender; | ||
} | ||
(bool success, ) = _proxyContract.call(abi.encodeWithSignature("mint(address[])", minters)); | ||
|
||
require(success, "Proxy call failed"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
// We require the Hardhat Runtime Environment explicitly here. This is optional | ||
// but useful for running the script in a standalone fashion through `node <script>`. | ||
// | ||
// When running the script with `npx hardhat run <script>` you'll find the Hardhat | ||
// Runtime Environment's members available in the global scope. | ||
|
||
import { confirm } from '@inquirer/prompts'; | ||
import { HardhatRuntimeEnvironment } from 'hardhat/types'; | ||
import { ContractDetails } from './common/constants'; | ||
import { checkCodeVersion, estimateGas } from './utils/helper'; | ||
import { Overrides } from 'ethers'; | ||
|
||
interface IDeployRandomGameParams { | ||
name: string; | ||
symbol: string; | ||
tokenurisuffix: string; | ||
maxsupply: string; | ||
globalwalletlimit: string; | ||
cosigner?: string; | ||
timestampexpiryseconds?: number; | ||
useoperatorfilterer?: boolean; | ||
openedition?: boolean; | ||
mintcurrency?: string; | ||
fundreceiver?: string; | ||
proxycontract: string; | ||
gaspricegwei?: number; | ||
gaslimit?: number; | ||
} | ||
|
||
export const deployRandomGame = async ( | ||
args: IDeployRandomGameParams, | ||
hre: HardhatRuntimeEnvironment, | ||
) => { | ||
console.log("123"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do this too. You're going to catch me |
||
// Compile again in case we have a coverage build (binary too large to deploy) | ||
const contractName = 'RandomGamesMinting'; | ||
|
||
let maxsupply = hre.ethers.BigNumber.from(args.maxsupply); | ||
|
||
if (args.openedition) { | ||
maxsupply = hre.ethers.BigNumber.from('999999999'); | ||
} | ||
|
||
const overrides: Overrides = {}; | ||
if (args.gaspricegwei) { | ||
overrides.gasPrice = hre.ethers.BigNumber.from(args.gaspricegwei * 1e9); | ||
} | ||
if (args.gaslimit) { | ||
overrides.gasLimit = hre.ethers.BigNumber.from(args.gaslimit); | ||
} | ||
|
||
const [signer] = await hre.ethers.getSigners(); | ||
const contractFactory = await hre.ethers.getContractFactory(contractName, signer); | ||
|
||
const params = [ | ||
args.name, | ||
args.symbol, | ||
args.tokenurisuffix, | ||
maxsupply, | ||
hre.ethers.BigNumber.from(args.globalwalletlimit), | ||
args.cosigner ?? hre.ethers.constants.AddressZero, | ||
args.timestampexpiryseconds ?? 300, | ||
args.mintcurrency ?? hre.ethers.constants.AddressZero, | ||
args.fundreceiver ?? signer.address, | ||
args.proxycontract, | ||
] as any[]; | ||
|
||
console.log( | ||
`Going to deploy ${contractName} with params`, | ||
JSON.stringify(args, null, 2), | ||
); | ||
|
||
if ( | ||
!(await estimateGas( | ||
hre, | ||
contractFactory.getDeployTransaction( | ||
args.name, | ||
args.symbol, | ||
args.tokenurisuffix, | ||
maxsupply, | ||
hre.ethers.BigNumber.from(args.globalwalletlimit), | ||
args.cosigner ?? hre.ethers.constants.AddressZero, | ||
args.timestampexpiryseconds ?? 300, | ||
args.mintcurrency ?? hre.ethers.constants.AddressZero, | ||
args.fundreceiver ?? signer.address, | ||
args.proxycontract, | ||
), | ||
overrides, | ||
)) | ||
) | ||
return; | ||
|
||
if (!(await confirm({ message: 'Continue to deploy?' }))) return; | ||
|
||
const contract = await contractFactory.deploy( | ||
args.name, | ||
args.symbol, | ||
args.tokenurisuffix, | ||
maxsupply, | ||
hre.ethers.BigNumber.from(args.globalwalletlimit), | ||
args.cosigner ?? hre.ethers.constants.AddressZero, | ||
args.timestampexpiryseconds ?? 300, | ||
args.mintcurrency ?? hre.ethers.constants.AddressZero, | ||
args.fundreceiver ?? signer.address, | ||
args.proxycontract, | ||
overrides); | ||
console.log('Deploying contract... '); | ||
console.log('tx:', contract.deployTransaction.hash); | ||
|
||
await contract.deployed(); | ||
|
||
console.log(`${contractName} deployed to:`, contract.address); | ||
console.log('run the following command to verify the contract:'); | ||
const paramsStr = params | ||
.map((param) => { | ||
if (hre.ethers.BigNumber.isBigNumber(param)) { | ||
return `"${param.toString()}"`; | ||
} | ||
return `"${param}"`; | ||
}) | ||
.join(' '); | ||
|
||
console.log( | ||
`npx hardhat verify --network ${hre.network.name} ${contract.address} ${paramsStr}`, | ||
); | ||
|
||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
require(newProxyContract != address(0), "Proxy contract cannot be zero address");
You may want to deploy without setting an address, I see your setter function. Then I would add a similar check to the
mint
andmintWithLimit
functions to ensure the_proxyContract
address has been set at the beginning of the funciton.