From e29567a29a1297ff86442f752469a9eac62b401b Mon Sep 17 00:00:00 2001 From: 1marcghannam <1marc.ghannam@gmail.com> Date: Thu, 28 Mar 2024 11:48:03 -0400 Subject: [PATCH] feat: Add view function --- contracts/airdrop/MerkleDistributor.sol | 32 +++++++++++++++++++------ 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/contracts/airdrop/MerkleDistributor.sol b/contracts/airdrop/MerkleDistributor.sol index 53b32ae0..8db180d9 100644 --- a/contracts/airdrop/MerkleDistributor.sol +++ b/contracts/airdrop/MerkleDistributor.sol @@ -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]); } } @@ -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); } }