@@ -26,29 +26,24 @@ contract QuestDonation is Ownable {
2626 event FundsWithdrawn (address indexed token , uint256 amount );
2727 event PriceOracleSet (address indexed token , address indexed oracle );
2828
29- constructor (
30- address _admin ,
31- uint256 _targetAmount ,
32- address _creator
33- ) Ownable (_admin) {
29+ constructor (address _admin , uint256 _targetAmount , address _creator ) Ownable (_admin) {
3430 require (_admin != address (0 ), "Invalid admin address " );
3531 require (_creator != address (0 ), "Invalid creator address " );
3632 require (_targetAmount > 0 , "Invalid target amount " );
37-
33+
3834 admin = _admin;
3935 targetAmount = _targetAmount;
4036 creator = _creator;
4137 }
4238
43-
4439 modifier withinDonationLimit (address token , uint256 amount ) {
4540 require (address (priceOracles[token]) != address (0 ), "No price oracle set for token " );
4641 AggregatorV3Interface priceFeed = priceOracles[token];
47- (, int256 price , , , ) = priceFeed.latestRoundData ();
42+ (, int256 price ,,, ) = priceFeed.latestRoundData ();
4843 uint8 priceDecimals = priceFeed.decimals ();
49-
44+
5045 require (price > 0 , "Invalid price " );
51-
46+
5247 uint256 usdValue;
5348 if (token == address (0 )) {
5449 // Native token (ETH) has 18 decimals
@@ -59,23 +54,25 @@ contract QuestDonation is Ownable {
5954 // Adjust the calculation based on token decimals
6055 usdValue = (amount * uint256 (price)) / (10 ** tokenDecimals) / (10 ** priceDecimals);
6156 }
62-
57+
6358 uint256 lastYear = lastDonationTimestamp[msg .sender ];
6459 if (block .timestamp - lastYear > YEAR) {
6560 yearlyDonations[msg .sender ] = 0 ;
6661 lastDonationTimestamp[msg .sender ] = block .timestamp ;
6762 }
68- require (yearlyDonations[msg .sender ] + usdValue <= MAX_DONATION, "Donation exceeds $5000/year. Contact info@etherguild.xyz " );
69-
63+ require (
64+ yearlyDonations[msg .sender ] + usdValue <= MAX_DONATION,
65+ "Donation exceeds $5000/year. Contact info@etherguild.xyz "
66+ );
67+
7068 yearlyDonations[msg .sender ] += usdValue;
7169 _;
7270 }
7371
7472 function donateETH () external payable withinDonationLimit (address (0 ), msg .value ) {
75-
7673 require (msg .value > 0 , "Donation amount must be greater than 0 " );
7774 AggregatorV3Interface priceFeed = priceOracles[address (0 )];
78- (, int256 price , , , ) = priceFeed.latestRoundData ();
75+ (, int256 price ,,, ) = priceFeed.latestRoundData ();
7976 uint8 priceDecimals = priceFeed.decimals ();
8077 emit DonationReceived (msg .sender , address (0 ), msg .value , msg .value * uint256 (price) / (10 ** priceDecimals));
8178 }
@@ -84,7 +81,7 @@ contract QuestDonation is Ownable {
8481 require (allowedTokens[token], "Token not allowed " );
8582 IERC20 (token).safeTransferFrom (msg .sender , address (this ), amount);
8683 AggregatorV3Interface priceFeed = priceOracles[token];
87- (, int256 price , , , ) = priceFeed.latestRoundData ();
84+ (, int256 price ,,, ) = priceFeed.latestRoundData ();
8885 uint8 priceDecimals = priceFeed.decimals ();
8986 emit DonationReceived (msg .sender , token, amount, amount * uint256 (price) / (10 ** priceDecimals));
9087 }
@@ -100,12 +97,11 @@ contract QuestDonation is Ownable {
10097 function setPriceOracle (address token , address oracle ) external onlyOwner {
10198 require (allowedTokens[token], "Token not allowed " );
10299 require (oracle != address (0 ), "Invalid oracle address " );
103-
100+
104101 priceOracles[token] = AggregatorV3Interface (oracle);
105102 emit PriceOracleSet (token, oracle);
106103 }
107104
108-
109105 function withdraw (address token , uint256 amount ) external {
110106 require (msg .sender == admin, "Only admin can withdraw " );
111107 if (token == address (0 )) {
0 commit comments