Skip to content

Commit

Permalink
feat: Add ipfsHash merkle distributor
Browse files Browse the repository at this point in the history
  • Loading branch information
1marcghannam committed Mar 28, 2024
1 parent ced14eb commit 34fdbaa
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions contracts/airdrop/MerkleDistributor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,20 @@ contract MerkleDistributor is Ownable {
uint256 expiryTimestamp;
bytes32 merkleRoot;
uint256 totalAmount;
string ipfsHash;
mapping(address => uint256) claimed;
}
address[] public tokens;
mapping(address => Distribution) public distributions;

event Claimed(address indexed token, uint256 index, address indexed account, uint256 amount);
event DistributionAdded(uint256 indexed tokenIndex, address indexed token, uint256 totalAmount, uint256 expiryTimestamp);
event DistributionAdded(
uint256 indexed tokenIndex,
address indexed token,
uint256 totalAmount,
uint256 expiryTimestamp,
string ipfsHash
);
event DistributionUpdated(address indexed token, uint256 additionalAmount, uint256 expiryTimestamp);
event SetExpiryTimestamp(address indexed token, uint256 expiryTimestamp);

Expand Down Expand Up @@ -55,15 +62,16 @@ contract MerkleDistributor is Ownable {
address[] calldata _tokens,
bytes32[] calldata _merkleRoots,
uint256[] calldata _totalAmounts,
uint256[] calldata _expiryTimestamps
uint256[] calldata _expiryTimestamps,
string memory _ipfsHash
) external onlyOwner {
require(
_tokens.length == _merkleRoots.length && _tokens.length == _totalAmounts.length,
"MerkleDistributor: Array lengths need to match."
);

for (uint256 i = 0; i < _tokens.length; i++) {
addDistribution(_tokens[i], _merkleRoots[i], _totalAmounts[i], _expiryTimestamps[i]);
addDistribution(_tokens[i], _merkleRoots[i], _totalAmounts[i], _expiryTimestamps[i], _ipfsHash[i]);
}
}

Expand All @@ -78,7 +86,8 @@ contract MerkleDistributor is Ownable {
address _token,
bytes32 _merkleRoot,
uint256 _totalAmount,
uint256 _expiryTimestamp
uint256 _expiryTimestamp,
string memory _ipfsHash
) public onlyOwner {
require(distributions[_token].token == address(0), "MerkleDistributor: Distribution is already added.");
require(IERC20(_token).balanceOf(address(this)) >= _totalAmount, "MerkleDistributor: Insufficient balance.");
Expand All @@ -88,8 +97,9 @@ contract MerkleDistributor is Ownable {
distributions[_token].merkleRoot = _merkleRoot;
distributions[_token].totalAmount = _totalAmount;
distributions[_token].expiryTimestamp = _expiryTimestamp;
distributions[_token].ipfsHash = _ipfsHash;

emit DistributionAdded(tokens.length - 1, _token, _totalAmount, _expiryTimestamp);
emit DistributionAdded(tokens.length - 1, _token, _totalAmount, _expiryTimestamp, _ipfsHash);
}

/**
Expand Down Expand Up @@ -249,4 +259,11 @@ contract MerkleDistributor is Ownable {
distributions[_token].expiryTimestamp = _expiryTimestamp;
emit SetExpiryTimestamp(_token, _expiryTimestamp);
}

/**
* @notice returns the addresses of all token distributions
**/
function getTokenDistributionAddresses() external view returns (address[] memory) {
return tokens;
}
}

0 comments on commit 34fdbaa

Please sign in to comment.