Skip to content

Commit

Permalink
claim condition id and reset
Browse files Browse the repository at this point in the history
  • Loading branch information
kumaryash90 committed Mar 21, 2024
1 parent 14553e2 commit 0b51a7f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
34 changes: 21 additions & 13 deletions contracts/prebuilts/unaudited/airdrop/Airdrop.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@ contract Airdrop is EIP712, Initializable, Ownable {
State, constants & structs
//////////////////////////////////////////////////////////////*/

bytes32 public merkleRootETH;
mapping(address => bool) public claimedETH;

// token contract address => merkle root
/// @dev token contract address => conditionId
mapping(address => bytes32) public conditionIdForToken;
/// @dev token contract address => merkle root
mapping(address => bytes32) public merkleRoot;
// hash(claimer address || token address || token id [1155]) => has claimed
mapping(bytes32 => bool) private claimed;
/// @dev conditionId => hash(claimer address, token address, token id [1155]) => has claimed
mapping(bytes32 => mapping(bytes32 => bool)) private claimed;
/// @dev Mapping from request UID => whether the request is processed.
mapping(bytes32 => bool) private processed;

Expand Down Expand Up @@ -284,7 +283,9 @@ contract Airdrop is EIP712, Initializable, Ownable {

function claim20(address _token, address _receiver, uint256 _quantity, bytes32[] calldata _proofs) external {
bytes32 claimHash = _getClaimHashERC20(msg.sender, _token);
if (claimed[claimHash]) {
bytes32 conditionId = conditionIdForToken[_token];

if (claimed[conditionId][claimHash]) {
revert AirdropAlreadyClaimed();

Check warning on line 289 in contracts/prebuilts/unaudited/airdrop/Airdrop.sol

View check run for this annotation

Codecov / codecov/patch

contracts/prebuilts/unaudited/airdrop/Airdrop.sol#L289

Added line #L289 was not covered by tests
}

Expand All @@ -300,7 +301,7 @@ contract Airdrop is EIP712, Initializable, Ownable {
revert AirdropInvalidProof();

Check warning on line 301 in contracts/prebuilts/unaudited/airdrop/Airdrop.sol

View check run for this annotation

Codecov / codecov/patch

contracts/prebuilts/unaudited/airdrop/Airdrop.sol#L301

Added line #L301 was not covered by tests
}

claimed[claimHash] = true;
claimed[conditionId][claimHash] = true;

if (_token == CurrencyTransferLib.NATIVE_TOKEN) {
(bool success, ) = _receiver.call{ value: _quantity }("");
Expand All @@ -312,7 +313,9 @@ contract Airdrop is EIP712, Initializable, Ownable {

function claim721(address _token, address _receiver, uint256 _tokenId, bytes32[] calldata _proofs) external {
bytes32 claimHash = _getClaimHashERC721(msg.sender, _token);
if (claimed[claimHash]) {
bytes32 conditionId = conditionIdForToken[_token];

if (claimed[conditionId][claimHash]) {
revert AirdropAlreadyClaimed();

Check warning on line 319 in contracts/prebuilts/unaudited/airdrop/Airdrop.sol

View check run for this annotation

Codecov / codecov/patch

contracts/prebuilts/unaudited/airdrop/Airdrop.sol#L319

Added line #L319 was not covered by tests
}

Expand All @@ -328,7 +331,7 @@ contract Airdrop is EIP712, Initializable, Ownable {
revert AirdropInvalidProof();

Check warning on line 331 in contracts/prebuilts/unaudited/airdrop/Airdrop.sol

View check run for this annotation

Codecov / codecov/patch

contracts/prebuilts/unaudited/airdrop/Airdrop.sol#L331

Added line #L331 was not covered by tests
}

claimed[claimHash] = true;
claimed[conditionId][claimHash] = true;

IERC721(_token).safeTransferFrom(owner(), _receiver, _tokenId);
}
Expand All @@ -341,7 +344,9 @@ contract Airdrop is EIP712, Initializable, Ownable {
bytes32[] calldata _proofs
) external {
bytes32 claimHash = _getClaimHashERC1155(msg.sender, _token, _tokenId);
if (claimed[claimHash]) {
bytes32 conditionId = conditionIdForToken[_token];

if (claimed[conditionId][claimHash]) {
revert AirdropAlreadyClaimed();

Check warning on line 350 in contracts/prebuilts/unaudited/airdrop/Airdrop.sol

View check run for this annotation

Codecov / codecov/patch

contracts/prebuilts/unaudited/airdrop/Airdrop.sol#L350

Added line #L350 was not covered by tests
}

Expand All @@ -357,7 +362,7 @@ contract Airdrop is EIP712, Initializable, Ownable {
revert AirdropInvalidProof();

Check warning on line 362 in contracts/prebuilts/unaudited/airdrop/Airdrop.sol

View check run for this annotation

Codecov / codecov/patch

contracts/prebuilts/unaudited/airdrop/Airdrop.sol#L362

Added line #L362 was not covered by tests
}

claimed[claimHash] = true;
claimed[conditionId][claimHash] = true;

IERC1155(_token).safeTransferFrom(owner(), _receiver, _tokenId, _quantity, "");
}
Expand All @@ -366,7 +371,10 @@ contract Airdrop is EIP712, Initializable, Ownable {
Setter functions
//////////////////////////////////////////////////////////////*/

function setMerkleRoot(address _token, bytes32 _merkleRoot) external onlyOwner {
function setMerkleRoot(address _token, bytes32 _merkleRoot, bool _resetClaimStatus) external onlyOwner {
if (_resetClaimStatus || conditionIdForToken[_token] == bytes32(0)) {
conditionIdForToken[_token] = keccak256(abi.encodePacked(_token, block.number));
}
merkleRoot[_token] = _merkleRoot;
}

Expand Down
6 changes: 3 additions & 3 deletions src/test/benchmark/AirdropBenchmark.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ contract AirdropBenchmarkTest is BaseTest {

// set merkle root
vm.prank(signer);
airdrop.setMerkleRoot(address(erc20), root);
airdrop.setMerkleRoot(address(erc20), root, true);

// generate proof
inputs[1] = "src/test/scripts/getProofAirdrop.ts";
Expand Down Expand Up @@ -456,7 +456,7 @@ contract AirdropBenchmarkTest is BaseTest {

// set merkle root
vm.prank(signer);
airdrop.setMerkleRoot(address(erc721), root);
airdrop.setMerkleRoot(address(erc721), root, true);

// generate proof
inputs[1] = "src/test/scripts/getProofAirdrop.ts";
Expand Down Expand Up @@ -604,7 +604,7 @@ contract AirdropBenchmarkTest is BaseTest {

// set merkle root
vm.prank(signer);
airdrop.setMerkleRoot(address(erc1155), root);
airdrop.setMerkleRoot(address(erc1155), root, true);

// generate proof
inputs[1] = "src/test/scripts/getProofAirdrop.ts";
Expand Down

0 comments on commit 0b51a7f

Please sign in to comment.