Skip to content
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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions contracts/RandomGames.sol
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;

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 and mintWithLimit functions to ensure the _proxyContract address has been set at the beginning of the funciton.

}

function setProxyContract(address newProxyContract) external onlyOwner {
_proxyContract = newProxyContract;

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");

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);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

require(qty > 0, "Quantity cannot be zero")

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++) {

Choose a reason for hiding this comment

The 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);

Choose a reason for hiding this comment

The 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");
}
}
35 changes: 35 additions & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
deploy,
deploy1155,
deployClone,
deployRandomGame,
setBaseURI,
setCrossmintAddress,
mint,
Expand Down Expand Up @@ -228,6 +229,40 @@ task('deploy', 'Deploy ERC721M')
await deploy(tasksArgs, hre);
});

task('deployRandomGame', 'Deploy RandomGrames')
.addParam('name', 'name')
.addParam('symbol', 'symbol')
.addParam('maxsupply', 'max supply')
.addParam('tokenurisuffix', 'token uri suffix', '.json')
.addParam('globalwalletlimit', 'global wallet limit', '0')
.addParam('timestampexpiryseconds', 'timestamp expiry in seconds', '300')
.addParam('proxycontract', 'minting proxy contract')
.addParam<boolean>(
'openedition',
'whether or not a open edition mint (unlimited supply, 999,999,999)',
false,
types.boolean,
)
.addOptionalParam(
'cosigner',
'cosigner address (0x00...000 if not using cosign)',
'0x0000000000000000000000000000000000000000',
)
.addOptionalParam(
'mintcurrency',
'ERC-20 contract address (if minting with ERC-20)',
'0x0000000000000000000000000000000000000000',
)
.addOptionalParam(
'fundreceiver',
'The treasury wallet to receive mint fund',
)
.addOptionalParam('gaspricegwei', 'Set gas price in Gwei')
.addOptionalParam('gaslimit', 'Set maximum gas units to spend on transaction')
.setAction(async (tasksArgs, hre) => {
console.log('Deploying random games...');
await deployRandomGame(tasksArgs, hre);
});

task('deploy1155', 'Deploy ERC1155M')
.addParam('name', 'name')
Expand Down
127 changes: 127 additions & 0 deletions scripts/deployRandomGame.ts
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");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do this too. You're going to catch me console.log("roflcopter") a bunch of times.

// 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}`,
);

};
1 change: 1 addition & 0 deletions scripts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export * from './deploy';
export * from './deploy1155';
export * from './deployBA';
export * from './deployClone';
export * from './deployRandomGame';
export * from './mint';
export * from './ownerMint';
export * from './ownerMint1155';
Expand Down
Loading