Skip to content

Commit

Permalink
feat: Add view function
Browse files Browse the repository at this point in the history
  • Loading branch information
1marcghannam committed Mar 28, 2024
1 parent 34fdbaa commit e29567a
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions contracts/airdrop/MerkleDistributor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,18 @@ contract MerkleDistributor is Ownable {
bytes32[] calldata _merkleRoots,
uint256[] calldata _totalAmounts,
uint256[] calldata _expiryTimestamps,
string memory _ipfsHash
string[] calldata _ipfsHashes
) external onlyOwner {
require(
_tokens.length == _merkleRoots.length && _tokens.length == _totalAmounts.length,
_tokens.length == _merkleRoots.length &&
_tokens.length == _totalAmounts.length &&
_tokens.length == _expiryTimestamps.length &&
_tokens.length == _ipfsHashes.length,
"MerkleDistributor: Array lengths need to match."
);

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

Expand Down Expand Up @@ -261,9 +264,24 @@ contract MerkleDistributor is Ownable {
}

/**
* @notice returns the addresses of all token distributions
**/
function getTokenDistributionAddresses() external view returns (address[] memory) {
return tokens;
* @notice Returns the claimed amounts for a user across all distributions
* @param _user Address of the user
* @return claimedAmounts Array of amounts claimed by the user from each distribution
* @return tokenAddresses Array of token addresses corresponding to each claimed amount
*/
function getUserClaimedAmounts(
address _user
) external view returns (uint256[] memory claimedAmounts, address[] memory tokenAddresses) {
uint256 tokenCount = tokens.length;
claimedAmounts = new uint256[](tokenCount);
tokenAddresses = new address[](tokenCount);

for (uint256 i = 0; i < tokenCount; i++) {
address token = tokens[i];
claimedAmounts[i] = distributions[token].claimed[_user];
tokenAddresses[i] = token;
}

return (claimedAmounts, tokenAddresses);
}
}

0 comments on commit e29567a

Please sign in to comment.