Skip to content

Instantly share code, notes, and snippets.

@0x3b33
Created November 6, 2023 22:53
Show Gist options
  • Select an option

  • Save 0x3b33/558b919a57101e7a0942e557a464078a to your computer and use it in GitHub Desktop.

Select an option

Save 0x3b33/558b919a57101e7a0942e557a464078a to your computer and use it in GitHub Desktop.
If an airdrop happens before a mint the price could skyrocket
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
// forge test --match-test test_airdrop --lib-paths ../smart-contracts
import {Test} from "forge-std/Test.sol";
import {console} from "forge-std/console.sol";
import {NextGenAdmins} from "contracts/NextGenAdmins.sol";
import {randomPool as XRandoms} from "contracts/XRandoms.sol";
import {NextGenCore} from "contracts/NextGenCore.sol";
import {NextGenRandomizerNXT as RandomizerNXT} from "contracts/RandomizerNXT.sol";
import {DelegationManagementContract as NFTDelegation} from "contracts/NFTdelegation.sol";
import {NextGenMinterContract as MinterContract} from "contracts/MinterContract.sol";
import {IERC721Receiver} from "contracts/IERC721Receiver.sol";
import {MerkleProof} from "contracts/MerkleProof.sol";
contract FullTest is Test {
NextGenAdmins public nextGenAdmins;
XRandoms public xRandoms;
NextGenCore public nextGenCore;
RandomizerNXT public randomizerNXT;
NFTDelegation public nftDelegation;
MinterContract public minterContract;
uint256 mintCycle;
address user1;
address user2;
function setUp() public {
user1 = address(111);
user2 = address(222);
vm.label(user1, "user1");
vm.label(user2, "user2");
nextGenAdmins = new NextGenAdmins();
xRandoms = new XRandoms();
nextGenCore = new NextGenCore(
"NextGen Core",
"Core",
address(nextGenAdmins)
);
randomizerNXT = new RandomizerNXT(
address(xRandoms),
address(nextGenAdmins),
address(nextGenCore)
);
nftDelegation = new NFTDelegation();
minterContract = new MinterContract(
address(nextGenCore),
address(nftDelegation),
address(nextGenAdmins)
);
nextGenCore.addMinterContract(address(minterContract));
}
function hashPair(bytes32 a, bytes32 b) public pure returns (bytes32) {
return a < b ? efficientHash(a, b) : efficientHash(b, a);
}
function efficientHash(bytes32 a, bytes32 b) private pure returns (bytes32 value) {
/// @solidity memory-safe-assembly
assembly {
mstore(0x00, a)
mstore(0x20, b)
value := keccak256(0x00, 0x40)
}
}
function initCollection() public {
bytes32 leaf1 = keccak256(abi.encodePacked(user1, uint256(2), "Hello"));
bytes32 leaf2 = keccak256(abi.encodePacked(user1, uint256(2), "Hello"));
string[] memory script = new string[](1);
bytes32 merkleRoot = hashPair(leaf1, leaf2);
script[0] = "canvas.square();";
// create a fix priced collection
nextGenCore.createCollection(
"CollectionName", "Artist", "Description", "www.collection.com", "MIT", "localhost:3000//", "GenArt", script
);
nextGenCore.setCollectionData(
1, // ID
address(0x3b), // artist
100, // maxNFTs
300, // TotalSupp
500 //timeAfterintEnd
);
nextGenCore.addRandomizer(1, address(randomizerNXT));
minterContract.setCollectionCosts(
1, // ID
1e18, // mintCost
2e18, //endMintCost
10, // rate
3600, // timePeriod
3, // salesOption
address(0x3b)
);
minterContract.setCollectionPhases(
1, // ID
block.timestamp, //allowStart
block.timestamp + 1 days, // allowEnd
block.timestamp + 3600 * 4, //publicStart
block.timestamp + 3 days, // publicEnd
merkleRoot
);
}
function test_airdrop() public {
vm.warp(block.timestamp + 100 days);
initCollection();
bytes32[] memory merkleProof = new bytes32[](0);
address[] memory recepients = new address[](1);
uint256[] memory numberOfT = new uint256[](1);
string[] memory tokenData = new string[](1);
uint256[] memory saltfun_o = new uint256[](1);
recepients[0] = user2;
numberOfT[0] = 10;
tokenData[0] = "";
saltfun_o[0] = 0;
console.log("Price: ", minterContract.getPrice(1), " In 1e17: ", minterContract.getPrice(1) / 1e17);
console.log("Airdropping 10 tokens...");
minterContract.airDropTokens(recepients, tokenData, saltfun_o, 1,numberOfT);
console.log("Price: ", minterContract.getPrice(1), " In 1e17: ", minterContract.getPrice(1) / 1e17);
vm.warp(block.timestamp + 2 days);
deal(user1, 1e21);
vm.prank(user1);
minterContract.mint{value: 3e18}(1, 1, 2, "Hello", user1, merkleProof, address(0), 0);
console.log("Price: ", minterContract.getPrice(1), " In 1e17: ", minterContract.getPrice(1) / 1e17);
}
function onERC721Received(address, address, uint256, bytes memory) public returns (bytes4) {
return IERC721Receiver.onERC721Received.selector;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment