Skip to content

Commit

Permalink
already claimed addeda
Browse files Browse the repository at this point in the history
  • Loading branch information
panditdhamdhere committed Sep 9, 2024
1 parent a98bccb commit 7c8e48d
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/MerkleAirdrop.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,19 @@ contract MerkleAirdrop {
//////////// //////ERRORS /////////////////////
///////////////////////////////////////////////
error MerkleAirdrop__InvalidProof();
error MerkleAirdrop__AlreadyClaimed();

///////////////////////////////////////////////
///////////////STORAGE VARIABLES //////////////
///////////////STATE VARIABLES //////////////
///////////////////////////////////////////////

address[] claimers;
bytes32 private immutable i_merkleRoot;
IERC20 private immutable i_airdropToken;

// storage variable => mapping
mapping(address claimer => bool claimed) private s_hasClaimed;

///////////////////////////////////////////////
///////////////////EVENTS/////////////////////
///////////////////////////////////////////////
Expand All @@ -33,11 +37,19 @@ contract MerkleAirdrop {
i_airdropToken = airdropToken;
}

///////////////////////////////////////////////
///////////////////FUNCTIONS///////////////////
///////////////////////////////////////////////

function claim(
address account,
uint256 amount,
bytes32[] calldata merkleProof
) external {
if (s_hasClaimed[account]) {
revert MerkleAirdrop__AlreadyClaimed();
}

// calculate using the account and the amount. the hash -> leaf node
bytes32 leaf = keccak256(
bytes.concat(keccak256(abi.encode(account, amount)))
Expand All @@ -46,6 +58,7 @@ contract MerkleAirdrop {
if (!MerkleProof.verify(merkleProof, i_merkleRoot, leaf)) {
revert MerkleAirdrop__InvalidProof();
}
s_hasClaimed[account] = true;
emit Claim(account, amount);
i_airdropToken.safeTransfer(account, amount);
}
Expand Down

0 comments on commit 7c8e48d

Please sign in to comment.