Skip to content

Commit

Permalink
✨ Add airdrop functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
davisshaver committed Sep 26, 2024
1 parent acdd757 commit 61bfb49
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/ProtoGravaNFT.sol
Original file line number Diff line number Diff line change
Expand Up @@ -320,17 +320,27 @@ contract ProtoGravaNFT is ERC721, LilENS, LilOwnable, LilHash {

/* solhint-enable quotes */

/// @notice Airdrop a token
function airdrop(address to) external onlyContractOwner {
mintTo(to);
}

/// @notice Mint a token
function mint() external onlyWhenPublicMintEnabled {
mintTo(msg.sender);
}

/// @notice Mint a token to an address
function mintTo(address to) internal {
if (totalMinted + 1 >= MAX_TOTAL_MINTED) revert NoTokensLeft();

if (balanceOf(msg.sender) > 0) revert OnePerUser();
if (balanceOf(to) > 0) revert OnePerUser();

uint256 newItemId = ++totalMinted;

_mint(msg.sender, newItemId);
_mint(to, newItemId);

emit Events.Mint(msg.sender);
emit Events.Mint(to);
}

/// @notice Burn a token
Expand Down
19 changes: 19 additions & 0 deletions src/test/ProtoGravaNFT.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,25 @@ contract ProtoGravNFTTestContract is ProtoGravaNFTTest {
assertEq(protogravanft.balanceOf(address(this)), 1);
}

/// @notice Test that airdrop can only be called by owner
function testAirdrop() public {
// Collect Alice balance of tokens before mint
uint256 alicePreBalance = alice.tokenBalance();
// Mint approved token
protogravanft.airdrop(alice.getAddress());
// Collect Alice balance of tokens after mint
uint256 alicePostBalance = alice.tokenBalance();
assertEq(alicePreBalance, 0);
assertEq(alicePostBalance, 1);
assertEq(protogravanft.totalSupply(), 1);
assertEq(protogravanft.ownerOf(1), alice.getAddress());
vm.expectRevert(abi.encodeWithSignature("OnePerUser()"));
alice.mint();
charlieAddress = charlie.getAddress();
vm.expectRevert(abi.encodeWithSignature("NotOwner()"));
alice.airdrop(charlieAddress);
}

/// @notice Allow Alice to mint a token for approved hash
function testAliceMint() public {
// Collect Alice balance of tokens before mint
Expand Down
6 changes: 6 additions & 0 deletions src/test/utils/ProtoGravaNFTUser.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ contract ProtoGravaNFTUser is Test {

/// ============ Inherited functionality ============

/// @notice Airdrop a token
/// @param to address receiving airdrop
function airdrop(address to) public {
return PROTOGRAVANFT.airdrop(to);
}

/// @notice Mint a token
function mint() public {
return PROTOGRAVANFT.mint();
Expand Down

0 comments on commit 61bfb49

Please sign in to comment.